Custom Build of MathJax with toSpeech()








This example shows how to create a completely custom build of MathJax v4 that does not use the predefined MathJax components at all. This example provides a command to convert a TeX string to a speech string for that expression (and does no other typesetting).

The main code for the build is

which contains comments describing it in detail. In order to use the component in your web pages, you must package it into a single file using webpack. Although this build does not use any of the MathJax component files, you can still use the component building tools to make it easy to create the combined file. You do that by first defining the component using the file

which gives the name of the combined file. The dist property being set to '.' means that the combined file will be placed in the directory with the source file, but with .min.js as the extension rather than .js.

To make the actual combined file, use the commands

from the main directory of this repository. That will create the custom-mathjax.min.js file in the custom-build directory.

To include this in your own web page, you only need one line:

Our custom MathJax build creates a MathJax global variable that contains the command toSpeechMML(). The example HTML file uses this to convert user-provided TeX expressions and displays MathML node trees with the attached speech strings.

This build of MathJax includes the ability to provide a ready() function that is called when MathJax has initialized itself and is ready to process math. The example HTML file takes advantage of that to enable the user interface elements (which are initially disabled so that the user can’t press them until MathJax is ready). See the source code below.