@pie-lib/math-rendering 2.4.1 → 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 +11 -0
- package/lib/render-math.js +8 -7
- package/lib/render-math.js.map +1 -1
- package/package.json +2 -2
- package/src/render-math.js +17 -21
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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
|
+
|
|
6
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)
|
|
7
18
|
|
|
8
19
|
|
package/lib/render-math.js
CHANGED
|
@@ -123,6 +123,13 @@ var fixMathElements = function fixMathElements() {
|
|
|
123
123
|
|
|
124
124
|
exports.fixMathElements = fixMathElements;
|
|
125
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
|
+
|
|
126
133
|
var bootstrap = function bootstrap(opts) {
|
|
127
134
|
if (typeof window === 'undefined') {
|
|
128
135
|
return {
|
|
@@ -154,21 +161,15 @@ var bootstrap = function bootstrap(opts) {
|
|
|
154
161
|
longdiv: '\\enclose{longdiv}'
|
|
155
162
|
};
|
|
156
163
|
var texConfig = opts.useSingleDollar ? {
|
|
157
|
-
loader: {
|
|
158
|
-
require: require
|
|
159
|
-
},
|
|
160
164
|
packages: packages,
|
|
161
165
|
macros: macros,
|
|
162
166
|
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
|
163
|
-
displayMath: [['$$', '$$'], ['\\[', '\\]']],
|
|
164
167
|
processEscapes: true
|
|
165
168
|
} : {
|
|
166
169
|
packages: packages,
|
|
167
170
|
macros: macros
|
|
168
171
|
};
|
|
169
172
|
var mmlConfig = {
|
|
170
|
-
parseAs: 'html',
|
|
171
|
-
forceReparse: false,
|
|
172
173
|
parseError: function parseError(node) {
|
|
173
174
|
// function to process parsing errors
|
|
174
175
|
console.log('error:', node);
|
|
@@ -181,7 +182,6 @@ var bootstrap = function bootstrap(opts) {
|
|
|
181
182
|
wrapperFactory: new _WrapperFactory.CHTMLWrapperFactory(_objectSpread(_objectSpread({}, _WrapperFactory.CHTMLWrapperFactory.defaultNodes), _mstack.chtmlNodes))
|
|
182
183
|
};
|
|
183
184
|
var mml = new _mathml.MathML(mmlConfig);
|
|
184
|
-
console.log([new _tex.TeX(texConfig), mml]);
|
|
185
185
|
var customMmlFactory = new _MmlFactory.MmlFactory(_objectSpread(_objectSpread({}, _MmlFactory.MmlFactory.defaultNodes), _mstack.mmlNodes));
|
|
186
186
|
|
|
187
187
|
var html = _mathjax.mathjax.document(document, {
|
|
@@ -232,6 +232,7 @@ var bootstrap = function bootstrap(opts) {
|
|
|
232
232
|
var renderMath = function renderMath(el, renderOpts) {
|
|
233
233
|
//TODO: remove this - has nothing to do with math-rendering (it's from editable-html)
|
|
234
234
|
fixMathElements();
|
|
235
|
+
adjustMathMLStyle();
|
|
235
236
|
|
|
236
237
|
if (!getGlobal().instance) {
|
|
237
238
|
getGlobal().instance = bootstrap(renderOpts);
|
package/lib/render-math.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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","bootstrap","Typeset","useSingleDollar","console","warn","packages","AllPackages","filter","push","macros","parallelogram","overarc","napprox","longdiv","texConfig","loader","require","inlineMath","displayMath","processEscapes","mmlConfig","parseAs","forceReparse","parseError","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","updatedDocument","findMath","length","compile","getMetrics","typeset","updateDocument","list","next","data","mathMl","root","parsedMathMl","replaceAll","typesetRoot","setAttribute","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,qCAApB;AACD;;AAWD,IAAMC,OAAO,GAAG,IAAIC,0CAAJ,EAAhB;;AACA,IAAMC,KAAK,GAAG,SAARA,KAAQ,CAAAC,IAAI;AAAA,SAAIH,OAAO,CAACI,SAAR,CAAkBD,IAAlB,CAAJ;AAAA,CAAlB;;AAEA,IAAME,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,IAA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,eAAe,CAACkB,KAAhB;AACD;AAzBI,GAAP;AA2BD,CAxHD;;AA0HA,IAAMC,UAAU,GAAG,SAAbA,UAAa,CAACC,EAAD,EAAKC,UAAL,EAAoB;AACrC;AACA9E,EAAAA,eAAe;;AAEf,MAAI,CAACd,SAAS,GAAG6F,QAAjB,EAA2B;AACzB7F,IAAAA,SAAS,GAAG6F,QAAZ,GAAuBzE,SAAS,CAACwE,UAAD,CAAhC;AACD;;AAED,MAAI,CAACD,EAAL,EAAS;AACP9F,IAAAA,GAAG,CAAC,iBAAD,CAAH;AACA;AACD;;AAED,MAAI8F,EAAE,YAAYG,OAAlB,EAA2B;AACzB9F,IAAAA,SAAS,GAAG6F,QAAZ,CAAqBxE,OAArB,CAA6BsE,EAA7B;AACD,GAFD,MAEO,IAAIA,EAAE,CAAClB,MAAP,EAAe;AAAA;;AACpB,QAAMsB,GAAG,GAAGC,KAAK,CAACC,IAAN,CAAWN,EAAX,CAAZ;;AACA,2BAAA3F,SAAS,GAAG6F,QAAZ,EAAqBxE,OAArB,+CAAgC0E,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 { 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 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 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\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,qCAApB;AACD;;AAWD,IAAMC,OAAO,GAAG,IAAIC,0CAAJ,EAAhB;;AACA,IAAMC,KAAK,GAAG,SAARA,KAAQ,CAAAC,IAAI;AAAA,SAAIH,OAAO,CAACI,SAAR,CAAkBD,IAAlB,CAAJ;AAAA,CAAlB;;AAEA,IAAME,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,OAAOd,MAAP,KAAkB,WAAtB,EAAmC;AACjC,QAAI,CAACA,MAAM,CAACU,GAAD,CAAX,EAAkB;AAChBV,MAAAA,MAAM,CAACU,GAAD,CAAN,GAAc,EAAd;AACD;;AACD,WAAOV,MAAM,CAACU,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,IAAM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;AAAA;;AACpB,QAAMqB,GAAG,GAAGC,KAAK,CAACC,IAAN,CAAWN,EAAX,CAAZ;;AACA,2BAAAxF,SAAS,GAAG0F,QAAZ,EAAqBlE,OAArB,+CAAgCoE,GAAhC;AACD;AACF,CApBD;AAsBA;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 { 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.4.
|
|
3
|
+
"version": "2.4.2",
|
|
4
4
|
"description": "math rendering utilities",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
"lodash": "^4.17.11",
|
|
15
15
|
"mathjax-full": "3.2.0"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "debcaf764c62d97a1401f2898b062183847ce33b",
|
|
18
18
|
"scripts": {}
|
|
19
19
|
}
|
package/src/render-math.js
CHANGED
|
@@ -71,6 +71,11 @@ export const fixMathElements = () => {
|
|
|
71
71
|
mathElements.forEach(item => fixMathElement(item));
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
+
const adjustMathMLStyle = () => {
|
|
75
|
+
const nodes = document.querySelectorAll('math');
|
|
76
|
+
nodes.forEach(node => node.setAttribute('displaystyle', 'true'));
|
|
77
|
+
};
|
|
78
|
+
|
|
74
79
|
const bootstrap = opts => {
|
|
75
80
|
if (typeof window === 'undefined') {
|
|
76
81
|
return { Typeset: () => ({}) };
|
|
@@ -98,29 +103,20 @@ const bootstrap = opts => {
|
|
|
98
103
|
|
|
99
104
|
const texConfig = opts.useSingleDollar
|
|
100
105
|
? {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
],
|
|
110
|
-
displayMath: [
|
|
111
|
-
['$$', '$$'],
|
|
112
|
-
['\\[', '\\]']
|
|
113
|
-
],
|
|
114
|
-
processEscapes: true
|
|
115
|
-
}
|
|
106
|
+
packages,
|
|
107
|
+
macros,
|
|
108
|
+
inlineMath: [
|
|
109
|
+
['$', '$'],
|
|
110
|
+
['\\(', '\\)']
|
|
111
|
+
],
|
|
112
|
+
processEscapes: true
|
|
113
|
+
}
|
|
116
114
|
: {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
115
|
+
packages,
|
|
116
|
+
macros
|
|
117
|
+
};
|
|
120
118
|
|
|
121
119
|
const mmlConfig = {
|
|
122
|
-
parseAs: 'html',
|
|
123
|
-
forceReparse: false,
|
|
124
120
|
parseError: function(node) {
|
|
125
121
|
// function to process parsing errors
|
|
126
122
|
console.log('error:', node);
|
|
@@ -139,7 +135,6 @@ const bootstrap = opts => {
|
|
|
139
135
|
};
|
|
140
136
|
|
|
141
137
|
const mml = new MathML(mmlConfig);
|
|
142
|
-
console.log([new TeX(texConfig), mml]);
|
|
143
138
|
|
|
144
139
|
const customMmlFactory = new MmlFactory({
|
|
145
140
|
...MmlFactory.defaultNodes,
|
|
@@ -196,6 +191,7 @@ const bootstrap = opts => {
|
|
|
196
191
|
const renderMath = (el, renderOpts) => {
|
|
197
192
|
//TODO: remove this - has nothing to do with math-rendering (it's from editable-html)
|
|
198
193
|
fixMathElements();
|
|
194
|
+
adjustMathMLStyle();
|
|
199
195
|
|
|
200
196
|
if (!getGlobal().instance) {
|
|
201
197
|
getGlobal().instance = bootstrap(renderOpts);
|