how to do something like ^1/_2 with frac?
![](https://secure.gravatar.com/avatar/044c8a63f3f5f0173d96580aa6f23552.jpg?s=120&d=mm&r=g)
Hi all again, I try to do something like 1/2 with an upper 1 and a lower 2. The code below still doesn't quite work. \def\nfrac#1#2{\leavevmode\kern.1em% \raise.5ex\hbox{\scriptsize #1}% \kern-.1em/\kern-.15em% \lower.25ex\hbox{\scriptsize #2}} Help would be very much appreciated! Hubertus P.S. Is there a good pdf around to get some insight's of this tex-magic?
![](https://secure.gravatar.com/avatar/565476157eb3895a9c928ffce26d988d.jpg?s=120&d=mm&r=g)
Hubertus wrote:
Hi all again, I try to do something like 1/2 with an upper 1 and a lower 2. The code below still doesn't quite work.
\def\nfrac#1#2{\leavevmode\kern.1em% \raise.5ex\hbox{\scriptsize #1}% \kern-.1em/\kern-.15em% \lower.25ex\hbox{\scriptsize #2}}
Such a macro is already present. The command's name is \vulgarfraction, and even is configurable (3 is the default rendering);-) Best, taco % example taken from core-mis.tex \starttext \starttabulate \HL \NC \bf method \NC \bf visualization \NC\NR \HL \NC 0 \NC \chardef\vulgarfractionmethod0\vulgarfraction{1}{2} \NC\NR \NC 1 \NC \chardef\vulgarfractionmethod1\vulgarfraction{1}{2} \NC\NR \NC 2 \NC \chardef\vulgarfractionmethod2\vulgarfraction{1}{2} \NC\NR \NC 3 \NC \chardef\vulgarfractionmethod3\vulgarfraction{1}{2} \NC\NR \HL \stoptabulate \stoptext
![](https://secure.gravatar.com/avatar/c5ae4f9aa0d3a9bd5376e92b322c3e50.jpg?s=120&d=mm&r=g)
On Fri, 26 Jan 2007, Taco Hoekwater wrote:
Hubertus wrote:
Hi all again, I try to do something like 1/2 with an upper 1 and a lower 2. The code below still doesn't quite work.
\def\nfrac#1#2{\leavevmode\kern.1em% \raise.5ex\hbox{\scriptsize #1}% \kern-.1em/\kern-.15em% \lower.25ex\hbox{\scriptsize #2}}
Such a macro is already present. The command's name is \vulgarfraction, and even is configurable (3 is the default rendering);-)
Best, taco
% example taken from core-mis.tex
\starttext \starttabulate \HL \NC \bf method \NC \bf visualization \NC\NR \HL \NC 0 \NC \chardef\vulgarfractionmethod0\vulgarfraction{1}{2} \NC\NR \NC 1 \NC \chardef\vulgarfractionmethod1\vulgarfraction{1}{2} \NC\NR \NC 2 \NC \chardef\vulgarfractionmethod2\vulgarfraction{1}{2} \NC\NR \NC 3 \NC \chardef\vulgarfractionmethod3\vulgarfraction{1}{2} \NC\NR \HL \stoptabulate \stoptext
Be careful. This method does not work correctly inside math mode. I do not know if it is a good idea to use such a construct inside math mode. I am mentioning this because someone added an example on the wiki where \vfrac is used in math mode. Look at the output of $\vulgarfraction{a}{b} (a+b)$ The a and b of the fraction is in text mode rather than math mode. On the LaTeX end, there are two packages that provide such a feature: nicefrac and xfrac. Nicefrac ensures that the height of the fraction is not greater than `M'. It is somewhat cleaver, and works "correctly" in displaystyle, textstyle, scriptstyle and scriptscriptstyle. See units.dtx for its implementation http://www.ctan.org/tex-archive/macros/latex/contrib/units/ On the other hand, if you want to read what is wrong with nicefrac, read the documentation of xfrac by Morton Høgholm ftp://tug.ctan.org/pub/tex-archive/macros/latex/exptl/xfrac/doc/xfrac.pdf His main objection is that nicefrac uses virglue instead of a solidus to separate fractions --- since a solidus is absent from CM fonts. (What are these things? Is a solidus present in LM?) Another thing is that nicefrac does not work with old style figures. xfrac allows you to configure the font for the numerator, solidus and the denominator, amongst other things. The vulgarfrac in ConTeXt suffers from most of the problems of nicefrac. The best option is for the font to provide more symbols like \onehalf \threequarter etc. Failing that we need to have a macro \vulgarfrac where \vulgrarfrac 12 is same as \onehalf. Aditya
participants (3)
-
Aditya Mahajan
-
Hubertus
-
Taco Hoekwater