LaTeX writer: Fix footnotes in table caption and cells.
This fixes a bug wherein footnotes appeared in the wrong order, and with duplicate numbers, when in table captions and cells. We now use regular `\footnote` commands, even in the table caption and the minipages containing cells. Apparently longtable knows how to handle this. Closes #5367.
This commit is contained in:
parent
97acf152e0
commit
1e60776226
2 changed files with 55 additions and 13 deletions
|
@ -590,7 +590,7 @@ blockToLaTeX (Plain lst) =
|
|||
inlineListToLaTeX $ dropWhile isLineBreakOrSpace lst
|
||||
-- title beginning with fig: indicates that the image is a figure
|
||||
blockToLaTeX (Para [Image attr@(ident, _, _) txt (src,'f':'i':'g':':':tit)]) = do
|
||||
(capt, captForLof, footnotes) <- getCaption txt
|
||||
(capt, captForLof, footnotes) <- getCaption True txt
|
||||
lab <- labelFor ident
|
||||
let caption = "\\caption" <> captForLof <> braces capt <> lab
|
||||
img <- inlineToLaTeX (Image attr txt (src,tit))
|
||||
|
@ -783,7 +783,7 @@ blockToLaTeX (Header level (id',classes,_) lst) = do
|
|||
modify $ \s -> s{stInHeading = False}
|
||||
return hdr
|
||||
blockToLaTeX (Table caption aligns widths heads rows) = do
|
||||
(captionText, captForLof, footnotes) <- getCaption caption
|
||||
(captionText, captForLof, footnotes) <- getCaption False caption
|
||||
let toHeaders hs = do contents <- tableRowToLaTeX True aligns widths hs
|
||||
return ("\\toprule" $$ contents $$ "\\midrule")
|
||||
let removeNote (Note _) = Span ("", [], []) []
|
||||
|
@ -816,18 +816,20 @@ blockToLaTeX (Table caption aligns widths heads rows) = do
|
|||
$$ "\\end{longtable}"
|
||||
$$ footnotes
|
||||
|
||||
getCaption :: PandocMonad m => [Inline] -> LW m (Doc, Doc, Doc)
|
||||
getCaption txt = do
|
||||
inMinipage <- gets stInMinipage
|
||||
modify $ \st -> st{ stInMinipage = True, stNotes = [] }
|
||||
getCaption :: PandocMonad m => Bool -> [Inline] -> LW m (Doc, Doc, Doc)
|
||||
getCaption externalNotes txt = do
|
||||
oldIsMinipage <- gets stInMinipage
|
||||
modify $ \st -> st{ stInMinipage = externalNotes, stNotes = [] }
|
||||
capt <- inlineListToLaTeX txt
|
||||
notes <- gets stNotes
|
||||
modify $ \st -> st{ stInMinipage = inMinipage, stNotes = [] }
|
||||
modify $ \st -> st{ stInMinipage = oldIsMinipage, stNotes = [] }
|
||||
-- We can't have footnotes in the list of figures/tables, so remove them:
|
||||
captForLof <- if null notes
|
||||
then return empty
|
||||
else brackets <$> inlineListToLaTeX (walk deNote txt)
|
||||
let footnotes = notesToLaTeX notes
|
||||
let footnotes = if externalNotes
|
||||
then notesToLaTeX notes
|
||||
else empty
|
||||
return (capt, captForLof, footnotes)
|
||||
|
||||
toColDescriptor :: Alignment -> String
|
||||
|
@ -893,10 +895,7 @@ tableCellToLaTeX :: PandocMonad m => Bool -> (Double, Alignment, [Block])
|
|||
tableCellToLaTeX _ (0, _, blocks) =
|
||||
blockListToLaTeX $ walk fixLineBreaks $ walk displayMathToInline blocks
|
||||
tableCellToLaTeX header (width, align, blocks) = do
|
||||
modify $ \st -> st{ stInMinipage = True, stNotes = [] }
|
||||
cellContents <- blockListToLaTeX blocks
|
||||
notes <- gets stNotes
|
||||
modify $ \st -> st{ stInMinipage = False, stNotes = [] }
|
||||
let valign = text $ if header then "[b]" else "[t]"
|
||||
let halign = case align of
|
||||
AlignLeft -> "\\raggedright"
|
||||
|
@ -906,8 +905,7 @@ tableCellToLaTeX header (width, align, blocks) = do
|
|||
return $ ("\\begin{minipage}" <> valign <>
|
||||
braces (text (printf "%.2f\\columnwidth" width)) <>
|
||||
(halign <> cr <> cellContents <> "\\strut" <> cr) <>
|
||||
"\\end{minipage}") $$
|
||||
notesToLaTeX notes
|
||||
"\\end{minipage}")
|
||||
|
||||
notesToLaTeX :: [Doc] -> Doc
|
||||
notesToLaTeX [] = empty
|
||||
|
|
44
test/command/5367.md
Normal file
44
test/command/5367.md
Normal file
|
@ -0,0 +1,44 @@
|
|||
```
|
||||
% pandoc -t latex
|
||||
hello[^1]
|
||||
|
||||
: Sample table.[^2]
|
||||
|
||||
-----------
|
||||
Fruit[^3]
|
||||
-----------
|
||||
Bans[^4]
|
||||
-----------
|
||||
|
||||
dolly[^5]
|
||||
|
||||
[^1]: doc footnote
|
||||
[^2]: caption footnote
|
||||
[^3]: header footnote
|
||||
[^4]: table cell footnote
|
||||
[^5]: doc footnote
|
||||
^D
|
||||
hello\footnote{doc footnote}
|
||||
|
||||
\begin{longtable}[]{@{}c@{}}
|
||||
\caption[Sample table.]{Sample table.\footnote{caption footnote}}\tabularnewline
|
||||
\toprule
|
||||
\begin{minipage}[b]{0.16\columnwidth}\centering
|
||||
Fruit\footnote{header footnote}\strut
|
||||
\end{minipage}\tabularnewline
|
||||
\midrule
|
||||
\endfirsthead
|
||||
\toprule
|
||||
\begin{minipage}[b]{0.16\columnwidth}\centering
|
||||
Fruit{}\strut
|
||||
\end{minipage}\tabularnewline
|
||||
\midrule
|
||||
\endhead
|
||||
\begin{minipage}[t]{0.16\columnwidth}\centering
|
||||
Bans\footnote{table cell footnote}\strut
|
||||
\end{minipage}\tabularnewline
|
||||
\bottomrule
|
||||
\end{longtable}
|
||||
|
||||
dolly\footnote{doc footnote}
|
||||
```
|
Loading…
Reference in a new issue