|
1 | 1 | /// <reference types="./mathjax" /> |
2 | | -// |
3 | | -// Import the needed TeX packages |
4 | | -// |
5 | | -import "@mathjax/src/js/input/tex/base/BaseConfiguration.js" |
6 | | -import "@mathjax/src/js/input/tex/ams/AmsConfiguration.js" |
7 | | -import "@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js" |
8 | | -import "@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js" |
9 | | -import { liteAdaptor } from "@mathjax/src/js/adaptors/liteAdaptor" |
10 | | -import { RegisterHTMLHandler } from "@mathjax/src/js/handlers/html" |
11 | | -import { TeX } from "@mathjax/src/js/input/tex" |
12 | | -import { mathjax } from "@mathjax/src/js/mathjax" |
13 | | -import { CHTML } from "@mathjax/src/js/output/chtml" |
| 2 | +let mathjax: any |
| 3 | +async function loadMathJax() { |
| 4 | + return (mathjax ??= (await import("mathjax/tex-chtml.js")).mathjax) |
| 5 | +} |
14 | 6 |
|
15 | 7 | export namespace math { |
16 | | - export async function typeset(document: string): Promise<string> { |
17 | | - const adaptor = liteAdaptor() |
18 | | - RegisterHTMLHandler(adaptor as any) |
19 | | - const tex = new TeX({ packages: ["base", "ams", "newcommand", "noundefined"], inlineMath: [["$", "$"]] }) |
20 | | - const chtml = new CHTML({ |
21 | | - fontURL: "https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.0.0/es5/output/chtml/fonts/woff-v2", |
22 | | - }) |
23 | | - const html = mathjax.document(document, { InputJax: tex, OutputJax: chtml }) |
24 | | - html.render() |
25 | | - return adaptor.outerHTML(adaptor.root(html.document)) |
| 8 | + export async function typeset(math: string): Promise<string> { |
| 9 | + const mj = await loadMathJax() |
| 10 | + const node = await mj.tex2chtmlPromise(math, { display: true }) |
| 11 | + return node.outerHTML |
26 | 12 | } |
27 | 13 | } |
0 commit comments