git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: use {} around options containing special chars.

Closes #2892.

commit1fbe79db05c55495cf9096cb5be15e499d9a21ec authorJohn MacFarlane <jgm@berkeley.edu> dateSun 1 May 2016, 11:20 (10 years ago) parent91dc334
1 file changed+9−4
src/Text/Pandoc/Writers/LaTeX.hs+9−4
src/Text/Pandoc/Writers/LaTeX.hs+9−4
@@ -40,7 +40,8 @@ import Text.Printf ( printf )
4040import Network.URI ( isURI, unEscapeString )
4141import Data.Aeson (object, (.=), FromJSON)
4242import Data.List ( (\\), isInfixOf, stripPrefix, intercalate, intersperse, nub, nubBy )
43−import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
43+import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit,
44+ ord, isAlphaNum )
4445import Data.Maybe ( fromMaybe, isJust, catMaybes )
4546import qualified Data.Text as T
4647import Control.Applicative ((<|>))
@@ -471,23 +472,27 @@ blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
471472 st <- get
472473 let params = if writerListings (stOptions st)
473474 then (case getListingsLanguage classes of
474− Just l -> [ "language=" ++ l ]
475+ Just l -> [ "language=" ++ mbBraced l ]
475476 Nothing -> []) ++
476477 [ "numbers=left" | "numberLines" `elem` classes
477478 || "number" `elem` classes
478479 || "number-lines" `elem` classes ] ++
479480 [ (if key == "startFrom"
480481 then "firstnumber"
481− else key) ++ "=" ++ attr |
482+ else key) ++ "=" ++ mbBraced attr |
482483 (key,attr) <- keyvalAttr ] ++
483484 (if identifier == ""
484485 then []
485486 else [ "label=" ++ ref ])
486487
487488 else []
489+ mbBraced x = if not (all isAlphaNum x)
490+ then "{" <> x <> "}"
491+ else x
488492 printParams
489493 | null params = empty
490− | otherwise = brackets $ hcat (intersperse ", " (map text params))
494+ | otherwise = brackets $ hcat (intersperse ", "
495+ (map text params))
491496 return $ flush ("\\begin{lstlisting}" <> printParams $$ text str $$
492497 "\\end{lstlisting}") $$ cr
493498 let highlightedCodeBlock =