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.
This commit is contained in:
Jesse Rosenthal
2016-02-18 22:32:38 -05:00
parent 5848416852
commit 4112b321cd
+21 -6
View File
@@ -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 '}')