/itexToMML

To download this project, use:
bzr branch http://golem.ph.utexas.edu/~distler/code/itexToMML/

« back to all changes in this revision

Viewing changes to itex-src/itextomml.rb

  • Committer: Jacques Distler
  • Date: 2016-08-14 21:56:27 UTC
  • Revision ID: distler@golem.ph.utexas.edu-20160814215627-s85ojfrb4unki05t
Tags: 1.5.3
itex2MML 1.5.3

Build fixes for Bison3 and Ruby.
Buffer length type: unsigned long => size_t.
Fix an issue on Windows (and possibly other) Ruby platforms.
  (Thanks to Rod McGuire and David Aaron Fendley)
Clean up itex_stringsupport.rb.
Update tests.

Show diffs side-by-side

added added

removed removed

107
107
 
108
108
    def test_inline_html
109
109
      itex = Itex2MML::Parser.new
110
 
      assert_equal("Inline: <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></math>", itex.html_filter('Inline: $\sin(x)$'))
 
110
      assert_equal("Inline: <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></mrow><annotation encoding='application/x-tex'>\\sin(x)</annotation></semantics></math>", itex.html_filter('Inline: $\sin(x)$'))
111
111
    end
112
112
 
113
113
    def test_inline
114
114
      itex = Itex2MML::Parser.new
115
 
      assert_equal("<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></math>", itex.filter('Inline: $\sin(x)$'))
 
115
      assert_equal("<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></mrow><annotation encoding='application/x-tex'>\\sin(x)</annotation></semantics></math>", itex.filter('Inline: $\sin(x)$'))
116
116
    end
117
117
 
118
118
    def test_inline_inline
119
119
      itex = Itex2MML::Parser.new
120
 
      assert_equal("<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></math>", itex.inline_filter('\sin(x)'))
 
120
      assert_equal("<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></mrow><annotation encoding='application/x-tex'>\\sin(x)</annotation></semantics></math>", itex.inline_filter('\sin(x)'))
121
121
    end
122
122
 
123
123
    def test_block_html
124
124
      itex = Itex2MML::Parser.new
125
 
      assert_equal("Block: <math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></math>", itex.html_filter('Block: $$\sin(x)$$'))
 
125
      assert_equal("Block: <math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></mrow><annotation encoding='application/x-tex'>\\sin(x)</annotation></semantics></math>", itex.html_filter('Block: $$\sin(x)$$'))
126
126
    end
127
127
 
128
128
    def test_block
129
129
      itex = Itex2MML::Parser.new
130
 
      assert_equal("<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></math>", itex.filter('Block: $$\sin(x)$$'))
 
130
      assert_equal("<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></mrow><annotation encoding='application/x-tex'>\\sin(x)</annotation></semantics></math>", itex.filter('Block: $$\sin(x)$$'))
131
131
    end
132
132
 
133
133
    def test_block_block
134
134
      itex = Itex2MML::Parser.new
135
 
      assert_equal("<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></math>", itex.block_filter('\sin(x)'))
 
135
      assert_equal("<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></mrow><annotation encoding='application/x-tex'>\\sin(x)</annotation></semantics></math>", itex.block_filter('\sin(x)'))
136
136
    end
137
137
 
138
138
    def test_inline_utf8
139
139
      itex = Itex2MML::Parser.new
140
140
      s = "".respond_to?(:force_encoding) ? "\u00F3" : "\303\263"
141
141
      assert_equal("ecuasi"+ s + "n <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'>" +
142
 
             "<mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></math>",
 
142
             "<semantics><mrow><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></mrow><annotation encoding='application/x-tex'>\\sin(x)</annotation></semantics></math>",
143
143
              itex.html_filter("ecuasi\303\263n $\\sin(x)$"))
144
144
    end
145
145
 
146
146
    def test_inline_utf8_inline
147
147
      itex = Itex2MML::Parser.new
148
 
      assert_equal("<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></math>", itex.filter("ecuasi\303\263n $\\sin(x)$"))
 
148
      assert_equal("<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></mrow><annotation encoding='application/x-tex'>\\sin(x)</annotation></semantics></math>", itex.filter("ecuasi\303\263n $\\sin(x)$"))
149
149
    end
150
150
    
151
151
    def test_utf8_in_svg_foreignObject
152
152
      itex = Itex2MML::Parser.new
153
153
      s = "".respond_to?(:force_encoding) ? "\u2032" : "\342\200\262"
154
 
      assert_equal("<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mi>g" +
155
 
          "</mi><mo>&prime;</mo><mo>=</mo><semantics><annotation-xml encoding=\"SVG1.1\"><svg w" +
156
 
          "idth='40' height='40' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3." +
157
 
          "org/1999/xlink'><foreignObject height='19' width='20' font-size='16' y='0' x='0'><ma" +
158
 
          "th display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>g</mi><mo>" +
159
 
          s + "</mo></math></foreignObject></svg></annotation-xml></semantics></math>",
 
154
      assert_equal("<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics>" +
 
155
          "<mrow><mi>g</mi><mo>&prime;</mo><mo>=</mo><semantics><annotation-xml encoding=\"SVG1.1\">" +
 
156
          "<svg width='40' height='40' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www" +
 
157
          ".w3.org/1999/xlink'><foreignObject height='19' width='20' font-size='16' y='0' x='0'><" +
 
158
          "math display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>g</mi><mo>" + s +
 
159
          "</mo></math></foreignObject></svg></annotation-xml></semantics></mrow><annotation enco" +
 
160
          "ding='application/x-tex'>g&apos; = \\begin{svg}&lt;svg width=&apos;40&apos; height=&apo" +
 
161
          "s;40&apos; xmlns=&apos;http://www.w3.org/2000/svg&apos; xmlns:xlink=&apos;http://www.w" +
 
162
          "3.org/1999/xlink&apos;&gt;&lt;foreignObject height=&apos;19&apos; width=&apos;20&apos;" +
 
163
          " font&#x2d;size=&apos;16&apos; y=&apos;0&apos; x=&apos;0&apos;&gt;&lt;math display=&ap" +
 
164
          "os;inline&apos; xmlns=&apos;http://www.w3.org/1998/Math/MathML&apos;&gt;&lt;mi&gt;g&lt" +
 
165
          ";/mi&gt;&lt;mo&gt;" + s + "&lt;/mo&gt;&lt;/math&gt;&lt;/foreignObject&gt;&lt;/svg&gt;\\" +
 
166
          "end{svg}</annotation></semantics></math>",
160
167
        itex.filter("$g' = \\begin{svg}<svg width='40' height='40' xmlns='http://www.w3.org/20" +
161
168
          "00/svg' xmlns:xlink='http://www.w3.org/1999/xlink'><foreignObject height='19' width='" +
162
169
          "20' font-size='16' y='0' x='0'><math display='inline' xmlns='http://www.w3.org/1998/M" +