From e13aa5c0157744de262ac512cc95a76a4562e37b Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 16 Sep 2025 17:59:42 +0200 Subject: [PATCH] LaTeX writer: ensure that unlabelled tables don't increment counter. Closes #11141. --- src/Text/Pandoc/Writers/LaTeX/Table.hs | 4 +++- test/command/7272.md | 2 ++ test/command/8638.md | 2 ++ test/command/9350.md | 2 ++ test/tables.latex | 8 ++++++++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Text/Pandoc/Writers/LaTeX/Table.hs b/src/Text/Pandoc/Writers/LaTeX/Table.hs index 5eea02116..79025ded3 100644 --- a/src/Text/Pandoc/Writers/LaTeX/Table.hs +++ b/src/Text/Pandoc/Writers/LaTeX/Table.hs @@ -98,8 +98,10 @@ tableToLaTeX inlnsToLaTeX blksToLaTeX tbl = do modify $ \s -> s{ stTable = True } notes <- notesToLaTeX <$> gets stNotes beamer <- gets stBeamer + let makeUnnumbered x = "{\\def\\LTcaptype{} % do not increment counter" $$ x $$ "}" return - $ "\\begin{longtable}[]" <> + $ (if null capt then makeUnnumbered else id) + $ "\\begin{longtable}[]" <> braces ("@{}" <> colDescriptors isSimpleTable tbl <> "@{}") -- the @{} removes extra space at beginning and end $$ head' diff --git a/test/command/7272.md b/test/command/7272.md index 9a97abf57..0daf2a2d4 100644 --- a/test/command/7272.md +++ b/test/command/7272.md @@ -14,6 +14,7 @@ ^D +{\def\LTcaptype{} % do not increment counter \begin{longtable}[]{@{} >{\raggedright\arraybackslash}p{(\linewidth - 0\tabcolsep) * \real{1.0000}}@{}} \toprule\noalign{} @@ -25,4 +26,5 @@ text2 }\strut \end{minipage} \\ \end{longtable} +} ``` diff --git a/test/command/8638.md b/test/command/8638.md index 2da8ded01..e77396aa8 100644 --- a/test/command/8638.md +++ b/test/command/8638.md @@ -7,6 +7,7 @@ | oranges | 4.25 | ^D \begin{frame} +{\def\LTcaptype{} % do not increment counter \begin{longtable}[]{@{}lr@{}} \toprule\noalign{} fruit & price \\ @@ -16,5 +17,6 @@ apple & 2.05 \\ oranges & 4.25 \\ \bottomrule\noalign{} \end{longtable} +} \end{frame} ``` diff --git a/test/command/9350.md b/test/command/9350.md index d641f8b76..205f29271 100644 --- a/test/command/9350.md +++ b/test/command/9350.md @@ -2,6 +2,7 @@ % pandoc -f html -t latex
^D +{\def\LTcaptype{} % do not increment counter \begin{longtable}[]{@{}l@{}} \toprule\noalign{} \endhead @@ -9,4 +10,5 @@ \endlastfoot \\ \end{longtable} +} ``` diff --git a/test/tables.latex b/test/tables.latex index 6bb80df81..e29780883 100644 --- a/test/tables.latex +++ b/test/tables.latex @@ -19,6 +19,7 @@ Right & Left & Center & Default \\ Simple table without caption: +{\def\LTcaptype{} % do not increment counter \begin{longtable}[]{@{}rlcl@{}} \toprule\noalign{} Right & Left & Center & Default \\ @@ -30,6 +31,7 @@ Right & Left & Center & Default \\ 123 & 123 & 123 & 123 \\ 1 & 1 & 1 & 1 \\ \end{longtable} +} Simple table indented two spaces: @@ -90,6 +92,7 @@ Second & row & 5.0 & Here's another one. Note the blank line between rows. \\ Multiline table without caption: +{\def\LTcaptype{} % do not increment counter \begin{longtable}[]{@{} >{\centering\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.1500}} >{\raggedright\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.1375}} @@ -112,9 +115,11 @@ Default aligned First & row & 12.0 & Example of a row that spans multiple lines. \\ Second & row & 5.0 & Here's another one. Note the blank line between rows. \\ \end{longtable} +} Table without column headers: +{\def\LTcaptype{} % do not increment counter \begin{longtable}[]{@{}rlcr@{}} \toprule\noalign{} \endhead @@ -124,9 +129,11 @@ Table without column headers: 123 & 123 & 123 & 123 \\ 1 & 1 & 1 & 1 \\ \end{longtable} +} Multiline table without column headers: +{\def\LTcaptype{} % do not increment counter \begin{longtable}[]{@{} >{\centering\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.1500}} >{\raggedright\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.1375}} @@ -139,3 +146,4 @@ Multiline table without column headers: First & row & 12.0 & Example of a row that spans multiple lines. \\ Second & row & 5.0 & Here's another one. Note the blank line between rows. \\ \end{longtable} +}