@pie-lib/math-rendering 2.3.13 → 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,44 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.4.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.4.1...@pie-lib/math-rendering@2.4.2) (2022-05-30)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * unable to load items locally ([17ab686](https://github.com/pie-framework/pie-lib/commit/17ab6864557288aef6ec1d9a130cb508e2591562))
12
+
13
+
14
+
15
+
16
+
17
+ ## [2.4.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.4.0...@pie-lib/math-rendering@2.4.1) (2022-05-24)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * unable to load items locally ([a0ddf20](https://github.com/pie-framework/pie-lib/commit/a0ddf2095646e6e84569cb7e0de42d0cd9ea0fb6))
23
+
24
+
25
+
26
+
27
+
28
+ # [2.4.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.13...@pie-lib/math-rendering@2.4.0) (2022-04-28)
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * tests ([90d79c4](https://github.com/pie-framework/pie-lib/commit/90d79c4b8c61c029959a729ba1eea1d69a3f2cbe))
34
+
35
+
36
+ ### Features
37
+
38
+ * add data-mathml attribute on MathJax containers to be able to use with Text to Speech (TTS) PD-1499 ([df50318](https://github.com/pie-framework/pie-lib/commit/df503184814f0463ef588e468570db3f7d2651df))
39
+
40
+
41
+
42
+
43
+
6
44
  ## [2.3.13](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.12...@pie-lib/math-rendering@2.3.13) (2022-03-21)
7
45
 
8
46
 
@@ -29,6 +29,8 @@ var _normalization = require("./normalization");
29
29
 
30
30
  var _MmlFactory = require("mathjax-full/js/core/MmlTree/MmlFactory");
31
31
 
32
+ var _SerializedMmlVisitor = require("mathjax-full/js/core/MmlTree/SerializedMmlVisitor");
33
+
32
34
  var _WrapperFactory = require("mathjax-full/js/output/chtml/WrapperFactory");
33
35
 
34
36
  var _mspace = require("mathjax-full/js/output/chtml/Wrappers/mspace");
@@ -47,6 +49,8 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
47
49
 
48
50
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
49
51
 
52
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
53
+
50
54
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
51
55
 
52
56
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -57,6 +61,12 @@ if (typeof window !== 'undefined') {
57
61
  (0, _html.RegisterHTMLHandler)((0, _browserAdaptor.browserAdaptor)());
58
62
  }
59
63
 
64
+ var visitor = new _SerializedMmlVisitor.SerializedMmlVisitor();
65
+
66
+ var toMMl = function toMMl(node) {
67
+ return visitor.visitTree(node);
68
+ };
69
+
60
70
  var log = (0, _debug["default"])('pie-lib:math-rendering');
61
71
  var NEWLINE_BLOCK_REGEX = /\\embed\{newLine\}\[\]/g;
62
72
  var NEWLINE_LATEX = '\\newline ';
@@ -113,6 +123,13 @@ var fixMathElements = function fixMathElements() {
113
123
 
114
124
  exports.fixMathElements = fixMathElements;
115
125
 
126
+ var adjustMathMLStyle = function adjustMathMLStyle() {
127
+ var nodes = document.querySelectorAll('math');
128
+ nodes.forEach(function (node) {
129
+ return node.setAttribute('displaystyle', 'true');
130
+ });
131
+ };
132
+
116
133
  var bootstrap = function bootstrap(opts) {
117
134
  if (typeof window === 'undefined') {
118
135
  return {
@@ -144,21 +161,15 @@ var bootstrap = function bootstrap(opts) {
144
161
  longdiv: '\\enclose{longdiv}'
145
162
  };
146
163
  var texConfig = opts.useSingleDollar ? {
147
- loader: {
148
- require: require
149
- },
150
164
  packages: packages,
151
165
  macros: macros,
152
166
  inlineMath: [['$', '$'], ['\\(', '\\)']],
153
- displayMath: [['$$', '$$'], ['\\[', '\\]']],
154
167
  processEscapes: true
155
168
  } : {
156
169
  packages: packages,
157
170
  macros: macros
158
171
  };
159
172
  var mmlConfig = {
160
- parseAs: 'html',
161
- forceReparse: false,
162
173
  parseError: function parseError(node) {
163
174
  // function to process parsing errors
164
175
  console.log('error:', node);
@@ -171,7 +182,6 @@ var bootstrap = function bootstrap(opts) {
171
182
  wrapperFactory: new _WrapperFactory.CHTMLWrapperFactory(_objectSpread(_objectSpread({}, _WrapperFactory.CHTMLWrapperFactory.defaultNodes), _mstack.chtmlNodes))
172
183
  };
173
184
  var mml = new _mathml.MathML(mmlConfig);
174
- console.log([new _tex.TeX(texConfig), mml]);
175
185
  var customMmlFactory = new _MmlFactory.MmlFactory(_objectSpread(_objectSpread({}, _MmlFactory.MmlFactory.defaultNodes), _mstack.mmlNodes));
176
186
 
177
187
  var html = _mathjax.mathjax.document(document, {
@@ -198,9 +208,23 @@ var bootstrap = function bootstrap(opts) {
198
208
  elements[_key] = arguments[_key];
199
209
  }
200
210
 
201
- this.html.findMath(elements.length ? {
211
+ var updatedDocument = this.html.findMath(elements.length ? {
202
212
  elements: elements
203
- } : {}).compile().getMetrics().typeset().updateDocument().clear();
213
+ } : {}).compile().getMetrics().typeset().updateDocument();
214
+
215
+ try {
216
+ var list = updatedDocument.math.list;
217
+
218
+ for (var item = list.next; _typeof(item.data) !== 'symbol'; item = item.next) {
219
+ var mathMl = toMMl(item.data.root);
220
+ var parsedMathMl = mathMl.replaceAll('\n', '');
221
+ item.data.typesetRoot.setAttribute('data-mathml', parsedMathMl);
222
+ }
223
+ } catch (e) {
224
+ console.error(e.toString());
225
+ }
226
+
227
+ updatedDocument.clear();
204
228
  }
205
229
  };
206
230
  };
@@ -208,6 +232,7 @@ var bootstrap = function bootstrap(opts) {
208
232
  var renderMath = function renderMath(el, renderOpts) {
209
233
  //TODO: remove this - has nothing to do with math-rendering (it's from editable-html)
210
234
  fixMathElements();
235
+ adjustMathMLStyle();
211
236
 
212
237
  if (!getGlobal().instance) {
213
238
  getGlobal().instance = bootstrap(renderOpts);
@@ -236,7 +261,7 @@ var renderMath = function renderMath(el, renderOpts) {
236
261
  "display": 'in-line',
237
262
  "text-align": 'left'
238
263
  } which prevents it from showing as a newline value
239
- */
264
+ */
240
265
 
241
266
 
242
267
  _mspace.CHTMLmspace.styles = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/render-math.js"],"names":["window","log","NEWLINE_BLOCK_REGEX","NEWLINE_LATEX","getGlobal","key","pkg","name","version","split","defaultOpts","opts","fixMathElement","element","property","textContent","unwrapped","replace","fixMathElements","mathElements","document","querySelectorAll","forEach","item","bootstrap","Typeset","useSingleDollar","console","warn","packages","AllPackages","filter","push","macros","parallelogram","overarc","napprox","longdiv","texConfig","loader","require","inlineMath","displayMath","processEscapes","mmlConfig","parseAs","forceReparse","parseError","node","error","adaptor","fontURL","mathjax","htmlConfig","wrapperFactory","CHTMLWrapperFactory","defaultNodes","chtmlNodes","mml","MathML","TeX","customMmlFactory","MmlFactory","mmlNodes","html","compileError","mj","math","err","typesetError","doc","InputJax","OutputJax","CHTML","setMmlFactory","elements","findMath","length","compile","getMetrics","typeset","updateDocument","clear","renderMath","el","renderOpts","instance","Element","arr","Array","from","CHTMLmspace","styles","display","height"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;AAVA,IAAI,OAAOA,MAAP,KAAkB,WAAtB,EAAmC;AACjC,iCAAoB,qCAApB;AACD;;AAUD,IAAMC,GAAG,GAAG,uBAAM,wBAAN,CAAZ;AAEA,IAAMC,mBAAmB,GAAG,yBAA5B;AACA,IAAMC,aAAa,GAAG,YAAtB;;AAEA,IAAMC,SAAS,GAAG,SAAZA,SAAY,GAAM;AACtB,MAAMC,GAAG,aAAMC,oBAAIC,IAAV,cAAkBD,oBAAIE,OAAJ,CAAYC,KAAZ,CAAkB,GAAlB,EAAuB,CAAvB,CAAlB,CAAT;;AAEA,MAAI,OAAOT,MAAP,KAAkB,WAAtB,EAAmC;AACjC,QAAI,CAACA,MAAM,CAACK,GAAD,CAAX,EAAkB;AAChBL,MAAAA,MAAM,CAACK,GAAD,CAAN,GAAc,EAAd;AACD;;AACD,WAAOL,MAAM,CAACK,GAAD,CAAb;AACD,GALD,MAKO;AACL,WAAO,EAAP;AACD;AACF,CAXD;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,IAAMK,WAAW,GAAG,SAAdA,WAAc;AAAA,SAAMN,SAAS,GAAGO,IAAZ,IAAoB,EAA1B;AAAA,CAApB;;AAEO,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,CAAAC,OAAO,EAAI;AACvC,MAAIC,QAAQ,GAAG,WAAf;;AAEA,MAAID,OAAO,CAACE,WAAZ,EAAyB;AACvBD,IAAAA,QAAQ,GA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CA3GD;;AA6GA,IAAMC,UAAU,GAAG,SAAbA,UAAa,CAACC,EAAD,EAAKC,UAAL,EAAoB;AACrC;AACAnE,EAAAA,eAAe;;AAEf,MAAI,CAACd,SAAS,GAAGkF,QAAjB,EAA2B;AACzBlF,IAAAA,SAAS,GAAGkF,QAAZ,GAAuB9D,SAAS,CAAC6D,UAAD,CAAhC;AACD;;AAED,MAAI,CAACD,EAAL,EAAS;AACPnF,IAAAA,GAAG,CAAC,iBAAD,CAAH;AACA;AACD;;AAED,MAAImF,EAAE,YAAYG,OAAlB,EAA2B;AACzBnF,IAAAA,SAAS,GAAGkF,QAAZ,CAAqB7D,OAArB,CAA6B2D,EAA7B;AACD,GAFD,MAEO,IAAIA,EAAE,CAACP,MAAP,EAAe;AAAA;;AACpB,QAAMW,GAAG,GAAGC,KAAK,CAACC,IAAN,CAAWN,EAAX,CAAZ;;AACA,2BAAAhF,SAAS,GAAGkF,QAAZ,EAAqB7D,OAArB,+CAAgC+D,GAAhC;AACD;AACF,CAnBD;AAqBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACAG,oBAAYC,MAAZ,GAAqB;AACnB,gBAAc;AACZC,IAAAA,OAAO,EAAE,OADG;AAEZ,kBAAc,QAFF;AAGZC,IAAAA,MAAM,EAAE;AAHI;AADK,CAArB;eAQeX,U","sourcesContent":["import { mathjax } from 'mathjax-full/js/mathjax';\nimport { MathML } from 'mathjax-full/js/input/mathml';\nimport { TeX } from 'mathjax-full/js/input/tex';\n\nimport { CHTML } from 'mathjax-full/js/output/chtml';\nimport { RegisterHTMLHandler } from 'mathjax-full/js/handlers/html';\nimport { browserAdaptor } from 'mathjax-full/js/adaptors/browserAdaptor';\nimport { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';\n\nif (typeof window !== 'undefined') {\n RegisterHTMLHandler(browserAdaptor());\n}\n\nimport pkg from '../package.json';\nimport { mmlNodes, chtmlNodes } from './mstack';\nimport debug from 'debug';\nimport { wrapMath, unWrapMath } from './normalization';\nimport { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';\nimport { CHTMLWrapperFactory } from 'mathjax-full/js/output/chtml/WrapperFactory';\nimport { CHTMLmspace } from 'mathjax-full/js/output/chtml/Wrappers/mspace';\n\nconst log = debug('pie-lib:math-rendering');\n\nconst NEWLINE_BLOCK_REGEX = /\\\\embed\\{newLine\\}\\[\\]/g;\nconst NEWLINE_LATEX = '\\\\newline ';\n\nconst getGlobal = () => {\n const key = `${pkg.name}@${pkg.version.split('.')[0]}`;\n\n if (typeof window !== 'undefined') {\n if (!window[key]) {\n window[key] = {};\n }\n return window[key];\n } else {\n return {};\n }\n};\n\n/** Add temporary support for a global singleDollar override\n * <code>\n * // This will enable single dollar rendering\n * window.pie = window.pie || {};\n * window.pie.mathRendering = {useSingleDollar: true };\n * </code>\n */\nconst defaultOpts = () => getGlobal().opts || {};\n\nexport const fixMathElement = element => {\n let property = 'innerText';\n\n if (element.textContent) {\n property = 'textContent';\n }\n\n if (element[property]) {\n element[property] = wrapMath(unWrapMath(element[property]).unwrapped);\n // because mathquill doesn't understand line breaks, sometimes we end up with custom elements on prompts/rationale/etc.\n // we need to replace the custom embedded elements with valid latex that Mathjax can understand\n element[property] = element[property].replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX);\n }\n};\n\nexport const fixMathElements = () => {\n const mathElements = document.querySelectorAll('[data-latex]');\n\n mathElements.forEach(item => fixMathElement(item));\n};\n\nconst bootstrap = opts => {\n if (typeof window === 'undefined') {\n return { Typeset: () => ({}) };\n }\n\n opts = opts || defaultOpts();\n\n if (opts.useSingleDollar) {\n // eslint-disable-next-line\n console.warn('[math-rendering] using $ is not advisable, please use $$..$$ or \\\\(...\\\\)');\n }\n\n const packages = AllPackages.filter(name => name !== 'bussproofs'); // Bussproofs needs an output jax\n\n // The autoload extension predefines all the macros from the extensions that haven't been loaded already\n // so that they automatically load the needed extension when they are first used\n packages.push('autoload');\n\n const macros = {\n parallelogram: '\\\\lower.2em{\\\\Huge\\\\unicode{x25B1}}',\n overarc: '\\\\overparen',\n napprox: '\\\\not\\\\approx',\n longdiv: '\\\\enclose{longdiv}'\n };\n\n const texConfig = opts.useSingleDollar\n ? {\n loader: {\n require: require\n },\n packages,\n macros,\n inlineMath: [\n ['$', '$'],\n ['\\\\(', '\\\\)']\n ],\n displayMath: [\n ['$$', '$$'],\n ['\\\\[', '\\\\]']\n ],\n processEscapes: true\n }\n : {\n packages,\n macros\n };\n\n const mmlConfig = {\n parseAs: 'html',\n forceReparse: false,\n parseError: function(node) {\n // function to process parsing errors\n console.log('error:', node);\n this.error(this.adaptor.textContent(node).replace(/\\n.*/g, ''));\n }\n };\n\n const fontURL = `https://unpkg.com/mathjax-full@${mathjax.version}/ts/output/chtml/fonts/tex-woff-v2`;\n const htmlConfig = {\n fontURL,\n\n wrapperFactory: new CHTMLWrapperFactory({\n ...CHTMLWrapperFactory.defaultNodes,\n ...chtmlNodes\n })\n };\n\n const mml = new MathML(mmlConfig);\n console.log([new TeX(texConfig), mml]);\n\n const customMmlFactory = new MmlFactory({\n ...MmlFactory.defaultNodes,\n ...mmlNodes\n });\n\n const html = mathjax.document(document, {\n compileError: (mj, math, err) => {\n console.log('bad math?:', math);\n console.error(err);\n },\n typesetError: function(doc, math, err) {\n console.log('typeset error');\n console.error(err);\n doc.typesetError(math, err);\n },\n\n InputJax: [new TeX(texConfig), mml],\n OutputJax: new CHTML(htmlConfig)\n });\n\n // Note: we must set this *after* mathjax.document (no idea why)\n mml.setMmlFactory(customMmlFactory);\n\n return {\n version: mathjax.version,\n html: html,\n\n Typeset: function(...elements) {\n this.html\n .findMath(elements.length ? { elements } : {})\n .compile()\n .getMetrics()\n .typeset()\n .updateDocument()\n .clear();\n }\n };\n};\n\nconst renderMath = (el, renderOpts) => {\n //TODO: remove this - has nothing to do with math-rendering (it's from editable-html)\n fixMathElements();\n\n if (!getGlobal().instance) {\n getGlobal().instance = bootstrap(renderOpts);\n }\n\n if (!el) {\n log('el is undefined');\n return;\n }\n\n if (el instanceof Element) {\n getGlobal().instance.Typeset(el);\n } else if (el.length) {\n const arr = Array.from(el);\n getGlobal().instance.Typeset(...arr);\n }\n};\n\n/**\n * This style is added to overried default styling of mjx-mspace Mathjax tag\n * In mathjax src code \\newline latex gets parsed to <mjx-mspace></mjx-mspace>,\n * but has the default style\n * 'mjx-mspace': {\n \"display\": 'in-line',\n \"text-align\": 'left'\n} which prevents it from showing as a newline value\n*/\nCHTMLmspace.styles = {\n 'mjx-mspace': {\n display: 'block',\n 'text-align': 'center',\n height: '5px'\n }\n};\n\nexport default renderMath;\n"],"file":"render-math.js"}
1
+ {"version":3,"sources":["../src/render-math.js"],"names":["window","visitor","SerializedMmlVisitor","toMMl","node","visitTree","log","NEWLINE_BLOCK_REGEX","NEWLINE_LATEX","getGlobal","key","pkg","name","version","split","defaultOpts","opts","fixMathElement","element","property","textContent","unwrapped","replace","fixMathElements","mathElements","document","querySelectorAll","forEach","item","adjustMathMLStyle","nodes","setAttribute","bootstrap","Typeset","useSingleDollar","console","warn","packages","AllPackages","filter","push","macros","parallelogram","overarc","napprox","longdiv","texConfig","inlineMath","processEscapes","mmlConfig","parseError","error","adaptor","fontURL","mathjax","htmlConfig","wrapperFactory","CHTMLWrapperFactory","defaultNodes","chtmlNodes","mml","MathML","customMmlFactory","MmlFactory","mmlNodes","html","compileError","mj","math","err","typesetError","doc","InputJax","TeX","OutputJax","CHTML","setMmlFactory","elements","updatedDocument","findMath","length","compile","getMetrics","typeset","updateDocument","list","next","data","mathMl","root","parsedMathMl","replaceAll","typesetRoot","e","toString","clear","renderMath","el","renderOpts","instance","Element","arr","Array","from","CHTMLmspace","styles","display","height"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;AAXA,IAAI,OAAOA,MAAP,KAAkB,WAAtB,EAAmC;AACjC,iCAAoB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/js/mathjax';\nimport { MathML } from 'mathjax-full/js/input/mathml';\nimport { TeX } from 'mathjax-full/js/input/tex';\n\nimport { CHTML } from 'mathjax-full/js/output/chtml';\nimport { RegisterHTMLHandler } from 'mathjax-full/js/handlers/html';\nimport { browserAdaptor } from 'mathjax-full/js/adaptors/browserAdaptor';\nimport { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';\n\nif (typeof window !== 'undefined') {\n RegisterHTMLHandler(browserAdaptor());\n}\n\nimport pkg from '../package.json';\nimport { mmlNodes, chtmlNodes } from './mstack';\nimport debug from 'debug';\nimport { wrapMath, unWrapMath } from './normalization';\nimport { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';\nimport { SerializedMmlVisitor } from 'mathjax-full/js/core/MmlTree/SerializedMmlVisitor';\nimport { CHTMLWrapperFactory } from 'mathjax-full/js/output/chtml/WrapperFactory';\nimport { CHTMLmspace } from 'mathjax-full/js/output/chtml/Wrappers/mspace';\n\nconst visitor = new SerializedMmlVisitor();\nconst toMMl = node => visitor.visitTree(node);\n\nconst log = debug('pie-lib:math-rendering');\n\nconst NEWLINE_BLOCK_REGEX = /\\\\embed\\{newLine\\}\\[\\]/g;\nconst NEWLINE_LATEX = '\\\\newline ';\n\nconst getGlobal = () => {\n const key = `${pkg.name}@${pkg.version.split('.')[0]}`;\n\n if (typeof window !== 'undefined') {\n if (!window[key]) {\n window[key] = {};\n }\n return window[key];\n } else {\n return {};\n }\n};\n\n/** Add temporary support for a global singleDollar override\n * <code>\n * // This will enable single dollar rendering\n * window.pie = window.pie || {};\n * window.pie.mathRendering = {useSingleDollar: true };\n * </code>\n */\nconst defaultOpts = () => getGlobal().opts || {};\n\nexport const fixMathElement = element => {\n let property = 'innerText';\n\n if (element.textContent) {\n property = 'textContent';\n }\n\n if (element[property]) {\n element[property] = wrapMath(unWrapMath(element[property]).unwrapped);\n // because mathquill doesn't understand line breaks, sometimes we end up with custom elements on prompts/rationale/etc.\n // we need to replace the custom embedded elements with valid latex that Mathjax can understand\n element[property] = element[property].replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX);\n }\n};\n\nexport const fixMathElements = () => {\n const mathElements = document.querySelectorAll('[data-latex]');\n\n mathElements.forEach(item => fixMathElement(item));\n};\n\nconst adjustMathMLStyle = () => {\n const nodes = document.querySelectorAll('math');\n nodes.forEach(node => node.setAttribute('displaystyle', 'true'));\n};\n\nconst bootstrap = opts => {\n if (typeof window === 'undefined') {\n return { Typeset: () => ({}) };\n }\n\n opts = opts || defaultOpts();\n\n if (opts.useSingleDollar) {\n // eslint-disable-next-line\n console.warn('[math-rendering] using $ is not advisable, please use $$..$$ or \\\\(...\\\\)');\n }\n\n const packages = AllPackages.filter(name => name !== 'bussproofs'); // Bussproofs needs an output jax\n\n // The autoload extension predefines all the macros from the extensions that haven't been loaded already\n // so that they automatically load the needed extension when they are first used\n packages.push('autoload');\n\n const macros = {\n parallelogram: '\\\\lower.2em{\\\\Huge\\\\unicode{x25B1}}',\n overarc: '\\\\overparen',\n napprox: '\\\\not\\\\approx',\n longdiv: '\\\\enclose{longdiv}'\n };\n\n const texConfig = opts.useSingleDollar\n ? {\n packages,\n macros,\n inlineMath: [\n ['$', '$'],\n ['\\\\(', '\\\\)']\n ],\n processEscapes: true\n }\n : {\n packages,\n macros\n };\n\n const mmlConfig = {\n parseError: function(node) {\n // function to process parsing errors\n console.log('error:', node);\n this.error(this.adaptor.textContent(node).replace(/\\n.*/g, ''));\n }\n };\n\n const fontURL = `https://unpkg.com/mathjax-full@${mathjax.version}/ts/output/chtml/fonts/tex-woff-v2`;\n const htmlConfig = {\n fontURL,\n\n wrapperFactory: new CHTMLWrapperFactory({\n ...CHTMLWrapperFactory.defaultNodes,\n ...chtmlNodes\n })\n };\n\n const mml = new MathML(mmlConfig);\n\n const customMmlFactory = new MmlFactory({\n ...MmlFactory.defaultNodes,\n ...mmlNodes\n });\n\n const html = mathjax.document(document, {\n compileError: (mj, math, err) => {\n console.log('bad math?:', math);\n console.error(err);\n },\n typesetError: function(doc, math, err) {\n console.log('typeset error');\n console.error(err);\n doc.typesetError(math, err);\n },\n\n InputJax: [new TeX(texConfig), mml],\n OutputJax: new CHTML(htmlConfig)\n });\n\n // Note: we must set this *after* mathjax.document (no idea why)\n mml.setMmlFactory(customMmlFactory);\n\n return {\n version: mathjax.version,\n html: html,\n Typeset: function(...elements) {\n const updatedDocument = this.html\n .findMath(elements.length ? { elements } : {})\n .compile()\n .getMetrics()\n .typeset()\n .updateDocument();\n\n try {\n const list = updatedDocument.math.list;\n\n for (let item = list.next; typeof item.data !== 'symbol'; item = item.next) {\n const mathMl = toMMl(item.data.root);\n const parsedMathMl = mathMl.replaceAll('\\n', '');\n\n item.data.typesetRoot.setAttribute('data-mathml', parsedMathMl);\n }\n } catch (e) {\n console.error(e.toString());\n }\n\n updatedDocument.clear();\n }\n };\n};\n\nconst renderMath = (el, renderOpts) => {\n //TODO: remove this - has nothing to do with math-rendering (it's from editable-html)\n fixMathElements();\n adjustMathMLStyle();\n\n if (!getGlobal().instance) {\n getGlobal().instance = bootstrap(renderOpts);\n }\n\n if (!el) {\n log('el is undefined');\n return;\n }\n\n if (el instanceof Element) {\n getGlobal().instance.Typeset(el);\n } else if (el.length) {\n const arr = Array.from(el);\n getGlobal().instance.Typeset(...arr);\n }\n};\n\n/**\n * This style is added to overried default styling of mjx-mspace Mathjax tag\n * In mathjax src code \\newline latex gets parsed to <mjx-mspace></mjx-mspace>,\n * but has the default style\n * 'mjx-mspace': {\n \"display\": 'in-line',\n \"text-align\": 'left'\n} which prevents it from showing as a newline value\n */\nCHTMLmspace.styles = {\n 'mjx-mspace': {\n display: 'block',\n 'text-align': 'center',\n height: '5px'\n }\n};\n\nexport default renderMath;\n"],"file":"render-math.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/math-rendering",
3
- "version": "2.3.13",
3
+ "version": "2.4.2",
4
4
  "description": "math rendering utilities",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -12,8 +12,8 @@
12
12
  "dependencies": {
13
13
  "debug": "^4.1.1",
14
14
  "lodash": "^4.17.11",
15
- "mathjax-full": "^3.2.0"
15
+ "mathjax-full": "3.2.0"
16
16
  },
17
- "gitHead": "aece71eebc3d81299789f41be579058ca796d106",
17
+ "gitHead": "debcaf764c62d97a1401f2898b062183847ce33b",
18
18
  "scripts": {}
19
19
  }
@@ -16,9 +16,13 @@ import { mmlNodes, chtmlNodes } from './mstack';
16
16
  import debug from 'debug';
17
17
  import { wrapMath, unWrapMath } from './normalization';
18
18
  import { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';
19
+ import { SerializedMmlVisitor } from 'mathjax-full/js/core/MmlTree/SerializedMmlVisitor';
19
20
  import { CHTMLWrapperFactory } from 'mathjax-full/js/output/chtml/WrapperFactory';
20
21
  import { CHTMLmspace } from 'mathjax-full/js/output/chtml/Wrappers/mspace';
21
22
 
23
+ const visitor = new SerializedMmlVisitor();
24
+ const toMMl = node => visitor.visitTree(node);
25
+
22
26
  const log = debug('pie-lib:math-rendering');
23
27
 
24
28
  const NEWLINE_BLOCK_REGEX = /\\embed\{newLine\}\[\]/g;
@@ -67,6 +71,11 @@ export const fixMathElements = () => {
67
71
  mathElements.forEach(item => fixMathElement(item));
68
72
  };
69
73
 
74
+ const adjustMathMLStyle = () => {
75
+ const nodes = document.querySelectorAll('math');
76
+ nodes.forEach(node => node.setAttribute('displaystyle', 'true'));
77
+ };
78
+
70
79
  const bootstrap = opts => {
71
80
  if (typeof window === 'undefined') {
72
81
  return { Typeset: () => ({}) };
@@ -94,19 +103,12 @@ const bootstrap = opts => {
94
103
 
95
104
  const texConfig = opts.useSingleDollar
96
105
  ? {
97
- loader: {
98
- require: require
99
- },
100
106
  packages,
101
107
  macros,
102
108
  inlineMath: [
103
109
  ['$', '$'],
104
110
  ['\\(', '\\)']
105
111
  ],
106
- displayMath: [
107
- ['$$', '$$'],
108
- ['\\[', '\\]']
109
- ],
110
112
  processEscapes: true
111
113
  }
112
114
  : {
@@ -115,8 +117,6 @@ const bootstrap = opts => {
115
117
  };
116
118
 
117
119
  const mmlConfig = {
118
- parseAs: 'html',
119
- forceReparse: false,
120
120
  parseError: function(node) {
121
121
  // function to process parsing errors
122
122
  console.log('error:', node);
@@ -135,7 +135,6 @@ const bootstrap = opts => {
135
135
  };
136
136
 
137
137
  const mml = new MathML(mmlConfig);
138
- console.log([new TeX(texConfig), mml]);
139
138
 
140
139
  const customMmlFactory = new MmlFactory({
141
140
  ...MmlFactory.defaultNodes,
@@ -163,15 +162,28 @@ const bootstrap = opts => {
163
162
  return {
164
163
  version: mathjax.version,
165
164
  html: html,
166
-
167
165
  Typeset: function(...elements) {
168
- this.html
166
+ const updatedDocument = this.html
169
167
  .findMath(elements.length ? { elements } : {})
170
168
  .compile()
171
169
  .getMetrics()
172
170
  .typeset()
173
- .updateDocument()
174
- .clear();
171
+ .updateDocument();
172
+
173
+ try {
174
+ const list = updatedDocument.math.list;
175
+
176
+ for (let item = list.next; typeof item.data !== 'symbol'; item = item.next) {
177
+ const mathMl = toMMl(item.data.root);
178
+ const parsedMathMl = mathMl.replaceAll('\n', '');
179
+
180
+ item.data.typesetRoot.setAttribute('data-mathml', parsedMathMl);
181
+ }
182
+ } catch (e) {
183
+ console.error(e.toString());
184
+ }
185
+
186
+ updatedDocument.clear();
175
187
  }
176
188
  };
177
189
  };
@@ -179,6 +191,7 @@ const bootstrap = opts => {
179
191
  const renderMath = (el, renderOpts) => {
180
192
  //TODO: remove this - has nothing to do with math-rendering (it's from editable-html)
181
193
  fixMathElements();
194
+ adjustMathMLStyle();
182
195
 
183
196
  if (!getGlobal().instance) {
184
197
  getGlobal().instance = bootstrap(renderOpts);
@@ -205,7 +218,7 @@ const renderMath = (el, renderOpts) => {
205
218
  "display": 'in-line',
206
219
  "text-align": 'left'
207
220
  } which prevents it from showing as a newline value
208
- */
221
+ */
209
222
  CHTMLmspace.styles = {
210
223
  'mjx-mspace': {
211
224
  display: 'block',