-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Support version 3 of MathJax
and add config.typesetMath
#6073
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
Merged
Merged
Changes from 44 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
6231b4a
support for mathjax v3 as well
archmoj 912fb1d
add PR log and adjust comments
archmoj b01c4e0
Update src/lib/svg_text_utils.js
archmoj a49e611
adjust mathjax element selection for v3
archmoj b568b61
correct bundle test flag for v3
archmoj cfbcc75
select glyphs only when needed
archmoj 41e37b6
refactor mathjax selection
archmoj 63964e2
refactor mathajx typeset return
archmoj 6e4c968
select defs for mathjax v3
archmoj 13fbb8d
add jasmine tests for v3
archmoj 386dd87
refactor mathjax tmp node draw and selection
archmoj 502c3e8
base to support chtml output in mathjax v3
archmoj 1dd51fd
do not try to handle non-svg mathjax for now
archmoj 4ba005f
Anton Akhmerov's workaround to mock v2 API for pages with both chtml …
archmoj 04d8005
no need for mocking API v2 to handle both chtml & svg outputs
archmoj 7be4e73
set and reset inline mathjax config
archmoj 5cd3ba0
simplify
archmoj 8e204e6
edit mathjax devtools
archmoj eeddb7b
simplify mathjax config
archmoj 42d76e8
call defaultReady after resetting config and renderer
archmoj ec0e0d3
use startup.promise after startup.defaultReady
archmoj 63e240e
fixup defs selection in v3
archmoj 7b0ab24
run mathjax v2 and v3 in the same container
archmoj f0f283d
update PR log
archmoj f3f9424
update readme on mathjax v3
archmoj 3a12c15
add image test for mathjax v3
archmoj 8b4dba7
revise setting inlineMath for mathjax v3
archmoj 41ae662
increase parallelism for jasmine tests
archmoj cbdcad5
modify readme
archmoj 4bb1714
update package lock - exact 2.7.5 version
archmoj c48654d
align new mathjax dashboards to PR 6096
archmoj cb73ab7
Update README.md
archmoj ff983b6
Merge branch 'master' into mathjax-v3
archmoj 0cdd3bb
improve example for how to control typeset at startup
archmoj 9beda27
Merge remote-tracking branch 'origin/master' into mathjax-v3
archmoj cee5832
add typesetMath to config
archmoj b24f3f4
correct typesetMath
archmoj d2426f0
update draft log
archmoj 1de176c
respect MathJax.config.tex.inlineMath
archmoj 7677258
refactor functions for v2 and v3 and strict conditions
archmoj 870e1ce
abstract load script for mathjax tests
archmoj 600035d
move load script to test assests
archmoj 353d393
use mathjax_test file for both v2 and v3
archmoj 4d7869a
add tests for mathjax reset config & renderer
archmoj d5e10a7
fixup config of mathjax v3
archmoj 1739f3d
Update src/plot_api/plot_config.js
archmoj ff75df4
adjust test and update schema
archmoj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected]/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). | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!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/[email protected]" 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 id="pWithMathJax">MathJax $V^3$ with $svg$ output on the page as well as plotly graphs</p> | ||
<h4>no MathJax: Apple: $2, Orange: $3</h4> | ||
|
||
<div id="plots"> | ||
<div id="graph"></div> | ||
</div> | ||
<div id="snapshot"></div> | ||
|
||
<script> | ||
window.MathJax = { | ||
startup: { | ||
elements: [ | ||
document.getElementById('pWithMathJax') | ||
], | ||
// typeset: false, | ||
// in case the elements array is empty one could disable startup typeset | ||
// https://docs.mathjax.org/en/latest/options/startup/startup.html#the-configuration-block | ||
} | ||
}; | ||
</script> | ||
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/[email protected]" 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']}, | ||
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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Add support for MathJax version 3 and `typesetMath` attribute to config [[#6073](https://github.com/plotly/plotly.js/pull/6073)], | ||
with thanks to [Equinor](https://www.equinor.com) for sponsoring the related development! |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
@@ -152,7 +154,8 @@ | |
"karma-viewport": "1.0.2", | ||
"lodash": "^4.17.21", | ||
"madge": "^5.0.1", | ||
"mathjax": "2.7.5", | ||
"mathjax-v2": "npm:[email protected]", | ||
"mathjax-v3": "npm:mathjax@^3.2.0", | ||
"minify-stream": "^2.1.0", | ||
"npm-link-check": "^4.0.0", | ||
"open": "^8.4.0", | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.