Skip to content

Correctly consume the longtable environment in LaTeX input #2411

Closed
HalosGhost opened this Issue · 1 comment

2 participants

@HalosGhost

In working with pandoc, I have stumbled on an annoying asymmetry. Using pandoc to convert rst to latex, pandoc uses the longtable environment. E.g.:

======= =====
example table
======= =====
stuff   other
random  junk
======= =====
\begin{longtable}[c]{@{}ll@{}}
\toprule
example & table\tabularnewline
\midrule
\endhead
stuff & other\tabularnewline
random & junk\tabularnewline
\bottomrule
\end{longtable}

However, if you attempt to feed pandoc a longtable in latex input and convert it to something else, it will be garbage:

\begin{longtable}[c]{@{}ll@{}}
\toprule
example & table\tabularnewline
\midrule
\endhead
stuff & other\tabularnewline
random & junk\tabularnewline
\bottomrule
\end{longtable}
<p>[c]<span>@ll@</span> example &amp; tablestuff &amp; otherrandom &amp; junk</p>

(Note that the above example actually fed the LaTeX output from pandoc directly back into itself, but that any use of the longtable environment fails to be parsed).

In fact, it seems that pandoc only supports the tabular environment for tables (for latex input). However, the tabular environment does not span pages in PDF output. Resultingly, the only way to have a latex source file for pandoc that will also be used for PDF output that uses tables is to do something like the following:

\usepackage{ifxetex,longtable}
\begin{document}
\ifxetex\let\tabular\longtable\let\endtabular\endlongtable\fi
\begin{tabular}[h]{l|l|l}
…
\end{tabular}
\end{document}

The main line of note in the snippet above is the use of an if command (which is specific to the output engine) that conditionally redefines tabular to be longtable. If Pandoc were to, instead of needing this shockingly ugly workaround, simply consume the longtable environment (which does not seem too far out-of-scope since pandoc itself generates longtable environments), this whole situation could be made much simpler.

@jgm jgm added a commit that closed this issue
@jgm LaTeX reader: support longtable.
Closes #2411.
72e71a1
@jgm jgm closed this in 72e71a1
@jgm
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.