# Latex typesetting in Plots with plotly backend?

**URL:** <https://discourse.julialang.org/t/latex-typesetting-in-plots-with-plotly-backend/35545>\
**Category:** General Usage\
**Tags:** question, plotting\
**Created:** [March 4, 2020, 10:49pm UTC](https://discourse.julialang.org/t/latex-typesetting-in-plots-with-plotly-backend/35545 "2020-03-04T22:49:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brunopjacob](https://avatars.discourse-cdn.com/v4/letter/b/41988e/32.png) [@brunopjacob](https://discourse.julialang.org/u/brunopjacob)\
**Post date:** [March 4, 2020, 10:49pm UTC](https://discourse.julialang.org/t/latex-typesetting-in-plots-with-plotly-backend/35545/1 "2020-03-04T22:49:03Z")

</div>

I am using Plots.jl and plotly for making plots, but I would like to have my legend, title and labels typed in latex. Using LaTeXStrings and the syntax L"…" works for gr and pyplot backends, but not for plotly. Does anyone have any idea how to write latex strings with plotly?

thanks,  
bruno

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 5, 2020, 9:45am UTC](https://discourse.julialang.org/t/latex-typesetting-in-plots-with-plotly-backend/35545/2 "2020-03-05T09:45:48Z")

</div>

This doesn’t answer your question, but if you want fully customizable LaTeX, consider

> **[GitHub - KristofferC/PGFPlotsX.jl: Plots in Julia using the PGFPlots LaTeX...](https://github.com/KristofferC/PGFPlotsX.jl)**
>
> Plots in Julia using the PGFPlots LaTeX package. Contribute to KristofferC/PGFPlotsX.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![hhaensel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hhaensel/32/1207_2.png) [@hhaensel](https://discourse.julialang.org/u/hhaensel)\
**Post date:** [May 15, 2020, 8:12am UTC](https://discourse.julialang.org/t/latex-typesetting-in-plots-with-plotly-backend/35545/3 "2020-05-15T08:12:12Z")

</div>

Currently it doesn’t work in the Juno IDE, but it does work in IJulia, if you copy the correct fonts to the mathjax directory:

- Download [MathJax-2.7.7.zip](https://github.com/mathjax/MathJax/releases/tag/2.7.7)
- copy the `jax` -folder to `C:\Users\<username>\.julia\conda\3\Lib\site-packages\notebook\static\components\MathJax` or wherever this is on your system. Note that there might be more MathJax folders, (e.g. `C:\Users\<username>\.julia\conda\3\pkgs\notebook-6.0.3-py36_0\Lib\site-packages\notebook\static\components\MathJax`, but only one is the true source for the server.

The background seems to be that Mathjax changed the default font to TeX, but the current distribution that comes with Jupyter only contains Stix-Web. I have [posted](https://stackoverflow.com/a/61803319/12074150) this recently on stackoverflow.

```julia
using Plots, LaTeXStrings

plotly()
Plots.plot(1:4, [[1,4,9,16], [0.5, 2, 4.5, 8]], 
    labels = [L"\alpha_{1c} = 352 \pm 11 \text{ km s}^{-1}" L"\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}"],
    xlabel = L"\sqrt{(n_\text{c}(t|{T_\text{early}}))}",
    ylabel = L"d, r \text{ (solar radius)}"
    )

```

produces  
 ![p6](https://global.discourse-cdn.com/julialang/original/3X/2/d/2dafe2cda0b4dce5cfae23697419d6dc08758bcd.png)

EDIT:  
The following lines make it available in Juno. Make sure, Conda is installed and the files are copied as described above.

```julia
using Plots, LaTeXStrings

plotly()

import Plots.plotly_html_head
import Conda.ROOTENV

function mathjax()
    mathjaxdir = joinpath(ROOTENV, "Lib\\site-packages\\notebook\\static\\components\\MathJax")
    mathjaxfile = joinpath(mathjaxdir, "MathJax.js?config=TeX-AMS-MML_HTMLorMML-full")
    return """<script type="text/javascript" src="$mathjaxfile"></script>"""
end

function Plots.plotly_html_head(plt::Plots.Plot)
    local_file = ("file://" * Plots.plotly_local_file_path)
    plotly = Plots.use_local_dependencies[] ? Plots.local_file : Plots.plotly_remote_file_path
    if Plots.isijulia() && !Plots.ijulia_initialized[]
        # using requirejs seems to be key to load a js depency in IJulia!
        # https://requirejs.org/docs/start.html
        # https://github.com/JuliaLang/IJulia.jl/issues/345
        display("text/html", """
        <script type="text/javascript">
        requirejs([$(repr(plotly))], function(p) {
        window.Plotly = p
        });
        </script>
        """)
        ijulia_initialized[] = true
    end
    return """$(mathjax())
    <script src=$(repr(plotly))></script>"""
end

```
