The latex symbol is not working in a plot title

I’m using the symbol latex \lambda in Julia scripts (\lambda = 5). When I plot, I need to put the \lambda symbol in the Title, but it’s not working. I am using the Jupyter Notebook on Chrome!

using Plots
title_ = ["λ =$λ, n = $nn  " "" ""  "" ""] 

I don’t know why the symbol is not showing. Does anyone have any tips on how to resolve this?

You should probably mention what package you are using for plotting, GR through Plots.jl?

1 Like

Use the LaTeXStrings package and LaTeX-like markup.

using LaTeXStrings
title_ = L"\lambda=$λ"
plot(title=title_)
1 Like

It displays LaTeX even without LaTeXStrings:

using Plots
λ=5
title_ = "λ=$λ"
plot(title=title_, size=(300, 200))
1 Like

This seems to solve the problem, but other problems appear.

Plots.jl

Yes, I believe that the problem should not be Julia’s, but maybe an update is needed. Is that it?

Or

using Latexify
_title=@latexdefine λ

I checked it in REPL, and Jupyter Notebook, without any update.

The $ symbol is the standard symbol to “interpolate” in text strings, e.g., with x = 2, the string "Here, x = $x" works.

If you use LaTeXStrings, this will, however, not work because LaTeXStrings will interpret the $ character as indicating a LaTeX symbol.

Instead, in LaTeXStrings, you need to use %$ as interpolation symbol. So with x = 2, the string L"Here, $x = %$(x) should work.