Skip to content

renderMath

Official

Render some LaTeX math using the MathJax engine. Returns an HTMLElement. Requires calling finishRenderMath when rendering is all done to flush the MathJax stylesheet.

Import:

import { renderMath } from 'obsidian';

Example:

console.log(renderMath('\\frac{1}{2}', true));

Signature:

function renderMath(source: string, display: boolean): HTMLElement

Parameters:

ParameterTypeDescription
sourcestringThe LaTeX source code.
displaybooleanWhether to render the math in display mode.

Returns: HTMLElement — The rendered math element.

Example:

console.log(renderMath('\\frac{1}{2}', true));