@@ -39,12 +39,15 @@ import Text.Pandoc.Parsing hiding ( F, unF, askF, asksF, runF
39 , newline, orderedListMarker
39 , newline, orderedListMarker
40 , parseFromString
40 , parseFromString
41 , updateLastStrPos )
41 , updateLastStrPos )
42+import Text.Pandoc.Readers.LaTeX (inlineCommand, rawLaTeXInline)
42import Text.Pandoc.Shared (compactify', compactify'DL)
43import Text.Pandoc.Shared (compactify', compactify'DL)
44+import Text.Parsec.Pos (updatePosString)
45+import Text.TeXMath (texMathToPandoc, DisplayType(..))
44import Control.Applicative ( Applicative, pure
47import Control.Applicative ( Applicative, pure
45 , (<$>), (<$), (<*>), (<*), (*>), (<**>) )
48 , (<$>), (<$), (<*>), (<*), (*>), (<**>) )
46import Control.Arrow (first)
49import Control.Arrow (first)
47−import Control.Monad (foldM, guard, liftM, liftM2, mzero, when)
50+import Control.Monad (foldM, guard, liftM, liftM2, mplus, mzero, when)
48import Control.Monad.Reader (Reader, runReader, ask, asks)
51import Control.Monad.Reader (Reader, runReader, ask, asks)
49import Data.Char (isAlphaNum, toLower)
52import Data.Char (isAlphaNum, toLower)
50import Data.Default
53import Data.Default
@@ -886,6 +889,7 @@ inline =
886 , verbatim
889 , verbatim
887 , subscript
890 , subscript
888 , superscript
891 , superscript
890 ] <* (guard =<< newlinesCountWithinLimits)
894 ] <* (guard =<< newlinesCountWithinLimits)
891 <?> "inline"
895 <?> "inline"
@@ -1351,3 +1355,29 @@ simpleSubOrSuperString = try $
1351 , mappend <$> option [] ((:[]) <$> oneOf "+-")
1355 , mappend <$> option [] ((:[]) <$> oneOf "+-")
1352 <*> many1 alphaNum
1356 <*> many1 alphaNum
1359+inlineLaTeX :: OrgParser (F Inlines)
1360+inlineLaTeX = try $ do
1361+ cmd <- inlineLaTeXCommand
1362+ maybe mzero returnF $ parseAsMath cmd `mplus` parseAsInlineLaTeX cmd
1364+ parseAsMath :: String -> Maybe Inlines
1365+ parseAsMath cs = maybeRight $ B.fromList <$> texMathToPandoc DisplayInline cs
1367+ parseAsInlineLaTeX :: String -> Maybe Inlines
1368+ parseAsInlineLaTeX cs = maybeRight $ runParser inlineCommand state "" cs
1370+ state :: ParserState
1371+ state = def{ stateOptions = def{ readerParseRaw = True }}
1373+maybeRight :: Either a b -> Maybe b
1374+maybeRight = either (const Nothing) Just
1376+inlineLaTeXCommand :: OrgParser String
1377+inlineLaTeXCommand = try $ do
1380+ case runParser rawLaTeXInline def "source" rest of
1381+ Right (RawInline _ cs) -> cs <$ (setInput $ drop (length cs) rest)
1382+ <* (setPosition $ updatePosString pos cs)