@@ -1581,8 +1581,8 @@ inlineLaTeX = try $ do
15811581
15821582 parseAsMathMLSym :: String -> Maybe Inlines
15831583 parseAsMathMLSym cs = B.str <$> MathMLEntityMap.getUnicode (clean cs)
1584− -- dropWhileEnd would be nice here, but it's not available before base 4.5
1585− where clean = reverse . dropWhile (`elem` ("{}" :: String)) . reverse . drop 1
1584+ -- drop initial backslash and any trailing "{}"
1585+ where clean = dropWhileEnd (`elem` ("{}" :: String)) . drop 1
15861586
15871587 state :: ParserState
15881588 state = def{ stateOptions = def{ readerParseRaw = True }}
@@ -1598,13 +1598,18 @@ inlineLaTeXCommand = try $ do
15981598 rest <- getInput
15991599 case runParser rawLaTeXInline def "source" rest of
16001600 Right (RawInline _ cs) -> do
1601− -- drop any trailing whitespace, those should not be part of the command
1602− let cmdNoSpc = takeWhile (not . isSpace) $ cs
1601+ -- drop any trailing whitespace, those are not be part of the command as
1602+ -- far as org mode is concerned.
1603+ let cmdNoSpc = dropWhileEnd isSpace cs
16031604 let len = length cmdNoSpc
16041605 count len anyChar
16051606 return cmdNoSpc
16061607 _ -> mzero
16071608
1609+-- Taken from Data.OldList.
1610+dropWhileEnd :: (a -> Bool) -> [a] -> [a]
1611+dropWhileEnd p = foldr (\x xs -> if p x && null xs then [] else x : xs) []
1612+
16081613smart :: OrgParser (F Inlines)
16091614smart = do
16101615 getOption readerSmart >>= guard