4

I'm writing things like 2/3 or 1/4 in my text and I'd like to make them appear as they do automatically in a processor like Word where they are slightly smaller and have the diagonal separation if that makes sense, instead of being placed on top of each other like it would appear in math mode.

2
  • 1
    try nicefrac package. welcome to tex.se.
    – Zarko
    Aug 18, 2017 at 19:19
  • If by any chance you're already using the Charter fonts via XCharter.sty, you could also use \textfrac{}{}
    – dedded
    Aug 18, 2017 at 19:22

1 Answer 1

4

I suggest you load the xfrac package and write $\sfrac{1}{2}$ to achieve your formatting objective by hand.

If you want to fully automate the process of typesetting all inline-math fractions with the \sfrac macro, the following, LuaLaTeX-based solution may be of interest to you.

enter image description here

% !TeX program = lualatex
\documentclass{article}
\usepackage{xfrac}   % for \sfrac macro
\usepackage{luacode} % for "luacode" env.

%% Lua-side code
\begin{luacode}
function make_nice_fracs(s)
  return (s:gsub ( "(%d%d*)/(%d%d*)", "\\sfrac{%1}{%2}" ))
end
\end{luacode}
%% LaTeX-side code
\newcommand{\ActivateMakeNiceFracs}{\directlua{%
   luatexbase.add_to_callback ( "process_input_buffer", 
      make_nice_fracs, "make_nice_fracs" )}}
\AtBeginDocument{\ActivateMakeNiceFracs}

\begin{document}
From $\sfrac{1}{22}$ to $\sfrac{33}{444}$. The quick brown dog\dots

From $1/22$ to $33/444$. The quick brown dog\dots

% Use whitespace before or after "/" suspends the Lua function
From $1 /22$ to $33/ 444$. The quick brown dog\dots
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .