What does \relax do? [duplicate]

The title suggest the question. On and off, I see macros here in TeX.SE and I see the \relax command frequently.

1. I was wondering what it does and where/when should I used it?
2. Are there any precautions that I should take while using it? (Are there side-effects?)

It would be great if you support your answers with a simple example.

marked as duplicate by Martin Schröder, barbara beeton, Mensch, Stefan Kottwitz♦Feb 2 '13 at 20:56

• Short answer: it does nothing, but is not expandable. – egreg Feb 2 '13 at 18:59
• It's often used after some "fragile" commands and in \if constructions. – Eddy_Em Feb 2 '13 at 19:01
• What you often see on this site, is to make TeX stop collecting for an argument of specific type (very very roughly speaking). Suppose your macro is looking for some number in the argument \mymacro12345\relax 678 would make it stop at five and then do whatever else it's supposed to do. There are many more usecases but that's pretty much the main reason of its appearance in the answers here. – percusse Feb 2 '13 at 19:05
• – David Carlisle Feb 2 '13 at 19:08

Although \relax does nothing by itself, it is a safe command to stop expansion of another command. Some examples:

• (plain tex) \hskip 5pt\relax -- in the absence of \relax, the \hskip will keep looking for plus or minus

• (latex) at the end of a line, \\ \relax [...] will prevent what is in brackets from being interpreted as a dimension that would add vertical space

(actually, this is pretty well explained by answers to this question.)

• @Τίμων Of course your suggested edit of the capitalization is technically correct, but in this special case, the missing capitalization actually carries information, see e.g. tug.org/interviews/beeton.html, so an edit would change the meaning of the answer. – user36296 Aug 8 '16 at 13:51

It is what's called a no-op: It does nothing, and it's used in various places where you don't want anything done, but the syntax requires something. TeX's rules also dictate that in an \if statement, an undefined macro will compare equal to \relax. So it's sort of a general-purpose nothing.

(The empty brace group {} is another kind of nothing, as the question linked to by David Carlisle illustrates).