Pandoc: Latex reader fails parse nested tables

Created on 29 Jun 2018  路  4Comments  路  Source: jgm/pandoc

This should be valid latex, however it fails to parse with pandoc compiled from today's master branch. I'm looking into the latex reader, maybe someone can give me pointers where this can be fixed

input: tables.tex

\begin{tabular}{c c}
  \begin{tabular}{c} a \\ \end{tabular}
  &
  \\
\end{tabular}

Executing pandoc tables.tex gives me this error:

Error at "source" (line 5, column 1):
unexpected Tok "source" (line 5, column 1) (CtrlSeq "end") "\\end"
expecting end of input
\end{tabular}
^

pandoc 2.2.1
Compiled with pandoc-types 1.17.5, texmath 0.11, skylighting 0.7.2

LaTeX reader

Most helpful comment

I'm facing the same issue right now using pandoc 2.9.2.1.

My table has a header that is a tabular to make it multiline and right aligned:

\begin{table}[ht]
    \begin{tabular}{@{}lr@{}}
        \toprule
        \textbf{Simple header} & \textbf{\begin{tabular}[c]{@{}r@{}}Multiline\\ header \\ right aligned\end{tabular}} \\
        \midrule
        Foo     &  123 \\
        Bar     &  456 \\
        \bottomrule
    \end{tabular}
\end{table}

Are there plans to fix this? Or is there perhaps an extension that can circumvent or solve this problem in the meantime?

All 4 comments

maybe someone can give me pointers where this can be fixed

Should be around parseTableRow.

Should be around parseTableRow.

Thanks, I created this fix: e91b74cc9dc3f98c9fafb9ab799270f8a444904e

Right now there are two problems I'm facing with this.

Firstly, I don't know how to add the column prefixes and suffixes to each cell (as in https://github.com/jgm/pandoc/commit/e91b74cc9dc3f98c9fafb9ab799270f8a444904e#diff-1c5206ea07dccd86de1ea3be10ff30d9L2632). I'm not sure how to get the tokens from an already parsed table cell. Alternatively one could somehow insert the prefix and suffix tokens into the token stream. I don't see how this is possible currently.

Secondly, we would need to settle on which characters to treat as LaTeX control characters (and not parse as strings in inline - see
https://github.com/jgm/pandoc/commit/e91b74cc9dc3f98c9fafb9ab799270f8a444904e#diff-1c5206ea07dccd86de1ea3be10ff30d9R1907). Right now I only do it for '&'.
Maybe it should be all of Readers.LaTeX.specialChars but I guess if we don't, the reader is more permissive in the sense that it automatically escapes some special characters if they don't make sense otherwise.

I guess @jgm is more familiar with the LaTeX reader...

I'm facing the same issue right now using pandoc 2.9.2.1.

My table has a header that is a tabular to make it multiline and right aligned:

\begin{table}[ht]
    \begin{tabular}{@{}lr@{}}
        \toprule
        \textbf{Simple header} & \textbf{\begin{tabular}[c]{@{}r@{}}Multiline\\ header \\ right aligned\end{tabular}} \\
        \midrule
        Foo     &  123 \\
        Bar     &  456 \\
        \bottomrule
    \end{tabular}
\end{table}

Are there plans to fix this? Or is there perhaps an extension that can circumvent or solve this problem in the meantime?

Was this page helpful?
0 / 5 - 0 ratings