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

Support version 3 of MathJax and add config.typesetMath #6073

Merged
merged 47 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
6231b4a
support for mathjax v3 as well
archmoj Dec 14, 2021
912fb1d
add PR log and adjust comments
archmoj Dec 24, 2021
b01c4e0
Update src/lib/svg_text_utils.js
archmoj Jan 3, 2022
a49e611
adjust mathjax element selection for v3
archmoj Jan 3, 2022
b568b61
correct bundle test flag for v3
archmoj Jan 3, 2022
cfbcc75
select glyphs only when needed
archmoj Jan 4, 2022
41e37b6
refactor mathjax selection
archmoj Jan 4, 2022
63964e2
refactor mathajx typeset return
archmoj Jan 4, 2022
6e4c968
select defs for mathjax v3
archmoj Jan 4, 2022
13fbb8d
add jasmine tests for v3
archmoj Jan 4, 2022
386dd87
refactor mathjax tmp node draw and selection
archmoj Jan 5, 2022
502c3e8
base to support chtml output in mathjax v3
archmoj Jan 5, 2022
1dd51fd
do not try to handle non-svg mathjax for now
archmoj Jan 5, 2022
4ba005f
Anton Akhmerov's workaround to mock v2 API for pages with both chtml …
archmoj Jan 5, 2022
04d8005
no need for mocking API v2 to handle both chtml & svg outputs
archmoj Jan 5, 2022
7be4e73
set and reset inline mathjax config
archmoj Jan 6, 2022
5cd3ba0
simplify
archmoj Jan 6, 2022
8e204e6
edit mathjax devtools
archmoj Jan 6, 2022
eeddb7b
simplify mathjax config
archmoj Jan 6, 2022
42d76e8
call defaultReady after resetting config and renderer
archmoj Jan 6, 2022
ec0e0d3
use startup.promise after startup.defaultReady
archmoj Jan 6, 2022
63e240e
fixup defs selection in v3
archmoj Jan 7, 2022
7b0ab24
run mathjax v2 and v3 in the same container
archmoj Jan 7, 2022
f0f283d
update PR log
archmoj Jan 7, 2022
f3f9424
update readme on mathjax v3
archmoj Jan 7, 2022
3a12c15
add image test for mathjax v3
archmoj Jan 8, 2022
8b4dba7
revise setting inlineMath for mathjax v3
archmoj Jan 10, 2022
41ae662
increase parallelism for jasmine tests
archmoj Jan 10, 2022
cbdcad5
modify readme
archmoj Jan 10, 2022
4bb1714
update package lock - exact 2.7.5 version
archmoj Jan 12, 2022
c48654d
align new mathjax dashboards to PR 6096
archmoj Jan 28, 2022
cb73ab7
Update README.md
archmoj Feb 1, 2022
ff983b6
Merge branch 'master' into mathjax-v3
archmoj Feb 1, 2022
0cdd3bb
improve example for how to control typeset at startup
archmoj Feb 15, 2022
9beda27
Merge remote-tracking branch 'origin/master' into mathjax-v3
archmoj Feb 15, 2022
cee5832
add typesetMath to config
archmoj Feb 23, 2022
b24f3f4
correct typesetMath
archmoj Feb 24, 2022
d2426f0
update draft log
archmoj Feb 24, 2022
1de176c
respect MathJax.config.tex.inlineMath
archmoj Mar 1, 2022
7677258
refactor functions for v2 and v3 and strict conditions
archmoj Mar 4, 2022
870e1ce
abstract load script for mathjax tests
archmoj Mar 4, 2022
600035d
move load script to test assests
archmoj Mar 4, 2022
353d393
use mathjax_test file for both v2 and v3
archmoj Mar 4, 2022
4d7869a
add tests for mathjax reset config & renderer
archmoj Mar 4, 2022
d5e10a7
fixup config of mathjax v3
archmoj Mar 4, 2022
1739f3d
Update src/plot_api/plot_config.js
archmoj Mar 4, 2022
ff75df4
adjust test and update schema
archmoj Mar 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ jobs:
name: Run jasmine tests (part D)
command: .circleci/test.sh bundle-jasmine

