# Partial compilation commands/environment?

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{%
\makeatletter
\input{bk#1.clo}%
\makeatother
}

\usepackage{lastpage}
% page number override for book class:
\makeatletter
\makeatother
% \usepackage{fancyhdr}
% \pagestyle{plain}

\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):

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:

... 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}
%\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.

• If you just want to skip the skipped region and not worry about references into the skipped region or page numbers, the comment package will let you define your environment to be a comment or not. Otherwise by far the simplest thing is to change each of your top level \input to \include and then use \includeonly It doesn't matter if they \input further files. – David Carlisle Feb 18 '15 at 23:54
• Consider using a PDF viewer which keeps your place even if the number of pages in the file changes? I'm surprised that evince doesn't do this since it is, I think, based on the same stuff as okular. – cfr Feb 19 '15 at 4:34
• Your environment PartialPreview is something like the opposite of the comment environment. You want to discard everything but what's inside of it..? At the end of the day, I suspect \includeonly will be more user-friendly. – jon Feb 19 '15 at 7:10
• Note that the comment package provides a feature to define your own comment environments: \includecomment{stuff} and \excludecomment{stuff} in the preamble both define a respective stuff environment that is either included or thrown away throughout the document. No need to comment/uncomment lines in the document itself. – Daniel Feb 19 '15 at 8:56
• @sdaau no you'd just have one environment and switch its definition between being a comment environment and not. – David Carlisle Feb 19 '15 at 11:06

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).

Ok, apologies for making this one short; but I managed to post an example matching this problem on Adding \comment or \begin{comment} to \AtBeginDocument? ; it uses the {comment} package, and defines a modified version of its \excludecomment; such that one can use:

\end{SKIPLINES} % the below range will be typeset:
\lipsum[5]
\begin{SKIPLINES}


... (note the \end opens, \begin closes) to define parts that will be typeset (while the rest will be blanked), if the process is ran with pdflatex "\let\doskip\relax\input{test.tex}".

I am aware that the linked solution is also a bit problematic (it doesn't work inside \input files either), so I hope a more erudite answer will eventually emerge; I also hope to have time in the future to update this answer, with a modification of the linked answer so it fits this question better.