Klartex

PDF generation via LaTeX — structured data in, professional documents out.

Klartex is an open-source CLI tool and Python library that generates professional PDF documents from JSON data. It uses XeLaTeX under the hood.

Install

pip install klartex

Requires Python ≥ 3.12 and XeLaTeX (brew install --cask mactex or apt install texlive-xetex).

Templates

TemplateDescription
_blockUniversal block engine — compose documents freely from typed blocks
fakturaInvoice with line items, VAT, and payment info
protokollMeeting minutes with agenda, decisions, and adjusters

Usage

# Generate a PDF from JSON data
klartex -t faktura -d invoice.json

# Pipe JSON via stdin (defaults to block engine)
echo '{ "body": [...] }' | klartex

# Show the JSON Schema for a template
klartex schema faktura

# Start HTTP API server
klartex serve --port 8000

Example: Invoice

{
  "invoice_number": "2026-001",
  "date": "2026-02-15",
  "due_date": "2026-03-17",
  "recipient": {
    "name": "Kundforetaget AB",
    "org_number": "556123-4567",
    "address_line1": "Storgatan 1",
    "address_line2": "123 45 Stockholm"
  },
  "lines": [
    {
      "description": "Consulting services",
      "quantity": 40,
      "unit": "hrs",
      "unit_price": 1200.00,
      "vat_percent": 25
    }
  ],
  "bankgiro": "1234-5678",
  "note": "Thank you!"
}

Save as invoice.json, then run: klartex -t faktura -d invoice.json

Links