# atbegshi warnings printed as part of output

Consider the following example:

\documentclass{article}
\usepackage{lipsum,atbegshi}
\usepackage[2-]{pagesel}% Ignore first page
\begin{document}
\lipsum[1-50]
\end{document}


The output includes a warning from atbegshi:

How can I avoid this?

## 2 Answers

This will happen after every discarded page.

pagesel discards pages depending on the inclusion criteria you specify. When a page is excluded, the shipout box is voided, which confuses atbegshi.

To avoid this, switch the load order, loading atbegshi after pagesel:

\documentclass{article}
\usepackage[2-]{pagesel}
\usepackage{lipsum,atbegshi}
\begin{document}
\lipsum[1-50]
\end{document}


Additions to Werner's answer.

Also package atbegshi has a "page discard" feature. For example, the first page can be ignored by:

\documentclass{article}
\usepackage{lipsum,atbegshi}
% \usepackage[2-]{pagesel}% Ignore first page
\AtBeginShipoutNext{\AtBeginShipoutDiscard}
\begin{document}
\lipsum[1-50]
\end{document}


Or ignoring all even pages:

\documentclass{article}
\usepackage{lipsum,atbegshi}
\AtBeginShipout{%
\ifodd\value{page}%
\else
\AtBeginShipoutDiscard
\fi
}
\begin{document}
\lipsum[1-50]
\end{document}


Of course, the syntax is not as comfortable as with package pagesel, thus Werner's solution with using pagesel before atbegshi is the easiest way.

Nevertheless, the ignoring via atbegshi allows funnier things, like ignoring pages, which are marked by a reference:

% \nofiles % for the final run
\documentclass{article}
\usepackage{lipsum,atbegshi, refcount}
\AtBeginShipout{%
\ifnum\getrefbykeydefault{IgnoreThisPage}{page}{-\maxdimen}=\value{page}%
\AtBeginShipoutDiscard
\fi
}
\begin{document}
\lipsum[1-25]
\section{This page is ignored}
\label{IgnoreThisPage}
\lipsum[26-50]
\end{document}


In the first run the reference is written to the .aux file. In the second run the page with the reference is then discarded. Since the page is not output, the reference does not get written to the .aux file and a third run writes the reference again, but includes the page. Therefore the run, which excludes files should call \nofiles to prevent changes to the auxiliary files.