git.iko.soy/typeable/pandoc
on master help sign in
Updated for texmath 0.5.
23aae79John MacFarlane
pandoc.cabal+1−1
@@ -171,7 +171,7 @@ Library
171 process >= 1, directory >= 1,
171 process >= 1, directory >= 1,
172 bytestring >= 0.9, zip-archive >= 0.1.1.4,
172 bytestring >= 0.9, zip-archive >= 0.1.1.4,
173 utf8-string >= 0.3, old-time >= 1,
173 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,
175 random, extensible-exceptions,
175 random, extensible-exceptions,
176 citeproc-hs >= 0.3 && < 0.4,
176 citeproc-hs >= 0.3 && < 0.4,
177 pandoc-types == 1.7.*,
177 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
27
27
28Conversion of TeX math to a list of 'Pandoc' inline elements.
28Conversion of TeX math to a list of 'Pandoc' inline elements.
29-}
29-}
30−module Text.Pandoc.Readers.TeXMath (
30+module Text.Pandoc.Readers.TeXMath ( readTeXMath ) where
31− readTeXMath
32− ) where
33
31
34−import Text.ParserCombinators.Parsec
35import Text.Pandoc.Definition
32import Text.Pandoc.Definition
33+import Text.TeXMath.Types
36import Text.TeXMath.Parser
34import Text.TeXMath.Parser
37
35
38-- | Converts a raw TeX math formula to a list of 'Pandoc' inlines.
36-- | Converts a raw TeX math formula to a list of 'Pandoc' inlines.
@@ -40,16 +38,17 @@ import Text.TeXMath.Parser
40-- can't be converted.
38-- can't be converted.
41readTeXMath :: String -- ^ String to parse (assumes @'\n'@ line endings)
39readTeXMath :: String -- ^ String to parse (assumes @'\n'@ line endings)
42 -> [Inline]
40 -> [Inline]
43−readTeXMath inp = case readTeXMath' inp of
41+readTeXMath inp = case texMathToPandoc inp of
44− Nothing -> [Str ("$" ++ inp ++ "$")]
42+ Left _ -> [Str ("$" ++ inp ++ "$")]
45− Just res -> res
43+ Right res -> res
46
44
47−-- | Like 'readTeXMath', but without the default.
45+texMathToPandoc :: String -> Either String [Inline]
48−readTeXMath' :: String -- ^ String to parse (assumes @'\n'@ line endings)
46+texMathToPandoc inp = inp `seq`
49− -> Maybe [Inline]
47+ case parseFormula inp of
50−readTeXMath' inp = case parse formula "formula" inp of
48+ Left err -> Left err
51− Left _ -> Just [Str inp]
49+ Right exps -> case expsToInlines exps of
52− Right exps -> expsToInlines exps
50+ Nothing -> Left "Formula too complex for [Inline]"
51+ Just r -> Right r
53
52
54expsToInlines :: [Exp] -> Maybe [Inline]
53expsToInlines :: [Exp] -> Maybe [Inline]
55expsToInlines xs = do
54expsToInlines xs = do
@@ -111,3 +110,4 @@ expToInlines (EOver (EGrouped [EIdentifier [c]]) (ESymbol Accent [accent])) =
111 _ -> Nothing
110 _ -> Nothing
112expToInlines _ = Nothing
111expToInlines _ = Nothing
113
112
113+