itextomml 1.3.20

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.
data/ext/y.tab.h ADDED
@@ -0,0 +1,357 @@
1
+ /* A Bison parser, made by GNU Bison 2.3. */
2
+
3
+ /* Skeleton interface for Bison's Yacc-like parsers in C
4
+
5
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6
+ Free Software Foundation, Inc.
7
+
8
+ This program is free software; you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation; either version 2, or (at your option)
11
+ any later version.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program; if not, write to the Free Software
20
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
+ Boston, MA 02110-1301, USA. */
22
+
23
+ /* As a special exception, you may create a larger work that contains
24
+ part or all of the Bison parser skeleton and distribute that work
25
+ under terms of your choice, so long as that work isn't itself a
26
+ parser generator using the skeleton or a modified version thereof
27
+ as a parser skeleton. Alternatively, if you modify or redistribute
28
+ the parser skeleton itself, you may (at your option) remove this
29
+ special exception, which will cause the skeleton and the resulting
30
+ Bison output files to be licensed under the GNU General Public
31
+ License without this special exception.
32
+
33
+ This special exception was added by the Free Software Foundation in
34
+ version 2.2 of Bison. */
35
+
36
+ /* Tokens. */
37
+ #ifndef YYTOKENTYPE
38
+ # define YYTOKENTYPE
39
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
40
+ know about them. */
41
+ enum yytokentype {
42
+ TEXATOP = 258,
43
+ TEXOVER = 259,
44
+ CHAR = 260,
45
+ STARTMATH = 261,
46
+ STARTDMATH = 262,
47
+ ENDMATH = 263,
48
+ MI = 264,
49
+ MIB = 265,
50
+ MN = 266,
51
+ MO = 267,
52
+ SUP = 268,
53
+ SUB = 269,
54
+ MROWOPEN = 270,
55
+ MROWCLOSE = 271,
56
+ LEFT = 272,
57
+ RIGHT = 273,
58
+ BIG = 274,
59
+ BBIG = 275,
60
+ BIGG = 276,
61
+ BBIGG = 277,
62
+ BIGL = 278,
63
+ BBIGL = 279,
64
+ BIGGL = 280,
65
+ BBIGGL = 281,
66
+ FRAC = 282,
67
+ TFRAC = 283,
68
+ OPERATORNAME = 284,
69
+ MATHOP = 285,
70
+ MATHBIN = 286,
71
+ MATHREL = 287,
72
+ MOP = 288,
73
+ MOL = 289,
74
+ MOLL = 290,
75
+ MOF = 291,
76
+ MOR = 292,
77
+ PERIODDELIM = 293,
78
+ OTHERDELIM = 294,
79
+ LEFTDELIM = 295,
80
+ RIGHTDELIM = 296,
81
+ MOS = 297,
82
+ MOB = 298,
83
+ SQRT = 299,
84
+ ROOT = 300,
85
+ BINOM = 301,
86
+ UNDER = 302,
87
+ OVER = 303,
88
+ OVERBRACE = 304,
89
+ UNDERLINE = 305,
90
+ UNDERBRACE = 306,
91
+ UNDEROVER = 307,
92
+ TENSOR = 308,
93
+ MULTI = 309,
94
+ ARRAY = 310,
95
+ COLSEP = 311,
96
+ ROWSEP = 312,
97
+ ARRAYOPTS = 313,
98
+ COLLAYOUT = 314,
99
+ COLALIGN = 315,
100
+ ROWALIGN = 316,
101
+ ALIGN = 317,
102
+ EQROWS = 318,
103
+ EQCOLS = 319,
104
+ ROWLINES = 320,
105
+ COLLINES = 321,
106
+ FRAME = 322,
107
+ PADDING = 323,
108
+ ATTRLIST = 324,
109
+ ITALICS = 325,
110
+ BOLD = 326,
111
+ SLASHED = 327,
112
+ RM = 328,
113
+ BB = 329,
114
+ ST = 330,
115
+ END = 331,
116
+ BBLOWERCHAR = 332,
117
+ BBUPPERCHAR = 333,
118
+ BBDIGIT = 334,
119
+ CALCHAR = 335,
120
+ FRAKCHAR = 336,
121
+ CAL = 337,
122
+ FRAK = 338,
123
+ CLAP = 339,
124
+ LLAP = 340,
125
+ RLAP = 341,
126
+ ROWOPTS = 342,
127
+ TEXTSIZE = 343,
128
+ SCSIZE = 344,
129
+ SCSCSIZE = 345,
130
+ DISPLAY = 346,
131
+ TEXTSTY = 347,
132
+ TEXTBOX = 348,
133
+ TEXTSTRING = 349,
134
+ XMLSTRING = 350,
135
+ CELLOPTS = 351,
136
+ ROWSPAN = 352,
137
+ COLSPAN = 353,
138
+ THINSPACE = 354,
139
+ MEDSPACE = 355,
140
+ THICKSPACE = 356,
141
+ QUAD = 357,
142
+ QQUAD = 358,
143
+ NEGSPACE = 359,
144
+ PHANTOM = 360,
145
+ HREF = 361,
146
+ UNKNOWNCHAR = 362,
147
+ EMPTYMROW = 363,
148
+ STATLINE = 364,
149
+ TOOLTIP = 365,
150
+ TOGGLE = 366,
151
+ FGHIGHLIGHT = 367,
152
+ BGHIGHLIGHT = 368,
153
+ SPACE = 369,
154
+ INTONE = 370,
155
+ INTTWO = 371,
156
+ INTTHREE = 372,
157
+ BAR = 373,
158
+ WIDEBAR = 374,
159
+ VEC = 375,
160
+ WIDEVEC = 376,
161
+ HAT = 377,
162
+ WIDEHAT = 378,
163
+ CHECK = 379,
164
+ WIDECHECK = 380,
165
+ TILDE = 381,
166
+ WIDETILDE = 382,
167
+ DOT = 383,
168
+ DDOT = 384,
169
+ DDDOT = 385,
170
+ DDDDOT = 386,
171
+ UNARYMINUS = 387,
172
+ UNARYPLUS = 388,
173
+ BEGINENV = 389,
174
+ ENDENV = 390,
175
+ MATRIX = 391,
176
+ PMATRIX = 392,
177
+ BMATRIX = 393,
178
+ BBMATRIX = 394,
179
+ VMATRIX = 395,
180
+ VVMATRIX = 396,
181
+ SVG = 397,
182
+ ENDSVG = 398,
183
+ SMALLMATRIX = 399,
184
+ CASES = 400,
185
+ ALIGNED = 401,
186
+ GATHERED = 402,
187
+ SUBSTACK = 403,
188
+ PMOD = 404,
189
+ RMCHAR = 405,
190
+ COLOR = 406,
191
+ BGCOLOR = 407
192
+ };
193
+ #endif
194
+ /* Tokens. */
195
+ #define TEXATOP 258
196
+ #define TEXOVER 259
197
+ #define CHAR 260
198
+ #define STARTMATH 261
199
+ #define STARTDMATH 262
200
+ #define ENDMATH 263
201
+ #define MI 264
202
+ #define MIB 265
203
+ #define MN 266
204
+ #define MO 267
205
+ #define SUP 268
206
+ #define SUB 269
207
+ #define MROWOPEN 270
208
+ #define MROWCLOSE 271
209
+ #define LEFT 272
210
+ #define RIGHT 273
211
+ #define BIG 274
212
+ #define BBIG 275
213
+ #define BIGG 276
214
+ #define BBIGG 277
215
+ #define BIGL 278
216
+ #define BBIGL 279
217
+ #define BIGGL 280
218
+ #define BBIGGL 281
219
+ #define FRAC 282
220
+ #define TFRAC 283
221
+ #define OPERATORNAME 284
222
+ #define MATHOP 285
223
+ #define MATHBIN 286
224
+ #define MATHREL 287
225
+ #define MOP 288
226
+ #define MOL 289
227
+ #define MOLL 290
228
+ #define MOF 291
229
+ #define MOR 292
230
+ #define PERIODDELIM 293
231
+ #define OTHERDELIM 294
232
+ #define LEFTDELIM 295
233
+ #define RIGHTDELIM 296
234
+ #define MOS 297
235
+ #define MOB 298
236
+ #define SQRT 299
237
+ #define ROOT 300
238
+ #define BINOM 301
239
+ #define UNDER 302
240
+ #define OVER 303
241
+ #define OVERBRACE 304
242
+ #define UNDERLINE 305
243
+ #define UNDERBRACE 306
244
+ #define UNDEROVER 307
245
+ #define TENSOR 308
246
+ #define MULTI 309
247
+ #define ARRAY 310
248
+ #define COLSEP 311
249
+ #define ROWSEP 312
250
+ #define ARRAYOPTS 313
251
+ #define COLLAYOUT 314
252
+ #define COLALIGN 315
253
+ #define ROWALIGN 316
254
+ #define ALIGN 317
255
+ #define EQROWS 318
256
+ #define EQCOLS 319
257
+ #define ROWLINES 320
258
+ #define COLLINES 321
259
+ #define FRAME 322
260
+ #define PADDING 323
261
+ #define ATTRLIST 324
262
+ #define ITALICS 325
263
+ #define BOLD 326
264
+ #define SLASHED 327
265
+ #define RM 328
266
+ #define BB 329
267
+ #define ST 330
268
+ #define END 331
269
+ #define BBLOWERCHAR 332
270
+ #define BBUPPERCHAR 333
271
+ #define BBDIGIT 334
272
+ #define CALCHAR 335
273
+ #define FRAKCHAR 336
274
+ #define CAL 337
275
+ #define FRAK 338
276
+ #define CLAP 339
277
+ #define LLAP 340
278
+ #define RLAP 341
279
+ #define ROWOPTS 342
280
+ #define TEXTSIZE 343
281
+ #define SCSIZE 344
282
+ #define SCSCSIZE 345
283
+ #define DISPLAY 346
284
+ #define TEXTSTY 347
285
+ #define TEXTBOX 348
286
+ #define TEXTSTRING 349
287
+ #define XMLSTRING 350
288
+ #define CELLOPTS 351
289
+ #define ROWSPAN 352
290
+ #define COLSPAN 353
291
+ #define THINSPACE 354
292
+ #define MEDSPACE 355
293
+ #define THICKSPACE 356
294
+ #define QUAD 357
295
+ #define QQUAD 358
296
+ #define NEGSPACE 359
297
+ #define PHANTOM 360
298
+ #define HREF 361
299
+ #define UNKNOWNCHAR 362
300
+ #define EMPTYMROW 363
301
+ #define STATLINE 364
302
+ #define TOOLTIP 365
303
+ #define TOGGLE 366
304
+ #define FGHIGHLIGHT 367
305
+ #define BGHIGHLIGHT 368
306
+ #define SPACE 369
307
+ #define INTONE 370
308
+ #define INTTWO 371
309
+ #define INTTHREE 372
310
+ #define BAR 373
311
+ #define WIDEBAR 374
312
+ #define VEC 375
313
+ #define WIDEVEC 376
314
+ #define HAT 377
315
+ #define WIDEHAT 378
316
+ #define CHECK 379
317
+ #define WIDECHECK 380
318
+ #define TILDE 381
319
+ #define WIDETILDE 382
320
+ #define DOT 383
321
+ #define DDOT 384
322
+ #define DDDOT 385
323
+ #define DDDDOT 386
324
+ #define UNARYMINUS 387
325
+ #define UNARYPLUS 388
326
+ #define BEGINENV 389
327
+ #define ENDENV 390
328
+ #define MATRIX 391
329
+ #define PMATRIX 392
330
+ #define BMATRIX 393
331
+ #define BBMATRIX 394
332
+ #define VMATRIX 395
333
+ #define VVMATRIX 396
334
+ #define SVG 397
335
+ #define ENDSVG 398
336
+ #define SMALLMATRIX 399
337
+ #define CASES 400
338
+ #define ALIGNED 401
339
+ #define GATHERED 402
340
+ #define SUBSTACK 403
341
+ #define PMOD 404
342
+ #define RMCHAR 405
343
+ #define COLOR 406
344
+ #define BGCOLOR 407
345
+
346
+
347
+
348
+
349
+ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
350
+ typedef int YYSTYPE;
351
+ # define yystype YYSTYPE /* obsolescent; will be withdrawn */
352
+ # define YYSTYPE_IS_DECLARED 1
353
+ # define YYSTYPE_IS_TRIVIAL 1
354
+ #endif
355
+
356
+ extern YYSTYPE itex2MML_yylval;
357
+
data/lib/itextomml.rb ADDED
@@ -0,0 +1,171 @@
1
+ # Ruby module for itex2MML
2
+ #
3
+ # Installation
4
+ # ------------
5
+ # 1. You need SWIG (>= 1.3) and GNU Make to install
6
+ # the Ruby module.
7
+ # 2. Then type:
8
+ # make ruby
9
+ # make test_ruby
10
+ # make install_ruby
11
+ # 3. This module can then be invoked like:
12
+ #
13
+ # require 'itextomml'
14
+ #
15
+ # itex = Itex2MML::Parser.new
16
+ # itex.html_filter(string)
17
+ #
18
+ # Usage
19
+ # -----
20
+ #
21
+ # There are four public methods
22
+ #
23
+ # itex.html_filter(a_string)
24
+ # converts all itex equations in a_string to MathML, passing the
25
+ # rest of a_string unmodified. Returns the converted string.
26
+ #
27
+ # itex.filter(a_string)
28
+ # converts all itex equations in a_string to MathML. Returns just
29
+ # the MathML equation(s), as a string.
30
+ #
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
+ #
44
+ # Placed in the Public Domain
45
+
46
+ require 'itex2MML'
47
+ require 'thread'
48
+
49
+ module Itex2MML
50
+ class Error < RuntimeError; end
51
+
52
+ class Parser
53
+ def self.semaphore
54
+ @semaphore ||= Mutex.new
55
+ end
56
+
57
+ def html_filter(string)
58
+ parse(string, :itex2MML_html_filter)
59
+ end
60
+
61
+ def filter(string)
62
+ parse(string, :itex2MML_filter)
63
+ end
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
+
73
+ private
74
+
75
+ def parse(string, message)
76
+ str = as_bytes(string.to_str)
77
+ self.class.semaphore.synchronize do
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
+
103
+ end
104
+ end
105
+
106
+ ## Unit Tests ##
107
+ if __FILE__ == $0
108
+ require 'test/unit'
109
+
110
+ class Itex2MMLTest < Test::Unit::TestCase
111
+
112
+ def test_inline_html
113
+ itex = Itex2MML::Parser.new
114
+ assert_equal("Inline: <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('Inline: $\sin(x)$'))
115
+ end
116
+
117
+ def test_inline
118
+ itex = Itex2MML::Parser.new
119
+ 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)$'))
120
+ end
121
+
122
+ def test_inline_inline
123
+ itex = Itex2MML::Parser.new
124
+ 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)'))
125
+ end
126
+
127
+ def test_block_html
128
+ itex = Itex2MML::Parser.new
129
+ 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)$$'))
130
+ end
131
+
132
+ def test_block
133
+ itex = Itex2MML::Parser.new
134
+ 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)$$'))
135
+ end
136
+
137
+ def test_block_block
138
+ itex = Itex2MML::Parser.new
139
+ 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)'))
140
+ end
141
+
142
+ def test_inline_utf8
143
+ itex = Itex2MML::Parser.new
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)$"))
148
+ end
149
+
150
+ def test_inline_utf8_inline
151
+ itex = Itex2MML::Parser.new
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)$"))
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
169
+
170
+ end
171
+ end