如何在pandoc中使用latex宏?

5

根据pandoc 用户指南(已加重强调):

对于除LaTeX以外的输出格式,pandoc将解析LaTeX \newcommand和\renewcommand定义,并将生成的宏应用于所有LaTeX数学公式。因此,例如以下内容在所有输出格式中都可以使用,而不仅仅是在LaTeX中:

\newcommand{\tuple}[1]{\langle #1 \rangle}

$\tuple{a, b, c}$

例如,使用这个测试文件:

在LaTeX输出中,\newcommand定义将被简单地传递到输出中,不做任何改变。

\renewcommand{\vec}[1]{\mathbf{#1}}

The gravitational force 

$$\vec{g}$$

The gravitational force 

$$\mathbf{g}$$

And with some code:

~~~{.cpp .numberLines startFrom="1"}
class A {}; 
~~~ 

使用pandoc test.md -o test.html进行转换,结果为

<p>[1]{}</p>
<p>The gravitational force</p>
<p><br /><span class="math display">$$\vec{g}$$</span><br /></p>
<p>The gravitational force</p>
<p><br /><span class="math display"><strong>g</strong></span><br /></p>
<p>And with some code:</p>
<div class="sourceCode" startFrom="1"><table class="sourceCode cpp numberLines"><tr class="sourceCode"><td class="lineNumbers"><pre>1
</pre></td><td class="sourceCode"><pre><code class="sourceCode cpp"><span class="kw">class</span> A {}; </code></pre></td></tr></table></div>

如果pandoc真的解析了newcommandrenewcommand,那么为什么在第一个g向量的HTML文件中,LaTeX源代码被保留呢?
<p><br /><span class="math display">$$\vec{g}$$</span><br /></p>

另一个定义g向量的latex公式已成功转换为粗体g字母,这是一致的吗?启用latex_macros扩展(通过调用pandoc test.md --from markdown+latex_macros -o test.html)也会得到相同的结果。


2
应该是\renewcommand{\vec}而不是\renewcommand{vec} - scoa
1个回答

7

我认为这是一个笔误。这份文档:

\renewcommand{\vec}[1]{\mathbf{#1}}

The gravitational force 

$$\vec{g}$$

The gravitational force 

$$\mathbf{g}$$

And with some code:

~~~{.cpp .numberLines startFrom="1"}
class A {}; 
~~~ 

使用 pandoc test.md -o test.html 命令生成预期的输出结果(第2行和第4行与预期相同: \vec 已经被定义为 \mathbf)。

<p>The gravitational force</p>
<p><br /><span class="math display"><strong>g</strong></span><br /></p>
<p>The gravitational force</p>
<p><br /><span class="math display"><strong>g</strong></span><br /></p>
<p>And with some code:</p>
<div class="sourceCode" startFrom="1"><table class="sourceCode cpp numberLines"><tr class="sourceCode"><td class="lineNumbers"><pre>1
</pre></td><td class="sourceCode"><pre><code class="sourceCode cpp"><span class="kw">class</span> A {}; </code></pre></td></tr></table></div>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接