Adding equations in Drupal 9

Submitted by Rork on Sat, 12/19/2020 - 15:17

Most websites consist of basic text and images but to add equation to websites some extra tools are required. In Drupal 9 two such tools are available: MathJax and Equation Editor.

The Equation Editor module offers a WYSIWYG environment to design the equation in LaTeX. It uses codecogs to show the equation as an externally hosted GIF image. The CKEditor Equation Editor plugin has to be installed as a library and a button to insert equations has to be added to CKEditor. This theoretically limits the equation code length to about 650 characters. It is not possible to host the image creating software locally, of course it's possible to download the image and store that locally. The WYSIWYG environment can be tried out at the codecogs demo.

The MathJax module uses a template and Javascript to layout the equation. It's based on MathJax which can be hosted externally or locally. A local installation would allow for customization but unfortunately I could not figure out how to install it. MathJax has to be enabled in configuration > text formats and editors. In that case the Javascript library will be loaded when the format is used. So if MathJax is only used occasionally it might be best to make a separate text format for it. The equation can be entered in LaTeX, MathML and AsciiMath and can be added in a line or in a separate paragraph. MathJax does not come with a WYSIWYG editor but copying code made in the codecogs demo seems to work well.

Because it can be hosted locally MathJax would be my module of preference. However, I want to hook it up to my Book Export RTF module and using MathJax would require me to also convert the equations to RTF. As RTF does support some mathematical denotations this seems possible, and it sounds like fun. But adding the GIF support required for Equation Editor seems to be the easier way to go for now.

Tags