Backend reasoning on font size in math mode

math-modetex-core

This is more of a philosophical question. I was looking for ways to increase the font size within math mode locally (eg. in only one equation/align environment) but the solutions I come across often just revert to text mode. I was wondering is there some structural reason in the TeX system that we cannot access directly the font size for mathematical symbols (locally in only a single equation/align environment)? There are commands such as "dfrac", so I would expect to have more global control too.

For example, as you can see in these answers, the authors revert to text mode.

thanks

Best Answer

To expand on David's answer, what \DeclareMathSizes does is define a macro S@XX where XX is the current type size in points, e.g.,

 \S@10 = macro: -> {
    \gdef\tf@size{10}
    \gdef\sf@size{7}
    \gdef\ssf@size{5}
 }

(I've modified spaces and line breaks from the output of \meaning for the sake of clarity).

This means that if you want to see what the sizes are, you can just look at the values of those macros and, in fact that's exactly what happens in the definition of the LaTeX macro:

\DeclareRobustCommand{\LaTeX}{L\kern-.36em%
        {\sbox\z@ T%
         \vbox to\ht\z@{\hbox{\check@mathfonts
                              \fontsize\sf@size\z@ % 👈
                              \math@fontsfalse\selectfont
                              A}%
                        \vss}%
        }%
        \kern-.15em%
        \TeX}

But you want to change this locally. For this, there is a sneaky way to do it. We can't sprinkle \DeclareMathSizes around the document since it's preamble-only, but we can create a new type size that's slightly off³,⁴ from the normal typesize and use that.

In the preamble:

\DeclareMathSizes{10.0001}{12}{10}{8}

Then we can write (but this is best in a command or environment):

\fontsize{10.0001}{\baselineskip}\selectfont

This is $x^2$ 

Now as for why this is all so weird, it comes down to the fact that math fonts and text fonts are treated distinctly in the underlying TeX engine. In text, it's enough to invoke a control sequence that loaded a font with \font, so in plain TeX, \fiverm selects cmr5 or in LaTeX \OT1/cmr/m/n/10 selects cmr10. But font selection in math mode is handled via families instead of the text font selection, which is why \mathbf{+} does not give a bold +. This parallel-universe font selection also applies to size changes which are restricted to the \displaystyle, \textstyle, \scriptstyle and \scriptscriptstyle commands. You really would need to read the relevant chapters of The TeXbook to get a full picture of how this works.


  1. For all the hyperrationality of Lamport's user interface in designing LaTeX, I curse that he followed Knuth's lead in randomly sprinkling @ in different places in private macro names. This is one of the biggest plusses of ExpL3 to me. Finally some Teutonic organization applied to the naming conventions.²

  2. Us older folks will remember the inscrutable names that were used in the Bitnet/EARN days for German and Austrian host names which, while they looked like a cat sat on the keyboard when it was time to pick a hostname were actually a mapping of key information about each host into the available 8 characters for a hostname.

  3. The variation in size here is miniscule, 0.001% which means that, for example, the amount of space that a lowercase m in cmr10 takes up will increase from 8.33336pt to 8.3334433336pt, a difference of about 5.5sp=.03μm so we're looking at molecular-scale dimensions here.

  4. Although this is moot with Computer Modern since NFSS will switch to cmr10 at 10pt anyway. In XeLaTeX and LuaLaTeX, though, since they're using lmr instead of cmr, they'll happily request a 10.0001pt font.

Related Question