3

I see some very strange behaviour related to the use of \sfrac in a figure caption. The reason seems to be font size issues, but I can't figure out how to resolve them.

MWE

The issues appear in the following example.

\documentclass[11pt]{article}

\usepackage{amssymb}
\usepackage{anyfontsize}
\usepackage[font=small]{caption}
\usepackage{xfrac}

\begin{document}
\begin{figure}
\caption{Test 1: $\sfrac12$, $\sfrac14$.}
\end{figure}

\begin{figure}
\caption{Test 2: $\sfrac12$, $\sfrac14$.}
\end{figure}

\begin{figure}
\caption{Test 3: $\sfrac12$, $\sfrac14$.}
\end{figure}%

\end{document}



The problem

The figure caption is the same three times in a row, but only the third one triggers errors, namely the following (taken from the log file, it appears there six times):

(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd
File: umsb.fd 2013/01/14 v3.01 AMS symbols B
)
! Improper `at' size (0.0pt), replaced by 10pt.
<to be read again> 
                   relax 
l.20 \caption{Test 3: $\sfrac12$, $\sfrac14$.}
                                              
I can only handle fonts at positive sizes that are
less than 2048pt, so I've changed what you said to 10pt.

Observations and comments

  • If I take out one of the figures and leave only two of them, everything seems fine.
  • Taking out any of the amssymb, anyfontsize, or caption packages (or even just the small option of the caption package) resolves the problem. I don't want to take any of these out though in my original document (Ironically, I believe I started using anyfonsize to get rid of font size replacement warnings...)

Any help is much appreciated, even if it's just towards understanding what is going on here.

1
  • 1
    Note that a copy of the caption is being sent to the aus file, You really don't want formatted text there. This include any math or font changes. It will only cause an error if used, but it still looks ugly. The optional [short caption] or lots of \protects will fix it. Aug 11, 2023 at 14:35

1 Answer 1

3

The problem is with the obsolete package anyfontsize:

% anyfontsize.sty -- allow font size substitutions
% by Péter Szabó <[email protected]> at Sat Feb  3 13:56:49 CET 2007

The right package to use is fix-cm.

\RequirePackage{fix-cm}% because you're using OT1

\documentclass[11pt]{article}

\usepackage{amssymb}
\usepackage[font=small]{caption}
\usepackage{xfrac}

\begin{document}
\begin{figure}
\caption{Test 1: $\sfrac12$, $\sfrac14$.}
\end{figure}

\begin{figure}
\caption{Test 2: $\sfrac12$, $\sfrac14$.}
\end{figure}

\begin{figure}
\caption{Test 3: $\sfrac12$, $\sfrac14$.}
\end{figure}%

\end{document}

You can load fix-cm as usual after \documentclass if you pass to the T1 encoding, with \usepackage[T1]{fontenc}.

But, of course, \sfrac is to be used only in recipe books. 🤭

enter image description here

3
  • I am of course writing a recipe book, no worries ;-) After trying to read up a bit on fonts (but then again giving up, actually), I realize that what might in fact worry you more is that I am using the times package on top of the above. Does that change your answer? Or, given that fix-cm still helps, why does it help? And, finally (but least important), why did my problem only occur in the third caption?
    – user279611
    Aug 11, 2023 at 11:43
  • 1
    @user279611 With times (which is obsolete as well) you need fix-cm because of math mode in Computer Modern (they don't really blend). You might try mathptmx instead or, better newtx.
    – egreg
    Aug 11, 2023 at 13:20
  • Thanks for the pointer. I fear that I got so used to the font mix that I actually like it by now--seeing all my math actually typeset in a times-like-font with newtx is strange...
    – user279611
    Aug 11, 2023 at 13:45

You must log in to answer this question.

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