1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
5 from librarian import get_resource
6 from . import TreeEmbed, create_embed, downgrades_to
9 class MathML(TreeEmbed):
10 @downgrades_to('application/x-latex')
13 >>> print(MathML(etree.fromstring(
14 ... '<mat>a < b</mat>'
15 ... )).to_latex().data.strip())
18 >>> print(MathML(etree.fromstring(
19 ... '<mat>< & &lt; A</mat>'
20 ... )).to_latex().data.strip())
24 xslt = etree.parse(get_resource('res/embeds/mathml/mathml2latex.xslt'))
25 output = self.tree.xslt(xslt)
27 # Workaround for entities being preserved in output.
28 # But there should be a better way.
29 text = text.replace('<', '<').replace('&', '&')
30 return create_embed('application/x-latex', data=text)