# PlutoPlotly: save a plot with LaTeX strings

**URL:** <https://discourse.julialang.org/t/plutoplotly-save-a-plot-with-latex-strings/110163>\
**Category:** General Usage\
**Tags:** latexstrings, plutoplotly\
**Created:** [February 13, 2024, 5:15pm UTC](https://discourse.julialang.org/t/plutoplotly-save-a-plot-with-latex-strings/110163 "2024-02-13T17:15:31Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![disberd](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@disberd](https://discourse.julialang.org/u/disberd)\
**Post date:** [February 13, 2024, 6:11pm UTC](https://discourse.julialang.org/t/plutoplotly-save-a-plot-with-latex-strings/110163/2 "2024-02-13T18:11:04Z")

</div>

Hi @VivMendes, you have to tell Kaleido (which is used internally to save plots) that it has to load mathjax or the plot will not render latex as you experienced there.

I do not think that the `savefig` from PlotlyJS has that functionality, but luckily you don’t need to use the outdated `savefig` in PlotlyJS with PlutoPlotly and you can directly use the smaller and more featureful PlotlyKaleido.jl package, which implemented mathjax in kaleido with [this PR](https://github.com/JuliaPlots/PlotlyKaleido.jl/pull/11).

With PlotlyKaleido (if you are on windows you may catch the problem of Kaleido always hanging that is mentioned [here](https://discourse.julialang.org/t/plotlyjs-causes-errors-cant-figure-out-how-to-use-plotlylight-how-to-use-plotly-from-julia/108853/29), [here](https://github.com/JuliaPlots/PlotlyKaleido.jl/issues/13) and in other places, but that is a problem of underlying library and is also present in PlotlyJS), you can simply use this code

```julia
# ╔═╡ 42cd34bf-7b19-4d01-87c2-b76d6ef01912
import Pkg

# ╔═╡ a18c9202-8390-4861-a33b-732b940dde7f
using PlutoUI , PlutoPlotly , LaTeXStrings

# ╔═╡ 90f140e1-33fa-4240-bb9e-112e3cd7c34a
begin
	Pkg.pkg"add Kaleido_jll@v0.1.0"
	using PlotlyKaleido
end

# ╔═╡ 9d18f8e9-8c4b-473e-a775-a29d01b4aae0
PlotlyKaleido.start(;mathjax = true)

# ╔═╡ 6eabfdc0-ca94-11ee-0ba2-7df4b3955314
begin
	

	fig2 = plot(1:300, [randn(300) randn(300)])
		
	relayout!(fig2, 
		height = 450,
		title_text = L"\text{A title with some LaTeX:} \sum \beta^i x_{t-i}", title_x = 0.5, 
		hovermode = "x", 
		yaxis_title = L"y(t), x(t)", 
		xaxis_title = L"t",
		xaxis_range=[-10 , 310]) 
	
	restyle!(fig2, 
		name = [L"\sigma^2_x = 1" , L"\sigma^2_y = 1"], 
		mode="markers+lines", line_width = 0.3, line_color = ["RoyalBlue", "Maroon"])
	
	fig2
	
	savefig(fig2, "fig2.pdf", width = 1000)
end

```

(I am importing `Pkg` and calling `Pkg.pkg""` to install a custom version of Kaleido\_jll without upsetting Pluto Pkg Manager to fix the issue mentioned above. If you don’t have problems on your machine with Kaleido you can skip that instruction).

This will generate the pdf with latex correctly:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/0/b02a1e21dffaf8fd61c7b82ed3fa4bcba9044fc4.jpeg)

As you can see, the only issue is that latex text is bold, but again that is an [issue with the underlying Kaleido library](https://github.com/plotly/plotly.py/issues/3828#issuecomment-1798544806) which has currently no fix.

---

_[View the full topic](https://discourse.julialang.org/t/plutoplotly-save-a-plot-with-latex-strings/110163)._
