git.iko.soy/typeable/pandoc
on master help sign in
LaTeX untokenize: Ensure space between control sequence and following letter.

Closes #5836.

commit041cfbd5eeffd2bc79447c4894652fc3c108c40d authorJohn MacFarlane <jgm@berkeley.edu> dateSat 2 Nov 2019, 12:20 (7 years ago) parent6c9a20b
2 files changed+15−2
src/Text/Pandoc/Readers/LaTeX.hs+1 src/Text/Pandoc/Readers/LaTeX/Parsing.hs+14−2
src/Text/Pandoc/Readers/LaTeX.hs+1
@@ -618,6 +618,7 @@ accent combiningAccent fallBack = try $ do
618618 [Space] -> return $ str [fromMaybe combiningAccent fallBack]
619619 [] -> return $ str [fromMaybe combiningAccent fallBack]
620620 _ -> return ils
621+
621622mathDisplay :: String -> Inlines
622623mathDisplay = displayMath . trimMath
623624
src/Text/Pandoc/Readers/LaTeX/Parsing.hs+14−2
@@ -92,6 +92,7 @@ import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..),
9292 ArgSpec (..), Tok (..), TokType (..))
9393import Text.Pandoc.Shared
9494import Text.Parsec.Pos
95+-- import Debug.Trace
9596
9697newtype DottedNum = DottedNum [Int]
9798 deriving (Show)
@@ -350,10 +351,21 @@ isLowerHex :: Char -> Bool
350351isLowerHex x = x >= '0' && x <= '9' || x >= 'a' && x <= 'f'
351352
352353untokenize :: [Tok] -> Text
353−untokenize = mconcat . map untoken
354+untokenize = foldr untokenAccum mempty
355+
356+untokenAccum :: Tok -> Text -> Text
357+untokenAccum (Tok _ (CtrlSeq _) t) accum =
358+ -- insert space to prevent breaking a control sequence; see #5836
359+ case (T.unsnoc t, T.uncons accum) of
360+ (Just (_,c), Just (d,_))
361+ | isLetter c
362+ , isLetter d
363+ -> t <> " " <> accum
364+ _ -> t <> accum
365+untokenAccum (Tok _ _ t) accum = t <> accum
354366
355367untoken :: Tok -> Text
356−untoken (Tok _ _ t) = t
368+untoken t = untokenAccum t mempty
357369
358370toksToString :: [Tok] -> String
359371toksToString = T.unpack . untokenize