git.iko.soy/typeable/pandoc
on master help sign in
Updated for texmath 0.5.
commit23aae79b016711c15d27058b5c902e26f2169261 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 5 Jan 2011, 14:44 (16 years ago) parenteb83f0e
2 files changed+14−14
pandoc.cabal+1−1 src/Text/Pandoc/Readers/TeXMath.hs+13−13
pandoc.cabal+1−1
@@ -171,7 +171,7 @@ Library
171171 process >= 1, directory >= 1,
172172 bytestring >= 0.9, zip-archive >= 0.1.1.4,
173173 utf8-string >= 0.3, old-time >= 1,
174− HTTP >= 4000.0.5, texmath >= 0.4, xml >= 1.3.5 && < 1.4,
174+ HTTP >= 4000.0.5, texmath >= 0.5, xml >= 1.3.5 && < 1.4,
175175 random, extensible-exceptions,
176176 citeproc-hs >= 0.3 && < 0.4,
177177 pandoc-types == 1.7.*,
src/Text/Pandoc/Readers/TeXMath.hs+13−13
@@ -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+