diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2009-12-31 21:18:36 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2009-12-31 21:18:36 +0000 |
commit | bdd448ea2cf41324a63bd09771b5ac553e65f540 (patch) | |
tree | 694c12cce932a0a9ac04e7c8c6893a8cf667ced9 | |
parent | 07fe1aedd0d3b393d7cc82c8aa81b309e6eab956 (diff) | |
download | pandoc-bdd448ea2cf41324a63bd09771b5ac553e65f540.tar.gz |
LaTeX writer: Only require listings package if needed.
That is, if literate Haskell code is used.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1759 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 9 | ||||
-rw-r--r-- | templates/latex.template | 2 | ||||
-rw-r--r-- | tests/lhs-test.latex | 2 | ||||
-rw-r--r-- | tests/writer.latex | 2 |
4 files changed, 9 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 1c8604c8a..b9e7e42a8 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -49,6 +49,7 @@ data WriterState = , stLink :: Bool -- true if document has links , stUrl :: Bool -- true if document has visible URL link , stGraphics :: Bool -- true if document contains images + , stLHS :: Bool -- true if document has literate haskell code } -- | Convert Pandoc to LaTeX. @@ -58,7 +59,8 @@ writeLaTeX options document = WriterState { stInNote = False, stOLLevel = 1, stOptions = options, stVerbInNote = False, stEnumerate = False, stTable = False, stStrikeout = False, stSubscript = False, - stLink = False, stUrl = False, stGraphics = False } + stLink = False, stUrl = False, stGraphics = False, + stLHS = False } pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do @@ -88,6 +90,7 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do [ ("subscript", "yes") | stSubscript st ] ++ [ ("links", "yes") | stLink st ] ++ [ ("url", "yes") | stUrl st ] ++ + [ ("lhs", "yes") | stLHS st ] ++ [ ("graphics", "yes") | stGraphics st ] return $ if writerStandalone options then renderTemplate context $ writerTemplate options @@ -139,7 +142,9 @@ blockToLaTeX (CodeBlock (_,classes,_) str) = do st <- get env <- if writerLiterateHaskell (stOptions st) && "haskell" `elem` classes && "literate" `elem` classes - then return "code" + then do + modify $ \s -> s{ stLHS = True } + return "code" else if stInNote st then do modify $ \s -> s{ stVerbInNote = True } diff --git a/templates/latex.template b/templates/latex.template index 5441694cf..8b2dfa8c0 100644 --- a/templates/latex.template +++ b/templates/latex.template @@ -9,8 +9,10 @@ $else$ \usepackage[mathletters]{ucs} \usepackage[utf8x]{inputenc} $endif$ +$if(lhs)$ \usepackage{listings} \lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{} +$endif$ \setlength{\parindent}{0pt} \setlength{\parskip}{6pt plus 2pt minus 1pt} $endif$ diff --git a/tests/lhs-test.latex b/tests/lhs-test.latex index 776e9c46f..2c4dd6e0f 100644 --- a/tests/lhs-test.latex +++ b/tests/lhs-test.latex @@ -2,8 +2,6 @@ \usepackage{amsmath} \usepackage[mathletters]{ucs} \usepackage[utf8x]{inputenc} -\usepackage{listings} -\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{} \setlength{\parindent}{0pt} \setlength{\parskip}{6pt plus 2pt minus 1pt} \setcounter{secnumdepth}{0} diff --git a/tests/writer.latex b/tests/writer.latex index b5b58721d..5b9c08126 100644 --- a/tests/writer.latex +++ b/tests/writer.latex @@ -2,8 +2,6 @@ \usepackage{amsmath} \usepackage[mathletters]{ucs} \usepackage[utf8x]{inputenc} -\usepackage{listings} -\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{} \setlength{\parindent}{0pt} \setlength{\parskip}{6pt plus 2pt minus 1pt} \usepackage{fancyvrb} |