Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

share|improve this question
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. –  drozzy Jan 15 '12 at 21:38

3 Answers 3

up vote 12 down vote accepted

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.

\documentclass{article}

\usepackage{nicefrac}

\begin{document}

\nicefrac{1}{2}

\end{document}

enter image description here

share|improve this answer
    
Thanks, I'll take the help any way I can get it. –  drozzy Jan 15 '12 at 21:20

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.

\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}
share|improve this answer
    
Thanks, looks great! –  drozzy Jan 15 '12 at 21:20
    
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! –  drozzy 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.

\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.

fraction

share|improve this answer
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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