LaTexLearner wrote:
- I still don't understand that the @ symbol has been specified as a letter, but I still don't see the purpose of using the @ symbol as opposed to, say, a capital Z or A or hyphen or something like that.
- What does
\mathpalette
do? I Googled that one but the answers were way over my head.
It is a widely used practice to distinguish between “document commands”, i.e., macros for usage after
\begin{document}
and internal commands that better are not accessed directly. To make it harder to use internal macros the usual use it to put a
@
in the name somewhere. If you look at the code of packages or in the LaTeX kernel you will see this a lot. (For understanding how this works the understanding of TeX's
category codes is necessary, though)
The macro
\mathpalette
is defined like this:
Code: Select all
\newcommand*\mathpalette[2]{%
\mathchoice
{#1\displaystyle{#2}}%
{#1\textstyle{#2}}%
{#1\scriptstyle{#2}}%
{#1\scriptscriptstyle{#2}}}
So if we have
Code: Select all
\newcommand*\foo[1]{\mathpalette\@foo{#1}}
\newcommand*\@foo[2]{\mbox{$#1#2$}}
and use it like this:
we get
and then
Code: Select all
\mathchoice
{\@foo\displaystyle{bla bla}}
{\@foo\textstyle{bla bla}}
{\@foo\scriptstyle{bla bla}}
{\@foo\scriptscriptstyle{bla bla}}
The macro
\mathchoice
detects which of TeX's math modes (display, text, script or scriptscript) is active and either places its first, second, third or forth argument in the stream. (It is a little more complicated here but we can ignore that.) So if
\foo{bla bla}
is placed in displaystyle (an
{equation}
, say) the first argument
\@foo\displaystyle{bla bla}
is inserted. We then end up with
this ensures that inside the math of
\@foo
we always get the suiting font size for the current math surrounding.
Quintessence: the surrounding macro
\foo
works like the user expects it to even if it is a superscript
$x^{\foo{bla}}$