@pie-lib/math-rendering 2.3.6 → 2.3.10-next.86
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.json +30 -0
- package/CHANGELOG.md +13 -33
- package/lib/render-math.js +24 -2
- package/lib/render-math.js.map +1 -1
- package/package.json +3 -3
- package/src/render-math.js +26 -3
package/CHANGELOG.json
CHANGED
|
@@ -638,5 +638,35 @@
|
|
|
638
638
|
"committerDate": "2021-02-22 09:01:40 +0200",
|
|
639
639
|
"isTagged": true,
|
|
640
640
|
"tag": "@pie-lib/math-rendering@2.3.5"
|
|
641
|
+
},
|
|
642
|
+
{
|
|
643
|
+
"type": "fix",
|
|
644
|
+
"scope": "math-rendering",
|
|
645
|
+
"subject": "fix symbols in math markup that trigger undefined control sequence error PD-1267, PD-368, PD-1173",
|
|
646
|
+
"merge": null,
|
|
647
|
+
"header": "fix(math-rendering): fix symbols in math markup that trigger undefined control sequence error PD-1267, PD-368, PD-1173",
|
|
648
|
+
"body": null,
|
|
649
|
+
"footer": null,
|
|
650
|
+
"notes": [],
|
|
651
|
+
"hash": "a7d9934bea5d0305daa6d75820c007d1e76f3fbb",
|
|
652
|
+
"gitTags": "",
|
|
653
|
+
"committerDate": "2021-08-17 10:59:50 +0300",
|
|
654
|
+
"isTagged": true,
|
|
655
|
+
"tag": "@pie-lib/math-rendering@2.3.9"
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
"type": "fix",
|
|
659
|
+
"scope": null,
|
|
660
|
+
"subject": "wip",
|
|
661
|
+
"merge": null,
|
|
662
|
+
"header": "fix: wip",
|
|
663
|
+
"body": null,
|
|
664
|
+
"footer": null,
|
|
665
|
+
"notes": [],
|
|
666
|
+
"hash": "fe4316df075edfc2c0565641b58c4ca453057651",
|
|
667
|
+
"gitTags": " (origin/fix/fix-math-module)",
|
|
668
|
+
"committerDate": "2021-09-06 13:29:44 +0100",
|
|
669
|
+
"isTagged": true,
|
|
670
|
+
"tag": "@pie-lib/math-rendering@2.3.10"
|
|
641
671
|
}
|
|
642
672
|
]
|
package/CHANGELOG.md
CHANGED
|
@@ -3,79 +3,59 @@
|
|
|
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.3.
|
|
6
|
+
## [2.3.9](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.8...@pie-lib/math-rendering@2.3.9) (2021-08-30)
|
|
7
7
|
|
|
8
|
-
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
9
8
|
|
|
9
|
+
### Bug Fixes
|
|
10
10
|
|
|
11
|
+
* **math-rendering:** fix symbols in math markup that trigger undefined control sequence error PD-1267, PD-368, PD-1173 ([a7d9934](https://github.com/pie-framework/pie-lib/commit/a7d9934))
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
|
|
14
|
-
## [2.3.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.4...@pie-lib/math-rendering@2.3.5) (2021-03-01)
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
## [2.3.8](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.6...@pie-lib/math-rendering@2.3.8) (2021-06-25)
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
20
20
|
|
|
21
|
+
## [2.3.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.5...@pie-lib/math-rendering@2.3.6) (2021-03-01)
|
|
21
22
|
|
|
23
|
+
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
22
24
|
|
|
25
|
+
## [2.3.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.4...@pie-lib/math-rendering@2.3.5) (2021-03-01)
|
|
23
26
|
|
|
27
|
+
### Bug Fixes
|
|
28
|
+
|
|
29
|
+
- **math-rendering:** linebreak rendering fixed for mathquill custom elements - PD-787 ([5216f6a](https://github.com/pie-framework/pie-lib/commit/5216f6a))
|
|
24
30
|
|
|
25
31
|
## [2.3.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.3...@pie-lib/math-rendering@2.3.4) (2021-02-15)
|
|
26
32
|
|
|
27
33
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
35
|
## [2.3.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.1...@pie-lib/math-rendering@2.3.3) (2021-02-15)
|
|
34
36
|
|
|
35
37
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
39
|
## [2.3.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.0...@pie-lib/math-rendering@2.3.1) (2021-01-28)
|
|
42
40
|
|
|
43
|
-
|
|
44
41
|
### Bug Fixes
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
- add lodash dependency ([de2227f](https://github.com/pie-framework/pie-lib/commit/de2227f))
|
|
51
44
|
|
|
52
45
|
# [2.3.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.2.4...@pie-lib/math-rendering@2.3.0) (2021-01-25)
|
|
53
46
|
|
|
54
|
-
|
|
55
47
|
### Features
|
|
56
48
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
49
|
+
- demo changes include for the issue PD-368 ([c493d9f](https://github.com/pie-framework/pie-lib/commit/c493d9f))
|
|
62
50
|
|
|
63
51
|
## [2.2.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.2.3...@pie-lib/math-rendering@2.2.4) (2021-01-11)
|
|
64
52
|
|
|
65
53
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
66
54
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
55
|
## [2.2.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.2.2...@pie-lib/math-rendering@2.2.3) (2020-10-26)
|
|
72
56
|
|
|
73
57
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
74
58
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
59
|
## [2.2.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.2.1...@pie-lib/math-rendering@2.2.2) (2020-10-26)
|
|
80
60
|
|
|
81
61
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
package/lib/render-math.js
CHANGED
|
@@ -17,6 +17,8 @@ var _html = require("mathjax-full/js/handlers/html");
|
|
|
17
17
|
|
|
18
18
|
var _browserAdaptor = require("mathjax-full/js/adaptors/browserAdaptor");
|
|
19
19
|
|
|
20
|
+
var _AllPackages = require("mathjax-full/js/input/tex/AllPackages");
|
|
21
|
+
|
|
20
22
|
var _package = _interopRequireDefault(require("../package.json"));
|
|
21
23
|
|
|
22
24
|
var _mstack = require("./mstack");
|
|
@@ -123,10 +125,29 @@ var bootstrap = function bootstrap(opts) {
|
|
|
123
125
|
console.warn('[math-rendering] using $ is not advisable, please use $$..$$ or \\(...\\)');
|
|
124
126
|
}
|
|
125
127
|
|
|
128
|
+
var packages = _AllPackages.AllPackages.filter(function (name) {
|
|
129
|
+
return name !== 'bussproofs';
|
|
130
|
+
}); // Bussproofs needs an output jax
|
|
131
|
+
// The autoload extension predefines all the macros from the extensions that haven't been loaded already
|
|
132
|
+
// so that they automatically load the needed extension when they are first used
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
packages.push('autoload');
|
|
136
|
+
var macros = {
|
|
137
|
+
parallelogram: "\\lower.2em{\\Huge\\unicode{x25B1}}",
|
|
138
|
+
overarc: '\\overparen',
|
|
139
|
+
napprox: '\\not\\approx',
|
|
140
|
+
longdiv: '\\enclose{longdiv}'
|
|
141
|
+
};
|
|
126
142
|
var texConfig = opts.useSingleDollar ? {
|
|
143
|
+
packages: packages,
|
|
144
|
+
macros: macros,
|
|
127
145
|
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
|
128
146
|
processEscapes: true
|
|
129
|
-
} : {
|
|
147
|
+
} : {
|
|
148
|
+
packages: packages,
|
|
149
|
+
macros: macros
|
|
150
|
+
};
|
|
130
151
|
var mmlConfig = {
|
|
131
152
|
parseError: function parseError(node) {
|
|
132
153
|
// function to process parsing errors
|
|
@@ -210,7 +231,8 @@ var renderMath = function renderMath(el, renderOpts) {
|
|
|
210
231
|
_mspace.CHTMLmspace.styles = {
|
|
211
232
|
'mjx-mspace': {
|
|
212
233
|
display: 'block',
|
|
213
|
-
'text-align': 'center'
|
|
234
|
+
'text-align': 'center',
|
|
235
|
+
height: '5px'
|
|
214
236
|
}
|
|
215
237
|
};
|
|
216
238
|
var _default = renderMath;
|
package/lib/render-math.js.map
CHANGED
|
@@ -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","texConfig","inlineMath","processEscapes","mmlConfig","parseError","node","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","findMath","length","compile","getMetrics","typeset","updateDocument","clear","renderMath","el","renderOpts","instance","Element","arr","Array","from","CHTMLmspace","styles","display"],"mappings":";;;;;;;AAAA;;AACA;;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AAA,QAAQ,EAARA;AAAF,OAAlB,GAAiC,EAD7C,EAEGG,OAFH,GAGGC,UAHH,GAIGC,OAJH,GAKGC,cALH,GAMGC,KANH;AAOD;AAZI,GAAP;AAcD,CAzED;;AA2EA,IAAMC,UAAU,GAAG,SAAbA,UAAa,CAACC,EAAD,EAAKC,UAAL,EAAoB;AACrC;AACArD,EAAAA,eAAe;;AAEf,MAAI,CAACd,SAAS,GAAGoE,QAAjB,EAA2B;AACzBpE,IAAAA,SAAS,GAAGoE,QAAZ,GAAuBhD,SAAS,CAAC+C,UAAD,CAAhC;AACD;;AAED,MAAI,CAACD,EAAL,EAAS;AACPrE,IAAAA,GAAG,CAAC,iBAAD,CAAH;AACA;AACD;;AAED,MAAIqE,EAAE,YAAYG,OAAlB,EAA2B;AACzBrE,IAAAA,SAAS,GAAGoE,QAAZ,CAAqB/C,OAArB,CAA6B6C,EAA7B;AACD,GAFD,MAEO,IAAIA,EAAE,CAACP,MAAP,EAAe;AAAA;;AACpB,QAAMW,GAAG,GAAGC,KAAK,CAACC,IAAN,CAAWN,EAAX,CAAZ;;AACA,2BAAAlE,SAAS,GAAGoE,QAAZ,EAAqB/C,OAArB,+CAAgCiD,GAAhC;AACD;AACF,CAnBD;AAqBA;;;;;;;;;;;AASAG,oBAAYC,MAAZ,GAAqB;AACnB,gBAAc;AACZC,IAAAA,OAAO,EAAE,OADG;AAEZ,kBAAc;AAFF;AADK,CAArB;eAOeV,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';\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 texConfig = opts.useSingleDollar\n ? { inlineMath: [['$', '$'], ['\\\\(', '\\\\)']], processEscapes: true }\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\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 }\n};\n\nexport default renderMath;\n"],"file":"render-math.js"}
|
|
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","inlineMath","processEscapes","mmlConfig","parseError","node","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","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,EAA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ACC,EAAD,EAAKC,UAAL,EAAoB;AACrC;AACA9D,EAAAA,eAAe;;AAEf,MAAI,CAACd,SAAS,GAAG6E,QAAjB,EAA2B;AACzB7E,IAAAA,SAAS,GAAG6E,QAAZ,GAAuBzD,SAAS,CAACwD,UAAD,CAAhC;AACD;;AAED,MAAI,CAACD,EAAL,EAAS;AACP9E,IAAAA,GAAG,CAAC,iBAAD,CAAH;AACA;AACD;;AAED,MAAI8E,EAAE,YAAYG,OAAlB,EAA2B;AACzB9E,IAAAA,SAAS,GAAG6E,QAAZ,CAAqBxD,OAArB,CAA6BsD,EAA7B;AACD,GAFD,MAEO,IAAIA,EAAE,CAACP,MAAP,EAAe;AAAA;;AACpB,QAAMW,GAAG,GAAGC,KAAK,CAACC,IAAN,CAAWN,EAAX,CAAZ;;AACA,2BAAA3E,SAAS,GAAG6E,QAAZ,EAAqBxD,OAArB,+CAAgC0D,GAAhC;AACD;AACF,CAnBD;AAqBA;;;;;;;;;;;AASAG,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 packages,\n macros,\n inlineMath: [['$', '$'], ['\\\\(', '\\\\)']],\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\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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/math-rendering",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.10-next.86+f45a2d2e",
|
|
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.
|
|
15
|
+
"mathjax-full": "^3.2.0"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "f45a2d2e117fa21914e67a74c97fbec724227986",
|
|
18
18
|
"scripts": {}
|
|
19
19
|
}
|
package/src/render-math.js
CHANGED
|
@@ -5,6 +5,7 @@ import { TeX } from 'mathjax-full/js/input/tex';
|
|
|
5
5
|
import { CHTML } from 'mathjax-full/js/output/chtml';
|
|
6
6
|
import { RegisterHTMLHandler } from 'mathjax-full/js/handlers/html';
|
|
7
7
|
import { browserAdaptor } from 'mathjax-full/js/adaptors/browserAdaptor';
|
|
8
|
+
import { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';
|
|
8
9
|
|
|
9
10
|
if (typeof window !== 'undefined') {
|
|
10
11
|
RegisterHTMLHandler(browserAdaptor());
|
|
@@ -78,9 +79,30 @@ const bootstrap = opts => {
|
|
|
78
79
|
console.warn('[math-rendering] using $ is not advisable, please use $$..$$ or \\(...\\)');
|
|
79
80
|
}
|
|
80
81
|
|
|
82
|
+
const packages = AllPackages.filter(name => name !== 'bussproofs'); // Bussproofs needs an output jax
|
|
83
|
+
|
|
84
|
+
// The autoload extension predefines all the macros from the extensions that haven't been loaded already
|
|
85
|
+
// so that they automatically load the needed extension when they are first used
|
|
86
|
+
packages.push('autoload');
|
|
87
|
+
|
|
88
|
+
const macros = {
|
|
89
|
+
parallelogram: '\\lower.2em{\\Huge\\unicode{x25B1}}',
|
|
90
|
+
overarc: '\\overparen',
|
|
91
|
+
napprox: '\\not\\approx',
|
|
92
|
+
longdiv: '\\enclose{longdiv}'
|
|
93
|
+
};
|
|
94
|
+
|
|
81
95
|
const texConfig = opts.useSingleDollar
|
|
82
|
-
? {
|
|
83
|
-
|
|
96
|
+
? {
|
|
97
|
+
packages,
|
|
98
|
+
macros,
|
|
99
|
+
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
|
100
|
+
processEscapes: true
|
|
101
|
+
}
|
|
102
|
+
: {
|
|
103
|
+
packages,
|
|
104
|
+
macros
|
|
105
|
+
};
|
|
84
106
|
|
|
85
107
|
const mmlConfig = {
|
|
86
108
|
parseError: function(node) {
|
|
@@ -174,7 +196,8 @@ const renderMath = (el, renderOpts) => {
|
|
|
174
196
|
CHTMLmspace.styles = {
|
|
175
197
|
'mjx-mspace': {
|
|
176
198
|
display: 'block',
|
|
177
|
-
'text-align': 'center'
|
|
199
|
+
'text-align': 'center',
|
|
200
|
+
height: '5px'
|
|
178
201
|
}
|
|
179
202
|
};
|
|
180
203
|
|