{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE OverloadedStrings #-}
module Text.TeXMath.Readers.OMML (readOMML) where
import Text.XML.Light
import Data.Maybe (isJust, mapMaybe, fromMaybe)
import Data.List (intercalate)
import Data.Char (isDigit, readLitChar)
import qualified Data.Text as T
import Text.TeXMath.Types
import Text.TeXMath.Shared (fixTree, getSpaceWidth, getOperator)
import Text.TeXMath.Unicode.ToTeX (getSymbolType)
import Control.Applicative ((<$>))
import Text.TeXMath.Unicode.Fonts (getUnicode, textToFont)
readOMML :: T.Text -> Either T.Text [Exp]
readOMML :: Text -> Either Text [Exp]
readOMML Text
s | Just Element
e <- Text -> Maybe Element
forall s. XmlSource s => s -> Maybe Element
parseXMLDoc Text
s =
case Element -> Maybe [Exp]
elemToOMML Element
e of
Just [Exp]
exs -> [Exp] -> Either Text [Exp]
forall a b. b -> Either a b
Right ([Exp] -> Either Text [Exp]) -> [Exp] -> Either Text [Exp]
forall a b. (a -> b) -> a -> b
$ (Exp -> Exp) -> [Exp] -> [Exp]
forall a b. (a -> b) -> [a] -> [b]
map Exp -> Exp
fixTree ([Exp] -> [Exp]) -> [Exp] -> [Exp]
forall a b. (a -> b) -> a -> b
$ [Exp] -> [Exp]
unGroup [Exp]
exs
Maybe [Exp]
Nothing -> Text -> Either Text [Exp]
forall a b. a -> Either a b
Left Text
"xml file was not an <m:oMathPara> or <m:oMath> element."
readOMML Text
_ = Text -> Either Text [Exp]
forall a b. a -> Either a b
Left Text
"Couldn't parse OMML file"
unGroup :: [Exp] -> [Exp]
unGroup :: [Exp] -> [Exp]
unGroup [EGrouped [Exp]
exps] = [Exp]
exps
unGroup [Exp]
exps = [Exp]
exps
elemToOMML :: Element -> Maybe [Exp]
elemToOMML :: Element -> Maybe [Exp]
elemToOMML Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"oMathPara" Element
element = do
let expList :: [[Exp]]
expList = (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Element -> Maybe [Exp]
elemToOMML (Element -> [Element]
elChildren Element
element)
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ ([Exp] -> Exp) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> [a] -> [b]
map (\[Exp]
l -> if [Exp] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Exp]
l Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 then ([Exp] -> Exp
forall a. [a] -> a
head [Exp]
l) else [Exp] -> Exp
EGrouped [Exp]
l) [[Exp]]
expList
elemToOMML Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"oMath" Element
element =
[Exp] -> Maybe [Exp]
forall a. a -> Maybe a
Just ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ [[Exp]] -> [Exp]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Element -> Maybe [Exp]
elemToExps ([Element] -> [[Exp]]) -> [Element] -> [[Exp]]
forall a b. (a -> b) -> a -> b
$ [Element] -> [Element]
unwrapWTags ([Element] -> [Element]) -> [Element] -> [Element]
forall a b. (a -> b) -> a -> b
$ Element -> [Element]
elChildren Element
element
elemToOMML Element
_ = Maybe [Exp]
forall a. Maybe a
Nothing
unwrapWTags :: [Element] -> [Element]
unwrapWTags :: [Element] -> [Element]
unwrapWTags [Element]
elements = (Element -> [Element]) -> [Element] -> [Element]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Element -> [Element]
unwrapChild [Element]
elements
where unwrapChild :: Element -> [Element]
unwrapChild Element
element = case QName -> Maybe String
qPrefix (QName -> Maybe String) -> QName -> Maybe String
forall a b. (a -> b) -> a -> b
$ Element -> QName
elName Element
element of
Just String
"w" -> Element -> [Element]
elChildren Element
element
Maybe String
_ -> [Element
element]
isElem :: String -> String -> Element -> Bool
isElem :: String -> String -> Element -> Bool
isElem String
prefix String
name Element
element =
let qp :: String
qp = String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe String
"" (QName -> Maybe String
qPrefix (Element -> QName
elName Element
element))
in
QName -> String
qName (Element -> QName
elName Element
element) String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
name Bool -> Bool -> Bool
&&
String
qp String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
prefix
hasElemName :: String -> String -> QName -> Bool
hasElemName :: String -> String -> QName -> Bool
hasElemName String
prefix String
name QName
qn =
let qp :: String
qp = String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe String
"" (QName -> Maybe String
qPrefix QName
qn)
in
QName -> String
qName QName
qn String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
name Bool -> Bool -> Bool
&&
String
qp String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
prefix
data OMathRunElem = TextRun T.Text
| LnBrk
| Tab
deriving Int -> OMathRunElem -> ShowS
[OMathRunElem] -> ShowS
OMathRunElem -> String
(Int -> OMathRunElem -> ShowS)
-> (OMathRunElem -> String)
-> ([OMathRunElem] -> ShowS)
-> Show OMathRunElem
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OMathRunElem] -> ShowS
$cshowList :: [OMathRunElem] -> ShowS
show :: OMathRunElem -> String
$cshow :: OMathRunElem -> String
showsPrec :: Int -> OMathRunElem -> ShowS
$cshowsPrec :: Int -> OMathRunElem -> ShowS
Show
data OMathRunTextStyle = NoStyle
| Normal
| Styled { OMathRunTextStyle -> Maybe OMathTextScript
oMathScript :: Maybe OMathTextScript
, OMathRunTextStyle -> Maybe OMathTextStyle
oMathStyle :: Maybe OMathTextStyle }
deriving Int -> OMathRunTextStyle -> ShowS
[OMathRunTextStyle] -> ShowS
OMathRunTextStyle -> String
(Int -> OMathRunTextStyle -> ShowS)
-> (OMathRunTextStyle -> String)
-> ([OMathRunTextStyle] -> ShowS)
-> Show OMathRunTextStyle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OMathRunTextStyle] -> ShowS
$cshowList :: [OMathRunTextStyle] -> ShowS
show :: OMathRunTextStyle -> String
$cshow :: OMathRunTextStyle -> String
showsPrec :: Int -> OMathRunTextStyle -> ShowS
$cshowsPrec :: Int -> OMathRunTextStyle -> ShowS
Show
data OMathTextScript = ORoman
| OScript
| OFraktur
| ODoubleStruck
| OSansSerif
| OMonospace
deriving (Int -> OMathTextScript -> ShowS
[OMathTextScript] -> ShowS
OMathTextScript -> String
(Int -> OMathTextScript -> ShowS)
-> (OMathTextScript -> String)
-> ([OMathTextScript] -> ShowS)
-> Show OMathTextScript
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OMathTextScript] -> ShowS
$cshowList :: [OMathTextScript] -> ShowS
show :: OMathTextScript -> String
$cshow :: OMathTextScript -> String
showsPrec :: Int -> OMathTextScript -> ShowS
$cshowsPrec :: Int -> OMathTextScript -> ShowS
Show, OMathTextScript -> OMathTextScript -> Bool
(OMathTextScript -> OMathTextScript -> Bool)
-> (OMathTextScript -> OMathTextScript -> Bool)
-> Eq OMathTextScript
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OMathTextScript -> OMathTextScript -> Bool
$c/= :: OMathTextScript -> OMathTextScript -> Bool
== :: OMathTextScript -> OMathTextScript -> Bool
$c== :: OMathTextScript -> OMathTextScript -> Bool
Eq)
data OMathTextStyle = OPlain
| OBold
| OItalic
| OBoldItalic
deriving (Int -> OMathTextStyle -> ShowS
[OMathTextStyle] -> ShowS
OMathTextStyle -> String
(Int -> OMathTextStyle -> ShowS)
-> (OMathTextStyle -> String)
-> ([OMathTextStyle] -> ShowS)
-> Show OMathTextStyle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OMathTextStyle] -> ShowS
$cshowList :: [OMathTextStyle] -> ShowS
show :: OMathTextStyle -> String
$cshow :: OMathTextStyle -> String
showsPrec :: Int -> OMathTextStyle -> ShowS
$cshowsPrec :: Int -> OMathTextStyle -> ShowS
Show, OMathTextStyle -> OMathTextStyle -> Bool
(OMathTextStyle -> OMathTextStyle -> Bool)
-> (OMathTextStyle -> OMathTextStyle -> Bool) -> Eq OMathTextStyle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OMathTextStyle -> OMathTextStyle -> Bool
$c/= :: OMathTextStyle -> OMathTextStyle -> Bool
== :: OMathTextStyle -> OMathTextStyle -> Bool
$c== :: OMathTextStyle -> OMathTextStyle -> Bool
Eq)
elemToBase :: Element -> Maybe Exp
elemToBase :: Element -> Maybe Exp
elemToBase Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"e" Element
element = do
[Exp]
bs <- Element -> Maybe [Exp]
elemToBases Element
element
Exp -> Maybe Exp
forall (m :: * -> *) a. Monad m => a -> m a
return (Exp -> Maybe Exp) -> Exp -> Maybe Exp
forall a b. (a -> b) -> a -> b
$ case [Exp]
bs of
(Exp
e : []) -> Exp
e
[Exp]
exps -> [Exp] -> Exp
EGrouped [Exp]
exps
elemToBase Element
_ = Maybe Exp
forall a. Maybe a
Nothing
elemToBases :: Element -> Maybe [Exp]
elemToBases :: Element -> Maybe [Exp]
elemToBases Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"e" Element
element =
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ [[Exp]] -> [Exp]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Element -> Maybe [Exp]
elemToExps' (Element -> [Element]
elChildren Element
element)
elemToBases Element
_ = Maybe [Exp]
forall a. Maybe a
Nothing
filterAmpersand :: Exp -> Exp
filterAmpersand :: Exp -> Exp
filterAmpersand (EIdentifier Text
s) = Text -> Exp
EIdentifier ((Char -> Bool) -> Text -> Text
T.filter (Char
'&' Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/=) Text
s)
filterAmpersand (EText TextType
tt Text
s) = TextType -> Text -> Exp
EText TextType
tt ((Char -> Bool) -> Text -> Text
T.filter (Char
'&' Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/=) Text
s)
filterAmpersand (EStyled TextType
tt [Exp]
exps) = TextType -> [Exp] -> Exp
EStyled TextType
tt ((Exp -> Exp) -> [Exp] -> [Exp]
forall a b. (a -> b) -> [a] -> [b]
map Exp -> Exp
filterAmpersand [Exp]
exps)
filterAmpersand (EGrouped [Exp]
exps) = [Exp] -> Exp
EGrouped ((Exp -> Exp) -> [Exp] -> [Exp]
forall a b. (a -> b) -> [a] -> [b]
map Exp -> Exp
filterAmpersand [Exp]
exps)
filterAmpersand Exp
e = Exp
e
elemToOMathRunTextStyle :: Element -> OMathRunTextStyle
elemToOMathRunTextStyle :: Element -> OMathRunTextStyle
elemToOMathRunTextStyle Element
element
| Just Element
mrPr <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemNameString
"m" String
"rPr") Element
element
, Just Element
_ <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemNameString
"m" String
"nor") Element
mrPr =
OMathRunTextStyle
Normal
| Just Element
mrPr <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemNameString
"m" String
"rPr") Element
element =
let scr :: Maybe OMathTextScript
scr =
case
(QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemNameString
"m" String
"scr") Element
mrPr Maybe Element -> (Element -> Maybe String) -> Maybe String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe String
findAttrBy (String -> String -> QName -> Bool
hasElemNameString
"m" String
"val")
of
Just String
"roman" -> OMathTextScript -> Maybe OMathTextScript
forall a. a -> Maybe a
Just OMathTextScript
ORoman
Just String
"script" -> OMathTextScript -> Maybe OMathTextScript
forall a. a -> Maybe a
Just OMathTextScript
OScript
Just String
"fraktur" -> OMathTextScript -> Maybe OMathTextScript
forall a. a -> Maybe a
Just OMathTextScript
OFraktur
Just String
"double-struck" -> OMathTextScript -> Maybe OMathTextScript
forall a. a -> Maybe a
Just OMathTextScript
ODoubleStruck
Just String
"sans-serif" -> OMathTextScript -> Maybe OMathTextScript
forall a. a -> Maybe a
Just OMathTextScript
OSansSerif
Just String
"monospace" -> OMathTextScript -> Maybe OMathTextScript
forall a. a -> Maybe a
Just OMathTextScript
OMonospace
Maybe String
_ -> Maybe OMathTextScript
forall a. Maybe a
Nothing
sty :: Maybe OMathTextStyle
sty =
case
(QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemNameString
"m" String
"sty") Element
mrPr Maybe Element -> (Element -> Maybe String) -> Maybe String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe String
findAttrBy (String -> String -> QName -> Bool
hasElemNameString
"m" String
"val")
of
Just String
"p" -> OMathTextStyle -> Maybe OMathTextStyle
forall a. a -> Maybe a
Just OMathTextStyle
OPlain
Just String
"b" -> OMathTextStyle -> Maybe OMathTextStyle
forall a. a -> Maybe a
Just OMathTextStyle
OBold
Just String
"i" -> OMathTextStyle -> Maybe OMathTextStyle
forall a. a -> Maybe a
Just OMathTextStyle
OItalic
Just String
"bi" -> OMathTextStyle -> Maybe OMathTextStyle
forall a. a -> Maybe a
Just OMathTextStyle
OBoldItalic
Maybe String
_ -> Maybe OMathTextStyle
forall a. Maybe a
Nothing
in
Styled :: Maybe OMathTextScript -> Maybe OMathTextStyle -> OMathRunTextStyle
Styled { oMathScript :: Maybe OMathTextScript
oMathScript = Maybe OMathTextScript
scr, oMathStyle :: Maybe OMathTextStyle
oMathStyle = Maybe OMathTextStyle
sty }
| Bool
otherwise = OMathRunTextStyle
NoStyle
elemToOMathRunElem :: Element -> Maybe OMathRunElem
elemToOMathRunElem :: Element -> Maybe OMathRunElem
elemToOMathRunElem Element
element
| String -> String -> Element -> Bool
isElem String
"w" String
"t" Element
element
Bool -> Bool -> Bool
|| String -> String -> Element -> Bool
isElem String
"m" String
"t" Element
element
Bool -> Bool -> Bool
|| String -> String -> Element -> Bool
isElem String
"w" String
"delText" Element
element = OMathRunElem -> Maybe OMathRunElem
forall a. a -> Maybe a
Just (OMathRunElem -> Maybe OMathRunElem)
-> OMathRunElem -> Maybe OMathRunElem
forall a b. (a -> b) -> a -> b
$ Text -> OMathRunElem
TextRun (Text -> OMathRunElem) -> Text -> OMathRunElem
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Element -> String
strContent Element
element
| String -> String -> Element -> Bool
isElem String
"w" String
"br" Element
element = OMathRunElem -> Maybe OMathRunElem
forall a. a -> Maybe a
Just OMathRunElem
LnBrk
| String -> String -> Element -> Bool
isElem String
"w" String
"tab" Element
element = OMathRunElem -> Maybe OMathRunElem
forall a. a -> Maybe a
Just OMathRunElem
Tab
| String -> String -> Element -> Bool
isElem String
"w" String
"sym" Element
element = OMathRunElem -> Maybe OMathRunElem
forall a. a -> Maybe a
Just (OMathRunElem -> Maybe OMathRunElem)
-> OMathRunElem -> Maybe OMathRunElem
forall a b. (a -> b) -> a -> b
$ Text -> OMathRunElem
TextRun (Text -> OMathRunElem) -> Text -> OMathRunElem
forall a b. (a -> b) -> a -> b
$ Element -> Text
getSymChar Element
element
| Bool
otherwise = Maybe OMathRunElem
forall a. Maybe a
Nothing
elemToOMathRunElems :: Element -> Maybe [OMathRunElem]
elemToOMathRunElems :: Element -> Maybe [OMathRunElem]
elemToOMathRunElems Element
element
| String -> String -> Element -> Bool
isElem String
"w" String
"r" Element
element
Bool -> Bool -> Bool
|| String -> String -> Element -> Bool
isElem String
"m" String
"r" Element
element =
[OMathRunElem] -> Maybe [OMathRunElem]
forall a. a -> Maybe a
Just ([OMathRunElem] -> Maybe [OMathRunElem])
-> [OMathRunElem] -> Maybe [OMathRunElem]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe OMathRunElem) -> [Element] -> [OMathRunElem]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Element -> Maybe OMathRunElem
elemToOMathRunElem) (Element -> [Element]
elChildren Element
element)
elemToOMathRunElems Element
_ = Maybe [OMathRunElem]
forall a. Maybe a
Nothing
oMathRunElemToText :: OMathRunElem -> T.Text
oMathRunElemToText :: OMathRunElem -> Text
oMathRunElemToText (TextRun Text
s) = Text
s
oMathRunElemToText (OMathRunElem
LnBrk) = Text
"\n"
oMathRunElemToText (OMathRunElem
Tab) = Text
"\t"
oMathRunElemsToText :: [OMathRunElem] -> T.Text
oMathRunElemsToText :: [OMathRunElem] -> Text
oMathRunElemsToText = [Text] -> Text
T.concat ([Text] -> Text)
-> ([OMathRunElem] -> [Text]) -> [OMathRunElem] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (OMathRunElem -> Text) -> [OMathRunElem] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map OMathRunElem -> Text
oMathRunElemToText
oMathRunTextStyleToTextType :: OMathRunTextStyle -> Maybe TextType
oMathRunTextStyleToTextType :: OMathRunTextStyle -> Maybe TextType
oMathRunTextStyleToTextType (OMathRunTextStyle
Normal) = TextType -> Maybe TextType
forall a. a -> Maybe a
Just (TextType -> Maybe TextType) -> TextType -> Maybe TextType
forall a b. (a -> b) -> a -> b
$ TextType
TextNormal
oMathRunTextStyleToTextType (OMathRunTextStyle
NoStyle) = Maybe TextType
forall a. Maybe a
Nothing
oMathRunTextStyleToTextType (Styled Maybe OMathTextScript
scr Maybe OMathTextStyle
sty)
| Just OMathTextStyle
OBold <- Maybe OMathTextStyle
sty
, Just OMathTextScript
OSansSerif <- Maybe OMathTextScript
scr =
TextType -> Maybe TextType
forall a. a -> Maybe a
Just (TextType -> Maybe TextType) -> TextType -> Maybe TextType
forall a b. (a -> b) -> a -> b
$ TextType
TextSansSerifBold
| Just OMathTextStyle
OBoldItalic <- Maybe OMathTextStyle
sty
, Just OMathTextScript
OSansSerif <- Maybe OMathTextScript
scr =
TextType -> Maybe TextType
forall a. a -> Maybe a
Just (TextType -> Maybe TextType) -> TextType -> Maybe TextType
forall a b. (a -> b) -> a -> b
$ TextType
TextSansSerifBoldItalic
| Just OMathTextStyle
OBold <- Maybe OMathTextStyle
sty
, Just OMathTextScript
OScript <- Maybe OMathTextScript
scr =
TextType -> Maybe TextType
forall a. a -> Maybe a
Just (TextType -> Maybe TextType) -> TextType -> Maybe TextType
forall a b. (a -> b) -> a -> b
$ TextType
TextBoldScript
| Just OMathTextStyle
OBold <- Maybe OMathTextStyle
sty
, Just OMathTextScript
OFraktur <- Maybe OMathTextScript
scr =
TextType -> Maybe TextType
forall a. a -> Maybe a
Just (TextType -> Maybe TextType) -> TextType -> Maybe TextType
forall a b. (a -> b) -> a -> b
$ TextType
TextBoldFraktur
| Just OMathTextStyle
OItalic <- Maybe OMathTextStyle
sty
, Just OMathTextScript
OSansSerif <- Maybe OMathTextScript
scr =
TextType -> Maybe TextType
forall a. a -> Maybe a
Just (TextType -> Maybe TextType) -> TextType -> Maybe TextType
forall a b. (a -> b) -> a -> b
$ TextType
TextSansSerifItalic
| Just OMathTextStyle
OBold <- Maybe OMathTextStyle
sty =
TextType -> Maybe TextType
forall a. a -> Maybe a
Just (TextType -> Maybe TextType) -> TextType -> Maybe TextType
forall a b. (a -> b) -> a -> b
$ TextType
TextBold
| Just OMathTextStyle
OItalic <- Maybe OMathTextStyle
sty =
TextType -> Maybe TextType
forall a. a -> Maybe a
Just (TextType -> Maybe TextType) -> TextType -> Maybe TextType
forall a b. (a -> b) -> a -> b
$ TextType
TextItalic
| Just OMathTextScript
OMonospace <- Maybe OMathTextScript
scr =
TextType -> Maybe TextType
forall a. a -> Maybe a
Just (TextType -> Maybe TextType) -> TextType -> Maybe TextType
forall a b. (a -> b) -> a -> b
$ TextType
TextMonospace
| Just OMathTextScript
OSansSerif <- Maybe OMathTextScript
scr =
TextType -> Maybe TextType
forall a. a -> Maybe a
Just (TextType -> Maybe TextType) -> TextType -> Maybe TextType
forall a b. (a -> b) -> a -> b
$ TextType
TextSansSerif
| Just OMathTextScript
ODoubleStruck <- Maybe OMathTextScript
scr =
TextType -> Maybe TextType
forall a. a -> Maybe a
Just (TextType -> Maybe TextType) -> TextType -> Maybe TextType
forall a b. (a -> b) -> a -> b
$ TextType
TextDoubleStruck
| Just OMathTextScript
OScript <- Maybe OMathTextScript
scr =
TextType -> Maybe TextType
forall a. a -> Maybe a
Just (TextType -> Maybe TextType) -> TextType -> Maybe TextType
forall a b. (a -> b) -> a -> b
$ TextType
TextScript
| Just OMathTextScript
OFraktur <- Maybe OMathTextScript
scr =
TextType -> Maybe TextType
forall a. a -> Maybe a
Just (TextType -> Maybe TextType) -> TextType -> Maybe TextType
forall a b. (a -> b) -> a -> b
$ TextType
TextFraktur
| Just OMathTextStyle
OBoldItalic <- Maybe OMathTextStyle
sty =
TextType -> Maybe TextType
forall a. a -> Maybe a
Just (TextType -> Maybe TextType) -> TextType -> Maybe TextType
forall a b. (a -> b) -> a -> b
$ TextType
TextBoldItalic
| Bool
otherwise = Maybe TextType
forall a. Maybe a
Nothing
elemToExps :: Element -> Maybe [Exp]
elemToExps :: Element -> Maybe [Exp]
elemToExps Element
element = [Exp] -> [Exp]
unGroup ([Exp] -> [Exp]) -> Maybe [Exp] -> Maybe [Exp]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Element -> Maybe [Exp]
elemToExps' Element
element
elemToExps' :: Element -> Maybe [Exp]
elemToExps' :: Element -> Maybe [Exp]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"acc" Element
element = do
let chr :: Maybe Char
chr = (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"accPr") Element
element Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"chr") Maybe Element -> (Element -> Maybe String) -> Maybe String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe String
findAttrBy (String -> String -> QName -> Bool
hasElemName String
"m" String
"val") Maybe String -> (String -> Maybe Char) -> Maybe Char
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Char -> Maybe Char
forall a. a -> Maybe a
Just (Char -> Maybe Char) -> (String -> Char) -> String -> Maybe Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Char
forall a. [a] -> a
head
chr' :: Text
chr' = case Maybe Char
chr of
Just Char
c -> Char -> Text
T.singleton Char
c
Maybe Char
Nothing -> Text
"\x302"
Exp
baseExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"e") Element
element Maybe Element -> (Element -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Element -> Maybe Exp
elemToBase
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ [Bool -> Exp -> Exp -> Exp
EOver Bool
False Exp
baseExp (TeXSymbolType -> Text -> Exp
ESymbol TeXSymbolType
Accent Text
chr')]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"bar" Element
element = do
String
pos <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"barPr") Element
element Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"pos") Maybe Element -> (Element -> Maybe String) -> Maybe String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe String
findAttrBy (String -> String -> QName -> Bool
hasElemName String
"m" String
"val")
Exp
baseExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"e") Element
element Maybe Element -> (Element -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Element -> Maybe Exp
elemToBase
case String
pos of
String
"top" -> [Exp] -> Maybe [Exp]
forall a. a -> Maybe a
Just [Bool -> Exp -> Exp -> Exp
EOver Bool
False Exp
baseExp (TeXSymbolType -> Text -> Exp
ESymbol TeXSymbolType
TOver Text
"\773")]
String
"bot" -> [Exp] -> Maybe [Exp]
forall a. a -> Maybe a
Just [Bool -> Exp -> Exp -> Exp
EUnder Bool
False Exp
baseExp (TeXSymbolType -> Text -> Exp
ESymbol TeXSymbolType
TUnder Text
"\818")]
String
_ -> Maybe [Exp]
forall a. Maybe a
Nothing
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"box" Element
element = do
Exp
baseExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"e") Element
element Maybe Element -> (Element -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Element -> Maybe Exp
elemToBase
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return [Exp
baseExp]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"borderBox" Element
element = do
Exp
baseExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"e") Element
element Maybe Element -> (Element -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Element -> Maybe Exp
elemToBase
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return [Exp -> Exp
EBoxed Exp
baseExp]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"d" Element
element =
let baseExps :: [[Exp]]
baseExps = (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe
Element -> Maybe [Exp]
elemToBases
(Element -> [Element]
elChildren Element
element)
inDelimExps :: [[Either a Exp]]
inDelimExps = ([Exp] -> [Either a Exp]) -> [[Exp]] -> [[Either a Exp]]
forall a b. (a -> b) -> [a] -> [b]
map ((Exp -> Either a Exp) -> [Exp] -> [Either a Exp]
forall a b. (a -> b) -> [a] -> [b]
map Exp -> Either a Exp
forall a b. b -> Either a b
Right) [[Exp]]
baseExps
dPr :: Maybe Element
dPr = (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"dPr") Element
element
begChr :: Maybe Char
begChr = Maybe Element
dPr Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"begChr") Maybe Element -> (Element -> Maybe String) -> Maybe String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe String
findAttrBy (String -> String -> QName -> Bool
hasElemName String
"m" String
"val") Maybe String -> (String -> Maybe Char) -> Maybe Char
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(\String
c -> if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
c then (Char -> Maybe Char
forall a. a -> Maybe a
Just Char
' ') else (Char -> Maybe Char
forall a. a -> Maybe a
Just (Char -> Maybe Char) -> Char -> Maybe Char
forall a b. (a -> b) -> a -> b
$ String -> Char
forall a. [a] -> a
head String
c))
sepChr :: Maybe Char
sepChr = Maybe Element
dPr Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"sepChr") Maybe Element -> (Element -> Maybe String) -> Maybe String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe String
findAttrBy (String -> String -> QName -> Bool
hasElemName String
"m" String
"val") Maybe String -> (String -> Maybe Char) -> Maybe Char
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(\String
c -> if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
c then (Char -> Maybe Char
forall a. a -> Maybe a
Just Char
' ') else (Char -> Maybe Char
forall a. a -> Maybe a
Just (Char -> Maybe Char) -> Char -> Maybe Char
forall a b. (a -> b) -> a -> b
$ String -> Char
forall a. [a] -> a
head String
c))
endChr :: Maybe Char
endChr = Maybe Element
dPr Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"endChr") Maybe Element -> (Element -> Maybe String) -> Maybe String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe String
findAttrBy (String -> String -> QName -> Bool
hasElemName String
"m" String
"val") Maybe String -> (String -> Maybe Char) -> Maybe Char
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(\String
c -> if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
c then (Char -> Maybe Char
forall a. a -> Maybe a
Just Char
' ') else (Char -> Maybe Char
forall a. a -> Maybe a
Just (Char -> Maybe Char) -> Char -> Maybe Char
forall a b. (a -> b) -> a -> b
$ String -> Char
forall a. [a] -> a
head String
c))
beg :: Text
beg = Text -> (Char -> Text) -> Maybe Char -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"(" Char -> Text
T.singleton Maybe Char
begChr
end :: Text
end = Text -> (Char -> Text) -> Maybe Char -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
")" Char -> Text
T.singleton Maybe Char
endChr
sep :: Text
sep = Text -> (Char -> Text) -> Maybe Char -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"|" Char -> Text
T.singleton Maybe Char
sepChr
exps :: [Either Text Exp]
exps = [Either Text Exp] -> [[Either Text Exp]] -> [Either Text Exp]
forall a. [a] -> [[a]] -> [a]
intercalate [Text -> Either Text Exp
forall a b. a -> Either a b
Left Text
sep] [[Either Text Exp]]
forall a. [[Either a Exp]]
inDelimExps
in
[Exp] -> Maybe [Exp]
forall a. a -> Maybe a
Just [Text -> Text -> [Either Text Exp] -> Exp
EDelimited Text
beg Text
end [Either Text Exp]
exps]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"eqArr" Element
element =
let expLst :: [[Exp]]
expLst = (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Element -> Maybe [Exp]
elemToBases (Element -> [Element]
elChildren Element
element)
expLst' :: [[[Exp]]]
expLst' = ([Exp] -> [[Exp]]) -> [[Exp]] -> [[[Exp]]]
forall a b. (a -> b) -> [a] -> [b]
map (\[Exp]
es -> [(Exp -> Exp) -> [Exp] -> [Exp]
forall a b. (a -> b) -> [a] -> [b]
map Exp -> Exp
filterAmpersand [Exp]
es]) [[Exp]]
expLst
in
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return [[Alignment] -> [[[Exp]]] -> Exp
EArray [] [[[Exp]]]
expLst']
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"f" Element
element = do
Element
num <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"num") Element
element
Element
den <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"den") Element
element
let numExp :: Exp
numExp = [Exp] -> Exp
EGrouped ([Exp] -> Exp) -> [Exp] -> Exp
forall a b. (a -> b) -> a -> b
$ [[Exp]] -> [Exp]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Element -> Maybe [Exp]
elemToExps) (Element -> [Element]
elChildren Element
num)
denExp :: Exp
denExp = [Exp] -> Exp
EGrouped ([Exp] -> Exp) -> [Exp] -> Exp
forall a b. (a -> b) -> a -> b
$ [[Exp]] -> [Exp]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Element -> Maybe [Exp]
elemToExps) (Element -> [Element]
elChildren Element
den)
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ [FractionType -> Exp -> Exp -> Exp
EFraction FractionType
NormalFrac Exp
numExp Exp
denExp]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"func" Element
element = do
Element
fName <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"fName") Element
element
Exp
baseExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"e") Element
element Maybe Element -> (Element -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Element -> Maybe Exp
elemToBase
let fnameExp :: Exp
fnameExp = case [[Exp]] -> [Exp]
forall a. Monoid a => [a] -> a
mconcat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Element -> Maybe [Exp]
elemToExps') (Element -> [Element]
elChildren Element
fName) of
[Exp
x] -> Exp
x
[Exp]
xs -> [Exp] -> Exp
EGrouped [Exp]
xs
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return [Exp
fnameExp, Exp
baseExp]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"groupChr" Element
element = do
let gPr :: Maybe Element
gPr = (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"groupChrPr") Element
element
chr :: Maybe String
chr = Maybe Element
gPr Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"chr") Maybe Element -> (Element -> Maybe String) -> Maybe String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe String
findAttrBy (String -> String -> QName -> Bool
hasElemName String
"m" String
"val")
pos :: Maybe String
pos = Maybe Element
gPr Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"pos") Maybe Element -> (Element -> Maybe String) -> Maybe String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe String
findAttrBy (String -> String -> QName -> Bool
hasElemName String
"m" String
"val")
justif :: Maybe String
justif = Maybe Element
gPr Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"vertJC") Maybe Element -> (Element -> Maybe String) -> Maybe String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe String
findAttrBy (String -> String -> QName -> Bool
hasElemName String
"m" String
"val")
Exp
baseExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"e") Element
element Maybe Element -> (Element -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Element -> Maybe Exp
elemToBase
case Maybe String
pos of
Just String
"top" ->
let chr' :: Text
chr' = case Maybe String
chr of
Just (Char
c:String
_) -> Char -> Text
T.singleton Char
c
Maybe String
_ -> Text
"\65079"
in
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$
case Maybe String
justif of
Just String
"top" -> [Bool -> Exp -> Exp -> Exp
EUnder Bool
False (TeXSymbolType -> Text -> Exp
ESymbol TeXSymbolType
TOver Text
chr') Exp
baseExp]
Maybe String
_ -> [Bool -> Exp -> Exp -> Exp
EOver Bool
False Exp
baseExp (TeXSymbolType -> Text -> Exp
ESymbol TeXSymbolType
TOver Text
chr')]
Maybe String
_ ->
let chr' :: Text
chr' = case Maybe String
chr of
Just (Char
c:String
_) -> Char -> Text
T.singleton Char
c
Maybe String
_ -> Text
"\65080"
in
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$
case Maybe String
justif of
Just String
"top" -> [Bool -> Exp -> Exp -> Exp
EUnder Bool
False Exp
baseExp (TeXSymbolType -> Text -> Exp
ESymbol TeXSymbolType
TUnder Text
chr')]
Maybe String
_ -> [Bool -> Exp -> Exp -> Exp
EOver Bool
False (TeXSymbolType -> Text -> Exp
ESymbol TeXSymbolType
TUnder Text
chr') Exp
baseExp]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"limLow" Element
element = do
Exp
baseExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"e") Element
element
Maybe Element -> (Element -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Element -> Maybe Exp
elemToBase
Exp
limExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"lim") Element
element
Maybe Element -> (Element -> Maybe [Exp]) -> Maybe [Exp]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\Element
e -> [Exp] -> Maybe [Exp]
forall a. a -> Maybe a
Just ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ [[Exp]] -> [Exp]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Element -> Maybe [Exp]
elemToExps) (Element -> [Element]
elChildren Element
e))
Maybe [Exp] -> ([Exp] -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Exp -> Maybe Exp
forall (m :: * -> *) a. Monad m => a -> m a
return (Exp -> Maybe Exp) -> ([Exp] -> Exp) -> [Exp] -> Maybe Exp
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Exp] -> Exp
EGrouped)
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return [Bool -> Exp -> Exp -> Exp
EUnder Bool
True Exp
baseExp Exp
limExp]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"limUpp" Element
element = do
Exp
baseExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"e") Element
element
Maybe Element -> (Element -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Element -> Maybe Exp
elemToBase
Exp
limExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"lim") Element
element
Maybe Element -> (Element -> Maybe [Exp]) -> Maybe [Exp]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\Element
e -> [Exp] -> Maybe [Exp]
forall a. a -> Maybe a
Just ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ [[Exp]] -> [Exp]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Element -> Maybe [Exp]
elemToExps) (Element -> [Element]
elChildren Element
e))
Maybe [Exp] -> ([Exp] -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Exp -> Maybe Exp
forall (m :: * -> *) a. Monad m => a -> m a
return (Exp -> Maybe Exp) -> ([Exp] -> Exp) -> [Exp] -> Maybe Exp
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Exp] -> Exp
EGrouped)
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return [Bool -> Exp -> Exp -> Exp
EOver Bool
True Exp
baseExp Exp
limExp]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"m" Element
element =
let rows :: [Element]
rows = (QName -> Bool) -> Element -> [Element]
filterChildrenName (String -> String -> QName -> Bool
hasElemName String
"m" String
"mr") Element
element
rowExps :: [[[Exp]]]
rowExps = (Element -> [[Exp]]) -> [Element] -> [[[Exp]]]
forall a b. (a -> b) -> [a] -> [b]
map
(\Element
mr -> (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe
Element -> Maybe [Exp]
elemToBases
(Element -> [Element]
elChildren Element
mr))
[Element]
rows
in
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return [[Alignment] -> [[[Exp]]] -> Exp
EArray [Alignment
AlignCenter] [[[Exp]]]
rowExps]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"nary" Element
element = do
let naryPr :: Maybe Element
naryPr = (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"naryPr") Element
element
naryChr :: Maybe String
naryChr = Maybe Element
naryPr Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"chr") Maybe Element -> (Element -> Maybe String) -> Maybe String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe String
findAttrBy (String -> String -> QName -> Bool
hasElemName String
"m" String
"val")
opChr :: Text
opChr = case Maybe String
naryChr of
Just (Char
c:String
_) -> Char -> Text
T.singleton Char
c
Maybe String
_ -> Text
"\8747"
limLoc :: Maybe String
limLoc = Maybe Element
naryPr Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"limLoc") Maybe Element -> (Element -> Maybe String) -> Maybe String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(QName -> Bool) -> Element -> Maybe String
findAttrBy (String -> String -> QName -> Bool
hasElemName String
"m" String
"val")
[Exp]
subExps <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"sub") Element
element Maybe Element -> (Element -> Maybe [Exp]) -> Maybe [Exp]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(\Element
e -> [Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ [[Exp]] -> [Exp]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Element -> Maybe [Exp]
elemToExps) (Element -> [Element]
elChildren Element
e))
[Exp]
supExps <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"sup") Element
element Maybe Element -> (Element -> Maybe [Exp]) -> Maybe [Exp]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(\Element
e -> [Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ [[Exp]] -> [Exp]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Element -> Maybe [Exp]
elemToExps) (Element -> [Element]
elChildren Element
e))
Exp
baseExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"e") Element
element Maybe Element -> (Element -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Element -> Maybe Exp
elemToBase
case Maybe String
limLoc of
Just String
"undOvr" -> [Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return [Bool -> Exp -> Exp -> Exp -> Exp
EUnderover Bool
True
(TeXSymbolType -> Text -> Exp
ESymbol TeXSymbolType
Op Text
opChr)
([Exp] -> Exp
EGrouped [Exp]
subExps)
([Exp] -> Exp
EGrouped [Exp]
supExps)
, Exp
baseExp]
Maybe String
_ -> [Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return [Exp -> Exp -> Exp -> Exp
ESubsup
(TeXSymbolType -> Text -> Exp
ESymbol TeXSymbolType
Op Text
opChr)
([Exp] -> Exp
EGrouped [Exp]
subExps)
([Exp] -> Exp
EGrouped [Exp]
supExps)
, Exp
baseExp]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"phant" Element
element = do
Exp
baseExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"e") Element
element Maybe Element -> (Element -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Element -> Maybe Exp
elemToBase
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return [Exp -> Exp
EPhantom Exp
baseExp]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"rad" Element
element = do
[Exp]
degExps <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"deg") Element
element Maybe Element -> (Element -> Maybe [Exp]) -> Maybe [Exp]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(\Element
e -> [Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ [[Exp]] -> [Exp]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Element -> Maybe [Exp]
elemToExps) (Element -> [Element]
elChildren Element
e))
Exp
baseExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"e") Element
element Maybe Element -> (Element -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Element -> Maybe Exp
elemToBase
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ case [Exp]
degExps of
[] -> [Exp -> Exp
ESqrt Exp
baseExp]
[Exp]
ds -> [Exp -> Exp -> Exp
ERoot ([Exp] -> Exp
EGrouped [Exp]
ds) Exp
baseExp]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"sPre" Element
element = do
[Exp]
subExps <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"sub") Element
element Maybe Element -> (Element -> Maybe [Exp]) -> Maybe [Exp]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(\Element
e -> [Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ [[Exp]] -> [Exp]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Element -> Maybe [Exp]
elemToExps) (Element -> [Element]
elChildren Element
e))
[Exp]
supExps <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"sup") Element
element Maybe Element -> (Element -> Maybe [Exp]) -> Maybe [Exp]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(\Element
e -> [Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ [[Exp]] -> [Exp]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Element -> Maybe [Exp]
elemToExps) (Element -> [Element]
elChildren Element
e))
Exp
baseExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"e") Element
element Maybe Element -> (Element -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Element -> Maybe Exp
elemToBase
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return [Exp -> Exp -> Exp -> Exp
ESubsup
(Text -> Exp
EIdentifier Text
"")
([Exp] -> Exp
EGrouped [Exp]
subExps)
([Exp] -> Exp
EGrouped [Exp]
supExps)
, Exp
baseExp]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"sSub" Element
element = do
Exp
baseExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"e") Element
element Maybe Element -> (Element -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Element -> Maybe Exp
elemToBase
[Exp]
subExps <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"sub") Element
element Maybe Element -> (Element -> Maybe [Exp]) -> Maybe [Exp]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(\Element
e -> [Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ [[Exp]] -> [Exp]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Element -> Maybe [Exp]
elemToExps) (Element -> [Element]
elChildren Element
e))
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return [Exp -> Exp -> Exp
ESub Exp
baseExp ([Exp] -> Exp
EGrouped [Exp]
subExps)]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"sSubSup" Element
element = do
Exp
baseExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"e") Element
element Maybe Element -> (Element -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Element -> Maybe Exp
elemToBase
[Exp]
subExps <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"sub") Element
element Maybe Element -> (Element -> Maybe [Exp]) -> Maybe [Exp]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(\Element
e -> [Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ [[Exp]] -> [Exp]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Element -> Maybe [Exp]
elemToExps) (Element -> [Element]
elChildren Element
e))
[Exp]
supExps <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"sup") Element
element Maybe Element -> (Element -> Maybe [Exp]) -> Maybe [Exp]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(\Element
e -> [Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ [[Exp]] -> [Exp]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Element -> Maybe [Exp]
elemToExps) (Element -> [Element]
elChildren Element
e))
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return [Exp -> Exp -> Exp -> Exp
ESubsup Exp
baseExp ([Exp] -> Exp
EGrouped [Exp]
subExps) ([Exp] -> Exp
EGrouped [Exp]
supExps)]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"sSup" Element
element = do
Exp
baseExp <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"e") Element
element Maybe Element -> (Element -> Maybe Exp) -> Maybe Exp
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Element -> Maybe Exp
elemToBase
[Exp]
supExps <- (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"sup") Element
element Maybe Element -> (Element -> Maybe [Exp]) -> Maybe [Exp]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(\Element
e -> [Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$ [[Exp]] -> [Exp]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Exp]] -> [Exp]) -> [[Exp]] -> [Exp]
forall a b. (a -> b) -> a -> b
$ (Element -> Maybe [Exp]) -> [Element] -> [[Exp]]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Element -> Maybe [Exp]
elemToExps) (Element -> [Element]
elChildren Element
e))
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return [Exp -> Exp -> Exp
ESuper Exp
baseExp ([Exp] -> Exp
EGrouped [Exp]
supExps)]
elemToExps' Element
element | String -> String -> Element -> Bool
isElem String
"m" String
"r" Element
element = do
let mrPr :: Maybe Element
mrPr = (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"rPr") Element
element
lit :: Maybe Element
lit = Maybe Element
mrPr Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"lit")
nor :: Maybe Element
nor = Maybe Element
mrPr Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> String -> QName -> Bool
hasElemName String
"m" String
"nor")
txtSty :: Maybe TextType
txtSty = OMathRunTextStyle -> Maybe TextType
oMathRunTextStyleToTextType (OMathRunTextStyle -> Maybe TextType)
-> OMathRunTextStyle -> Maybe TextType
forall a b. (a -> b) -> a -> b
$ Element -> OMathRunTextStyle
elemToOMathRunTextStyle Element
element
[OMathRunElem]
mrElems <- Element -> Maybe [OMathRunElem]
elemToOMathRunElems Element
element
[Exp] -> Maybe [Exp]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Exp] -> Maybe [Exp]) -> [Exp] -> Maybe [Exp]
forall a b. (a -> b) -> a -> b
$
if Maybe Element -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Maybe Element
lit Bool -> Bool -> Bool
&& Maybe Element -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Maybe Element
nor
then case Maybe TextType
txtSty of
Maybe TextType
Nothing ->
Text -> [Exp]
interpretText (Text -> [Exp]) -> Text -> [Exp]
forall a b. (a -> b) -> a -> b
$ [OMathRunElem] -> Text
oMathRunElemsToText [OMathRunElem]
mrElems
Just TextType
textSty ->
[TextType -> [Exp] -> Exp
EStyled TextType
textSty ([Exp] -> Exp) -> [Exp] -> Exp
forall a b. (a -> b) -> a -> b
$ Text -> [Exp]
interpretText (Text -> [Exp]) -> Text -> [Exp]
forall a b. (a -> b) -> a -> b
$ [OMathRunElem] -> Text
oMathRunElemsToText [OMathRunElem]
mrElems]
else [TextType -> Text -> Exp
EText (TextType -> Maybe TextType -> TextType
forall a. a -> Maybe a -> a
fromMaybe TextType
TextNormal Maybe TextType
txtSty) (Text -> Exp) -> Text -> Exp
forall a b. (a -> b) -> a -> b
$ [OMathRunElem] -> Text
oMathRunElemsToText [OMathRunElem]
mrElems]
elemToExps' Element
_ = Maybe [Exp]
forall a. Maybe a
Nothing
interpretChar :: Char -> Exp
interpretChar :: Char -> Exp
interpretChar Char
c | Char -> Bool
isDigit Char
c = Text -> Exp
ENumber (Text -> Exp) -> Text -> Exp
forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton Char
c
interpretChar Char
c = case Char -> TeXSymbolType
getSymbolType Char
c of
TeXSymbolType
Alpha -> Text -> Exp
EIdentifier Text
c'
TeXSymbolType
Ord | Char -> Bool
isDigit Char
c -> Text -> Exp
ENumber Text
c'
| Bool
otherwise -> case Char -> Maybe Rational
getSpaceWidth Char
c of
Just Rational
x -> Rational -> Exp
ESpace Rational
x
Maybe Rational
Nothing -> TeXSymbolType -> Text -> Exp
ESymbol TeXSymbolType
Ord Text
c'
TeXSymbolType
symType -> TeXSymbolType -> Text -> Exp
ESymbol TeXSymbolType
symType Text
c'
where
c' :: Text
c' = Char -> Text
T.singleton Char
c
interpretText :: T.Text -> [Exp]
interpretText :: Text -> [Exp]
interpretText Text
s
| Just (Char
c, Text
xs) <- Text -> Maybe (Char, Text)
T.uncons Text
s
, Text -> Bool
T.null Text
xs = [Char -> Exp
interpretChar Char
c]
| (Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isDigit Text
s = [Text -> Exp
ENumber Text
s]
| Maybe TeX -> Bool
forall a. Maybe a -> Bool
isJust (Exp -> Maybe TeX
getOperator (Text -> Exp
EMathOperator Text
s))
= [Text -> Exp
EMathOperator Text
s]
| Bool
otherwise =
case (Char -> Exp) -> String -> [Exp]
forall a b. (a -> b) -> [a] -> [b]
map Char -> Exp
interpretChar (Text -> String
T.unpack Text
s) of
[Exp]
xs | (Exp -> Bool) -> [Exp] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Exp -> Bool
isIdentifierOrSpace [Exp]
xs -> [TextType -> Text -> Exp
EText TextType
TextNormal Text
s]
| Bool
otherwise -> [Exp]
xs
where isIdentifierOrSpace :: Exp -> Bool
isIdentifierOrSpace (EIdentifier Text
_) = Bool
True
isIdentifierOrSpace (ESpace Rational
_) = Bool
True
isIdentifierOrSpace Exp
_ = Bool
False
getSymChar :: Element -> T.Text
getSymChar :: Element -> Text
getSymChar Element
element
| Just String
s <- ShowS
lowerFromPrivate ShowS -> Maybe String -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe String
getCodepoint
, Just Font
font <- Maybe Font
getFont =
let [(Char
char, String
_)] = ReadS Char
readLitChar (String
"\\x" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s) in
Text -> (Char -> Text) -> Maybe Char -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" Char -> Text
T.singleton (Maybe Char -> Text) -> Maybe Char -> Text
forall a b. (a -> b) -> a -> b
$ Font -> Char -> Maybe Char
getUnicode Font
font Char
char
where
getCodepoint :: Maybe String
getCodepoint = (QName -> Bool) -> Element -> Maybe String
findAttrBy (String -> String -> QName -> Bool
hasElemName String
"w" String
"char") Element
element
getFont :: Maybe Font
getFont = (Text -> Maybe Font
textToFont (Text -> Maybe Font) -> (String -> Text) -> String -> Maybe Font
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack) (String -> Maybe Font) -> Maybe String -> Maybe Font
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (QName -> Bool) -> Element -> Maybe String
findAttrBy (String -> String -> QName -> Bool
hasElemName String
"w" String
"font") Element
element
lowerFromPrivate :: ShowS
lowerFromPrivate (Char
'F':String
xs) = Char
'0'Char -> ShowS
forall a. a -> [a] -> [a]
:String
xs
lowerFromPrivate String
xs = String
xs
getSymChar Element
_ = Text
""