# Less vertical space in frac

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

\documentclass{article}
\usepackage{fontspec}
\usepackage{xfrac}
\usepackage{unicode-math}
\setmathfont{Cambria Math}
\setmainfont{Cambria}

\newcommand{\otfrac}[2]{%
\frac%
{\raisebox{-.1em}{\scriptsize $#1$}}%
{\raisebox{.15em}{\scriptsize $#2$}}%
}

\newcommand{\ofrac}[2]{%
\text{%
\divslash{}%
}%
}

\begin{document}
% 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:
\DeclareInstance{xfrac}{default}{text}{
numerator-top-sep = -.1ex,
denominator-bot-sep = -.1ex,
slash-symbol=\divslash,
}
\DeclareCollectionInstance{plainmath}{xfrac}{mathdefault}{math}{
numerator-top-sep = -.2ex,
denominator-bot-sep = -.1ex,
scale-factor = 0.8333,
scale-relative = true,
slash-right-mkern = -0mu,
slash-left-mkern = -0mu,
slash-symbol=\text{\divslash}
}
\UseCollection{xfrac}{plainmath}
custom sfrac text \sfrac{19}{30} math $\sfrac{19}{30}$\\
%
% +frac feature just superscripts all digits
+numr/+dnom: \ofrac{19}{30} \\
%
% customize sfrac this way:
\DeclareInstance{xfrac}{default}{text}{
numerator-bot-sep = 0pt, denominator-bot-sep = 0pt,
scaling = false, slash-symbol=\divslash,
}
\ExplSyntaxOn
\DeclareCollectionInstance{plainmath}{xfrac}{mathdefault}{math}{
numerator-top-sep = \c_max_dim, numerator-bot-sep = 0pt,
denominator-bot-sep = 0pt, scaling = false,
slash-right-mkern = 0mu, slash-left-mkern = 0mu,
slash-symbol=\text{\divslash},
%------------------vvvv-- or no \text{}, doesn't matter.
}
\ExplSyntaxOff
\UseCollection{xfrac}{plainmath}
% nice
otf custom sfrac text \sfrac{19}{30}
% what?!
math $\sfrac{19}{30}, \sfrac{\text{19}}{\text{30}}$\\

\end{document}


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?

-
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}
\usepackage{fontspec}
\usepackage{unicode-math}
\usepackage{luacode}
\usepackage{luatexbase-mcb}
\setmathfont{Cambria Math}
\setmainfont{Cambria}
\begin{luacode*}
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
end
end
\end{luacode*}
\begin{document}
$\frac{19}{30}$
\end{document}

-
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

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