【问题标题】:Trouble rendering MathJax equations wrapped in span tags无法渲染包含在 span 标签中的 MathJax 方程
【发布时间】:2021-08-01 07:05:14
【问题描述】:

我正在尝试使用 Django 以及 CKEditor 在我的模板中呈现数学方程式。当我在检查元素中渲染我的数学方程式时,它看起来像这样:

<p><span class="mathjax-latex">\(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\)</span></p></p>

但是,即使启用了 MathJax 脚本,当我查看公式时,它也不会呈现。这是模板中的 MathJax 脚本:

    <script type="text/x-mathjax-config">
MathJax.Hub.Config({
    showProcessingMessages: false, //Close js loading process information
    messageStyle: "none", //Do not display information
    extensions: ["tex2jax.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {
        inlineMath:  [ ["$", "$"] ], //In-line formula selection$
        displayMath: [ ["$$","$$"] ], //The formula selection in the paragraph$$
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre','code','a'], //Avoid certain tags
        ignoreClass:"comment-content", //Avoid tags containing the Class
        processClass: "mathjax-latex",
    },
    "HTML-CSS": {
        availableFonts: ["STIX","TeX"], //Optional font
        showMathMenu: false //Close the right-click menu display
    }
});
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
</script>
<script src="https://cdn.bootcss.com/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

我需要做什么来渲染带有span标签的数学方程?

【问题讨论】:

    标签: django latex ckeditor mathjax


    【解决方案1】:

    Latex 有两种数学模式,内联模式和显示模式。第一个用于分隔应该显示“它在哪里”(例如在句子中间)的数学,而后者用于分隔应该以更独立和“花哨”的方式显示的数学(在它的自己的段落并居中)。

    在您提供的输入配置中,您告诉 MathJax 使用 $ 来分隔内联数学,并使用 $$ 来分隔显示数学。

        inlineMath:  [ ["$", "$"] ], //In-line formula selection$
        displayMath: [ ["$$","$$"] ], //The formula selection in the paragraph$$
    

    这些分隔符是非常常用的,虽然不是默认值。事实上,\(\) 是内联数学的默认值,您也可以在示例中使用。

    因为您已经告诉 MathJax 使用 $ 作为分隔符,所以它不会将您提供的数学识别为需要处理的东西,因此它会跳过它并且数学保持未排版。切换到使用您提供的分隔符$,它将起作用。

    这是一个只有此更改的工作沙盒:https://codesandbox.io/s/mathjax-jw4py

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-22
      • 2019-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-07
      • 2021-12-18
      • 1970-01-01
      相关资源
      最近更新 更多