diff options
-rw-r--r-- | README | 13 | ||||
-rw-r--r-- | changelog | 2 | ||||
-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 | ||||
-rw-r--r-- | src/pandoc.hs | 14 |
6 files changed, 65 insertions, 37 deletions
@@ -213,7 +213,7 @@ Reader options abbreviations, such as "Mr." (Note: This option is significant only when the input format is `markdown` or `textile`. It is selected automatically when the input format is `textile` or the output format is `latex` or - `context`.) + `context`, unless `--no-tex-ligatures` is used.) `--old-dashes` : Selects the pandoc <= 1.8.2.1 behavior for parsing smart dashes: `-` before @@ -358,6 +358,17 @@ Options affecting specific writers : Number section headings in LaTeX, ConTeXt, or HTML output. By default, sections are not numbered. +`--no-tex-ligatures` +: Do not convert quotation marks, apostrophes, and dashes to + the TeX ligatures when writing LaTeX or ConTeXt. Instead, just + use literal unicode characters. This is needed for using advanced + OpenType features with XeLaTeX and LuaLaTeX. Note: normally + `--smart` is selected automatically for LaTeX and ConTeXt + output, but it must be specified explicitly if `--no-tex-ligatures` + is selected. If you use literal curly quotes, dashes, and ellipses + in your source, then you may want to use `--no-tex-ligatures` + without `--smart`. + `--listings` : Use listings package for LaTeX code blocks @@ -43,6 +43,8 @@ pandoc (1.9.3) * LaTeX writer: + + Added `--no-tex-ligatures` option to avoid replacing + quotation marks and dashes with TeX ligatures. + Use `fixltx2e` package to provide '\textsubscript'. + Improve spacing around LaTeX block environments: quote, verbatim, itemize, description, enumerate. 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 <> "\\]" diff --git a/src/pandoc.hs b/src/pandoc.hs index a8a70a1b4..a25e7d8d6 100644 --- a/src/pandoc.hs +++ b/src/pandoc.hs @@ -135,6 +135,7 @@ data Opt = Opt , optSlideLevel :: Maybe Int -- ^ Header level that creates slides , optSetextHeaders :: Bool -- ^ Use atx headers for markdown level 1-2 , optAscii :: Bool -- ^ Use ascii characters only in html + , optTeXLigatures :: Bool -- ^ Use TeX ligatures for quotes/dashes } -- | Defaults for command-line options. @@ -187,6 +188,7 @@ defaultOpts = Opt , optSlideLevel = Nothing , optSetextHeaders = True , optAscii = False + , optTeXLigatures = True } -- | A list of functions, each transforming the options data structure @@ -438,6 +440,11 @@ options = (\opt -> return opt { optNumberSections = True })) "" -- "Number sections in LaTeX" + , Option "" ["no-tex-ligatures"] + (NoArg + (\opt -> return opt { optTeXLigatures = False })) + "" -- "Don't use tex ligatures for quotes, dashes" + , Option "" ["listings"] (NoArg (\opt -> return opt { optListings = True })) @@ -804,6 +811,7 @@ main = do , optSlideLevel = slideLevel , optSetextHeaders = setextHeaders , optAscii = ascii + , optTeXLigatures = texLigatures } = opts when dumpArgs $ @@ -918,7 +926,8 @@ main = do lhsExtension sources, stateStandalone = standalone', stateCitations = map CSL.refId refs, - stateSmart = smart || laTeXOutput || writerName' == "context", + stateSmart = smart || (texLigatures && + (laTeXOutput || writerName' == "context")), stateOldDashes = oldDashes, stateColumns = columns, stateStrict = strict, @@ -961,7 +970,8 @@ main = do writerSlideLevel = slideLevel, writerHighlight = highlight, writerHighlightStyle = highlightStyle, - writerSetextHeaders = setextHeaders + writerSetextHeaders = setextHeaders, + writerTeXLigatures = texLigatures } when (writerName' `elem` nonTextFormats&& outputFile == "-") $ |