I need a macro for a test if a page has no text, means the current point is the upper left corner of the text area. This does not work:
\documentclass{article}
\makeatletter
\newcommand*\isOnTopOfPage{%
\ifdim \pagetotal > \pagegoal
\expandafter@secondoftwo
\else
\expandafter@firstoftwo
\fi
}
\makeatother
\begin{document}
foo bar \par
\isOnTopOfPage{>> On top of the page}%
{>> not on top of the page}
\clearpage
\isOnTopOfPage{>> On top of the page}%
{>> not on top of the page}
\end{document}
Edit 1: Problems are still lines without a \par and empty boxes. Only the second one is correct:
\documentclass{article}
\makeatletter
\providecommand@secondofthree[3]{#2}
\newcommand*\isOnTopOfPage{%
\ifdim\pagetotal=\z@
\unless\ifdim\pagegoal=\maxdimen
\expandafter@gobbletwo
\fi
\expandafter@secondofthree
\fi
@secondoftwo
}
\makeatother
\begin{document}
f
\isOnTopOfPage{>> On top of the page}%
{>> not on top of the page}
\clearpage
\isOnTopOfPage{>> On top of the page}%
{>> not on top of the page}
\clearpage
\null% empty box
\isOnTopOfPage{>> On top of the page}%
{>> not on top of the page}
\end{document}
\pdfsaveposand check it on the next run. – David Carlisle May 29 '21 at 14:00\nullthe following will not end up at the top of the page (you could use theshowframepackage to see this). But @DavidCarlisle is right, this is not really possible for each and every case. – Skillmon May 29 '21 at 16:07\pdfsavepos– user187802 May 29 '21 at 17:58