How do I easily compile only a page range or page selection? That is, I would like a document that
- looks exactly like the full document,
- has only the subset of pages that were manually chosen, by page number (this can be one contiguous range or a more complicated selection, like "12-15,23,45-49"),
- has correct page numbers, and
- has correct links, except links to missing pages should be either dysfunctional or absent.
Best Answer
atbegshi
provides the capability to discard a ready-to-be-shipped-out page using\AtBeginShipoutDiscard
. Together withetoolbox
's list-processing capability, you can easily discard/retain pages conditionally:The above 47-page document is scaled down to 39 after having removed the 8 pages 1, 3, 5, 7, 9, 29, 35, 40 (as supplied by
\discardpages{1,3,5,7,9,29,35,40}
). To discard zero pages, you could use\discardpages{}
(or make no call to\discardpages
). Using\keeppages{2,4,6}
instead leaves you with a 3-page document consisting of only pages 2, 4 and 6. It should not be that difficult to extend this to include more complicated page ranges.The above has not been tested with hyperlinks from
hyperref
.