/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: 2007-01-12 15:59:05 UTC
  • Revision ID: distler@golem.ph.utexas.edu-20070112155905-xbx2sdw5zumxr1uj
Added two new methods to the Ruby bindings.

Show diffs side-by-side

added added

removed removed

18
18
#  Usage
19
19
#  -----
20
20
#
21
 
#      There are two public methods
 
21
#      There are four public methods
22
22
#
23
23
#       itex.html_filter(a_string)
24
24
#               converts all itex equations in a_string to MathML, passing the
28
28
#               converts all itex equations in a_string to MathML. Returns just
29
29
#               the MathML equation(s), as a string.
30
30
#
31
 
#  Author: Justin Bonnar <jbonnar@berkeley.edu>
 
31
#       itex.inline_filter(a_string)
 
32
#               treats a_string as an inline equation (automatically supplies
 
33
#               the surrounding $...$, so you don't have to) and converts it
 
34
#               MathML. Returns the MathML inline equation, as a string.
 
35
#
 
36
#       itex.block_filter(a_string)
 
37
#               treats a_string as a block equation (automatically supplies
 
38
#               the surrounding $$...$$, so you don't have to) and converts it
 
39
#               MathML. Returns the MathML block equation, as a string.
 
40
#
 
41
#  Authors: Justin Bonnar <jbonnar@berkeley.edu>
 
42
#           Jacques Distler <distler@golem.ph.utexas.edu>
 
43
#
32
44
#  Placed in the Public Domain
33
45
 
34
46
require 'itex2MML'
50
62
      parse(string, :itex2MML_filter)
51
63
    end
52
64
 
 
65
    def inline_filter(string)
 
66
      parse("\$#{string}\$", :itex2MML_filter)
 
67
    end
 
68
 
 
69
    def block_filter(string)
 
70
      parse("\$\$#{string}\$\$", :itex2MML_filter)
 
71
    end
 
72
 
53
73
  private
54
74
 
55
75
    def parse(string, message)
78
98
      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)$'))
79
99
    end
80
100
 
 
101
    def test_inline_inline
 
102
      itex = Itex2MML::Parser.new
 
103
      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)'))
 
104
    end
 
105
 
81
106
    def test_block_html
82
107
      itex = Itex2MML::Parser.new
83
108
      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)$$'))
88
113
      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)$$'))
89
114
    end
90
115
 
 
116
    def test_block_block
 
117
      itex = Itex2MML::Parser.new
 
118
      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)'))
 
119
    end
 
120
 
91
121
  end
92
122
end