Create a LaTeX style title with the content of a variable [Solved]

My aim is to title my plot with a LaTeX style.
My code is the following

using Plots
using LaTeXStrings
V= "My Title"
plot([1,2],[1,2], title=L"&(V)")

But it does not work. I already used title=latexstring(V) , but the space disappeared (This idea come from LaTeX code for titles, labels,... with Plots.jl )

PS : Make title=L"My Title" is not a solution in my context

Thanks in advance

You can use %$V to interpolate V into the Latex string, see GitHub - JuliaStrings/LaTeXStrings.jl: convenient input and display of LaTeX equation strings for the Julia language.

In the default GR backend its a bit tricky but

plot([1,2],[1,2], title=latexstring("\\textrm{$(replace(V, " " => "~"))}"))

worked for this example.

With pgfplotsx()

plot([1,2],[1,2], title=LaTeXString(V))

would suffice.

1 Like

Thank you, I selected your first solution which works well.