diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2012-05-11 22:58:49 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2012-05-11 23:00:46 -0700 |
commit | 5f889b93963dda851b3610dfd2ed74c17a3e4091 (patch) | |
tree | f48b191b5ff559225962bf7281e5c9a0c7a8bf1e /src/Text/Pandoc | |
parent | 1aec24a169a37a01e446079625f79ea67796e28c (diff) | |
download | pandoc-5f889b93963dda851b3610dfd2ed74c17a3e4091.tar.gz |
Added writerTeXLigatures to WriterOptions, `--no-tex-ligatures` option.
This is useful for those who want to use advanced OpenType features
with xelatex/lualatex.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 2 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/ConTeXt.hs | 24 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 47 |
3 files changed, 39 insertions, 34 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index cd5b19164..1fb07ca05 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -520,6 +520,7 @@ data WriterOptions = WriterOptions , writerHighlight :: Bool -- ^ Highlight source code , writerHighlightStyle :: Style -- ^ Style to use for highlighting , writerSetextHeaders :: Bool -- ^ Use setext headers for levels 1-2 in markdown + , writerTeXLigatures :: Bool -- ^ Use tex ligatures quotes, dashes in latex } deriving Show {-# DEPRECATED writerXeTeX "writerXeTeX no longer does anything" #-} @@ -558,6 +559,7 @@ defaultWriterOptions = , writerHighlight = False , writerHighlightStyle = pygments , writerSetextHeaders = True + , writerTeXLigatures = True } -- diff --git a/src/Text/Pandoc/Writers/ConTeXt.hs b/src/Text/Pandoc/Writers/ConTeXt.hs index 9cca76ada..08165ea1b 100644 --- a/src/Text/Pandoc/Writers/ConTeXt.hs +++ b/src/Text/Pandoc/Writers/ConTeXt.hs @@ -86,8 +86,9 @@ pandocToConTeXt options (Pandoc (Meta title authors date) blocks) = do -- escape things as needed for ConTeXt -escapeCharForConTeXt :: Char -> String -escapeCharForConTeXt ch = +escapeCharForConTeXt :: WriterOptions -> Char -> String +escapeCharForConTeXt opts ch = + let ligatures = writerTeXLigatures opts in case ch of '{' -> "\\letteropenbrace{}" '}' -> "\\letterclosebrace{}" @@ -105,15 +106,15 @@ escapeCharForConTeXt ch = ']' -> "{]}" '_' -> "\\letterunderscore{}" '\160' -> "~" - '\x2014' -> "---" - '\x2013' -> "--" - '\x2019' -> "'" + '\x2014' | ligatures -> "---" + '\x2013' | ligatures -> "--" + '\x2019' | ligatures -> "'" '\x2026' -> "\\ldots{}" x -> [x] -- | Escape string for ConTeXt -stringToConTeXt :: String -> String -stringToConTeXt = concatMap escapeCharForConTeXt +stringToConTeXt :: WriterOptions -> String -> String +stringToConTeXt opts = concatMap (escapeCharForConTeXt opts) -- | Convert Elements to ConTeXt elementToConTeXt :: WriterOptions -> Element -> State WriterState Doc @@ -254,8 +255,9 @@ inlineToConTeXt (SmallCaps lst) = do return $ braces $ "\\sc " <> contents inlineToConTeXt (Code _ str) | not ('{' `elem` str || '}' `elem` str) = return $ "\\type" <> braces (text str) -inlineToConTeXt (Code _ str) = - return $ "\\mono" <> braces (text $ stringToConTeXt str) +inlineToConTeXt (Code _ str) = do + opts <- gets stOptions + return $ "\\mono" <> braces (text $ stringToConTeXt opts str) inlineToConTeXt (Quoted SingleQuote lst) = do contents <- inlineListToConTeXt lst return $ "\\quote" <> braces contents @@ -263,7 +265,9 @@ inlineToConTeXt (Quoted DoubleQuote lst) = do contents <- inlineListToConTeXt lst return $ "\\quotation" <> braces contents inlineToConTeXt (Cite _ lst) = inlineListToConTeXt lst -inlineToConTeXt (Str str) = return $ text $ stringToConTeXt str +inlineToConTeXt (Str str) = do + opts <- gets stOptions + return $ text $ stringToConTeXt opts str inlineToConTeXt (Math InlineMath str) = return $ char '$' <> text str <> char '$' inlineToConTeXt (Math DisplayMath str) = diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 6460f98f7..d32a7122f 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -174,9 +174,11 @@ elementToLaTeX opts (Sec level _ id' title' elements) = do -- escape things as needed for LaTeX stringToLaTeX :: Bool -> String -> State WriterState String -stringToLaTeX _ [] = return "" -stringToLaTeX isUrl (x:xs) = do +stringToLaTeX _ [] = return "" +stringToLaTeX isUrl (x:xs) = do + opts <- gets stOptions rest <- stringToLaTeX isUrl xs + let ligatures = writerTeXLigatures opts when (x == '€') $ modify $ \st -> st{ stUsesEuro = True } return $ @@ -201,13 +203,13 @@ stringToLaTeX isUrl (x:xs) = do '[' -> "{[}" ++ rest -- to avoid interpretation as ']' -> "{]}" ++ rest -- optional arguments '\160' -> "~" ++ rest - '\x2018' -> "`" ++ rest - '\x2019' -> "'" ++ rest - '\x201C' -> "``" ++ rest - '\x201D' -> "''" ++ rest '\x2026' -> "\\ldots{}" ++ rest - '\x2014' -> "---" ++ rest - '\x2013' -> "--" ++ rest + '\x2018' | ligatures -> "`" ++ rest + '\x2019' | ligatures -> "'" ++ rest + '\x201C' | ligatures -> "``" ++ rest + '\x201D' | ligatures -> "''" ++ rest + '\x2014' | ligatures -> "---" ++ rest + '\x2013' | ligatures -> "--" ++ rest _ -> x : rest -- | Puts contents into LaTeX command. @@ -536,23 +538,11 @@ inlineToLaTeX (Code (_,classes,_) str) = do Just h -> modify (\st -> st{ stHighlighting = True }) >> return (text h) rawCode = liftM (text . (\s -> "\\texttt{" ++ s ++ "}")) - $ stringToLaTeX False str -inlineToLaTeX (Quoted SingleQuote lst) = do - contents <- inlineListToLaTeX lst - csquotes <- liftM stCsquotes get - if csquotes - then return $ "\\enquote" <> braces contents - else do - let s1 = if (not (null lst)) && (isQuoted (head lst)) - then "\\," - else empty - let s2 = if (not (null lst)) && (isQuoted (last lst)) - then "\\," - else empty - return $ char '`' <> s1 <> contents <> s2 <> char '\'' -inlineToLaTeX (Quoted DoubleQuote lst) = do + $ stringToLaTeX False str +inlineToLaTeX (Quoted qt lst) = do contents <- inlineListToLaTeX lst csquotes <- liftM stCsquotes get + opts <- gets stOptions if csquotes then return $ "\\enquote" <> braces contents else do @@ -562,7 +552,16 @@ inlineToLaTeX (Quoted DoubleQuote lst) = do let s2 = if (not (null lst)) && (isQuoted (last lst)) then "\\," else empty - return $ "``" <> s1 <> contents <> s2 <> "''" + let inner = s1 <> contents <> s2 + return $ case qt of + DoubleQuote -> + if writerTeXLigatures opts + then text "``" <> inner <> text "''" + else char '\x201C' <> inner <> char '\x201D' + SingleQuote -> + if writerTeXLigatures opts + then char '`' <> inner <> char '\'' + else char '\x2018' <> inner <> char '\x2019' inlineToLaTeX (Str str) = liftM text $ stringToLaTeX False str inlineToLaTeX (Math InlineMath str) = return $ char '$' <> text str <> char '$' inlineToLaTeX (Math DisplayMath str) = return $ "\\[" <> text str <> "\\]" |