From 4112b321cd70036e8325b352a640e176130c95a9 Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Thu, 18 Feb 2016 13:58:43 -0500 Subject: 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. --- src/Text/Pandoc/Writers/LaTeX.hs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/Text/Pandoc/Writers') diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index e4e882b8c..5ac166de2 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -113,12 +113,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do (fmap (render colwidth) . inlineListToLaTeX) meta let bookClasses = ["memoir","book","report","scrreprt","scrbook"] - let documentClass = case P.parse (do P.skipMany (P.satisfy (/='\\')) - P.string "\\documentclass" - P.skipMany (P.satisfy (/='{')) - P.char '{' - P.manyTill P.letter (P.char '}')) "template" - template of + let documentClass = case P.parse pDocumentClass "template" template of Right r -> r Left _ -> "" case lookup "documentclass" (writerVariables options) `mplus` @@ -1260,3 +1255,23 @@ commonFromBcp47 x = fromIso $ head x deNote :: Inline -> Inline deNote (Note _) = RawInline (Format "latex") "" deNote x = x + +pDocumentOptions :: P.Parsec String () [String] +pDocumentOptions = do + P.char '[' + P.sepBy + (P.many $ + P.spaces *> P.noneOf (" ,]" :: String) <* P.spaces) + (P.char ',') + +pDocumentClass :: P.Parsec String () String +pDocumentClass = + do P.skipMany (P.satisfy (/='\\')) + P.string "\\documentclass" + classOptions <- pDocumentOptions <|> return [] + if ("article" :: String) `elem` classOptions + then return "article" + else do P.skipMany (P.satisfy (/='{')) + P.char '{' + P.manyTill P.letter (P.char '}') + -- cgit v1.2.3