Skip to content

LaTeX

spawn_latex shows formulas as solid 3D characters. LaTeX doesn't need to be installed.

from ue_spawn import spawn_latex
from unreal_engine import FVector

spawn_latex(r'\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}',
            location=FVector(0, 0, 300))

Click a formula to edit its source; Ctrl+Enter or Esc when done.

More examples

spawn_latex(r'x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}')
spawn_latex(r'\begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}')
spawn_latex(r'|x| = \begin{cases} \textcolor{skyblue}{x} & \text{if } x \ge 0 \\ '
            r'\textcolor{orange}{-x} & \text{otherwise} \end{cases}')
spawn_latex(r'Let $f:\mathbb{C}\to\mathbb{C}$ be \textbf{entire} and bounded.')

Options

Option Does
size UU per em
depth Thickness in UU (default 0.18 em)
color Linear RGB; \color{...} and \textcolor{...}{...} work in the source
anchor What sits at location: 'bottom' (lower left), 'baseline' or 'center'
edit Start editing at once

spawn_focused_latex() puts an empty formula in front of you, ready to type. The proxy (actor.get_py_proxy()) has set_source(), source, errors, edit() and finish().

In the tests

Copied from the code when this site is built. LATEX_EXAMPLES in test_spawn.py lists the formulas it shows.

From the tests: test_latex (Content/Scripts/test_spawn.py:1859)
def test_latex(base_y=0):
    """Formulas as solid 3D characters (spawn_latex), 2 columns.

    Click one to edit its source, Ctrl+Enter or Escape when done. Offline checks
    are in ue_math/latex/test_latex.py.
    """
    from ue_spawn import spawn_latex

    results = {}
    for i, (name, source) in enumerate(LATEX_EXAMPLES):
        column, row = divmod(i, 5)
        loc = FVector(0, base_y + 100 + column * 1000, 1200 - row * 270)
        actor = None
        t0 = time.monotonic()
        try:
            actor = spawn_latex(source, location=loc)
            errors = actor.get_py_proxy().errors if actor else []
        except Exception as e:
            _log_exception(f'latex_{name}', e)
            errors = []
        results.update(_result(f'latex_{name}', actor, extra='; '.join(errors),
                               elapsed=time.monotonic() - t0))
    return results

View it on GitHub