summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers/LaTeX.hs
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-07-28 01:40:48 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-07-28 01:40:48 +0000
commitd488dd0f66e14a7728873f31d80b51bab625b442 (patch)
tree8794e67a838e6aaa9c5c37dedb9e17b0b2a7ce00 /src/Text/Pandoc/Writers/LaTeX.hs
parentb29f221cba949934dda402f96b1606cda8ed73a6 (diff)
Reinstated dependence on fancyvrb. It is compatible with examplep.
fancyvrb is needed for verbatim environments in footnotes. git-svn-id: https://pandoc.googlecode.com/svn/trunk@808 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text/Pandoc/Writers/LaTeX.hs')
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index c9c923dae..2d74b9ffa 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -38,17 +38,22 @@ import Data.Char ( isAlphaNum )
import qualified Data.Set as S
import Control.Monad.State
-type WriterState = S.Set String -- set of strings to include in header
- -- constructed based on content of document
+data WriterState =
+ WriterState { stIncludes :: S.Set String -- strings to include in header
+ , stInNote :: Bool } -- @True@ if we're in a note
-- | Add line to header.
addToHeader :: String -> State WriterState ()
-addToHeader str = modify (S.insert str)
+addToHeader str = do
+ st <- get
+ let includes = stIncludes st
+ put st {stIncludes = S.insert str includes}
-- | Convert Pandoc to LaTeX.
writeLaTeX :: WriterOptions -> Pandoc -> String
writeLaTeX options document =
- evalState (pandocToLaTeX options document) S.empty
+ evalState (pandocToLaTeX options document) $
+ WriterState { stIncludes = S.empty, stInNote = False }
pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
pandocToLaTeX options (Pandoc meta blocks) = do
@@ -75,7 +80,10 @@ latexHeader options (Meta title authors date) = do
then return ""
else do title' <- inlineListToLaTeX title
return $ "\\title{" ++ title' ++ "}\n"
- extras <- get >>= (return . unlines . S.toList)
+ extras <- get >>= (return . unlines . S.toList. stIncludes)
+ let verbatim = if "\\usepackage{fancyvrb}" `isInfixOf` extras
+ then "\\VerbatimFootnotes % allows verbatim text in footnotes\n"
+ else ""
let authorstext = "\\author{" ++ (joinWithSep "\\\\"
(map stringToLaTeX authors)) ++ "}\n"
let datetext = if date == ""
@@ -87,7 +95,7 @@ latexHeader options (Meta title authors date) = do
else "\\setcounter{secnumdepth}{0}\n"
let baseHeader = writerHeader options
let header = baseHeader ++ extras
- return $ header ++ secnumline ++ titletext ++ authorstext ++
+ return $ header ++ secnumline ++ verbatim ++ titletext ++ authorstext ++
datetext ++ "\\begin{document}\n" ++ maketitle ++ "\n"
-- escape things as needed for LaTeX
@@ -120,8 +128,11 @@ blockToLaTeX (Para lst) = (inlineListToLaTeX lst) >>= (return . (++ "\n\n"))
blockToLaTeX (BlockQuote lst) = do
contents <- blockListToLaTeX lst
return $ "\\begin{quote}\n" ++ contents ++ "\\end{quote}\n"
-blockToLaTeX (CodeBlock str) = return $
- "\\begin{verbatim}\n" ++ str ++ "\n\\end{verbatim}\n"
+blockToLaTeX (CodeBlock str) = do
+ st <- get
+ let verbEnv = if stInNote st then "Verbatim" else "verbatim"
+ return $ "\\begin{" ++ verbEnv ++ "}\n" ++ str ++
+ "\n\\end{" ++ verbEnv ++ "}\n"
blockToLaTeX (RawHtml str) = return ""
blockToLaTeX (BulletList lst) = do
items <- mapM listItemToLaTeX lst
@@ -243,6 +254,10 @@ inlineToLaTeX (Image alternate (source, tit)) = do
addToHeader "\\usepackage{graphicx}"
return $ "\\includegraphics{" ++ source ++ "}"
inlineToLaTeX (Note contents) = do
+ st <- get
+ put (st {stInNote = True})
contents' <- blockListToLaTeX contents
+ st <- get
+ put (st {stInNote = False})
+ addToHeader "\\usepackage{fancyvrb}"
return $ "\\footnote{" ++ stripTrailingNewlines contents' ++ "}"
-