[Tex/LaTex] How to leave horizontal mode


There is this question: How do I leave horizontal mode? – but there is no answer no how to leave horizontal mode.

I know there is a command \leavevmode (Function and usage of \leavevmode); the post What are vertical and horizontal modes? points to its definition:

Plain, LaTeX and pdfTeX have built-in macros to make easier to switch from one mode to another such as \leavevmode, which is simply a void box that is opened:

\protected\def\leavevmode{\unhbox \voidb@x}

Ok, but there is no \leavehmode command ?

So what command can I use to leave horizontal mode, and re-enter vertical mode – without artifacts as say new lines, or insertion of additional horizontal or vertical spaces?

Best Answer

You seem to be misunderstanding what vertical and horizontal modes are.

First of all, let me consider the relationship between vertical and horizontal mode. TeX always starts off in vertical mode.

Under certain circumstances (precisely when it sees a horizontal command), TeX leaves vertical mode and starts horizontal mode in order to make paragraphs. You can't “leave” this mode in other ways than ending the paragraph.

You're probably misled by the name of the \leavevmode command, which could have been named something like \StartMakingAParagraphIfItMakesSense; the command does \unhbox\v@idbox and \unhbox is a horizontal command, so

  • (unrestricted) horizontal mode is started if TeX was in vertical mode,
  • nothing happens if TeX is in horizontal mode or in math mode.

The only way to end unrestricted horizontal mode is by issuing (explicitly or implicitly) a primitive \par command. Every vertical command, if found when TeX is in unrestricted horizontal mode, issues a \par token.

Note that \par might not mean the primitive \par, but the redefined \par should at some point execute the primitive \par or strange things will happen: the simple


will start an infinite loop, for example, because \vskip will continue to issue \par in order to be executed in the vertical mode that's never reached.

You can start vertical mode when in horizontal mode by opening a \vbox or \vtop, but the resulting list will eventually be appended to the horizontal list being built, so this doesn't seem what you're looking for.

There is an escape to the surrounding vertical mode: if TeX finds \vadjust{...} in (unrestricted) horizontal mode, it will package the vertical list given as argument, and this list will be inserted between the line where the command happens to be and the next one, after the paragraph has been formed. Such a vertical list will be appended before the interline glue. So

abc\vadjust{\vskip3pt} text text ... text

will have 3pt of additional vertical space between the first and second lines of the paragraph.

There is no symmetry between vertical mode and horizontal mode, because they do very different things.