/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: 2010-02-20 20:18:52 UTC
  • Revision ID: distler@golem.ph.utexas.edu-20100220201852-xxergbgsx8p2s677
Tags: 1.3.20
Fix Ruby bindings to work in Ruby 1.9

In ruby 1.9, we return a utf-8 encoded
string. 

(Also, it seems my Linux build server is on the fritz,
so no Linux binary for this release.)

Show diffs side-by-side

added added

removed removed

73
73
  private
74
74
 
75
75
    def parse(string, message)
76
 
      string = string.to_str
 
76
      str = as_bytes(string.to_str)
77
77
      self.class.semaphore.synchronize do
78
 
        raise Itex2MML::Error unless Itex2MML.send(message, string, string.length) == 0
79
 
        Itex2MML.itex2MML_output
80
 
      end
81
 
    end
 
78
        raise Itex2MML::Error unless Itex2MML.send(message, str, str.length) == 0
 
79
        as_utf8(Itex2MML.itex2MML_output)
 
80
      end
 
81
    end
 
82
    
 
83
    if "".respond_to?(:force_encoding)
 
84
      def as_bytes(string)
 
85
        string.force_encoding("ASCII-8BIT")
 
86
      end
 
87
    else
 
88
      def as_bytes(string)
 
89
        string
 
90
      end
 
91
    end
 
92
 
 
93
    if "".respond_to?(:force_encoding)
 
94
      def as_utf8(string)
 
95
        string.force_encoding("UTF-8")
 
96
      end
 
97
    else
 
98
      def as_utf8(string)
 
99
        string
 
100
      end
 
101
    end
 
102
 
82
103
  end
83
104
end
84
105
 
120
141
 
121
142
    def test_inline_utf8
122
143
      itex = Itex2MML::Parser.new
123
 
      assert_equal("ecuasi\303\263n <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("ecuasi\303\263n $\\sin(x)$"))
 
144
      s = "".respond_to?(:force_encoding) ? "\u00F3" : "\303\263"
 
145
      assert_equal("ecuasi"+ s + "n <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'>" +
 
146
             "<mi>sin</mi><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo></math>",
 
147
              itex.html_filter("ecuasi\303\263n $\\sin(x)$"))
124
148
    end
125
149
 
126
150
    def test_inline_utf8_inline
127
151
      itex = Itex2MML::Parser.new
128
152
      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)$"))
129
153
    end
 
154
    
 
155
    def test_utf8_in_svg_foreignObject
 
156
      itex = Itex2MML::Parser.new
 
157
      s = "".respond_to?(:force_encoding) ? "\u2032" : "\342\200\262"
 
158
      assert_equal("<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mi>g" +
 
159
          "</mi><mo>&prime;</mo><mo>=</mo><semantics><annotation-xml encoding=\"SVG1.1\"><svg w" +
 
160
          "idth='40' height='40' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3." +
 
161
          "org/1999/xlink'><foreignObject height='19' width='20' font-size='16' y='0' x='0'><ma" +
 
162
          "th display='inline' xmlns='http://www.w3.org/1998/Math/MathML'><mi>g</mi><mo>" +
 
163
          s + "</mo></math></foreignObject></svg></annotation-xml></semantics></math>",
 
164
        itex.filter("$g' = \\begin{svg}<svg width='40' height='40' xmlns='http://www.w3.org/20" +
 
165
          "00/svg' xmlns:xlink='http://www.w3.org/1999/xlink'><foreignObject height='19' width='" +
 
166
          "20' font-size='16' y='0' x='0'><math display='inline' xmlns='http://www.w3.org/1998/M" +
 
167
          "ath/MathML'><mi>g</mi><mo>\342\200\262</mo></math></foreignObject></svg>\\end{svg}$"))
 
168
    end
130
169
 
131
170
  end
132
171
end