-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add MathJax / Latex support for offline plot/iplot/FigureWidget #1243
Conversation
we don't break existing code that relied on positional indexes
# Conflicts: # plotly/offline/offline.py # plotly/tests/test_core/test_offline/test_offline.py
plotly/offline/offline.py
Outdated
'/ajax/libs/mathjax/2.7.5/MathJax.js'))) | ||
elif (isinstance(include_mathjax, six.string_types) and | ||
include_mathjax.endswith('.js')): | ||
mathjax_script = '<script src="{url}"></script>'.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs ?config=TeX-AMS-MML_SVG
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, add STIX_Web
font config from mathjax_config
plotly/offline/offline.py
Outdated
Received value: {val} | ||
|
||
include_mathjax may be specified as False, 'cdn', or a string ending with '.js' | ||
""".format(typ=type(include_mathjax), val=include_mathjax)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use val=repr(include_mathjax)
to be a bit more clear
plotly/offline/offline.py
Outdated
|
||
if include_mathjax == 'cdn': | ||
mathjax_script = ( | ||
'<script src="{url}?config=TeX-AMS-MML_SVG"></script>'.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add STIX_Web
font config from mathjax_config
. This way appearance of exported html will match iplot
and FigureWidget
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an example on how to use include_mathjax='cdn'
in a Jupyter notebook? For instance where would I enable LaTeX in plotly in the following block?
import plotly.offline as py
py.init_notebook_mode()
import plotly.graph_objs as go
from ipywidgets import interact
fig = go.FigureWidget()
I don't seem to get LaTeX working in the resulting interactive plots.
Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @dealmeidavf ,
include_mathajx
is only needed for plotly.offline.plot
. For FigureWidget
and plotly.offline.iplot
Jupyter's internal MathJax should be used automatically.
import plotly.graph_objs as go
go.FigureWidget(layout={'title': '$\LaTeX$'})
Could you open a new issue with your browser info, and whether you're using the classic notebook of JupyterLab? There are some issues with FireFox still, so try it out with Chrome if you haven't. Also, in JupyterLab you sometimes need to run a markdown cell containing LaTeX first so that the MathJax is initialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I am using Jupyter notebook in the anaconda navigator on a Mac. LaTeX does not work on a Mac Firefox. It works on Safari. I am new to plotly but a user of matplotlib. The interactive plots in plotly using ipywidgets are amazing!
…ly#1243) * Add include_mathjax argument to plotly.offline.plot * Add MathJax support for plotly.offline.iplot in the notebook * Add MathJax/LaTeX support for FigureWidget
Overview
This PR adds support for displaying figures with LaTeX typesetting using:
plotly.offline.plot
for standalone HTMLplotly.offline.iplot
inline in the classic notebookFigureWidget
:To be effective, these changes require unreleased changes in plotly.js master. In particular (plotly/plotly.js#2994). These will be available as plotly.js 1.42 which will be included with plotly.py 3.4.0 release.
plotly.offline.plot
changesA new
include_mathjax
argument has been added toplotly.offline.plot
. This argument mirrors theinclude_plotlyjs
argument and supports a subset of its options. It defaults toFalse
, matching the existing behavior of not adding any MathJax related code to the resulting HTML file/div. Setting it to'cdn'
adds a script tag referencing a predefined CDN locaiton, and setting it to a string ending with'.js'
allows the user to specify a custom CDN path to be included in the script tag.Full docstring
iplot and FigureWidget
The
iplot
andFigureWidget
changes do not involve any API updates. They make it possible for plotly.js to take advantage of the MathJax instance already in use by the Jupyter Notebook and JupyterLab.Outstanding issues
The only outstanding issue is that unlike the classic notebook, JupyterLab doesn't seem to load the global MathJax instance until it is needed by the markdown renderer. See jupyter-widgets/ipywidgets#2253. This may not be something we can address in the 3.4.0 timeframe.