Skip to main content

A Python module to speed up TeX compilation.

Project description

tex-fast-recompile

A Python module to speed up TeX compilation.

This is similar to the mylatexformat TeX package that it works by "speed up" some "preamble", but unlike using "precompiled preamble" i.e. custom TeX format, this package works with every package including package that executes some Lua code, or load OpenType font.

Installation

It can be installed from PyPI or GitHub:

You also need to install the helper TeX package fastrecompile.sty, which can be found in the tex/ directory. Refer to https://tex.stackexchange.com/q/1137/250119 for installation instruction.

(currently the TeX package is not available on CTAN)

Usage

Normal mode

If installed properly, an executable tex_fast_recompile should be available on your command-line.

Run tex_fast_recompile --help to view the available options.

For example you can use it as follows:

tex_fast_recompile pdflatex a.tex

to compile a.tex to a.pdf and automatically watch it on changes.

Usually prepending it to your LaTeX compilation command suffices.

LaTeXmk emulation mode

For compatibility with e.g. vimtex plugin, an executable tex_fast_recompile_latexmk is provided, which takes arguments similar to that of latexmk. (but it does not do multiple compilation passes or invoke bibliography/indexing commands etc., and the simulation might not be complete)

Run tex_fast_recompile_latexmk --help to view the available options. (should be similar to latexmk's accepted options)

For VimTeX usage, putting the following configuration in .vimrc usually suffices:

let g:vimtex_compiler_method='latexmk'
let g:vimtex_compiler_latexmk = { 'executable' : 'tex_fast_recompile_latexmk' }

Limitations

  • Any file \input in the preamble must not be changed. (when the preamble changes, the program will automatically detect that)
  • You must not read from the terminal anywhere in the preamble, such as with functions \read -1 to ... or \ior_get_term:nN .... (if you're not sure what this mean, you should be safe)

Advanced notes

Extra note

If you want to read the log file, refer to the help of --copy-log option.

It's possible to print out some content in the "preamble" part, but if you do so...

\documentclass{article}
\usepackage{fastrecompile}  % add the package here
% other preamble lines...
\begin{document}

123
\clearpage
\fastrecompileendpreamble
456

\end{document}

you must also use the --copy-output option if you want to view the resulting PDF.

--no-add-package mode

Behind the scene, some magic is done on your TeX file.

If you want to do that manually, you need to modify your TeX file as follows:

\documentclass{article}
\usepackage{fastrecompile}  % manually add the package here
% other preamble lines...
\begin{document}

% put the line below where the preamble ends:
\fastrecompileendpreamble

...

\end{document}

then compile your document with --no-add-package flag added.

Note that:

  • \fastrecompileendpreamble must appear exactly once in the main file.
  • There must be nothing else on the line that contains \fastrecompileendpreamble.
  • SyncTeX features of the text part in the "preamble" may not be correct.

How does it work?

The principle is very simple. Notice that while the user want fast refresh, the file does not change very frequently.

As such, we start the compiler before the file has changed to process the "preamble", then when the file changed we continue processing the rest of the file.

A graph for illustration:

Before:

(each * represents a file change, |--.--| represents a compilation where the . marks where the preamble processing is done)

+----------------------------------------------------> Time
     *          *                *           *
     |--.--|    |--.--|          |--.--|     |--.--|

After:

+----------------------------------------------------> Time
     *          *                *           *
     |--.--|--. --|--.           --|--.      --|

It can be easily seen that after the change, it only takes 2 instead of 5 time units from when the file is saved to when the change is reflected in the PDF.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tex-fast-recompile-0.4.0.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

tex_fast_recompile-0.4.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file tex-fast-recompile-0.4.0.tar.gz.

File metadata

  • Download URL: tex-fast-recompile-0.4.0.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for tex-fast-recompile-0.4.0.tar.gz
Algorithm Hash digest
SHA256 a48b1ce02552e26a3168c5a8311bd1d1bae8c6561a6d4b854f4cb1761c561bb3
MD5 65b5c6929342bf9b7153741a313de0cc
BLAKE2b-256 58951ea29ff90b56f5dc89d24d76f869be081fd556b9e37f3cdbfeb75f9c659c

See more details on using hashes here.

File details

Details for the file tex_fast_recompile-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tex_fast_recompile-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd934c251b5de8ab1e28bcee6bb44bf37b65542c78ec55c798a115a3b6f72bfc
MD5 a134854a8bc4f9979785f2f206d086c9
BLAKE2b-256 9a143a2d8ed16acb274363b2df51de0a613333bf568f7d9039232d2b03aa8190

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page