[Tex/LaTex] Difference between \mskip and \mkern

comparisonmath-modespacingtex-core

What are the differences between \mskip and \mkern? The TeXbook writes the following (ch. 18):

You can insert math glue into any formula just by giving the command
\mskip⟨muglue⟩’. […] Similarly, you can use the command ‘\mkern’ when there is no stretching or shrinking; […]. TeX insists that \mskip and \mkern be used only with mu; conversely, \hskip and \kern (which are also allowed in formulas) must never give units in mu.

Is there anything else to know? Are there standard practices or minor syntactic usage differences to be aware of? For example, \thickmuskip is defined as 5mu plus 5mu, but \(X X \mkern\thickmuskip X X\) (as opposed to \(X X \mskip\thickmuskip X X\)) compiles just fine, so it seems like \mkern disables stretching or shrinking but doesn't forbid such expressions for its argument.

Best Answer

I quote from TeX By Topic, which is freely available via texdoc texbytopic:

The \kern command specifies a kern item in whatever mode TeX is currently in. A kern item is much like a glue item without stretch or shrink. It differs from glue in that it is in general not a legal breakpoint. Thus in

.. text .. \hbox{a}\kern0pt\hbox{b}

TeX will not break lines in between the boxes; in

.. text .. \hbox{a}\hskip0pt\hbox{b}

a line can be broken in between the boxes. However, if a kern is followed by glue, TEX can break at the kern (provided that it is not in math mode). In horizontal mode both the kern and the glue then disappear in the break.

The only difference between glue and kerns, aside from stretchability, is whether or not a line or page can break at them. This is equally true in math mode, which can also be broken across lines and pages (though with far fewer legal breakpoints).

Thus, the correct use of \kern or \mkern is to "move the cursor", as for placing symbols on top of each other, eliminating an unwanted space when piecing together a big and notionally unified object from smaller ones, or (dually) creating a space between two objects that ought to appear together anyway.

Again, this has nothing to do with math mode, except that \mkern must be given its argument in mu units, just like \mskip.