Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use latex equation environment in Pandoc Markdown?

Tags:

In Pandoc markdown, I can use '$$' to start a display math environment. However, these equations are not numbered in latex so I hope to use the equation environment instead, like this:

\begin{equation} x+1 = 2 \\ y+2 = 3  \end{equation} 

That's fine if I convert markdown to latex. But it does't work when I convert it to HTML with Mathjax because Pandoc treats these lines as raw_latex ignores them in HTML.

I tried to forbid the raw_latex extension

pandoc -f markdown-raw_latex ... 

This time the two equations are displayed in the same line because the backslashes are escaped by Pandoc so the "\" doesn't produce a newline correctly.

Note that the following code works fine when converted to HTML but produces compilation error in latex.

$$     \begin{equation}     x+1 = 2 \\     y+2 = 3  \end{equation} $$ 

Is there any way to handle this problem?

like image 958
Stan Avatar asked Jul 30 '14 17:07

Stan


People also ask

How do I use LaTeX code in Markdown?

We can use LaTeX to write mathematical equations in Markdown. To write inline LaTeX formula use a single $ before and after the equation and use a double $ to display equations.

Does pandoc need LaTeX?

By default, pandoc will use LaTeX to create the PDF, which requires that a LaTeX engine be installed (see --pdf-engine below). Alternatively, pandoc can use ConTeXt, roff ms, or HTML as an intermediate format.

Can you write equations in Markdown?

We are pleased to announce that math expressions can now be rendered natively in Markdown on GitHub.

Can pandoc convert PDF to Markdown?

You can use the program pandoc on the SCF Linux and Mac machines (via the terminal window) to convert from formats such as HTML, LaTeX and Markdown to formats such as HTML, LaTeX, Word, OpenOffice, and PDF, among others.


1 Answers

Try the pandoc-eqnos filter. Labels may be attached to equations using attributes:

 $$ y = mx +b $$ {#eq:description} 

... and then referenced like this:

@eq:description 

For tex/pdf output, LaTeX's native equation environment and \label and \ref macros are used; for all others the numbers are hard-coded.

Instructions are given on the pandoc-eqnos page for how to install and apply the filter.

like image 110
tjd Avatar answered Oct 12 '22 01:10

tjd