I'd like to implement sizing functions like \Huge
in a way that makes them work in math mode as well. Essentially I want to create a command myHuge
which maps {foo \myHuge bar}
to {foo \mbox{\Huge $bar$}}
so that the sizing command is in text mode while everything else still is in math mode.
The problem here is that for the sake of consistency I want to use the same syntax used for text mode sizing commands, i.e. apply the command to everything up to the end of the current group. This answer gave me an idea of how to achieve this using \afterassignment
in combination with assignment to a tokens register. But for some reason, this doesn't work well with \frac
:
\documentclass[10pt]{article}
\usepackage{amsmath}
\newtoks\myToks
\def\myHuge{\afterassignment\myHugeDo\myToks=\bgroup\Huge$}
\def\myHugeDo{\bgroup\mbox{\the\myToks$\egroup}\egroup}
\begin{document}
This works: $a + {b \myHuge c} + d$ \\
This does not: $\frac{\myHuge x}{y}$ \\
This however does: $\frac{{\myHuge x}}{y}$
\end{document}
I had even included the outer level of \bgroup…\egroup
in the definition of \myHugeDo
in an attempt to make the second example behave like the third, but apparently that's not where the problem lies. Using {…}
instead doesn't improve things. The message I get is this:
! Missing $ inserted.
<inserted text>
$
l.9 This does not: $\frac{\myHuge x}{y}
$ \\
! Missing } inserted.
<inserted text>
}
l.9 This does not: $\frac{\myHuge x}{y}
$ \\
! Missing } inserted.
<inserted text>
}
l.9 This does not: $\frac{\myHuge x}{y}
$ \\
! Missing } inserted.
<inserted text>
}
l.9 This does not: $\frac{\myHuge x}{y}
$ \\
! Too many }'s.
<argument> \the \myToks $\egroup
l.9 This does not: $\frac{\myHuge x}{y}
$ \\
! Too many }'s.
\mbox #1->\leavevmode \hbox {#1}
l.9 This does not: $\frac{\myHuge x}{y}
$ \\
! Too many }'s.
\myHugeDo ...mbox {\the \myToks $\egroup }\egroup
l.9 This does not: $\frac{\myHuge x}{y}
$ \\
! Missing $ inserted.
<inserted text>
$
l.10 This however does: $\frac{{\myHuge x}}{y}
$
! Extra }, or forgotten $.
\frac #1#2->{\begingroup #1\endgroup \@@over #2}
l.10 This however does: $\frac{{\myHuge x}}{y}
$
[1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./t.aux) )
(\end occurred inside a group at level 1)
### simple group (level 1) entered at line 10 ({)
### bottom level
How can I fix this? Is there a different approach I should consider?
{<font switch>...}
in math mode (it used to, but things changed with LaTeX2e, issued more than 20 years ago).{foo \scriptstyle bar}
, which has a very similar visual effect as a font size switch.\scriptstyle
performs a very different action than a font switching command.