Render LaTeX in Grav without Javascript

5531aa5 Add in onPageRaw handler, clean up hash function

a month ago

3037d2f Docs + 0.1.3 prep

2 months ago

#Grav StaticMath Plugin

The StaticMath Plugin is an extension for Grav CMS. This plugin converts LaTeX to static math (with some CSS) using server-side KaTeX.


Installing the StaticMath plugin can be done in one of three ways: The GPM (Grav Package Manager) installation method lets you quickly install the plugin with a simple terminal command, the manual method lets you do so via a zip file, and the admin method lets you do so via the Admin Plugin.

#Server (Required)

Install the StaticMath server first.

#GPM Installation (Preferred)

To install the plugin via the GPM, through your system's terminal (also called the command line), navigate to the root of your Grav-installation, and enter:

bin/gpm install staticmath

This will install the staticmath plugin into your /user/plugins-directory within Grav. Its files can be found under /your/site/grav/user/plugins/staticmath.

#Manual Installation

To install the plugin manually, download the zip-version of this repository and unzip it under /your/site/grav/user/plugins. Then rename the folder to staticmath. You can find these files on GitHub or via GetGrav.org.

You should now have all the plugin files under


#Admin Plugin

If you use the Admin Plugin, you can install the plugin directly by browsing the Plugins-menu and clicking on the Add button.


Before configuring this plugin, you should copy the user/plugins/staticmath/staticmath.yaml to user/config/plugins/staticmath.yaml and only edit that copy.

Here is the default configuration and an explanation of available options:

enabled: true
built_in_css: true # Uses built-in KaTeX CSS
active: false # Whether the plugin is active on a page
server: "http://localhost:3000" # The location of the StaticMath server
weight: -5 # Priority of this plugin
  inline:                 # Inline delimiters
    '\(': '\)'            # - MathJax/KaTeX
    '$': '$'              # - LaTeX

  block:                  # Block delimiters
    '\[': '\]'            # - MathJax/KaTeX
    '$$': '$$'            # - LaTeX

Note that if you use the Admin Plugin, a file with your configuration named staticmath.yaml will be saved in the user/config/plugins/-folder once the configuration is saved in the Admin.


Wherever you want LaTeX code in your server, use the delimiters set in the configuration, like so:

\text{This is a block of LaTeX code}

And $\text{this}$ is inline LaTeX code.


Much thanks to KaTeX for rendering the math, the Grav MathJax Plugin for giving me a base to build off of, and the Grav ZMarkdown Plugin to give me pointers for how to do networking in PHP.