aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-07-16 15:52:38 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-07-16 15:52:38 -0700
commit075ad9a4067fb3ed2ac766191af7b781375e5a34 (patch)
tree56ec47daa80ea97a6693192f598286fbfcb16c32 /src/Text/Pandoc/Writers
parent47a2dab1371729cf66eb283ef1946a473eed7c53 (diff)
downloadpandoc-075ad9a4067fb3ed2ac766191af7b781375e5a34.tar.gz
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.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs14
1 files 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: