Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

273
Vistas
Mathjax won't load formula when loading from a different file

I am trying to make a website where pressing a button loads a formula written in latex in a different html file in my current html file. But when i do this i only get the latex code and not the formula. I have tried to use MathJax.typeset() but it does not work. Sometimes it works for a split second when i am constantly pressing the button, but turns back to latex right after. This is the main file called index.html. I have used jquery to load the file just because it is easier.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
    <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <title>index</title>
</head>
    <body>
        <button onclick="loadHTML('test1.html')">Press for formula</button>
        <div id="content" class="content">Formulas coming here</div>
    </body>
</html>
<script>
    function loadHTML(filename){
        let file = `formulas/${filename}`
        $("#content").load(file);
        MathJax.typeset();
    };
</script>

and the test1.html file including the formula (inside a folder i have called "formula")

$$a = {b \over c}$$
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The jQuery load() function is asynchronous, so even though it completes and goes on to the next line in your code, that doesn't mean the file has actually been loaded, so you are calling MathJax.typeset() before the new content is in the page. You can pass a callback function to load() that is called when the page has been updated. Use that to call MathJax.typeset():

    function loadHTML(filename){
        let file = `formulas/${filename}`
        $("#content").load(file, function () {
            MathJax.typeset();
        });
    };
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda