Modifying fraction macro for in-line text and exponents
OpenType support in TeX as of when I first wrote xfrac in early 2004 was basically non-existent - XeTeX hadn't even been released back then. Therefore, the package was never designed with that in mind. Besides, the fundamental purpose was to provide a way to write nice fractions for fonts that didn't include them.
The package could very likely be made OpenType aware by making a few changes as to how fonts are selected. However, you should also be able to define an instance for the font in question by using the numerator-format key to select the font. The following instance declaration will basically make \sfrac behave as you wish for your chosen variant of Garamond. This is very similar to the Janson example from the manual.
\DeclareInstance{xfrac}{EBGaramond12Regular(0)}{text}{
numerator-format = {\fontspec{EBGaramond12Regular}[RawFeature=+numr]#1},
scaling = false,
numerator-bot-sep = 0pt,
denominator-bot-sep = 0 pt,
denominator-format = {\addfontfeatures{RawFeature=+dnom}#1}
}
Hope this helps, Morten
Here I create \altfrac{}{}
. It does not require fontspec
, it obeys math mode, its font is larger than that of \sfrac
, the denominator lies on the baseline, while the top of the numerator I tries to lay at the top of the normal text font. The numbers are presented in \footnotesize
. The slash is a horizontally stretched /
to give it more of the fractional slash appearance.
It's downside is that is does not work properly if the current fontsize is anything other than \normalsize
.
\documentclass{article}
\usepackage{xfrac,graphicx}
\newcommand{\altfrac}[2]{\ifmmode\def\tmp{$}\else\def\tmp{}\fi\mbox{%
{\footnotesize \raisebox{.24\ht\strutbox}{\tmp#1\tmp}}%
\kern-2.2pt\scalebox{1.6}[1]{/}\kern-1.8pt%⁄% That slash is U+2044 FRACTION SLASH, which has special spacing
{\footnotesize\tmp#2\tmp}%
}}
\begin{document}
\parindent 0pt
This is \texttt{altfrac:}\qquad
\altfrac{12}{14} \altfrac{31415}{27182} \altfrac{abc}{def} \altfrac{Foo!}{Bar?}
\altfrac{\#\$\%+/<>=}{?\@[]\textbackslash\_|\{\}§†}
\[\left(\frac{3x}{2y}\right)^{\altfrac{3}{2}}=\altfrac{\lambda}{2x}\]
\qquad And here is \altfrac{x}{y} versus $\altfrac{x}{y}$\\
And this is \texttt{sfrac:}\qquad
\sfrac{12}{14} \sfrac{31415}{27182} \sfrac{abc}{def} \sfrac{Foo!}{Bar?}
\sfrac{\#\$\%+/<>=}{?\@[]\textbackslash\_|\{\}§†}
\[\left(\frac{3x}{2y}\right)^{\sfrac{3}{2}}=\sfrac{\lambda}{2x}\]\\
\end{document}