# STEM

When converting to HTML, Asciidoctor relies on the JavaScript-based MathJax library to parse and render the STEM expressions in the browser when the page is loaded. The HTML converter wraps the expressions in special markup so MathJax can find and process them. However, unlike Asciidoctor’s built-in HTML converter, Asciidoctor PDF does not provide native support for STEM blocks and inline macros (i.e., asciimath and latexmath).

In order to insert a rendered expression into the PDF, the toolchain must parse the expressions and convert them to a format the PDF writer (Prawn) can understand. That typically means converting to an image.

One solution that provides this capability is an extension named Asciidoctor Mathematical, which is covered in the next section.

## Asciidoctor Mathematical

Asciidoctor Mathematical is an extension that processes STEM blocks and inline macros and converts them to a PDF-compatible format. After the document has been parsed, the extension locates each asciimath, latexmath, and stem block and inline macro, converts the expression to an image, and replaces the expression with an image. It uses Mathematical to render the LaTeX notation as an image. If the expression is AsciiMath, it first uses AsciiMath gem to convert to LaTeX. Conversion then proceeds as normal.

Asciidoctor Mathematical is a Ruby gem that uses native extensions. It has a few system prerequisites which limit installation to Linux and macOS. Refer to the installation section in the Asciidoctor Mathematical README to learn how to install it.

### Activate Asciidoctor Mathematical

Once Asciidoctor Mathematical is installed, you can enable it when invoking Asciidoctor PDF using the -r flag: