有没有办法在README中渲染LaTex ?md在GitHub存储库?我在谷歌上搜索了堆栈溢出,但没有一个相关的答案似乎可行。
当前回答
编辑:正如锗指出的那样,它对README不起作用。Md但其他git页面,虽然没有解释可用。 我的快速解决方案是这样的
步骤1。将latex添加到.md文件中
$$x=\sqrt{2}$$
注意:数学公式必须在$$…$$或\\(…\ \)。
步骤2。将以下代码添加到scripts.html或主题文件中(将此代码附加在末尾)
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
完成了!。通过加载页面查看你的等式。
其他回答
编写内联表达式:
这句话使用$分隔符来显示数学内联: $ \√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文档。
你也可以使用这个在线编辑器:https://www.codecogs.com/latex/eqneditor.php,它可以动态生成SVG文件。你可以像这样在你的文档中添加一个链接: ,结果是: .
你可以获得持续集成服务(例如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上的这篇文章。
我测试了其他人提出的一些解决方案,我想推荐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插件停止工作-即使重新安装后:(
推荐文章
- GitHub上的分叉和克隆有什么区别?
- 在LaTeX中突出显示源代码
- 如何将现有的解决方案从Visual Studio 2013添加到GitHub
- 是否可以在GitHub上搜索特定的文件名?
- 如何将LaTeX与Markdown混合?
- GitHub -未能连接到GitHub 443 windows/连接到GitHub失败-无错误
- 我怎么能让詹金斯CI与Git触发器推到主人?
- 在LaTeX中出现“Missing $ inserted”错误
- 如何从拉请求中删除提交
- 如何用分发文件发布npm包?
- 如何同步项目到GitHub与Android工作室?
- 跟踪在GitHub上创建的一个新的远程分支
- 如何将一个特定的提交从一个分支合并到Git中的另一个分支?
- 从pull请求中删除一个修改过的文件
- 下载GitHub项目的最快方式