Simple Text Processor (or Scala Text Processor). This is an experiment on combining LaTeX with Scala, sbt and Twirl templates for text processing.
To run the project you will need:
- sbt installed
xelatex
command available from command line — you need to install a TeX distributiuon
To generate PDF output just execute
sbt run
You will need Internet access for sbt and LaTeX to load all the dependencies
Although LaTeX is a great text processing tool with extensive library of packages covering virtually any use case and an active community, writing your own extensions and automations for LaTeX is usually a complicated task since TeX was not intended to be a handy programming language.
Why do you need programming in LaTeX? Well, maybe for most kinds of text documents you don't. But rich programming capabilities will be extremely useful if you create something like a course material with a set of tasks, tests, exam variants and so on.
Our approach enables one to use Scala to create extensions and automations in a simple, declarative, object-oriented, functional and type-safe way. Since we are mostly dealing with string literals it is convinient to use a templating engine — we use Twirl. To automate the build process and dependency management we use sbt.
LaTeX file templates should be placed in src/main/twirl. These templates are compiled by Twirl.
PDF output is generated by running the project — i.e. by executing
Main.main
. First, TeX source files should be
produced from templates — this is done by calling
latex(tex.mytemplate)
It returns a File
object for the generated file.
To generate the PDF output from a TeX source file you should apply pdf
to this
file. The resulting file will be placed in target/latex
folder. This is the
folder where generated TeX sources are stored and processed by xelatex
.
Any static files (TeX sources, style files, images etc.) that do not need to be preprocessed by Twirl should be placed in src/main/static.
While executing xelatex
command we filter out errors and warnings and log them
to the console. Filtering is done using
regexes taken from
TeXnicCenter sources.