%From Tugboat volume 8, number 2 july 1987
%by Donald Knuth
%
%  The idea is to make TeX look for a file called pages.tex.  if such a
%file doesn't exit, everything works as before, Otherwise the file
%should contain a list of apge numbers, one per line, in the order that
%they will be generated.  After the last page number has been matched,
%all further pages will be printed.  Thus, if you want ot print pages
%123 and all pages from 300 onwards, your file pages.tex should say
%	123 
%	300 
%but if you want to print pages 123 and 300 only, the file should say,
%e.g.,
%	123
%	300
%	-99999999999 % impossible number   
%so that the end of file will never occur.
%

\let\Shipout=\shipout
\newread\pages \newcount\nextpage \openin\pages=pages
\def\getnextpage{\ifeof\pages\else
 {\endlinechar=-1\read\pages to\next \ifx\next\empty % in this case we
should have eof now \else\global\nextpage=\next\fi}\fi}
\ifeof\pages\else\message{OK, I'll ship only the requested pages!}
 \getnextpage\fi
\def\shipout{\ifeof\pages\let\next=\Shipout
 \else\ifnum\pageno=\nextpage\getnextpage\let\next=\Shipout
  \else\let\next=\Tosspage\fi\fi \next}
\newbox\garbage \def\Tosspage{\deadcycles=0\setbox\garbage=}
