If you're using XeTeX or LuaTeX with fontspec
, you might be using a font that has the OpenType feature frac
, which might either be limited to a certain number of fixed fractions (e.g. Junicode), or it works with any combination of digits, e.g. in Linux Libertine (libertineotf
package) or EB Garamond.
Here's a MWE using libertineotf
:
\documentclass{article}
\usepackage{fontspec}
\usepackage{libertineotf}
\begin{document}
\addfontfeatures{RawFeature=+frac}
1/2 3/4 5/6 7/8 9/10 11/12 31415/27182 1000/1000000
\end{document}

If the font contains the OpenType features numr
(numerator) and dnom
(denominator), we can get even fancier and typically include a greater variety of glyphs:
\documentclass{article}
\usepackage{fontspec}
\setmainfont{EB Garamond 12 Regular}
\newcommand{\unifrac}[2]{\mbox{% making sure we don't get a line break
{\addfontfeatures{RawFeature=+numr}#1}%
⁄% That slash is U+2044 FRACTION SLASH, which has special spacing
{\addfontfeatures{RawFeature=+dnom}#2}%
}}
\begin{document}
\unifrac{12}{14} \unifrac{31415}{27182} \unifrac{abc}{def} \unifrac{Foo!}{Bar?}
\unifrac{\#\$\%+/<>=}{?\@[]\textbackslash\_|\{\}§†}
\end{document}

To find out which features your OpenType font has, see
To find our which fractions are included e.g. in Junicode's frac
feature, see
To get started with Xe(La)TeX and/or Lua(La)TeX, see