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/Writers/LaTeX.hs | |
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/Writers/LaTeX.hs')
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 47 |
1 files changed, 23 insertions, 24 deletions
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 <> "\\]" |