Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaTeX not rendering in Plotly figures #8131

Open
stephteo opened this issue Nov 1, 2021 · 6 comments
Open

LaTeX not rendering in Plotly figures #8131

stephteo opened this issue Nov 1, 2021 · 6 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@stephteo
Copy link

stephteo commented Nov 1, 2021

Environment data

  • VS Code version: 1.61.2
  • Jupyter Extension version (available under the Extensions sidebar): v2021.9.1101343141
  • Python Extension version (available under the Extensions sidebar): v2021.10.1365161279
  • OS (Windows | Mac | Linux distro) and version: Mac Big Sur Version 11.6
  • Python and/or Anaconda version: Python 3.9.7
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): XXX
  • Jupyter server running: Tried both Local and Remote
  • Plotly version: 4.14.3

Expected behaviour

Successfully have LaTeX render in Plotly figures when running on either Jupyter Notebook or JupyterLab from a Chrome browser (Version 95.0.4638.54). Tested this with the examples directly from Plotly: https://plotly.com/python/LaTeX/

import plotly.express as px

fig = px.line(x=[1, 2, 3, 4], y=[1, 4, 9, 16], title=r'$\alpha_{1c} = 352 \pm 11 \text{ km s}^{-1}$')
fig.update_layout(
    xaxis_title=r'$\sqrt{(n_\text{c}(t|{T_\text{early}}))}$',
    yaxis_title=r'$d, r \text{ (solar radius)}$'
)
fig.show()

Screen Shot 2021-11-01 at 3 59 29 PM

import plotly.graph_objs as go

fig = go.Figure()
fig.add_trace(go.Scatter(
    x=[1, 2, 3, 4],
    y=[1, 4, 9, 16],
    name=r'$\alpha_{1c} = 352 \pm 11 \text{ km s}^{-1}$'
))
fig.add_trace(go.Scatter(
    x=[1, 2, 3, 4],
    y=[0.5, 2, 4.5, 8],
    name=r'$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$'
))
fig.update_layout(
    xaxis_title=r'$\sqrt{(n_\text{c}(t|{T_\text{early}}))}$',
    yaxis_title=r'$d, r \text{ (solar radius)}$'
)
fig.show()

Screen Shot 2021-11-01 at 3 59 36 PM

Note: Using Chrome because there is a bug in Firefox that prevents proper rendering of Plotly figures with Mathjax (plotly/plotly.js#5993)

It looks like this may be related to this issue: #6802 since you can wrap the above figure in Plotly FigureWidget:

f = go.FigureWidget(fig)
f.show()

Actual behaviour

No LaTeX rendering when using the same Jupyter notebook in VS Code.

Screen Shot 2021-11-01 at 3 58 34 PM

Screen Shot 2021-11-01 at 3 58 28 PM

Steps to reproduce:

Simply run any of the above code in VS Code with the same environment as listed above.

@stephteo stephteo added the bug Issue identified by VS Code Team member as probable bug label Nov 1, 2021
@rchiodo
Copy link
Contributor

rchiodo commented Nov 1, 2021

Thanks for the bug. Related issue #7801

@rchiodo rchiodo removed their assignment Nov 1, 2021
@DonJayamanne
Copy link
Contributor

Duplicate of #7801

@DonJayamanne DonJayamanne marked this as a duplicate of #7801 Nov 2, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2022
@amunger amunger reopened this Dec 6, 2022
@amunger amunger closed this as completed Dec 6, 2022
@amunger amunger reopened this Dec 6, 2022
@amunger
Copy link
Contributor

amunger commented Dec 6, 2022

re-opening this since it has a good explanation of the remaining issue - that latex doesn't render within plotly widgets

@tomas-mazak
Copy link

tomas-mazak commented Jun 13, 2023

Hi all, I have the same issue, but seeing exactly the same using Jupyter Lab as well. Did a little bit of digging, and found this plotly issue: plotly/plotly.py#515

Based on the discussion there, I've put together this workaround, that seems to work in VSCode as well:

import plotly
from IPython.display import display, HTML

plotly.offline.init_notebook_mode()
display(HTML(
    '<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_SVG"></script>'
))

@janosh
Copy link
Contributor

janosh commented Sep 25, 2023

@tomas-mazak Thanks for the workaround!

Would be great if this issue could be revisited so plotly LaTeX labels in VS Code work out of the box. Thanks!

rawlins added a commit to rawlins/lambda-notebook that referenced this issue Oct 4, 2023
This package relies on MathJax within HTML working in order to render
derivations, and this is broken in VSCode (the relevant bug is
microsoft/vscode-jupyter#7801, but it seems to
have been auto-closed without resolution; see also
https://github.com/microsoft/vscode-jupyter/issues/12537 and maybe
microsoft/vscode-jupyter#8131). It's possible
that given time I'll be able to find a workaround (as I did for colab),
but this looks if anything less trivial than colab -- since there's no
browser tools etc., and google searches are much less promising. For
now, directly flag the issue to users as a vscode-jupyter issue.
@mfouesneau
Copy link

This fix the title but removes the rest of the labels for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

7 participants