@@ -20,6 +20,7 @@ module Text.Pandoc.Writers.LaTeX (
2020import Prelude
2121import Control.Applicative ((<|>))
2222import Control.Monad.State.Strict
23+import Data.Monoid (Any(..))
2324import Data.Aeson (FromJSON, object, (.=))
2425import Data.Char (isAlphaNum, isAscii, isDigit, isLetter, isSpace,
2526 isPunctuation, ord, toLower)
@@ -792,7 +793,7 @@ blockToLaTeX (Header level (id',classes,_) lst) = do
792793 modify $ \s -> s{stInHeading = False}
793794 return hdr
794795blockToLaTeX (Table caption aligns widths heads rows) = do
795− (captionText, captForLof, footnotes) <- getCaption False caption
796+ (captionText, captForLof, captNotes) <- getCaption False caption
796797 let toHeaders hs = do contents <- tableRowToLaTeX True aligns widths hs
797798 return ("\\toprule" $$ contents $$ "\\midrule")
798799 let removeNote (Note _) = Span ("", [], []) []
@@ -813,6 +814,7 @@ blockToLaTeX (Table caption aligns widths heads rows) = do
813814 rows' <- mapM (tableRowToLaTeX False aligns widths) rows
814815 let colDescriptors = text $ concatMap toColDescriptor aligns
815816 modify $ \s -> s{ stTable = True }
817+ notes <- notesToLaTeX <$> gets stNotes
816818 return $ "\\begin{longtable}[]" <>
817819 braces ("@{}" <> colDescriptors <> "@{}")
818820 -- the @{} removes extra space at beginning and end
@@ -823,22 +825,25 @@ blockToLaTeX (Table caption aligns widths heads rows) = do
823825 $$ vcat rows'
824826 $$ "\\bottomrule"
825827 $$ "\\end{longtable}"
826− $$ footnotes
828+ $$ captNotes
829+ $$ notes
827830
828831getCaption :: PandocMonad m => Bool -> [Inline] -> LW m (Doc, Doc, Doc)
829832getCaption externalNotes txt = do
830833 oldExternalNotes <- gets stExternalNotes
831834 modify $ \st -> st{ stExternalNotes = externalNotes, stNotes = [] }
832835 capt <- inlineListToLaTeX txt
833− notes <- gets stNotes
834836 modify $ \st -> st{ stExternalNotes = oldExternalNotes, stNotes = [] }
835837 -- We can't have footnotes in the list of figures/tables, so remove them:
836− captForLof <- if null notes
837− then return empty
838− else brackets <$> inlineListToLaTeX (walk deNote txt)
839− let footnotes = if externalNotes
840− then notesToLaTeX notes
841− else empty
838+ let getNote (Note _) = Any True
839+ getNote _ = Any False
840+ let hasNotes = getAny . query getNote
841+ captForLof <- if hasNotes txt
842+ then brackets <$> inlineListToLaTeX (walk deNote txt)
843+ else return empty
844+ footnotes <- if externalNotes
845+ then notesToLaTeX <$> gets stNotes
846+ else return empty
842847 return (capt, captForLof, footnotes)
843848
844849toColDescriptor :: Alignment -> String
@@ -1300,12 +1305,12 @@ inlineToLaTeX (Note contents) = do
13001305 let beamerMark = if beamer
13011306 then text "<.->"
13021307 else empty
1303− modify $ \st -> st{ stNotes = noteContents : stNotes st }
1304− return $
1305− if externalNotes
1306− then "\\footnotemark{}"
1308+ if externalNotes
1309+ then do
1310+ modify $ \st -> st{ stNotes = noteContents : stNotes st }
1311+ return "\\footnotemark{}"
13071312 -- note: a \n before } needed when note ends with a Verbatim environment
1308− else "\\footnote" <> beamerMark <> braces noteContents
1313+ else return $ "\\footnote" <> beamerMark <> braces noteContents
13091314
13101315-- A comment at the end of math needs to be followed by a newline,
13111316-- or the closing delimiter gets swallowed.