Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to understand how Pandoc converts from Markdown to Latex

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.

like image 561
Akshay Gaur Avatar asked Oct 15 '25 15:10

Akshay Gaur


1 Answers

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}
```
like image 95
mb21 Avatar answered Oct 19 '25 01:10

mb21



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!