rtex
A native TeX to PDF converter CLI written in Rust with no external dependencies.
Features
- Native TeX to PDF conversion - No pdflatex or LaTeX installation required!
- Pure Rust implementation with built-in TeX parser
- Simple CLI interface
- Trait-based architecture for extensibility
- Comprehensive error handling
- Test-friendly design
- Supports common LaTeX features:
- Document structure (\part, \chapter, \section, \subsection, \appendix)
- Text formatting (\textbf, \textit, \texttt, \underline, \emph, \textsc, \sout, \overline)
- Lists (itemize, enumerate with optional \item[label], description-style labels)
- Mathematical equations (inline and display, 566+ Unicode symbols)
- Math alphabets (\mathbb, \mathcal, \mathfrak, \mathbf, \mathit, \mathsf, \mathtt)
- Math accents (\vec, \hat, \tilde, \bar, \dot, \ddot)
- Tables (tabular with alignment, booktabs rules)
- Environments (center, quote, quotation, abstract, equation, lstlisting)
- Graphics (\includegraphics with PNG/JPEG)
- References (\cite, \label, \ref, \pageref, \index, \glossary)
- Bibliography (\thebibliography, \bibliography, \bibliographystyle)
- PDF transformations (\rotatebox, \scalebox, \raisebox, \phantom)
- Title, author, and date metadata
- Table of contents, list of figures, list of tables
- Font size commands, colors, alignment, page breaks, horizontal/vertical rules
- 201+ LaTeX commands supported
Text Output Quality Validation
Text elements are validated before writing to PDF content streams:
- Inline math safety: unmatched
$is preserved as literal text (not dropped) - Text normalization: collapses excessive whitespace and removes non-printable control chars
- Wrapping robustness: long tokens are split by Unicode character count to avoid overflow
This improves final PDF text stability for noisy or mixed TeX input.
Mathematical Symbol Support
✅ Unicode Math Symbols: Successfully implemented using lopdf with UTF-16BE encoding and DejaVu Sans font embedding.
Supported Features:
- 566 mathematical symbols (Greek letters, operators, relations, arrows, integrals, summation)
- Inline and display math equations
- Special roots (∛ cube root, ∜ fourth root)
- Full alphabet super/subscripts
- Math alphabets: \mathbb, \mathcal, \mathfrak, \mathbf, \mathit, \mathsf, \mathtt
- Math accents: \vec, \hat, \tilde, \bar, \dot, \ddot
- Fractions with Unicode fraction characters and parenthesized form
- Proper Unicode text encoding
Status:
- ✅ Math formatter: 566 LaTeX commands → Unicode symbols
- ✅ Font embedding: DejaVu Sans TrueType with full Unicode support
- ✅ PDF generation: lopdf with UTF-16BE encoding
- ⚠️ File size: ~750KB per PDF (due to embedded font)
For production documents, this native converter now provides good math support. For complex documents with advanced features (TikZ, complex tables, etc.), use pdflatex.
See docs/MATH_LEARNINGS_FROM_MINITEX.md for implementation details.
Prerequisites
- Rust (edition 2024)
- No LaTeX installation required!
Installation
Usage
Convert a TeX file to PDF (outputs to output/ folder by default):
# Creates: output/input.pdf
Specify custom output path:
Or after building:
# Creates: output/input.pdf
Note: The output/ directory is created automatically if it doesn't exist.
Architecture
The project follows KISS and DRY principles with a trait-based design:
TexConvertertrait: Defines the conversion interfaceNativeTexConverter: Pure Rust implementation with native TeX parser and PDF builderTexParser: Parses LaTeX syntax into structured elementsPdfBuilder: Generates PDF documents from parsed elementsconvert_tex_to_pdf: Convenience function for direct conversion
See ARCHITECTURE.md for detailed design documentation.
Examples
The examples/ directory contains various TeX files for testing:
minimal.tex- Simplest possible documentsample.tex- Comprehensive sample with multiple featuresmath.tex- Mathematical equationstable.tex- Tables with booktabslists.tex- Itemized and enumerated listscode.tex- Code listings with syntax highlighting
Try them:
# Generates output/minimal.pdf
# Generates my_math.pdf in current directory
# Generate all examples at once
Testing
Run tests:
The test suite includes:
- 317 comprehensive tests
- Native PDF generation verification
- File size validation
- PDF header verification
- Multiple document types (minimal, math, tables, lists, complex)
- Error handling tests
- Output directory creation tests
- Round-trip tests for deterministic conversion
- Math formatter tests (fractions, roots, symbols, accents, alphabets)
- Parser tests for 201+ LaTeX commands
All tests run without any external dependencies!
Development
The codebase follows these principles:
- DRY (Don't Repeat Yourself)
- KISS (Keep It Simple, Stupid)
- SoC (Separation of Concerns)
- Test-friendly trait-based design
- Minimal public surface area
License
MIT