@@ -265,7 +265,7 @@ List of all DocBook tags, with [x] indicating implemented,
265265[ ] manvolnum - A reference volume number
266266[x] markup - A string of formatting markup in text that is to be
267267 represented literally
268−[ ] mathphrase - A mathematical phrase, an expression that can be represented
268+[x] mathphrase - A mathematical phrase, an expression that can be represented
269269 with ordinary text and a small amount of markup
270270[ ] medialabel - A name that identifies the physical medium on which some
271271 information resides
@@ -727,6 +727,8 @@ parseBlock (Elem e) =
727727 "bibliodiv" -> sect 1
728728 "biblioentry" -> parseMixed para (elContent e)
729729 "bibliomixed" -> parseMixed para (elContent e)
730+ "equation" -> para <$> equation e displayMath
731+ "informalequation" -> para <$> equation e displayMath
730732 "glosssee" -> para . (\ils -> text "See " <> ils <> str ".")
731733 <$> getInlines e
732734 "glossseealso" -> para . (\ils -> text "See also " <> ils <> str ".")
@@ -953,9 +955,9 @@ parseInline (CRef ref) =
953955 return $ maybe (text $ map toUpper ref) text $ lookupEntity ref
954956parseInline (Elem e) =
955957 case qName (elName e) of
956− "equation" -> equation displayMath
957− "informalequation" -> equation displayMath
958− "inlineequation" -> equation math
958+ "equation" -> equation e displayMath
959+ "informalequation" -> equation e displayMath
960+ "inlineequation" -> equation e math
959961 "subscript" -> subscript <$> innerInlines
960962 "superscript" -> superscript <$> innerInlines
961963 "inlinemediaobject" -> getMediaobject e
@@ -1034,13 +1036,6 @@ parseInline (Elem e) =
10341036 _ -> innerInlines
10351037 where innerInlines = (trimInlines . mconcat) <$>
10361038 mapM parseInline (elContent e)
1037− equation constructor = return $ mconcat $
1038− map (constructor . writeTeX)
1039− $ rights
1040− $ map (readMathML . showElement . everywhere (mkT removePrefix))
1041− $ filterChildren (\x -> qName (elName x) == "math" &&
1042− qPrefix (elName x) == Just "mml") e
1043− removePrefix elname = elname { qPrefix = Nothing }
10441039 codeWithLang = do
10451040 let classes' = case attrValue "language" e of
10461041 "" -> []
@@ -1091,3 +1086,45 @@ parseInline (Elem e) =
10911086 xrefLabel = attrValue "xreflabel" el
10921087 descendantContent name = maybe "???" strContent
10931088 . filterElementName (\n -> qName n == name)
1089+
1090+-- | Extract a math equation from an element
1091+--
1092+-- asciidoc can generate Latex math in CDATA sections.
1093+--
1094+-- Note that if some MathML can't be parsed it is silently ignored!
1095+equation
1096+ :: Monad m
1097+ => Element
1098+ -- ^ The element from which to extract a mathematical equation
1099+ -> (String -> Inlines)
1100+ -- ^ A constructor for some Inlines, taking the TeX code as input
1101+ -> m Inlines
1102+equation e constructor =
1103+ return $ mconcat $ map constructor $ mathMLEquations ++ latexEquations
1104+ where
1105+ mathMLEquations :: [String]
1106+ mathMLEquations = map writeTeX $ rights $ readMath
1107+ (\x -> qName (elName x) == "math" && qPrefix (elName x) == Just "mml")
1108+ (readMathML . showElement)
1109+
1110+ latexEquations :: [String]
1111+ latexEquations = readMath (\x -> qName (elName x) == "mathphrase")
1112+ (concat . fmap showVerbatimCData . elContent)
1113+
1114+ readMath :: (Element -> Bool) -> (Element -> b) -> [b]
1115+ readMath childPredicate fromElement =
1116+ ( map (fromElement . everywhere (mkT removePrefix))
1117+ $ filterChildren childPredicate e
1118+ )
1119+
1120+-- | Get the actual text stored in a verbatim CData block. 'showContent'
1121+-- returns the text still surrounded by the [[CDATA]] tags.
1122+--
1123+-- Returns 'showContent' if this is not a verbatim CData
1124+showVerbatimCData :: Content -> String
1125+showVerbatimCData (Text (CData CDataVerbatim d _)) = d
1126+showVerbatimCData c = showContent c
1127+
1128+-- | Set the prefix of a name to 'Nothing'
1129+removePrefix :: QName -> QName
1130+removePrefix elname = elname { qPrefix = Nothing }