【问题标题】:Inserting Mathematical equation into HTML [closed]将数学方程插入 HTML [关闭]
【发布时间】:2015-12-31 05:02:04
【问题描述】:

我正在通过 AJAX 变量检索以纯 Tex 格式存储在数据库中的数学方程。但是方程没有出现。请帮忙。

【问题讨论】:

  • 查看tex.stackexchange.com/a/23807 以获取相关资源
  • 你不能只是把 TeX 的东西扔进 HTML 文档,然后期望它正确呈现。有关将其转换为合适格式的详细信息,请参阅 joe_young 评论中的链接。
  • 立即查看我的答案@/fairy @JohnHascall

标签: javascript ajax latex tex mathematical-expressions


【解决方案1】:

看看MathJax,这个工作的JSFiddle:https://jsfiddle.net/joe_young/w01r2dku/

您需要包含 MathJax.js,您可以从此处的 CDN 获取该文件:https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full

<!-- Link to MathJax script from CDN -->
    <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full"></script>

<!-- Configuration script -->
    <script type="text/x-mathjax-config">
        //Note the above <script> attribute type="text/x-mathjax-config" 
            MathJax.Hub.Config({
                tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}
            });
    </script>

<!-- And your markup -->
    <p>
        When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are
        $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
    </p>

【讨论】:

  • 未来注意事项:cdn.mathjax.org 即将结束生命周期,请查看 mathjax.org/cdn-shutting-down 以了解迁移提示。