# Mathtools package cramped command

Within the mathtools package, \cramped is defined as follows.

\providecommand*\cramped[1][\@empty]{
\ifx\@empty#1\@empty
\expandafter \mathpalette \expandafter \MT_cramped_internal:Nn
\else
\expandafter \MT_cramped_internal:Nn \expandafter #1
\fi
}
\def\MT_cramped_internal:Nn #1#2{
\sbox\z@{$\m@th#1\nulldelimiterspace=\z@\radical\z@{#2}$}
\ifx#1\displaystyle
\dimen@=\fontdimen8\textfont3
\else
\dimen@=1.25\fontdimen8
\ifx#1\textstyle\textfont
\else
\ifx#1\scriptstyle
\scriptfont
\else
\scriptscriptfont
\fi
\fi
3
\fi
\box\z@
}


Q1 After reading Appendix G of The TeXbook (Rule 18), why wouldn't the package simply do the following (locally within the math environment)?

\fontdimen13\textfont2=\fontdimen15\textfont2
\fontdimen14\textfont2=\fontdimen15\textfont2
\fontdimen13\scriptfont2=\fontdimen15\scriptfont2
\fontdimen14\scriptfont2=\fontdimen15\scriptfont2
\fontdimen13\scriptscriptfont2=\fontdimen15\scriptscriptfont2
\fontdimen14\scriptscriptfont2=\fontdimen15\scriptscriptfont2


Q2 I omit here the code to make it local because I'm not sure how to do it but surely it's doable(?) Does anyone know how to do it locally?

• I think the issue is precisely with the "locally". \fontdimen assignments are always global. Feb 26, 2021 at 8:37

From the TeXbook, page 277:

In all of the following cases, the presence or absence of \global as a prefix has no effect.

⟨global assignment⟩ → ⟨font assignment⟩
| ⟨hyphenation assignment⟩
| ⟨box size assignment⟩
| ⟨interaction mode assignment⟩
| ⟨intimate assignment⟩
⟨font assignment⟩ → \fontdimen⟨number⟩⟨font⟩⟨equals⟩⟨dimen⟩
| \hyphenchar⟨font⟩⟨equals⟩⟨number⟩
| \skewchar⟨font⟩⟨equals⟩⟨number⟩
⟨hyphenation assignment⟩ → \hyphenation⟨general text⟩
| \patterns⟨general text⟩
⟨box size assignment⟩ → ⟨box dimension⟩⟨8-bit number⟩⟨equals⟩⟨dimen⟩
⟨interaction mode assignment⟩ → \errorstopmode | \scrollmode
| \nonstopmode | \batchmode
⟨intimate assignment⟩ → ⟨special integer⟩⟨equals⟩⟨number⟩
| ⟨special dimen⟩⟨equals⟩⟨dimen⟩

The case you're interested in is

⟨font assignment⟩ → \fontdimen⟨number⟩⟨font⟩⟨equals⟩⟨dimen⟩

and you see that such assignment is global independently of adding \global in front of \fontdimen.

You might think to do the setting and undo it after processing, but this doesn't work, because the \fontdimen parameter are only examined when math mode ends and the math list is converted to a horizontal list. The only way would be to add a boxing level, starting math mode inside it (don't forget to use \mathchoice), doing the setting of the parameters, process the subformula, end math mode, undo the settings and finish the box.