Generating images statically using LaTeX [tfmt-000L]
Because of the general inadequacy of the other available tools, most authors of hypertext mathematics with diagramming needs tend to rely on the static generation of images from LaTeX code using a local LaTeX toolchain. It is not difficult to instrument pandoc with a Lua filter to render tikz code to SVG images.
There are also a variety of other tools that do something similar, which tend to be employed in static site generation:
- antex by Paolo Brasolin is used by Krater as well as jekyll-sheafy, both via jekyll-antex.
- Forester by Jonathan Sterling is used by the present web site.
The basic architecture of such a tool is to scan for LaTeX blocks, and then identify them by a hash of their contents. This hash is used as a filename for .tex files, which are compiled to .dvi and thence to .svg using the dvisvgm tool; the resulting file is then embedded in HTML using an <img> tag. Alternatively, is also possible to transclude the resulting <svg> element directly, but then one must be careful to rename all identifiers in the <svg> element uniquely, as it is possible for two different <svg> elements on a single page to interfere one each other.
Both antex and Forester support passing a macro library to be used when rendering. Both jekyll-sheafy and Forester set their macro libraries on a page-local basis.
A serious downside of generating images from LaTeX code is the negative impact on accessibility tools. This seems only slightly mitigated by the transclusion of the <svg> element as opposed to using <img>. Ultimately accessibility for mathematical diagrams remains an unsolved problem, and it does not seem that the existing discussion on accessibility of hypertext mathematics has much to say about this problem.