Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

126
Visualizações
inserting mathjax equation into innerHTML from javascript

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

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

JavaScript Compiler unescapes backslash escaping

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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda