i have just released GladTeX 0.6, a maths preprocessor for HTML documents. In this article, I will introduce the new features of GladTeX and will give practical examples on how to use GladTeX, i.e. to render MarkDown files with formulas.
About
GladTeX is a preprocessor for HTML files to enable math formulas within HTML
documents by embedding images and generating an alternative text for blind people.
Everything surrounded by <eq>...</eq>
will be taken as a LaTeX formula
and converted.\
Additionally, GladTeX can be used to transform Markdown documents to HTML with
formulas, if used with Pandoc.
Where To Get It
I have decided to rewrite GladTeX in Python. Before it has been a Perl/C mixture which was hard to port and not working on Windows. Python in contrast is a nowadays wide-spread scripting language with the ability to write platform-independent code very easily. From this version on, there's a Windows executable available. On Debian and derived systems (like Ubuntu) you can also install GladTeX using
sudo apt-get install gladtex
I am maintaining this package and keep it up-to-date.
The latest version can be easily build from
source. It boils down to execute
sudo python3 setup.py install
on the command line.
To run GladTeX you will need a LaTeX distribution like MikTeX (for
Windows) containing preview.sty
and dvipng
.
Both are included in MikTeX and Texlive.
Embedding GladTeX Into Other Applications
I've decided to split the program into two parts: a library and a
command line frontend. This way it's easily possible to embed the
library gleetex
into another application. This application can choose
to either also parse HTML files and produce HTML with formula images or
just use gleetex as a simple way to convert LaTeX formulas to images.
There's no separate library documentation yet, but I've payed attention
to document all the classes extensively, so feel free to just browse
the source.
Shell-piping support has been added as well, so that formula images can be created without a HTML document. This might be useful for web site generators, etc. Consider the following:
echo '<eq>\gamma\alpha</eq>' | gladtex -d images -o /dev/null
or on Windows
echo "<eq>\gamma\alpha</eq>" | gladtex -d images -o nul
Additionally there's a cache containing formula → image mappings which is now a gzipped json file and can be hence post-processed by scripts as well.
MarkDown and GladTeX
It is possible to embed formulas into MarkDown files when using Pandoc as a converter. It is as easy as surrounding formulas by a \$ sign (or double \$\$ for display math), like this:
This is an inline formula: $\frac{1}{m^2}$
This is displaymath $$\frac{\frac{1}{m}}{\big(\tau\cdot (\pi + \gamma)\big)}$$
Pandoc brings the --gladtex
option and with the new GladTeX version,
converting a file called input.md
is as easy as:
pandoc --smart -t html --gladtex input.md | gladtex -d images -o output.html
Which will create a file called output.html
with images containing the
desired formulas and all images located in a separate images directory.
High Test Coverage
Something which is not immediately visible from outside is that the new GladTeX is now fully tested with unit tests. I hope to make GladTeX as bug free as possible. It actually saved a considerable amount of time when developing GladTeX, because I discovered a lot of problems very early.
Comments