LaTeX reader: allow space at end of math after \
.
Closes #5010. Expose trimMath from T.P.Shared.
This commit is contained in:
parent
9e3a2b61ec
commit
c51be5dfc8
4 changed files with 34 additions and 3 deletions
|
@ -627,7 +627,7 @@ mathInlineWith op cl = try $ do
|
|||
return " "
|
||||
) (try $ string cl)
|
||||
notFollowedBy digit -- to prevent capture of $5
|
||||
return $ trim $ concat words'
|
||||
return $ trimMath $ concat words'
|
||||
where
|
||||
inBalancedBraces :: Stream s m Char => Int -> String -> ParserT s st m String
|
||||
inBalancedBraces 0 "" = do
|
||||
|
|
|
@ -605,10 +605,10 @@ accent combiningAccent fallBack = try $ do
|
|||
[] -> return $ str [fromMaybe combiningAccent fallBack]
|
||||
_ -> return ils
|
||||
mathDisplay :: String -> Inlines
|
||||
mathDisplay = displayMath . trim
|
||||
mathDisplay = displayMath . trimMath
|
||||
|
||||
mathInline :: String -> Inlines
|
||||
mathInline = math . trim
|
||||
mathInline = math . trimMath
|
||||
|
||||
dollarsMath :: PandocMonad m => LP m Inlines
|
||||
dollarsMath = do
|
||||
|
|
|
@ -49,6 +49,7 @@ module Text.Pandoc.Shared (
|
|||
trim,
|
||||
triml,
|
||||
trimr,
|
||||
trimMath,
|
||||
stripFirstAndLast,
|
||||
camelCaseToHyphenated,
|
||||
toRomanNumeral,
|
||||
|
@ -224,6 +225,15 @@ triml = dropWhile (`elem` " \r\n\t")
|
|||
trimr :: String -> String
|
||||
trimr = reverse . triml . reverse
|
||||
|
||||
-- | Trim leading space and trailing space unless after \.
|
||||
trimMath :: String -> String
|
||||
trimMath = triml . reverse . stripspace . reverse
|
||||
where
|
||||
stripspace (c1:c2:cs)
|
||||
| c1 `elem` [' ','\t','\n','\r']
|
||||
, c2 /= '\\' = stripspace (c2:cs)
|
||||
stripspace cs = cs
|
||||
|
||||
-- | Strip leading and trailing characters from string
|
||||
stripFirstAndLast :: String -> String
|
||||
stripFirstAndLast str =
|
||||
|
|
21
test/command/5010.md
Normal file
21
test/command/5010.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
```
|
||||
% pandoc -f latex -t latex
|
||||
\(\left\{ \begin{matrix}
|
||||
y\,\,\,\, \geqq \,\,\, f\,(\, x\,)\,\, \\
|
||||
y\,\,\, \leqq \,\,\, g\,(\, x\,)\, \\
|
||||
\end{matrix} \right.\ \)
|
||||
^D
|
||||
\(\left\{ \begin{matrix}
|
||||
y\,\,\,\, \geqq \,\,\, f\,(\, x\,)\,\, \\
|
||||
y\,\,\, \leqq \,\,\, g\,(\, x\,)\, \\
|
||||
\end{matrix} \right.\ \)
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f markdown -t latex
|
||||
$x\ $
|
||||
^D
|
||||
\(x\ \)
|
||||
```
|
||||
|
||||
|
Loading…
Reference in a new issue