# Why are xfrac-style fractions so ugly in this document?

I seem to have stumbled on a rather robust way of stopping the xfrac package from working properly.

This is a MWE of the problem:

\documentclass{amsart}

\usepackage[a5paper, margin=28mm, marginparwidth=20mm, marginparsep=3mm]{geometry}
\usepackage{verse, microtype, mathtools, xfrac, marginnote, graphicx, ragged2e, xstring, afterpage, pifont}

\usepackage{fontspec}
\setmainfont[Numbers=OldStyle]{CMU Serif}

\DeclareInstance{xfrac}{mjnj}{text} { numerator-font = mjn1, denominator-font = mjn0, scaling = false, numerator-bot-sep = 0 pt, denominator-bot-sep = 0 pt }

\begin{document}

This -- \sfrac{1}{2} -- is not what I want a half to look like!

\end{document}


As you can see from the screenshot below, I get an unsightly mess, instead of the crisp, tight-looking fractions that I'm used to getting. Why is this happening, and what can I do about it?

Things I've tried already that haven't worked:

• Changing \setmainfont[Numbers=OldStyle]{CMU Serif} to \setmainfont{CMU Serif}, i.e. removing old style numerals.
• Calling $\sfrac{1}{2}$ or \sfrac{$1$}{$2$} instead.
• possibly unrelated but never use \usepackage[T1]{fontenc} with xetex Aug 23, 2021 at 21:45
• \usepackage[T1]{fontenc} is certainly wrong. You remove that. Aug 23, 2021 at 21:45
• xfrac provides a template interface allowing you to customise all the font sizes and spacings, it needs to be adjusted if you are using non standard fonts as here: Aug 23, 2021 at 21:48
• you need a declaration such as \DeclareInstance{xfrac}{mjnj}{text} { numerator-font = mjn1, denominator-font = mjn0, scaling = false, numerator-bot-sep = 0 pt, denominator-bot-sep = 0 pt }  tuned to your fonts (there are many more parameters) I do not have your font set but it seems your main font is CMU can you not make a more reasonable example that people can run to see the issue? Aug 23, 2021 at 21:51
• no that was an example from the documentation refering to a different font family. If you made an example so people could see the bad fraction perhaps someone will suggest how to tune it, but your code block can not be run to see anything it has no \documentclass no example of \sfrac and lines such as \newfontfamily\frakturish{Fette UNZ Fraktur} mean that it will just give unknown font errors in most places, and presumably that has no relation to the fraction shown. Please make the example a complete small document. Aug 23, 2021 at 22:33

As much as offering a way to set fractions xfrac is an experiment in providing a template interface to typesetting parameters, as such it is an over-parameterised interface and you can tweak all aspects of the layout for each base font.

This isn't looking that great still (I think I should have started with a smaller /) but will get you started, see the xfrac manual for the full set of parameters you can set.

\documentclass{amsart}

\usepackage[a5paper, margin=28mm, marginparwidth=20mm, marginparsep=3mm]{geometry}
\usepackage{verse, microtype, mathtools, xfrac, marginnote, graphicx, ragged2e, xstring, afterpage, pifont}

\usepackage{fontspec}
\setmainfont[Numbers=OldStyle]{CMU Serif}

\DeclareInstance{xfrac}{CMUSerif(0)}{text} {
slash-symbol-font = CMUSerif(0),
numerator-font= CMUSerif(0),
denominator-font=CMUSerif(0),
numerator-top-sep = -1pt,
scale-factor=0.95,
denominator-bot-sep = -1pt,
slash-right-kern=-.15em,
slash-left-kern=-.1em,
}

\begin{document}

This -- \sfrac{1}{2} -- is not what I want a half to look like!

\end{document}

• What does the 0 do in CMUSerif(0)? Is that specifying that we don't want to use old-style numerals within each sfrac? Aug 24, 2021 at 19:05
• @TomHosker it's just a name, fontspec generates latex NFSS names and mappings that in traditional tex had to be hand crafted for each font, you might load the same font twice with different settings so it generates names (as may be used with \fontfamily{...}\selectfont based on the filename and a numeric counter starting with 0, I used \showthe\font originally to see the name fontspec had picked. Aug 24, 2021 at 19:11