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


当前回答

我的诀窍是用木星笔记本。

GitHub内置了呈现.ipynb文件的支持。你可以编写内联的LaTeX代码并在笔记本中显示,GitHub会为你呈现它。

下面是一个示例笔记本文件:https://gist.github.com/cyhsutw/d5983d166fb70ff651f027b2aa56ee4e

其他回答

对于推送到GitHub的自动转换,看看TeXify应用程序:

GitHub应用程序,在你的推文件扩展名*.tex。md和渲染它的TeX表达式为SVG图像

它是如何工作的(从源存储库):

每当你按TeXify将运行并搜索*.tex。Md文件。对于其中的每一个,它将运行readme2tex,它将接受美元符号之间的LaTeX表达式,将其转换为普通的SVG图像,然后将输出保存到.md扩展文件中(这意味着将处理名为README.tex.md的文件,并将输出保存为README.md)。在此之后,将提交输出文件和新的SVG图像并将其推回您的repo。

对于简短的表达式和不那么花哨的数学,您可以使用内联HTML在codecogs上获得乳胶渲染的数学,然后嵌入生成的图像。这里有一个例子:

- <img src="https://latex.codecogs.com/gif.latex?O_t=\text { Onset event at time bin } t " /> 
- <img src="https://latex.codecogs.com/gif.latex?s=\text { sensor reading }  " /> 
- <img src="https://latex.codecogs.com/gif.latex?P(s | O_t )=\text { Probability of a sensor reading value when sleep onset is observed at a time bin } t " />

这会导致类似下一次的事情吗

更新:这是伟大的工作在eclipse,但不是在github不幸。唯一的解决办法是:

把你的乳胶方程,去http://www.codecogs.com/latex/eqneditor.php,在你的方程出现的区域的底部显示有一个小的下拉菜单,选择URL编码,然后粘贴在你的github markdown下一种方式:

![equation](http://latex.codecogs.com/gif.latex?O_t%3D%5Ctext%20%7B%20Onset%20event%20at%20time%20bin%20%7D%20t)
![equation](http://latex.codecogs.com/gif.latex?s%3D%5Ctext%20%7B%20sensor%20reading%20%7D) 
![equation](http://latex.codecogs.com/gif.latex?P%28s%20%7C%20O_t%20%29%3D%5Ctext%20%7B%20Probability%20of%20a%20sensor%20reading%20value%20when%20sleep%20onset%20is%20observed%20at%20a%20time%20bin%20%7D%20t)

您还可以看看我的工具latexMarkdown2Markdown,它可以将LaTeX转换为SVG并生成带有章节编号的内容表。

我测试了其他人提出的一些解决方案,我想推荐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插件停止工作-即使重新安装后:(

你可以获得持续集成服务(例如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上的这篇文章。