math_ml 0.14 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +339 -0
- data/lib/math_ml/element.rb +233 -225
- data/lib/math_ml/latex/builtin/symbol.rb +546 -546
- data/lib/math_ml/latex/builtin.rb +3 -3
- data/lib/math_ml/latex.rb +1140 -1103
- data/lib/math_ml/string.rb +17 -16
- data/lib/math_ml/symbol/character_reference.rb +2100 -2101
- data/lib/math_ml/symbol/entity_reference.rb +2100 -2100
- data/lib/math_ml/symbol/utf8.rb +2100 -2102
- data/lib/math_ml/util.rb +350 -339
- data/lib/math_ml.rb +14 -14
- metadata +43 -75
- data/Rakefile +0 -60
- data/Rakefile.utirake +0 -392
- data/spec/math_ml/element_spec.rb +0 -32
- data/spec/math_ml/latex/macro_spec.rb +0 -122
- data/spec/math_ml/latex/parser_spec.rb +0 -580
- data/spec/math_ml/latex/scanner_spec.rb +0 -202
- data/spec/math_ml/string_spec.rb +0 -29
- data/spec/math_ml/util_spec.rb +0 -700
- data/spec/math_ml_spec.rb +0 -14
- data/spec/util.rb +0 -43
data/lib/math_ml/element.rb
CHANGED
@@ -1,227 +1,235 @@
|
|
1
1
|
module MathML
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
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
|