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 33 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
40 changes: 39 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
environment:
# Alaska time (arbitrary timezone to test date logic)
TZ: "America/Anchorage"
parallelism: 8
parallelism: 12
working_directory: ~/plotly.js
steps:
- browser-tools/install-browser-tools: &browser-versions
Expand Down Expand Up @@ -216,6 +216,24 @@ jobs:
name: Test MathJax on firefox-latest
command: .circleci/test.sh mathjax-firefox82+

make-baselines-mathjax3:
docker:
- image: circleci/python:3.8.9
working_directory: ~/plotly.js
steps:
- attach_workspace:
at: ~/
- run:
name: Install kaleido, plotly.io and required fonts
command: .circleci/env_image.sh
- run:
name: Create mathjax v3 png files
command: .circleci/test.sh make-baselines-mathjax3
- persist_to_workspace:
root: ~/
paths:
- plotly.js

make-baselines:
parallelism: 4
docker:
Expand Down Expand Up @@ -249,6 +267,20 @@ jobs:
path: build
destination: /

test-baselines-mathjax3:
docker:
- image: circleci/node:16.8.0
working_directory: ~/plotly.js
steps:
- attach_workspace:
at: ~/
- run:
name: Compare pixels of mathjax v3 baselines
command: .circleci/test.sh test-image-mathjax3
- store_artifacts:
path: build
destination: /

make-exports:
docker:
- image: circleci/python:3.8.9
Expand Down Expand Up @@ -413,6 +445,12 @@ workflows:
- flaky-no-gl-jasmine:
requires:
- install-and-cibuild
- make-baselines-mathjax3:
requires:
- install-and-cibuild
- test-baselines-mathjax3:
requires:
- make-baselines-mathjax3
- make-baselines:
requires:
- install-and-cibuild
Expand Down
15 changes: 13 additions & 2 deletions .circleci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,18 @@ case $1 in
;;

mathjax-firefox)
./node_modules/karma/bin/karma start test/jasmine/karma.conf.js --FF --bundleTest=mathjax --nowatch || EXIT_STATE=$?
./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=$?
./node_modules/karma/bin/karma start test/jasmine/karma.conf.js --FF --skip-tags=noFF82 --bundleTest=mathjax_v2 --nowatch &&
./node_modules/karma/bin/karma start test/jasmine/karma.conf.js --FF --skip-tags=noFF82 --bundleTest=mathjax_v3 --nowatch || EXIT_STATE=$?
exit $EXIT_STATE
;;

make-baselines-mathjax3)
python3 test/image/make_baseline.py mathjax3 legend_mathjax_title_and_items mathjax parcats_grid_subplots table_latex_multitrace_scatter table_plain_birds table_wrapped_birds ternary-mathjax || EXIT_STATE=$?
exit $EXIT_STATE
;;

Expand All @@ -90,6 +96,11 @@ case $1 in
exit $EXIT_STATE
;;

test-image-mathjax3)
node test/image/compare_pixels_test.js mathjax3 || { tar -cvf build/baselines.tar build/test_images/*.png ; exit 1 ; } || EXIT_STATE=$?
exit $EXIT_STATE
;;

source-syntax)
npm run lint || EXIT_STATE=$?
npm run test-syntax || EXIT_STATE=$?
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,19 @@ While non-minified source files may contain characters outside UTF-8, it is reco

> Please note that as of v2 the "plotly-latest" outputs (e.g. https://cdn.plot.ly/plotly-latest.min.js) will no longer be updated on the CDN, and will stay at the last v1 patch v1.58.5. Therefore, to use the CDN with plotly.js v2 and higher, you must specify an exact plotly.js version.

To support MathJax, you need to load version two of MathJax e.g. `v2.7.5` files from CDN or npm.
To support MathJax, you could load either version two or version three of MathJax files, for example:
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG.js"></script>
```

```html
<script src="https://cdn.jsdelivr.net/npm/mathjax@3.2.0/es5/tex-svg.js"></script>
```

> When using MathJax version 3, it is also possible to use `chtml` output on the other parts of the page in addition to `svg` output for the plotly graph.
Please refer to `devtools/test_dashboard/index-mathjax3chtml.html` to see an example.


## Bundles
There are two kinds of plotly.js bundles:
1. Complete and partial official bundles that are distributed to `npm` and the `CDN`, described in [the dist README](https://github.com/plotly/plotly.js/blob/master/dist/README.md).
Expand Down
29 changes: 29 additions & 0 deletions devtools/test_dashboard/index-mathjax3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>Plotly.js Devtools - MathJax v3 loaded with svg output</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>

<p>MathJax $V^3$ with $svg$ output on the page as well as plotly graphs</p>
<div id="plots">
<div id="graph"></div>
</div>
<div id="snapshot"></div>

<script src="../../node_modules/mathjax-v3/es5/tex-svg.js"></script>
<script charset="utf-8" id="source" src="../../build/plotly.js" type="module"></script>
<script charset="utf-8" src="../../build/test_dashboard-bundle.js"></script>
</body>
</html>
67 changes: 67 additions & 0 deletions devtools/test_dashboard/index-mathjax3chtml.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<title>Plotly.js Devtools - MathJax v3 loaded with chtml output</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>

<p>MathJax $V^3$ with $chtml$ output on the page and <b>svg</b> output on the plotly graphs</p>
<div id="plots">
<div id="graph"></div>
</div>
<div id="snapshot"></div>

<script>
window.MathJax = window.MathJax || {
// see https://github.com/mathjax/MathJax/issues/2705#issuecomment-859742446
loader: {load: ['output/svg']},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting... I guess if this becomes a common use case we could try to bake similar code (but designed to run later, not on startup) into plotly.js directly. For now though this is fine, as long as we're comfortable using only svg rendering in dash markdown.

startup: {
ready() {
// Get the MathJax modules that we need.
const {mathjax} = MathJax._.mathjax;
const {SVG} = MathJax._.output.svg_ts;

// Do the normal setup
MathJax.startup.defaultReady();

// Create an SVG output jax and a new MathDocument that uses it.
const svgOutput = new SVG(MathJax.config.svg);
const svgDocument = mathjax.document(document, {
...MathJax.config.options,
InputJax: MathJax.startup.input,
OutputJax: svgOutput
});

// Define the SVG-based conversion methods
MathJax.tex2svg = (math, options = {}) => {
options.format = svgDocument.inputJax[0].name;
return svgDocument.convert(math, options);
};
/*
MathJax.tex2svgPromise = (math, options = {}) => {
options.format = svgDocument.inputJax[0].name;
return mathjax.handleRetriesFor(() => svgDocument.convert(math, options));
};
*/
MathJax.svgStylesheet = () => svgOutput.styleSheet(svgDocument);
}
}
};
</script>
<script src="../../node_modules/mathjax-v3/es5/tex-chtml.js"></script>

<script charset="utf-8" id="source" src="../../build/plotly.js" type="module"></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" src="../../build/plotly.js" type="module"></script>
<script charset="utf-8" src="../../build/test_dashboard-bundle.js"></script>
</body>
Expand Down
8 changes: 7 additions & 1 deletion devtools/test_dashboard/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ 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;
var mathjax3chtml = args.mathjax3chtml;

// Create server
var server = http.createServer(ecstatic({
Expand All @@ -25,7 +27,11 @@ 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' :
mathjax3chtml ? '-mathjax3chtml' : ''
) + '.html');
});

// Bundle devtools code
Expand Down
2 changes: 2 additions & 0 deletions draftlogs/add_6073.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add support for MathJax version 3 [[#6073](https://github.com/plotly/plotly.js/pull/6073)],
with thanks to [Equinor](https://www.equinor.com) for sponsoring the related development!
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.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"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",
"mathjax3chtml": "node devtools/test_dashboard/server.js --mathjax3chtml",
alexcjohnson marked this conversation as resolved.
Show resolved Hide resolved
"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 +154,8 @@
"karma-viewport": "1.0.2",
"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
Loading