git.iko.soy/typeable/pandoc
on master help sign in
Fix footnote in image caption.

Regression! The fix for #4683 broke this case.

commita20323033ee0a718fc18ec2db00c913369944e29 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 1 May 2019, 16:56 (8 years ago) parent4a7f5b6
2 files changed+28−10
src/Text/Pandoc/Writers/LaTeX.hs+16−10 test/command/5476.md+12
src/Text/Pandoc/Writers/LaTeX.hs+16−10
@@ -54,6 +54,7 @@ data WriterState =
5454 , stInQuote :: Bool -- true if in a blockquote
5555 , stExternalNotes :: Bool -- true if in context where
5656 -- we need to store footnotes
57+ , stInMinipage :: Bool -- true if in minipage
5758 , stInHeading :: Bool -- true if in a section heading
5859 , stInItem :: Bool -- true if in \item[..]
5960 , stNotes :: [Doc] -- notes in a minipage
@@ -80,6 +81,7 @@ startingState options = WriterState {
8081 , stInQuote = False
8182 , stExternalNotes = False
8283 , stInHeading = False
84+ , stInMinipage = False
8385 , stInItem = False
8486 , stNotes = []
8587 , stOLLevel = 1
@@ -608,11 +610,12 @@ blockToLaTeX (Para [Image attr@(ident, _, _) txt (src,'f':'i':'g':':':tit)]) = d
608610 "\\centering" $$ img $$ caption <> cr
609611 let figure = cr <> "\\begin{figure}" $$ innards $$ "\\end{figure}"
610612 st <- get
611− return $ if stExternalNotes st
612− -- can't have figures in notes or minipage (here, table cell)
613− -- http://www.tex.ac.uk/FAQ-ouparmd.html
614− then "\\begin{center}" $$ img $+$ capt $$ "\\end{center}"
615− else figure $$ footnotes
613+ return $ (if stInMinipage st
614+ -- can't have figures in notes or minipage (here, table cell)
615+ -- http://www.tex.ac.uk/FAQ-ouparmd.html
616+ then cr <> "\\begin{center}" $$ img $+$ capt $$
617+ "\\end{center}"
618+ else figure) $$ footnotes
616619-- . . . indicates pause in beamer slides
617620blockToLaTeX (Para [Str ".",Space,Str ".",Space,Str "."]) = do
618621 beamer <- gets stBeamer
@@ -833,6 +836,9 @@ getCaption externalNotes txt = do
833836 oldExternalNotes <- gets stExternalNotes
834837 modify $ \st -> st{ stExternalNotes = externalNotes, stNotes = [] }
835838 capt <- inlineListToLaTeX txt
839+ footnotes <- if externalNotes
840+ then notesToLaTeX <$> gets stNotes
841+ else return empty
836842 modify $ \st -> st{ stExternalNotes = oldExternalNotes, stNotes = [] }
837843 -- We can't have footnotes in the list of figures/tables, so remove them:
838844 let getNote (Note _) = Any True
@@ -841,9 +847,6 @@ getCaption externalNotes txt = do
841847 captForLof <- if hasNotes txt
842848 then brackets <$> inlineListToLaTeX (walk deNote txt)
843849 else return empty
844− footnotes <- if externalNotes
845− then notesToLaTeX <$> gets stNotes
846− else return empty
847850 return (capt, captForLof, footnotes)
848851
849852toColDescriptor :: Alignment -> String
@@ -911,11 +914,14 @@ tableCellToLaTeX _ (0, _, blocks) =
911914tableCellToLaTeX header (width, align, blocks) = do
912915 beamer <- gets stBeamer
913916 externalNotes <- gets stExternalNotes
917+ inMinipage <- gets stInMinipage
914918 -- See #5367 -- footnotehyper/footnote don't work in beamer,
915919 -- so we need to produce the notes outside the table...
916− modify $ \st -> st{ stExternalNotes = beamer }
920+ modify $ \st -> st{ stExternalNotes = beamer,
921+ stInMinipage = True }
917922 cellContents <- blockListToLaTeX blocks
918− modify $ \st -> st{ stExternalNotes = externalNotes }
923+ modify $ \st -> st{ stExternalNotes = externalNotes,
924+ stInMinipage = inMinipage }
919925 let valign = text $ if header then "[b]" else "[t]"
920926 let halign = case align of
921927 AlignLeft -> "\\raggedright"
test/command/5476.mdnew file+12
@@ -0,0 +1,12 @@
1+```
2+% pandoc -t latex
3+![moon^[the moon]](test/lalune.jpg)
4+^D
5+\begin{figure}
6+\centering
7+\includegraphics{test/lalune.jpg}
8+\caption[moon]{moon\footnotemark{}}
9+\end{figure}
10+\footnotetext{the moon}
11+```
12+