LaTeX in Julia -- Is there any way to make it work?

Hello!
I have been trying to get some LaTeX into my labels and this snippet from the docs has not worked in vscode’s julia notebook nor in the REPL.
I dug around and found some complicated workarounds that were limited to the html plots, but since I would like to save them as svg this wouldn’t help me that much.

If you want a MWE, doing the following

using Plots, LaTeXStrings


p = plot(rand(10),label = "test", )
p = xlabel!("\$\\alpha \\, F_\\mathrm{test}\$")
p = ylabel!(L"\Gamma^2")

produces this plot (using the GR backend):

While this:

using Plots, LaTeXStrings
plotlyjs()

p = plot(rand(10),label = "test", )
p = xlabel!("\$\\alpha \\, F_\\mathrm{test}\$")
p = ylabel!(L"\Gamma^2")

doesn’t render LaTeX properly:

If anyone has found a workaround I would be very grateful.

Cheers!

This rendering is handled by the MathJax library (version 2.7.5), which must be loaded in the environment where figures are being rendered. MathJax is included by default in Jupyter-like environments, but when embedding Plotly figures in other contexts it may be required to ensure that MathJax is separately loaded, for example via a <script> tag pointing to a content-delivery network (CDN).

Hi! If I understand correctly, this only works when saving to html, right? There is no way to load MathJax “internally” while rendering the plot in other formats, such as pdf or svg?

MathJax is a JavaScript library used to render the LaTeX you write in HTML into the way you want. When using LaTeX in PDF, it is common practice to have PDFTeX help you compile it. If you are using Jupyter, there are plugins that can help you generate .tex files or invoke PDFTex to generate PDFs for you.

1 Like