[Tex/LaTex] 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?

Best Answer

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.


Text\par\hbox{Hello} World




Text\par\mbox{Hello} World


  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).

For further reading about \leavevmode please see "The TeXBook" by Donald E. Knuth, Appendix A, section 13.1, page 313 as well Appendix B, page 356.

Related Question