MiniTeX
MiniTeX is a typesetting system implemented as a library in a programming language.
The document produced by MiniTeX is a box, which can be rendered on screen. The user may pick individual boxes inside the rendered document.
Documents are composed from combinators. They're functions that take in environment and produce a list of boxes. Here's an implementation of par
-combinator:
def par(env):
return [vglue(env.font_size)]
Combinators are passed to functions that produce larger combinators, for exapmle vbox
or table
:
vbox(["first paragraph", par, "second paragraph"])
table([
["a", "b", "c"],
["d", "f", "g"],
])
The user can produce his own combinators to supplement additional needs. Here's an implementation of scope
-combinator:
def scope(contents, values={}):
def _scope(env):
env = Environ.let(env, values)
for item in contents:
for box in fold(item, env):
yield box
return _scope
The fold
function invokes a combinator. It allows strings literals to be to be treated as combinators, eg.
fold("string", env) -> [s t r i n g]
fold(par, env) -> [vglue(env.font_size)]
The user may adjust rendering by giving parameters to the environment. For example scale and font size may be changed.
Finally the combinators can be gathered into a list to produce the document and display it:
env = Environ.root(width=screen.width)
box = toplevel([
"Hello World"
], env)
print box.width, box.height, box.depth
display(box, x, y)
I've got one of these in textended-editor, but it's not suitable for a library release. I don't have good enough rendering infrastructure in place.