# Medium sized fraction macro, instead of using the nccmath package

We could get good looking medium sized fractions using the nccmath package. However, there may be some incompatibilities with other packages and I would prefer to get rid of that package, since I just want to use its medium fraction. I created a macro to try to repoduce the smaller fraction (not \tfrac !), but I'm currently unable to get it right. Here's a MWE showing the medium fraction and it's current reproduction with a macro:

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage{lmodern}
\usepackage{nccmath,amsmath}
\usepackage{mathtools}

\newcommand*{\medfrac}[2]{\vcenter{\hbox{\scalebox{1}{\ensuremath{\frac{#1}{#2}}}}}}

\begin{document}

Blabla bla bla blabla :
$$\frac{1}{2} = \mfrac{1}{2} \: A = \medfrac{1}{2} \: A = \frac{1}{2} \: A.$$

\end{document}


Preview:

As you can see here, the \medfrac macro gives a tiny fraction, while using 1 as a scale parameter in the macro. So what is going on, and how could we get the same output as \mfrac?

• you are setting a textstyle fraction not displaystyle, but avoid applying \scalebox to text, nccmath does not use scaling at all,. – David Carlisle Dec 7 '19 at 22:55
• Which incompatibilities do you have? The only one I've observed is with the \shortintertext command from mathtools, and it is solved loading nccmath before mathtools. – Bernard Dec 7 '19 at 23:12
• @Bernard, I don’t have incompatibilities yet, but my preamble is already a huge castle of cards, so I would prefer to get rid of packages I don’t absolutely need. So how should I define that medium fraction ? – Cham Dec 8 '19 at 18:37
• @David, in what way is my macro a textsyle definition? I don’t get it. – Cham Dec 8 '19 at 18:42
• @Cham if you ignore the superfluous scalebox and ensuremath then you have \hbox{$\frac{#1}{#2}$} so a textstyle fraction. – David Carlisle Dec 8 '19 at 18:44

It isn't clear why you don't want to use the package, but if not don't use \scalebox on text. This is a simple version, which only works for \normalsize text and displays a \small \displaystyle fraction with tighter spacing around the fraction bar and raised slightly to align with the math axis of the outer equation, The font dimen parameters are listed in this answer

What do different \fontdimen<num> mean

The macro makes the third 1/2 here, with the nccmath mfrac for comparison shown in the final case.

\documentclass{article}
\usepackage{amsmath,nccmath}
\newcommand\zfrac[2]{\text{\footnotesize\raisebox{.15ex}{%
\dimen0=\fontdimen8\textfont2  % numerator shift
\dimen2=\fontdimen11\textfont2 % denominator shift
\dimen4=\fontdimen8\textfont3  % fraction rule
$% \fontdimen8\textfont2=.5\dimen0 \fontdimen11\textfont2=.5\dimen2 \fontdimen8\textfont3=1.1\dimen4 \dfrac{#1}{#2}$%
\fontdimen8\textfont2=\dimen0
\fontdimen11\textfont2=\dimen2
\fontdimen8\textfont3=\dimen4
}}}

\begin{document}

$\frac{1}{2}+\tfrac{1}{2}+\zfrac{1}{2}+\mfrac{1}{2}$
\end{document}
`
• actually I think I over-compensated the fraction bar width 1.1 multiplier is probably too much. – David Carlisle Dec 8 '19 at 20:03
• Hmm, that's pretty complicated. I'm a bit confused now, about using a macro without the nccmath package, or else simply using the package for the mfrac command only. – Cham Dec 8 '19 at 23:41
• @Cham it's only a dozen lines of code, that's not really very complicated, it's just changing the font size, adjusting three parameters, setting a fraction then restoring them. But using a package is simpler, that's rather the point of packages. – David Carlisle Dec 9 '19 at 0:28
• I'm wondering why such a medium fraction isn't standard, by default, like \tfrac, \dfrac. – Cham Dec 9 '19 at 0:31
• @Cham most documents have no need for such a construct (I've been using tex for 30 years and never used it for example) – David Carlisle Dec 9 '19 at 0:32