1. 程式人生 > 其它 >利用MathJax渲染Latex公式

利用MathJax渲染Latex公式

技術標籤:latexmathml

<!DOCTYPE html>
  <html >
  <head>
 <script type="text/x-mathjax-config">
        MathJax.Hub.Config({"HTML-CSS": { preferredFont: "TeX", availableFonts: ["STIX","TeX"], linebreaks: { automatic:true }, EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50) },
          tex2jax: { inlineMath: [ ["$", "$"], ["\\\\(","\\\\)"] ], displayMath: [ ["$$","$$"], ["\\[", "\\]"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno" },
          TeX: {
            extensions: ["begingroup.js"],
            noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } },
            Macros: { href: "{}" }
          },
          messageStyle: "none",
          styles: { ".MathJax_Display, .MathJax_Preview, .MathJax_Preview > *": { "background": "inherit" } },
          SEEditor: "mathjaxEditing"
      });
      </script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_HTML-full"></script>
  </head>
  <body >
       <span> $\frac{xe^{2x}}{(2x+1)^2}$</span> 
  </body>
  </html>

只要使用以上script設定和對mathjax.js的引用,就能對 以上span標籤中latex公式的渲染。渲染效果如下:

具體對應配置的作用請自行百度