
//Header
// When the user scrolls the page, execute myFunction
window.onscroll = function() {myFunction()};
// Get the header
var header = document.getElementById("stickheader");
// Get the offset position of the navbar
//var sticky = window.innerHeight / 20;
var sticky = header.offsetTop;
// Add the sticky class to the header when you reach its scroll position. Remove "sticky" when you leave the scroll position
function myFunction() {
  if (window.pageYOffset > sticky) {
    header.classList.add("sticky");
  } else {
    header.classList.remove("sticky");
  }
} 
function updateMath() {
    var input = document.getElementById('math-input').value;
    var latex = input
        .replace(/\(([^()]+)\)/g, '($1)')
        .replace(/\*/g, '\\cdot ')
        .replace(/([^<]+)\^(\([^<]+\)|[^\s<]+)/g, '$1^{$2}')
        .replace(/sqrt\(([^)]+)\)/g, '\\sqrt{$1}')
        .replace(/(\d+)\s*\^\s*(\d+)/g, "{$1}^{$2}")
        .replace(/(\d+)\s*\*\s*(\d+)/g, '$1 \\cdot $2')
        .replace(/(\d+)\s*\/\s*(\d+)/g, '\\frac{$1}{$2}')
        .replace(/(\d+)\s*\+\s*(\d+)/g, '$1 + $2')
        .replace(/(\d+)\s*-\s*(\d+)/g, '$1 - $2')
        .replace(/<p>(.*?)<\/p>/g, "\\paragraph{} $1")    // Paragraphs
        .replace(/<br\s*\/?>/g, "\\newline ")            // Line breaks
        .replace(/<u>(.*?)<\/u>/g, "\\underline{$1}")  // Underline text
        .replace(/<hr\s*\/?>/g, "\\rule{\\linewidth}{0.5mm}");
    var output = document.getElementById('math-output');
        output.innerText = `\\(${latex}\\)`; // Set the text inside math-output to the LaTeX
        MathJax.typesetPromise([output]); // Tell MathJax to update the rendering
}


