Skip to content

Commit

Permalink
Replace MathJax integration with official Just The Docs suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Mar 28, 2024
1 parent e280040 commit 6fd788c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 15 deletions.
2 changes: 2 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ liquid:
#strict_variables: true # commented out because it isn't supported by just-the-docs
strict_filters: true

math: mathjax

defaults:
- scope:
path: ""
Expand Down
7 changes: 7 additions & 0 deletions _includes/head_custom.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@

<meta name="Keywords" content="GAP,group theory,computational group theory,algebra,computational algebra,computational discrete algebra,mathematical computation" />

{% assign math = page.math | default: layout.math | default: site.math %}

{% case math %}
{% when "mathjax" %}
{% include mathjax.html %}
{% endcase %}

<title>{{ page.title }}</title>
9 changes: 9 additions & 0 deletions _includes/mathjax.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- Automatically display code inside script tags with type=math/tex using MathJax -->
<script type="text/javascript" defer
src="{{ site.baseurl }}/assets/js/mathjax-script-type.js">
</script>

<!-- Copied from https://docs.mathjax.org/en/latest/web/components/combined.html -->
<script type="text/javascript" id="MathJax-script" defer
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>
15 changes: 0 additions & 15 deletions _layouts/default_with_title.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,4 @@
layout: default
---
<h2>{{ page.title }}</h2>
<!-- add script to allow latex code to be displayed -->
<script>
MathJax = {
tex: {
inlineMath: [ ['$', '$'], ['\\(', '\\)'] ]
},
svg: {
fontCache: 'global'
}
};
</script>
<script
type="text/javascript" id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>
{{ content }}
12 changes: 12 additions & 0 deletions _layouts/mathjax.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
layout: default
math: mathjax
---
<div style="display: none">
\(
<!-- optional definitions using \newcommand, etc.
see https://docs.mathjax.org/en/latest/input/tex/macros.html -->
\)
</div>

{{ content }}
25 changes: 25 additions & 0 deletions assets/js/mathjax-script-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copied from https://docs.mathjax.org/en/latest/upgrading/v2.html#changes-in-the-mathjax-api
MathJax = {
tex: {
inlineMath: [ ['$', '$'], ['\\(', '\\)'] ]
},
svg: {
fontCache: 'global'
},

options: {
renderActions: {
findScript: [10, function (doc) {
for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
const display = !!node.type.match(/; *mode=display/);
const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
const text = document.createTextNode('');
node.parentNode.replaceChild(text, node);
math.start = {node: text, delim: '', n: 0};
math.end = {node: text, delim: '', n: 0};
doc.math.push(math);
}
}, '']
}
}
};

0 comments on commit 6fd788c

Please sign in to comment.