简体   繁体   English

Kramdown中的Latex \\ newcommand

[英]Latex \newcommand in kramdown

I understand that cramdown does not support \\newcommand type macros. 我了解cramdown不支持\\ newcommand类型的宏。 Is there a workaround that does not involve Pandoc, so that it could be used with Jekyll in a GitHub blog? 有没有不涉及Pandoc的解决方法,以便可以与GitHub博客中的Jekyll一起使用?

This would be the input markdown: 这将是输入减价:

---
layout: post
---

\newcommand{\a}{\alpha}

This is a test $$\a$$.

The output should be a Jekyll blog, with mathematical notation, like this . 输出应该是一个杰基尔博客,用数学符号,像这样

There seems to be two questions here — first, can one define commands in kramdown similar to LaTeX's \\newcommand syntax, and second, can kramdown support mathematics. 这里似乎有两个问题-首先,可以在kramdown中定义类似于LaTeX的\\newcommand语法的命令,其次,可以kramdown支持数学。

Regarding the first issue, kramdown itself doesn't support that syntax or anything like it that I'm aware of, and probably isn't going to in the future , so you can't define non-math kramdown commands. 关于第一个问题,kramdown本身不支持该语法或我所知道的类似语法, 并且将来可能不会支持该语法,因此您无法定义非数学的kramdown命令。 You'd need to use a language that's focused on completeness rather than ease and simplicity, like LaTeX, to get features like that. 您需要使用专注于完整性而不是简单易用的语言(例如LaTeX)来获得这样的功能。

For math, though, MathJax (the parser kramdown uses) does parse \\newcommand : just go ahead and use it in the first code block. 对于数学,尽管如此,MathJax(kramdown解析器使用的解析器)确实解析\\newcommand :只需继续在第一个代码块中使用它即可。 So for example, 例如

$$\newcommand{\a}{\alpha} \a{}/2 $$

yields the expected fraction with the expected Computer Modern italic Greek alpha, and you'll also be able to use \\a in every subsequent code block. 产生带有预期的Computer Modern italic Greek alpha的预期分数,并且您还可以在每个后续代码块中使用\\a You can also have a code block at the beginning of your document that contains all of your \\newcommand definitions if you don't want them to be interspersed in random code blocks throughout your document. 如果您不希望它们散布在整个文档的随机代码块中,则在文档的开头还可以包含一个包含所有\\newcommand定义的代码块。

Regarding the second issue, as I guess is obvious at this point, kramdown does handle math using similar notation to LaTeX: 关于第二个问题,我想这很明显,kramdown确实使用与LaTeX类似的符号处理数学:

Here is a paragraph with some inline math, $$ \pi{}/2 $$, followed by
some text and a math block.

$$ \int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi} $$

This yields: 这样产生:

<p>Here is a paragraph with some inline math, <script
type="math/tex">\pi{}/2</script>, followed by some text and a math 
block.</p>

<script type="math/tex; mode=display">\int_{-\infty}^{\infty} e^{-x^2}
dx = \sqrt{\pi}</script>

If that isn't successfully rendering for you on your site, don't forget to include the MathJax library in the <head> of your HTML page: 如果那不能在您的网站上成功呈现,请不要忘记在HTML页面的<head>包含MathJax库

<script type="text/javascript"
    src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM