如何在Pandoc Markdown中使用乳胶方程式环境?

Sta*_*tan 17 markdown latex mathjax pandoc

在Pandoc markdown中,我可以使用'$$'来启动显示数学环境.但是,这些方程式没有用乳胶编号,所以我希望使用方程式环境,如下所示:

\begin{equation}
x+1 = 2 \\
y+2 = 3 
\end{equation}
Run Code Online (Sandbox Code Playgroud)

如果我将降价改为乳胶,那就没关系.但是当我用Mathjax将它转换为HTML时它不起作用,因为Pandoc将这些行视为raw_latex在HTML中忽略它们.

我试图禁止raw_latex扩展

pandoc -f markdown-raw_latex ...
Run Code Online (Sandbox Code Playgroud)

这次两个方程显示在同一行,因为反斜杠由Pandoc转义,因此"\"不能正确生成换行符.

请注意,以下代码在转换为HTML时工作正常但在latex中产生编译错误.

$$    
\begin{equation}
    x+1 = 2 \\
    y+2 = 3 
\end{equation}
$$
Run Code Online (Sandbox Code Playgroud)

有没有办法解决这个问题?

tjd*_*tjd 14

试试pandoc-eqnos过滤器.标签可以使用属性附加到方程式:

 $$ y = mx +b $$ {#eq:description}
Run Code Online (Sandbox Code Playgroud)

...然后像这样引用:

@eq:description
Run Code Online (Sandbox Code Playgroud)

对于tex/pdf输出,使用LaTeX的本机equation环境\label\ref宏; 对于所有其他人来说,数字是硬编码的.

有关如何安装和应用过滤器的说明,请参见pandoc-eqnos页面.


Mat*_*ing 3

对于正确的方程编号没有良好的本机支持,但有一个解决方法。

> pandoc -s -o math.html --mathjax 
(@) $$y=5$$

A paragraph here explaining 

(@) $$y=6$$
Run Code Online (Sandbox Code Playgroud)

输出

<body>
<ol style="list-style-type: example">
<li><span class="math">\[y=5\]</span></li>
</ol>
<p>A paragraph here explaining</p>
<ol start="2" style="list-style-type: example">
<li><span class="math">\[y=6\]</span></li>
</ol>
</body>
Run Code Online (Sandbox Code Playgroud)

编号示例

显然,可以使用 css 来设置输出的样式以适应。另一方面,此方法的 tex 输出也将数字放在左侧。您选择哪种妥协取决于您。