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 need a "\smartmedskip" feature/macro in plain TeX which is in usual identical to \medskip, however, if we are right after display math mode, then it should be just "disabled", i.e. it should then behave as \par (or \vskip0pt).

(I want to use this in a macro that inserts exercises to my exercise list. Now if the last line of an exercise is a math formula, then in sum I get too much space between this and the next exercise.)

Thanks in advance.

share|improve this question
1  
Welcome to TeX.SX! A tip: You can use backticks ` to mark your inline code as I did in my edit. –  tohecz Feb 24 at 17:58
add comment

1 Answer

up vote 14 down vote accepted

You probably want that it does nothing whenever it follows another vertical skip:

\def\smartmedskip{\par
  \ifdim\lastskip>0pt \else \medskip\fi
}

This will be followed by a {\tt\string\medskip}.

\smartmedskip

This has a displayed formula
$$
a+b+c+d+e+f+g+h+i+j+k+l+m+n
$$
\smartmedskip
but the {\tt\string\smartmedskip} does nothing.

This has a displayed formula
$$
a+b+c+d+e+f+g+h+i+j+k+l+m+n
$$
\medskip
and we check the difference.

\bye

enter image description here

share|improve this answer
    
Wow, thanks for the quick reply. This solution does what I want. (In fact, I knew about \lastskip, but I did not know that it indicates \belowdisplayskip, too.) –  Gábor V. Nagy Feb 24 at 17:59
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.