LaTeX writer: add () after booktabs rules.

These commands take optional arguments with () and [],
which can lead to problems if the content of the table
cell begins with these characters.

Closes .
This commit is contained in:
John MacFarlane 2022-03-30 10:07:09 -07:00
parent bb5f0f7b76
commit 5f0bfd41a8
8 changed files with 55 additions and 55 deletions

View file

@ -52,7 +52,7 @@ tableToLaTeX inlnsToLaTeX blksToLaTeX tbl = do
else ($$ text "\\endfirsthead") <$> else ($$ text "\\endfirsthead") <$>
headToLaTeX blksToLaTeX thead headToLaTeX blksToLaTeX thead
head' <- if isEmptyHead thead head' <- if isEmptyHead thead
then return "\\toprule" then return "\\toprule()"
-- avoid duplicate notes in head and firsthead: -- avoid duplicate notes in head and firsthead:
else headToLaTeX blksToLaTeX else headToLaTeX blksToLaTeX
(if isEmpty firsthead (if isEmpty firsthead
@ -71,7 +71,7 @@ tableToLaTeX inlnsToLaTeX blksToLaTeX tbl = do
$$ head' $$ head'
$$ "\\endhead" $$ "\\endhead"
$$ vcat rows' $$ vcat rows'
$$ "\\bottomrule" $$ "\\bottomrule()"
$$ "\\end{longtable}" $$ "\\end{longtable}"
$$ captNotes $$ captNotes
$$ notes $$ notes
@ -161,7 +161,7 @@ headToLaTeX :: PandocMonad m
headToLaTeX blocksWriter (Ann.TableHead _attr headerRows) = do headToLaTeX blocksWriter (Ann.TableHead _attr headerRows) = do
rowsContents <- mapM (rowToLaTeX blocksWriter HeaderCell . headerRowCells) rowsContents <- mapM (rowToLaTeX blocksWriter HeaderCell . headerRowCells)
headerRows headerRows
return ("\\toprule" $$ vcat rowsContents $$ "\\midrule") return ("\\toprule()" $$ vcat rowsContents $$ "\\midrule()")
-- | Converts a row of table cells into a LaTeX row. -- | Converts a row of table cells into a LaTeX row.
rowToLaTeX :: PandocMonad m rowToLaTeX :: PandocMonad m

View file

@ -13,15 +13,15 @@ is used.
^D ^D
\begin{longtable}[]{@{}ll@{}} \begin{longtable}[]{@{}ll@{}}
\caption{a table}\tabularnewline \caption{a table}\tabularnewline
\toprule \toprule()
x & y\footnote{a footnote} \\ x & y\footnote{a footnote} \\
\midrule \midrule()
\endfirsthead \endfirsthead
\toprule \toprule()
x & y{} \\ x & y{} \\
\midrule \midrule()
\endhead \endhead
1 & 2 \\ 1 & 2 \\
\bottomrule \bottomrule()
\end{longtable} \end{longtable}
``` ```

View file

@ -23,20 +23,20 @@ hello\footnote{doc footnote}
\begin{longtable}[]{@{} \begin{longtable}[]{@{}
>{\centering\arraybackslash}p{(\columnwidth - 0\tabcolsep) * \real{0.1667}}@{}} >{\centering\arraybackslash}p{(\columnwidth - 0\tabcolsep) * \real{0.1667}}@{}}
\caption[Sample table.]{Sample table.\footnote{caption footnote}}\tabularnewline \caption[Sample table.]{Sample table.\footnote{caption footnote}}\tabularnewline
\toprule \toprule()
\begin{minipage}[b]{\linewidth}\centering \begin{minipage}[b]{\linewidth}\centering
Fruit\footnote{header footnote} Fruit\footnote{header footnote}
\end{minipage} \\ \end{minipage} \\
\midrule \midrule()
\endfirsthead \endfirsthead
\toprule \toprule()
\begin{minipage}[b]{\linewidth}\centering \begin{minipage}[b]{\linewidth}\centering
Fruit{} Fruit{}
\end{minipage} \\ \end{minipage} \\
\midrule \midrule()
\endhead \endhead
Bans\footnote{table cell footnote} \\ Bans\footnote{table cell footnote} \\
\bottomrule \bottomrule()
\end{longtable} \end{longtable}
dolly\footnote{doc footnote} dolly\footnote{doc footnote}

View file

@ -16,12 +16,12 @@
^D ^D
\begin{longtable}[]{@{} \begin{longtable}[]{@{}
>{\raggedright\arraybackslash}p{(\columnwidth - 0\tabcolsep) * \real{1.0000}}@{}} >{\raggedright\arraybackslash}p{(\columnwidth - 0\tabcolsep) * \real{1.0000}}@{}}
\toprule \toprule()
\endhead \endhead
\begin{minipage}[t]{\linewidth}\raggedright \begin{minipage}[t]{\linewidth}\raggedright
{ text\\ { text\\
text2 }\strut text2 }\strut
\end{minipage} \\ \end{minipage} \\
\bottomrule \bottomrule()
\end{longtable} \end{longtable}
``` ```

View file

@ -2,49 +2,49 @@ Simple table with caption:
\begin{longtable}[]{@{}rlcl@{}} \begin{longtable}[]{@{}rlcl@{}}
\caption{Demonstration of simple table syntax.}\tabularnewline \caption{Demonstration of simple table syntax.}\tabularnewline
\toprule \toprule()
Right & Left & Center & Default \\ Right & Left & Center & Default \\
\midrule \midrule()
\endfirsthead \endfirsthead
\toprule \toprule()
Right & Left & Center & Default \\ Right & Left & Center & Default \\
\midrule \midrule()
\endhead \endhead
12 & 12 & 12 & 12 \\ 12 & 12 & 12 & 12 \\
123 & 123 & 123 & 123 \\ 123 & 123 & 123 & 123 \\
1 & 1 & 1 & 1 \\ 1 & 1 & 1 & 1 \\
\bottomrule \bottomrule()
\end{longtable} \end{longtable}
Simple table without caption: Simple table without caption:
\begin{longtable}[]{@{}rlcl@{}} \begin{longtable}[]{@{}rlcl@{}}
\toprule \toprule()
Right & Left & Center & Default \\ Right & Left & Center & Default \\
\midrule \midrule()
\endhead \endhead
12 & 12 & 12 & 12 \\ 12 & 12 & 12 & 12 \\
123 & 123 & 123 & 123 \\ 123 & 123 & 123 & 123 \\
1 & 1 & 1 & 1 \\ 1 & 1 & 1 & 1 \\
\bottomrule \bottomrule()
\end{longtable} \end{longtable}
Simple table indented two spaces: Simple table indented two spaces:
\begin{longtable}[]{@{}rlcl@{}} \begin{longtable}[]{@{}rlcl@{}}
\caption{Demonstration of simple table syntax.}\tabularnewline \caption{Demonstration of simple table syntax.}\tabularnewline
\toprule \toprule()
Right & Left & Center & Default \\ Right & Left & Center & Default \\
\midrule \midrule()
\endfirsthead \endfirsthead
\toprule \toprule()
Right & Left & Center & Default \\ Right & Left & Center & Default \\
\midrule \midrule()
\endhead \endhead
12 & 12 & 12 & 12 \\ 12 & 12 & 12 & 12 \\
123 & 123 & 123 & 123 \\ 123 & 123 & 123 & 123 \\
1 & 1 & 1 & 1 \\ 1 & 1 & 1 & 1 \\
\bottomrule \bottomrule()
\end{longtable} \end{longtable}
Multiline table with caption: Multiline table with caption:
@ -55,7 +55,7 @@ Multiline table with caption:
>{\raggedleft\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1625}} >{\raggedleft\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1625}}
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3500}}@{}} >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3500}}@{}}
\caption{Here's the caption. It may span multiple lines.}\tabularnewline \caption{Here's the caption. It may span multiple lines.}\tabularnewline
\toprule \toprule()
\begin{minipage}[b]{\linewidth}\centering \begin{minipage}[b]{\linewidth}\centering
Centered Header Centered Header
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright \end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
@ -65,9 +65,9 @@ Right Aligned
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright \end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Default aligned Default aligned
\end{minipage} \\ \end{minipage} \\
\midrule \midrule()
\endfirsthead \endfirsthead
\toprule \toprule()
\begin{minipage}[b]{\linewidth}\centering \begin{minipage}[b]{\linewidth}\centering
Centered Header Centered Header
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright \end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
@ -77,11 +77,11 @@ Right Aligned
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright \end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Default aligned Default aligned
\end{minipage} \\ \end{minipage} \\
\midrule \midrule()
\endhead \endhead
First & row & 12.0 & Example of a row that spans multiple lines. \\ 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. \\ Second & row & 5.0 & Here's another one. Note the blank line between rows. \\
\bottomrule \bottomrule()
\end{longtable} \end{longtable}
Multiline table without caption: Multiline table without caption:
@ -91,7 +91,7 @@ Multiline table without caption:
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1375}} >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1375}}
>{\raggedleft\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1625}} >{\raggedleft\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1625}}
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3500}}@{}} >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3500}}@{}}
\toprule \toprule()
\begin{minipage}[b]{\linewidth}\centering \begin{minipage}[b]{\linewidth}\centering
Centered Header Centered Header
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright \end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
@ -101,22 +101,22 @@ Right Aligned
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright \end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Default aligned Default aligned
\end{minipage} \\ \end{minipage} \\
\midrule \midrule()
\endhead \endhead
First & row & 12.0 & Example of a row that spans multiple lines. \\ 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. \\ Second & row & 5.0 & Here's another one. Note the blank line between rows. \\
\bottomrule \bottomrule()
\end{longtable} \end{longtable}
Table without column headers: Table without column headers:
\begin{longtable}[]{@{}rlcr@{}} \begin{longtable}[]{@{}rlcr@{}}
\toprule \toprule()
\endhead \endhead
12 & 12 & 12 & 12 \\ 12 & 12 & 12 & 12 \\
123 & 123 & 123 & 123 \\ 123 & 123 & 123 & 123 \\
1 & 1 & 1 & 1 \\ 1 & 1 & 1 & 1 \\
\bottomrule \bottomrule()
\end{longtable} \end{longtable}
Multiline table without column headers: Multiline table without column headers:
@ -126,9 +126,9 @@ Multiline table without column headers:
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1375}} >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1375}}
>{\raggedleft\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1625}} >{\raggedleft\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1625}}
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3500}}@{}} >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3500}}@{}}
\toprule \toprule()
\endhead \endhead
First & row & 12.0 & Example of a row that spans multiple lines. \\ 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. \\ Second & row & 5.0 & Here's another one. Note the blank line between rows. \\
\bottomrule \bottomrule()
\end{longtable} \end{longtable}

View file

@ -4,7 +4,7 @@
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2000}} >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2000}}
>{\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.}}\tabularnewline \caption{States belonging to the \emph{Nordics.}}\tabularnewline
\toprule \toprule()
\begin{minipage}[b]{\linewidth}\centering \begin{minipage}[b]{\linewidth}\centering
Name Name
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering \end{minipage} & \begin{minipage}[b]{\linewidth}\centering
@ -16,9 +16,9 @@ Population\\
Area\\ Area\\
(in km\textsuperscript{2})\strut (in km\textsuperscript{2})\strut
\end{minipage} \\ \end{minipage} \\
\midrule \midrule()
\endfirsthead \endfirsthead
\toprule \toprule()
\begin{minipage}[b]{\linewidth}\centering \begin{minipage}[b]{\linewidth}\centering
Name Name
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering \end{minipage} & \begin{minipage}[b]{\linewidth}\centering
@ -30,7 +30,7 @@ Population\\
Area\\ Area\\
(in km\textsuperscript{2})\strut (in km\textsuperscript{2})\strut
\end{minipage} \\ \end{minipage} \\
\midrule \midrule()
\endhead \endhead
Denmark & Copenhagen & 5,809,502 & 43,094 \\ Denmark & Copenhagen & 5,809,502 & 43,094 \\
Finland & Helsinki & 5,537,364 & 338,145 \\ Finland & Helsinki & 5,537,364 & 338,145 \\
@ -38,5 +38,5 @@ Iceland & Reykjavik & 343,518 & 103,000 \\
Norway & Oslo & 5,372,191 & 323,802 \\ Norway & Oslo & 5,372,191 & 323,802 \\
Sweden & Stockholm & 10,313,447 & 450,295 \\ Sweden & Stockholm & 10,313,447 & 450,295 \\
Total & & 27,376,022 & 1,258,336 \\ Total & & 27,376,022 & 1,258,336 \\
\bottomrule \bottomrule()
\end{longtable} \end{longtable}

View file

@ -1,16 +1,16 @@
\begin{longtable}[]{@{}cclrrrrrrrrl@{}} \begin{longtable}[]{@{}cclrrrrrrrrl@{}}
\caption{Data about the planets of our solar system.}\tabularnewline \caption{Data about the planets of our solar system.}\tabularnewline
\toprule \toprule()
\multicolumn{2}{c}{} & Name & Mass (10\^{}24kg) & Diameter (km) & Density \multicolumn{2}{c}{} & Name & Mass (10\^{}24kg) & Diameter (km) & Density
(kg/m\^{}3) & Gravity (m/s\^{}2) & Length of day (hours) & Distance from Sun (kg/m\^{}3) & Gravity (m/s\^{}2) & Length of day (hours) & Distance from Sun
(10\^{}6km) & Mean temperature (C) & Number of moons & Notes \\ (10\^{}6km) & Mean temperature (C) & Number of moons & Notes \\
\midrule \midrule()
\endfirsthead \endfirsthead
\toprule \toprule()
\multicolumn{2}{c}{} & Name & Mass (10\^{}24kg) & Diameter (km) & Density \multicolumn{2}{c}{} & Name & Mass (10\^{}24kg) & Diameter (km) & Density
(kg/m\^{}3) & Gravity (m/s\^{}2) & Length of day (hours) & Distance from Sun (kg/m\^{}3) & Gravity (m/s\^{}2) & Length of day (hours) & Distance from Sun
(10\^{}6km) & Mean temperature (C) & Number of moons & Notes \\ (10\^{}6km) & Mean temperature (C) & Number of moons & Notes \\
\midrule \midrule()
\endhead \endhead
\multicolumn{2}{c}{\multirow{4}{*}{Terrestrial planets}} & Mercury & 0.330 & \multicolumn{2}{c}{\multirow{4}{*}{Terrestrial planets}} & Mercury & 0.330 &
4,879 & 5427 & 3.7 & 4222.6 & 57.9 & 167 & 0 & Closest to the Sun \\ 4,879 & 5427 & 3.7 & 4222.6 & 57.9 & 167 & 0 & Closest to the Sun \\
@ -26,5 +26,5 @@ planet \\
& & Neptune & 102 & 49,528 & 1638 & 11.0 & 16.1 & 4495.1 & -200 & 14 & \\ & & Neptune & 102 & 49,528 & 1638 & 11.0 & 16.1 & 4495.1 & -200 & 14 & \\
\multicolumn{2}{c}{Dwarf planets} & Pluto & 0.0146 & 2,370 & 2095 & 0.7 & 153.3 \multicolumn{2}{c}{Dwarf planets} & Pluto & 0.0146 & 2,370 & 2095 & 0.7 & 153.3
& 5906.4 & -225 & 5 & Declassified as a planet in 2006. \\ & 5906.4 & -225 & 5 & Declassified as a planet in 2006. \\
\bottomrule \bottomrule()
\end{longtable} \end{longtable}

View file

@ -2,21 +2,21 @@
>{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.5000}} >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.5000}}
>{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.5000}}@{}} >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.5000}}@{}}
\caption{List of Students}\tabularnewline \caption{List of Students}\tabularnewline
\toprule \toprule()
\begin{minipage}[b]{\linewidth}\centering \begin{minipage}[b]{\linewidth}\centering
Student ID Student ID
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering \end{minipage} & \begin{minipage}[b]{\linewidth}\centering
Name Name
\end{minipage} \\ \end{minipage} \\
\midrule \midrule()
\endfirsthead \endfirsthead
\toprule \toprule()
\begin{minipage}[b]{\linewidth}\centering \begin{minipage}[b]{\linewidth}\centering
Student ID Student ID
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering \end{minipage} & \begin{minipage}[b]{\linewidth}\centering
Name Name
\end{minipage} \\ \end{minipage} \\
\midrule \midrule()
\endhead \endhead
\multicolumn{2}{l}{Computer Science} \\ \multicolumn{2}{l}{Computer Science} \\
3741255 & Jones, Martha \\ 3741255 & Jones, Martha \\
@ -27,5 +27,5 @@ Name
\multicolumn{2}{l}{Astrophysics} \\ \multicolumn{2}{l}{Astrophysics} \\
4100332 & Petrov, Alexandra \\ 4100332 & Petrov, Alexandra \\
4100332 & Toyota, Hiroko \\ 4100332 & Toyota, Hiroko \\
\bottomrule \bottomrule()
\end{longtable} \end{longtable}