Hi, quick question on using latex strings for labeling plots in PyPlot.jl: what

Hi, quick question on using latex strings for labeling plots in PyPlot.jl: what would be a correct way to do in-place variable substitution? Here’s a piece of code that does not work ….

ax.set_title(L"$ $(a) $")

Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack, or pinging the poster here on Discourse so they can follow this thread.
(Original message :slack:) (More Info)

From the documentation:

If you want to perform string interpolation (inserting the values of other variables into your string), use %$ instead of the plain $ that you would use for interpolation in ordinary Julia strings. For example, if x=3 is a Julia variable, then L"y = %$x" will produce L"y = 3" .

2 Likes

L"y = %$x" will produce L"y = 3"

This is a very nice feature. (It has simplified my LaTeX strings considerably.) Thanks for adding it.

1 Like

Another option is explicit escaping:

ax.set_title("\$ $(a) \$")

But I agree that using %$ is nicer.