Architecture & Internal Design

latex_it is designed as a modular, dependency-minimal Ruby application that manages the end-to-end lifecycle of LaTeX document compilation.


1. Design Principles


2. Compilation Lifecycle

The build pipeline follows an orderly sequence of phases:

┌─────────────────────────────────────────────────────────────┐
│ 1. Discovery      Locate main .tex file, detect engine      │
│ 2. Pre-Flight     Scan for unclosed braces & syntax errors  │
│ 3. Workspace      Set up isolated junk/ directory & lockfile│
│ 4. Change Check   Compare file hashes; exit if up to date   │
│ 5. Compiler Loop  Execute LaTeX & BibTeX passes (1 to 3)    │
│ 6. Export Targets Copy .pdf, .bbl, .synctex.gz to root      │
│ 7. Diagnostics    Parse log; report errors, alerts, warnings│
└─────────────────────────────────────────────────────────────┘

Phase 1: Main File & Engine Discovery

Phase 2: Pre-Flight Auditing

Phase 3: Directory Isolation (junk/)

Phase 4: Convergence Pass Scheduling

Phase 5: Target Export & Diffing


3. Modular Library Structure

The codebase is organized into modular files under lib/latex_it/:

Module Responsibility
version.rb Canonical version string (VERSION) and executable metadata.
color.rb Terminal ANSI color rendering via Rainbow with automatic plain-text fallback.
compatibility.rb REVTeX 4.0 legacy compatibility tree staging and path injection.
config.rb JSONC configuration loader, quote-aware parser, and defaults.
utils.rb Engine detection, main file heuristics, log noise filtering, and file utilities.
brace_checker.rb Static lexical environment and brace validator.
diagnostics.rb AUCTeX-compatible log parser and 4-tier diagnostic classifier.
error_catalog.rb Declarative catalog of 55 TeX/LaTeX compilation errors with token extractors and explanations.
builder.rb Orchestrator managing passes, junk/ isolation, process execution, and locking.
packager.rb Bundler for portable paper zip archives (-z) and /tmp sandbox verifier (-t).
flattener.rb Recursive subfile inliner and comment sanitizer for arXiv packages.
meta_extractor.rb Source parser extracting Title, Authors, and MathJax-compatible Abstract.
arxiv.rb arXiv submission manager, biblatex version shielding, and visual page verification.

4. Development & Quality Tooling