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
Thanks!
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
Thanks!
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:

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.
\documentclass{article}
\usepackage{graphicx}
\usepackage{xfrac}
\newcommand*{\myxfrac}[2]{\raisebox{-0.33ex}{${}^{#1}$\kern-0.1em}/\kern-0.1em{{\raisebox{0.34ex}{$_{#2}$}}}}%
\begin{document}
\[
\myxfrac{1}{2} \quad \sfrac{1}{2}
\]
\end{document}
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.
\documentclass{minimal}
\makeatletter
\def\nicefrac#1#2{\check@mathfonts%
\raise.5ex\hbox{\the\scriptfont0 #1}%
\kern-.1em/\kern-.15em%
\lower.25ex\hbox{\the\scriptfont0 #2}}
\makeatother
\begin{document}
Here is a nice in-line fraction: $\nicefrac{21}{234}$.
\end{document}
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.

\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