经过研究,我发现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} ”。“ 就变成: 阅读有关使用高级格式的更多信息。

其他回答

另一种解决方法是使用jupyter笔记本,并在单元格中使用markdown模式来渲染方程。

基本的东西似乎很完美,比如居中方程

\begin{equation}
...
\end{equation}

或者内联方程

$ \sum_{\forall i}{x_i^{2}} $

虽然,我真正想要的一个函数在github中根本没有呈现是\mbox{},这是一个遗憾。但是,总的来说,这是在github上渲染方程的最成功的方式。

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

自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} ”。“ 就变成: 阅读有关使用高级格式的更多信息。

Markdown支持内联HTML。内联HTML可以用于快速和简单的内联方程,也可以使用外部工具进行更复杂的渲染。

快速简单的内联

对于快速和简单的内联项目,使用HTML &实体代码。将这种思想与markdown中的下标文本结合起来的一个例子是:hθ(x) = θo x + θ1x,其代码如下。

    h<sub>&theta;</sub>(x) = &theta;<sub>o</sub> x + &theta;<sub>1</sub>x

常见数学符号的HTML &实体代码可以在这里找到。这里是希腊字母的密码。一个广泛的列表html实体代码到Unicode字符可以在这里找到。

虽然这种方法有局限性,但它实际上适用于所有的降价,并且不需要任何外部库。

使用LaTeX和Codecogs进行复杂的可伸缩内联渲染

如果你的需求更大,可以使用像CodeCogs这样的外部LaTeX渲染器。用CodeCogs编辑器创建一个方程。选择svg来呈现,选择HTML来嵌入代码。Svg在调整大小时呈现良好。当您查看源代码时,HTML使LaTeX易于阅读。从页面底部复制嵌入代码,并将其粘贴到您的标记中。

<img src="https://latex.codecogs.com/svg.latex?\Large&space;x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}" title="\Large x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}" />

用markdown表示

![\Large x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}](https://latex.codecogs.com/svg.latex?\Large&space;x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}) 

它结合了这个和这个答案。

对我来说,GitHub只支持使用上面的原始html语法来编写可读的LaTeX。如果上面的不工作,你的另一个选择是选择URL编码呈现,并使用该输出手动创建一个链接,如:

![\Large x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}](https://latex.codecogs.com/svg.latex?x%3D%5Cfrac%7B-b%5Cpm%5Csqrt%7Bb%5E2-4ac%7D%7D%7B2a%7D)

这手动将LaTex合并到alt图像文本中,并使用一个编码的URL在GitHub上渲染。

多行显示

如果你需要多行渲染,看看这个答案。

如果只是想自己在浏览器中展示数学,你可以尝试Chrome扩展GitHub和MathJax。这很方便。