From 4b0ab13fe86b714ac1a906aa6f2dc35c2c176198 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Tue, 3 May 2022 09:26:26 -0400 Subject: [PATCH 1/2] ensure having MathJax.Hub before set config for MathJax v2 --- packages/javascript/jupyterlab-plotly/src/Figure.ts | 8 ++++++-- packages/python/plotly/plotly/io/_base_renderers.py | 2 +- packages/python/plotly/plotly/io/_html.py | 2 +- packages/python/plotly/plotly/offline/offline.py | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/javascript/jupyterlab-plotly/src/Figure.ts b/packages/javascript/jupyterlab-plotly/src/Figure.ts index 0540354697..5ae3c9b070 100644 --- a/packages/javascript/jupyterlab-plotly/src/Figure.ts +++ b/packages/javascript/jupyterlab-plotly/src/Figure.ts @@ -826,9 +826,13 @@ export class FigureView extends DOMWidgetView { this.model.on("change:_py2js_update", this.do_update, this); this.model.on("change:_py2js_animate", this.do_animate, this); - // MathJax configuration + // MathJax v2 configuration // --------------------- - if ((window as any).MathJax) { + if ( + (window as any).MathJax && + (window as any).MathJax.Hub && + (window as any).MathJax.Hub.Config + ) { (window as any).MathJax.Hub.Config({ SVG: { font: "STIX-Web" } }); } diff --git a/packages/python/plotly/plotly/io/_base_renderers.py b/packages/python/plotly/plotly/io/_base_renderers.py index 2142d1a756..f4ccd0c0f8 100644 --- a/packages/python/plotly/plotly/io/_base_renderers.py +++ b/packages/python/plotly/plotly/io/_base_renderers.py @@ -236,7 +236,7 @@ def __init__(self, width=None, height=None, scale=None, engine="auto"): window.PlotlyConfig = {MathJaxConfig: 'local'};""" _mathjax_config = """\ -if (window.MathJax) {MathJax.Hub.Config({SVG: {font: "STIX-Web"}});}""" +if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: "STIX-Web"}});}""" class HtmlRenderer(MimetypeRenderer): diff --git a/packages/python/plotly/plotly/io/_html.py b/packages/python/plotly/plotly/io/_html.py index d4f5d09406..b6f61facc5 100644 --- a/packages/python/plotly/plotly/io/_html.py +++ b/packages/python/plotly/plotly/io/_html.py @@ -20,7 +20,7 @@ _mathjax_config = """\ """ diff --git a/packages/python/plotly/plotly/offline/offline.py b/packages/python/plotly/plotly/offline/offline.py index 7afc79d85f..3060b67d12 100644 --- a/packages/python/plotly/plotly/offline/offline.py +++ b/packages/python/plotly/plotly/offline/offline.py @@ -190,7 +190,7 @@ def _get_jconfig(config=None): _mathjax_config = """\ """ From 13f7c91f7ba0c89ded4383b35ac0ffc46f563060 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Tue, 3 May 2022 09:49:32 -0400 Subject: [PATCH 2/2] refactor using ? --- packages/javascript/jupyterlab-plotly/src/Figure.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/javascript/jupyterlab-plotly/src/Figure.ts b/packages/javascript/jupyterlab-plotly/src/Figure.ts index 5ae3c9b070..6b0b4a6334 100644 --- a/packages/javascript/jupyterlab-plotly/src/Figure.ts +++ b/packages/javascript/jupyterlab-plotly/src/Figure.ts @@ -828,13 +828,7 @@ export class FigureView extends DOMWidgetView { // MathJax v2 configuration // --------------------- - if ( - (window as any).MathJax && - (window as any).MathJax.Hub && - (window as any).MathJax.Hub.Config - ) { - (window as any).MathJax.Hub.Config({ SVG: { font: "STIX-Web" } }); - } + (window as any)?.MathJax?.Hub?.Config?.({ SVG: { font: "STIX-Web" } }); // Get message ids // ---------------------