# How can we detect that we are right after display math mode? (for vertical spacing)

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.)

-
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

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
`

-
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