I need to put a MathJax equation into the innerHTML element.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tools for Operation Research</title>
<script type="text/javascript" src="D:/_Installers/MathJax-2.7.7/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
</head>
<body>
<section id="main_content">
Put text here:
</section>
<script>
document.getElementById("main_content").innerHTML = "The expresion is: <br> $$\displaystyle Q^*=\sqrt{\left( \frac{2DA}{h}\right)\left(\frac{1}{1-\frac{D}{\psi}}\right)\left(\frac{h+\pi}{\pi}\right)}$$";
</script>
</body>
The result is this:
$$displaystyle Q^*=sqrt{left( rac{2DA}{h} ight)left(rac{1}{1-rac{D}{psi}} ight)left(rac{h+pi}{pi} ight)}$$
not the equation. Shoulb be something like this: Correct equation
Because JavaScript uses backslash escaping, all the '\' characters before unrecognized letters in the equation are being removed by the JavaScript compiler, and '\r' is turned into an ASCII carriage return character which HTML then displays as whitespace.
The solution is to backslash escape the backslashes in the equation:
<script>
document.getElementById("main_content").innerHTML = "The expresion is: <br> $$\\displaystyle Q^*=\\sqrt{\\left( \\frac{2DA}{h}\\right)\\left(\\frac{1}{1-\\frac{D}{\\psi}}\\right)\\left(\frac{h+\pi}{\\pi}\\right)}$$";
</script>
Note I was able to verify the equation was displayed as symbols using a downloaded copy of MathJax from a CDN, but did not attempt a local installation.