[Tex/LaTex] Partial compilation commands/environment

compilingpackages

In the interest of speeding up compilation times of large documents, I got interested in partial compilation. (I'm already aware of "pre-compiling" preamble format fmt files and intend to use that as well).

The first problem is that I've inherited a skeleton of files, which use (nested) \inputs instead of \includes, so I can't really use \includeonly.

To demonstrate what I want, consider this MWE – for simplicity, a "flat"/single test.tex file:

\documentclass[11pt]{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{lipsum}

% https://tex.stackexchange.com/questions/4139/how-to-change-font-size-mid-document
% only 10, 11 and 12
\def\changeBaseFontSize#1{%
  \let\orignewcommand\newcommand
  \let\newcommand\renewcommand
  \makeatletter
  \input{bk#1.clo}%
  \makeatother
  \let\newcommand\orignewcommand
}

\usepackage{lastpage}
% page number override for book class:
\makeatletter
\def\@evenhead{\thepage\ of\ \pageref{LastPage}\hfil\slshape\leftmark}%
\def\@oddhead{{\slshape\rightmark}\hfil\thepage\ of\ \pageref{LastPage}}%
\makeatother
% \usepackage{fancyhdr}
% \pagestyle{plain}
% \lhead[\thepage\ of \pageref{LastPage}]{}
% \rhead[]{\thepage\ of \pageref{LastPage}}


\begin{document}
\frontmatter
\clearpage
\mainmatter

\chapter{Some chapter}
\section{Section One}
\lipsum[1-145]

Changing the FONT here... \changeBaseFontSize{12}

\lipsum[20]
\lipsum[23]


\section{Section Two}
\lipsum[35]

Changing the FONT here... \changeBaseFontSize{11}

\lipsum[38]


\section{Section Three}
\lipsum[1-145]


\end{document}

This results with a document of 65 pages; let's say I'm writing section Two, which ends up on pg 33 – and looks like this, minus the margins (click for full size):

test.png

What I'd like to do, is "wrap" the region of interest in commands on environment, say like this:

...
\lipsum[23]


\begin{PartialPreview} % PSEUDO
\section{Section Two}
\lipsum[35]

Changing the FONT here... \changeBaseFontSize{11}

\lipsum[38]
\end{PartialPreview} % PSEUDO


\section{Section Three}
...

At this point, upon compilation (either controllable through the command line, or by mere presence of the "PartialPreview" commands/environment), I'd like Latex to generate a document with first 32 pages being blank; page 33 being like this:

test1.png

… followed by blank pages up to page 65. In my workflow, I use evince to preview – and if the amount of pages doesn't change, then evince will keep the scrollbar position as it is, when it reloads a pdf file — and thus, I could keep the focus at the same place in the PDF, without scrolling, even if I switch between partial and full compilation.

I'd wish I could include this command/environment in arbitrary nesting of \input/\include; and since I'd want this to keep track of page numbers and other changes (like font size), I'd imagine a full compilation would be required at first, partial compilation being possible only subsequently. But then, I guess it would not be a problem to calculate new page numbers, if in the process of writing (and partial compilation previewing), the content of this "section Two" grows beyond one page in size.

Of course, I'd settle for something that doesn't necessarily insert blank pages, nor keep track of page numbers – as long as it can somehow make Latex "skip" all the portions not of interest during the partial compilation run, so it doesn't have to process all the macros (and text/images) on the way to the region of interest (and thus, a significant speedup could be expected).

Is there any package with commands or environments that do this?

PS: During my search, I found only a couple of things related (i.e. can do regional compilation), but not really applicable (as they are not packages for Latex per se):


EDIT: as per comments, I tried to use package comment, and add this at end of preamble:

\newenvironment{PartialPreview}{}{}
\ifx\doskip\relax
  \typeout{DOSKIP}
  \usepackage{etoolbox}
  \usepackage{comment}
  % https://tex.stackexchange.com/questions/14135/how-to-automatically-add-text-immediately-after-begindocument
  %\AtBeginDocument{\comment} % ! Extra \endgroup.
  %\AtBeginDocument{\begin{comment}} % Runaway argument? ! File ended while scanning use of \next.
  %\AfterEndPreamble{\comment} % ! Extra \endgroup.
  \AfterEndPreamble{\begin{comment}} % Runaway argument? ! File ended while scanning use of \next.
  %\AtEndDocument{\endcomment}%{\end{comment}}
\fi

… so wouldn't have to manually maintain the \begin{comment} at start of document, and I could control the preview from the command line through pdflatex "\let\doskip\relax\input{test.tex}"; unfortunately, that doesn't work – the error messages are added as % comments.

Best Answer

I use xemacs with AUC-TeX (there is a package for regular emacs too, but I haven't used it). It offers commands to just process the current file of a multi-file document, or just the marked region. Most references outside the piece processed will show up as undefined, but for a quick look-see it is enough.

If you \include{...} files, you can state \includeonly{list,of,files,to,include}, and processing the full document gives you just the files requested, filling in crossreferences from outside from previous runs (i.e., it assumes the page numbers don't change, no new \label{...}, no changes in chapter/section/... numbering).

Related Question