如何在github-pages中支持乳胶? [英] How to support latex in github-pages?

查看:88
本文介绍了如何在github-pages中支持乳胶?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jekyll撰写帖子并将其显示在github-pages中.我的源文件是用markdown写的.

如何将公式插入降价文件?

我不想将公式保存到图像中并将图像加载到markdown文件中.我实际上想直接在markdown文件中编写乳胶公式.

解决方案

由于有关此问题的在线资源已更改,因此此为有关通过GitHub Pages支持LateX的更新.

请注意,最接近Latex呈现而不导出为图像并在Jekyll网站上提供原生支持的方法是使用MathJax.

实际上建议使用MathJax ,在Jekyllrb文档中 数学支持,借助Kramdown,还可以将其从LaTeX转换为PNG,有关更多详细信息,请参见 MathURL 中编写方程式并将其嵌入.

您可以使用MathURL编写方程式,然后生成一个永久指向方程式的URL,并将其显示在<iframe>标记中.但是,如果MathURL脱机,这将停止工作.

选项2:实施 jsMath

jsMath将允许几乎类似LateX的语法,并且如果设置正确,它将在您的博客中得到支持,其中 MathJax也被mathematics.stackexchange.com使用!

  • 第1步:让您的网站在要显示数学的网站中加载脚本. (通常在标题中完成)

  • 可选:在_config.yml中检查您的降价解析器.在此示例中建议使用redcarpetkramdown.某些解析器(例如discount)会干扰语法,但是我在下面有一个解决方案.

  • 第2步:编写方程式.

Gaston Sanchez引用本教程:

MathJax的行为与LaTeX完全不同.默认情况下, tex2jax预处理器定义了LaTeX数学定界符,它们是 \(... \)用于内联数学,\ [... \]用于显示的方程式.它 还为显示的方程式定义了TeX分隔符$$ ... $$,但是 它没有将$ ... $定义为嵌入式数学定界符.

有关语法的详细信息,请阅读文档.

  • 注意:使用raw液体标记可确保Markdown解析器不会干扰MathJax语法.
  • 虽然可以将反斜杠(例如\\[ \frac{1}{n^{2}} \\])转义为 确保正确解析它们,如Chistopher Poole的描述 教程,这并不总是很直观,而且看起来很复杂.一种 更简单的解决方案是使用原始液体标签来确保 文字会被Markdown处理器忽略,并直接输出为 静态html.这是通过{% raw %}以及{% endraw %}
  • 完成的

这是一个代码示例:

 {% raw %}
  $$a^2 + b^2 = c^2$$ --> note that all equations between these tags will not need escaping! 
 {% endraw %}

最后还要确保字体支持显示LateX,因为有些字体大小过小等问题.另外,这里还有一些其他方法,例如Google图表和MathML ,乳胶StackExchange姐妹网站.

I use jekyll to write post and show it in github-pages. My source file is writen with markdown.

How can I insert formula into the markdown file?

I don't want to save the formula into an image and load the image in markdown file. I actually want to write latex formula in markdown file directly.

解决方案

Since resources online have changed regarding this question, here's an update on supporting LateX with GitHub Pages.

Note that the closest to Latex rendering without exporting as images and natively supporting it on your Jekyll site would be to use MathJax.

MathJax is actually recommended in Jekyllrb docs for math support, with Kramdown, it also converts it from LaTeX to PNG, more details on it here at the Kramdown documentation

Option 1: Write your equation in MathURL and embed it.

You could write the equation with MathURL, then generate a url that permanently points to the equation, and display this in an <iframe> tag. However, this will stop working if MathURL goes offline.

Option 2: Implement jsMath

jsMath will allow almost LateX like syntax and will be supported in your blog if you have set it up correctly, there is extensive documentation on this.

Option 3: Mathjax (by far the easiest in my opinion)

Many sites have mentioned that Mathjax is considered a successor of jsMath, and is much easier to implement with Jekyll. MathJax is also used by mathematics.stackexchange.com too!

  • Step 1: Have your site load the script in sites where you want to display math. (usually done in the header)

  • Optional: Check your markdown parser in _config.yml. redcarpet or kramdown is suggested in this example. Certain parsers like discount will interfere with the syntax but I have a solution below.

  • Step 2: Write your equations.

Quoting this tutorial by Gaston Sanchez:

MathJax does not have the exactly same behavior as LaTeX. By default, the tex2jax preprocessor defines the LaTeX math delimiters, which are \(...\) for in-line math, and \[...\] for displayed equations. It also defines the TeX delimiters $$...$$ for displayed equations, but it does not define $...$ as in-line math delimiters.

Read the documentation on the syntax for more details.

  • Note: Using the raw liquid tag to ensure Markdown parsers do not interfere with MathJax syntax.
  • While you could escape backslashes (e.g. \\[ \frac{1}{n^{2}} \\])to ensure they are parsed properly, as described by Chistopher Poole's tutorial, this is not always intuitive and looks complicated. A simpler solution would be to use the raw liquid tag to ensure the text is ignored by the Markdown processor and directly output as a static html. This is done with {% raw %}and also {% endraw %}

Here is a code sample:

 {% raw %}
  $$a^2 + b^2 = c^2$$ --> note that all equations between these tags will not need escaping! 
 {% endraw %}

Lastly also ensure that the fonts support displaying LateX as some have issues like font size being too small. Alternatively here are some additional methods like Google Charts and MathML discussed in the latex StackExchange sister site.

这篇关于如何在github-pages中支持乳胶?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