@@ -38,17 +38,22 @@ import Data.Char ( isAlphaNum )
3838import qualified Data.Set as S
3939import Control.Monad.State
4040
41−type WriterState = S.Set String -- set of strings to include in header
42− -- constructed based on content of document
41+data WriterState =
42+ WriterState { stIncludes :: S.Set String -- strings to include in header
43+ , stInNote :: Bool } -- @True@ if we're in a note
4344
4445-- | Add line to header.
4546addToHeader :: String -> State WriterState ()
46−addToHeader str = modify (S.insert str)
47+addToHeader str = do
48+ st <- get
49+ let includes = stIncludes st
50+ put st {stIncludes = S.insert str includes}
4751
4852-- | Convert Pandoc to LaTeX.
4953writeLaTeX :: WriterOptions -> Pandoc -> String
5054writeLaTeX options document =
51− evalState (pandocToLaTeX options document) S.empty
55+ evalState (pandocToLaTeX options document) $
56+ WriterState { stIncludes = S.empty, stInNote = False }
5257
5358pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
5459pandocToLaTeX options (Pandoc meta blocks) = do
@@ -75,7 +80,10 @@ latexHeader options (Meta title authors date) = do
7580 then return ""
7681 else do title' <- inlineListToLaTeX title
7782 return $ "\\title{" ++ title' ++ "}\n"
78− extras <- get >>= (return . unlines . S.toList)
83+ extras <- get >>= (return . unlines . S.toList. stIncludes)
84+ let verbatim = if "\\usepackage{fancyvrb}" `isInfixOf` extras
85+ then "\\VerbatimFootnotes % allows verbatim text in footnotes\n"
86+ else ""
7987 let authorstext = "\\author{" ++ (joinWithSep "\\\\"
8088 (map stringToLaTeX authors)) ++ "}\n"
8189 let datetext = if date == ""
@@ -87,7 +95,7 @@ latexHeader options (Meta title authors date) = do
8795 else "\\setcounter{secnumdepth}{0}\n"
8896 let baseHeader = writerHeader options
8997 let header = baseHeader ++ extras
90− return $ header ++ secnumline ++ titletext ++ authorstext ++
98+ return $ header ++ secnumline ++ verbatim ++ titletext ++ authorstext ++
9199 datetext ++ "\\begin{document}\n" ++ maketitle ++ "\n"
92100
93101-- escape things as needed for LaTeX
@@ -120,8 +128,11 @@ blockToLaTeX (Para lst) = (inlineListToLaTeX lst) >>= (return . (++ "\n\n"))
120128blockToLaTeX (BlockQuote lst) = do
121129 contents <- blockListToLaTeX lst
122130 return $ "\\begin{quote}\n" ++ contents ++ "\\end{quote}\n"
123−blockToLaTeX (CodeBlock str) = return $
124− "\\begin{verbatim}\n" ++ str ++ "\n\\end{verbatim}\n"
131+blockToLaTeX (CodeBlock str) = do
132+ st <- get
133+ let verbEnv = if stInNote st then "Verbatim" else "verbatim"
134+ return $ "\\begin{" ++ verbEnv ++ "}\n" ++ str ++
135+ "\n\\end{" ++ verbEnv ++ "}\n"
125136blockToLaTeX (RawHtml str) = return ""
126137blockToLaTeX (BulletList lst) = do
127138 items <- mapM listItemToLaTeX lst
@@ -243,6 +254,10 @@ inlineToLaTeX (Image alternate (source, tit)) = do
243254 addToHeader "\\usepackage{graphicx}"
244255 return $ "\\includegraphics{" ++ source ++ "}"
245256inlineToLaTeX (Note contents) = do
257+ st <- get
258+ put (st {stInNote = True})
246259 contents' <- blockListToLaTeX contents
260+ st <- get
261+ put (st {stInNote = False})
262+ addToHeader "\\usepackage{fancyvrb}"
247263 return $ "\\footnote{" ++ stripTrailingNewlines contents' ++ "}"
248−