@@ -586,7 +586,7 @@ uri = try $ do
586586mathInlineWith :: Stream s m Char => String -> String -> ParserT s st m String
587587mathInlineWith op cl = try $ do
588588 string op
589− notFollowedBy space
589+ when (op == "$") $ notFollowedBy space
590590 words' <- many1Till (count 1 (noneOf " \t\n\\")
591591 <|> (char '\\' >>
592592 -- This next clause is needed because \text{..} can
@@ -600,7 +600,7 @@ mathInlineWith op cl = try $ do
600600 return " "
601601 ) (try $ string cl)
602602 notFollowedBy digit -- to prevent capture of $5
603− return $ concat words'
603+ return $ trim $ concat words'
604604 where
605605 inBalancedBraces :: Stream s m Char => Int -> String -> ParserT s st m String
606606 inBalancedBraces 0 "" = do