2 releases

0.1.1 Dec 17, 2019
0.1.0 Dec 17, 2019

#1649 in Text processing

MIT license

10KB
190 lines

νTeX

The modern implementation of the TeX typesetting engine

Basics

νTeX is yet another WIP Rust crate with the lofty goal of reinventing Knuth's tried and true TeX typesetting system in Rust.

More specifically, the goal of the project is to introduce a typesetting engine and markup language that fully does away with a macro-based language in favor of a markup that is clean, flexible, supports painless scripting, and provides helpful error messages.

The Dream

The idea is to define a new markup language based around three, pivotal mechanics:

  1. \formats
  2. $functions
  3. @environments

Each of these three mechanics play a well defined role in the typesetting process.

Formats

Formats are indicated by \ and are used to toggle a setting for the duration of a given scope. These scopes can come in one of two flavors: inline scopes (delimited by {}), and block scopes (which use Python's indent delimitation).

The key thing that makes formats unique is the term "toggle". Formatting is done by applying modifiers to the text that follows it until it is "relaxed" (undone). Once toggled, a format can either be automatically relaxed at the end of the scope where it was invoked, or it may be relaxed manually with the special \relax format.

For example, \italics something like this, will render "something like this" and \italics something like\relax this will render "something like this".

Formats are stored on a stack, meaning that you can also relax formats temporarily by calling \relax within an inlined scope. This way \bold\italics something {\relax(bold) like} this will render "something like this".

Functions

Functions, in a short description, can be thought of as a script call that inserts something into your document. However, in general, functions will allow you to do a number of special things by sending signals to the νTeX typesetter (such as telling it to end a page).

Environments

Environments are the real beasts of the markup syntax. Environments, in essence, change how text within a scope is parsed. This means that environments allow for creating a custom mini-language that can render whatever the script designer sees fit.

A staple example of an environment is the @math environment:

@math:
    x = {-b $pm $sqrt(b^2 - 4ac)} // {2a}

which will render the quadratic equation on it's own line within a paragraph.

While environments can only operate on a specific scope, it doesn't matter which scope you use. This means you can create inlined math like @math:{y = mx + b}.

Dependencies

~5MB
~103K SLoC