git.iko.soy/typeable/pandoc
on master help sign in
Fixed footnotes in table captions.

Note that if the table has a first page header and a continuation page header, the notes will appear only on the first occurrence of the header. Closes #2378.

commit6a077ac9c79ac16d6af5409976e48ad80f42fd01 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 20 Jun 2017, 11:21 (9 years ago) parent8af1c06
2 files changed+45−16
src/Text/Pandoc/Writers/LaTeX.hs+18−16 test/command/2378.md+27
src/Text/Pandoc/Writers/LaTeX.hs+18−16
@@ -647,23 +647,25 @@ blockToLaTeX (Header level (id',classes,_) lst) = do
647647 modify $ \s -> s{stInHeading = False}
648648 return hdr
649649blockToLaTeX (Table caption aligns widths heads rows) = do
650− headers <- if all null heads
651− then return empty
652− else do
653− contents <- (tableRowToLaTeX True aligns widths) heads
654− return ("\\toprule" $$ contents $$ "\\midrule")
655− let endhead = if all null heads
656− then empty
657− else text "\\endhead"
658− let endfirsthead = if all null heads
659− then empty
660− else text "\\endfirsthead"
650+ let toHeaders hs = do contents <- (tableRowToLaTeX True aligns widths) hs
651+ return ("\\toprule" $$ contents $$ "\\midrule")
652+ let removeNote (Note _) = Span ("", [], []) []
653+ removeNote x = x
661654 captionText <- inlineListToLaTeX caption
655+ firsthead <- if isEmpty captionText || all null heads
656+ then return empty
657+ else ($$ text "\\endfirsthead") <$> toHeaders heads
658+ head' <- if all null heads
659+ then return empty
660+ -- avoid duplicate notes in head and firsthead:
661+ else ($$ text "\\endhead") <$>
662+ toHeaders (if isEmpty firsthead
663+ then heads
664+ else walk removeNote heads)
662665 let capt = if isEmpty captionText
663666 then empty
664− else text "\\caption" <> braces captionText <> "\\tabularnewline"
665− $$ headers
666− $$ endfirsthead
667+ else text "\\caption" <>
668+ braces captionText <> "\\tabularnewline"
667669 rows' <- mapM (tableRowToLaTeX False aligns widths) rows
668670 let colDescriptors = text $ concat $ map toColDescriptor aligns
669671 modify $ \s -> s{ stTable = True }
@@ -671,9 +673,9 @@ blockToLaTeX (Table caption aligns widths heads rows) = do
671673 braces ("@{}" <> colDescriptors <> "@{}")
672674 -- the @{} removes extra space at beginning and end
673675 $$ capt
676+ $$ firsthead
674677 $$ (if all null heads then "\\toprule" else empty)
675− $$ headers
676− $$ endhead
678+ $$ head'
677679 $$ vcat rows'
678680 $$ "\\bottomrule"
679681 $$ "\\end{longtable}"
test/command/2378.mdnew file+27
@@ -0,0 +1,27 @@
1+Ensure that we don't get duplicated footnotes when
2+a note occurs in a header cell and `\endfirsthead`
3+is used.
4+
5+```
6+% pandoc -t latex
7+| x | y[^fn] |
8+|-|-|
9+|1|2|
10+: a table
11+
12+[^fn]: a footnote
13+^D
14+\begin{longtable}[]{@{}ll@{}}
15+\caption{a table}\tabularnewline
16+\toprule
17+x & y\footnote{a footnote}\tabularnewline
18+\midrule
19+\endfirsthead
20+\toprule
21+x & y{}\tabularnewline
22+\midrule
23+\endhead
24+1 & 2\tabularnewline
25+\bottomrule
26+\end{longtable}
27+```