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

How can I detect if I am at a point in the source where I can end a text line, for example, with \\[5pt]?

I would like to have something like

\ifTEST \\[5pt]\else\vspace*{5pt}\fi

but I do not know what "TEST" might be.

share|improve this question
up vote 6 down vote accepted

You can test for horizontal mode like so:

 \ifhmode \\ \else \vspace*{5pt} \fi

although it's often a sign that something else is wrong if you are needing to do this?

share|improve this answer
+1 for "it's often a sign that something else is wrong". – yo' Mar 8 '12 at 13:08
Hmm! Might break if in inner mode. – Yiannis Lazarides Mar 8 '12 at 13:08
@YiannisLazarides it might break at the start of a table cell as well, it depends what the OP needs, as I tried to hint in my answer, it's better to know where you are and not need to ask:-) – David Carlisle Mar 8 '12 at 13:11
@DavidCarlisle Sure:) How about \ifinner !!!\aftergroup{\vspace*{5pt}}\else ...\\[5pt]\fi? – Yiannis Lazarides Mar 8 '12 at 13:12
@DavidCarlisle it worked thanks – Mário Mar 8 '12 at 13:17

You can also use the primitive \vskip, which breaks your line and enters vertical mode.Best practice is \vskip 5pt \vskip 0pt to ensure \removelastskip, used in some macros, does not remove your vertical skip.

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.