I want to define a command which prints \newpage if the remaining free space on the current page is below a certain size, e.g. 200pt.
I tried to adapt the snippet to my needs. The problem is that the if condition always produces an error message and I have no idea why.
\documentclass{article}
\newdimen\spaceleft
\spaceleft=\textheight
\multiply\spaceleft by -1
\newcommand{\conditionfornewpage}{
\advance\spaceleft by \pagetotal
\multiply\spaceleft by -1
% the following if condition produces an error
\ifdim(\spaceleft < 200pt)
\newpage
\else
\fi
}
\usepackage{blindtext}
\begin{document}
\blindtext[3]
\conditionfornewpage
\blindtext[2]
\end{document}
EDIT
Thanks to David's command I found a great solution for my problem. But I'll accept the answer which explains why I have an error in my code.
needspacepackage which essentially does just this – David Carlisle May 04 '16 at 09:00