# LaTeX-text does not work at all in plotly.offline?

**URL:** https://community.plotly.com/t/latex-text-does-not-work-at-all-in-plotly-offline/13800
**Category:** 📊 Plotly Python
**Created:** [September 21, 2018, 6:03am UTC](https://community.plotly.com/t/latex-text-does-not-work-at-all-in-plotly-offline/13800 "2018-09-21T06:03:30Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![LPG](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@LPG](https://community.plotly.com/u/LPG)
#### Post date: [September 21, 2018, 6:03am UTC](https://community.plotly.com/t/latex-text-does-not-work-at-all-in-plotly-offline/13800/1 "2018-09-21T06:03:30Z")

</div>

I tried the following code from the plotly homepage and only changed one word …

import plotly.plotly as py - \> new-\> import plotly.offline as py

```auto
import plotly.offline as py
import plotly.graph_objs as go

trace1 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[1, 4, 9, 16],
    name='$\\alpha_{1c} = 352 \\pm 11 \\text{ km s}^{-1}$'
)
trace2 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[0.5, 2, 4.5, 8],
    name='$\\beta_{1c} = 25 \\pm 11 \\text{ km s}^{-1}$'
)
data = [trace1, trace2]
layout = go.Layout(
    xaxis=dict(
        title='$\\sqrt{(n_\\text{c}(t|{T_\\text{early}}))}$'
    ),
    yaxis=dict(
        title='$d, r \\text{ (solar radius)}$'
    )
)
fig = go.Figure(data=data, layout=layout)
plot_url = py.plot(fig, filename='latex')

```

I got this graph:

 ![hc_2557](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/3/3efbbbfdf4980f92d023f1181252eecb174f42bd.png)

Why isn’t the LaTeX code interpreted? Do I somthing wronge?

Thanks,  
Peter

---

<div class="post-metadata">

### Author: ![jmmease](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jmmease/32/3706_2.png) [@jmmease](https://community.plotly.com/u/jmmease)
#### Post date: [September 21, 2018, 10:18am UTC](https://community.plotly.com/t/latex-text-does-not-work-at-all-in-plotly-offline/13800/2 "2018-09-21T10:18:32Z")

</div>

Hi Peter,

You’re not doing anything wrong, this is a know issue ([https://github.com/plotly/plotly.py/issues/515](https://github.com/plotly/plotly.py/issues/515)) that I’m actively working on ([https://github.com/plotly/plotly.py/issues/515](https://github.com/plotly/plotly.py/issues/515) and [https://github.com/plotly/plotly.js/pull/2994](https://github.com/plotly/plotly.js/pull/2994)). The plan is to release support for this in plotly.py 3.4.0, hopefully in about a month.

-Jon

---

<div class="post-metadata">

### Author: ![LPG](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@LPG](https://community.plotly.com/u/LPG)
#### Post date: [September 21, 2018, 12:29pm UTC](https://community.plotly.com/t/latex-text-does-not-work-at-all-in-plotly-offline/13800/3 "2018-09-21T12:29:37Z")

</div>

Jon, thanks for the answer. I was using the search before, but could not find what I was looking for.

Peter

---

<div class="post-metadata">

### Author: ![rtournem](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/rtournem/32/4496_2.png) [@rtournem](https://community.plotly.com/u/rtournem)
#### Post date: [December 5, 2018, 6:24pm UTC](https://community.plotly.com/t/latex-text-does-not-work-at-all-in-plotly-offline/13800/4 "2018-12-05T18:24:34Z")

</div>

Hello,  
I saw this thread on stackoverflow:

> <https://stackoverflow.com/questions/34500906/in-plotly-python-api-how-to-enable-latex-rendering-in-offline-mode>

I am using mac os x 10.14, python 3.7 and plotly 3.4.2 .

Unfortunately plotly.offline.iplot doesn’t display latex text on the chrome browser:

 ![44](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/a/a11255779cef3102f89dfb731ec28f4798e1ffaa.png)

The worst is that, even if the web version shows me the latex text, it does not save it in png (I see in this case J\_1)! I cannot exploit my graphs! I am reduced to produce the figure in plotly and add the latex inscription by hand using illustrator…

Thanks for the attention!

---

<div class="post-metadata">

### Author: ![jmmease](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jmmease/32/3706_2.png) [@jmmease](https://community.plotly.com/u/jmmease)
#### Post date: [December 6, 2018, 11:15am UTC](https://community.plotly.com/t/latex-text-does-not-work-at-all-in-plotly-offline/13800/5 "2018-12-06T11:15:04Z")

</div>

Hi @rtournem,

What is your browser version? Here’s what I see with this simple example on Chrome Version 70.0.3538.102 (I’m also on OS X). Could you try out this exact example?

```python
from plotly.offline import init_notebook_mode, iplot
import plotly.graph_objs as go
init_notebook_mode()

fig = go.Figure(layout={'title': '$J_1$'})
iplot(fig)

```

 ![newplot%20(15)](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/7/738f14e6a767c4b0e06750297cbfd05a559d67a3.png)

The LaTeX title is also preserved when I click the modebar to export as an image, or when I export using orca with `plotly.io.write_image`.

Are you working in the classic Jupyter notebook or in JupyterLab? Also, does LaTeX work for you inside a markdown cell? e.g. put

```nohighlight
variable $J_1$

```

in a Jupyter Notebook markdown cell and see if this renders as LaTeX.

-Jon

---

<div class="post-metadata">

### Author: ![LPG](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@LPG](https://community.plotly.com/u/LPG)
#### Post date: [December 7, 2018, 8:59am UTC](https://community.plotly.com/t/latex-text-does-not-work-at-all-in-plotly-offline/13800/6 "2018-12-07T08:59:22Z")

</div>

Hi Jon,

Encouraged through your answer, I tried your example code. It works fine in my Jupiter notebook too. In addition, I’m able to export this graph to plot.ly and get an perfect graph in the browser too.

Then I tried my code from the first post:

```auto
import plotly.offline as py
import plotly.graph_objs as go
import plotly.io as pio

trace1 = go.Scatter(
   x=[1, 2, 3, 4],
   y=[1, 4, 9, 16],
   name='$\\alpha_{1c} = 352 \\pm 11 \\text{ km s}^{-1}$'
)
trace2 = go.Scatter(
   x=[1, 2, 3, 4],
   y=[0.5, 2, 4.5, 8],
   name='$\\beta_{1c} = 25 \\pm 11 \\text{ km s}^{-1}$'
)
data = [trace1, trace2]
layout = go.Layout(
   xaxis=dict(
       title='$\\sqrt{(n_\\text{c}(t|{T_\\text{early}}))}$'
   ),
   yaxis=dict(
       title='$d, r \\text{ (solar radius)}$'
   )
)
fig = go.Figure(data=data, layout=layout)
#pio.write_image(fig, 'pic_23.png', width = 1280, height = 1024)
plot_url = py.plot(fig, filename='latex')

```

If I run this code as shown, I get an graph opened up in my browser, which isn’t right. It doesn’t matter, whether I sue IE or Chrome. It looks like:

 ![hc_2617](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/4/45c8c7a6d498927f515aebf2f7eba2f9dc0a3693.png)

If I uncommand the second to last command line, orca writes an perfect image to the disk!

 ![pic_23](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/c/c11cc6235a5cae3ee77ac5f6a96e0ffd4d68ce55.png)  
It seems to me, that the plot command from plotly.offline does not work we would expect.

Thanks again for your work!

Peter

---

<div class="post-metadata">

### Author: ![jmmease](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jmmease/32/3706_2.png) [@jmmease](https://community.plotly.com/u/jmmease)
#### Post date: [December 7, 2018, 11:13am UTC](https://community.plotly.com/t/latex-text-does-not-work-at-all-in-plotly-offline/13800/7 "2018-12-07T11:13:43Z")

</div>

Hi @LPG,

When outputting a plot to an HTML file, you need to explicitly enable MathJax in the output. Replace your last line with

```auto
plot_url = py.plot(fig, filename='latex', include_mathjax='cdn')

```

Hope that helps!  
-Jon

---

<div class="post-metadata">

### Author: ![LPG](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@LPG](https://community.plotly.com/u/LPG)
#### Post date: [December 7, 2018, 12:15pm UTC](https://community.plotly.com/t/latex-text-does-not-work-at-all-in-plotly-offline/13800/8 "2018-12-07T12:15:57Z")

</div>

Now it’s perfect! It works! Now can I do what I would like to do, wonderful graphs.

Thanks a lot!

Peter
