I'm using unicode-math in lualatex with the Cambria Math fonts. Compared to Computer Modern math, there is too much vertical space between fractions. Is there a way I can achieve my adjustment without having to patch \frac? For example a fontspec or unicode-math option?

i.e. I'm looking for an option to change the vertical space around the fraction bar.

Edit: added xfrac case and +frac, +numr/+dnom.

+frac just +sups all digits. Custom xfrac only works in math mode when enclosing the arguments in \text{19} but not with \text{#1}?!.

LuaTeX-0.70.2, Cambria 5.96

\setmathfont{Cambria Math}

        {\raisebox{-.1em}{\scriptsize $#1$}}%
        {\raisebox{.15em}{\scriptsize $#2$}}%


% tfracs look weird:
\noindent here is a first ygygyg line of text\\
bit too large: $\frac{19}{30}$. $\otfrac{19}{30}$ better?\\
here is anothÁÁÁÁÁÁ line of text\\[.5em]
% default sfrac looks weirder:
default sfrac text \sfrac{19}{30} math $\sfrac{19}{30}$\\
% customising helps some:
    numerator-top-sep = -.1ex,
    denominator-bot-sep = -.1ex,
    numerator-top-sep = -.2ex,
    denominator-bot-sep = -.1ex,
    scale-factor = 0.8333,
    scale-relative = true,
    slash-right-mkern = -0mu,
    slash-left-mkern = -0mu,
custom sfrac text \sfrac{19}{30} math $\sfrac{19}{30}$\\
% +frac feature just superscripts all digits
{\addfontfeature{Fractions=On} +frac 19/30, bad: 24. }
+numr/+dnom: \ofrac{19}{30} \\
% customize sfrac this way:
    numerator-bot-sep = 0pt, denominator-bot-sep = 0pt,
    scaling = false, slash-symbol=\divslash,
    numerator-top-sep = \c_max_dim, numerator-bot-sep = 0pt,
    denominator-bot-sep = 0pt, scaling = false,
    slash-right-mkern = 0mu, slash-left-mkern = 0mu,
    %------------------vvvv-- or no \text{}, doesn't matter.
% nice
otf custom sfrac text \sfrac{19}{30}
% what?!
math $\sfrac{19}{30}, \sfrac{\text{19}}{\text{30}}$\\


rendering of code sample

I'm not using \sfrac with anything other than digits as arguments anyway so I'll use this instead for consistency, but a way to modify \tfrac would still be interesting, or is \tfrac = \otfrac the best way?

  • 2
    Have you considered \setmainfont[RawFeature=+frac]{Cambria}? Try it with 19/30 in text mode. | Or the xfrac package and \sfrac{19}{30} (both modes)? – Qrrbrbirlbel Sep 6 '12 at 23:54
  • +frac doesn't work for some reason, maybe my version of the font is broken? Building the fraction manually works, but I would still prefer the upright fractions instead of vulgar though. – pascal Sep 7 '12 at 2:17
  • I have a similar problem (the one titled "bad" in your example) when I use Linux Libertine O. Seems to me like a bug in fontspecnicefrac package doesn’s seem to provide better options than xfrac and \tfrac. – Qrrbrbirlbel Sep 7 '12 at 3:02
  • It looks fine with Computer Modern, I guess Cambria Math just specifies a greater depth and height? – pascal Sep 7 '12 at 18:56
  • @pascal: Please forget what I wrote in my previous comment about an erroneous implementation. I completely forgot about the fontdimen parameters Philipp explained in his answer. – Hendrik Vogt Sep 9 '12 at 15:15

The positioning of numerators and denominators is controlled by a font parameter that can easily be modified in LuaLaTeX:

\documentclass[pagesize=auto, version=last]{scrartcl}
\setmathfont{Cambria Math}
  local function patch_cambria_frac(fontdata)
    if fontdata.psname == "CambriaMath" then
      local mc = fontdata.MathConstants
      mc.FractionNumeratorShiftUp = 0.4 * mc.FractionNumeratorShiftUp
      mc.FractionDenominatorShiftDown = 0.4 * mc.FractionDenominatorShiftDown
  luatexbase.add_to_callback("luaotfload.patch_font", patch_cambria_frac, "cambria_frac")
  • awesome, looks like it's time to not just use LuaTeX as a drop-in replacement for XeTeX anymore. – pascal Sep 8 '12 at 17:14

Maybe this does help you

\usepackage{amsmath} % load before unicode-math

In the document you can use it as \superfrac{19}{30}.

The vertical alignment (.3ex) may need to be adjusted. The 2 denotes the scriptstyle.

Todd Lehmann has created some interesting macros: Improved kerning in fractions?

  • But that's just not as high because the overall font size is smaller, the relative height of the space around the bar isn't reduced… Looking at the source for genfrac though, it's just calling \over or \above, so there's no more way to squeeze any options in as I asked, so I guess it's impossible to change without patching it. – pascal Sep 7 '12 at 19:24

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.