5

I believed that \prime is the appropriate code to insert a prime in math mode and assumed that it would be equivalent to type '. I find that \prime inserts an ugly, large prime, whereas the ' produces something ok. Is there an explanation?

\documentclass{article}

\begin{document}

$a'_{i}$ dürfen zu $x'_{i}$ nur

$a\prime_{i}$ dürfen zu $x\prime_{i}$ nur

\end{document}

enter image description here

4
  • 4
    $a'_{i}$ is actually $a^{\prime}_{i}$
    – moewe
    Commented Apr 13, 2020 at 16:38
  • 5
    you should almost never use \prime just use ' Commented Apr 13, 2020 at 16:40
  • 3
    See also tex.stackexchange.com/q/87134/35864
    – moewe
    Commented Apr 13, 2020 at 16:41
  • 1
    I've taken the liberty of inserting a larger screenshot of your code.
    – Mico
    Commented Apr 13, 2020 at 17:38

1 Answer 1

8

You wrote,

I find that \prime inserts an ugly, large prime, whereas the ' produces something ok. Is there an explanation?

To address this question in depth, it's useful to check how ' (in math mode) is defined relative to \prime. Here's an excerpt from the current version (2020-02-02, patch level 5) of the LaTeX2e "kernel" -- lines 5939 to 5954 from latex.ltx, to be exact -- that provides the code that defines ' in LaTeX. (The Plain-TeX definition of ' is similar.)

\def\active@math@prime{^\bgroup\prim@s}
{\catcode`\'=\active \global\let'\active@math@prime}
\def\prim@s{%
  \prime\futurelet\@let@token\pr@m@s}
\def\pr@m@s{%
  \ifx'\@let@token
    \expandafter\pr@@@s
  \else
    \ifx^\@let@token
      \expandafter\expandafter\expandafter\pr@@@t
    \else
      \egroup
    \fi
  \fi}
\def\pr@@@s#1{\prim@s}
\def\pr@@@t#1#2{#2\egroup}

I won't claim that this code is easy to grasp. Here's the gist of what's going on.

  • The instruction

    \catcode`\'=\active
    

    makes the character ' ("apostrophe" or "prime") active, in the TeX sense of the word, if the character is encountered in math mode.

  • The character is let to \active@math@prime, which is defined as ^\bgroup\prim@s. Note the initiation of an exponent term via ^, followed by \bgroup -- as well as the absence, for now, of a corresponding \egroup directive.

  • \prim@s, in turn, is defined as \prime\futurelet\@let@token\pr@m@s. Finally, we encounter \prime -- yay! The \prime directive -- recall that it is executed in superscript mode, so the resulting symbol is smaller than the text-style version of \prime -- is followed by

    \futurelet\@let@token\pr@m@s
    

    \futurelet\@let@token assigns the next token to \@let@token. So, what does \pr@m@s do?

  • The code for \pr@m@s covers 10 lines of code; it is by far the most complicated of the macros in this bunch. It basically tells LaTeX to compare the look-ahead token (via a couple of \ifx statements) to a number of possible alternatives. In fact, the code considers three alternatives.

    • If the look-ahead token is not equal to either ' or ^, then \egroup is issued -- meaning that the exponent term group is closed and can be processed by LaTeX -- and we're done. Whew!

    • If the next character is equal to ^ (as in, say, g'^2), code needed to handle the exponent term, including an \egroup directive, is executed. (In case you're curious: g'^2 evaluates to g^{\prime2}. If you'd rather have the square term placed a bit further up, you will need to write {g'}^2.)

    • Finally, if the next character is equal to ', then (after some more stirring of the pot...) another round of \prime\futurelet\@let@token\pr@m@s is executed, i.e., another \prime directive is executed followed by some more looking ahead.

Remembering that \bgroup and \egroup evaluate to { and }, respectively, we come to the following conclusion: the code assures that u'v gets interpreted as u^{\prime}v, w''x gets interpreted as w^{\prime\prime}x, f''' gets interpreted as f^{\prime\prime\prime}, etc. What's really important is to notice that w''x it NOT interpreted as w^{\prime}^{\prime}x, as that would trigger a dreaded "Double superscript" error.

In short, (a) typing f\prime\prime does not trigger an error message but is most definitely incorrect from a typographic perspective; (b) f^{\prime\prime} is both typographically and syntactically correct but also exceedingly tedious; (c) f'' is both correct and easy. Can you guess which method is recommended? For what it's worth, my impression is that Donald Knuth intended users to input f' and f'' all along.

5
  • 1
    One further consideration, regarding the size of the bare \prime. Occasionally, not very often, a prime is used as a subscript. By providing a "text-size" prime shape, it can be used very easily as either a superscript or subscript in the expected size. And yes, I am sure that Knuth intended users to input f' and f'' -- after all, he and his secretary were the first users, entering the text for The Art of Computer Programming, where it would both streamline entry and yield a nicely readable file. Commented Apr 13, 2020 at 22:23
  • In ConTeXt (and maybe in the LaTeX Unicode engines) the input f' actually becomes 𝑓′ with U+1D453 MATHEMATICAL ITALIC SMALL F and U+2032 PRIME. Commented Apr 13, 2020 at 23:11
  • 1
    @HenriMenke - Thanks. To those of us :-) not as familiar with the difference between the "ordinary" math-italic lowercase letter "f" and U+1D453 MATHEMATICAL ITALIC SMALL F, could you say a word (or maybe post a separate answer) on this subject? I'm sure quite a few people (me included!) would find this very interesting.
    – Mico
    Commented Apr 14, 2020 at 1:16
  • @barbarabeeton - Many thanks for offering this historically very valuable first-hand reflection.
    – Mico
    Commented Apr 14, 2020 at 1:18
  • 1
    Now I (mostly) understand what is going on. I did not expect that much complication and the answer is overwhelming, but clear enough documented to be understandable! Again, thank you very much!
    – user855443
    Commented Apr 15, 2020 at 8:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .