13

Which way is more correct? I don't see any differences, but maybe I something missed?

  • Welcome to TeX.SX! There is no difference between the two versions, for readability of the code, $x y = 1$ is better, however. If you want to some space, use \, or \; where desired, but this is a matter of taste – user31729 Nov 25 '14 at 6:24
20

There is no difference. Let's look at how the output is constructed by adding \showoutput and checking the .log when compiling the following minimal example:

\documentclass{article}
\pagestyle{empty}% To avoid page numbers in the output
\showoutput% Show how the output is constructed
\begin{document}
$xy=1$

$x y = 1$
\end{document}

This is extracted from the .log:

Completed box being shipped out [1]
\vbox(633.0+0.0)x407.0
.\glue 16.0
.\vbox(617.0+0.0)x345.0, shifted 62.0
..\vbox(12.0+0.0)x345.0, glue set 12.0fil
...\glue 0.0 plus 1.0fil
...\hbox(0.0+0.0)x345.0
..\glue 25.0
..\glue(\lineskip) 0.0
..\vbox(550.0+0.0)x345.0, glue set 525.99937fil
...\write-{}
...\glue(\topskip) 3.55556
...\hbox(6.44444+1.94444)x345.0, glue set 300.6899fil
....\hbox(0.0+0.0)x15.0
....\mathon                                       <---------------- mathon
....\OML/cmm/m/it/10 x
....\OML/cmm/m/it/10 y
....\kern0.35878
....\glue(\thickmuskip) 2.77771 plus 2.77771
....\OT1/cmr/m/n/10 =
....\penalty 500
....\glue(\thickmuskip) 2.77771 plus 2.77771
....\OT1/cmr/m/n/10 1
....\mathoff                                      <---------------- mathoff
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
...\glue(\parskip) 0.0 plus 1.0
...\glue(\baselineskip) 3.61111
...\hbox(6.44444+1.94444)x345.0, glue set 300.6899fil
....\hbox(0.0+0.0)x15.0
....\mathon                                       <---------------- mathon
....\OML/cmm/m/it/10 x
....\OML/cmm/m/it/10 y
....\kern0.35878
....\glue(\thickmuskip) 2.77771 plus 2.77771
....\OT1/cmr/m/n/10 =
....\penalty 500
....\glue(\thickmuskip) 2.77771 plus 2.77771
....\OT1/cmr/m/n/10 1
....\mathoff                                      <---------------- mathoff
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
...\glue 0.0 plus 1.0fil
...\glue 0.0
...\glue 0.0 plus 0.0001fil
..\glue(\baselineskip) 30.0
..\hbox(0.0+0.0)x345.0

I've highlighted the important bits above starting with the call mathon (called with the processing of the first $) and ending with mathoff (called with the processing of the final $):

....\mathon                                       <---------------- mathon
....\OML/cmm/m/it/10 x
....\OML/cmm/m/it/10 y
....\kern0.35878
....\glue(\thickmuskip) 2.77771 plus 2.77771
....\OT1/cmr/m/n/10 =
....\penalty 500
....\glue(\thickmuskip) 2.77771 plus 2.77771
....\OT1/cmr/m/n/10 1
....\mathoff                                      <---------------- mathoff

Both instances are exactly the same, implying the output is exactly the same. Knuth also mentions this in the TeXbook (Chapter 16: Typing Math Formulas, p 127):

Formulas that have been typeset by a printer who is unaccustomed to mathematics usually look quite strange to a mathematician, because a novice printer usually gets the spacing all wrong. In order to alleviate this problem, TeX does most of its own spacing in math formulas; and it ignores any spaces that you yourself put between $'s. For example, if you type $ x$ and $ 2 $, they will mean the same thing as $x$ and $2$. You can type (x + y)/(x - y) or (x+y) / (x-y), but both will result in $(x+y)/(x-y)$, a formula in which there is a bit of extra space surrounding the + and - signs but none around the `/ sign. Thus, you do not have to memorize the complicated rules of math spacing, and you are free to use blank spaces in any way you like.

Which is best? Make your code readable, so use spaces where necessary.

14

There is no difference between $xy=1$ and $x y = 1$ or $ x y = 1 $. They are rendered the same exactly:

xy = 1

The spacing depends on the classification into math atoms:

$
\mathord{x}
\mathord{y}
\mathrel{=}
\mathord{1}
$

Spacing:

  • There is not spacing at the begin or end of the formula except for \mathsurround, which is usually 0 pt.

  • No space between ordinary math atoms (\mathord).

  • But as space of \muskip\thickmuskip = \; is inserted between ordinary and relational (\mathrel) atoms.

The following example shows the inserted spaces:

% plain TeX or LaTeX
\showboxdepth=\maxdimen
\showboxbreadth=\maxdimen
\tracingonline=1
\nonstopmode

\setbox0=\hbox{$x y = 1$}
\showbox0

\csname @@end\endcsname\end % end job for plain TeX and LaTeX

The result on the console:

> \box0=
\hbox(6.44444+1.94444)x29.3101
.\mathon
.\teni x
.\teni y
.\kern0.35878
.\glue(\thickmuskip) 2.77771 plus 2.77771
.\tenrm =
.\glue(\thickmuskip) 2.77771 plus 2.77771
.\tenrm 1
.\mathoff
  • Thank you! Unfortunately I can set both your and Werner's anwsers as solved, but it helps alot! – yarpoplar Nov 25 '14 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.