git.iko.soy/typeable/pandoc
on master help sign in
Fixed footnotes in table captions.
6a077acJohn MacFarlane
src/Text/Pandoc/Writers/LaTeX.hs+18−16
@@ -647,23 +647,25 @@ blockToLaTeX (Header level (id',classes,_) lst) = do
647 modify $ \s -> s{stInHeading = False}
647 modify $ \s -> s{stInHeading = False}
648 return hdr
648 return hdr
649blockToLaTeX (Table caption aligns widths heads rows) = do
649blockToLaTeX (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
650+ let toHeaders hs = do contents <- (tableRowToLaTeX True aligns widths) hs
654− return ("\\toprule" $$ contents $$ "\\midrule")
651+ return ("\\toprule" $$ contents $$ "\\midrule")
655− let endhead = if all null heads
652+ let removeNote (Note _) = Span ("", [], []) []
656− then empty
653+ removeNote x = x
657− else text "\\endhead"
658− let endfirsthead = if all null heads
659− then empty
660− else text "\\endfirsthead"
661 captionText <- inlineListToLaTeX caption
654 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)
662 let capt = if isEmpty captionText
665 let capt = if isEmpty captionText
663 then empty
666 then empty
667+ else text "\\caption" <>
664− else text "\\caption" <> braces captionText <> "\\tabularnewline"
668+ braces captionText <> "\\tabularnewline"
665− $$ headers
666− $$ endfirsthead
667 rows' <- mapM (tableRowToLaTeX False aligns widths) rows
669 rows' <- mapM (tableRowToLaTeX False aligns widths) rows
668 let colDescriptors = text $ concat $ map toColDescriptor aligns
670 let colDescriptors = text $ concat $ map toColDescriptor aligns
669 modify $ \s -> s{ stTable = True }
671 modify $ \s -> s{ stTable = True }
@@ -671,9 +673,9 @@ blockToLaTeX (Table caption aligns widths heads rows) = do
671 braces ("@{}" <> colDescriptors <> "@{}")
673 braces ("@{}" <> colDescriptors <> "@{}")
672 -- the @{} removes extra space at beginning and end
674 -- the @{} removes extra space at beginning and end
673 $$ capt
675 $$ capt
676+ $$ firsthead
674 $$ (if all null heads then "\\toprule" else empty)
677 $$ (if all null heads then "\\toprule" else empty)
675− $$ headers
678+ $$ head'
676− $$ endhead
677 $$ vcat rows'
679 $$ vcat rows'
678 $$ "\\bottomrule"
680 $$ "\\bottomrule"
679 $$ "\\end{longtable}"
681 $$ "\\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+```