gpt4 book ai didi

pandoc - 如何在 pandoc 中使用 latex 宏?

转载 作者:行者123 更新时间:2023-12-03 21:31:17 26 4
gpt4 key购买 nike

pandoc User's Guide状态(强调添加):

For output formats other than LaTeX, pandoc will parse LaTeX \newcommand and \renewcommand definitions and apply the resulting macros to all LaTeX math. So, for example, the following will work in all output formats, not just LaTeX:


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

$\tuple{a, b, c}$

In LaTeX output, the \newcommand definition will simply be passed unchanged to the output.



例如,使用这个测试文件:
\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 ,为什么第一个 的HTML文件中留下了latex源代码克向量:
<p><br /><span class="math display">$$\vec{g}$$</span><br /></p>

而另一个定义 的 latex 方程克矢量已成功转换为粗体 信?

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

最佳答案

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

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

关于pandoc - 如何在 pandoc 中使用 latex 宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34747428/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com