【问题标题】:How to use latex macros with pandoc?如何在 pandoc 中使用乳胶宏?
【发布时间】:2016-01-12 15:22:28
【问题描述】:

pandoc User's Guide 声明(已添加重点):

对于 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 向量的乳胶方程已成功转换为粗体 g 字母?

这是不一致吗?通过调用pandoc test.md --from markdown+latex_macros -o test.html 启用latex_macros 扩展时,结果是相同的。

【问题讨论】:

  • 不应该是\renewcommand{\vec} 而不是\renewcommand{vec}

标签: pandoc


【解决方案1】:

我认为这是一个错字。本文档:

\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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-11
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    相关资源
    最近更新 更多