@vmz/plugin-mathjax 0.3.4 → 0.3.6
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/README.md +34 -34
- package/package.json +2 -2
- package/runtime.ts +56 -56
package/README.md
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
# @vmz/plugin-mathjax
|
|
2
|
-
|
|
3
|
-
## Broad TeX support when mathematics is the product
|
|
4
|
-
|
|
5
|
-
`@vmz/plugin-mathjax` connects MathJax to VMZ for applications whose mathematical content needs deeper TeX coverage,
|
|
6
|
-
richer notation, or compatibility with existing scholarly material.
|
|
7
|
-
|
|
8
|
-
Peer dependency: `@mathjax/src` **v4+** (replaces deprecated `mathjax-full`).
|
|
9
|
-
|
|
10
|
-
## The tradeoff
|
|
11
|
-
|
|
12
|
-
MathJax is the capability-first choice. It can handle cases that a lightweight typesetter may not, but it carries a
|
|
13
|
-
higher cost than KaTeX. For a documentation-heavy or formula-intensive product, that trade can be exactly right. For
|
|
14
|
-
common formulas on performance-sensitive pages, `@vmz/plugin-katex` is usually the better default.
|
|
15
|
-
|
|
16
|
-
VMZ keeps that choice explicit. The formula engine changes the presentation capability, not the application's state,
|
|
17
|
-
server, route, or deployment semantics. SSR and progressive interaction remain part of the VMZ application plan.
|
|
18
|
-
|
|
19
|
-
Think of MathJax as the right specialist tool when formula fidelity is worth a heavier delivery budget. 📐
|
|
20
|
-
|
|
21
|
-
## Where it earns its weight
|
|
22
|
-
|
|
23
|
-
- Scholarly material imported from established TeX sources.
|
|
24
|
-
- Products where advanced notation is central to the experience.
|
|
25
|
-
- Documentation that cannot accept a smaller supported syntax surface.
|
|
26
|
-
- Mathematical publishing that depends on the broader MathJax ecosystem.
|
|
27
|
-
|
|
28
|
-
| Product priority | Better starting point |
|
|
29
|
-
|------------------------------------------------|-----------------------|
|
|
30
|
-
| Fast common formulas and compact delivery | KaTeX |
|
|
31
|
-
| Broad TeX compatibility and specialist content | MathJax |
|
|
32
|
-
|
|
33
|
-
The choice remains local to mathematical presentation. It does not force a different VMZ routing, state, testing, or
|
|
34
|
-
deployment model.
|
|
1
|
+
# @vmz/plugin-mathjax
|
|
2
|
+
|
|
3
|
+
## Broad TeX support when mathematics is the product
|
|
4
|
+
|
|
5
|
+
`@vmz/plugin-mathjax` connects MathJax to VMZ for applications whose mathematical content needs deeper TeX coverage,
|
|
6
|
+
richer notation, or compatibility with existing scholarly material.
|
|
7
|
+
|
|
8
|
+
Peer dependency: `@mathjax/src` **v4+** (replaces deprecated `mathjax-full`).
|
|
9
|
+
|
|
10
|
+
## The tradeoff
|
|
11
|
+
|
|
12
|
+
MathJax is the capability-first choice. It can handle cases that a lightweight typesetter may not, but it carries a
|
|
13
|
+
higher cost than KaTeX. For a documentation-heavy or formula-intensive product, that trade can be exactly right. For
|
|
14
|
+
common formulas on performance-sensitive pages, `@vmz/plugin-katex` is usually the better default.
|
|
15
|
+
|
|
16
|
+
VMZ keeps that choice explicit. The formula engine changes the presentation capability, not the application's state,
|
|
17
|
+
server, route, or deployment semantics. SSR and progressive interaction remain part of the VMZ application plan.
|
|
18
|
+
|
|
19
|
+
Think of MathJax as the right specialist tool when formula fidelity is worth a heavier delivery budget. 📐
|
|
20
|
+
|
|
21
|
+
## Where it earns its weight
|
|
22
|
+
|
|
23
|
+
- Scholarly material imported from established TeX sources.
|
|
24
|
+
- Products where advanced notation is central to the experience.
|
|
25
|
+
- Documentation that cannot accept a smaller supported syntax surface.
|
|
26
|
+
- Mathematical publishing that depends on the broader MathJax ecosystem.
|
|
27
|
+
|
|
28
|
+
| Product priority | Better starting point |
|
|
29
|
+
|------------------------------------------------|-----------------------|
|
|
30
|
+
| Fast common formulas and compact delivery | KaTeX |
|
|
31
|
+
| Broad TeX compatibility and specialist content | MathJax |
|
|
32
|
+
|
|
33
|
+
The choice remains local to mathematical presentation. It does not force a different VMZ routing, state, testing, or
|
|
34
|
+
deployment model.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@vmz/plugin": "0.3.
|
|
3
|
+
"@vmz/plugin": "0.3.6"
|
|
4
4
|
},
|
|
5
5
|
"description": "VMZ MathJax adapter - <Mathjax> + math engine",
|
|
6
6
|
"devDependencies": {
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
},
|
|
44
44
|
"type": "module",
|
|
45
45
|
"types": "./vmz.plugin.ts",
|
|
46
|
-
"version": "0.3.
|
|
46
|
+
"version": "0.3.6"
|
|
47
47
|
}
|
package/runtime.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MathJax TeX -> SVG helper (MathJax v4 / `@mathjax/src`).
|
|
3
|
-
* Prefer KaTeX for common docs; MathJax for heavier TeX coverage.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
type TexConvert = (tex: string, display: boolean) => string;
|
|
7
|
-
|
|
8
|
-
let tex2svg: TexConvert | null = null;
|
|
9
|
-
|
|
10
|
-
const EM = 16;
|
|
11
|
-
const EX = 8;
|
|
12
|
-
|
|
13
|
-
async function getConvert(): Promise<TexConvert> {
|
|
14
|
-
if (tex2svg) return tex2svg;
|
|
15
|
-
|
|
16
|
-
const { mathjax } = await import('@mathjax/src/js/mathjax.js');
|
|
17
|
-
const { TeX } = await import('@mathjax/src/js/input/tex.js');
|
|
18
|
-
const { SVG } = await import('@mathjax/src/js/output/svg.js');
|
|
19
|
-
const { liteAdaptor } = await import('@mathjax/src/js/adaptors/liteAdaptor.js');
|
|
20
|
-
const { RegisterHTMLHandler } = await import('@mathjax/src/js/handlers/html.js');
|
|
21
|
-
await import('@mathjax/src/js/util/asyncLoad/esm.js');
|
|
22
|
-
await import('@mathjax/src/js/input/tex/base/BaseConfiguration.js');
|
|
23
|
-
await import('@mathjax/src/js/input/tex/ams/AmsConfiguration.js');
|
|
24
|
-
|
|
25
|
-
const adaptor = liteAdaptor({ fontSize: EM });
|
|
26
|
-
RegisterHTMLHandler(adaptor);
|
|
27
|
-
|
|
28
|
-
const html = mathjax.document('', {
|
|
29
|
-
InputJax: new TeX({ packages: ['base', 'ams'] }),
|
|
30
|
-
OutputJax: new SVG({ fontCache: 'none', exFactor: EX / EM }),
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
tex2svg = (tex, display) => {
|
|
34
|
-
const node = html.convert(tex ?? '', {
|
|
35
|
-
display: !!display,
|
|
36
|
-
em: EM,
|
|
37
|
-
ex: EX,
|
|
38
|
-
containerWidth: 80 * EM,
|
|
39
|
-
});
|
|
40
|
-
return adaptor.outerHTML(node);
|
|
41
|
-
};
|
|
42
|
-
return tex2svg;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function renderMathjax(tex: string, display = false): Promise<string> {
|
|
46
|
-
const convert = await getConvert();
|
|
47
|
-
return convert(tex, display);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function renderMathjaxFallback(tex: string): string {
|
|
51
|
-
const escaped = String(tex ?? '')
|
|
52
|
-
.replace(/&/g, '&')
|
|
53
|
-
.replace(/</g, '<')
|
|
54
|
-
.replace(/>/g, '>');
|
|
55
|
-
return `<span class="mathjax-fallback">${escaped}</span>`;
|
|
56
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* MathJax TeX -> SVG helper (MathJax v4 / `@mathjax/src`).
|
|
3
|
+
* Prefer KaTeX for common docs; MathJax for heavier TeX coverage.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
type TexConvert = (tex: string, display: boolean) => string;
|
|
7
|
+
|
|
8
|
+
let tex2svg: TexConvert | null = null;
|
|
9
|
+
|
|
10
|
+
const EM = 16;
|
|
11
|
+
const EX = 8;
|
|
12
|
+
|
|
13
|
+
async function getConvert(): Promise<TexConvert> {
|
|
14
|
+
if (tex2svg) return tex2svg;
|
|
15
|
+
|
|
16
|
+
const { mathjax } = await import('@mathjax/src/js/mathjax.js');
|
|
17
|
+
const { TeX } = await import('@mathjax/src/js/input/tex.js');
|
|
18
|
+
const { SVG } = await import('@mathjax/src/js/output/svg.js');
|
|
19
|
+
const { liteAdaptor } = await import('@mathjax/src/js/adaptors/liteAdaptor.js');
|
|
20
|
+
const { RegisterHTMLHandler } = await import('@mathjax/src/js/handlers/html.js');
|
|
21
|
+
await import('@mathjax/src/js/util/asyncLoad/esm.js');
|
|
22
|
+
await import('@mathjax/src/js/input/tex/base/BaseConfiguration.js');
|
|
23
|
+
await import('@mathjax/src/js/input/tex/ams/AmsConfiguration.js');
|
|
24
|
+
|
|
25
|
+
const adaptor = liteAdaptor({ fontSize: EM });
|
|
26
|
+
RegisterHTMLHandler(adaptor);
|
|
27
|
+
|
|
28
|
+
const html = mathjax.document('', {
|
|
29
|
+
InputJax: new TeX({ packages: ['base', 'ams'] }),
|
|
30
|
+
OutputJax: new SVG({ fontCache: 'none', exFactor: EX / EM }),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
tex2svg = (tex, display) => {
|
|
34
|
+
const node = html.convert(tex ?? '', {
|
|
35
|
+
display: !!display,
|
|
36
|
+
em: EM,
|
|
37
|
+
ex: EX,
|
|
38
|
+
containerWidth: 80 * EM,
|
|
39
|
+
});
|
|
40
|
+
return adaptor.outerHTML(node);
|
|
41
|
+
};
|
|
42
|
+
return tex2svg;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function renderMathjax(tex: string, display = false): Promise<string> {
|
|
46
|
+
const convert = await getConvert();
|
|
47
|
+
return convert(tex, display);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function renderMathjaxFallback(tex: string): string {
|
|
51
|
+
const escaped = String(tex ?? '')
|
|
52
|
+
.replace(/&/g, '&')
|
|
53
|
+
.replace(/</g, '<')
|
|
54
|
+
.replace(/>/g, '>');
|
|
55
|
+
return `<span class="mathjax-fallback">${escaped}</span>`;
|
|
56
|
+
}
|