LinuxCommandLibrary

texliveonfly

Compile LaTeX documents automatically installing missing packages

TLDR

Download missing packages while compiling

$ texliveonfly [source.tex]
copy

Use a specific compiler (defaults to pdflatex)
$ texliveonfly [[-c|--compiler]] [compiler] [source.tex]
copy

Use a custom TeX Live bin folder
$ texliveonfly --texlive_bin=[path/to/texlive_bin] [source.tex]
copy

SYNOPSIS

texliveonfly [OPTIONS] COMMAND [ARGUMENTS...]
texliveonfly COMMAND [ARGUMENTS...]

PARAMETERS

--install-prefix | -p
    Specifies an alternative installation prefix for tlmgr. Useful for installing packages in a user-specific directory rather than system-wide.

--dry-run | -n
    Performs a trial run without actually installing any packages. It will show which packages would be installed.

--no-install | -N
    Disables automatic package installation. The script will simply execute the specified command without attempting to resolve missing packages.

--quiet | -q
    Suppresses most of texliveonfly's output, showing only the wrapped command's output.

--verbose | -v
    Enables more verbose output from texliveonfly, providing more details about its operations.

--debug | -d
    Enables debug mode, showing all debug messages which can be helpful for troubleshooting.

--help | -h
    Displays a help message with usage information and available options.

--version | -V
    Displays the version information of the texliveonfly script.

DESCRIPTION

texliveonfly is a wrapper script designed to automatically detect and install missing TeX Live packages during the compilation of LaTeX documents. When a LaTeX compiler (such as pdflatex, xelatex, or lualatex) reports an error due to a missing package, texliveonfly parses the output, identifies the required package, and then uses the tlmgr (TeX Live Manager) utility to download and install it. This eliminates the need for manual package installation, streamlining the workflow for LaTeX users, especially when working with new or complex documents that have many dependencies. It then re-runs the original compilation command after successful installation. It is particularly useful for development and quick testing, saving significant time by resolving common package dependency issues automatically.

CAVEATS

While texliveonfly is convenient, it has several important caveats:
1. It requires tlmgr (TeX Live Manager) to be installed and accessible in your PATH. It is designed specifically for the TeX Live distribution and will not work with other TeX distributions like MiKTeX.
2. An active internet connection is necessary for package downloads and installation.
3. Depending on your TeX Live installation, running tlmgr (and thus texliveonfly) might require root or administrator privileges, which could pose a security risk if not managed carefully.
4. For reproducible builds, it's generally better to explicitly manage your LaTeX dependencies rather than relying on on-the-fly installations. This script is more suited for development or exploration.
5. It might not correctly identify all missing packages in complex scenarios or if error messages deviate from expected patterns.
6. Repeated compilation attempts might occur if a package cannot be found or installed, potentially leading to slow builds.

WORKING PRINCIPLE

texliveonfly operates by redirecting the standard output and error streams of the wrapped LaTeX command. It then scans these streams for specific error messages indicating missing TeX Live packages. If such a message is found, it extracts the package name and attempts to install it using tlmgr install. After the installation, the original command is re-executed, assuming the dependency is now resolved. This cycle can repeat if multiple missing packages are detected. This approach makes it a seamless experience for the user, as they only need to run their compilation command once.

HISTORY

texliveonfly was developed by Alexey Malakhov to address a common frustration among LaTeX users: the manual installation of missing packages. Before such tools, users would encounter an error, identify the missing package from the log, open a terminal, run tlmgr install <package-name>, and then retry compilation. texliveonfly automates this tedious process, making it significantly easier to work with new or unfamiliar LaTeX documents and reducing the barrier to entry for beginners encountering dependency issues.

SEE ALSO

tlmgr(1), latex(1), pdflatex(1), xelatex(1), lualatex(1)

Copied to clipboard