git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: treat memoir template with `article` opt as article

We currently treat all memoir templates as books. This means that pandoc will infer the `--chapters` argument, even if the `article` iption is set for memoir. This commit makes pandoc treats the document as an article if there is an article option (i.e., `\documentclass[12pt,article]{memoir}`). Note that this refactors out the parsec parsers for document class and options, to make it a little clearer what's going on.

commit4112b321cd70036e8325b352a640e176130c95a9 authorJesse Rosenthal <jrosenthal@jhu.edu> dateThu 18 Feb 2016, 13:58 (11 years ago) parent5848416
1 file changed+21−6
src/Text/Pandoc/Writers/LaTeX.hs+21−6
src/Text/Pandoc/Writers/LaTeX.hs+21−6
@@ -113,12 +113,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
113113 (fmap (render colwidth) . inlineListToLaTeX)
114114 meta
115115 let bookClasses = ["memoir","book","report","scrreprt","scrbook"]
116− let documentClass = case P.parse (do P.skipMany (P.satisfy (/='\\'))
117− P.string "\\documentclass"
118− P.skipMany (P.satisfy (/='{'))
119− P.char '{'
120− P.manyTill P.letter (P.char '}')) "template"
121− template of
116+ let documentClass = case P.parse pDocumentClass "template" template of
122117 Right r -> r
123118 Left _ -> ""
124119 case lookup "documentclass" (writerVariables options) `mplus`
@@ -1260,3 +1255,23 @@ commonFromBcp47 x = fromIso $ head x
12601255deNote :: Inline -> Inline
12611256deNote (Note _) = RawInline (Format "latex") ""
12621257deNote x = x
1258+
1259+pDocumentOptions :: P.Parsec String () [String]
1260+pDocumentOptions = do
1261+ P.char '['
1262+ P.sepBy
1263+ (P.many $
1264+ P.spaces *> P.noneOf (" ,]" :: String) <* P.spaces)
1265+ (P.char ',')
1266+
1267+pDocumentClass :: P.Parsec String () String
1268+pDocumentClass =
1269+ do P.skipMany (P.satisfy (/='\\'))
1270+ P.string "\\documentclass"
1271+ classOptions <- pDocumentOptions <|> return []
1272+ if ("article" :: String) `elem` classOptions
1273+ then return "article"
1274+ else do P.skipMany (P.satisfy (/='{'))
1275+ P.char '{'
1276+ P.manyTill P.letter (P.char '}')
1277+