Probably a silly/simple question… I have tried to strip down the essence of my problem to illustrate what I want to do — the example doesn’t fully illustrate the usefulness:
The idea is to define a label for a plot using LaTeXStrings notation, say:
plot!(label=L"x")
and replace the x with something else, say L"\frac{\Theta}{T}".
So my attempt was:
xx = L"\frac{\Theta}{T}"
plot(f,label=L"$(xx)$")
This doesn’t work.
I hope this gives an idea of what I want to do — the x I have used in the example will in reality be some f(x)… if I insert the true expression for x (say, L"\frac{\Theta}{T}"), the label expression becomes long/cumbersome to type, and I’m hoping I can replace the x by interpolation/substitution – somewhat like macros in LaTeX.
You can use the LaTeXString constructor (which accepts string interpolation because it is not a string macro) but it removes quite a few of the advantages of using LaTeXStrings in the first place.
Thanks, korsbo. In addition to switching from L"..." to raw"...", it was also necessary to switch from LaTeXString(...) to latexstring(...).
To make it pretty (with flexible parenthesis), it got quite complex, though:
xx = raw"\frac{\Theta_\mathrm{E}}{T_0}"
label=latexstring("3\\left($xx\\right)^2\\frac{\\exp\\left($xx\\right)}{\\left(\\exp\\left($xx\\right)-1\\right)^2}")
leading to what I wanted.
Thanks again. It could probably have been automated somewhat, but perhaps the problem is rare so it is not worthwhile…
If you are just using this for plot labels and are willing to escape all of the backslashes etcetera, you don’t need to use LaTeXString at all — at the end of the day, it is just passed as an ordinary string to the plot backend.
One thing that would be nice would be for LaTeXString to support some custom interpolation syntax, e.g. L"\frac{\Theta}{$$x}", so that you get the advantage of not having to escape the backslashes etcetera but you can still interpolate. I’m not sure what syntax to use, though. $$x seems problematic because $$ in LaTeX is a display equation.