Sometimes I would like to tell latex to do something after it finishes the line currently being typeset. For example, one might want to use the command \needspace{4\baselineskip}
(assuming the needspace
package is loaded) in the middle of a paragraph to prevent a pagebreak after the current paragraph. If done naively, this could end the current paragraph prematurely.
I know that some standard latex commands like \vspace
automatically wait until the end of the current line before executing. Is there a way to mimic this behavior for other commands?
Note: Personally, I don't think a MWE is really helpful in this case. However, since I am sure someone will ask for one if I don't provide one, here is a not-entirely-minimal working example:
\documentclass[letterpaper]{article}
\usepackage{lipsum}
\usepackage{needspace}
\usepackage{amsthm}
\theoremstyle{plain}
\newtheorem{exercise}{Exercise}
\usepackage{xcolor}
\newcommand{\blank}[1]{\textcolor{white}{#1}}
%\newcommand{\blank}[1]{#1}
\begin{document}
\lipsum[1-4]
\begin{exercise}
This is an exercise that involves an equation, which is printed below.
\begin{equation}
1+1=2
\end{equation}
Please study the equation and somehow do something in the Solution box,
which may or may not be filled in depending on which line is commented out.
Please study the equation and\needspace{4\baselineskip}\noindent somehow do something in the Solution box,
which may or may not be filled in depending on which line is commented out.
\end{exercise}
\begin{proof}[Solution]
\blank{%
\lipsum[5-6]\qedhere%
}
\end{proof}
\end{document}
wrapfigure
, which by default dictates that the line write before it must break.