git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: recognize book documentclass if set in metadata.
8e404aaJohn MacFarlane
src/Text/Pandoc/Writers/LaTeX.hs+10−8
@@ -42,6 +42,7 @@ import Data.List ( (\\), isSuffixOf, isInfixOf, stripPrefix,
42 isPrefixOf, intercalate, intersperse )
42 isPrefixOf, intercalate, intersperse )
43import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
43import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
44import Data.Maybe ( fromMaybe )
44import Data.Maybe ( fromMaybe )
45+import Data.Aeson.Types ( (.:), parseMaybe, withObject )
45import Control.Applicative ((<|>))
46import Control.Applicative ((<|>))
46import Control.Monad.State
47import Control.Monad.State
47import Text.Pandoc.Pretty
48import Text.Pandoc.Pretty
@@ -102,8 +103,16 @@ pandocToLaTeX options (Pandoc meta blocks) = do
102 modify $ \s -> s{ stInternalLinks = query isInternalLink blocks' }
103 modify $ \s -> s{ stInternalLinks = query isInternalLink blocks' }
103 let template = writerTemplate options
104 let template = writerTemplate options
104 -- set stBook depending on documentclass
105 -- set stBook depending on documentclass
106+ let colwidth = if writerWrapText options
107+ then Just $ writerColumns options
108+ else Nothing
109+ metadata <- metaToJSON options
110+ (fmap (render colwidth) . blockListToLaTeX)
111+ (fmap (render colwidth) . inlineListToLaTeX)
112+ meta
105 let bookClasses = ["memoir","book","report","scrreprt","scrbook"]
113 let bookClasses = ["memoir","book","report","scrreprt","scrbook"]
106− case lookup "documentclass" (writerVariables options) of
114+ case lookup "documentclass" (writerVariables options) `mplus`
115+ parseMaybe (withObject "object" (.: "documentclass")) metadata of
107 Just x | x `elem` bookClasses -> modify $ \s -> s{stBook = True}
116 Just x | x `elem` bookClasses -> modify $ \s -> s{stBook = True}
108 | otherwise -> return ()
117 | otherwise -> return ()
109 Nothing | any (\x -> "\\documentclass" `isPrefixOf` x &&
118 Nothing | any (\x -> "\\documentclass" `isPrefixOf` x &&
@@ -114,13 +123,6 @@ pandocToLaTeX options (Pandoc meta blocks) = do
114 -- \enquote{...} for smart quotes:
123 -- \enquote{...} for smart quotes:
115 when ("{csquotes}" `isInfixOf` template) $
124 when ("{csquotes}" `isInfixOf` template) $
116 modify $ \s -> s{stCsquotes = True}
125 modify $ \s -> s{stCsquotes = True}
117− let colwidth = if writerWrapText options
118− then Just $ writerColumns options
119− else Nothing
120− metadata <- metaToJSON options
121− (fmap (render colwidth) . blockListToLaTeX)
122− (fmap (render colwidth) . inlineListToLaTeX)
123− meta
124 let (blocks'', lastHeader) = if writerCiteMethod options == Citeproc then
126 let (blocks'', lastHeader) = if writerCiteMethod options == Citeproc then
125 (blocks', [])
127 (blocks', [])
126 else case last blocks' of
128 else case last blocks' of