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) \input
s instead of \include
s, 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):
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):
- AUCTeX (via How to speed up LaTeX compilation with several TikZ pictures?) - this is a "plugin" for Emacs, which I have never used; and it seems it is best for getting individual equations or graphs as standalone images, rather than contiguous content in a .pdf
- Whizzytex (via Custom format file: How to automate the generation of the "precompiled preamble" whenever one of the files that are used there are changed) - again a "plugin" for Emacs, but it only works with
latex
and DVI files (while I usepdf/xe/lualatex
and want to work with PDF)
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.
\input
to\include
and then use\includeonly
It doesn't matter if they\input
further files.evince
doesn't do this since it is, I think, based on the same stuff asokular
.PartialPreview
is something like the opposite of thecomment
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.comment
package provides a feature to define your own comment environments:\includecomment{stuff}
and\excludecomment{stuff}
in the preamble both define a respectivestuff
environment that is either included or thrown away throughout the document. No need to comment/uncomment lines in the document itself.