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!
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_eqref
— Functioninitialize_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
PlutoExtras.LaTeXEqModule.texeq
— Functiontexeq(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
PlutoExtras.LaTeXEqModule.@texeq_str
— Macro@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
"
PlutoExtras.LaTeXEqModule.eqref
— Functioneqref(label::String)
Function that create an hyperlink pointing to a previously defined labelled equation using texeq()