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

    \expandafter \mathpalette \expandafter \MT_cramped_internal:Nn
    \expandafter \MT_cramped_internal:Nn \expandafter #1
\def\MT_cramped_internal:Nn #1#2{
      \advance\dimen@ .25\fontdimen5\textfont2
    \advance\dimen@-\ht\z@ \ht\z@=-\dimen@

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


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?

  • 2
    I think the issue is precisely with the "locally". \fontdimen assignments are always global. – campa Feb 26 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.

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.