Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Hosts and APIs

A host is the program that runs the Texl engine: it gives the engine a template, the data the template needs, and a way to load the documents it imports. The template language is the same in every host.

HostUse it toReference
Command linerender template files from a terminal or a scripttexl command
JavaScriptrender templates in a web page or a web workerJavaScript API
Pythonrender templates in a Python program, with asyncioPython API
Rustrender templates in a Rust program, or build a new hosttexl_core, swan_core
Node.jscoming soon

What differs between hosts

The hosts differ in three ways:

  • Which locations they can load. The command-line tool reads local files; the JavaScript library fetches URLs over HTTP; the Python library does both. Python and Rust programs can add their own loaders.
  • Which globals they pass. The command-line tool passes none. JavaScript, Python and Rust programs pass any values and functions they want.
  • How they run asynchronous work. Each host connects the engine to its own event loop: the browser's, asyncio in Python. This only matters to Rust programs, which choose the runtime.

The crates

Texl is a Cargo workspace with five crates:

CrateContents
swan-coreThe Swan language: lexer, parser, evaluator and built-in library.
texl-coreThe template renderer and the engine: documents, loaders, imports.
texl-cliThe texl command.
texl-wasmThe JavaScript library, compiled to WebAssembly (@onlabsorg/texl on npm).
pytexlThe Python library: a native module and the pytexl package.

The API documentation of swan-core and texl-core is generated from the source code by rustdoc.