git.iko.soy/typeable/pandoc
on master help sign in
Consider header files when determining whether to use csquotes.
f0c4790Andreas Lööw
README+7−6
@@ -184,10 +184,10 @@ document contains images), [`color`], [`hyperref`], [`ulem`],
184[`mathspec`], [`polyglossia`] (with `lang`), [`xecjk`], and
184[`mathspec`], [`polyglossia`] (with `lang`), [`xecjk`], and
185[`bidi`] (with the `dir` variable set). The [`upquote`] and
185[`bidi`] (with the `dir` variable set). The [`upquote`] and
186[`microtype`] packages are used if available, and [`csquotes`] will
186[`microtype`] packages are used if available, and [`csquotes`] will
187−be used for [smart punctuation] if added to the template. The
187+be used for [smart punctuation] if added to the template or included in
188−[`natbib`], [`biblatex`], [`bibtex`], and [`biber`] packages can
188+any header file. The [`natbib`], [`biblatex`], [`bibtex`], and [`biber`]
189−optionally be used for [citation rendering]. These are included with
189+packages can optionally be used for [citation rendering]. These are
190−all recent versions of [TeX Live].
190+included with all recent versions of [TeX Live].
191
191
192PDF output can be controlled using [variables for LaTeX].
192PDF output can be controlled using [variables for LaTeX].
193
193
@@ -2377,8 +2377,9 @@ correct output, converting straight quotes to curly quotes, `---` to
2377em-dashes, `--` to en-dashes, and `...` to ellipses. Nonbreaking spaces
2377em-dashes, `--` to en-dashes, and `...` to ellipses. Nonbreaking spaces
2378are inserted after certain abbreviations, such as "Mr."
2378are inserted after certain abbreviations, such as "Mr."
2379
2379
2380−Note: if your LaTeX template calls for the [`csquotes`] package, pandoc will
2380+Note: if your LaTeX template or any included header file call for the
2381+[`csquotes`] package, pandoc will detect this automatically and use
2381−detect this automatically and use `\enquote{...}` for quoted text.
2382+`\enquote{...}` for quoted text.
2382
2383
2383Inline formatting
2384Inline formatting
2384-----------------
2385-----------------
src/Text/Pandoc/Writers/LaTeX.hs+7−2
@@ -38,7 +38,7 @@ import Text.Pandoc.Options
38import Text.Pandoc.Templates
38import Text.Pandoc.Templates
39import Text.Printf ( printf )
39import Text.Printf ( printf )
40import Network.URI ( isURI, unEscapeString )
40import Network.URI ( isURI, unEscapeString )
41−import Data.Aeson (object, (.=))
41+import Data.Aeson ( object, (.=), FromJSON )
42import Data.List ( (\\), isInfixOf, stripPrefix, intercalate, intersperse )
42import Data.List ( (\\), isInfixOf, stripPrefix, intercalate, intersperse )
43import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
43import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
44import Data.Maybe ( fromMaybe )
44import Data.Maybe ( fromMaybe )
@@ -129,7 +129,12 @@ pandocToLaTeX options (Pandoc meta blocks) = do
129 | otherwise -> return ()
129 | otherwise -> return ()
130 -- check for \usepackage...{csquotes}; if present, we'll use
130 -- check for \usepackage...{csquotes}; if present, we'll use
131 -- \enquote{...} for smart quotes:
131 -- \enquote{...} for smart quotes:
132+ let headerIncludesField :: FromJSON a => Maybe a
133+ headerIncludesField = getField "header-includes" metadata
134+ let headerIncludes = fromMaybe [] $ mplus
135+ (fmap return headerIncludesField)
136+ headerIncludesField
132− when ("{csquotes}" `isInfixOf` template) $
137+ when (any (isInfixOf "{csquotes}") (template : headerIncludes)) $
133 modify $ \s -> s{stCsquotes = True}
138 modify $ \s -> s{stCsquotes = True}
134 let (blocks'', lastHeader) = if writerCiteMethod options == Citeproc then
139 let (blocks'', lastHeader) = if writerCiteMethod options == Citeproc then
135 (blocks', [])
140 (blocks', [])