Pandoc not generating new lines in markdown with latex
Asked Answered
L

1

6

I am working on a .md file which includes latex. The file looks like this:

$$
1+1 = 2
\\
2+2 = 4
$$

The File:

the file

When viewing it as markdown the file looks perfectly fine with the new line properly added.

Although when I use pandoc to write the file to a pdf the following happens:

PDF File (from pandoc)

pandoc

As you can see the new line has been completely removed and makes the latex hard to read.

I am using the following pandoc command:

pandoc --wrap=preserve in.md -o out.pdf

The --wrap=preserve does not seem to be working as it ignores a new line. I have also tried to use \newline \linebreak instead of \\ and neither seem to be working.

How can I specify a line break so pandoc will make sure to keep the breaks rather than keeping everything inline?

Longshoreman answered 11/8, 2020 at 1:23 Comment(1)
` \\ ` should not be used for linebreaks outside tables. If you want to have multiline equations, have a look at split or similar environmentsGuanabana
A
1

Whatever file preview tool you are using: it is lying to you. Double-backslash is not the correct way to insert newlines into math.

Pandoc either parses the math and converts it into the target format, or just passes the code through, depending on the output format. For PDF output via LaTeX, the equation is just passed through. (You can check by running pandoc with --verbose, which, among other things, will print the generated raw LaTeX code.) So it is clear that the problem lies with the input.

There are multiple ways to add linebreaks into math in LaTeX. One of them is the align* environment:

\begin{align*}
1+1 = 2
\\
2+2 = 4
\end{align*}

This will give you the expected PDF output, but has the downside of not showing up in other output formats like HTML. I'm not aware of any method which would produce linebreaks in math equations across all possible pandoc output formats. You'll have to use multiple single-line equations if you need that.

Abdella answered 11/8, 2020 at 8:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.