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@{}}
\toprule\addlinespace
$x$ & $F(x)$
\\\addlinespace
\midrule\endhead
$0$ & $\frac{2}{8}$
\\\addlinespace
$1$ & $0$
\\\addlinespace
$2$ & $\frac{1}{2}$
\\\addlinespace
$3$ & $2\frac{1}{2}$
\\\addlinespace
$4$ & $6\frac{3}{4}$
\\\addlinespace
$5$ & $14$
\\\addlinespace
\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.
Best Answer
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:
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:(I'm using ImageMagick to create the JPEG for visualizing the resulting output in this answer, below.)