LaTeX reader: Fixed dollar-math parsing...
...to ensure that space is left between a control seq and a following word that would otherwise change its meaning. Closes #5836.
This commit is contained in:
parent
f39c44f0ba
commit
65593043c3
2 changed files with 17 additions and 9 deletions
|
@ -629,28 +629,28 @@ dollarsMath :: PandocMonad m => LP m Inlines
|
||||||
dollarsMath = do
|
dollarsMath = do
|
||||||
symbol '$'
|
symbol '$'
|
||||||
display <- option False (True <$ symbol '$')
|
display <- option False (True <$ symbol '$')
|
||||||
(do contents <- try $ T.unpack <$> pDollarsMath 0
|
(do contents <- try $ T.unpack . untokenize <$> pDollarsMath 0
|
||||||
if display
|
if display
|
||||||
then (mathDisplay contents <$ symbol '$')
|
then (mathDisplay contents <$ symbol '$')
|
||||||
else return $ mathInline contents)
|
else return $ mathInline contents)
|
||||||
<|> (guard display >> return (mathInline ""))
|
<|> (guard display >> return (mathInline ""))
|
||||||
|
|
||||||
-- Int is number of embedded groupings
|
-- Int is number of embedded groupings
|
||||||
pDollarsMath :: PandocMonad m => Int -> LP m Text
|
pDollarsMath :: PandocMonad m => Int -> LP m [Tok]
|
||||||
pDollarsMath n = do
|
pDollarsMath n = do
|
||||||
Tok _ toktype t <- anyTok
|
tk@(Tok _ toktype t) <- anyTok
|
||||||
case toktype of
|
case toktype of
|
||||||
Symbol | t == "$"
|
Symbol | t == "$"
|
||||||
, n == 0 -> return mempty
|
, n == 0 -> return []
|
||||||
| t == "\\" -> do
|
| t == "\\" -> do
|
||||||
Tok _ _ t' <- anyTok
|
tk' <- anyTok
|
||||||
return (t <> t')
|
((tk :) . (tk' :)) <$> pDollarsMath n
|
||||||
| t == "{" -> (t <>) <$> pDollarsMath (n+1)
|
| t == "{" -> (tk :) <$> pDollarsMath (n+1)
|
||||||
| t == "}" ->
|
| t == "}" ->
|
||||||
if n > 0
|
if n > 0
|
||||||
then (t <>) <$> pDollarsMath (n-1)
|
then (tk :) <$> pDollarsMath (n-1)
|
||||||
else mzero
|
else mzero
|
||||||
_ -> (t <>) <$> pDollarsMath n
|
_ -> (tk :) <$> pDollarsMath n
|
||||||
|
|
||||||
-- citations
|
-- citations
|
||||||
|
|
||||||
|
|
|
@ -17,3 +17,11 @@ $\vara \varb$
|
||||||
^D
|
^D
|
||||||
\(\alpha b\)
|
\(\alpha b\)
|
||||||
```
|
```
|
||||||
|
```
|
||||||
|
% pandoc -f latex -t latex
|
||||||
|
\newcommand{\vara}{\alpha}
|
||||||
|
\newcommand{\varb}{b}
|
||||||
|
\[\vara \varb\]
|
||||||
|
^D
|
||||||
|
\[\alpha b\]
|
||||||
|
```
|
||||||
|
|
Loading…
Add table
Reference in a new issue