Pretty Fractions by NikNakk

z=strsplit(gsub("([-+*=])(?![^(]*\\))","&\\1&",readLines("stdin"),pe=T),"&")
f=`if`
p=function(...)paste(...,sep="",collapse="")
for(a in z)cat(c(apply(sapply(strsplit(a,"/"),function(b)f(length(b)==1,c(w<-p(rep(" ",nchar(b))),b,w),{
b=gsub("[()]","",b);d=nchar(b[1])-nchar(b[2]);b[1+(d>0)]=p(p(rep(" ",w<-abs(d)%/%2)),b[1+(d>0)],p(rep(" ",abs(d)-w)))
c(b[1],p(rep("-",nchar(b[1]))),b[2])})),1,p),""),sep="\n")

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page