latex

Renders LaTeX or KaTeX within a jupyter notebook cell.

LaTeX is a typesetting engine often used for writing mathematical formulas along with technical and scientific documentation. (see latex.render())

KaTeX is a very fast typesetting library specifically to write math notation. It implements a subset of the LaTeX specification. (see latex.katex())  

Note on Backslashes

Both LaTeX and KaTeX use slashed characters that are not normally understood by JavaScript strings.

For example: "c = \pm\sqrt{a^2 + b^2}"

An alternative to using additional backslashes is possible: c = \\pm\\sqrt{a^2 + b^2}

However, use of String.raw may be easier.

(Please note though, that some sequences still need to be escaped, such as: ${, \n, \x

For example:

utils.latex.render(String.raw`Given : $\pi = 3.14$ , $\alpha = \frac{3\pi}{4}\, rad$
$$
\omega = 2\pi f \\
f = \frac{c}{\lambda}\\
\lambda_0=\theta^2+\delta\\
\Delta\lambda = \frac{1}{\lambda^2}
$$`);

Renders as:

Screenshot of Latex

Learn more about how to write LaTeX in the Toward Data Science article here

Or in the Illinois University document here

Methods

(static) katex(expression, katexRenderOptions, htmlScriptOptions)

See:

Renders a KaTeX math expression through ijs.htmlScript in the Browser.

It is a subset of LaTeX - see here for supported functions that focuses primarily on Math representation.

While not supported out of the box, it does provide a number of very nice features and options not supported by standalone LaTeX.

For example, here we can give options on display options, and additional custom macros.

utils.latex.katex("c = \\pm\\root{a^2 + b^2}\\in\\RR", {
    displayMode: false,
    macros: {
      "\\RR": "\\mathbb{R}",
      "\\root": "\\sqrt"
    }
});

Screenshot of KaTeX with Options

See the note the Note on Backslashes above.

(As this runs within htmlScript, and not within latex, it may not be preserved in all output formats)

Parameters:
Name Type Description
expression String

KaTeX expression to render (note comment on String.raw)

katexRenderOptions Object

Options object to pass to katex.render

htmlScriptOptions Object

Options to pass to the htmlScript renderer.

(static) render(body)

Renders the body text as LaTeX using the Jupyter Lab supported mime-type: text/latex.

See the note the Note on Backslashes above.

For example:

utils.latex.render(String.raw`Given : $\pi = 3.14$ , $\alpha = \frac{3\pi}{4}\, rad$
$$
\omega = 2\pi f \\
f = \frac{c}{\lambda}\\
\lambda_0=\theta^2+\delta\\
\Delta\lambda = \frac{1}{\lambda^2}
$$`);

Screenshot of Latex

Parameters:
Name Type Description
body String