The answers above did not work for me due to race conditions. The Squarespace path displays the Markdown blocks - to process them at runtime and embed HTML output in the DOM on the fly. If this happens after we call the MathJax API for the page set, the newly inserted elements will display raw LaTeX instead of the output of the set.
To answer this, I instead placed this in the footer:
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script> <script> document.addEventListener("DOMNodeInserted", function(event){ var element=event.target; MathJax.Hub.Queue(["Typeset",MathJax.Hub,element.parent]); }); MathJax.Hub.Queue(["Typeset",MathJax.Hub]); </script>
Note that if you use this code, you must be very careful not to wrap LaTeX in Markdown blocks in HTML elements, to avoid an infinite loop.
UPDATE: Since the MathJax CDN is disconnected (and so that LaTeX in Markdown blocks fixes the problem that I hinted at above), the current code I'm using is:
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script> <script> document.addEventListener("DOMNodeInserted", function(event){ var element=event.target; if (element.tagName.toLowerCase()!= 'script') { MathJax.Hub.Queue(["Typeset",MathJax.Hub,element.parent]); } }); MathJax.Hub.Queue(["Typeset",MathJax.Hub]); </script>
source share