2

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
      \advance\dimen@ .25\fontdimen5\textfont2
    \else
      \dimen@=1.25\fontdimen8
      \ifx#1\textstyle\textfont
      \else
        \ifx#1\scriptstyle
          \scriptfont
        \else
          \scriptscriptfont
        \fi
      \fi
      3
    \fi
    \advance\dimen@-\ht\z@ \ht\z@=-\dimen@
    \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?

1
  • 2
    I think the issue is precisely with the "locally". \fontdimen assignments are always global. – campa Feb 26 at 8:37
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.