git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: recognize book documentclass if set in metadata.

This sets `--chapters` implicitly if the documentclass in metadata is a book documentclass. Previously this was done only if a book documentclass was set in a variable. Closes #1971.

commit8e404aaca066a5d1f4014ebf9317748c03c2b716 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 25 Feb 2015, 08:57 (12 years ago) parent47bfdca
1 file changed+10−8
src/Text/Pandoc/Writers/LaTeX.hs+10−8
src/Text/Pandoc/Writers/LaTeX.hs+10−8
@@ -42,6 +42,7 @@ import Data.List ( (\\), isSuffixOf, isInfixOf, stripPrefix,
4242 isPrefixOf, intercalate, intersperse )
4343import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
4444import Data.Maybe ( fromMaybe )
45+import Data.Aeson.Types ( (.:), parseMaybe, withObject )
4546import Control.Applicative ((<|>))
4647import Control.Monad.State
4748import Text.Pandoc.Pretty
@@ -102,8 +103,16 @@ pandocToLaTeX options (Pandoc meta blocks) = do
102103 modify $ \s -> s{ stInternalLinks = query isInternalLink blocks' }
103104 let template = writerTemplate options
104105 -- 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
105113 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
107116 Just x | x `elem` bookClasses -> modify $ \s -> s{stBook = True}
108117 | otherwise -> return ()
109118 Nothing | any (\x -> "\\documentclass" `isPrefixOf` x &&
@@ -114,13 +123,6 @@ pandocToLaTeX options (Pandoc meta blocks) = do
114123 -- \enquote{...} for smart quotes:
115124 when ("{csquotes}" `isInfixOf` template) $
116125 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
124126 let (blocks'', lastHeader) = if writerCiteMethod options == Citeproc then
125127 (blocks', [])
126128 else case last blocks' of