From 075ad9a4067fb3ed2ac766191af7b781375e5a34 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 16 Jul 2015 15:52:38 -0700 Subject: 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. --- src/Text/Pandoc/Writers/LaTeX.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 35cd4ebae..8ee7f3559 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -45,6 +45,7 @@ import Data.Maybe ( fromMaybe ) import Data.Aeson.Types ( (.:), parseMaybe, withObject ) import Control.Applicative ((<|>)) import Control.Monad.State +import qualified Text.Parsec as P import Text.Pandoc.Pretty import Text.Pandoc.Slides import Text.Pandoc.Highlighting (highlight, styleToLaTeX, @@ -111,13 +112,20 @@ 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 + Right r -> r + Left _ -> "" case lookup "documentclass" (writerVariables options) `mplus` parseMaybe (withObject "object" (.: "documentclass")) metadata of Just x | x `elem` bookClasses -> modify $ \s -> s{stBook = True} | otherwise -> return () - Nothing | any (\x -> "\\documentclass" `isPrefixOf` x && - (any (`isSuffixOf` x) bookClasses)) - (lines template) -> modify $ \s -> s{stBook = True} + Nothing | documentClass `elem` bookClasses + -> modify $ \s -> s{stBook = True} | otherwise -> return () -- check for \usepackage...{csquotes}; if present, we'll use -- \enquote{...} for smart quotes: -- cgit v1.2.3