@@ -30,93 +30,13 @@ Conversion of TeX math to a list of 'Pandoc' inline elements.
30module Text.Pandoc.Readers.TeXMath ( readTeXMath ) where
30module Text.Pandoc.Readers.TeXMath ( readTeXMath ) where
32import Text.Pandoc.Definition
32import Text.Pandoc.Definition
33−import Text.TeXMath.Types
33+import Text.TeXMath
34−import Text.TeXMath.Parser
36-- | Converts a raw TeX math formula to a list of 'Pandoc' inlines.
35-- | Converts a raw TeX math formula to a list of 'Pandoc' inlines.
37-- Defaults to raw formula between @$@ characters if entire formula
36-- Defaults to raw formula between @$@ characters if entire formula
38-- can't be converted.
37-- can't be converted.
39readTeXMath :: String -- ^ String to parse (assumes @'\n'@ line endings)
38readTeXMath :: String -- ^ String to parse (assumes @'\n'@ line endings)
40 -> [Inline]
39 -> [Inline]
41−readTeXMath inp = case texMathToPandoc inp of
40+readTeXMath inp = case texMathToPandoc DisplayInline inp of
42 Left _ -> [Str ("$" ++ inp ++ "$")]
41 Left _ -> [Str ("$" ++ inp ++ "$")]
43 Right res -> res
42 Right res -> res
45−texMathToPandoc :: String -> Either String [Inline]
46−texMathToPandoc inp = inp `seq`
47− case parseFormula inp of
49− Right exps -> case expsToInlines exps of
50− Nothing -> Left "Formula too complex for [Inline]"
53−expsToInlines :: [Exp] -> Maybe [Inline]
55− res <- mapM expToInlines xs
58−expToInlines :: Exp -> Maybe [Inline]
59−expToInlines (ENumber s) = Just [Str s]
60−expToInlines (EIdentifier s) = Just [Emph [Str s]]
61−expToInlines (EMathOperator s) = Just [Str s]
62−expToInlines (ESymbol t s) = Just $ addSpace t (Str s)
63− where addSpace Op x = [x, thinspace]
64− addSpace Bin x = [medspace, x, medspace]
65− addSpace Rel x = [widespace, x, widespace]
66− addSpace Pun x = [x, thinspace]
68− thinspace = Str "\x2006"
69− medspace = Str "\x2005"
70− widespace = Str "\x2004"
71−expToInlines (EStretchy x) = expToInlines x
72−expToInlines (EDelimited start end xs) = do
73− xs' <- mapM expToInlines xs
74− return $ [Str start] ++ concat xs' ++ [Str end]
75−expToInlines (EGrouped xs) = expsToInlines xs
76−expToInlines (ESpace "0.167em") = Just [Str "\x2009"]
77−expToInlines (ESpace "0.222em") = Just [Str "\x2005"]
78−expToInlines (ESpace "0.278em") = Just [Str "\x2004"]
79−expToInlines (ESpace "0.333em") = Just [Str "\x2004"]
80−expToInlines (ESpace "1em") = Just [Str "\x2001"]
81−expToInlines (ESpace "2em") = Just [Str "\x2001\x2001"]
82−expToInlines (ESpace _) = Just [Str " "]
83−expToInlines (EBinary _ _ _) = Nothing
84−expToInlines (ESub x y) = do
87− return $ x' ++ [Subscript y']
88−expToInlines (ESuper x y) = do
91− return $ x' ++ [Superscript y']
92−expToInlines (ESubsup x y z) = do
96− return $ x' ++ [Subscript y'] ++ [Superscript z']
97−expToInlines (EDown x y) = expToInlines (ESub x y)
98−expToInlines (EUp x y) = expToInlines (ESuper x y)
99−expToInlines (EDownup x y z) = expToInlines (ESubsup x y z)
100−expToInlines (EText TextNormal x) = Just [Str x]
101−expToInlines (EText TextBold x) = Just [Strong [Str x]]
102−expToInlines (EText TextMonospace x) = Just [Code nullAttr x]
103−expToInlines (EText TextItalic x) = Just [Emph [Str x]]
104−expToInlines (EText _ x) = Just [Str x]
105−expToInlines (EOver (EGrouped [EIdentifier [c]]) (ESymbol Accent [accent])) =
107− '\x203E' -> Just [Emph [Str [c,'\x0304']]] -- bar
108− '\x00B4' -> Just [Emph [Str [c,'\x0301']]] -- acute
109− '\x0060' -> Just [Emph [Str [c,'\x0300']]] -- grave
110− '\x02D8' -> Just [Emph [Str [c,'\x0306']]] -- breve
111− '\x02C7' -> Just [Emph [Str [c,'\x030C']]] -- check
112− '.' -> Just [Emph [Str [c,'\x0307']]] -- dot
113− '\x00B0' -> Just [Emph [Str [c,'\x030A']]] -- ring
114− '\x20D7' -> Just [Emph [Str [c,'\x20D7']]] -- arrow right
115− '\x20D6' -> Just [Emph [Str [c,'\x20D6']]] -- arrow left
116− '\x005E' -> Just [Emph [Str [c,'\x0302']]] -- hat
117− '\x0302' -> Just [Emph [Str [c,'\x0302']]] -- hat
118− '~' -> Just [Emph [Str [c,'\x0303']]] -- tilde
120−expToInlines _ = Nothing