[Tex/LaTex] the difference between \relax and {}

macrostex-core

As I understand it, the point of \relax is to stop a macro from swallowing up subsequent material (such as whitespace). But {} (\bgroup\egroup) serves the same function. Why do we need both?

Best Answer

Try the following couple examples:

\documentclass{article}

\begin{document}

\[
\begin{array}{rl}
+9mm   & +9m^2 \\
[+9mm] & [+3m]^2 \\{}
+9mm   & +9m^2 \\{}
[+9mm] & [+3m]^2 \\\relax
+9mm   & +9m^2 \\\relax
[+9mm] & [+3m]^2
\end{array}
\]

\end{document}

enter image description here

  • If you leave there \\ alone, the [+9mm] is interpreted as an optional argument to \\ and transformed into a vertical space.
  • If you use {}, then it inserts an "empty thing" into the formula and the + is improperly spaced.
  • Only the variant with \relax works correctly here, because it really does nothing.

Very similar examples can be used to show that \relax is the correct terminator of \dimexpr and \numexpr expansion etc.