Add Mathjax to Hugo

Code copy&paste from Ataias Pereira Reis’s PR adityatelange/hugo-PaperMod#140 with some modifed on toggle option. Creat two files under layouts/partials/. Create math.html: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 <script> MathJax = { tex: { inlineMath: [["$", "$"], ["\\(", "\\)"]], displayMath: [["$$", "$$"]], processEscapes: true, processEnvironments: true, tags: "ams", }, options: { skipHtmlTags: [ "script", "noscript", "style", "textarea", "pre", ], }, startup: { ready: () => { MathJax.startup.defaultReady(); // Fix <code> tags after MathJax finishes running const all = MathJax.typesetPromise(); all.then(() => { document.querySelectorAll(".MathJax").forEach( (el) => { el.parentNode.className += " has-jax"; }, ); }); }, }, }; </script> <script id="MathJax-script" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js" ></script> Create extend_head.html: ...

 ·  · 1 min · 177 words · ringsaturn