# 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:** 1\
**Showing post:** 3

<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

```

---

_[View the full topic](https://discourse.julialang.org/t/latex-typesetting-in-plots-with-plotly-backend/35545)._
