mathtype 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/lib/mathtype/version.rb +3 -0
- data/lib/mathtype.rb +61 -0
- data/lib/records/char.rb +84 -0
- data/lib/records/color.rb +13 -0
- data/lib/records/color_def.rb +37 -0
- data/lib/records/embell.rb +103 -0
- data/lib/records/encoding_def.rb +22 -0
- data/lib/records/end.rb +8 -0
- data/lib/records/eqn_prefs.rb +44 -0
- data/lib/records/font_def.rb +14 -0
- data/lib/records/font_style_def.rb +14 -0
- data/lib/records/future.rb +14 -0
- data/lib/records/line.rb +36 -0
- data/lib/records/matrix.rb +41 -0
- data/lib/records/mtef.rb +118 -0
- data/lib/records/nudge.rb +34 -0
- data/lib/records/pile.rb +28 -0
- data/lib/records/ruler.rb +22 -0
- data/lib/records/size.rb +44 -0
- data/lib/records/snapshot.rb +19 -0
- data/lib/records/tmpl.rb +449 -0
- data/lib/records/typesizes.rb +24 -0
- data/mathtype.gemspec +28 -0
- data/spec/fixtures/expected/embelishments.xml +848 -0
- data/spec/fixtures/expected/equation1.xml +492 -0
- data/spec/fixtures/expected/equation10.xml +369 -0
- data/spec/fixtures/expected/equation11.xml +370 -0
- data/spec/fixtures/expected/equation12.xml +433 -0
- data/spec/fixtures/expected/equation13.xml +680 -0
- data/spec/fixtures/expected/equation2.xml +429 -0
- data/spec/fixtures/expected/equation3.xml +1374 -0
- data/spec/fixtures/expected/equation4.xml +360 -0
- data/spec/fixtures/expected/equation5.xml +377 -0
- data/spec/fixtures/expected/equation6.xml +364 -0
- data/spec/fixtures/expected/equation7.xml +369 -0
- data/spec/fixtures/expected/equation8.xml +362 -0
- data/spec/fixtures/expected/equation9.xml +355 -0
- data/spec/fixtures/input/embelishments.bin +0 -0
- data/spec/fixtures/input/equation1.bin +0 -0
- data/spec/fixtures/input/equation10.bin +0 -0
- data/spec/fixtures/input/equation11.bin +0 -0
- data/spec/fixtures/input/equation12.bin +0 -0
- data/spec/fixtures/input/equation13.bin +0 -0
- data/spec/fixtures/input/equation2.bin +0 -0
- data/spec/fixtures/input/equation3.bin +0 -0
- data/spec/fixtures/input/equation4.bin +0 -0
- data/spec/fixtures/input/equation5.bin +0 -0
- data/spec/fixtures/input/equation6.bin +0 -0
- data/spec/fixtures/input/equation7.bin +0 -0
- data/spec/fixtures/input/equation8.bin +0 -0
- data/spec/fixtures/input/equation9.bin +0 -0
- data/spec/mathtype_spec.rb +16 -0
- data/spec/spec_helper.rb +64 -0
- metadata +233 -0
data/lib/records/tmpl.rb
ADDED
@@ -0,0 +1,449 @@
|
|
1
|
+
require_relative "snapshot"
|
2
|
+
|
3
|
+
# TMPL record (3):
|
4
|
+
|
5
|
+
# Consists of:
|
6
|
+
# record type (3)
|
7
|
+
# options
|
8
|
+
# [nudge] if mtefOPT_NUDGE is set
|
9
|
+
# [selector] template selector code
|
10
|
+
# [variation] template variation code (1 or 2 bytes; see below)
|
11
|
+
# [options] template-specific options
|
12
|
+
# [subobject list] either a single character (e.g. sigma in a summation) and/or lines
|
13
|
+
# The template selector and variation codes determine the class of the
|
14
|
+
# template and various properties of the template, such as which subobjects
|
15
|
+
# can be deleted by the user (see Templates). The class of a template
|
16
|
+
# determines the order and meaning of each of its subobjects (see Template
|
17
|
+
# subobject order).
|
18
|
+
|
19
|
+
# The variation code may be 1 or 2 bytes long. If the first byte value has the
|
20
|
+
# high bit set (0x80), the next byte is read and combined with the first
|
21
|
+
# according to this formula:
|
22
|
+
|
23
|
+
# variation code = (byte1 & 0x7F) | (byte2 << 8)
|
24
|
+
|
25
|
+
# Template-specific options field only used for integrals & fence templates:
|
26
|
+
# Fence template option field values (fence alignment):
|
27
|
+
# 0 center fence on math axis, place math axis of contents on math axis of
|
28
|
+
# containing line (default);
|
29
|
+
# 1 center fence on contents, place math axis of contents on math axis of
|
30
|
+
# containing line;
|
31
|
+
# 2 center fence on contents, center contents on math axis of containing line.
|
32
|
+
# Warning: the expanding integral property is duplicated in the integral
|
33
|
+
# templates variation codes (see Limit variations). On reading, MathType only
|
34
|
+
# looks at the variation code.
|
35
|
+
|
36
|
+
# Integral template option field values:
|
37
|
+
# 0 fixed-size integral;
|
38
|
+
# 1 the integral expands vertically to fit its contents.
|
39
|
+
|
40
|
+
# Limit variations:
|
41
|
+
|
42
|
+
# The following variation codes apply to all templates whose class is BigOpBoxClass or LimBoxClass:
|
43
|
+
|
44
|
+
# variation bits symbol description
|
45
|
+
# 0x0001 tvBO_LOWER lower limit is present
|
46
|
+
# 0x0002 tvBO_UPPER upper limit is present
|
47
|
+
# 0x0040 tvBO_SUM summation-style limit positions, else integral-style
|
48
|
+
|
49
|
+
# Template selectors and variations:
|
50
|
+
# Fences (parentheses, etc.):
|
51
|
+
# selector symbol description class
|
52
|
+
# 0 tmANGLE angle brackets ParBoxClass
|
53
|
+
# 1 tmPAREN parentheses ParBoxClass
|
54
|
+
# 2 tmBRACE braces (curly brackets) ParBoxClass
|
55
|
+
# 3 tmBRACK square brackets ParBoxClass
|
56
|
+
# 4 tmBAR vertical bars ParBoxClass
|
57
|
+
# 5 tmDBAR double vertical bars ParBoxClass
|
58
|
+
# 6 tmFLOOR floor brackets ParBoxClass
|
59
|
+
# 7 tmCEILING ceiling brackets ParBoxClass
|
60
|
+
# 8 tmOBRACK open (white) brackets ParBoxClass
|
61
|
+
# variations variation bits symbol description
|
62
|
+
# 0x0001 tvFENCE_L left fence is present
|
63
|
+
# 0x0002 tvFENCE_R right fence is present
|
64
|
+
# Intervals:
|
65
|
+
# selector symbol description class
|
66
|
+
# 9 tmINTERVAL unmatched brackets and parentheses ParBoxClass
|
67
|
+
# variations variation bits symbol description
|
68
|
+
# 0x0000 tvINTV_LEFT_LP left fence is left parenthesis
|
69
|
+
# 0x0001 tvINTV_LEFT_RP left fence is right parenthesis
|
70
|
+
# 0x0002 tvINTV_LEFT_LB left fence is left bracket
|
71
|
+
# 0x0003 tvINTV_LEFT_RB left fence is right bracket
|
72
|
+
# 0x0000 tvINTV_RIGHT_LP right fence is left parenthesis
|
73
|
+
# 0x0010 tvINTV_RIGHT_RP right fence is right parenthesis
|
74
|
+
# 0x0020 tvINTV_RIGHT_LB right fence is left bracket
|
75
|
+
# 0x0030 tvINTV_RIGHT_RB right fence is right bracket
|
76
|
+
# Radicals (square and nth roots):
|
77
|
+
# selector symbol description class
|
78
|
+
# 10 tmROOT radical RootBoxClass
|
79
|
+
# variations variation symbol description
|
80
|
+
# 0 tvROOT_SQ square root
|
81
|
+
# 1 tvROOT_NTH nth root
|
82
|
+
# Fractions:
|
83
|
+
# selector symbol description class
|
84
|
+
# 11 tmFRACT fractions FracBoxClass
|
85
|
+
# variations variation bits symbol description
|
86
|
+
# 0x0001 tvFR_SMALL subscript-size slots (piece fraction)
|
87
|
+
# 0x0002 tvFR_SLASH fraction bar is a slash
|
88
|
+
# 0x0004 tvFR_BASE num. and denom. are baseline aligned
|
89
|
+
# Over and Underbars:
|
90
|
+
# selector symbol description class
|
91
|
+
# 12 tmUBAR underbar BarBoxClass
|
92
|
+
# 13 tmOBAR overbar BarBoxClass
|
93
|
+
# variations variation bits symbol description
|
94
|
+
# 0x0001 tvBAR_DOUBLE bar is doubled, else single
|
95
|
+
# Arrows:
|
96
|
+
# selector symbol description class
|
97
|
+
# 14 tmARROW arrow ArroBoxClass
|
98
|
+
# variations variation symbol description
|
99
|
+
# 0x0000 tvAR_SINGLE single arrow
|
100
|
+
# 0x0001 tvAR_DOUBLE double arrow
|
101
|
+
# 0x0002 tvAR_HARPOON harpoon
|
102
|
+
# 0x0004 tvAR_TOP top slot is present
|
103
|
+
# 0x0008 tvAR_BOTTOM bottom slot is present
|
104
|
+
# 0x0010 tvAR_LEFT if single, arrow points left
|
105
|
+
# 0x0020 tvAR_RIGHT if single, arrow points right
|
106
|
+
# 0x0010 tvAR_LOS if double or harpoon, large over small
|
107
|
+
# 0x0020 tvAR_SOL if double or harpoon, small over large
|
108
|
+
# Integrals (see Limit Variations):
|
109
|
+
# selector symbol description class
|
110
|
+
# 15 tmINTEG integral BigOpBoxClass
|
111
|
+
# variations variation symbol description
|
112
|
+
# 0x0001 tvINT_1 single integral sign
|
113
|
+
# 0x0002 tvINT_2 double integral sign
|
114
|
+
# 0x0003 tvINT_3 triple integral sign
|
115
|
+
# 0x0004 tvINT_LOOP has loop w/o arrows
|
116
|
+
# 0x0008 tvINT_CW_LOOP has clockwise loop
|
117
|
+
# 0x000C tvINT_CCW_LOOP has counter-clockwise loop
|
118
|
+
# 0x0100 tvINT_EXPAND integral signs expand
|
119
|
+
# Sums, products, coproducts, unions, intersections, etc. (see Limit Variations):
|
120
|
+
# selector symbol description class
|
121
|
+
# 16 tmSUM sum BigOpBoxClass
|
122
|
+
# 17 tmPROD product BigOpBoxClass
|
123
|
+
# 18 tmCOPROD coproduct BigOpBoxClass
|
124
|
+
# 19 tmUNION union BigOpBoxClass
|
125
|
+
# 20 tmINTER intersection BigOpBoxClass
|
126
|
+
# 21 tmINTOP integral-style big operator BigOpBoxClass
|
127
|
+
# 22 tmSUMOP summation-style big operator BigOpBoxClass
|
128
|
+
# Limits (see Limit Variations):
|
129
|
+
# selector symbol description class
|
130
|
+
# 23 tmLIM limits LimBoxClass
|
131
|
+
# variations variation symbol description
|
132
|
+
# 0 tvSUBAR single underbar
|
133
|
+
# 1 tvDUBAR double underbar
|
134
|
+
# Horizontal braces and brackets:
|
135
|
+
# selector symbol description class
|
136
|
+
# 24 tmHBRACE horizontal brace HFenceBoxClass
|
137
|
+
# 25 tmHBRACK horizontal bracket HFenceBoxClass
|
138
|
+
# variation symbol description
|
139
|
+
# 0x0001 tvHB_TOP slot is on the top, else on the bottom
|
140
|
+
# Long division:
|
141
|
+
# selector symbol description class
|
142
|
+
# 26 tmLDIV long division LDivBoxClass
|
143
|
+
# variation symbol description
|
144
|
+
# 0x0001 tvLD_UPPER upper slot is present
|
145
|
+
# Subscripts and superscripts:
|
146
|
+
# selector symbol description class
|
147
|
+
# 27 tmSUB subscript ScrBoxClass
|
148
|
+
# 28 tmSUP superscript ScrBoxClass
|
149
|
+
# 29 tmSUBSUP subscript and superscript ScrBoxClass
|
150
|
+
# variation symbol description
|
151
|
+
# 0x0001 tvSU_PRECEDES script precedes scripted item,
|
152
|
+
# else follows
|
153
|
+
# Dirac bra-ket notation:
|
154
|
+
# selector symbol description class
|
155
|
+
# 30 tmDIRAC bra-ket notation DiracBoxClass
|
156
|
+
# variation symbol description
|
157
|
+
# 0x0001 tvDI_LEFT left part is present
|
158
|
+
# 0x0002 tvDI_RIGHT right part is present
|
159
|
+
# Vectors:
|
160
|
+
# selector symbol description class
|
161
|
+
# 31 tmVEC vector HatBoxClass
|
162
|
+
# variation symbol description
|
163
|
+
# 0x0001 tvVE_LEFT arrow points left
|
164
|
+
# 0x0002 tvVE_RIGHT arrow points right
|
165
|
+
# 0x0004 tvVE_UNDER arrow under slot, else over slot
|
166
|
+
# 0x0008 tvVE_HARPOON harpoon
|
167
|
+
# Hats, arcs, tilde, joint status:
|
168
|
+
# selector symbol description class
|
169
|
+
# 32 tmTILDE tilde over characters HatBoxClass
|
170
|
+
# 33 tmHAT hat over characters HatBoxClass
|
171
|
+
# 34 tmARC arc over characters HatBoxClass
|
172
|
+
# 35 tmJSTATUS joint status construct HatBoxClass
|
173
|
+
# Overstrikes (cross-outs):
|
174
|
+
# selector symbol description class
|
175
|
+
# 36 tmSTRIKE overstrike (cross-out) StrikeBoxClass
|
176
|
+
# variation symbol description
|
177
|
+
# 0x0001 tvST_HORIZ line is horizontal, else slashes
|
178
|
+
# 0x0002 tvST_UP if slashes, slash from lower-left to upper-right is present
|
179
|
+
# 0x0004 tvST_DOWN if slashes, slash from upper-left to lower-right is present
|
180
|
+
# Boxes:
|
181
|
+
# selector symbol description class
|
182
|
+
# 37 tmBOX box TBoxBoxClass
|
183
|
+
# variation symbol description
|
184
|
+
# 0x0001 tvBX_ROUND corners are round, else square
|
185
|
+
# 0x0002 tvBX_LEFT left side is present
|
186
|
+
# 0x0004 tvBX_RIGHT right side is present
|
187
|
+
# 0x0008 tvBX_TOP top side is present
|
188
|
+
# 0x0010 tvBX_BOTTOM bottom side is present
|
189
|
+
|
190
|
+
module Mathtype
|
191
|
+
class RecordTmpl < BinData::Record
|
192
|
+
include Snapshot
|
193
|
+
EXPOSED_IN_SNAPSHOT = %i(selector variation template_specific_options nudge
|
194
|
+
subobject_list)
|
195
|
+
|
196
|
+
SELECTORS = {
|
197
|
+
# Fences (parentheses, etc.):
|
198
|
+
0 => "tmANGLE",
|
199
|
+
1 => "tmPAREN",
|
200
|
+
2 => "tmBRACE",
|
201
|
+
3 => "tmBRACK",
|
202
|
+
4 => "tmBAR",
|
203
|
+
5 => "tmDBAR",
|
204
|
+
6 => "tmFLOOR",
|
205
|
+
7 => "tmCEILING",
|
206
|
+
8 => "tmOBRACK",
|
207
|
+
# Intervals:
|
208
|
+
9 => "tmINTERVAL",
|
209
|
+
# Radicals (square and nth roots):
|
210
|
+
10 => "tmROOT",
|
211
|
+
# Fractions:
|
212
|
+
11 => "tmFRACT",
|
213
|
+
# Over and Underbars:
|
214
|
+
12 => "tmUBAR",
|
215
|
+
13 => "tmOBAR",
|
216
|
+
# Arrows:
|
217
|
+
14 => "tmARROW",
|
218
|
+
# Integrals (see Limit Variations):
|
219
|
+
15 => "tmINTEG",
|
220
|
+
# Sums, products, coproducts, unions, intersections, etc. (see Limit Variations):
|
221
|
+
16 => "tmSUM",
|
222
|
+
17 => "tmPROD",
|
223
|
+
18 => "tmCOPROD",
|
224
|
+
19 => "tmUNION",
|
225
|
+
20 => "tmINTER",
|
226
|
+
21 => "tmINTOP",
|
227
|
+
22 => "tmSUMOP",
|
228
|
+
# Limits (see Limit Variations):
|
229
|
+
23 => "tmLIM",
|
230
|
+
# Horizontal braces and brackets:
|
231
|
+
24 => "tmHBRACE",
|
232
|
+
25 => "tmHBRACK",
|
233
|
+
# Long division:
|
234
|
+
26 => "tmLDIV",
|
235
|
+
# Subscripts and superscripts:
|
236
|
+
27 => "tmSUB",
|
237
|
+
28 => "tmSUP",
|
238
|
+
29 => "tmSUBSUP",
|
239
|
+
# Dirac bra-ket notation:
|
240
|
+
30 => "tmDIRAC",
|
241
|
+
# Vectors:
|
242
|
+
31 => "tmVEC",
|
243
|
+
# Hats, arcs, tilde, joint status:
|
244
|
+
32 => "tmTILDE",
|
245
|
+
33 => "tmHAT",
|
246
|
+
34 => "tmARC",
|
247
|
+
35 => "tmJSTATUS",
|
248
|
+
# Overstrikes (cross-outs):
|
249
|
+
36 => "tmSTRIKE",
|
250
|
+
# Boxes:
|
251
|
+
37 => "tmBOX"
|
252
|
+
}
|
253
|
+
|
254
|
+
# Top-level keys are template identifiers, defined in TEMPLATES.
|
255
|
+
# Second-level keys are bits for certain variations, negative keys mean
|
256
|
+
# that the variation is present if the bit is absent.
|
257
|
+
|
258
|
+
VARIATIONS = {
|
259
|
+
# Fences (parentheses, etc.):
|
260
|
+
0..8 => {
|
261
|
+
0x0001 => "tvFENCE_L", # left fence is present
|
262
|
+
0x0002 => "tvFENCE_R", # right fence is present
|
263
|
+
},
|
264
|
+
|
265
|
+
# Intervals:
|
266
|
+
9 => {
|
267
|
+
0x0000 => "tvINTV_LEFT_LP", # left fence is left parenthesis
|
268
|
+
0x0001 => "tvINTV_LEFT_RP", # left fence is right parenthesis
|
269
|
+
0x0002 => "tvINTV_LEFT_LB", # left fence is left bracket
|
270
|
+
0x0003 => "tvINTV_LEFT_RB", # left fence is right bracket
|
271
|
+
0x0004 => "tvINTV_RIGHT_LP", # right fence is left parenthesis # WARNING: DOCUMENTATION SAYS 0x0000?
|
272
|
+
0x0010 => "tvINTV_RIGHT_RP", # right fence is right parenthesis
|
273
|
+
0x0020 => "tvINTV_RIGHT_LB", # right fence is left bracket
|
274
|
+
0x0030 => "tvINTV_RIGHT_RB", # right fence is right bracket
|
275
|
+
# Added to match MathML translator
|
276
|
+
0x0022 => "tvINTV_LBLB",
|
277
|
+
0x0033 => "tvINTV_RBRB",
|
278
|
+
0x0023 => "tvINTV_RBLB",
|
279
|
+
0x0012 => "tvINTV_LBRP",
|
280
|
+
0x0030 => "tvINTV_LPRB"
|
281
|
+
},
|
282
|
+
|
283
|
+
# Radicals (square and nth roots):
|
284
|
+
10 => {
|
285
|
+
0 => "tvROOT_SQ", # square root
|
286
|
+
1 => "tvROOT_NTH", # nth root
|
287
|
+
},
|
288
|
+
|
289
|
+
# Fractions:
|
290
|
+
11 => {
|
291
|
+
0x0001 => "tvFR_SMALL", # subscript-size slots (piece fraction)
|
292
|
+
0x0002 => "tvFR_SLASH", # fraction bar is a slash
|
293
|
+
0x0004 => "tvFR_BASE", # num. and denom. are baseline aligned
|
294
|
+
},
|
295
|
+
|
296
|
+
# Over and Underbars:
|
297
|
+
12..13 => {
|
298
|
+
0x0001 => "tvBAR_DOUBLE", # bar is doubled, else single
|
299
|
+
},
|
300
|
+
|
301
|
+
# Arrows:
|
302
|
+
14 => {
|
303
|
+
0x0000 => "tvAR_SINGLE", # single arrow
|
304
|
+
0x0001 => "tvAR_DOUBLE", # double arrow
|
305
|
+
0x0010 => {
|
306
|
+
0x0001 => "tvAR_LOS", # if double, large over small,
|
307
|
+
0x0002 => "tvAR_LOS", # if harpoon, large over small,
|
308
|
+
0x0000 => "tvAR_LEFT" # if single, arrow points left
|
309
|
+
},
|
310
|
+
0x0020 => {
|
311
|
+
0x0001 => "tvAR_SOL", # if double, small over large
|
312
|
+
0x0002 => "tvAR_SOL", # if harpoon, small over large
|
313
|
+
0x0000 => "tvAR_RIGHT", # if single, arrow points right
|
314
|
+
},
|
315
|
+
0x0002 => "tvAR_HARPOON", # harpoon
|
316
|
+
0x0004 => "tvAR_TOP", # top slot is present
|
317
|
+
0x0008 => "tvAR_BOTTOM", # bottom slot is present
|
318
|
+
# Added combinations and hidden options
|
319
|
+
0x000c => "tvAR_TOPBOTTOM", # both slots
|
320
|
+
},
|
321
|
+
|
322
|
+
# Integrals (see Limit Variations):
|
323
|
+
15 => {
|
324
|
+
0x0001 => "tvINT_1", # single integral sign
|
325
|
+
0x0002 => "tvINT_2", # double integral sign
|
326
|
+
0x0003 => "tvINT_3", # triple integral sign
|
327
|
+
0x0004 => "tvINT_LOOP", # has loop w/o arrows
|
328
|
+
0x0008 => "tvINT_CW_LOOP", # has clockwise loop
|
329
|
+
0x000C => "tvINT_CCW_LOOP", # has counter-clockwise loop
|
330
|
+
0x0100 => "tvINT_EXPAND", # integral signs expand
|
331
|
+
},
|
332
|
+
|
333
|
+
# Limit variations
|
334
|
+
15..23 => {
|
335
|
+
0x0010 => "tvBO_LOWER", # lower limit is present
|
336
|
+
0x0020 => "tvBO_UPPER", # upper limit is present
|
337
|
+
0x0040 => "tvBO_SUM", # summation-style limit positions,
|
338
|
+
-0x0040 => "tvBO_INT" # else integral-style
|
339
|
+
},
|
340
|
+
|
341
|
+
# Sums, products, coproducts, unions, intersections, etc. (see Limit Variations):
|
342
|
+
23 => {
|
343
|
+
0 => "tvSUBAR", # single underbar
|
344
|
+
1 => "tvDUBAR", # double underbar
|
345
|
+
},
|
346
|
+
|
347
|
+
# Horizontal braces and brackets:
|
348
|
+
24..25 => {
|
349
|
+
0x0001 => "tvHB_TOP", # slot is on the top, else on the bottom
|
350
|
+
},
|
351
|
+
|
352
|
+
# Long division:
|
353
|
+
26 => {
|
354
|
+
0x0001 => "tvLD_UPPER", # upper slot is present
|
355
|
+
},
|
356
|
+
|
357
|
+
# Subscripts and superscripts:
|
358
|
+
27..29 => {
|
359
|
+
0x0001 => "tvSU_PRECEDES", # script precedes scripted item, else follows
|
360
|
+
},
|
361
|
+
|
362
|
+
# Dirac bra-ket notation:
|
363
|
+
30 => {
|
364
|
+
0x0001 => "tvDI_LEFT", # left part is present
|
365
|
+
0x0002 => "tvDI_RIGHT", # right part is present
|
366
|
+
},
|
367
|
+
|
368
|
+
# Vectors:
|
369
|
+
31 => {
|
370
|
+
0x0001 => "tvVE_LEFT", # arrow points left
|
371
|
+
0x0002 => "tvVE_RIGHT", # arrow points right
|
372
|
+
0x0004 => "tvVE_UNDER", # arrow under slot, else over slot
|
373
|
+
0x0008 => "tvVE_HARPOON", # harpoon
|
374
|
+
},
|
375
|
+
|
376
|
+
# Hats, arcs, tilde, joint status:
|
377
|
+
32..35 => {},
|
378
|
+
|
379
|
+
# Overstrikes (cross-outs):
|
380
|
+
36 => {
|
381
|
+
0x0001 => "tvST_HORIZ", # line is horizontal, else slashes
|
382
|
+
0x0002 => "tvST_UP", # if slashes, slash from lower-left to upper-right is present
|
383
|
+
0x0004 => "tvST_DOWN", # if slashes, slash from upper-left to lower-right is present
|
384
|
+
},
|
385
|
+
|
386
|
+
# Boxes:
|
387
|
+
37 => {
|
388
|
+
0x0001 => "tvBX_ROUND", # corners are round, else square
|
389
|
+
0x0002 => "tvBX_LEFT", # left side is present
|
390
|
+
0x0004 => "tvBX_RIGHT", # right side is present
|
391
|
+
0x0008 => "tvBX_TOP", # top side is present
|
392
|
+
0x0010 => "tvBX_BOTTOM", # bottom side is present
|
393
|
+
}
|
394
|
+
}
|
395
|
+
|
396
|
+
int8 :options
|
397
|
+
|
398
|
+
nudge :nudge, onlyif: lambda { options & OPTIONS["mtefOPT_NUDGE"] > 0 }
|
399
|
+
|
400
|
+
int8 :_selector
|
401
|
+
|
402
|
+
int8 :_variation_first_byte
|
403
|
+
int8 :_variation_second_byte, onlyif: (lambda do
|
404
|
+
_variation_first_byte & 0x80 > 0
|
405
|
+
end)
|
406
|
+
|
407
|
+
int8 :template_specific_options
|
408
|
+
|
409
|
+
array :subobject_list, read_until: lambda { element.record_type == 0 } do
|
410
|
+
named_record
|
411
|
+
end
|
412
|
+
|
413
|
+
def variation
|
414
|
+
variation = (_variation_first_byte & 0x7F) | (_variation_second_byte << 8)
|
415
|
+
|
416
|
+
variations = VARIATIONS.select do |selector, _|
|
417
|
+
selector === _selector
|
418
|
+
end.values.reduce(Hash.new, :merge)
|
419
|
+
|
420
|
+
process_variations(variation, variations)
|
421
|
+
end
|
422
|
+
|
423
|
+
def process_variations(variation, variations)
|
424
|
+
variations.select do |bit, value|
|
425
|
+
# bit should NOT be active
|
426
|
+
if bit < 0
|
427
|
+
variation & -bit == 0
|
428
|
+
# bit should be active
|
429
|
+
else
|
430
|
+
variation & bit == bit
|
431
|
+
end
|
432
|
+
end.map do |bit, value|
|
433
|
+
case value
|
434
|
+
when Hash # Conditional variations
|
435
|
+
result = value.detect do |conditional, value|
|
436
|
+
variation & conditional == conditional
|
437
|
+
end
|
438
|
+
result.last if result
|
439
|
+
else
|
440
|
+
value
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
def selector
|
446
|
+
SELECTORS[_selector]
|
447
|
+
end
|
448
|
+
end
|
449
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Typesize records (10-14):
|
2
|
+
# Consists of:
|
3
|
+
# record type (10-14)
|
4
|
+
# These records are just short ways of specifying a simple typesize where dsize
|
5
|
+
# is zero. The tag value represents an lsize + 10. So if the tag value is 10,
|
6
|
+
# it means equation content following it will be Full size (szFULL), tag value
|
7
|
+
# 11 means szSUB, and so on. See typesize.
|
8
|
+
|
9
|
+
module Mathtype
|
10
|
+
class RecordFull < BinData::Record
|
11
|
+
end
|
12
|
+
|
13
|
+
class RecordSub < BinData::Record
|
14
|
+
end
|
15
|
+
|
16
|
+
class RecordSub2 < BinData::Record
|
17
|
+
end
|
18
|
+
|
19
|
+
class RecordSym < BinData::Record
|
20
|
+
end
|
21
|
+
|
22
|
+
class RecordSubsym < BinData::Record
|
23
|
+
end
|
24
|
+
end
|
data/mathtype.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mathtype/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mathtype"
|
8
|
+
spec.version = Mathtype::VERSION
|
9
|
+
spec.authors = ["Jure Triglav"]
|
10
|
+
spec.email = ["juretriglav@gmail.com"]
|
11
|
+
spec.summary = %q{ A Ruby gem for reading MathType binaries and converting them to an XML form. }
|
12
|
+
spec.description = %q{ This gem can read proprietary MathType binary equations that are usually embedded in Word documents and convert these equations into an XML form. This XML form can then be used for further processing, e.g. to convert the equation to MathML.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
24
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
25
|
+
spec.add_dependency "bindata", "~> 2.1"
|
26
|
+
spec.add_dependency "nokogiri", "~> 1.6"
|
27
|
+
spec.add_dependency "ruby-ole", "~> 1.2"
|
28
|
+
end
|