Math Formula API¶
The math module provides registration and management of LaTeX formula rendering backends.
Module Overview¶
| Export | Type | Responsibility |
|---|---|---|
MathBackend |
Protocol | Backend interface protocol |
SVGFragment |
dataclass | Render result (SVG content + dimensions) |
QuickJaxBackend |
class | Default backend (based on QuickJax / MathJax v4) |
register_backend() |
function | Register a custom backend |
set_default_backend() |
function | Set the default backend |
get_backend() |
function | Get a backend instance |
get_default_backend_name() |
function | Get the default backend name |
Basic Usage¶
from latticesvg.math import get_backend
backend = get_backend() # Default QuickJax
fragment = backend.render(r"E = mc^2", font_size=20, display=True)
print(fragment.width, fragment.height)
print(fragment.svg) # SVG string fragment
Custom Backends¶
from latticesvg.math import register_backend, set_default_backend
class MyBackend:
def render(self, latex: str, font_size: float, display: bool = True):
# Return SVGFragment
...
register_backend("my_backend", MyBackend)
set_default_backend("my_backend")
Auto-generated API Docs¶
Backend Management¶
math ¶
Math formula rendering — pluggable backend system.
Default backend: quickjax (in-process MathJax v4 via QuickJS).
Usage::
from latticesvg.math import get_backend
backend = get_backend() # default QuickJax
frag = backend.render(r"E=mc^2", font_size=16)
SVGFragment
dataclass
¶
Result of rendering a LaTeX expression to SVG.
depth
class-attribute
instance-attribute
¶
Depth below baseline in px (for inline alignment).
QuickJaxBackend ¶
Render LaTeX math via QuickJax (in-process MathJax v4).
QuickJax runs MathJax inside an embedded QuickJS engine — no Node.js, no subprocess, no network. It is the recommended and default backend.
Source code in src/latticesvg/math/backend.py
register_backend ¶
Register a math backend class under name.
set_default_backend ¶
get_default_backend_name ¶
get_backend ¶
Return a (cached) backend instance.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Backend name.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the requested backend is not registered. |
RuntimeError
|
If the backend reports itself as unavailable. |
Source code in src/latticesvg/math/__init__.py
QuickJax Backend¶
backend ¶
Math backend protocol and QuickJax implementation.
SVGFragment
dataclass
¶
Result of rendering a LaTeX expression to SVG.
depth
class-attribute
instance-attribute
¶
Depth below baseline in px (for inline alignment).
QuickJaxBackend ¶
Render LaTeX math via QuickJax (in-process MathJax v4).
QuickJax runs MathJax inside an embedded QuickJS engine — no Node.js, no subprocess, no network. It is the recommended and default backend.