From 1e6077622635b6536ec10c8c67651ef0f4901cff Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 22 Mar 2019 11:55:41 -0700 Subject: 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. --- src/Text/Pandoc/Writers/LaTeX.hs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index bee68bd53..0ef04db3f 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -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 -- cgit v1.2.3