git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: handle math right before digit.

We insert an HTML comment to avoid a `$` right before a digit, which pandoc will not recognize as a math delimiter.

commit9223788a05fe619d567bcbdf4cb31db63de86f32 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 29 Jan 2021, 18:29 (6 years ago) parentd82fe52
2 files changed+11−1
src/Text/Pandoc/Writers/Markdown.hs+5−1 test/command/7058.md+6
src/Text/Pandoc/Writers/Markdown.hs+5−1
@@ -22,7 +22,7 @@ module Text.Pandoc.Writers.Markdown (
2222 writePlain) where
2323import Control.Monad.Reader
2424import Control.Monad.State.Strict
25−import Data.Char (isAlphaNum)
25+import Data.Char (isAlphaNum, isDigit)
2626import Data.Default
2727import Data.List (find, intersperse, sortOn, transpose)
2828import qualified Data.Map as M
@@ -987,6 +987,10 @@ inlineListToMarkdown opts lst = do
987987 inlist <- asks envInList
988988 go (if inlist then avoidBadWrapsInList lst else lst)
989989 where go [] = return empty
990+ go (x@Math{}:y@(Str t):zs)
991+ | T.all isDigit (T.take 1 t) -- starts with digit -- see #7058
992+ = liftM2 (<>) (inlineToMarkdown opts x)
993+ (go (RawInline (Format "html") "<!-- -->" : y : zs))
990994 go (i:is) = case i of
991995 Link {} -> case is of
992996 -- If a link is followed by another link, or '[', '(' or ':'
test/command/7058.mdnew file+6
@@ -0,0 +1,6 @@
1+```
2+% pandoc -f latex -t markdown
3+5\(-\)8 \(x\)
4+^D
5+5$-$`<!-- -->`{=html}8 $x$
6+```