# 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?

• It's simply \par. What you're asking in the final paragraph doesn't make sense: in horizontal mode you make paragraphs. – egreg Mar 30 '15 at 8:49
• Thanks @egreg - but wouldn't \par insert a new line/line break as well? – sdaau Mar 30 '15 at 8:51

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

\def\par{}
x\vskip1pt


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.

• Many thanks @egreg - you nailed it, both with "You can't “leave” this mode in other ways than ending the paragraph" and with "You're probably misled by the name of the \leavevmode command ..."; that was indeed the core of my confusion. Moved the accept here; thanks again - cheers! – sdaau Mar 30 '15 at 9:19

If you want to end the current horizontal list and enter vertical mode the command is the (primitive) \par.

If you want to start a nested vertical list that will be added to the current horizontal list when completed the command is \vbox{...}.

• "inserting a new line" is a general english language description for a specific technical Tex behaviour which (as far as I can guess) is "end horizontal mode". – David Carlisle Mar 30 '15 at 8:53
• @sdaau I can't even guess what you would want the behaviour of that to be. Where would you want the vertical material to go if you did not put it after (ie below) the horizontal material you had just left? – David Carlisle Mar 30 '15 at 8:59
• Well, the thing is - I want to insert a tikzpicture which shouldn't take up any space (remember picture, overlay) inside a \titleformat*, tex.stackexchange.com/questions/235818/…, but the tikzpicture does a \leavevmode anyways, which subsequently breaks my approach. I myself cannot imagine what's going on in this context either - I just know somewhat correct rendering is shown if I keep going after all the "Entered in horizontal mode" errors - so I'd like to get rid of these errors :) – sdaau Mar 30 '15 at 9:05
• In other words, if there was a TeX "cursor" that changes its x/y position as boxes are added, I'd like a command that doesn't change the cursor position, only the horizontal mode as detected by \ifhmode... – sdaau Mar 30 '15 at 9:07
• @sdaau That is \vbox then. But also (depending what you mean) it could be \par \par just ends the current horizontal mode, that causes the paragraph to be broken into lines and added to the current vertical list, it doesn't cause any additional vertical space to be added (\parskip glue will be added by a following horizontal command that triggers a new horizontal list) – David Carlisle Mar 30 '15 at 9:09