2

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 :
    \begin{equation}
        \frac{1}{2} = \mfrac{1}{2} \: A = \medfrac{1}{2} \: A = \frac{1}{2} \: A.
    \end{equation}

\end{document}

Preview:

enter image description here

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?

Cham
  • 2,304
  • you are setting a textstyle fraction not displaystyle, but avoid applying \scalebox to text, nccmath does not use scaling at all,. – David Carlisle Dec 07 '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 07 '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 08 '19 at 18:37
  • @David, in what way is my macro a textsyle definition? I don’t get it. – Cham Dec 08 '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 08 '19 at 18:44
  • I’m sorry, I’m not sure I understand. Maybe you could add an answer with the proper macro which creates the same medium fraction as the one from the package? – Cham Dec 08 '19 at 18:48
  • @Cham: in a displayed equation, you may try \text{\smaller$ \frac ab $}, but you'll have ti load relsize, and the fraction rules won't be exactly aligned with the other fraction rules. This being said, nccmath loads amsmath so you don't have to load the latter. – Bernard Dec 08 '19 at 18:50
  • @Cham no, sorry if you want something that acts like that, just use the package or copy the definition of just that command from the package. I'm just explaining what is wrong with the code posted here. – David Carlisle Dec 08 '19 at 18:50
  • Curently, I’m not in front of my computer so can’t test any LaTeX. – Cham Dec 08 '19 at 18:50
  • Another unrelated question (or maybe it’s related) : why adding « * » alter the command \newcommand? – Cham Dec 08 '19 at 18:55

1 Answers1

2

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

enter image description here

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}
David Carlisle
  • 757,742
  • actually I think I over-compensated the fraction bar width 1.1 multiplier is probably too much. – David Carlisle Dec 08 '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 08 '19 at 23:41
  • 1
    @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 09 '19 at 00:28
  • I'm wondering why such a medium fraction isn't standard, by default, like \tfrac, \dfrac. – Cham Dec 09 '19 at 00: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 09 '19 at 00:32
  • The output is much nicer with \mfrac, in a series, for example. – Cham Dec 09 '19 at 00:36