git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Fixed detection of 'chapters' from template.

If a documentclass isn't specified in metadata, but the template has a hardwired bookish documentclass, act as if `--chapters` was used. This was the default in earlier versions, but it has been broken for a little while.

commit075ad9a4067fb3ed2ac766191af7b781375e5a34 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 16 Jul 2015, 15:52 (11 years ago) parent47a2dab
1 file changed+11−3
src/Text/Pandoc/Writers/LaTeX.hs+11−3
src/Text/Pandoc/Writers/LaTeX.hs+11−3
@@ -45,6 +45,7 @@ import Data.Maybe ( fromMaybe )
4545import Data.Aeson.Types ( (.:), parseMaybe, withObject )
4646import Control.Applicative ((<|>))
4747import Control.Monad.State
48+import qualified Text.Parsec as P
4849import Text.Pandoc.Pretty
4950import Text.Pandoc.Slides
5051import Text.Pandoc.Highlighting (highlight, styleToLaTeX,
@@ -111,13 +112,20 @@ pandocToLaTeX options (Pandoc meta blocks) = do
111112 (fmap (render colwidth) . inlineListToLaTeX)
112113 meta
113114 let bookClasses = ["memoir","book","report","scrreprt","scrbook"]
115+ let documentClass = case P.parse (do P.skipMany (P.satisfy (/='\\'))
116+ P.string "\\documentclass"
117+ P.skipMany (P.satisfy (/='{'))
118+ P.char '{'
119+ P.manyTill P.letter (P.char '}')) "template"
120+ template of
121+ Right r -> r
122+ Left _ -> ""
114123 case lookup "documentclass" (writerVariables options) `mplus`
115124 parseMaybe (withObject "object" (.: "documentclass")) metadata of
116125 Just x | x `elem` bookClasses -> modify $ \s -> s{stBook = True}
117126 | otherwise -> return ()
118− Nothing | any (\x -> "\\documentclass" `isPrefixOf` x &&
119− (any (`isSuffixOf` x) bookClasses))
120− (lines template) -> modify $ \s -> s{stBook = True}
127+ Nothing | documentClass `elem` bookClasses
128+ -> modify $ \s -> s{stBook = True}
121129 | otherwise -> return ()
122130 -- check for \usepackage...{csquotes}; if present, we'll use
123131 -- \enquote{...} for smart quotes: