Skip to content

Commit

Permalink
Use \toprule\noalign{} instead of \toprule() in LaTeX tables.
Browse files Browse the repository at this point in the history
And similar for `\midrule` and `\bottomrule`.

This facilitates redefining `\toprule`, `\midrule`, and `\bottomrule`
without needing to gobble the ()s.

Closes #8223.
  • Loading branch information
jgm committed Jan 4, 2023
1 parent c4995fe commit 7a82686
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 60 deletions.
10 changes: 5 additions & 5 deletions src/Text/Pandoc/Writers/LaTeX/Table.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ tableToLaTeX inlnsToLaTeX blksToLaTeX tbl = do
head' <- do
let mkHead = headToLaTeX blksToLaTeX colCount
case (not $ isEmpty capt, not $ isEmptyHead thead) of
(False, False) -> return "\\toprule()"
(False, False) -> return "\\toprule\\noalign{}"
(False, True) -> mkHead thead
(True, False) -> return (capt $$ "\\toprule()" $$ "\\endfirsthead")
(True, False) -> return (capt $$ "\\toprule\\noalign{}" $$ "\\endfirsthead")
(True, True) -> do
-- avoid duplicate notes in head and firsthead:
firsthead <- mkHead thead
Expand All @@ -73,7 +73,7 @@ tableToLaTeX inlnsToLaTeX blksToLaTeX tbl = do
else do
lastfoot <- mapM (rowToLaTeX blksToLaTeX colCount BodyCell) $
footRows tfoot
pure $ "\\midrule()" $$ vcat lastfoot
pure $ "\\midrule\\noalign{}" $$ vcat lastfoot
modify $ \s -> s{ stTable = True }
notes <- notesToLaTeX <$> gets stNotes
return
Expand All @@ -83,7 +83,7 @@ tableToLaTeX inlnsToLaTeX blksToLaTeX tbl = do
$$ head'
$$ "\\endhead"
$$ foot'
$$ "\\bottomrule()"
$$ "\\bottomrule\\noalign{}"
$$ "\\endlastfoot"
$$ vcat rows'
$$ "\\end{longtable}"
Expand Down Expand Up @@ -184,7 +184,7 @@ headToLaTeX blocksWriter colCount (Ann.TableHead _attr headerRows) = do
rowsContents <-
mapM (rowToLaTeX blocksWriter colCount HeaderCell . headerRowCells)
headerRows
return ("\\toprule()" $$ vcat rowsContents $$ "\\midrule()")
return ("\\toprule\\noalign{}" $$ vcat rowsContents $$ "\\midrule\\noalign{}")

-- | Converts a row of table cells into a LaTeX row.
rowToLaTeX :: PandocMonad m
Expand Down
10 changes: 5 additions & 5 deletions test/command/2378.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ is used.
^D
\begin{longtable}[]{@{}ll@{}}
\caption{a table}\tabularnewline
\toprule()
\toprule\noalign{}
x & y\footnote{a footnote} \\
\midrule()
\midrule\noalign{}
\endfirsthead
\toprule()
\toprule\noalign{}
x & y{} \\
\midrule()
\midrule\noalign{}
\endhead
\bottomrule()
\bottomrule\noalign{}
\endlastfoot
1 & 2 \\
\end{longtable}
Expand Down
10 changes: 5 additions & 5 deletions test/command/5367.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ hello\footnote{doc footnote}
\begin{longtable}[]{@{}
>{\centering\arraybackslash}p{(\columnwidth - 0\tabcolsep) * \real{0.1667}}@{}}
\caption[Sample table.]{Sample table.\footnote{caption footnote}}\tabularnewline
\toprule()
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\centering
Fruit\footnote{header footnote}
\end{minipage} \\
\midrule()
\midrule\noalign{}
\endfirsthead
\toprule()
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\centering
Fruit{}
\end{minipage} \\
\midrule()
\midrule\noalign{}
\endhead
\bottomrule()
\bottomrule\noalign{}
\endlastfoot
Bans\footnote{table cell footnote} \\
\end{longtable}
Expand Down
4 changes: 2 additions & 2 deletions test/command/7272.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
^D
\begin{longtable}[]{@{}
>{\raggedright\arraybackslash}p{(\columnwidth - 0\tabcolsep) * \real{1.0000}}@{}}
\toprule()
\toprule\noalign{}
\endhead
\bottomrule()
\bottomrule\noalign{}
\endlastfoot
\begin{minipage}[t]{\linewidth}\raggedright
{ text\\
Expand Down
4 changes: 2 additions & 2 deletions test/command/8219.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
^D
\begin{longtable}[]{@{}ll@{}}
\caption{}\label{test}\tabularnewline
\toprule()
\toprule\noalign{}
\endfirsthead
\endhead
\bottomrule()
\bottomrule\noalign{}
\endlastfoot
one & two \\
\end{longtable}
Expand Down
50 changes: 25 additions & 25 deletions test/tables.latex
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ Simple table with caption:

\begin{longtable}[]{@{}rlcl@{}}
\caption{Demonstration of simple table syntax.}\tabularnewline
\toprule()
\toprule\noalign{}
Right & Left & Center & Default \\
\midrule()
\midrule\noalign{}
\endfirsthead
\toprule()
\toprule\noalign{}
Right & Left & Center & Default \\
\midrule()
\midrule\noalign{}
\endhead
\bottomrule()
\bottomrule\noalign{}
\endlastfoot
12 & 12 & 12 & 12 \\
123 & 123 & 123 & 123 \\
Expand All @@ -20,11 +20,11 @@ Right & Left & Center & Default \\
Simple table without caption:

\begin{longtable}[]{@{}rlcl@{}}
\toprule()
\toprule\noalign{}
Right & Left & Center & Default \\
\midrule()
\midrule\noalign{}
\endhead
\bottomrule()
\bottomrule\noalign{}
\endlastfoot
12 & 12 & 12 & 12 \\
123 & 123 & 123 & 123 \\
Expand All @@ -35,15 +35,15 @@ Simple table indented two spaces:

\begin{longtable}[]{@{}rlcl@{}}
\caption{Demonstration of simple table syntax.}\tabularnewline
\toprule()
\toprule\noalign{}
Right & Left & Center & Default \\
\midrule()
\midrule\noalign{}
\endfirsthead
\toprule()
\toprule\noalign{}
Right & Left & Center & Default \\
\midrule()
\midrule\noalign{}
\endhead
\bottomrule()
\bottomrule\noalign{}
\endlastfoot
12 & 12 & 12 & 12 \\
123 & 123 & 123 & 123 \\
Expand All @@ -58,7 +58,7 @@ Multiline table with caption:
>{\raggedleft\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1625}}
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3500}}@{}}
\caption{Here's the caption. It may span multiple lines.}\tabularnewline
\toprule()
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\centering
Centered Header
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Expand All @@ -68,9 +68,9 @@ Right Aligned
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Default aligned
\end{minipage} \\
\midrule()
\midrule\noalign{}
\endfirsthead
\toprule()
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\centering
Centered Header
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Expand All @@ -80,9 +80,9 @@ Right Aligned
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Default aligned
\end{minipage} \\
\midrule()
\midrule\noalign{}
\endhead
\bottomrule()
\bottomrule\noalign{}
\endlastfoot
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. \\
Expand All @@ -95,7 +95,7 @@ Multiline table without caption:
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1375}}
>{\raggedleft\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1625}}
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3500}}@{}}
\toprule()
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\centering
Centered Header
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Expand All @@ -105,9 +105,9 @@ Right Aligned
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Default aligned
\end{minipage} \\
\midrule()
\midrule\noalign{}
\endhead
\bottomrule()
\bottomrule\noalign{}
\endlastfoot
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. \\
Expand All @@ -116,9 +116,9 @@ Second & row & 5.0 & Here's another one. Note the blank line between rows. \\
Table without column headers:

