@@ -27,12 +27,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2727
2828Conversion of TeX math to a list of 'Pandoc' inline elements.
2929-}
30−module Text.Pandoc.Readers.TeXMath (
31− readTeXMath
32− ) where
30+module Text.Pandoc.Readers.TeXMath ( readTeXMath ) where
3331
34−import Text.ParserCombinators.Parsec
3532import Text.Pandoc.Definition
33+import Text.TeXMath.Types
3634import Text.TeXMath.Parser
3735
3836-- | Converts a raw TeX math formula to a list of 'Pandoc' inlines.
@@ -40,16 +38,17 @@ import Text.TeXMath.Parser
4038-- can't be converted.
4139readTeXMath :: String -- ^ String to parse (assumes @'\n'@ line endings)
4240 -> [Inline]
43−readTeXMath inp = case readTeXMath' inp of
44− Nothing -> [Str ("$" ++ inp ++ "$")]
45− Just res -> res
41+readTeXMath inp = case texMathToPandoc inp of
42+ Left _ -> [Str ("$" ++ inp ++ "$")]
43+ Right res -> res
4644
47−-- | Like 'readTeXMath', but without the default.
48−readTeXMath' :: String -- ^ String to parse (assumes @'\n'@ line endings)
49− -> Maybe [Inline]
50−readTeXMath' inp = case parse formula "formula" inp of
51− Left _ -> Just [Str inp]
52− Right exps -> expsToInlines exps
45+texMathToPandoc :: String -> Either String [Inline]
46+texMathToPandoc inp = inp `seq`
47+ case parseFormula inp of
48+ Left err -> Left err
49+ Right exps -> case expsToInlines exps of
50+ Nothing -> Left "Formula too complex for [Inline]"
51+ Just r -> Right r
5352
5453expsToInlines :: [Exp] -> Maybe [Inline]
5554expsToInlines xs = do
@@ -111,3 +110,4 @@ expToInlines (EOver (EGrouped [EIdentifier [c]]) (ESymbol Accent [accent])) =
111110 _ -> Nothing
112111expToInlines _ = Nothing
113112
113+