我想使用Mathjax使用python代码?我试过下面的代码,但它不是渲染python,而是渲染数学方程式。
您可以在jsbin中进行测试。
相同的代码如下所示:
<!DOCTYPE html>
<html>
<head>
<title>MathJax TeX Test Page</title>
<!-- <script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script> -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {extensions:["mhchem.js"]},
jax: ["input/TeX", "output/HTML-CSS"],
tex2jax: {
inlineMath: [["$","$"],["\\(","\\)"]]
},
"HTML-CSS": { preferredFont: "TeX", availableFonts: ["STIX","TeX"] },
processEscapes: true
});
</script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
</head>
<body>
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}.$$
<pre>
~~
import numpy as np
a = np.zeros((1, 2))
~~
</pre>
</body>
</html>
答案 0 :(得分:0)
您可以使用Google Code Prettify渲染Python代码并使用Mathjax渲染数学方程式。
<!DOCTYPE html>
<html>
<head>
<title>MathJax TeX Test Page</title>
<!--Google Code Prettify script tag-->
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
<!-- <script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script> -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {extensions:["mhchem.js"]},
jax: ["input/TeX", "output/HTML-CSS"],
tex2jax: {
inlineMath: [["$","$"],["\\(","\\)"]]
},
"HTML-CSS": { preferredFont: "TeX", availableFonts: ["STIX","TeX"] },
processEscapes: true
});
</script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
</head>
<body>
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}.$$
<!--Google Code Prettify usage-->
<pre class="prettyprint">
~~
import numpy as np
a = np.zeros((1, 2))
~~
</pre>
</body>
</html>