Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Jul 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
    
6  
@Martin: We already have mathmode. So introducing vertical-mode and horizontal-mode might make sense. –  Caramdir Jul 12 '11 at 16:07
add comment

1 Answer

up vote 42 down vote accepted

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

share|improve this answer
    
Thanks a lot. That helps. –  Jason Xu Jul 14 '11 at 16:20
3  
+1 Your last sentence is particularly enlightening. –  doncherry Feb 19 '12 at 21:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.