# Flexibly start a new page for proof environment

I would like to redefine my proof environment so that if the content of the proof environment is only, say, 3 lines or fewer, then the entire proof environment will just start on a new page. Here is a MWE:

\documentclass[11pt]{article}

\usepackage{lipsum}
\usepackage{amsthm}

\begin{document}

\lipsum[1-4]

\begin{proof}
\lipsum[1]
\end{proof}

\end{document}


In this case, there are only 2 lines of a proof on the first page, so I would like the new proof environment to automatically start the proof on the next page. If the proof environment contained 4 or more lines on a page, then it will behave as normal.

I found a thread here where they gave an example of defining an environment with different spacing and page breaking rules, but I do not understand the solution well enough to adapt it to what I am trying to do with the proof environment. Is there a way to adapt this solution to my problem?

One way would be to use the needspace package

## Code:

\documentclass[11pt]{article}

\usepackage{lipsum}
\usepackage{amsthm}
\usepackage{needspace}

\newenvironment{MyProof}{%
\needspace{3\baselineskip}%
\begin{proof}%
}{%
\end{proof}%
}%

\begin{document}

\lipsum[1-4]

\begin{MyProof}
\lipsum[1]
\end{MyProof}

\end{document}