A custom formatter for SuperFences that displays LuaLaTeX as SVGs within Markdown.
This project was inspired by Markdown TikZ.
For LuaLaTeX compilation, a LaTeX distribution that includes lualatex
and dvisvgm
executables is required, which have to be available in PATH
.
The formatter can be installed via pip
. This will also install the PyMdown Extensions
package if it is not already available.
pip install git+https://github.com/kgnlp/markdown-tex
For use with MkDocs, the formatter can be configured as a custom SuperFences fence in mkdocs.yml
:
markdown_extensions:
- pymdownx.superfences:
custom_fences:
- name: latex
class: latex
format: !!python/name:markdown_tex.formatter
For direct compatibility with Obsidian TikZJax
, it can also be configured for tikz
code blocks:
- name: tikz
class: tikz
format: !!python/name:markdown_tex.formatter
Based on the configuration, latex
and tikz
codeblocks without a documentclass
will now be rendered to SVG and displayed inline. Note that the document class is set to standalone
and tikz
is included by default to support Obsidian TikZJax
.
```latex
\usepackage{amssymb}
\begin{document}
Some \textit{math} can be included as follows: $5x^2 - 4x + 2 = 0$, where $x \in \mathbb{R}^{N}$
\end{document}
```