Skip to content

Commit 2433206

Browse files
committed
Update *-page to not include styles if no math is found (preload version)
1 parent 8fa3d81 commit 2433206

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

preload/am2chtml-page

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,19 @@ MathJax.loader.preLoad(
100100
MathJax.config.startup.ready();
101101

102102
//
103-
// Output the typeset page
103+
// Typeset the document
104104
//
105105
MathJax.typeset();
106106
const adaptor = MathJax.startup.adaptor;
107107
const html = MathJax.startup.document;
108+
109+
//
110+
// If no math was found on the page, remove the stylesheet
111+
//
112+
if (html.math.toArray().length === 0) adaptor.remove(html.outputJax.chtmlStyles);
113+
114+
//
115+
// Output the resulting HTML
116+
//
108117
console.log(adaptor.doctype(html.document));
109118
console.log(adaptor.outerHTML(adaptor.root(html.document)));

preload/mml2chtml-page

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,19 @@ MathJax.loader.preLoad(
105105
MathJax.config.startup.ready();
106106

107107
//
108-
// Output the typeset page
108+
// Typeset the document
109109
//
110110
MathJax.typeset();
111111
const adaptor = MathJax.startup.adaptor;
112112
const html = MathJax.startup.document;
113+
114+
//
115+
// If no math was found on the page, remove the stylesheet
116+
//
117+
if (html.math.toArray().length === 0) adaptor.remove(html.outputJax.chtmlStyles);
118+
119+
//
120+
// Output the resulting HTML
121+
//
113122
console.log(adaptor.doctype(html.document));
114123
console.log(adaptor.outerHTML(adaptor.root(html.document)));

preload/mml2svg-page

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,23 @@ MathJax.loader.preLoad(
9090
MathJax.config.startup.ready();
9191

9292
//
93-
// Output the typeset page
93+
// Typeset the document
9494
//
9595
MathJax.typeset();
9696
const adaptor = MathJax.startup.adaptor;
9797
const html = MathJax.startup.document;
98+
99+
//
100+
// If no math was found on the page, remove the stylesheet and font cache (if any)
101+
//
102+
if (html.math.toArray().length === 0) {
103+
adaptor.remove(html.outputJax.svgStyles);
104+
const cache = adaptor.elementById(adaptor.body(html.document), 'MJX-SVG-global-cache');
105+
if (cache) adaptor.remove(cache);
106+
}
107+
108+
//
109+
// Output the resulting HTML
110+
//
98111
console.log(adaptor.doctype(html.document));
99112
console.log(adaptor.outerHTML(adaptor.root(html.document)));

preload/tex2chtml-page

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,19 @@ MathJax.loader.preLoad(
112112
MathJax.config.startup.ready();
113113

114114
//
115-
// Output the typeset page
115+
// Typeset the page
116116
//
117117
MathJax.typeset();
118118
const adaptor = MathJax.startup.adaptor;
119119
const html = MathJax.startup.document;
120+
121+
//
122+
// If no math was found on the page, remove the stylesheet
123+
//
124+
if (html.math.toArray().length === 0) adaptor.remove(html.outputJax.chtmlStyles);
125+
126+
//
127+
// Output the resulting HTML
128+
//
120129
console.log(adaptor.doctype(html.document));
121130
console.log(adaptor.outerHTML(adaptor.root(html.document)));

preload/tex2svg-page

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,23 @@ MathJax.loader.preLoad(
114114
MathJax.config.startup.ready();
115115

116116
//
117-
// Output the typeset page
117+
// Typeset the document
118118
//
119119
MathJax.typeset();
120120
const adaptor = MathJax.startup.adaptor;
121121
const html = MathJax.startup.document;
122+
123+
//
124+
// If no math was found on the page, remove the stylesheet and font cache (if any)
125+
//
126+
if (html.math.toArray().length === 0) {
127+
adaptor.remove(html.outputJax.svgStyles);
128+
const cache = adaptor.elementById(adaptor.body(html.document), 'MJX-SVG-global-cache');
129+
if (cache) adaptor.remove(cache);
130+
}
131+
132+
//
133+
// Output the resulting HTML
134+
//
122135
console.log(adaptor.doctype(html.document));
123136
console.log(adaptor.outerHTML(adaptor.root(html.document)));

0 commit comments

Comments
 (0)