LaTeX reader: disable ligatures inside \texttt.

Closes #10781.
This commit is contained in:
John MacFarlane
2025-04-14 10:23:26 -07:00
parent 01b7612a9d
commit 47610fe3de
4 changed files with 28 additions and 6 deletions
+17 -5
View File
@@ -343,6 +343,12 @@ inlineCommands = M.unions
, biblatexInlineCommands tok
, rest ]
where
disableLigatures p = do
oldLigatures <- sLigatures <$> getState
updateState (\s -> s{ sLigatures = False })
res <- p
updateState (\s -> s{ sLigatures = oldLigatures })
pure res
rest = M.fromList
[ ("emph", extractSpaces emph <$> tok)
, ("textit", extractSpaces emph <$> tok)
@@ -352,7 +358,7 @@ inlineCommands = M.unions
, ("textmd", extractSpaces (spanWith ("",["medium"],[])) <$> tok)
, ("textrm", extractSpaces (spanWith ("",["roman"],[])) <$> tok)
, ("textup", extractSpaces (spanWith ("",["upright"],[])) <$> tok)
, ("texttt", formatCode nullAttr <$> tok)
, ("texttt", formatCode nullAttr <$> disableLigatures tok)
, ("alert", skipopts >> spanWith ("",["alert"],[]) <$> tok) -- beamer
, ("textsuperscript", extractSpaces superscript <$> tok)
, ("textsubscript", extractSpaces subscript <$> tok)
@@ -634,6 +640,7 @@ inline = do
do eatOneToken
report $ ParsingUnescaped t pos
return $ str t
ligatures <- sLigatures <$> getState
case toktype of
Comment -> mempty <$ eatOneToken
Spaces -> space <$ eatOneToken
@@ -641,14 +648,19 @@ inline = do
Word -> str t <$ eatOneToken
Symbol ->
case t of
"-" -> eatOneToken *>
"-" | ligatures
-> eatOneToken *>
option (str "-") (symbol '-' *>
option (str "") (str "" <$ symbol '-'))
"'" -> eatOneToken *>
option (str "") (str "" <$ symbol '\'')
option (str "") (str "" <$ (guard ligatures *> symbol '\''))
"~" -> str "\160" <$ eatOneToken
"`" -> doubleQuote <|> singleQuote <|> symbolAsString
"\"" -> doubleQuote <|> singleQuote <|> symbolAsString
"`" | ligatures
-> doubleQuote <|> singleQuote <|> (str "" <$ symbol '`')
| otherwise
-> str "" <$ symbol '`'
"\"" | ligatures
-> doubleQuote <|> singleQuote <|> symbolAsString
"" -> doubleQuote <|> symbolAsString
"" -> singleQuote <|> symbolAsString
"$" -> dollarsMath <|> unescapedSymbolAsString
+2
View File
@@ -173,6 +173,7 @@ data LaTeXState = LaTeXState{ sOptions :: ReaderOptions
, sFileContents :: M.Map Text Text
, sEnableWithRaw :: Bool
, sRawTokens :: IntMap.IntMap [Tok]
, sLigatures :: Bool
}
deriving Show
@@ -201,6 +202,7 @@ defaultLaTeXState = LaTeXState{ sOptions = def
, sFileContents = M.empty
, sEnableWithRaw = True
, sRawTokens = IntMap.empty
, sLigatures = True
}
instance PandocMonad m => HasQuoteContext LaTeXState m where
+8
View File
@@ -0,0 +1,8 @@
```
% pandoc -f latex -t markdown --wrap=preserve
This is \texttt{--flag} with dashes.
This is the same --flag without a code.
^D
This is `--flag` with dashes.
This is the same --flag without a code.
```
+1 -1
View File
@@ -9,7 +9,7 @@
% pandoc -f latex -t native
\texttt{``hi''}
^D
[ Para [ Code ( "" , [] , [] ) "\8220hi\8221" ] ]
[ Para [ Code ( "" , [] , [] ) "\8216\8216hi\8217\8217" ] ]
```
```