Module

roles.builtins.math

Math role for inline mathematical expressions.

Provides the {math} role as an alternative to $...$ syntax.

Example:

The equation {math}E = mc^2is famous.

Classes

MathRole 4 ▼
Handler for \{math}`expression` role. Renders inline mathematical expressions. The output format d…

Handler for {math}expressionrole.

Renders inline mathematical expressions. The output format depends on the math rendering library configured (MathJax, KaTeX, etc.).

Syntax:

\{math}`E = mc^2`
\{math}`\sum_{i=1}^n x_i`

Thread Safety:

Stateless handler. Safe for concurrent use.

Attributes

Name Type Description
names ClassVar[tuple[str, ...]] —
token_type ClassVar[str] —

Methods

parse 3 Role ▼
Parse math role content. Content is preserved as-is for math rendering.
def parse(self, name: str, content: str, location: SourceLocation) -> Role
Parameters
Name Type Description
name —
content —
location —
Returns
Role
render 2 ▼
Render math expression. Uses span with math class for CSS styling and JS rende…
def render(self, node: Role, sb: StringBuilder) -> None

Render math expression.

Uses span with math class for CSS styling and JS rendering. Outputs raw LaTeX (matches plugin format) for KaTeX katex.render().

Parameters
Name Type Description
node —
sb —