# L strings not working in Makie

Hello. First post on this forum so I apologize if I fall short of the conventions.

I can’t get L strings to work with Makie on Jupyter Notebook. I just installed Makie, CairoMakie and MakieTeX. I couldn’t get my own examples to work, so I just copied one of the examples from the tutorial, which also doesn’t work:

First, if I just do as quoted in the code (see below), I get the error: LoadError: UndefVarError: @L_str not defined in expression starting at In[3]:6

using Makie, MakieTeX
using CairoMakie

fig = Figure()
l1 = Label(
fig[1, 1], L"A \emph{convex} function $f \in C$ is \textcolor{blue}{denoted} as \tikz{\draw[line width=1pt, >->] (0, -2pt) arc (-180:0:8pt);}";
tellwidth = false, tellheight = true
)
ax1 = Axis(
fig[2, 1];
xtickformat = x -> latexstring.("a_{" .* string.(x) .* "}"),
ytickformat = x -> latexstring.(string.(x)),
ylabel = L"\displaystyle \Phi(\vec x) = f(\vec x) + g(V)",
)
heatmap!(ax1, Makie.peaks())
fig

If I use LaTexStrings, the error goes away, but the L strings don’t seem to work:

using Makie, MakieTeX
using CairoMakie, LaTeXStrings

fig = Figure()
l1 = Label(
fig[1, 1], L"A \emph{convex} function $f \in C$ is \textcolor{blue}{denoted} as \tikz{\draw[line width=1pt, >->] (0, -2pt) arc (-180:0:8pt);}";
tellwidth = false, tellheight = true
)
ax1 = Axis(
fig[2, 1];
xtickformat = x -> latexstring.("a_{" .* string.(x) .* "}"),
ytickformat = x -> latexstring.(string.(x)),
ylabel = L"\displaystyle \Phi(\vec x) = f(\vec x) + g(V)",
)
heatmap!(ax1, Makie.peaks())
fig

Thanks a lot for any help.

You do not need MakieTeX, which was a different attempt at adding LaTeX capabilities to Makie. Now, this is built-in via the dependency MathTeXEngine.jl. I assume you got an old version of Makie due to installing MakieTeX. Just remove that, update, and you should be good to go.

However, I note that you use complex expressions using tikz etc in your L-strings, this is not supported by MathTeXEngine, which is merely an approximation of LaTeX but doesn’t actually use it. That was a benefit of the old MakieTeX approach, however it was quite slow due to the roundtrip. MathTeXEngine, while limited, also works for interactive figures with GLMakie.

Thanks a lot. I managed to update to new versions, but I still get the error LoadError: UndefVarError: @L_str not defined when running the following simple code

using Makie, CairoMakie

# Asset poliy function
f = Figure()
ax = Axis(f[1, 1],
title = L"Asset policy function $g(a,s)$",
xlabel = "a",
ylabel = "g(a,s)"
)
vlines!(ax, 0, color = :black)
hlines!(ax, 0, color = :black)

for i in 1:length(R.S)
s = round(R.S[i],digits=2)
X = R.asset_grid
Y = R.g[:,i]
lines!(ax, X, Y, label = "s = \$s")
end
axislegend()
f

You do still need a using LaTeXStrings line.
MakieTeX is the only one that needs to be removed.

You do not need using LaTeXStrings, the L" macro is re-exported by Makie. What version are you on? Latest is Makie v0.17.13.

And in case you didn’t, you need to restart Julia after updating versions so you actually get the new one.

This solved my issue, thanks a lot!