how to enable asciimath formula using mathjax in asciidoctorJ

Upasana | May 23, 2019 | 2 min read | 128 views

In this tutorial we will learn how to integrate asciimath diagrams using AsciidoctorJ and any compatible browser.

Lets consider we have the following sample asciidoc file that contains asciimath markup.

Sample Asciidoc File
= My Diabolical Mathmatical Opus
Jamie Moriarty


asciimath:[sqrt(4) = 2]
stem:[sqrt(4) = 2]

We can use the below java program that converts the given asciidoc document into HTML5 output.

Java program to convert Asciidoc to HTML5
Attributes attributes = AttributesBuilder.attributes()
            .math("asciimath")  (1)

Options options = OptionsBuilder.options()

asciidoctor.convert(asciiDoc, options);
1 Enable support for asciimath extension

Here we are using this version of asciidoctorj program

Output on browser

\$sqrt(4) = 2\$
\$sqrt(4) = 2\$

We can see that AsciidoctorJ has escaped the asciimath input using \$.

Using mathjax to render asciimath inside browser

Asciidoctor support asciimath and latexmath syntax and the output produced by asciimath can be rendered on browser using js library (other asciimath libraries can also be used).

We can download the mathjax js library from

We need to configure MathJax to use \$ as the delimiter for asciimath formulas using the following configuration:

Mathjax configuration
<script type="text/x-mathjax-config">
       asciimath2jax: {
           delimiters: [['\\$','\\$'], ['`','`']]

Here is the complete HTML template that we can use to render asciimath in AsciidoctorJ

HTML Template
<script type="text/x-mathjax-config">
       asciimath2jax: {
           delimiters: [['\\$','\\$'], ['`','`']]
<script type="text/javascript" async src="">
//rest of html

We can refer to this section of Asciidoctor documents for activating support of asciimath inside asciidocs:

Top articles in this category:
  1. Using Asciidoctor in Java and Spring Boot
  2. Asciidoc: How to use nofollow option in asciidoc document
  3. Reverting default shell to bash from Zsh in Mac OS Catalina
  4. 2factor SMS in Spring Boot App
  5. Integrating PayUmoney with your Java Server Side
  6. Integrating PayUmoney Webhooks with your Java backend

Recommended books for interview preparation:

Find more on this topic: