|
23 | 23 |
|
24 | 24 | <script>
|
25 | 25 | window.MathJax = window.MathJax || {
|
26 |
| - // mocking v2 API as suggested by https://github.com/akhmerov namely to handle both chtml output on the page as well as svg outputs for plotly |
27 |
| - |
28 | 26 | startup: {
|
29 |
| - // |
30 |
| - // Mapping of old extension names to new ones |
31 |
| - // |
32 |
| - requireMap: { |
33 |
| - AMSmath: 'ams', |
34 |
| - AMSsymbols: 'ams', |
35 |
| - AMScd: 'amscd', |
36 |
| - SVG: 'svg', |
37 |
| - noErrors: 'noerrors', |
38 |
| - noUndefined: 'noundefined' |
39 |
| - }, |
40 | 27 | ready() {
|
41 |
| - // Here and later using recipe from https://github.com/mathjax/MathJax/issues/2705 |
42 | 28 | //
|
43 | 29 | // Get the MathJax modules that we need.
|
44 | 30 | //
|
45 | 31 | const {mathjax} = MathJax._.mathjax;
|
46 | 32 | const {SVG} = MathJax._.output.svg_ts;
|
47 |
| - |
48 |
| - // Now using https://docs.mathjax.org/en/v3.2-latest/upgrading/v2.html#version-2-compatibility-example |
49 | 33 | //
|
50 |
| - // Replace the require command map with a new one that checks for |
51 |
| - // renamed extensions and converts them to the new names. |
| 34 | + // Do the normal setup |
52 | 35 | //
|
53 |
| - var CommandMap = MathJax._.input.tex.SymbolMap.CommandMap; |
54 |
| - var requireMap = MathJax.config.startup.requireMap; |
55 |
| - var RequireLoad = MathJax._.input.tex.require.RequireConfiguration.RequireLoad; |
56 |
| - var RequireMethods = { |
57 |
| - Require: function (parser, name) { |
58 |
| - var required = parser.GetArgument(name); |
59 |
| - if (required.match(/[^_a-zA-Z0-9]/) || required === '') { |
60 |
| - throw new TexError('BadPackageName', 'Argument for %1 is not a valid package name', name); |
61 |
| - } |
62 |
| - if (requireMap.hasOwnProperty(required)) { |
63 |
| - required = requireMap[required]; |
64 |
| - } |
65 |
| - RequireLoad(parser, required); |
66 |
| - } |
67 |
| - }; |
68 |
| - new CommandMap('require', {require: 'Require'}, RequireMethods); |
69 |
| - MathJax.Callback = function (args) { |
70 |
| - if (Array.isArray(args)) { |
71 |
| - if (args.length === 1 && typeof(args[0]) === 'function') { |
72 |
| - return args[0]; |
73 |
| - } else if (typeof(args[0]) === 'string' && args[1] instanceof Object && |
74 |
| - typeof(args[1][args[0]]) === 'function') { |
75 |
| - return Function.bind.apply(args[1][args[0]], args.slice(1)); |
76 |
| - } else if (typeof(args[0]) === 'function') { |
77 |
| - return Function.bind.apply(args[0], [window].concat(args.slice(1))); |
78 |
| - } else if (typeof(args[1]) === 'function') { |
79 |
| - return Function.bind.apply(args[1], [args[0]].concat(args.slice(2))); |
80 |
| - } |
81 |
| - } else if (typeof(args) === 'function') { |
82 |
| - return args; |
83 |
| - } |
84 |
| - throw Error("Can't make callback from given data"); |
85 |
| - }; |
86 |
| - // |
87 |
| - // Add a replacement for MathJax.Hub commands |
88 |
| - // |
89 |
| - MathJax.Hub = { |
90 |
| - Queue: function () { |
91 |
| - for (var i = 0, m = arguments.length; i < m; i++) { |
92 |
| - var fn = MathJax.Callback(arguments[i]); |
93 |
| - MathJax.startup.promise = MathJax.startup.promise.then(fn); |
94 |
| - } |
95 |
| - return MathJax.startup.promise; |
96 |
| - }, |
97 |
| - Typeset: function (element, callback) { |
98 |
| - var promise = MathJax.typesetSVGPromise([element]).then( |
99 |
| - () => { |
100 |
| - element.firstElementChild.classList.add("MathJax_SVG"); |
101 |
| - } |
102 |
| - ); |
103 |
| - if (callback) { |
104 |
| - promise = promise.then(callback); |
105 |
| - } |
106 |
| - return promise; |
107 |
| - }, |
108 |
| - Config: function () {}, |
109 |
| - Configured: function () {console.log('MathJax cannot be configured like this')}, |
110 |
| - config: {menuSettings: {renderer: "SVG"}} |
111 |
| - }; |
112 |
| - |
113 | 36 | MathJax.startup.defaultReady();
|
114 |
| - |
115 |
| - // Continuing from https://github.com/mathjax/MathJax/issues/2705 |
116 | 37 | //
|
117 | 38 | // Create an SVG output jax and a new MathDocument that uses it.
|
118 | 39 | //
|
119 | 40 | const svgOutput = new SVG(MathJax.config.svg);
|
120 | 41 | const svgDocument = mathjax.document(document, {
|
121 |
| - ...MathJax.config.options, |
122 |
| - InputJax: MathJax.startup.input, |
123 |
| - OutputJax: svgOutput |
| 42 | + ...MathJax.config.options, |
| 43 | + InputJax: MathJax.startup.input, |
| 44 | + OutputJax: svgOutput |
124 | 45 | });
|
125 | 46 | //
|
126 | 47 | // Define the SVG-based conversion methods
|
127 | 48 | //
|
128 |
| - MathJax.svgStylesheet = () => svgOutput.styleSheet(svgDocument); |
129 |
| - MathJax.typesetSVGPromise = (elements) => { |
130 |
| - svgDocument.options.elements = elements; |
131 |
| - svgDocument.reset(); |
132 |
| - return mathjax.handleRetriesFor(() => { |
133 |
| - svgDocument.render(); |
134 |
| - }); |
| 49 | + MathJax.tex2svg = (math, options = {}) => { |
| 50 | + options.format = svgDocument.inputJax[0].name; |
| 51 | + return svgDocument.convert(math, options); |
| 52 | + }; |
| 53 | + MathJax.tex2svgPromise = (math, options = {}) => { |
| 54 | + options.format = svgDocument.inputJax[0].name; |
| 55 | + return mathjax.handleRetriesFor(() => svgDocument.convert(math, options)); |
135 | 56 | };
|
| 57 | + MathJax.svgStylesheet = () => svgOutput.styleSheet(svgDocument); |
136 | 58 | }
|
137 | 59 | },
|
138 | 60 | loader: {load: ["output/svg"]},
|
139 | 61 | tex: {
|
140 |
| - inlineMath: [["\\(", "\\)"], ["$", "$"]], |
141 |
| - displayMath: [["\\[", "\\]"], ["$$", "$$"]], |
142 |
| - processEscapes: true, |
143 |
| - processEnvironments: true, |
144 |
| - autoload: { |
145 |
| - color: [], // don't autoload the color extension |
146 |
| - colorv2: ['color'], // do autoload the colorv2 extension |
147 |
| - } |
| 62 | + inlineMath: [["\\(", "\\)"], ["$", "$"]], |
148 | 63 | }
|
149 | 64 | };
|
150 | 65 | </script>
|
151 | 66 | <script src="../../node_modules/mathjax-v3/es5/tex-mml-chtml.js"></script>
|
152 |
| - <script> |
153 |
| - // let plotly.js know that v2 API is mocked |
154 |
| - window.MathJax._mockedV2API = true; |
155 |
| - </script> |
156 | 67 | <script charset="utf-8" id="source" type="module">import "../../build/plotly.js"</script>
|
157 | 68 | <script charset="utf-8" src="../../build/test_dashboard-bundle.js"></script>
|
158 | 69 | </body>
|
|
0 commit comments