mathjax-firefox81:
mathjax-v2-firefox81:
docker:
# need '-browsers' version to test in real (xvfb-wrapped) browsers
- image: cimg/node:16.8.0-browsers
Expand All @@ -176,10 +176,10 @@ jobs:
- attach_workspace:
at: ~/
- run:
name: Test MathJax on firefox-81
command: .circleci/test.sh mathjax-firefox
name: Test MathJax v2 on firefox-81
command: .circleci/test.sh mathjax-v2-firefox

mathjax-firefox82:
mathjax-v2-firefox82:
docker:
# need '-browsers' version to test in real (xvfb-wrapped) browsers
- image: cimg/node:16.8.0-browsers
Expand All @@ -195,10 +195,10 @@ jobs:
- attach_workspace:
at: ~/
- run:
name: Test MathJax on firefox-82
command: .circleci/test.sh mathjax-firefox82+
name: Test MathJax v2 on firefox-82
command: .circleci/test.sh mathjax-v2-firefox82+

mathjax-firefoxLatest:
mathjax-v2-firefoxLatest:
docker:
# need '-browsers' version to test in real (xvfb-wrapped) browsers
- image: cimg/node:16.8.0-browsers
Expand All @@ -213,8 +213,26 @@ jobs:
- attach_workspace:
at: ~/
- run:
name: Test MathJax on firefox-latest
command: .circleci/test.sh mathjax-firefox82+
name: Test MathJax v2 on firefox-latest
command: .circleci/test.sh mathjax-v2-firefox82+

mathjax-v3-firefoxLatest:
docker:
# need '-browsers' version to test in real (xvfb-wrapped) browsers
- image: cimg/node:16.8.0-browsers
environment:
# Alaska time (arbitrary timezone to test date logic)
TZ: "America/Anchorage"
working_directory: ~/plotly.js
steps:
- browser-tools/install-browser-tools: &browser-versions
install-chrome: false
install-chromedriver: false
- attach_workspace:
at: ~/
- run:
name: Test MathJax v3 on firefox-latest
command: .circleci/test.sh mathjax-v3-firefox82+

make-baselines:
parallelism: 4
Expand Down Expand Up @@ -395,13 +413,16 @@ workflows:
- bundle-jasmine:
requires:
- install-and-cibuild
- mathjax-firefox81:
- mathjax-v2-firefox81:
requires:
- install-and-cibuild
- mathjax-v2-firefox82:
requires:
- install-and-cibuild
- mathjax-firefox82:
- mathjax-v2-firefoxLatest:
requires:
- install-and-cibuild
- mathjax-firefoxLatest:
- mathjax-v3-firefoxLatest:
requires:
- install-and-cibuild
- no-gl-jasmine:
Expand Down
13 changes: 9 additions & 4 deletions .circleci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,18 @@ case $1 in
exit $EXIT_STATE
;;

mathjax-firefox)
./node_modules/karma/bin/karma start test/jasmine/karma.conf.js --FF --bundleTest=mathjax --nowatch || EXIT_STATE=$?
mathjax-v2-firefox)
./node_modules/karma/bin/karma start test/jasmine/karma.conf.js --FF --bundleTest=mathjax_v2 --nowatch || EXIT_STATE=$?
exit $EXIT_STATE
;;

mathjax-firefox82+)
./node_modules/karma/bin/karma start test/jasmine/karma.conf.js --FF --skip-tags=noFF82 --bundleTest=mathjax --nowatch || EXIT_STATE=$?
mathjax-v2-firefox82+)
./node_modules/karma/bin/karma start test/jasmine/karma.conf.js --FF --skip-tags=noFF82 --bundleTest=mathjax_v2 --nowatch || EXIT_STATE=$?
exit $EXIT_STATE
;;

mathjax-v3-firefox82+)
./node_modules/karma/bin/karma start test/jasmine/karma.conf.js --FF --skip-tags=noFF82 --bundleTest=mathjax_v2 --nowatch || EXIT_STATE=$?
exit $EXIT_STATE
;;

