经过研究,我发现mathjax可以做到这一点。但是当我在我的markdown文件中写一些例子时,它并没有显示正确的方程:

我在markdown文件的头部添加了这个:

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=default"></script>

然后输入mathjax语句:

\(E=mc^2\),$$x_{1,2} = \frac{-b \pm \sqrt{b^2-4ac}}{2b}.$$

但是github没有显示任何数学符号!请帮帮我,谢谢! 告诉我如何显示数学符号在github markdown页面。


当前回答

自2022年5月起正式支持:

Render mathematical expressions in Markdown You can now use LaTeX style syntax to render math expressions within Markdown inline (using $ delimiters) or in blocks (using $$ delimiters). Writing expressions as blocks To add math as a multiline block displayed separately from surrounding text, start a new line and delimit the expression with two dollar symbols $$. **The Cauchy-Schwarz Inequality** $$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$ Writing inline expressions To include a math expression inline with your text, delimit the expression with a dollar symbol $. This sentence uses `$` delimiters to show math inline: $\sqrt{3x-1}+(1+x)^2$ GitHub's math rendering capability uses MathJax; an open source, JavaScript-based display engine. MathJax supports a wide range of LaTeX macros and a number of useful accessibility extensions. For more information, see the MathJax documentation and the MathJax Accessibility Extensions documentation. Some users have previously used a workaround to generate images of mathematical expressions through API requests. Images generated this way will remain viewable, but this technique will no longer work. Going forward, expressions should be written directly in Markdown using LaTeX syntax as described above. For more information about authoring content with advanced formatting, see Working with advanced formatting in the GitHub documentation.


这仍然是测试版,并受到批评。 参见“GitHub上的数学:好,坏和丑”,来自Nico Schlömer。 语法介绍:

竞争Markdown和数学渲染器 难以解释的数学问题


正如brc-dd在评论中指出的:

2022年6月:

用于数学表达式的隔离块语法 除了已经支持的分隔符之外,用户现在还可以使用“math fenced”代码块语法来描述数学表达式。 如果使用此方法,则不需要两个美元符号$$分隔符。 这里有一些数学!** ' '的数学 \ sqrt {3} ”。“ 就变成: 阅读有关使用高级格式的更多信息。

其他回答

Mathcha是一个复杂的数学编辑器,但它可以用于呈现单个方程并将其保存为纯html,然后可以将其作为内联html添加到文档中,也可以保存为SVG并作为图像插入。https://www.mathcha.io/

我在标记文件的头部使用了以下内容

<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js? 
config=TeX-MML-AM_CHTML"
</script>

然后输入以下mathjax语句 $$x_{1,2} = \frac{-b \pm \sqrt{b^2-4ac}}{2b}.$$ 这对我很有效

自2022年5月起正式支持:

Render mathematical expressions in Markdown You can now use LaTeX style syntax to render math expressions within Markdown inline (using $ delimiters) or in blocks (using $$ delimiters). Writing expressions as blocks To add math as a multiline block displayed separately from surrounding text, start a new line and delimit the expression with two dollar symbols $$. **The Cauchy-Schwarz Inequality** $$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$ Writing inline expressions To include a math expression inline with your text, delimit the expression with a dollar symbol $. This sentence uses `$` delimiters to show math inline: $\sqrt{3x-1}+(1+x)^2$ GitHub's math rendering capability uses MathJax; an open source, JavaScript-based display engine. MathJax supports a wide range of LaTeX macros and a number of useful accessibility extensions. For more information, see the MathJax documentation and the MathJax Accessibility Extensions documentation. Some users have previously used a workaround to generate images of mathematical expressions through API requests. Images generated this way will remain viewable, but this technique will no longer work. Going forward, expressions should be written directly in Markdown using LaTeX syntax as described above. For more information about authoring content with advanced formatting, see Working with advanced formatting in the GitHub documentation.


这仍然是测试版,并受到批评。 参见“GitHub上的数学:好,坏和丑”,来自Nico Schlömer。 语法介绍:

竞争Markdown和数学渲染器 难以解释的数学问题


正如brc-dd在评论中指出的:

2022年6月:

用于数学表达式的隔离块语法 除了已经支持的分隔符之外,用户现在还可以使用“math fenced”代码块语法来描述数学表达式。 如果使用此方法,则不需要两个美元符号$$分隔符。 这里有一些数学!** ' '的数学 \ sqrt {3} ”。“ 就变成: 阅读有关使用高级格式的更多信息。

有一个很好的解决方案,你的问题-使用TeXify github插件(提到了汤姆黑尔的答案-但我开发了他的答案在下面给出的链接)-关于这个github插件的更多细节,并解释为什么这是一个很好的方法,你可以在答案中找到。

另一种可能是依赖GitHub自己的笔记本渲染器。这甚至可以在SO中工作。

要呈现x_{1,2} = \frac{-b \pm \sqrt{b^2-4ac}}{2b},请使用以下HTML img标记:

<img src="https://render.githubusercontent.com/render/math?math=x_{1,2} = \frac{-b \pm \sqrt{b^2-4ac}}{2b}">

现场演示:

这种方法的伟大之处在于,你可以直接在Markdown中编辑你的公式,预览版也会相应更新。 您可以通过编辑这个答案来尝试一下。(如果你的编辑不能给答案加分,那就扔掉吧;))

来源:https://gist.github.com/a-rodin/fef3f543412d6e1ec5b6cf55bf197d7b