[Tex/LaTex] Keeping equations as part of a paragraph on the same page

math-modepage-breakingparagraphs

I want to have equations with item lists as part of a paragraph such that there is no page break between the equation and the item list, but there can be a page break in the middle of the paragraph.

Currently I am using:

\def\formula#1#2{
\begin{samepage}
    \begin{align} 
    #1 
    \end{align}  where 
    \begin{itemize}
    #2
    \end{itemize}
\end{samepage}
}

For example used like The formula is given by: \formula{f(x)=x^2}{\item $x$ is some variable}.

However, this seems to cause the whole paragraph it is used in not to have a page break.

I've tried using the minipage environment, but that causes the minipage to start where the line ended; it is shifted to the right so that part of the sentence after which the formula started was printed to its left. Introducing a line break (\\*) between the sentence and the formula then causes errors, since I sometimes do use the command as a separate paragraph, in which case there is no line to end.

I've also tried \nopagebreak[4], but that didn't seem to do anything at all.

How can I keep the equation and the itemize on the same page without necessarily having the whole paragraph on that page as well?

Best Answer

\documentclass[a5paper]{article}
\usepackage{amsmath}
\def\formula#1#2{\par\noindent%
   \minipage{\linewidth}\noindent
    \belowdisplayskip=0pt
    \belowdisplayshortskip=0pt
    \begin{align} 
    #1 
    \intertext{%
      \parbox[t]{\linewidth}{%
      where  \\[-\normalbaselineskip]
      \begin{itemize}
      #2
      \end{itemize}\vspace{-\normalbaselineskip}}}\nonumber
    \end{align}
   \endminipage
}

\begin{document}
Lorem ipsum dolorsitamet, consecteturadipisicingelit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minimveniam, exercitationullamcolaborisnisi ut aliquipexeacommodoconsequat. Duisautereprehenderit in voluptatevelit esse cillumdolore eu fugiatnullapariatur. Occaecatcupidatat non proident, sunt in culpa quiofficiadeseruntmollit. 
\formula{f(x) &= x^2}{\item $x$ is some variable}
Lorem ipsum dolorsitamet, consecteturadipisicingelit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minimveniam, exercitationullamcolaborisnisi ut aliquipexeacommodoconsequat. Duisautereprehenderit in voluptatevelit esse cillumdolore eu fugiatnullapariatur. Occaecatcupidatat non proident, sunt in culpa quiofficiadeseruntmollit. 

\end{document}
Related Question