Mathjax首次渲染时在div中显示奇怪的公式 [英] Mathjax displays weird formula in div first time it renders

查看:373
本文介绍了Mathjax首次渲染时在div中显示奇怪的公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Mathjax在div中渲染分数.第一次渲染时,显示 div中的一个公式(Latex),然后将其更改为我想要的分数形式.仅在第一次渲染分数时才会发生这种情况.我试图在页面首次加载时运行Mathjax Typeset,但是它 没有帮助.有什么办法可以抑制这种情况?

I am using Mathjax to render fractions in a div. The first time it renders, it displays a formula (Latex) in the div briefly, which then changes to the fraction that I want the way I want to see it. This happens only the first time a fraction is rendered. I have tried running Mathjax Typeset when the page first loads, but it has not helped. Is there any way to suppress this?

推荐答案

正如Peter在上面的评论中提到的,MathJax只能在页面加载后才能运行,并且必须在加载页面时才能运行配置文件您选择的.这意味着未处理的页面将对读者可见,直到MathJax文件被加载并运行为止.因此,您所看到的是正常的.它仅在第一次发生的原因是,当您重新加载页面时,MathJax文件已经在浏览器缓存中,因此不需要再次通过网络进行检索,MathJax可以更快地处理页面(尽管原始的LaTeX代码可能仍会短暂可见).

As Peter mentioned in his comment above, MathJax cannot run until after the page is loaded, and when it does it must load the files that it needs for the configuration that you have selected. That means the unprocessed page will be visible to the reader until the MathJax files are loaded and it runs. So what you are seeing is normal. The reason that it only happens the first time is that when you reload the page, the MathJax files are already in the browser cache, so don't need to be retrieved over the network again, and MathJax can process the page faster (though the original LaTeX code may still be visible briefly).

这是MathJax运行的固有方式,没有简单的方法可以阻止它.正如Peter所建议的那样,可以使用CSS隐藏页面直到MathJax完成处理之后,但这仅对没有太多数学运算的页面有用(否则该页面将长时间显示为空白).请参见这些示例,尤其是一种在display:none上.另请参见此示例,以了解如何隐藏页,直到数学加载完毕.您将需要查看源代码以了解其工作原理.

This is inherent in the way that MathJax operates, and there is no easy way to prevent it. As Peter suggests, it is possible to use CSS to hide the page until after MathJax has completed its processing, but that is only useful for pages without very much math on them (otherwise the page will appear blank for a long time). See these examples, especially the one on display:none for one approach. See also this example for how to hide the page until the math is loaded. You will need to view the source code to see how it works.

还可以将LaTeX放入MathJax内部使用的<script>标记中,以将数学存储在页面中(请参见

It is also possible to put your LaTeX into the <script> tags that MathJax uses internally to store the math in the page (see the documentation for details), so that they won't be visible in the page initially, but you may still see the page without the math when it first loads, and then the typeset math will appear after MathJax runs.

都不是理想的解决方案.

Neither is an ideal solution.

这篇关于Mathjax首次渲染时在div中显示奇怪的公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