math_ml 0.13 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,227 +1,235 @@
1
1
  module MathML
2
- class Element < XMLElement
3
- attr_reader :display_style
4
-
5
- def as_display_style
6
- @display_style = true
7
- self
8
- end
9
- end
10
-
11
- module Variant
12
- NORMAL = "normal"
13
- BOLD = "bold"
14
- BOLD_ITALIC = "bold-italic"
15
- def variant=(v)
16
- self["mathvariant"] = v
17
- end
18
- end
19
-
20
- module Align
21
- CENTER = "center"
22
- LEFT = "left"
23
- RIGHT = "right"
24
- end
25
-
26
- module Line
27
- SOLID = "solid"
28
- NONE = "none"
29
- end
30
-
31
- class Math < XMLElement
32
- def initialize(display_style)
33
- super("math", "xmlns"=>"http://www.w3.org/1998/Math/MathML")
34
- self[:display] = display_style ? "block" : "inline"
35
- end
36
- end
37
-
38
- class Row < Element
39
- def initialize
40
- super("mrow")
41
- end
42
- end
43
-
44
- class None < Element
45
- def initialize
46
- super("none")
47
- end
48
- end
49
-
50
- class Space < Element
51
- def initialize(width)
52
- super("mspace", "width"=>width)
53
- end
54
- end
55
-
56
- class Fenced < Element
57
- attr_reader :open, :close
58
-
59
- def initialize
60
- super("mfenced")
61
- end
62
-
63
- def open=(o)
64
- o = "" if o.to_s=="." || !o
65
- o = "{" if o.to_s=="\\{"
66
- self[:open] = MathML.pcstring(o, true)
67
- end
68
-
69
- def close=(c)
70
- c = "" if c.to_s=="." || !c
71
- c = "}" if c.to_s=="\\}"
72
- self[:close] = MathML.pcstring(c, true)
73
- end
74
- end
75
-
76
- class Frac < Element
77
- def initialize(numerator, denominator)
78
- super("mfrac")
79
- self << numerator
80
- self << denominator
81
- end
82
- end
83
-
84
- class SubSup < Element
85
- attr_reader :sub, :sup, :body
86
-
87
- def initialize(display_style, body)
88
- super("mrow")
89
- as_display_style if display_style
90
- @body = body
91
- end
92
-
93
- def update_name
94
- if @sub || @sup
95
- name = "m"
96
- name << (@sub ? (@display_style ? "under" : "sub") : "")
97
- name << (@sup ? (@display_style ? "over" : "sup") : "")
98
- else
99
- name = "mrow"
100
- end
101
- self.name = name
102
- end
103
- private :update_name
104
-
105
- def update_contents
106
- contents.clear
107
- contents << @body
108
- contents << @sub if @sub
109
- contents << @sup if @sup
110
- end
111
- private :update_contents
112
-
113
- def update
114
- update_name
115
- update_contents
116
- end
117
- private :update
118
-
119
- def sub=(sub)
120
- @sub = sub
121
- update
122
- end
123
-
124
- def sup=(sup)
125
- @sup = sup
126
- update
127
- end
128
- end
129
-
130
- class Over < Element
131
- def initialize(base, over)
132
- super("mover")
133
- self << base << over
134
- end
135
- end
136
-
137
- class Under < Element
138
- def initialize(base, under)
139
- super("munder")
140
- self << base << under
141
- end
142
- end
143
-
144
- class Number < Element
145
- def initialize
146
- super("mn")
147
- end
148
- end
149
-
150
- class Identifier < Element
151
- def initialize
152
- super("mi")
153
- end
154
- end
155
-
156
- class Operator < Element
157
- def initialize
158
- super("mo")
159
- end
160
- end
161
-
162
- class Text < Element
163
- def initialize
164
- super("mtext")
165
- end
166
- end
167
-
168
- class Sqrt < Element
169
- def initialize
170
- super("msqrt")
171
- end
172
- end
173
-
174
- class Root < Element
175
- def initialize(index, base)
176
- super("mroot")
177
- self << base
178
- self << index
179
- end
180
- end
181
-
182
- class Table < Element
183
- def initialize
184
- super("mtable")
185
- end
186
-
187
- def set_align_attribute(name, a, default)
188
- if a.is_a?(Array) && a.size>0
189
- value = ""
190
- a.each do |i|
191
- value << " "+i
192
- end
193
- if value =~ /^( #{default})*$/
194
- @attributes.delete(name)
195
- else
196
- @attributes[name] = value.strip
197
- end
198
- else
199
- @attributes.delete(name)
200
- end
201
- end
202
-
203
- def aligns=(a)
204
- set_align_attribute("columnalign", a, Align::CENTER)
205
- end
206
-
207
- def vlines=(a)
208
- set_align_attribute("columnlines", a, Line::NONE)
209
- end
210
-
211
- def hlines=(a)
212
- set_align_attribute("rowlines", a, Line::NONE)
213
- end
214
- end
215
-
216
- class Tr < Element
217
- def initialize
218
- super("mtr")
219
- end
220
- end
221
-
222
- class Td < Element
223
- def initialize
224
- super("mtd")
225
- end
226
- end
2
+ class Element < XMLElement
3
+ attr_reader :display_style
4
+
5
+ def as_display_style
6
+ @display_style = true
7
+ self
8
+ end
9
+ end
10
+
11
+ module Variant
12
+ NORMAL = 'normal'
13
+ BOLD = 'bold'
14
+ BOLD_ITALIC = 'bold-italic'
15
+ def variant=(v)
16
+ self['mathvariant'] = v
17
+ end
18
+ end
19
+
20
+ module Align
21
+ CENTER = 'center'
22
+ LEFT = 'left'
23
+ RIGHT = 'right'
24
+ end
25
+
26
+ module Line
27
+ SOLID = 'solid'
28
+ NONE = 'none'
29
+ end
30
+
31
+ class Math < XMLElement
32
+ def initialize(display_style)
33
+ super('math', 'xmlns' => 'http://www.w3.org/1998/Math/MathML')
34
+ self[:display] = display_style ? 'block' : 'inline'
35
+ end
36
+ end
37
+
38
+ class Row < Element
39
+ def initialize
40
+ super('mrow')
41
+ end
42
+ end
43
+
44
+ class None < Element
45
+ def initialize
46
+ super('none')
47
+ end
48
+ end
49
+
50
+ class Space < Element
51
+ def initialize(width)
52
+ super('mspace', 'width' => width)
53
+ end
54
+ end
55
+
56
+ class Fenced < Element
57
+ attr_reader :open, :close
58
+
59
+ def initialize
60
+ super('mfenced')
61
+ end
62
+
63
+ def open=(o)
64
+ o = '' if o.to_s == '.' || !o
65
+ o = '{' if o.to_s == '\\{'
66
+ self[:open] = MathML.pcstring(o, true)
67
+ end
68
+
69
+ def close=(c)
70
+ c = '' if c.to_s == '.' || !c
71
+ c = '}' if c.to_s == '\\}'
72
+ self[:close] = MathML.pcstring(c, true)
73
+ end
74
+ end
75
+
76
+ class Frac < Element
77
+ def initialize(numerator, denominator)
78
+ super('mfrac')
79
+ self << numerator
80
+ self << denominator
81
+ end
82
+ end
83
+
84
+ class SubSup < Element
85
+ attr_reader :sub, :sup, :body
86
+
87
+ def initialize(display_style, body)
88
+ super('mrow')
89
+ as_display_style if display_style
90
+ @body = body
91
+ end
92
+
93
+ def update_name
94
+ if @sub || @sup
95
+ name = 'm'
96
+ name << (if @sub
97
+ @display_style ? 'under' : 'sub'
98
+ else
99
+ ''
100
+ end)
101
+ name << (if @sup
102
+ @display_style ? 'over' : 'sup'
103
+ else
104
+ ''
105
+ end)
106
+ else
107
+ name = 'mrow'
108
+ end
109
+ self.name = name
110
+ end
111
+ private :update_name
112
+
113
+ def update_contents
114
+ contents.clear
115
+ contents << @body
116
+ contents << @sub if @sub
117
+ contents << @sup if @sup
118
+ end
119
+ private :update_contents
120
+
121
+ def update
122
+ update_name
123
+ update_contents
124
+ end
125
+ private :update
126
+
127
+ def sub=(sub)
128
+ @sub = sub
129
+ update
130
+ end
131
+
132
+ def sup=(sup)
133
+ @sup = sup
134
+ update
135
+ end
136
+ end
137
+
138
+ class Over < Element
139
+ def initialize(base, over)
140
+ super('mover')
141
+ self << base << over
142
+ end
143
+ end
144
+
145
+ class Under < Element
146
+ def initialize(base, under)
147
+ super('munder')
148
+ self << base << under
149
+ end
150
+ end
151
+
152
+ class Number < Element
153
+ def initialize
154
+ super('mn')
155
+ end
156
+ end
157
+
158
+ class Identifier < Element
159
+ def initialize
160
+ super('mi')
161
+ end
162
+ end
163
+
164
+ class Operator < Element
165
+ def initialize
166
+ super('mo')
167
+ end
168
+ end
169
+
170
+ class Text < Element
171
+ def initialize
172
+ super('mtext')
173
+ end
174
+ end
175
+
176
+ class Sqrt < Element
177
+ def initialize
178
+ super('msqrt')
179
+ end
180
+ end
181
+
182
+ class Root < Element
183
+ def initialize(index, base)
184
+ super('mroot')
185
+ self << base
186
+ self << index
187
+ end
188
+ end
189
+
190
+ class Table < Element
191
+ def initialize
192
+ super('mtable')
193
+ end
194
+
195
+ def set_align_attribute(name, a, default)
196
+ if a.is_a?(Array) && a.size > 0
197
+ value = ''
198
+ a.each do |i|
199
+ value << (' ' + i)
200
+ end
201
+ if value =~ /^( #{default})*$/
202
+ @attributes.delete(name)
203
+ else
204
+ @attributes[name] = value.strip
205
+ end
206
+ else
207
+ @attributes.delete(name)
208
+ end
209
+ end
210
+
211
+ def aligns=(a)
212
+ set_align_attribute('columnalign', a, Align::CENTER)
213
+ end
214
+
215
+ def vlines=(a)
216
+ set_align_attribute('columnlines', a, Line::NONE)
217
+ end
218
+
219
+ def hlines=(a)
220
+ set_align_attribute('rowlines', a, Line::NONE)
221
+ end
222
+ end
223
+
224
+ class Tr < Element
225
+ def initialize
226
+ super('mtr')
227
+ end
228
+ end
229
+
230
+ class Td < Element
231
+ def initialize
232
+ super('mtd')
233
+ end
234
+ end
227
235
  end