LaTeX Equations

PlutoExtras provides some convenience functions to display numbered equations using KaTeX. The use of KaTeX as opposed to Mathjax as in Markdown is that complex interpolation of Julia variables work better and automatic equation numbering based on the cell position in the notebook is possible.

KaTeX supports automatic numbering of equation environments. While it does not support equation reference and labelling, this hack on github shows how to achieve the label functionality.

Unfortunately, since automatic numbering in KaTeX uses CSS counters, it is not possible to access the value of the counter at a specific DOM element. We then create a function that loops through all possible katex equation and counts them, putting the relevant number in the appropriate hyperlink innerText to create equation references that automatically update.

If one wants the exploit equation referencing with automatic numbering update, this functionality must be initialized by having a cell which calls initialize_eqref as its last statement (so that the javascript code it generates is sent to the cell output)

Example

Open the latex test notebook to check this functionality in action!

Note

The notebook must be run from the original folder (test/notebooks) within the PlutoExtras package folder to properly load the PlutoExtras package

API

PlutoExtras.LaTeXEqModule.initialize_eqrefFunction

initialize_eqref()

When run in a Pluto cell, this function generates the necessary javascript to correctly handle and display latex equations made with texeq and equation references made with eqref

source
PlutoExtras.LaTeXEqModule.texeqFunction

texeq(code::String)

Take an input string and renders it inside an equation environemnt (numbered) using KaTeX

Equations can be given labels by adding "\\label{name}" inside the code string and subsequently referenced in other cells using eqref("name")

Note

To avoid the need of doubling backslashes, use the new @texeq_str macro if you are on Pluto ≥ v0.17

source
PlutoExtras.LaTeXEqModule.@texeq_strMacro
@texeq_str -> katex_html_code

Use to generate an HTML output that when rendered in Pluto shows latex equation using KaTeX.

Relies on texeq but avoids the need of double escaping backslashes.

Examples

texeq"
\frac{q \sqrt{2}}{15} + 42
"
source