有没有办法在README中渲染LaTex ?md在GitHub存储库?我在谷歌上搜索了堆栈溢出,但没有一个相关的答案似乎可行。


当前回答

编写内联表达式:

这句话使用$分隔符来显示数学内联: $ \√6 {3 x - 1} + (1 + x) ^ 2美元

将表达式写成块:

柯西-施瓦茨不等式 $ $ \离开(\ sum_ {k = 1} ^ n a_k b_k \右)^ 2左(\ \ leq \ sum_ {k = 1} ^ n a_k ^ 2 \右)\左(\sum {k=1}^n b_k^2 \右)$$

来源:https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/writing-mathematical-expressions

其他回答

如果你对https://www.codecogs.com/latex/eqneditor.php有问题,我发现https://alexanderrodin.com/github-latex-markdown/对我有用。它生成您需要的Markdown代码,因此您只需将其剪切并粘贴到README中。md文档。

编写内联表达式:

这句话使用$分隔符来显示数学内联: $ \√6 {3 x - 1} + (1 + x) ^ 2美元

将表达式写成块:

柯西-施瓦茨不等式 $ $ \离开(\ sum_ {k = 1} ^ n a_k b_k \右)^ 2左(\ \ leq \ sum_ {k = 1} ^ n a_k ^ 2 \右)\左(\sum {k=1}^n b_k^2 \右)$$

来源:https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/writing-mathematical-expressions

自述文件2Tex

我一直在写一个脚本,它可以自动地把LaTeX排版很好地转换成github风格的markdown: https://github.com/leegao/readme2tex

在Github上渲染LaTeX有一些挑战。首先,github风格的markdown去掉了大多数标签和属性。这意味着没有基于Javascript的库(如Mathjax),也没有任何CSS样式。

自然的解决方案似乎是嵌入预编译方程的图像。但是,您很快就会意识到,LaTeX不仅仅是将美元符号的封闭公式转换为图像。

简单地嵌入来自在线编译器的图像会给文档带来这种不自然的外观。事实上,我认为它在日常的x^2数学俚语中比跳跃更有可读性

我相信确保你的文档以自然和可读的方式排版是很重要的。这就是为什么我写了一个脚本,除了将公式编译成图像外,还确保生成的图像正确地拟合并与其余文本对齐。

例如,下面是一个.md文件的摘录,涉及正则表达式的一些枚举属性,使用readme2tex:

正如您所期望的,顶部的方程集是通过启动相应的align*环境来指定的

**Theorem**: The translation $[\![e]\!]$ given by
\begin{align*}
...
\end{align*}
...

注意,当内联方程($…$)与文本一起运行时,显示方程(那些由\begin{ENV}分隔的方程…\end{ENV}或$$…$$)居中。这使得那些已经习惯使用LaTeX的人可以很容易地保持工作效率。

如果这听起来有帮助,一定要去看看。https://github.com/leegao/readme2tex

我测试了其他人提出的一些解决方案,我想推荐TeXify在agurodriguez的评论中创建和提出,并由Tom Hale进一步描述-我想发展他的答案,并给出一些理由,为什么这是一个非常好的解决方案:

TeXify is wrapper of Readme2Tex (mention in Lee answer). To use Readme2Tex you must install a lot of software in your local machine (python, latex, ...) - but TeXify is github plugin so you don't need to install anything in your local machine - you only need to online installation that plugin in you github account by pressing one button and choose repositories for which TeXify will have read/write access to parse your tex formulas and generate pictures. When in your repository you create or update *.tex.md file, the TeXify will detect changes and generate *.md file where latex formulas will be exchanged by its pictures saved in tex directory in your repo. So if you create README.tex.md file then TeXify will generate README.md with pictures instead tex formulas. So parsing tex formulas and generate documentation is done automagically on each commit&push :) Because all your formulas are changed into pictures in tex directory and README.md file use links to that pictures, you can even uninstall TeXify and all your old documentation will still works :). The tex directory and *.tex.md files will stay on repository so you have access to your original latex formulas and pictures (you can also safely store in tex directory your other documentation pictures "made by hand" - TeXify will not touch them). You can use equations latex syntax directly in README.tex.md file (without loosing .md markdown syntax) which is very handy. Julii in his answer proposed to use special links (with formulas) to external service e.g . http://latex.codecogs.com/gif.latex?s%3D%5Ctext%20%7B%20sensor%20reading%20%7D which is good however has some drawbacks: the formulas in links are not easy (handy) to read and update, and if there will be some problem with that third-party service your old documentation will stop work... In TeXify your old documentation will works always even if you uninstall that plugin (because all your pictures generated from latex formulas are stay in repo in tex directory). The Yuchao Jiang in his answer, proposed to use Jupyter Notebook which is also nice however have som drawbacks: you cannot use formulas directly in README.md file, you need to make link there to other file *.ipynb in your repo which contains latex (MathJax) formulas. The file *.ipynb format is JSON which is not handy to maintain (e.g. Gist don't show detailed error with line number in *.ipynb file when you forgot to put comma in proper place...).

这里是我的一些回购的链接,我使用TeXify的文档是从README.tex.md文件生成的。

更新

今天2020.12.13我意识到TeXify插件停止工作-即使重新安装后:(

我将带有方程式的存储库上传到Gitlab,因为它在.md文件中原生支持LaTeX:

```math
SE = \frac{\sigma}{\sqrt{n}}
```

内联latex的语法是$ ' \sqrt{2} ' $。

Gitlab使用JavaScript在浏览器中呈现方程,而不是显示图像,这提高了方程的质量。

更多信息请点击这里。

希望Github将来也能实现这个功能。