Reputation: 5477
The pandoc User's Guide states (emphasis added):
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.
For example, using this test file:
\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 {};
~~~
and converting it with pandoc test.md -o test.html
results in
<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>
If pandoc really parses the newcommand
and renewcommand
, why is the latex source code left within the HTML file for the first g vector:
<p><br /><span class="math display">$$\vec{g}$$</span><br /></p>
while the other latex equation defining the g vector was successfully converted into the boldface g letter?
Is this an inconsistency? The result is the same when enabling the latex_macros
extension by calling pandoc test.md --from markdown+latex_macros -o test.html
.
Upvotes: 5
Views: 6667
Reputation: 19867
I think this is a typo. This document:
\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 {};
~~~
Gives the expected output with pandoc test.md -o test.html
(line 2 and 4 are identical as expected: \vec
has been defined as \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>
Upvotes: 7