# Pandoc managed Markdown to LaTeX to PDF workflow fails to port simple pipe_tables

I'd like to setup a simple workflow allowing me to type document segments in their own files using Markdown, then convert them to LaTeX using a common library such as pandoc, before finally collating all my document segments into a main file that would be output as PDF.

I've created a table that looks like the below in Markdown:

 $x$    |   $F(x)$
--------|------------------
$0$    |  $\frac{2}{8}$
$1$    |  $0$
$2$    |  $\frac{1}{2}$
$3$    |  $2\frac{1}{2}$
$4$    |  $6\frac{3}{4}$
$5$    |  $14$


This renders pleasantly enough in the markdown preview window I've got setup in Atom, but after I've converted this document using the commandline:

pandoc -f markdown+tex_math_dollars+pipe_tables table.md -o table.tex


The above construction is converted to:

\begin{longtable}[c]{@{}ll@{}}
$x$ & $F(x)$
$0$ & $\frac{2}{8}$
$1$ & $0$
$2$ & $\frac{1}{2}$
$3$ & $2\frac{1}{2}$
$4$ & $6\frac{3}{4}$
$5$ & $14$
\bottomrule
\end{longtable}


Which when piped through:

pandoc table.tex -o table.pdf


Doesn't resolve into a table, the initial line particularly looks fishy.

I can manually re-jig this to something like:

\begin{tabular}{c|c}
$x$ & $F(x)$ \\
\hline
$0$ & $\frac{2}{8}$ \\
$1$ & $0$ \\
$2$ & $\frac{1}{2}$ \\
$3$ & $2\frac{1}{2}$ \\
$4$ & $6\frac{3}{4}$ \\
$5$ & $14$ \\
\end{tabular}


Which is the result I want, but it takes time and I'd really like to be able to achieve this result directly from markup without human intervention.

• Is there a special reason for going from md -> latex -> pdf ? Pandoc is able to produce a pdf directly by using LaTex as the backend. Your MWE does work, I just simply process it with: pandoc -S pipetable.md -o pipetable.pdf. I am using pandoc 1.15.2 on Kubuntu 14.04 – blue_tiger300 Dec 20 '15 at 20:25
• I think I might like to skip the middle step, but at some point in the future, I'd like to group/compile multiple sections/chapters into a final document, and was under the impression that I'd only be able to have access to that kind of facility using latex \input or \include commands. – Thomas Kimber Dec 20 '15 at 20:30
• That's not necessary as you can pipe several .md files together. pandoc -s -S mermaid.md pipetable.md -o together.pdf You can also customize the appearance of your PDF by tweaking the LaTex template with pandoc -D latex > latex.default – blue_tiger300 Dec 20 '15 at 20:33
• OK cool, I've been able to try the md to pdf method, and find that works perfectly. And if I can go straight from md to pdf, then maybe I don't need the latex stepping-stone. – Thomas Kimber Dec 20 '15 at 20:36
• So it looks like this works for the immediate issue of generating a functioning pdf, but it would be good to get the latex middle-step, just so I can apply styling to one or more blocks of latex'd text. Though, I guess I can achieve much of this by updating the latex.default template as you mention...let me try that out... – Thomas Kimber Dec 20 '15 at 21:07

My answer: always re-test with the latest release of Pandoc if you run into any problems.

I'm currently using Pandoc v2.1, which is not even the newest one (that would be Pandoc v2.5). For your example table in Markdown, my 2.1 version gives me as LaTeX output:

pandoc          \
-f markdown+tex_math_dollars+pipe_tables \
-t latex     \
-o -         \
md-table.md

\begin{longtable}[]{@{}ll@{}}
\toprule
$$x$$ & $$F(x)$$\tabularnewline
\midrule
$$0$$ & $$\frac{2}{8}$$\tabularnewline
$$1$$ & $$0$$\tabularnewline
$$2$$ & $$\frac{1}{2}$$\tabularnewline
$$3$$ & $$2\frac{1}{2}$$\tabularnewline
$$4$$ & $$6\frac{3}{4}$$\tabularnewline
$$5$$ & $$14$$\tabularnewline
\bottomrule
\end{longtable}


The resulting LaTeX converts to PDF just fine, as well as a "direct" output of PDF works with the original Markdown. There isn't even a need to specify the Pandoc extensions (+tex_math_dollars+pipe_tables) as you did:

pandoc              \
md-table.md    \
-f markdown     \
-o md-table.pdf \
-V geometry:"margin=10pt, paperwidth=80pt, paperheight=120pt"

magick convert -density 300 md-table.{pdf,jpg}


(I'm using ImageMagick to create the JPEG for visualizing the resulting output in this answer, below.)