Skip to content

Commit dac7e27

Browse files
committed
Merge branch '23-fix-mathjax-rendering-issues-with-instant-navigation' into release
2 parents 81bdb91 + dc56431 commit dac7e27

2 files changed

Lines changed: 20 additions & 23 deletions

File tree

docs/javascripts/mathjax.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1-
// Load this BEFORE the MathJax CDN script in mkdocs.yml
1+
// MathJax v3 configuration for MkDocs Material
2+
// Place this file BEFORE the MathJax CDN script in mkdocs.yml
3+
24
window.MathJax = {
35
tex: {
4-
// include the delimiters you actually use:
5-
inlineMath: [['\\(', '\\)'], ['$', '$']],
6-
displayMath: [['\\[', '\\]'], ['$$', '$$']],
6+
inlineMath: [['\\(', '\\)'], ['$', '$']], // inline math
7+
displayMath: [['\\[', '\\]'], ['$$', '$$']], // display math
78
processEscapes: true,
89
processEnvironments: true
910
},
1011
options: {
11-
// With arithmatex(generic:true), content is wrapped in .arithmatex
12-
processHtmlClass: 'arithmatex',
13-
ignoreHtmlClass: '.*' // process only .arithmatex
12+
processHtmlClass: 'arithmatex', // only process .arithmatex spans
13+
ignoreHtmlClass: '.*'
1414
},
1515
startup: {
16-
// we'll control typesetting manually to avoid races
17-
typeset: false
16+
typeset: false // disable auto-typeset; we'll call it ourselves
1817
}
1918
};
2019

21-
// Re-typeset after every MkDocs Material page swap
20+
// Hook into MkDocs Material instant navigation
2221
if (window.document$) {
2322
document$.subscribe(() => {
24-
const container = document.querySelector('.md-content'); // main article
25-
// Defer to next animation frame so DOM is fully replaced
26-
requestAnimationFrame(() => {
27-
MathJax.typesetClear(); // clear previous MathItems
28-
MathJax.typesetPromise([container]); // typeset current page
29-
});
23+
const container = document.querySelector('.md-content');
24+
if (window.MathJax) {
25+
// Ensure MathJax has finished startup before typesetting
26+
MathJax.startup.promise
27+
.then(() => MathJax.typesetPromise([container]))
28+
.catch(err =>
29+
console.error("MathJax typeset failed: " + err.message)
30+
);
31+
}
3032
});
3133
}

mkdocs.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ plugins:
4949
theme:
5050
name: material
5151
custom_dir: docs/overrides
52-
highlightjs: true
5352
features:
5453
#- navigation.instant #<- messes up mathjax, keep it disabled!
5554
- search.suggest
@@ -80,10 +79,7 @@ extra:
8079
link: https://www.linkedin.com/in/steven-varga-04224a19/
8180
- icon: material/github
8281
link: https://github.com/vargaconsulting
83-
icons:
84-
- material
85-
- fontawesome/brands
86-
- fontawesome/solid
82+
8783
analytics:
8884
provider: google
8985
property: G-L58Z6SZ3TN
@@ -106,7 +102,6 @@ markdown_extensions:
106102
generic: true
107103
- pymdownx.details
108104
- pymdownx.superfences
109-
- pymdownx.snippets
110105
- pymdownx.blocks.caption
111106
- pymdownx.caret
112107
- pymdownx.mark
@@ -123,10 +118,10 @@ markdown_extensions:
123118
- docs/blog/scripts
124119

125120
extra_javascript:
121+
- javascripts/mathjax.js
126122
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
127123
- https://cdn.tailwindcss.com
128124
- javascripts/tw-config.js
129-
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
130125
- https://cdn.jsdelivr.net/npm/asciinema-player@3.0.1/dist/bundle/asciinema-player.js
131126
- https://unpkg.com/alpinejs@3.14.9/dist/cdn.min.js
132127
- https://unpkg.com/@popperjs/core@2

0 commit comments

Comments
 (0)