# Function and usage of \leavevmode

I am beginner of LaTeX. From many examples I found, I notice that it's very common to use command \leavevmode. I can't find any information about this command. Could anyone tell me what's the function of it and how to use it?

-

## migrated from stackoverflow.comJul 12 '11 at 10:42

This question came from our site for professional and enthusiast programmers.

@all: Do we need a tag for the different modes of TeX? – Martin Scharrer Jul 12 '11 at 10:56
– Martin Scharrer Jul 12 '11 at 10:58
@Martin: We already have mathmode. So introducing vertical-mode and horizontal-mode might make sense. – Caramdir Jul 12 '11 at 16:07

The \leavevmode is defined by LaTeX and plainTeX and ensures that the vertical mode is ended and horizontal mode is entered. In vertical mode, TeX stacks horizontal boxes vertically, whereas in horizontal mode, they are taken as part of the text line.

For example \mbox{..} is defined as \leavevmode\hbox{..} to ensure that horizontal mode is entered if it is used at the beginning of a paragraph. If you only use \hbox{ } it is stacked above the following paragraph instead.

Compare:

Text\par\hbox{Hello} World


Result:

  Text
Hello
World


with:

Text\par\mbox{Hello} World


Result:

  Text
Hello World


You see that in the first case the \hbox is stacked with the two paragraphs vertically (but without paragraph indention) because it is processed in vertical mode. In the second case horizontal mode is entered first and so Hello is processed as part of the second paragraph.

Use \leavevmode for all macros which could be used at the begin of the paragraph and add horizontal boxes by themselves (e.g. in form of text).

-
Thanks a lot. That helps. – Jason Xu Jul 14 '11 at 16:20
+1 Your last sentence is particularly enlightening. – doncherry Feb 19 '12 at 21:41