A small executable that pre-compile the preamble to speed up future compilations (with pdflatex). Then, it watches for file changes, and automatically recompile the source .tex file using this precompiled preamble.
> latex-fast-compile -h
latex-fast-compile (version: --): compile latex source using precompiled header.
Usage: latex-fast-compile [options] filename[.tex].
If filename.fmt is missing it is build before the compilation.
The available options are:
--precompile Force to create .fmt file even if it exists.
--skip-fmt Skip .fmt file and compile all.
--no-synctex Do not build .synctex file.
--no-watch Do not watch for file changes in the .tex file.
-x, --xelatex Use xelatex in place of pdflatex.
--compiles-at-start int Number of compiles before to start watching. (default 1)
--info string The info level [no|errors|errors+log|actions|debug]. (default "actions")
--log-sanitize string Match the log against this regex before display, or display all if empty.
(default "(?ms)^(?:! |l\\.|<recently read> ).*?$(?:\\s^.*?$){0,2}")
--split string The regex that defines the end of the preamble.
(default "(?m)^\\s*(?:%\\s*end\\s*preamble|\\\\begin{document})")
--temp-folder string Folder to store all temp files, .fmt included.
--clear string Clear auxiliary files and .fmt at end [auto|yes|no].
When watching auto=true, else auto=false.
In debug mode clear is false. (default "auto")
--aux-extensions string Extensions to remove in clear at the end procedure.
(default "aux,bbl,blg,fmt,fff,glg,glo,gls,idx,ilg,ind,lof,lot,nav,out,ptc,snm,sta,stp,toc")
--no-normalize Keep accents and spaces in intermediate file names.
--option strings Additional option to pass to the compiler. Can be used multiple times.
-v, --version Print the version number.
-h, --help Print this help message.
To compile cylinder.tex you can simply use:
> latex-fast-compile cylinder.tex
create cylinder.body.tex
create cylinder.preamble.tex
::::::: Precompile...done [2.0s]
::::::: Compile (use precompiled cylinder.fmt)...done [1.1s]
Watching for file changes...(to exit press Ctrl/Cmd-C).- The source
cylinder.texis split tocylinder.preamble.texandcylinder.body.tex. - Then if the precompiled header is missing (
cylinder.fmtis missing in our case) it is precompiled fromcylinder.preamble.tex. - The file is compiled using this precompiled header (
cylinder.fmtin our case) fromcylinder.body.tex. - The program waits (except if
--no-watchis used) for new changes in the.texfile. At every change the source is re-split and the body part is re-compiled using the precompiled header.
The .tex file is split into two files .preamble.tex and .body.tex. The file is split at % end preamble comment or at \begin{document} (which comes first). The file .preamble.tex is precompiled to .fmt only if needed. The file .body.tex is compiled using this .fmt file to .pdf.
The split point is controlled by the regular expression defined in the --split flag. This regular expression follows the go re2 syntax.
The output information is controlled by the string flags --info and --log-sanitize. The regular expression set in --log-sanitize, used to sanitize the log file, follows the go re2 syntax.
To keep your folder clean of temporary files, precompiled .fmt included, a temp folder can be set with the --temp-folders flag.
In the case of MiKTeX -aux-directory is used, but in TeX Live this option is not available so -output-directory is used, but then the resulting pdf and the corresponding synctex should be moved back to the main folder.
If the filename has non ascii symbols and/or spaces, it is normalized (except if -no-normalize is used). For example Très étrange.tex will be normalized to Tresetrange.tex and at the end the resulting Tresetrange.pdf will be renamed back to Très étrange.pdf.
latex-fast-compile Très\ étrange.tex --no-watch --compiles-at-start=2
create Tresetrange.body.tex
create Tresetrange.preamble.tex
::::::: Precompile...done [3.3s]
::::::: Compile draft (use precompiled Tresetrange.fmt)...done [1.9s]
::::::: Compile (use precompiled Tresetrange.fmt)...done [2.3s]
copy Tresetrange.pdf to Très étrange.pdf
delete Tresetrange.pdf
move Tresetrange.synctex to Très étrange.synctex
remove Tresetrange.preamble.tex
remove Tresetrange.body.texThis is necessary because this kind of filenames do not work well for precompiled .fmt files.
We can use xelatex in place of pdflatex by specifying the -x (--xelatex) option. But it is good to know that fontspec and polyglossia (and any other package that access ttf or otf fonts) can't be in the precompiled header. If these two libraries are present in the preamble they are moved outside. But if they are included indirectly, the compilation will fail.
You can download the executable for your platform from the releases.
This method will compile to executable named latex-fast-compile.
$ go get github.com/kpym/latex-fast-compileAfter cloning this repo you can compile the sources with goreleaser for all available platforms:
git clone https://github.com/kpym/latex-fast-compile.git .
goreleaser --snapshot --skip-publish --cleanYou will find the resulting binaries in the dist/ sub-folder.
MIT License