TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a command that creates a margin paragraph. This requires that this command is only used in vertical mode, which is fine. If the command is used in a float, LaTeX gives a "not in outer par mode" error, which is not very friendly. Is there a way to detect whether LaTeX is currently in vertical mode, so that I can write something helpful for the user?

share|improve this question

The \ifvmode switch indicates if you are in vertical mode including internal vertical mode. There is also \ifhmode for the horizontal mode and \ifinner for "inner" mode.

See The TeXBook, Chapter 20: Definitions (also called Macros), page 209 for more details.

Note that it is sometimes required to add a \relax before \ifvmode if it is at the beginning of a macro which can be used in a location where tokens are expanded. For example in a tabular/\halign cell tokens are expanded until something unexpandable is found in order to look for a \noalign. In such cases the wrong mode might be still active, e.g. TeX is then in vertical mode for the first cell of a row AFAIK because the cell is not entered yet so TeX is still between rows.

share|improve this answer

As an alternative to trying to duplicate the tests that LaTeX is doing, you could just locally redefine \@parmoderr and or \@ehb to something more specific to your environment.

\@parmoderr is defined initially as

  \@latex@error{Not in outer par mode}\@ehb}

which makes the "Not in outer par mode" error and then \@ehb is the help text you get if you type h which is initially defined as

  You've lost some text. \space \@ehc}
  Try typing \space <return> %
  \space to proceed.\MessageBreak
  If that doesn't work, type \space X <return> \space to quit.}

It would be a bad idea to globally change these definitions but reasonable to change them within a specific environment.

share|improve this answer

Your Answer


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.