# Detect if \\ can be used

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.

-

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?

-
+1 for "it's often a sign that something else is wrong". –  tohecz 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.

-