TeX ignores spaces after control sequences (formed by letters) *and* performs complete expansion when doing a `\write`

.

The tokens it sees when you do `\writefile{\Insert stuff.}`

are (separated by • just for clarity)

```
\Insert•s•t•u•f•f•.
```

and there's *no* space. The expansion gives

```
Insertstuff
```

When you put a pair of braces, the space after them is not ignored (it doesn't follow a control sequence):

```
\Insert•{•}• •s•t•u•f•f•.
```

With `\Insert\ stuff`

it's the same: the token "control space" is unexpandable, so you get

```
Insert\ stuff.
```

With `\Insert~stuff`

you lose: the complete expansion of `~`

is not what you'd expect: it's the set of instructions necessary to "print a non breaking space". Indeed LaTeX has `\protected@write`

to cope with this kind of commands that should not be expanded during a write.

As zeroth explained, the expansion of `\space`

is a space; but it's *not* ignored after `\Insert`

, because when TeX is reading tokens it doesn't yet see the expansion of `\space`

, but that token (which undoubtedly isn't a space token).

Calling these spacing commands is a bit misleading they are all commands to set boxes of specified dimensions.

`\rlap`

, `\llap`

`\clap`

are essentially `\makebox[0pt][r]`

, `\makebox[0pt][l]`

and `\makebox[0pt][c]`

except they can avoid the complication of looking for optional arguments etc. Also they differ in the way that `\hbox`

differs from `\mbox`

in that following the plain TeX rather than LaTeX tradition they lack a `\leavevmode`

at the start of their definition so they do not start a paragraph if used in vertical mode.

In text mode `\smash`

is in the same way essentially `\raisebox{0pt}[0pt][0pt]`

In text mode, the phantom commands are all equivalent to using an empty box with dimensions given by another box, so `\phantom`

is essentially

```
\def\Phantom#1{\savebox{0}{#1}\savebox{2}{}%
\ht2=\ht0 \dp2=\dp0 \wd2=\wd0
\usebox{2}}
```

`\vphantom`

is the same except that the width is forced to `0pt`

rather than the original width of the text in the first box.

The math mode versions are all essentially the same except for two complications, math mode has to be re-entered inside the box, and a `\mathchoice`

construct has to be used so they work correctly at display and script sizes. `\phantom`

and `\smash`

have built in math mode tests and then switch between the text and math definitions automatically. For `\rlap`

(just for historical reasons) it is text mode only, so for math mode you need to switch batc to math explictly or use `\mathrlap`

from a suitable package.

Note that in `\mathmode`

always makes a `mathord`

atom which gets no special spacing. In the examples in the question you compared the spacing of `-`

with the mathord spacing and the mahtop spacing but `-`

is a mathbin atom so you need `\mathbin{\phantom{-}}`

```
\documentclass{article}
\usepackage{amsmath,amssymb}
\pagestyle{empty}
\begin{document}
\begin{align*}
y &= x - z\raisebox{0ex}[0pt][0pt]{\rule[-4ex]{0.1pt}{4ex}} \\
&= x \mathbin{\phantom{-}} z\raisebox{0ex}[0pt][0pt]{\rule{0.1pt}{4ex}} \\
&= x \mathbin{\phantom{ - }} z \\
\end{align*}
\hspace*{\fill}Or even worse:\hspace*{\fill}
\begin{align*}
y &= x - z\raisebox{0ex}[0pt][0pt]{\rule[-4ex]{0.1pt}{4ex}} \\
&\phantom{{}= x -{}} z\raisebox{0ex}[0pt][0pt]{\rule{0.1pt}{4ex}} \\
\end{align*}
\end{document}
```

Even then spacing of subscripts may be different

```
\phantom{P}_x
```

is like

```
{P{}}_x
```

in which the subscript is not the same as

```
P_x
```

It's pretty hard to avoid that as the boxing implied by phantom obscures the kerning information in the font metrics, but fortunately it is rare to want a visible subscript on an invisible base.

## Best Answer

In the final part of the first row, try

`\phantom{a+{}}b+c`

to make the first plus sign act like a "real" math-binary element. Similarly, you'll also need to adjust the second row to`a\phantom{{}+b}+c`

.