jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.05k stars 3.35k forks source link

Latex Reader not able to recognize complex table #7757

Open luerhard opened 2 years ago

luerhard commented 2 years ago

Explain the problem.

The pandoc problem: It seems that the Latex Reader ist not able to recognize the first table in the 1. Example as a table.

When I try to consecutively simplify the code, I come to the 2. Example and 3. Example which are recognized as tables, but the Header is omitted in both cases.

\documentclass[11pt,a4paper]{article}

\usepackage{longtable}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{calc}

\begin{document}

1. Example: Is not recognized as a table at all:

\begin{longtable}[]{@{}
        >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.2000}}
        >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.5000}}
        >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.3000}}@{}}
    \toprule
    \begin{minipage}[b]{\linewidth}\raggedright
        1
    \end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
        2
    \end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
        3
    \end{minipage} \\
    \midrule
    \endhead
    hello & my & name \\
    \bottomrule
\end{longtable}

2. Example: Misses Header:

\begin{longtable}[]{lll}
    \toprule
    \begin{minipage}[b]{\linewidth}\raggedright
        1
    \end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
        2
    \end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
        3
    \end{minipage} \\
    \midrule
    \endhead
    hello & my & name \\
    \bottomrule
\end{longtable}

3. Example: Also misses Header:

\begin{longtable}[]{@{}
        >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.2000}}
        >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.5000}}
        >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.3000}}@{}}
    \toprule
    1 & 2 & 3 \\
    \midrule
    \endhead
    hello & my & name \\
    \bottomrule
\end{longtable}

4. Example: Works fine:

\begin{longtable}[]{lll}
    \toprule
    1 & 2 & 3 \\
    \midrule
    \endhead
    hello & my & name \\
    \bottomrule
\end{longtable}

\end{document}

If I run pandoc -o out.tex main.tex (for debugging purposes only), I get the following Latex back:

1. Example: Is not recognized as a table at all:

{@ \textgreater p{(- 4) * } \textgreater p{(- 4) * } \textgreater p{(-
4) * }@}

\&

\&

\hfill\break
hello \& my \& name\\

2. Example: Misses Header:

\begin{longtable}[]{@{}lll@{}}
\toprule
& & \\
\midrule
\endhead
hello & my & name \\
\bottomrule
\end{longtable}

3. Example: Also misses Header:

\begin{longtable}[]{@{}lll@{}}
\toprule
& & \\
\midrule
\endhead
hello & my & name \\
\bottomrule
\end{longtable}

4. Example: Works fine:

\begin{longtable}[]{@{}lll@{}}
\toprule
1 & 2 & 3 \\
\midrule
\endhead
hello & my & name \\
\bottomrule
\end{longtable}

I know this is a lot of Latex, and I think there are two different problems in the parser involved, but I am not able to disambiguate them further. The original 1. Example is the latex output if one uses the pantable filter and converts the following table to latex:

\```table
---
alignment: LLL
width: [0.2, 0.5, 0.3]
---
1,2,3
hello,my,name

\```

Pandoc version? pandoc 2.16 on Kubuntu 21.10

tarleb commented 2 years ago

It seems that the reader doesn't support >{\raggedright\arraybackslash} as part of the column definition. Example 3 works well after removing that.

Another problem seems to come from \raggedright. Removing it from the minipage environments fixes Example 2.