git.iko.soy/typeable/pandoc
on master help sign in
Moved most of Text.Pandoc.Readers.TeXMath to texmath 0.6.4.
commit74250b6c351180cb350150b8069824111193b913 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 24 Aug 2013, 16:10 (13 years ago) parent6e222ce
2 files changed+3−83
pandoc.cabal+1−1 src/Text/Pandoc/Readers/TeXMath.hs+2−82
pandoc.cabal+1−1
@@ -246,7 +246,7 @@ Library
246246 old-locale >= 1 && < 1.1,
247247 time >= 1.2 && < 1.5,
248248 HTTP >= 4000.0.5 && < 4000.3,
249− texmath >= 0.6.3 && < 0.7,
249+ texmath >= 0.6.4 && < 0.7,
250250 xml >= 1.3.12 && < 1.4,
251251 random >= 1 && < 1.1,
252252 extensible-exceptions >= 0.1 && < 0.2,
src/Text/Pandoc/Readers/TeXMath.hs+2−82
@@ -30,93 +30,13 @@ Conversion of TeX math to a list of 'Pandoc' inline elements.
3030module Text.Pandoc.Readers.TeXMath ( readTeXMath ) where
3131
3232import Text.Pandoc.Definition
33−import Text.TeXMath.Types
34−import Text.TeXMath.Parser
33+import Text.TeXMath
3534
3635-- | Converts a raw TeX math formula to a list of 'Pandoc' inlines.
3736-- Defaults to raw formula between @$@ characters if entire formula
3837-- can't be converted.
3938readTeXMath :: String -- ^ String to parse (assumes @'\n'@ line endings)
4039 -> [Inline]
41−readTeXMath inp = case texMathToPandoc inp of
40+readTeXMath inp = case texMathToPandoc DisplayInline inp of
4241 Left _ -> [Str ("$" ++ inp ++ "$")]
4342 Right res -> res
44−
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
52−
53−expsToInlines :: [Exp] -> Maybe [Inline]
54−expsToInlines xs = do
55− res <- mapM expToInlines xs
56− return (concat res)
57−
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]
67− addSpace _ x = [x]
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
85− x' <- expToInlines x
86− y' <- expToInlines y
87− return $ x' ++ [Subscript y']
88−expToInlines (ESuper x y) = do
89− x' <- expToInlines x
90− y' <- expToInlines y
91− return $ x' ++ [Superscript y']
92−expToInlines (ESubsup x y z) = do
93− x' <- expToInlines x
94− y' <- expToInlines y
95− z' <- expToInlines z
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])) =
106− case accent of
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
119− _ -> Nothing
120−expToInlines _ = Nothing
121−
122−