Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/mathtype_to_mathml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ def initialize(mathtype)
end

def convert
@mathtype.xpath(".//tmpl[selector='tmINTEG']").each do |ele|
ele.xpath('.//slot/text()').each do |text|
element = Nokogiri::XML::Element.new("mi", @mathtype)
t = Nokogiri::XML::Text.new(text.text, @mathtype)
element.prepend_child(t)
text.replace(element)
end
end

@mathtype.xpath('.//text()').each do |text|
if text.parent.name == "slot" or text.parent.name == "pile"
element = Nokogiri::XML::Element.new("mi", @mathtype)
t = Nokogiri::XML::Text.new(text.text, @mathtype)
element.prepend_child(t)
text.replace(element)
end
end
out = @xslt.transform(@mathtype)
# This is a hack, but XML namespaces are such a pain to get
# right, especially in nokigiri, so... We assume all content is
Expand Down
1 change: 1 addition & 0 deletions lib/transform.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<xsl:include href="xsl/box.xsl" />
<xsl:include href="xsl/fence.xsl" />
<xsl:include href="xsl/arrow.xsl"/>
<xsl:include href="xsl/root.xsl"/>
<xsl:include href="xsl/matrix.xsl"/>
<xsl:include href="xsl/long_embellishment.xsl"/>
<xsl:include href="xsl/long_division.xsl"/>
Expand Down
22 changes: 22 additions & 0 deletions lib/xsl/root.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="1.0">

<!-- SQRT -->

<xsl:template match="tmpl[selector='tmROOT' and variation='tvROOT_SQ']">
<msqrt>
<xsl:apply-templates select="slot[1] | pile[1]"/>
<xsl:apply-templates select="slot[2] | pile[2]"/>
</msqrt>
</xsl:template>

<xsl:template match="tmpl[selector='tmROOT' and variation='tvROOT_NTH']">
<mroot>
<xsl:apply-templates select="slot[1] | pile[1]"/>
<xsl:apply-templates select="slot[2] | pile[2]"/>
</mroot>
</xsl:template>
</xsl:stylesheet>