Trying to understand how Pandoc converts from Markdown to Latex

有些话、适合烂在心里 提交于 2020-03-22 05:53:07

问题


I apologize if this is a repeat.

I have a Markdown file test.md which has two latex math mode parts:

First latex block (in .md file):

\begin{flalign}
P(1<X) &= \int_{1}^{\infty} f(x) dx \nonumber \\
&= \int_{1}^{4} 0 dx + \int_{4}^{\infty} e^{-(x-4)} dx \nonumber \\
\boldsymbol{P(1<X)} &= \boldsymbol{1} \nonumber
\end{flalign}

Second latex block (in .md file):

\begin{flalign}
Expected \; Revenue &= 2.5 \cdot non-passenger \; vehicles + 1.0 \cdot passenger \; vehicles \nonumber \\
&= \$(2.5 \cdot (25 - E(X)) + 1.0 \cdot E(X)) \nonumber \\
&= \$(62.5 - 1.5(E(X))) \nonumber \\
&= \$(62.5 - 1.5 \cdot 15) \nonumber \\
\boldsymbol{Expected \; Revenue} &= \boldsymbol{\$40} \nonumber
\end{flalign}

When I run the following command:

pandoc -f markdown -t latex test.md -s -o test.tex

I get the output as test.tex where the above two blocks are rendered as:

First latex block (in .tex file):

\textbackslash{}begin\{flalign\} P(1\textless{}X) \&=
\int\emph{\{1\}\^{}\{\infty\} f(x) dx \nonumber \textbackslash{} \&=
\int}\{1\}\^{}\{4\} 0 dx + \int\_\{4\}\^{}\{\infty\} e\^{}\{-(x-4)\} dx
\nonumber \textbackslash{} \boldsymbol{P(1<X)} \&= \boldsymbol{1}
\nonumber \textbackslash{}end\{flalign\}

Second latex block (in .tex file):

\begin{flalign}
Expected \; Revenue &= 2.5 \cdot non-passenger \; vehicles + 1.0 \cdot passenger \; vehicles \nonumber \\
&= \$(2.5 \cdot (25 - E(X)) + 1.0 \cdot E(X)) \nonumber \\
&= \$(62.5 - 1.5(E(X))) \nonumber \\
&= \$(62.5 - 1.5 \cdot 15) \nonumber \\
\boldsymbol{Expected \; Revenue} &= \boldsymbol{\$40} \nonumber
\end{flalign}

I am not sure how this happened. I am using:

OS: Windows 10

Editor: Visual Studio Code 1.28.1

Pandoc Version: 2.2.3.2

I though maybe it is because of the line endings being different in Windows so I changed the Line Endings from CLRF to LF and vice-versa but this didn't effect the output.

I would like to be able to say with certain surety as to how the conversion will happen as this is confusing to me.

I have also uploaded the files in case it is an issue of encoding of chars.


回答1:


Pandoc's LaTeX parser is not 100% perfect, so for complicated cases like this, you should use generic-raw-attributes in your markdown:

```{=latex}
\begin{flalign}
Expected \; Revenue &= 2.5 \cdot non-passenger \; vehicles + 1.0 \cdot passenger \; vehicles \nonumber \\
&= \$(2.5 \cdot (25 - E(X)) + 1.0 \cdot E(X)) \nonumber \\
&= \$(62.5 - 1.5(E(X))) \nonumber \\
&= \$(62.5 - 1.5 \cdot 15) \nonumber \\
\boldsymbol{Expected \; Revenue} &= \boldsymbol{\$40} \nonumber
\end{flalign}
```


来源:https://stackoverflow.com/questions/52811244/trying-to-understand-how-pandoc-converts-from-markdown-to-latex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!