From ed1173ace6c545f5b98c2b84859db89a6b9e799d Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 19 Nov 2015 20:18:06 -0800 Subject: Rationalized behavior of --no-tex-ligatures and --smart. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change makes `--no-tex-ligatures` affect the LaTeX reader as well as the LaTeX and ConTeXt writers. If it is used, the LaTeX reader will parse characters `` ` ``, `'`, and `-` literally, rather than parsing ligatures for quotation marks and dashes. And the LaTeX writer will print unicode quotation mark and dash characters literally, rather than converting them to the standard ASCII ligatures. Note that `--smart` has no affect on the LaTeX reader. `--smart` is still the default for all input formats when LaTeX or ConTeXt is the output format, *unless* `--no-tex-ligatures` is used. Some examples to illustrate the logic: ``` % echo "'hi'" | pandoc -t latex `hi' % echo "'hi'" | pandoc -t latex --no-tex-ligatures 'hi' % echo "'hi'" | pandoc -t latex --no-tex-ligatures --smart ‘hi’ % echo "'hi'" | pandoc -f latex --no-tex-ligatures

'hi'

% echo "'hi'" | pandoc -f latex

’hi’

``` Closes #2541. --- src/Text/Pandoc/Readers/LaTeX.hs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/Text/Pandoc/Readers') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index a6db6ffad..b9645d034 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -169,17 +169,23 @@ quoted' f starter ender = do try ((f . mconcat) <$> manyTill inline ender) <|> lit startchs doubleQuote :: LP Inlines -doubleQuote = - quoted' doubleQuoted (try $ string "``") (void $ try $ string "''") - <|> quoted' doubleQuoted (string "“") (void $ char '”') - -- the following is used by babel for localized quotes: - <|> quoted' doubleQuoted (try $ string "\"`") (void $ try $ string "\"'") - <|> quoted' doubleQuoted (string "\"") (void $ char '"') +doubleQuote = do + smart <- getOption readerSmart + if smart + then quoted' doubleQuoted (try $ string "``") (void $ try $ string "''") + <|> quoted' doubleQuoted (string "“") (void $ char '”') + -- the following is used by babel for localized quotes: + <|> quoted' doubleQuoted (try $ string "\"`") (void $ try $ string "\"'") + <|> quoted' doubleQuoted (string "\"") (void $ char '"') + else str <$> many1 (oneOf "`'“”\"") singleQuote :: LP Inlines -singleQuote = - quoted' singleQuoted (string "`") (try $ char '\'' >> notFollowedBy letter) - <|> quoted' singleQuoted (string "‘") (try $ char '’' >> notFollowedBy letter) +singleQuote = do + smart <- getOption readerSmart + if smart + then quoted' singleQuoted (string "`") (try $ char '\'' >> notFollowedBy letter) + <|> quoted' singleQuoted (string "‘") (try $ char '’' >> notFollowedBy letter) + else str <$> many1 (oneOf "`\'‘’") inline :: LP Inlines inline = (mempty <$ comment) -- cgit v1.2.3