将数学方程式插入HTML

时间:2015-12-30 20:37:32

标签: javascript ajax latex tex mathematical-expressions

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

1 个答案:

答案 0 :(得分: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>