git.iko.soy/typeable/pandoc
on master help sign in
Rationalized behavior of --no-tex-ligatures and --smart.

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 <p>'hi'</p> % echo "'hi'" | pandoc -f latex <p>’hi’</p> ``` Closes #2541.

commited1173ace6c545f5b98c2b84859db89a6b9e799d authorJohn MacFarlane <jgm@berkeley.edu> dateThu 19 Nov 2015, 20:18 (11 years ago) parentda4103b
3 files changed+36−21
README+14−10 pandoc.hs+7−2 src/Text/Pandoc/Readers/LaTeX.hs+15−9
README+14−10
@@ -374,7 +374,7 @@ Reader options
374374 `...` to ellipses. Nonbreaking spaces are inserted after certain
375375 abbreviations, such as "Mr." (Note: This option is selected automatically
376376 when the output format is `latex` or `context`, unless `--no-tex-ligatures`
377− is used.)
377+ is used. It has no effect for `latex` input.)
378378
379379`--old-dashes`
380380
@@ -651,15 +651,19 @@ Options affecting specific writers
651651
652652`--no-tex-ligatures`
653653
654−: Do not convert quotation marks, apostrophes, and dashes to
655− the TeX ligatures when writing LaTeX or ConTeXt. Instead, just
656− use literal unicode characters. This is needed for using advanced
657− OpenType features with `xelatex` and `lualatex`. Note: normally
658− `--smart` is selected automatically for LaTeX and ConTeXt
659− output, but it must be specified explicitly if `--no-tex-ligatures`
660− is selected. If you use literal curly quotes, dashes, and ellipses
661− in your source, then you may want to use `--no-tex-ligatures`
662− without `--smart`.
654+: Do not use the TeX ligatures for quotation marks, apostrophes,
655+ and dashes (`` `...' ``, ` ``..'' `, `--`, `---`) when
656+ writing or reading LaTeX or ConTeXt. In reading LaTeX,
657+ parse the characters `` ` ``, `'`, and `-` literally, rather
658+ than parsing ligatures for quotation marks and dashes. In
659+ writing LaTeX or ConTeXt, print unicode quotation mark and
660+ dash characters literally, rather than converting them to
661+ the standard ASCII TeX ligatures. Note: normally `--smart`
662+ is selected automatically for LaTeX and ConTeXt output, but
663+ it must be specified explicitly if `--no-tex-ligatures` is
664+ selected. If you use literal curly quotes, dashes, and
665+ ellipses in your source, then you may want to use
666+ `--no-tex-ligatures` without `--smart`.
663667
664668`--listings`
665669
pandoc.hs+7−2
@@ -1176,6 +1176,9 @@ main = do
11761176 "beamer" `isPrefixOf` writerName'
11771177 let conTeXtOutput = "context" `isPrefixOf` writerName'
11781178
1179+ let laTeXInput = "latex" `isPrefixOf` readerName' ||
1180+ "beamer" `isPrefixOf` readerName'
1181+
11791182 writer <- if ".lua" `isSuffixOf` writerName'
11801183 -- note: use non-lowercased version writerName
11811184 then return $ IOStringWriter $ writeCustom writerName
@@ -1257,8 +1260,10 @@ main = do
12571260 uriFragment = "" }
12581261 _ -> Nothing
12591262
1260− let readerOpts = def{ readerSmart = smart || (texLigatures &&
1261− (laTeXOutput || conTeXtOutput))
1263+ let readerOpts = def{ readerSmart = if laTeXInput
1264+ then texLigatures
1265+ else smart || (texLigatures &&
1266+ (laTeXOutput || conTeXtOutput))
12621267 , readerStandalone = standalone'
12631268 , readerParseRaw = parseRaw
12641269 , readerColumns = columns
src/Text/Pandoc/Readers/LaTeX.hs+15−9
@@ -169,17 +169,23 @@ quoted' f starter ender = do
169169 try ((f . mconcat) <$> manyTill inline ender) <|> lit startchs
170170
171171doubleQuote :: LP Inlines
172−doubleQuote =
173− quoted' doubleQuoted (try $ string "``") (void $ try $ string "''")
174− <|> quoted' doubleQuoted (string "“") (void $ char '”')
175− -- the following is used by babel for localized quotes:
176− <|> quoted' doubleQuoted (try $ string "\"`") (void $ try $ string "\"'")
177− <|> quoted' doubleQuoted (string "\"") (void $ char '"')
172+doubleQuote = do
173+ smart <- getOption readerSmart
174+ if smart
175+ then quoted' doubleQuoted (try $ string "``") (void $ try $ string "''")
176+ <|> quoted' doubleQuoted (string "“") (void $ char '”')
177+ -- the following is used by babel for localized quotes:
178+ <|> quoted' doubleQuoted (try $ string "\"`") (void $ try $ string "\"'")
179+ <|> quoted' doubleQuoted (string "\"") (void $ char '"')
180+ else str <$> many1 (oneOf "`'“”\"")
178181
179182singleQuote :: LP Inlines
180−singleQuote =
181− quoted' singleQuoted (string "`") (try $ char '\'' >> notFollowedBy letter)
182− <|> quoted' singleQuoted (string "‘") (try $ char '’' >> notFollowedBy letter)
183+singleQuote = do
184+ smart <- getOption readerSmart
185+ if smart
186+ then quoted' singleQuoted (string "`") (try $ char '\'' >> notFollowedBy letter)
187+ <|> quoted' singleQuoted (string "‘") (try $ char '’' >> notFollowedBy letter)
188+ else str <$> many1 (oneOf "`\'‘’")
183189
184190inline :: LP Inlines
185191inline = (mempty <$ comment)