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.

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

2 Answers 2

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". –  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.

share|improve this answer

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.