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


当前回答

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

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

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

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

更多信息请点击这里。

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

其他回答

你可以获得持续集成服务(例如Travis CI)来呈现LaTeX并将结果提交到github。CI将在每次新提交后部署一个“云”worker。工作人员将您的文档编译为pdf,并使用ImageMagick将其转换为图像,或者使用PanDoc尝试LaTeX->HTML转换,其中成功与否可能取决于您的文档。Worker然后将图像或html提交到您的存储库,从那里可以在自述文件中显示。

示例TravisCi配置构建PDF,将其转换为PNG,并将其提交到您的repo的静态位置是粘贴下面。您需要添加一行来获取PDF,将PDF转换为图像

sudo: required
dist: trusty
os: linux
language: generic
services: docker
env:
  global:
  - GIT_NAME: Travis CI
  - GIT_EMAIL: builds@travis-ci.org
  - TRAVIS_REPO_SLUG: your-github-username/your-repo
  - GIT_BRANCH: master
# I recommend storing your GitHub Access token as a secret key in a Travis CI environment variable, for example $GH_TOKEN.
  - secure: ${GH_TOKEN}
script:
- wget https://raw.githubusercontent.com/blang/latex-docker/master/latexdockercmd.sh
- chmod +x latexdockercmd.sh
- "./latexdockercmd.sh latexmk -cd -f -interaction=batchmode -pdf yourdocument.tex -outdir=$TRAVIS_BUILD_DIR/"
- cd $TRAVIS_BUILD_DIR
- convert -density 300 -quality 90 yourdocument.pdf yourdocument.png
- git checkout --orphan $TRAVIS_BRANCH-pdf
- git rm -rf .
- git add -f yourdoc*.png
- git -c user.name='travis' -c user.email='travis' commit -m "updated PDF"
# note we are again using GitHub access key stored in the CI environment variable
- git push -q -f https://your-github-username:$GH_TOKEN@github.com/$TRAVIS_REPO_SLUG $TRAVIS_BRANCH-pdf
notifications:
  email: false

这个Travis Ci配置会启动一个Ubuntu worker,下载一个latex docker镜像,将文档编译为pdf,并将其提交到一个名为branchanme-pdf的分支。

要了解更多的例子,请参阅这个github回购及其附带的sx讨论,PanDoc示例, https://dfm.io/posts/travis-latex/,以及Medium上的这篇文章。

编写内联表达式:

这句话使用$分隔符来显示数学内联: $ \√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

你可以用markdown,例如:

![equ](https://latex.codecogs.com/gif.latex?log(y)=\beta_0&space;+&space;\beta_1&space;x&space;+&space;u)

代码可以在这里输入:https://www.codecogs.com/latex/eqneditor.php。

我一直在四处寻找,发现另一个问题中的这个答案最适合我。即使用githubcontent数学渲染器,例如显示:

使用这个链接 小心乳胶需要url编码,但其他工作对我来说很好。

你也可以使用这个在线编辑器:https://www.codecogs.com/latex/eqneditor.php,它可以动态生成SVG文件。你可以像这样在你的文档中添加一个链接: ![](https://latex.codecogs.com/svg.latex?y%3Dx%5E2),结果是: .