texp Manual
Abstract
texp
is a domain specific language embedded in Common Lisp for printing TeX expressions. Because, let's face it, TeX is a horrible programming language. I created texp
to ease the programatic generation of TeX documents and programs from within Common Lisp. By intertwining both languages, texp
brings high level meta programming to TeX and enables you to produce high quality print media in an easy and scalable fashion.
If you have no experience with TeX then none of what follows will make any sense to you. texp
has no model of TeX's semantics, besides escaping special characters. For an introduction to TeX I recommend Knuth's TeXbook.
A brief example
To utilize texp
we need to intern the texp
package and import the texp:syntax
readtable:
Assume we need to generate a localized document. We could do that by using a function that accepts localized captions and fills in a TeX document.
deftex
enables us to use TeX's \def
with more descriptive parameter names. br
prints a double newline and escape
handles escaping of TeX's many special characters. TeX macros can be expressed in a lispy way.
The tex
macro
The tex
macro translates its child expressions to TeX expressions. It is a very thin abstraction at the syntax layer. The translation rules are listed below:
s-expression | translates to |
---|---|
(foo bar baz) | \foo barbaz |
[foo bar] | [foobar] |
{foo bar} | {foobar} |
tex
translation rules. foo
and bar
could be strings or numbers as well. In case of symbols, the symbol-name
s are printed in lower case for convenience. Brackets and curly braces require the readtable texp:syntax
. All expressions can be nested.The (br)
form prints two newlines, used to seperate paragraphs in TeX:
The $
form lets you interpolate values into tex
bodies. Consider the following example:
The escape
function can be used to escape characters treated specially by TeX in strings of input. A table of escape rules is bound to *escape-table*
.
The deftex
macro
The deftex
macro simplifies writing TeX's \def
statements using texp
. It's best described by example:
As you can see, deftex
does not do much at all. Nevertheless, it provides a lispy syntax for TeX \def
's and enables you to use descriptive parameter names by hiding TeX's natural parameter syntax with a let
.