\begin{longtable}[]{@{}rlcr@{}}
\toprule()
\toprule\noalign{}
\endhead
\bottomrule()
\bottomrule\noalign{}
\endlastfoot
12 & 12 & 12 & 12 \\
123 & 123 & 123 & 123 \\
Expand All @@ -132,9 +132,9 @@ Multiline table without column headers:
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1375}}
>{\raggedleft\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1625}}
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3500}}@{}}
\toprule()
\toprule\noalign{}
\endhead
\bottomrule()
\bottomrule\noalign{}
\endlastfoot
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. \\
Expand Down
12 changes: 6 additions & 6 deletions test/tables/nordics.latex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2000}}
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2000}}@{}}
\caption{States belonging to the \emph{Nordics.}}\label{nordics}\tabularnewline
\toprule()
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\centering
Name
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
Expand All @@ -16,9 +16,9 @@ Population\\
Area\\
(in km\textsuperscript{2})\strut
\end{minipage} \\
\midrule()
\midrule\noalign{}
\endfirsthead
\toprule()
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\centering
Name
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
Expand All @@ -30,11 +30,11 @@ Population\\
Area\\
(in km\textsuperscript{2})\strut
\end{minipage} \\
\midrule()
\midrule\noalign{}
\endhead
\midrule()
\midrule\noalign{}
Total & & 27,376,022 & 1,258,336 \\
\bottomrule()
\bottomrule\noalign{}
\endlastfoot
Denmark & Copenhagen & 5,809,502 & 43,094 \\
Finland & Helsinki & 5,537,364 & 338,145 \\
Expand Down
10 changes: 5 additions & 5 deletions test/tables/planets.latex
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
\begin{longtable}[]{@{}cclrrrrrrrrl@{}}
\caption{Data about the planets of our solar system.}\tabularnewline
\toprule()
\toprule\noalign{}
\multicolumn{2}{@{}>{\centering\arraybackslash}p{(\columnwidth - 22\tabcolsep) * \real{0.0000} + 2\tabcolsep}}{%
} & Name & Mass (10\^{}24kg) & Diameter (km) & Density (kg/m\^{}3) & Gravity
(m/s\^{}2) & Length of day (hours) & Distance from Sun (10\^{}6km) & Mean
temperature (C) & Number of moons & Notes \\
\midrule()
\midrule\noalign{}
\endfirsthead
\toprule()
\toprule\noalign{}
\multicolumn{2}{@{}>{\centering\arraybackslash}p{(\columnwidth - 22\tabcolsep) * \real{0.0000} + 2\tabcolsep}}{%
} & Name & Mass (10\^{}24kg) & Diameter (km) & Density (kg/m\^{}3) & Gravity
(m/s\^{}2) & Length of day (hours) & Distance from Sun (10\^{}6km) & Mean
temperature (C) & Number of moons & Notes \\
\midrule()
\midrule\noalign{}
\endhead
\bottomrule()
\bottomrule\noalign{}
\endlastfoot
\multicolumn{2}{@{}>{\centering\arraybackslash}p{(\columnwidth - 22\tabcolsep) * \real{0.0000} + 2\tabcolsep}}{%
\multirow{4}{*}{Terrestrial planets}} & Mercury & 0.330 & 4,879 & 5427 & 3.7 &
Expand Down
10 changes: 5 additions & 5 deletions test/tables/students.latex
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
>{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.5000}}
>{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.5000}}@{}}
\caption{List of Students}\label{students}\tabularnewline
\toprule()
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\centering
Student ID
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
Name
\end{minipage} \\
\midrule()
\midrule\noalign{}
\endfirsthead
\toprule()
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\centering
Student ID
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
Name
\end{minipage} \\
\midrule()
\midrule\noalign{}
\endhead
\bottomrule()
\bottomrule\noalign{}
\endlastfoot
\multicolumn{2}{@{}>{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{1.0000} + 2\tabcolsep}@{}}{%
Computer Science} \\
Expand Down

0 comments on commit 7a82686

Please sign in to comment.