除非重新加载页面,否则 Mathjax 不会呈现方程式
Mathjax not rendering equation unless page reloaded
我通过 CDN 在我的 rails 项目中使用 mathjax,因为在我的应用程序中托管它时出现问题。
我将 mathjax 与以下内容一起使用
<script type="text/javascript" src="http://www.hostmath.com/Math/MathJax.js?config=OK"></script>
有一个 div 元素根据用户在页面上单击的按钮呈现部分内容。部分 "Other" 有其他内容,部分 "Math" 有数学方程式。有对应分音的按钮。
用户第一次单击 "Math" 数学部分中的所有方程式都会正确呈现。如果用户单击 "Other" 然后再次单击 "Math",则数学方程式不会正确呈现。仅显示原始数学语法。
我读到这可能是因为 MathJax 仅在页面加载时排版,但我不明白为什么当呈现的部分发生变化时格式会发生变化。
所以我添加了以下我在网上找到的内容来测试它是否能解决我的问题:
<script type="text/javascript">
MathJax.Hub.Queue(
["resetEquationNumbers",MathJax.InputJax.TeX],
["Typeset",MathJax.Hub]
);
</script>
现在一切如我所愿。用户可以按任何顺序单击 "Math" 或 "Other" 部分的按钮,而无需重新加载页面,并且方程式会正确呈现。
问题是我有一个js错误:
Uncaught ReferenceError: MathJax is not defined
当通过 CDN 而不是我的本地服务器引用 MathJax 时,如何使用上述代码 (MathJax.Hub.Queue...)?我也不明白为什么添加上面的代码可以解决 "MathJax" 未定义时的问题。
根据我在 docs 中阅读的内容,我想我需要配置一个本地配置文件来解决这个问题,但我不理解它们。有人可以帮忙吗?
这是数学方程的部分
<div class="custom-in-page-pages-view">
<div class="text-center">
<h1>Part 1</h1>
<h4>General 3d Motion Equation</h4><br><br>
</div>
<math>
<mrow>
<mtext selected="true">r</mtext>
<mo>=</mo>
<mtext>r</mtext>
<mtext mathvariant="italic">(t)</mtext>
<mo>=</mo>
<mtext mathvariant="italic">r</mtext>
<msub>
<mtext>ê</mtext>
<mtext mathvariant="italic">r</mtext>
</msub>
</mrow>
</math>
<br>
<br>
<math>
<mrow>
<mtext>v</mtext>
<mo>=</mo>
<mtext mathvariant="italic">v</mtext>
<msub>
<mtext>ê</mtext>
<mtext>r</mtext>
</msub>
<mo>+</mo>
<mtext mathvariant="italic">r</mtext>
<mfrac>
<mtext mathvariant="italic">dθ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
<msub>
<mtext>ê</mtext>
<mtext selected="true" mathvariant="italic">θ</mtext>
</msub>
<mo>+</mo>
<mtext mathvariant="italic">r</mtext>
<mfrac>
<mtext mathvariant="italic">dϕ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
<mtext mathvariant="normal">sin</mtext>
<mtext mathvariant="italic">θ</mtext>
<msub>
<mtext>ê</mtext>
<mtext mathvariant="italic">ϕ</mtext>
</msub>
</mrow>
</math>
<br>
<br>
<math>
<mrow>
<mtext selected="true">a</mtext>
<mo>=</mo>
<mfenced open="(" close=")">
<mrow>
<mtext mathvariant="italic">a</mtext>
<mo>-</mo>
<mtext mathvariant="italic">r</mtext>
<mo> </mo>
<msup>
<mfenced open="(" close=")">
<mfrac>
<mtext mathvariant="italic">dθ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
</mfenced>
<mn>2</mn>
</msup>
<mo>-</mo>
<mtext mathvariant="italic">r</mtext>
<mo> </mo>
<msup>
<mfenced open="(" close=")">
<mfrac>
<mtext mathvariant="italic">dϕ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
</mfenced>
<mn>2</mn>
</msup>
<mo> </mo>
<msup>
<mtext mathvariant="normal">sin</mtext>
<mn>2</mn>
</msup>
<mtext mathvariant="italic">θ</mtext>
</mrow>
</mfenced>
<mo> </mo>
<msub>
<mtext>ê</mtext>
<mtext>r</mtext>
</msub>
</mrow>
</math>
<br>
<br>
<math>
<mrow>
<mo>+</mo>
<mfenced open="(" close=")">
<mrow>
<mtext>r</mtext>
<mfrac>
<mrow>
<msup>
<mtext mathvariant="italic">d</mtext>
<mn>2</mn>
</msup>
<mtext mathvariant="italic">θ</mtext>
</mrow>
<mrow>
<mtext mathvariant="italic">d</mtext>
<msup>
<mtext mathvariant="italic">t</mtext>
<mn>2</mn>
</msup>
</mrow>
</mfrac>
<mo>+</mo>
<mtext mathvariant="italic">2v</mtext>
<mfrac>
<mtext mathvariant="italic">dθ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
<mo>-</mo>
<mtext mathvariant="italic">r</mtext>
<mo> </mo>
<msup>
<mfenced open="(" close=")">
<mfrac>
<mtext mathvariant="italic">dϕ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
</mfenced>
<mn>2</mn>
</msup>
<mo> </mo>
<mtext mathvariant="normal">sin</mtext>
<mtext mathvariant="italic">θ</mtext>
<mtext mathvariant="normal">cos</mtext>
<mtext mathvariant="italic">θ</mtext>
</mrow>
</mfenced>
<mo> </mo>
<msub>
<mtext>ê</mtext>
<mtext selected="true" mathvariant="italic">θ</mtext>
</msub>
</mrow>
</math>
<br>
<br>
<math>
<mrow>
<mo mathvariant="italic">+</mo>
<mfenced open="(" close=")">
<mrow>
<mtext mathvariant="italic">r</mtext>
<mfrac>
<mrow>
<msup>
<mtext mathvariant="italic">d</mtext>
<mn>2</mn>
</msup>
<mtext mathvariant="italic">ϕ</mtext>
</mrow>
<mrow>
<mtext mathvariant="italic">d</mtext>
<msup>
<mtext mathvariant="italic">t</mtext>
<mn>2</mn>
</msup>
</mrow>
</mfrac>
<mtext mathvariant="normal">sin</mtext>
<mtext mathvariant="italic">θ</mtext>
<mo>+</mo>
<mtext>2</mtext>
<mtext mathvariant="italic">v</mtext>
<mfrac>
<mtext mathvariant="italic">dϕ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
<mtext mathvariant="normal">sin</mtext>
<mtext mathvariant="italic">θ</mtext>
<mo>+</mo>
<mtext>2</mtext>
<mtext mathvariant="italic">r</mtext>
<mfrac>
<mtext mathvariant="italic">dθ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
<mfrac>
<mtext mathvariant="italic">dϕ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
<mtext mathvariant="normal">cos</mtext>
<mtext mathvariant="italic">θ</mtext>
</mrow>
</mfenced>
<mo> </mo>
<msub>
<mtext>ê</mtext>
<mtext selected="true" mathvariant="italic">ϕ</mtext>
</msub>
</mrow>
</math>
<br>
</div>
<script type="text/javascript"
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script type="text/javascript">
MathJax.Hub.Queue(
["resetEquationNumbers",MathJax.InputJax.TeX],
["Typeset",MathJax.Hub]
);
</script>
这是为了解决我在 Chrome 中测试时才看到的问题。在 Firefox 和 Safari 中查看代码时,我没有看到需要使用 MathJax.Hub.Queue... 的问题。
我通过有效的 mathjax 用户组得到了答案。这里是给大众的。
替换
<script type="text/javascript">
MathJax.Hub.Queue(
["resetEquationNumbers",MathJax.InputJax.TeX],
["Typeset",MathJax.Hub]
);
</script>
和
<script type="text/javascript">
if (window.MathJax) {
MathJax.Hub.Queue(
["resetEquationNumbers",MathJax.InputJax.TeX],
["Typeset",MathJax.Hub]
);
}
</script>
或者干脆
<script type="text/javascript">
if (window.MathJax) {
MathJax.Hub.Queue(
["Typeset",MathJax.Hub]
);
}
</script>
it is getting to the first bit before MathJax is loaded.
MathJax does load afterwards and renders your math OK (and doesn't
need the above), without further error.
I would suggest trying either:
(1) Removing the "resetEquationNumbers, Typeset" bit, since it's not
necessary and causing your error -Murray
和
the first time through (when MathJax hasn't been loaded), the
calls aren't made (and they aren't needed on the first pass, as Murray
points out), but the calls WILL be made on the second and subsequent
times you press the "Part 1" button, where they are needed. Note that
the resetEquationNumbers call is only needed if you are using
automatic equation numbers or use the \label macro. But it doesn't
hurt anything if you use it. -David
特别感谢 mathjax google 用户组的 Davide Cervone 和 Murray 帮助我解决了这个问题。
我通过 CDN 在我的 rails 项目中使用 mathjax,因为在我的应用程序中托管它时出现问题。
我将 mathjax 与以下内容一起使用
<script type="text/javascript" src="http://www.hostmath.com/Math/MathJax.js?config=OK"></script>
有一个 div 元素根据用户在页面上单击的按钮呈现部分内容。部分 "Other" 有其他内容,部分 "Math" 有数学方程式。有对应分音的按钮。
用户第一次单击 "Math" 数学部分中的所有方程式都会正确呈现。如果用户单击 "Other" 然后再次单击 "Math",则数学方程式不会正确呈现。仅显示原始数学语法。
我读到这可能是因为 MathJax 仅在页面加载时排版,但我不明白为什么当呈现的部分发生变化时格式会发生变化。
所以我添加了以下我在网上找到的内容来测试它是否能解决我的问题:
<script type="text/javascript">
MathJax.Hub.Queue(
["resetEquationNumbers",MathJax.InputJax.TeX],
["Typeset",MathJax.Hub]
);
</script>
现在一切如我所愿。用户可以按任何顺序单击 "Math" 或 "Other" 部分的按钮,而无需重新加载页面,并且方程式会正确呈现。
问题是我有一个js错误:
Uncaught ReferenceError: MathJax is not defined
当通过 CDN 而不是我的本地服务器引用 MathJax 时,如何使用上述代码 (MathJax.Hub.Queue...)?我也不明白为什么添加上面的代码可以解决 "MathJax" 未定义时的问题。
根据我在 docs 中阅读的内容,我想我需要配置一个本地配置文件来解决这个问题,但我不理解它们。有人可以帮忙吗?
这是数学方程的部分
<div class="custom-in-page-pages-view">
<div class="text-center">
<h1>Part 1</h1>
<h4>General 3d Motion Equation</h4><br><br>
</div>
<math>
<mrow>
<mtext selected="true">r</mtext>
<mo>=</mo>
<mtext>r</mtext>
<mtext mathvariant="italic">(t)</mtext>
<mo>=</mo>
<mtext mathvariant="italic">r</mtext>
<msub>
<mtext>ê</mtext>
<mtext mathvariant="italic">r</mtext>
</msub>
</mrow>
</math>
<br>
<br>
<math>
<mrow>
<mtext>v</mtext>
<mo>=</mo>
<mtext mathvariant="italic">v</mtext>
<msub>
<mtext>ê</mtext>
<mtext>r</mtext>
</msub>
<mo>+</mo>
<mtext mathvariant="italic">r</mtext>
<mfrac>
<mtext mathvariant="italic">dθ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
<msub>
<mtext>ê</mtext>
<mtext selected="true" mathvariant="italic">θ</mtext>
</msub>
<mo>+</mo>
<mtext mathvariant="italic">r</mtext>
<mfrac>
<mtext mathvariant="italic">dϕ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
<mtext mathvariant="normal">sin</mtext>
<mtext mathvariant="italic">θ</mtext>
<msub>
<mtext>ê</mtext>
<mtext mathvariant="italic">ϕ</mtext>
</msub>
</mrow>
</math>
<br>
<br>
<math>
<mrow>
<mtext selected="true">a</mtext>
<mo>=</mo>
<mfenced open="(" close=")">
<mrow>
<mtext mathvariant="italic">a</mtext>
<mo>-</mo>
<mtext mathvariant="italic">r</mtext>
<mo> </mo>
<msup>
<mfenced open="(" close=")">
<mfrac>
<mtext mathvariant="italic">dθ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
</mfenced>
<mn>2</mn>
</msup>
<mo>-</mo>
<mtext mathvariant="italic">r</mtext>
<mo> </mo>
<msup>
<mfenced open="(" close=")">
<mfrac>
<mtext mathvariant="italic">dϕ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
</mfenced>
<mn>2</mn>
</msup>
<mo> </mo>
<msup>
<mtext mathvariant="normal">sin</mtext>
<mn>2</mn>
</msup>
<mtext mathvariant="italic">θ</mtext>
</mrow>
</mfenced>
<mo> </mo>
<msub>
<mtext>ê</mtext>
<mtext>r</mtext>
</msub>
</mrow>
</math>
<br>
<br>
<math>
<mrow>
<mo>+</mo>
<mfenced open="(" close=")">
<mrow>
<mtext>r</mtext>
<mfrac>
<mrow>
<msup>
<mtext mathvariant="italic">d</mtext>
<mn>2</mn>
</msup>
<mtext mathvariant="italic">θ</mtext>
</mrow>
<mrow>
<mtext mathvariant="italic">d</mtext>
<msup>
<mtext mathvariant="italic">t</mtext>
<mn>2</mn>
</msup>
</mrow>
</mfrac>
<mo>+</mo>
<mtext mathvariant="italic">2v</mtext>
<mfrac>
<mtext mathvariant="italic">dθ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
<mo>-</mo>
<mtext mathvariant="italic">r</mtext>
<mo> </mo>
<msup>
<mfenced open="(" close=")">
<mfrac>
<mtext mathvariant="italic">dϕ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
</mfenced>
<mn>2</mn>
</msup>
<mo> </mo>
<mtext mathvariant="normal">sin</mtext>
<mtext mathvariant="italic">θ</mtext>
<mtext mathvariant="normal">cos</mtext>
<mtext mathvariant="italic">θ</mtext>
</mrow>
</mfenced>
<mo> </mo>
<msub>
<mtext>ê</mtext>
<mtext selected="true" mathvariant="italic">θ</mtext>
</msub>
</mrow>
</math>
<br>
<br>
<math>
<mrow>
<mo mathvariant="italic">+</mo>
<mfenced open="(" close=")">
<mrow>
<mtext mathvariant="italic">r</mtext>
<mfrac>
<mrow>
<msup>
<mtext mathvariant="italic">d</mtext>
<mn>2</mn>
</msup>
<mtext mathvariant="italic">ϕ</mtext>
</mrow>
<mrow>
<mtext mathvariant="italic">d</mtext>
<msup>
<mtext mathvariant="italic">t</mtext>
<mn>2</mn>
</msup>
</mrow>
</mfrac>
<mtext mathvariant="normal">sin</mtext>
<mtext mathvariant="italic">θ</mtext>
<mo>+</mo>
<mtext>2</mtext>
<mtext mathvariant="italic">v</mtext>
<mfrac>
<mtext mathvariant="italic">dϕ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
<mtext mathvariant="normal">sin</mtext>
<mtext mathvariant="italic">θ</mtext>
<mo>+</mo>
<mtext>2</mtext>
<mtext mathvariant="italic">r</mtext>
<mfrac>
<mtext mathvariant="italic">dθ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
<mfrac>
<mtext mathvariant="italic">dϕ</mtext>
<mtext mathvariant="italic">dt</mtext>
</mfrac>
<mtext mathvariant="normal">cos</mtext>
<mtext mathvariant="italic">θ</mtext>
</mrow>
</mfenced>
<mo> </mo>
<msub>
<mtext>ê</mtext>
<mtext selected="true" mathvariant="italic">ϕ</mtext>
</msub>
</mrow>
</math>
<br>
</div>
<script type="text/javascript"
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script type="text/javascript">
MathJax.Hub.Queue(
["resetEquationNumbers",MathJax.InputJax.TeX],
["Typeset",MathJax.Hub]
);
</script>
这是为了解决我在 Chrome 中测试时才看到的问题。在 Firefox 和 Safari 中查看代码时,我没有看到需要使用 MathJax.Hub.Queue... 的问题。
我通过有效的 mathjax 用户组得到了答案。这里是给大众的。
替换
<script type="text/javascript">
MathJax.Hub.Queue(
["resetEquationNumbers",MathJax.InputJax.TeX],
["Typeset",MathJax.Hub]
);
</script>
和
<script type="text/javascript">
if (window.MathJax) {
MathJax.Hub.Queue(
["resetEquationNumbers",MathJax.InputJax.TeX],
["Typeset",MathJax.Hub]
);
}
</script>
或者干脆
<script type="text/javascript">
if (window.MathJax) {
MathJax.Hub.Queue(
["Typeset",MathJax.Hub]
);
}
</script>
it is getting to the first bit before MathJax is loaded.
MathJax does load afterwards and renders your math OK (and doesn't need the above), without further error.
I would suggest trying either:
(1) Removing the "resetEquationNumbers, Typeset" bit, since it's not necessary and causing your error -Murray
和
the first time through (when MathJax hasn't been loaded), the calls aren't made (and they aren't needed on the first pass, as Murray points out), but the calls WILL be made on the second and subsequent times you press the "Part 1" button, where they are needed. Note that the resetEquationNumbers call is only needed if you are using automatic equation numbers or use the \label macro. But it doesn't hurt anything if you use it. -David
特别感谢 mathjax google 用户组的 Davide Cervone 和 Murray 帮助我解决了这个问题。