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 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
Welcome to TeX.SX! A tip: You can use backticks ` to mark your inline code as I did in my edit. – yo' Feb 24 '14 at 17:58
up vote 14 down vote accepted

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

  \ifdim\lastskip>0pt \else \medskip\fi

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


This has a displayed formula
but the {\tt\string\smartmedskip} does nothing.

This has a displayed formula
and we check the difference.


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 '14 at 17:59

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.