Lontar
Comprehensive document generation library for Rust — write once, render everywhere.
Lontar is a Rust library for creating documents programmatically and exporting them to multiple formats: DOCX, PPTX, PDF, XLSX, HTML, Markdown, LaTeX, and plain text.
Features
- Multi-format output: Generate DOCX, PPTX, PDF, XLSX, HTML, Markdown, LaTeX, and plain text from a single document AST
- Feature-gated backends: Only compile the backends you need
- Text shaping: Full Unicode support with BiDi, complex scripts (Balinese, Devanagari, Arabic, etc.)
- Native diagram engine: Auto-layout flowcharts, trees, and graphs with format-specific rendering
- Citations & bibliography: BibTeX/BibLaTeX integration with multiple citation styles
- Cross-references: Automatic numbering and references for figures, tables, equations, and sections
- Template system: Declarative document templates via Tera
Quick Start
Add Lontar to your Cargo.toml:
[]
= { = "0.1", = ["docx", "pdf", "html"] }
Example
use *;
Feature Flags
Lontar uses feature flags to enable specific backends and functionality:
| Feature | Description |
|---|---|
docx |
DOCX output (implies aksara) |
pptx |
PPTX output (implies aksara) |
pdf |
PDF output (implies aksara) |
xlsx |
XLSX output (wraps rust_xlsxwriter) |
md |
Markdown output |
html |
HTML output |
txt |
Plain text output |
aksara |
Text shaping, BiDi, font management |
diagram |
Native diagram engine with auto-layout |
template |
Declarative document templates (Tera) |
full |
All features enabled |
Default Features
By default, no features are enabled. Enable only what you need:
# Minimal: Markdown and plain text only
= { = "0.1", = ["md", "txt"] }
# Office formats only
= { = "0.1", = ["docx", "pptx", "xlsx"] }
# Everything
= { = "0.1", = ["full"] }
Supported Formats
Input
- Programmatic AST construction via builder API
- Template-based generation (with
templatefeature)
Output
- DOCX: Microsoft Word documents (Office Open XML)
- PPTX: Microsoft PowerPoint presentations
- PDF: Portable Document Format
- XLSX: Microsoft Excel spreadsheets
- HTML: Self-contained HTML with inline CSS
- Markdown: CommonMark-compatible Markdown
- LaTeX: XeLaTeX/LuaLaTeX source files with BibLaTeX
- TXT: Plain text with ASCII art tables
Architecture
Lontar uses a single-crate architecture with feature-gated modules:
lontar/
├── core/ - AST types (Block, Inline, Document, styles)
├── aksara/ - Text shaping, BiDi, font management
├── diagram/ - Diagram layout engine
├── template/ - Tera template integration
└── backends/ - Format-specific writers
├── docx/
├── pptx/
├── pdf/
├── xlsx/
├── md/
├── html/
└── txt/
Multi-Script Support
Lontar supports complex text shaping for:
- Latin, Cyrillic, Greek, Georgian
- Indic scripts: Devanagari, Bengali, Tamil, Telugu, Kannada, Malayalam
- Southeast Asian: Balinese (ᬮᭀᬦ᭄ᬢᬭ᭄), Javanese, Thai, Lao, Khmer, Myanmar
- RTL scripts: Arabic, Hebrew, Syriac
- CJK: Chinese, Japanese, Korean
- Tibetan and other complex scripts
Text shaping is automatically enabled when using binary format backends (docx, pptx, pdf).
Citation & Bibliography
use *;
let doc = new
.load_bibliography?
.add_paragraph
.add_citation
.add_text
.add_bibliography
.build;
Supports:
- BibTeX/BibLaTeX input
- CSL-JSON import (Zotero, Mendeley, EndNote)
- Multiple citation styles: numeric, author-year, Vancouver, APA, etc.
Diagrams
use *;
let diagram = new
.add_node
.add_node
.add_node
.add_edge
.add_edge
.layout
.build;
doc.add_diagram;
Renders to:
- DOCX/PPTX: DrawingML shapes
- PDF: Vector graphics
- HTML: SVG
- LaTeX: TikZ
- Markdown: Mermaid
- TXT: ASCII art
Minimum Supported Rust Version (MSRV)
Rust 1.88 or later.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.