diff options
| author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2010-01-03 08:47:54 +0000 | 
|---|---|---|
| committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2010-01-03 08:47:54 +0000 | 
| commit | e91cb556d298e9191ce3d23c8cc878e5b733621b (patch) | |
| tree | 072a728f31ffaf78e402f54fc33d5d52656a4a0c /src | |
| parent | af46691a209dad112754fb99810f1abb17971371 (diff) | |
| download | pandoc-e91cb556d298e9191ce3d23c8cc878e5b733621b.tar.gz | |
LaTeX writer: if book, report, or memoir documentclass, use \chapter{}
for first-level headers. Otherwise use \section{}.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1793 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 28 | 
1 files changed, 21 insertions, 7 deletions
| diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index b9e7e42a8..4ce2b44d1 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -32,7 +32,7 @@ import Text.Pandoc.Definition  import Text.Pandoc.Shared  import Text.Pandoc.Templates  import Text.Printf ( printf ) -import Data.List ( (\\), isSuffixOf, intersperse ) +import Data.List ( (\\), isSuffixOf, isPrefixOf, intersperse )  import Data.Char ( toLower )  import Control.Monad.State  import Text.PrettyPrint.HughesPJ hiding ( Str ) @@ -50,6 +50,7 @@ data WriterState =                , 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 +              , stBook       :: Bool          -- true if document uses book or memoir class                }  -- | Convert Pandoc to LaTeX. @@ -60,10 +61,16 @@ writeLaTeX options document =                  stVerbInNote = False, stEnumerate = False,                  stTable = False, stStrikeout = False, stSubscript = False,                  stLink = False, stUrl = False, stGraphics = False, -                stLHS = False }  +                stLHS = False, stBook = False }   pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String  pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do +  let template = writerTemplate options +  let usesBookClass x = "\\documentclass" `isPrefixOf` x && +         ("{memoir}" `isSuffixOf` x || "{book}" `isSuffixOf` x || +          "{report}" `isSuffixOf` x) +  when (any usesBookClass (lines template)) $ +    modify $ \s -> s{stBook = True}    titletext <- liftM render $ inlineListToLaTeX title    authorsText <- mapM (liftM render . inlineListToLaTeX) authors    dateText <- liftM render $ inlineListToLaTeX date @@ -93,7 +100,7 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do                   [ ("lhs", "yes") | stLHS st ] ++                   [ ("graphics", "yes") | stGraphics st ]    return $ if writerStandalone options -              then renderTemplate context $ writerTemplate options +              then renderTemplate context template                else main  -- escape things as needed for LaTeX @@ -195,10 +202,17 @@ blockToLaTeX (Header level lst) = do                   else do                     res <- inlineListToLaTeX lstNoNotes                     return $ char '[' <> res <> char ']' -  return $ if (level > 0) && (level <= 3) -              then text ("\\" ++ (concat (replicate (level - 1) "sub")) ++  -                   "section") <> optional <> char '{' <> txt <> text "}\n" -              else txt <> char '\n' +  let stuffing = optional <> char '{' <> txt <> char '}' +  book <- liftM stBook get +  return $ case (book, level) of +                (True, 1)    -> text "\\chapter" <> stuffing <> char '\n' +                (True, 2)    -> text "\\section" <> stuffing <> char '\n' +                (True, 3)    -> text "\\subsection" <> stuffing <> char '\n' +                (True, 4)    -> text "\\subsubsection" <> stuffing <> char '\n' +                (False, 1)   -> text "\\section" <> stuffing <> char '\n' +                (False, 2)   -> text "\\subsection" <> stuffing <> char '\n' +                (False, 3)   -> text "\\subsubsection" <> stuffing <> char '\n' +                _            -> txt <> char '\n'   blockToLaTeX (Table caption aligns widths heads rows) = do    headers <- tableRowToLaTeX heads    captionText <- inlineListToLaTeX caption | 
