latex_formula_renderer

Provides a LaTeX formula rendering infrastructure

To install, run nikola plugin -i latex_formula_renderer

The latex_formula_renderer plugin provides a static LaTeX formula rendering infrastructure, generating images which can be included in a website and do not depend on client-side rendering of formulae (as with MathJax and KaTeX). This plugin is not for end-users, but provided as a service for other plugins which can use it to not having to define their own formula-rendering functionality. As an example of its usage, take a look at the LaTeX compiler plugin.

The plugin has support for

  • inline formulae, display-style formulae,
  • align environments (see the AMSMath documentation),
  • XY-pic diagrams (in xymatrix environments inside any of the previous; see the XY-Pic user guide),
  • pstricks graphics (see here for more information), and for
  • tikzpicture graphics (see here for more information).

It allows to generate formulae in different output formats:

  • as .png bitmap images;
  • as .svg vector graphics;
  • as compressed .svgz vector graphics.

The generated images do not require the user to have a certain font installed, and should render the same in all browsers and on all output devices (assuming they support the chosen graphics format and don't screw up basic things).

To see how the plugin can be used, please check out the docstring of LaTeXFormulaRendererPlugin in latex_formula_renderer.py.

Suggested Configuration:

# The folder relative to OUTPUT_FOLDER in which the rendered formulae are stored.
# Defaults to /formula/.
LATEX_FORMULA_FOLDER = "formula"

# Whether to store the rendered formulae as images or to insert them with data URIs.
# Warning: data URIs can seriously blow up the generated HTML, especially if you
# use may formulae or repeatingly the same one!
LATEX_FORMULA_AS_DATAURI = False

# The output format used for the images. Possible values:
#   * "png" for PNG images with transparency;
#   * "svg" for SVG vector graphics;
#   * "svgz" for SVG vector graphics compressed with gzip.
# Note that depending on your web server's configuration, you might experience
# problems with .svgz files as the web server might treat them similar to .svg.gz
# files and deliver them claiming that they are .svg files.
LATEX_FORMULA_OUTPUT_FORMAT = 'png'

# Allows to include packages and define things in the preamble of the .tex files
# used to render the formulae. When generating a temporary .tex file, the plugin
# looks for the contents of the following keys:
#   * "": will always be included;
#   * "tikz": will be included when formula_type is ("tikzpicture", ...);
#   * "pstricks": will be included when formula_type is ("pstricks", ...);
#   * "xy": will be included if the formula contains "\xymatrix";
#   * "pdflatex": will be included if the .tex file is processed by pdflatex
#     to convert it to a .pdf file;
#   * "latex": will be included if the .tex file is processed by latex to convert
#     it to a .dvi file.
# The default is {}, which means no preamble additions. The following example
# shows how to define some macros for all formulae:
LATEX_FORMULA_ADDITIONAL_PREAMBLE = {
    "": r"""
\usepackage{amssymb}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}"""
}

Requirements:

Issues? Questions?

You can report issues with this plugin and request help via GitHub Issues.