{% if site.enable_math and page.pseudocode %}
  <!-- MathJax -->
  <script type="text/javascript">
    window.MathJax = {
      tex: {
        inlineMath: [
          ['$', '$'],
          ['\\(', '\\)'],
        ],
        displayMath: [
          ['$$', '$$'],
          ['\\[', '\\]'],
        ],
        processEscapes: true,
        processEnvironments: true,
      },
    };
  </script>
  <script
    type="text/javascript"
    id="MathJax-script"
    src="{{ site.third_party_libraries.mathjax.url.js }}"
  ></script>
  <script
    type="text/javascript"
    src="{{ site.third_party_libraries.pseudocode.url.js }}"
  ></script>
  <script>
    document.onreadystatechange = () => {
      if (document.readyState === 'complete') {
        document.querySelectorAll('pre>code.language-pseudocode').forEach((elem) => {
          const texData = elem.textContent;
          const parent = elem.parentElement.parentElement;
          /* create pseudocode node */
          let pseudoCodeElement = document.createElement('pre');
          pseudoCodeElement.classList.add('pseudocode');
          const text = document.createTextNode(texData);
          pseudoCodeElement.appendChild(text);
          /* add pseudocode node and remove the original code block */
          parent.appendChild(pseudoCodeElement);
          parent.removeChild(elem.parentElement);
          /* embed the visualization in the container */
          pseudocode.renderElement(pseudoCodeElement);
        });
      }
    };
  </script>
{% endif %}
