2

MWE:

\documentclass{scrbook}

\begin{document}

\makeatletter
\show\@textsuperscript
\show\sf@size
\makeatother

A\textsuperscript {B}C

A{\selectfont{${^{\mbox{\fontsize\sf@size\z@ B}}}$}}C

\end{document}

The log shows:

#1->{\m@th \ensuremath {^{\mbox {\fontsize \sf@size \z@ #1}}}}.
l.6 \show\@textsuperscript

> \sf@size=undefined.
l.7 \show\sf@size

How would I perform the \textsuperscript macro in the raw, without invoking the macro? Trying to learn some TeX!


UPDATE: Thanks to answer from Kruger, this works as expected.

Now, the question is why the raw invocation shows a bigger font size for the superscript compared to \textsuperscript?

UPDATE: Thanks to answer from Kruger, all complete!

It's been a fascinating rabbit hole!

Final answer: \ensuremath sets sf@size. Details in accepted answer.

A\textsuperscript {B}C

\makeatletter
A$\ensuremath{^{\mbox{\fontsize\sf@size\z@ {\selectfont B}}}}$C
\makeatother
3
  • To ask a follow up question, you should create a new question instead of editing the existing one. Otherwise the existing answers often no longer make sense and the edit does not receive a lot of attention. Apr 24, 2018 at 7:20
  • Please edit your question into a question (and such that the accepted answer makes sense as an answer to the question), not as something that starts with an answer. (I've done part of this for you—put the updates at the bottom—but consider whether the updates may be better as an answer, or removed, or left in the question.) Apr 25, 2018 at 1:39
  • 1
    The final code is a complicated version of A$^{\mbox{\fontsize\sf@size\z@\selectfont B}}$C. And no, \ensuremath does not set \sf@size as part of its job; it's a side effect of doing a math formula.
    – egreg
    Apr 25, 2018 at 7:53

1 Answer 1

5

\sf@size is the fontsize for the script math fonts. It depends on the current regular text fontsize, so it has to be recalculated for every block of math. This is done with \everymath: If you add \show\frozen@everymath to your document, you see that \frozen@everymath is set to \check@mathfonts \the \everymath. This means that everytime you enter inline math, TeX executes \check@mathfonts first. This macro sets \sf@size and does some other stuff. This also happens when \ensuremath enters math mode, which is the case for your \textsuperscript example.

So to \show \sf@size, it has to be set first by writing $ $ to enter (and leave) mathmode somewhere before \show\sf@size.

By the way, if you want to understand how the LaTeX commands are implemented, look at source2e. Apart from not having to \show all the macros separately you also see a lot of comments describing the functionality there.

To perform this without invoking the macro, you need two changes: First \makeatletter is required to allow using \sf@size (and \z@) in a document. Then you still get the wrong fontsize. This is because \fontsize does only set the next fontsize, but does not actually change the font. So \selectfont has to be invoked to select the font in the right size after \fontsize\sf@size\z@. In the macro, the call to \selectfont is inside \textsuperscript (without the @). In source2e the documentation of \@textsuperscript even contains a note that the argument should always start with a font selection command,

6
  • Kruger . How did u know that \sf@size is for script math fonts? What sorcery? Teach me? Is it found at source2e?
    – user152148
    Apr 24, 2018 at 6:17
  • Kruger. I managed to somewhat mimic the macro in raw TeX. However, the font size is different? Any clues?
    – user152148
    Apr 24, 2018 at 6:58
  • If you search for \sf@size in source2e, you can find it in \getanddefine@fonts where it is used to select the \scriptfont. The TeXbook explains that \scriptfont selects the font for the math script style. Apr 24, 2018 at 7:09
  • @Kruger . Thanks for your additional answer. Gosh, I missed that fact (too many brackets in LaTeX!). I would've created a separate question for you, but didn't think StackOverflow allows "really dumb questions resulting from unnecessary human error".
    – user152148
    Apr 25, 2018 at 0:56
  • @Kruger Can u pls answer this question? tex.stackexchange.com/questions/428395/…
    – user152148
    Apr 25, 2018 at 2:27

You must log in to answer this question.