A Linux shell script for automating the multi-step compilation process required for complex LaTeX documents (like the Tufte-style book example provided). A Perl script version is also provided for testing or systems that compile via .pl only.
Compiling LaTeX documents often requires multiple passes of pdflatex, bibtex, and makeindex to correctly resolve:
- Bibliographies and citations.
- Table of Contents, List of Figures, and List of Tables.
- Cross-references and stable page numbering.
- Indices.
The compile_latex.sh script automates these 5 steps in one go, using "non-stop mode" to ensure the process doesn't hang on minor warnings or formatting errors.
- Linux environment (Ubuntu/Debian recommended).
- TeX Live or a similar LaTeX distribution installed.
pdflatex,bibtex, andmakeindexavailable in your PATH.
-
Grant Execution Permissions (if not already set):
chmod +x compile_latex.sh
-
Run the script with your
.texfile as the argument. You can use the Bash or Perl version:# Bash version ./compile_latex.sh hello.tex # Perl version ./compile_latex.pl hello.tex
-
Result: The script will:
cdinto the file's directory (bypassing LaTeX security restrictions on absolute paths).- Attempt to compile the document 5 times to resolve all dependencies.
- Enable
-shell-escapefor advanced features. - Automatically open the resulting PDF.
The repository includes hello.tex, a comprehensive Tufte-Style book template that utilizes several advanced LaTeX features including:
tufte-bookdocument class.- Citations and bibliography entries.
- Complex indices and cross-references.
- Margin figures and full-width environments.
--
This script provides the same 5-pass compilation logic as the shell script but is written entirely in Perl in a non-bash environment
- Key Feature: Uses Perl's Cwd and File::Basename modules for platform-independent path handling.
- Intelligence: Parses the .aux file to check for citations and detects the .idx file before running the auxiliary tools.
- Security Bypass: Just like the Bash version, it switches directories automatically to ensure TeX Live can write its output files correctly.
_ Ex: _ How to use the Perl script/utility:
1 /home/ericbooth/Documents/compile_latex.pl /home/ericbooth/Documents/hello.tex
Eric A. Booth
- 🏛️ Sr Researcher, Texas 2036
- 📧 eric.a.booth@gmail.com
- 🌐 www.eric-booth.com
- 💼 GitHub Profile