Skip to content

Hiding content until typesetting is complete

pkra edited this page Apr 6, 2013 · 4 revisions

From https://groups.google.com/d/msg/mathjax-users/nI1eIEjk-ak/oVyy1nwtboYJ

The issue I face now is that on first load you can actually see it flash the orignal text before the ajax callback executes and MathJax renders the content. Is there a typical approach whereby only the rendered content actually displays? Or is this an expected result of doing this in an ajax call?

It is not unusual for the original text to be visible before MathJax processes it. If MathJax needs to load any components (like its output jax the first time it is used), that is done asynchronously, so the page will be displayed in the meantime until the component is loaded.

You could set the div's visibility:hidden property before loading its contents, and then after it is loaded, typeset the math setting visibility to "" afterward. You would need to use the MathJax.Hub.Queue to synchronize that. E.g.

    $("#DivID").css("visibility","hidden");

    $("#DivID").load('@Url.Action("ActionResultMethod", "ControllerName",{controller parameters})', function () {
      MathJax.Hub.Queue(
        ["Typeset",MathJax.Hub,"DivID"],
        function () {
          $("#DivID").css("visibility",""); // may have to be "visible" rather than ""
        }
      );
    });

might work. I don't use jQuery myself, so don't know if this is correct or not.

Clone this wiki locally