Expand Down
34 changes: 34 additions & 0 deletions devtools/test_dashboard/index-mathjax3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<title>Plotly.js Devtools</title>
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Droid+Sans|PT+Sans+Narrow|Gravitas+One|Droid+Sans+Mono|Droid+Serif|Raleway|Old+Standard+TT"/>
<link rel="stylesheet" type="text/css" href="./style.css">
</head>
<body>
<header>
<img src="http://images.plot.ly/logo/plotlyjs-logo@2x.png" onClick="Tabs.reload();" />
<span id="reload-time"></span>

<input id="mocks-search" type="text" placeholder="mocks search" />
<input id="css-transform" type="text" placeholder="css transform" />
</header>

<section id="mocks-list"></section>
<div id="plots">
<div id="graph"></div>
</div>
<div id="snapshot"></div>

<script>
window.MathJax = window.MathJax || {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
}
};
</script>
<script src="../../node_modules/mathjax-v3/es5/tex-mml-svg.js"></script>
<script charset="utf-8" id="source" type="module">import "../../build/plotly.js"</script>
<script charset="utf-8" src="../../build/test_dashboard-bundle.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion devtools/test_dashboard/index-strict.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>
<div id="snapshot"></div>

<script src="../../node_modules/mathjax/MathJax.js?config=TeX-AMS-MML_SVG"></script>
<script src="../../node_modules/mathjax-v2/MathJax.js?config=TeX-AMS-MML_SVG"></script>
<script charset="utf-8" id="source" src="../../build/plotly.js"></script>
<script charset="utf-8" src="../../build/test_dashboard-bundle.js"></script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion devtools/test_dashboard/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>
<div id="snapshot"></div>

<script src="../../node_modules/mathjax/MathJax.js?config=TeX-AMS-MML_SVG"></script>
<script src="../../node_modules/mathjax-v2/MathJax.js?config=TeX-AMS-MML_SVG"></script>
<script charset="utf-8" id="source" type="module">import "../../build/plotly.js"</script>
<script charset="utf-8" src="../../build/test_dashboard-bundle.js"></script>
</body>
Expand Down
6 changes: 5 additions & 1 deletion devtools/test_dashboard/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var shortcutPaths = require('../../tasks/util/shortcut_paths');
var args = minimist(process.argv.slice(2), {});
var PORT = args.port || 3000;
var strict = args.strict;
var mathjax3 = args.mathjax3;

// Create server
var server = http.createServer(ecstatic({
Expand All @@ -25,7 +26,10 @@ var server = http.createServer(ecstatic({
// Make watchified bundle for plotly.js
var bundlePlotly = makeWatchifiedBundle(strict, function() {
// open up browser window on first bundle callback
open('http://localhost:' + PORT + '/devtools/test_dashboard/index' + (strict ? '-strict' : '') + '.html');
open('http://localhost:' + PORT + '/devtools/test_dashboard/index' + (
strict ? '-strict' :
mathjax3 ? '-mathjax3' : ''
) + '.html');
});

// Bundle devtools code
Expand Down
1 change: 1 addition & 0 deletions draftlogs/add_6073.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add support for MathJax version 3 [[#6073](https://github.com/plotly/plotly.js/pull/6073)]
23 changes: 19 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"test-requirejs": "node tasks/test_requirejs.js",
"test-plain-obj": "node tasks/test_plain_obj.js",
"test": "npm run test-jasmine -- --nowatch && npm run test-bundle && npm run test-image && npm run test-export && npm run test-syntax && npm run lint",
"mathjax3": "node devtools/test_dashboard/server.js --mathjax3",
"strict": "node devtools/test_dashboard/server.js --strict",
"start": "node devtools/test_dashboard/server.js",
"baseline": "node test/image/make_baseline.js",
Expand Down Expand Up @@ -152,7 +153,8 @@
"karma-viewport": "^1.0.8",
"lodash": "^4.17.21",
"madge": "^5.0.1",
"mathjax": "2.7.5",
"mathjax-v2": "npm:mathjax@2.7.5",
"mathjax-v3": "npm:mathjax@^3.2.0",
"minify-stream": "^2.1.0",
"npm-link-check": "^4.0.0",
"open": "^8.4.0",
Expand Down
73 changes: 58 additions & 15 deletions src/lib/svg_text_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,25 @@ function cleanEscapesForTex(s) {
}

function texToSVG(_texString, _config, _callback) {
var MathJaxVersion = parseInt(
(MathJax.version || '').split('.')[0]
) || -1;

if(!MathJaxVersion) {
Lib.log('No MathJax version:', MathJax.version);
}

var originalRenderer,
originalConfig,
originalProcessSectionDelay,
tmpDiv;

MathJax.Hub.Queue(
function() {
var v2SetConfig = function() {
originalConfig = Lib.extendDeepAll({}, MathJax.Hub.config);

originalProcessSectionDelay = MathJax.Hub.processSectionDelay;
if(MathJax.Hub.processSectionDelay !== undefined) {
// MathJax 2.5+
// MathJax 2.5+ but not 3+
MathJax.Hub.processSectionDelay = 0;
}

Expand All @@ -196,47 +203,83 @@ function texToSVG(_texString, _config, _callback) {
},
displayAlign: 'left',
});
},
function() {
};

var v2SetRenderer = function() {
// Get original renderer
originalRenderer = MathJax.Hub.config.menuSettings.renderer;
if(originalRenderer !== 'SVG') {
return MathJax.Hub.setRenderer('SVG');
}
},
function() {
};

var initiateMathJax = function() {
var randomID = 'math-output-' + Lib.randstr({}, 64);
tmpDiv = d3.select('body').append('div')
.attr({id: randomID})
.style({visibility: 'hidden', position: 'absolute'})
.style({'font-size': _config.fontSize + 'px'})
.text(cleanEscapesForTex(_texString));

return MathJax.Hub.Typeset(tmpDiv.node());
},
function() {
var tmpNode = tmpDiv.node();

if(MathJaxVersion < 3) {
return MathJax.Hub.Typeset(tmpNode);
} {
return MathJax.typeset([tmpNode]);
}
archmoj marked this conversation as resolved.
Show resolved Hide resolved
};

var finalizeMathJax = function() {
var glyphDefs = d3.select('body').select('#MathJax_SVG_glyphs');

if(tmpDiv.select('.MathJax_SVG').empty() || !tmpDiv.select('svg').node()) {
var q;
if(MathJaxVersion < 3) {
q = tmpDiv.select('.MathJax_SVG');
} else {
q = tmpDiv;
}

if(q.empty() || !tmpDiv.select('svg').node()) {
Lib.log('There was an error in the tex syntax.', _texString);
_callback();
} else {
var svgBBox = tmpDiv.select('svg').node().getBoundingClientRect();
_callback(tmpDiv.select('.MathJax_SVG'), glyphDefs, svgBBox);
_callback(q, glyphDefs, svgBBox);
}

tmpDiv.remove();
};

var v2ResetRenderer = function() {
if(originalRenderer !== 'SVG') {
return MathJax.Hub.setRenderer(originalRenderer);
}
},
function() {
};

var v2ResetConfig = function() {
if(originalProcessSectionDelay !== undefined) {
MathJax.Hub.processSectionDelay = originalProcessSectionDelay;
}
return MathJax.Hub.Config(originalConfig);
});
};

if(MathJaxVersion < 3) {
MathJax.Hub.Queue(
v2SetConfig,
v2SetRenderer,
initiateMathJax,
finalizeMathJax,
v2ResetRenderer,
v2ResetConfig
);
} else {
MathJax.startup.defaultReady();
MathJax.startup.promise.then(function() {
initiateMathJax();
finalizeMathJax();
});
}
}

var TAG_STYLES = {
Expand Down
2 changes: 1 addition & 1 deletion tasks/noci_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test_image () {
$root/../orca/bin/orca.js graph \
$root/test/image/mocks/mapbox_osm-style.json \
$root/test/image/mocks/mapbox_density0-legend.json \
--mathjax $root/node_modules/mathjax/MathJax.js \
--mathjax $root/node_modules/mathjax-v2/MathJax.js \
--plotly $root/build/plotly.js \
--mapbox-access-token "pk.eyJ1IjoicGxvdGx5LWpzLXRlc3RzIiwiYSI6ImNrNG9meTJmOTAxa3UzZm10dWdteDQ2eWMifQ.2REjOFyIrleMqwS8H8y1-A" \
--output-dir $root/test/image/baselines/ \
Expand Down
Loading