1{- | 2 Module : Text.Pandoc.Writers.LaTeX.Caption 3 Copyright : Copyright (C) 2006-2021 John MacFarlane 4 License : GNU GPL, version 2 or above 5 6 Maintainer : John MacFarlane <jgm@berkeley.edu> 7 Stability : alpha 8 Portability : portable 9 10Write figure or table captions as LaTeX. 11-} 12module Text.Pandoc.Writers.LaTeX.Caption 13 ( getCaption 14 ) where 15 16import Control.Monad.State.Strict 17import Data.Monoid (Any(..)) 18import Data.Text (Text) 19import Text.Pandoc.Class.PandocMonad (PandocMonad) 20import Text.Pandoc.Definition 21import Text.DocLayout (Doc, brackets, empty) 22import Text.Pandoc.Shared 23import Text.Pandoc.Walk 24import Text.Pandoc.Writers.LaTeX.Notes (notesToLaTeX) 25import Text.Pandoc.Writers.LaTeX.Types 26 ( LW, WriterState (stExternalNotes, stNotes) ) 27 28getCaption :: PandocMonad m 29 => ([Inline] -> LW m (Doc Text)) 30 -> Bool -> [Inline] 31 -> LW m (Doc Text, Doc Text, Doc Text) 32getCaption inlineListToLaTeX externalNotes txt = do 33 oldExternalNotes <- gets stExternalNotes 34 modify $ \st -> st{ stExternalNotes = externalNotes, stNotes = [] } 35 capt <- inlineListToLaTeX txt 36 footnotes <- if externalNotes 37 then notesToLaTeX <$> gets stNotes 38 else return empty 39 modify $ \st -> st{ stExternalNotes = oldExternalNotes, stNotes = [] } 40 -- We can't have footnotes in the list of figures/tables, so remove them: 41 let getNote (Note _) = Any True 42 getNote _ = Any False 43 let hasNotes = getAny . query getNote 44 captForLof <- if hasNotes txt 45 then brackets <$> inlineListToLaTeX (walk deNote txt) 46 else return empty 47 return (capt, captForLof, footnotes) 48