2

In reading Appendix B of the TeXBook, I've noticed that Knuth consistently defines macros in Plain TeX with style switches of the form $\displaystyle{#1}$ as opposed to simply $\displaystyle#1$ (e.g., in mathpalette, in macros for use with mathpalette, in the math alignment macros, and more). I can't see any difference between these two, but the consistent use of the longer form suggests to me that there is a difference, especially since with non-style switch control sequences, Knuth often does just \cseq#1 (where \cseq doesn't take any arguments). Is there any difference between these two forms?

EDIT: @Werner requested some examples. I've collected the following examples based just on pages 360 and 362 of the TeXBook:

  • In every branch of the \mathchoice in \mathpalette:
    \def\mathpalette#1#2{\mathchoice{#1\displaystyle{#2}}%
      {#1\textstyle{#2}}{#1\scriptstyle{#2}}{#1\scriptscriptstyle{#2}}}
    
  • With \scriptscriptstyle inside \root:
    \def\root#1\of{\setbox\rootbox
      \hbox{$\m@th\scriptscriptstyle{#1}$}\mathpalette\r@@t}
    
  • In \mathph@nt, which is intended for use with \mathpalette, so #1 is replaced by a style switch:
    \def\mathph@nt#1#2{\setbox\z@\hbox{$\m@th#1{#2}$}\finph@nt}
    
  • \mathsm@sh is similar to \mathph@nt.
  • Twice in the template row of \ialign in \eqalign (the second instance is a little more interesting):
    \def\eqalign#1{\null\,\vcenter{\openup\jot\m@th
      \ialign{\strut\hfil$\displaystyle{##}$&$\displaystyle{{}##}$\hfil
          \crcr#1\crcr}}\,}
    
  • \eqalignno and \leqalignno are similar to \eqalign.
  • \displaylines is almost a counterexample (but not quite due to the following \hfil), so perhaps it will help reveal something:
    \def\displaylines#1{\displ@y \tabskip\z@skip
      \halign{\hbox to\displaywidth{$\@lign\hfil\displaystyle##\hfil$}\crcr
        #1\crcr}}
    
RobertR
  • 379
  • This really depends on the context. For example, in math mode, there is a major difference between a+b and a{+}b. Also, there is sometimes a major difference in how \mymacro#1 is presented compared to \mymacro{#1}; take this as an example. – Werner Feb 18 '21 at 04:08
  • @Werner I should have been more specific. I tried to emphasize that there is nothing else surrounding the \displaystyle{#1} by explicitly writing the dollar signs. I know that {+} causes + to become a mathord, but I can't see how that matters if nothing is surrounding it. Also, when I wrote \mymacro, I was assuming \mymacro took no arguments, just like how \XXXstyle has no arguments. – RobertR Feb 18 '21 at 05:10
  • Well then, be more specific. Show where/how it is used in your TeXBook references so we can examine what the use-case might be. – Werner Feb 18 '21 at 05:35
  • @Werner I did reference a few examples in my original post, but I've edited my post to directly include some examples. – RobertR Feb 18 '21 at 06:04

2 Answers2

7

Compare $\displaystyle 1\over2$ with $\displaystyle{1\over2}$.

The macros which use \displaystyle{#1} allow to use \macro{1\over2} and this will print correctly.

wipet
  • 74,238
4

note that \displaystyle never takes an argument so the difference is between ${...}$ and $...$ \over as wipet says but also {...} acts like a box, it freezes all white space at its natural size and prevents line breaking.

enter image description here

Compare $\displaystyle 1 + 2$ with $\displaystyle{1 + 2}$ \break here
\bye

A comment on the \displaylines example you added in the question, it is not braced there probably to allow glue to stretch (as in the l=l and r=r lines below) but not bracing has a bad effect on \over as shown, unless you explicitly add braces to correct.

enter image description here


wipet: Compare $\displaystyle 1\over2$ with $\displaystyle{1\over2}$

\bigskip

displaylines $$\displaylines{ a=b\cr x=y\cr l=l\hfill\cr \hfill r=r\cr 1 \over 2 \cr {1 \over 2}\cr } $$

\bye

David Carlisle
  • 757,742
  • What you're saying here implicitly recognizes that LaTeX has defined \frac to replace \over, which in plain TeX does definitely require the braces although the reason is not that what is inside them is an argument. This is a very significant difference between plain and LaTeX, and deserves to be highlighted. (And probably documented better.) – barbara beeton Feb 18 '21 at 19:29
  • @barbarabeeton it doesn't require braces (although normally you need them as normally the fraction isn't the whole expression) , the case in the question $ 1 \over 2 $ works perfectly well without braces. You only need to add braces if you want to add \displaystyle as $\displaystyle 1 \over 2$ doesn't do what you want. – David Carlisle Feb 18 '21 at 19:56
  • Of course, ${1 \over 2} abc$ needs braces whether or not \displaystyle is used. Maybe the lack of understanding should be laid on the TeXbook for not saying why the braces are there. (Although I haven't gone back to check the TeXbook, and may be mistaken.) – barbara beeton Feb 18 '21 at 21:09
  • @barbarabeeton yes but I think you missed that this question is specifically asking why the macros brace the whole expression It is not asking about \over at all, really. – David Carlisle Feb 18 '21 at 21:46
  • No argument there. But I still think it's not well enough appreciated that input braces are rather overloaded, and the overloading gets more complicated as LaTeX progresses. – barbara beeton Feb 18 '21 at 23:31