You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm wondering if there has been progress on this issue? Specifically, I would like to be able to render latex in the axis titles/labels of a graph.
I created dash-katex, a library that let you render latex inside a component DashKatex, obviously using katex js. This does not solve the problem of rendering latex inside a plotly graph object, but lets you dynamically run latex inside divs.
Is there any progress on this? Latex support is quite important for scientific dashboards...
Reacted by S1NH, peytondmurray-voltaiq, Collin McCarthy, Antoine Roy-Gobeil, Sun, Jeff Candy, Jesse Knight, Peter Sharpe, Lev Khoroshansky, Max Callaghan and 9 more
Well, now I'm confused. It looks like dynamic MathJax in axes labels now works. I thought that this was not working before. Can anybody confirm that this was part of the problem and now fixed?
This MWE will compile the user-input LaTeX live and render the result on y-axis label.
This asks MathJax to scan the page for any new $...$ every 1000 milliseconds, and re-render it. It solved all my MWE here without any extra modification of the Python code. You may want to increase the refresh rate by decreasing 1000. I tried 1 and it was very fast, but used CPU 5% ¯\_(ツ)_/¯.
Just one thing is a bit suboptimal, but that's a luxury problem. When I set the axis label to something like $\sigma_x$ [mm], only the sigma_x part is rendered, and the units are omitted.
Ugh. It seems the mathjax-refresh hack somehow interferes with the dynamic axis labelling, making it very slow. Apologies that I didn't test this enough before.
@renatobellotti I wouldn't call that a luxury problem. Mixing TeX and non-TeX might be quite common, and we shouldn't have to wrap all non-TeX in \textrm{...}.
Sometime in the past year it seems TeX support was added to axis labels, but I can't find any commit that references this. Essentially I'd like to turn that off, since I'd prefer the refresh hack.
EDIT: It seems our problems might be upstream at: plotly.js
@jessexknight , thank you for your solution, it works nice if there is a Graph output!
However, when there is no Graph output (but the app has some other outputs), then it seems MathJax is not loaded and the latex code in other controls is not rendered. Is there a quick workaround?
To get standard Plotly.s LaTeX support in figure titles and axis labels, it looks like doing the Dash equivalent of what's in the Plotly.js readme does work:
add external_scripts=["https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" ] to the app = dash.Dash() call
add a JS file to assets containing window.PlotlyConfig = {MathJaxConfig: 'local'};
edit: hmmm it doesn't seem like point 2 here is actually needed.
October 2021: MathJax and Plotly have mystery. I got this to work by adding an 'assets' folder as further posted by jessexknight. The bigger question is whether/when Plotly will provide official support for Latex/MathJax in general.
March 14, 2022: Dash 2.3.0 supports Mathjax 3 ... use it. Mystery solved for me. Thanks Plotly and Equinor.
Hey @haduong83, I think you're not invoking the script properly. Try checking here and take a look at the heading "Integrating MathJax into the template".
Activity
chriddyp commentedon Apr 9, 2018
I wonder if the solution is just to add MathJax to https://github.com/plotly/dash-core-components/blob/d034e25f6f56423ef2de7e5905328396040cf4d8/dash_core_components/__init__.py#L25-L29
jessexknight commentedon May 24, 2018
It is possible to render MathJax in static Dash content, but not in dynamic content.
Here is a MWE
related community.plot.ly thread
aztan2 commentedon Aug 22, 2018
Hi, I'm wondering if there has been progress on this issue? Specifically, I would like to be able to render latex in the axis titles/labels of a graph.
jessexknight commentedon Aug 22, 2018
There is a pull request in progress to solve this issue, but it seems like it has stalled at the moment.
xhluca commentedon Nov 2, 2018
I created dash-katex, a library that let you render latex inside a component
DashKatex, obviously using katex js. This does not solve the problem of rendering latex inside a plotly graph object, but lets you dynamically run latex inside divs.Link: https://github.com/xhlulu/dash-katex
vdkotian commentedon Jan 4, 2019
Is this issue still available for development? I am seeking to contribute.
renatobellotti commentedon Dec 9, 2019
Is there any progress on this? Latex support is quite important for scientific dashboards...
renatobellotti commentedon Feb 5, 2020
What about now?
yueyericardo commentedon Mar 20, 2020
After searching around, I found Latex to Image API very useful.
And I wrote a function to make it work with
$a+b$and$$a+b$$for dcc.markdown.renatobellotti commentedon Apr 2, 2020
Does this also work for axis labels?
jessexknight commentedon Apr 2, 2020
I will look into this in the next 2 weeks. For now, here are some ideas somebody may want to try:
2 remaining items
yueyericardo commentedon Apr 16, 2020
Hey sorry for the delay, I just created a complete example https://github.com/yueyericardo/dash_latex explain how to make it work.
Example2 will come later.
jessexknight commentedon Apr 16, 2020
Well, now I'm confused. It looks like dynamic MathJax in axes labels now works. I thought that this was not working before. Can anybody confirm that this was part of the problem and now fixed?
This MWE will compile the user-input LaTeX live and render the result on y-axis label.
jessexknight commentedon Apr 16, 2020
Okay. Here is another hack that will probably solve all dynamic LaTeX rendering issues but you have to decide the refresh rate (trading speed vs CPU).
After including MathJax like above:
add the file
./assets/mathjax-refresh.jswith the following content:This asks MathJax to scan the page for any new
$...$every 1000 milliseconds, and re-render it. It solved all my MWE here without any extra modification of the Python code. You may want to increase the refresh rate by decreasing1000. I tried1and it was very fast, but used CPU 5%¯\_(ツ)_/¯.more info:
renatobellotti commentedon Apr 21, 2020
That workaround seems to work, thank you so much!
Just one thing is a bit suboptimal, but that's a luxury problem. When I set the axis label to something like
$\sigma_x$ [mm], only the sigma_x part is rendered, and the units are omitted.Workaround:
Use
$\sigma_x \mathrm{[mm]}$instead.jessexknight commentedon Apr 21, 2020
Ugh. It seems the
mathjax-refreshhack somehow interferes with the dynamic axis labelling, making it very slow. Apologies that I didn't test this enough before.@renatobellotti I wouldn't call that a luxury problem. Mixing TeX and non-TeX might be quite common, and we shouldn't have to wrap all non-TeX in
\textrm{...}.Sometime in the past year it seems TeX support was added to axis labels, but I can't find any commit that references this. Essentially I'd like to turn that off, since I'd prefer the refresh hack.
EDIT: It seems our problems might be upstream at: plotly.js
Davide-sd commentedon Oct 26, 2020
@jessexknight , thank you for your solution, it works nice if there is a Graph output!
However, when there is no Graph output (but the app has some other outputs), then it seems MathJax is not loaded and the latex code in other controls is not rendered. Is there a quick workaround?
jessexknight commentedon Oct 26, 2020
I don't have time to look into this right now but this may be useful, or perhaps any one of the the MathJax issues upstream at plotly.js
nicolaskruchten commentedon Feb 9, 2021
To get standard Plotly.s LaTeX support in figure titles and axis labels, it looks like doing the Dash equivalent of what's in the Plotly.js readme does work:
external_scripts=["https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" ]to theapp = dash.Dash()calladd a JS file toassetscontainingwindow.PlotlyConfig = {MathJaxConfig: 'local'};edit: hmmm it doesn't seem like point 2 here is actually needed.
nicolaskruchten commentedon Feb 9, 2021
This is sort of a known feature of how Plotly.js works at the moment: labels in figures are either all-LaTex or all-not-LaTeX.
haduong83 commentedon Sep 22, 2021
Hi,
I tried to add the configuration into my app:
and render the following equation:
but it is not working. I am using the following dash version:
dash==1.19.0
dash-bootstrap-components==0.11.3
dash-core-components==1.15.0
dash-html-components==1.1.2
dash-renderer==1.9.0
I also tried the code @jessexknight posted in https://community.plotly.com/t/mathjax-latex-in-dash/6653/11 but it did not work either.
Any ideas on what could be wrong?
Thanks,
wvwhome commentedon Oct 19, 2021
October 2021: MathJax and Plotly have mystery. I got this to work by adding an 'assets' folder as further posted by jessexknight. The bigger question is whether/when Plotly will provide official support for Latex/MathJax in general.
March 14, 2022: Dash 2.3.0 supports Mathjax 3 ... use it. Mystery solved for me. Thanks Plotly and Equinor.
nopria commentedon Oct 30, 2021
Have you looked into this?
https://chrisvoncsefalvay.com/2020/07/25/dash-latex/
chrisvoncsefalvay commentedon Dec 3, 2021
Hey @haduong83, I think you're not invoking the script properly. Try checking here and take a look at the heading "Integrating MathJax into the template".
archmoj commentedon Mar 17, 2022
Resolved by v2.3.0.