0

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.

1 Answers1

0

Inspired by David's comment (Thanks!), I found this solution:

\documentclass{article}

\usepackage{needspace}

\usepackage{blindtext}

\begin{document}

    \blindtext[3]

    \needspace{200pt}

    \blindtext[2]

\end{document}