# LaTeX

Makie can render LaTeX strings from the LaTeXStrings.jl package using MathTeXEngine.jl.

This engine supports a subset of LaTeX's most used commands, which are rendered quickly enough for responsive use in GLMakie.

## Using L-strings

You can pass LaTeXString objects to almost any object with text labels. They are constructed using the L string macro prefix.

using CairoMakie

f = Figure(fontsize = 18)

Axis(f[1, 1],
title = L"\frac{x + y}{\sin(k^2)}",
xlabel = L"\sum_a^b{xy}",
ylabel = L"\sqrt{\frac{a}{b}}"
)

f

You can also mix math-mode and text-mode:

using CairoMakie

f = Figure(fontsize = 18)

Axis(f[1,1], title=L"Some text and some math: $\frac{2\alpha+1}{y}$")

f

## Caveats

You can currently not change a text object which has been instantiated with a normal String input to use a LaTeXString. If you do this, the LaTeXString is converted to a String implicitly, losing its special properties. Instead it appears with \$ signs wrapped around.

Notice how the second axis loses its LaTeX title. You have to pass the L-string at axis construction.

using CairoMakie

f = Figure(fontsize = 18)

Axis(f[1, 1], title = L"\frac{x + y}{\sin(k^2)}")
ax2 = Axis(f[1, 2])
ax2.title = L"\frac{x + y}{\sin(k^2)}"

f

For implicitly created axes, you can do this via the axis keyword argument.

scatter(randn(50, 2), axis = (; title = L"\frac{x + y}{\sin(k^2)}"))