Is it possible to create my own xfrac command - without using that package (it is giving me too much trouble)? I know you can do superscript, subscript to make a fraction look.

Can I do something like:

 \newcommand xfrac{a}{b} = ^a/_b


  • 2
    The problems you describe in the other question are still not resolved, and if they are it will make it a lot easier! I encourage you to stay on that path of resolution! – zeroth Jan 15 '12 at 20:35
  • Thanks, unfortunately I have a pressing deadline, so I need to find a way that works now :-( I will try to resolve the other problem when I get more time. – Andriy Drozdyuk Jan 15 '12 at 21:38
  • Related Question: How to make fractions in powers look good. – Peter Grill Sep 21 '14 at 3:09

Consider to use the nicefrac package. It was last updated in 1998, so it shouldn't cause "too much trouble". For its drawbacks see section 1.2 of the xfrac (sic!) documentation.






enter image description here


Here is the best I could come up with. You might need to adjust the parameters below as I have only tested it for this one case. The output on the left is the one from the macro below, and the output of \sfrac from the xfrac package is on the right. These two look pretty much identical to me:

enter image description here

This is adapted from what you posted with \kern being used to move the numbers closer to the slash, and \raisebox from the \graphicx package used to more the numbers into the same vertical position as the produced by \sfrac.



    \myxfrac{1}{2}  \quad \sfrac{1}{2}
  • You're welcome. But, please do consider what zeroth commented: You should figure out how to install the package and get to the bottom of why it is missing in your install. This might be an indication of other things that might also be broken. – Peter Grill Jan 15 '12 at 21:23
  • Maybe I'm just dumb and I would love to figure it out - but when I have to finish my project, and the thing does not work after two days of troubleshooting, I gotta draw a line somewhere! – Andriy Drozdyuk Jan 15 '12 at 21:37
  • Yep, that makes sense if you are the late stages of a project... – Peter Grill Jan 15 '12 at 21:57

If you want to avoid an extra package, you can could use the definition below as well. It now has taken egreg's comment from below into account.


  \raise.5ex\hbox{\the\scriptfont0 #1}%
  \lower.25ex\hbox{\the\scriptfont0 #2}}

Here is a nice in-line fraction: $\nicefrac{21}{234}$.

To give proper credit: I believe I found the definition once in a book by Knuth. It's living in my pile of TeX snippets that I search for occasions like this. You could rename it to \xfrac in the definition or use \let\xfrac\nicefrac to make it available under both names.


  • 1
    In order to use it also outside math-mode, one should do also \check@mathfonts, otherwise \scriptfont0 might be undefined or wrong. If you plan to use it only in math mode, then \leavevmode is redundant. – egreg Jan 15 '12 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.