diff options
Diffstat (limited to 'src/Text/Pandoc/Readers/TeXMath.hs')
-rw-r--r-- | src/Text/Pandoc/Readers/TeXMath.hs | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/src/Text/Pandoc/Readers/TeXMath.hs b/src/Text/Pandoc/Readers/TeXMath.hs index b0c6e86d4..b9a46e8ff 100644 --- a/src/Text/Pandoc/Readers/TeXMath.hs +++ b/src/Text/Pandoc/Readers/TeXMath.hs @@ -27,12 +27,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Conversion of TeX math to a list of 'Pandoc' inline elements. -} -module Text.Pandoc.Readers.TeXMath ( - readTeXMath - ) where +module Text.Pandoc.Readers.TeXMath ( readTeXMath ) where -import Text.ParserCombinators.Parsec import Text.Pandoc.Definition +import Text.TeXMath.Types import Text.TeXMath.Parser -- | Converts a raw TeX math formula to a list of 'Pandoc' inlines. @@ -40,16 +38,17 @@ import Text.TeXMath.Parser -- can't be converted. readTeXMath :: String -- ^ String to parse (assumes @'\n'@ line endings) -> [Inline] -readTeXMath inp = case readTeXMath' inp of - Nothing -> [Str ("$" ++ inp ++ "$")] - Just res -> res +readTeXMath inp = case texMathToPandoc inp of + Left _ -> [Str ("$" ++ inp ++ "$")] + Right res -> res --- | Like 'readTeXMath', but without the default. -readTeXMath' :: String -- ^ String to parse (assumes @'\n'@ line endings) - -> Maybe [Inline] -readTeXMath' inp = case parse formula "formula" inp of - Left _ -> Just [Str inp] - Right exps -> expsToInlines exps +texMathToPandoc :: String -> Either String [Inline] +texMathToPandoc inp = inp `seq` + case parseFormula inp of + Left err -> Left err + Right exps -> case expsToInlines exps of + Nothing -> Left "Formula too complex for [Inline]" + Just r -> Right r expsToInlines :: [Exp] -> Maybe [Inline] expsToInlines xs = do @@ -89,6 +88,26 @@ expToInlines (ESubsup x y z) = do expToInlines (EDown x y) = expToInlines (ESub x y) expToInlines (EUp x y) = expToInlines (ESuper x y) expToInlines (EDownup x y z) = expToInlines (ESubsup x y z) -expToInlines (EText _ x) = Just [Emph [Str x]] +expToInlines (EText "normal" x) = Just [Str x] +expToInlines (EText "bold" x) = Just [Strong [Str x]] +expToInlines (EText "monospace" x) = Just [Code nullAttr x] +expToInlines (EText "italic" x) = Just [Emph [Str x]] +expToInlines (EText _ x) = Just [Str x] +expToInlines (EOver (EGrouped [EIdentifier [c]]) (ESymbol Accent [accent])) = + case accent of + '\x203E' -> Just [Emph [Str [c,'\x0304']]] -- bar + '\x00B4' -> Just [Emph [Str [c,'\x0301']]] -- acute + '\x0060' -> Just [Emph [Str [c,'\x0300']]] -- grave + '\x02D8' -> Just [Emph [Str [c,'\x0306']]] -- breve + '\x02C7' -> Just [Emph [Str [c,'\x030C']]] -- check + '.' -> Just [Emph [Str [c,'\x0307']]] -- dot + '\x00B0' -> Just [Emph [Str [c,'\x030A']]] -- ring + '\x20D7' -> Just [Emph [Str [c,'\x20D7']]] -- arrow right + '\x20D6' -> Just [Emph [Str [c,'\x20D6']]] -- arrow left + '\x005E' -> Just [Emph [Str [c,'\x0302']]] -- hat + '\x0302' -> Just [Emph [Str [c,'\x0302']]] -- hat + '~' -> Just [Emph [Str [c,'\x0303']]] -- tilde + _ -> Nothing expToInlines _ = Nothing + |