mathematical 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1945 @@
1
+ /* itex2MML 1.4.5
2
+ * itex2MML.y last modified 10/2/2010
3
+ */
4
+
5
+ %parse-param {char **ret_str}
6
+
7
+ %{
8
+ #include <stdio.h>
9
+ #include <string.h>
10
+ #include <stdlib.h>
11
+
12
+ #include "itex2MML.h"
13
+
14
+ #define YYSTYPE char *
15
+ #define YYPARSE_PARAM_TYPE char **
16
+ #define YYPARSE_PARAM ret_str
17
+
18
+ #define yytext itex2MML_yytext
19
+
20
+ extern int yylex (void);
21
+
22
+ extern char * yytext;
23
+
24
+ static void itex2MML_default_error (const char * msg)
25
+ {
26
+ if (msg)
27
+ fprintf(stderr, "Line: %d Error: %s\n", itex2MML_lineno, msg);
28
+ }
29
+
30
+ void (*itex2MML_error) (const char * msg) = itex2MML_default_error;
31
+
32
+ static void yyerror (char **ret_str, const char * s)
33
+ {
34
+ char * msg = itex2MML_copy3 (s, " at token ", yytext);
35
+ if (itex2MML_error)
36
+ (*itex2MML_error) (msg);
37
+ itex2MML_free_string (msg);
38
+ }
39
+
40
+ /* Note: If length is 0, then buffer is treated like a string; otherwise only length bytes are written.
41
+ */
42
+ static void itex2MML_default_write (const char * buffer, unsigned long length)
43
+ {
44
+ if (buffer)
45
+ {
46
+ if (length)
47
+ fwrite (buffer, 1, length, stdout);
48
+ else
49
+ fputs (buffer, stdout);
50
+ }
51
+ }
52
+
53
+ static void itex2MML_default_write_mathml (const char * mathml)
54
+ {
55
+ if (itex2MML_write)
56
+ (*itex2MML_write) (mathml, 0);
57
+ }
58
+
59
+ #ifdef itex2MML_CAPTURE
60
+ static char * itex2MML_output_string = "" ;
61
+
62
+ const char * itex2MML_output ()
63
+ {
64
+ char * copy = (char *) malloc(strlen(itex2MML_output_string) +1);
65
+ if (copy)
66
+ {
67
+ if (itex2MML_output_string)
68
+ {
69
+ strcpy(copy, itex2MML_output_string);
70
+ if (itex2MML_output_string != "")
71
+ free(itex2MML_output_string);
72
+ }
73
+ else
74
+ copy[0] = 0;
75
+ }
76
+ itex2MML_output_string = "";
77
+ return copy;
78
+ }
79
+
80
+ static void itex2MML_capture (const char * buffer, unsigned long length)
81
+ {
82
+ if (buffer)
83
+ {
84
+ if (length)
85
+ {
86
+ unsigned long first_length = itex2MML_output_string ? strlen(itex2MML_output_string) : 0;
87
+ char * copy = (char *) malloc(first_length + length + 1);
88
+ if (copy)
89
+ {
90
+ if (itex2MML_output_string)
91
+ {
92
+ strcpy(copy, itex2MML_output_string);
93
+ if (itex2MML_output_string != "")
94
+ free(itex2MML_output_string);
95
+ }
96
+ else
97
+ copy[0] = 0;
98
+ strncat(copy, buffer, length);
99
+ }
100
+ itex2MML_output_string = copy;
101
+ }
102
+ else
103
+ {
104
+ char * copy = itex2MML_copy2(itex2MML_output_string, buffer);
105
+ if (itex2MML_output_string != "")
106
+ free(itex2MML_output_string);
107
+ itex2MML_output_string = copy;
108
+ }
109
+ }
110
+ }
111
+
112
+ static void itex2MML_capture_mathml (const char * buffer)
113
+ {
114
+ char * temp = itex2MML_copy2(itex2MML_output_string, buffer);
115
+ if (itex2MML_output_string != "")
116
+ free(itex2MML_output_string);
117
+ itex2MML_output_string = temp;
118
+ }
119
+ void (*itex2MML_write) (const char * buffer, unsigned long length) = itex2MML_capture;
120
+ void (*itex2MML_write_mathml) (const char * mathml) = itex2MML_capture_mathml;
121
+ #else
122
+ void (*itex2MML_write) (const char * buffer, unsigned long length) = itex2MML_default_write;
123
+ void (*itex2MML_write_mathml) (const char * mathml) = itex2MML_default_write_mathml;
124
+ #endif
125
+
126
+ char * itex2MML_empty_string = (char *) "";
127
+
128
+ /* Create a copy of a string, adding space for extra chars
129
+ */
130
+ char * itex2MML_copy_string_extra (const char * str, unsigned extra)
131
+ {
132
+ char * copy = (char *) malloc(extra + (str ? strlen (str) : 0) + 1);
133
+ if (copy)
134
+ {
135
+ if (str)
136
+ strcpy(copy, str);
137
+ else
138
+ copy[0] = 0;
139
+ }
140
+ return copy ? copy : itex2MML_empty_string;
141
+ }
142
+
143
+ /* Create a copy of a string, appending two strings
144
+ */
145
+ char * itex2MML_copy3 (const char * first, const char * second, const char * third)
146
+ {
147
+ int first_length = first ? strlen( first) : 0;
148
+ int second_length = second ? strlen(second) : 0;
149
+ int third_length = third ? strlen( third) : 0;
150
+
151
+ char * copy = (char *) malloc(first_length + second_length + third_length + 1);
152
+
153
+ if (copy)
154
+ {
155
+ if (first)
156
+ strcpy(copy, first);
157
+ else
158
+ copy[0] = 0;
159
+
160
+ if (second) strcat(copy, second);
161
+ if ( third) strcat(copy, third);
162
+ }
163
+ return copy ? copy : itex2MML_empty_string;
164
+ }
165
+
166
+ /* Create a copy of a string, appending a second string
167
+ */
168
+ char * itex2MML_copy2 (const char * first, const char * second)
169
+ {
170
+ return itex2MML_copy3(first, second, 0);
171
+ }
172
+
173
+ /* Create a copy of a string
174
+ */
175
+ char * itex2MML_copy_string (const char * str)
176
+ {
177
+ return itex2MML_copy3(str, 0, 0);
178
+ }
179
+
180
+ /* Create a copy of a string, escaping unsafe characters for XML
181
+ */
182
+ char * itex2MML_copy_escaped (const char * str)
183
+ {
184
+ unsigned long length = 0;
185
+
186
+ const char * ptr1 = str;
187
+
188
+ char * ptr2 = 0;
189
+ char * copy = 0;
190
+
191
+ if ( str == 0) return itex2MML_empty_string;
192
+ if (*str == 0) return itex2MML_empty_string;
193
+
194
+ while (*ptr1)
195
+ {
196
+ switch (*ptr1)
197
+ {
198
+ case '<': /* &lt; */
199
+ case '>': /* &gt; */
200
+ length += 4;
201
+ break;
202
+ case '&': /* &amp; */
203
+ length += 5;
204
+ break;
205
+ case '\'': /* &apos; */
206
+ case '"': /* &quot; */
207
+ case '-': /* &#x2d; */
208
+ length += 6;
209
+ break;
210
+ default:
211
+ length += 1;
212
+ break;
213
+ }
214
+ ++ptr1;
215
+ }
216
+
217
+ copy = (char *) malloc (length + 1);
218
+
219
+ if (copy)
220
+ {
221
+ ptr1 = str;
222
+ ptr2 = copy;
223
+
224
+ while (*ptr1)
225
+ {
226
+ switch (*ptr1)
227
+ {
228
+ case '<':
229
+ strcpy (ptr2, "&lt;");
230
+ ptr2 += 4;
231
+ break;
232
+ case '>':
233
+ strcpy (ptr2, "&gt;");
234
+ ptr2 += 4;
235
+ break;
236
+ case '&': /* &amp; */
237
+ strcpy (ptr2, "&amp;");
238
+ ptr2 += 5;
239
+ break;
240
+ case '\'': /* &apos; */
241
+ strcpy (ptr2, "&apos;");
242
+ ptr2 += 6;
243
+ break;
244
+ case '"': /* &quot; */
245
+ strcpy (ptr2, "&quot;");
246
+ ptr2 += 6;
247
+ break;
248
+ case '-': /* &#x2d; */
249
+ strcpy (ptr2, "&#x2d;");
250
+ ptr2 += 6;
251
+ break;
252
+ default:
253
+ *ptr2++ = *ptr1;
254
+ break;
255
+ }
256
+ ++ptr1;
257
+ }
258
+ *ptr2 = 0;
259
+ }
260
+ return copy ? copy : itex2MML_empty_string;
261
+ }
262
+
263
+ /* Create a hex character reference string corresponding to code
264
+ */
265
+ static char * itex2MML_character_reference (unsigned long int code)
266
+ {
267
+ #define ENTITY_LENGTH 10
268
+ char * entity = (char *) malloc(ENTITY_LENGTH);
269
+ sprintf(entity, "&#x%05lx;", code);
270
+ return entity;
271
+ }
272
+
273
+ void itex2MML_free_string (char * str)
274
+ {
275
+ if (str && str != itex2MML_empty_string)
276
+ free(str);
277
+ }
278
+
279
+ %}
280
+
281
+ %left TEXOVER TEXATOP
282
+ %token CHAR STARTMATH STARTDMATH ENDMATH MI MIB MN MO SUP SUB MROWOPEN MROWCLOSE LEFT RIGHT BIG BBIG BIGG BBIGG BIGL BBIGL BIGGL BBIGGL FRAC TFRAC OPERATORNAME MATHOP MATHBIN MATHREL MOP MOL MOLL MOF MOR PERIODDELIM OTHERDELIM LEFTDELIM RIGHTDELIM MOS MOB SQRT ROOT BINOM TBINOM UNDER OVER OVERBRACE UNDERLINE UNDERBRACE UNDEROVER TENSOR MULTI ARRAYALIGN COLUMNALIGN ARRAY COLSEP ROWSEP ARRAYOPTS COLLAYOUT COLALIGN ROWALIGN ALIGN EQROWS EQCOLS ROWLINES COLLINES FRAME PADDING ATTRLIST ITALICS BOLD BOXED SLASHED RM BB ST END BBLOWERCHAR BBUPPERCHAR BBDIGIT CALCHAR FRAKCHAR CAL FRAK CLAP LLAP RLAP ROWOPTS TEXTSIZE SCSIZE SCSCSIZE DISPLAY TEXTSTY TEXTBOX TEXTSTRING XMLSTRING CELLOPTS ROWSPAN COLSPAN THINSPACE MEDSPACE THICKSPACE QUAD QQUAD NEGSPACE PHANTOM HREF UNKNOWNCHAR EMPTYMROW STATLINE TOOLTIP TOGGLE FGHIGHLIGHT BGHIGHLIGHT SPACE INTONE INTTWO INTTHREE BAR WIDEBAR VEC WIDEVEC HAT WIDEHAT CHECK WIDECHECK TILDE WIDETILDE DOT DDOT DDDOT DDDDOT UNARYMINUS UNARYPLUS BEGINENV ENDENV MATRIX PMATRIX BMATRIX BBMATRIX VMATRIX VVMATRIX SVG ENDSVG SMALLMATRIX CASES ALIGNED GATHERED SUBSTACK PMOD RMCHAR COLOR BGCOLOR XARROW OPTARGOPEN OPTARGCLOSE
283
+
284
+ %%
285
+
286
+ doc: xmlmmlTermList {/* all processing done in body*/};
287
+
288
+ xmlmmlTermList:
289
+ {/* nothing - do nothing*/}
290
+ | char {/* proc done in body*/}
291
+ | expression {/* all proc. in body*/}
292
+ | xmlmmlTermList char {/* all proc. in body*/}
293
+ | xmlmmlTermList expression {/* all proc. in body*/};
294
+
295
+ char: CHAR {};
296
+
297
+ expression: STARTMATH ENDMATH {/* empty math group - ignore*/}
298
+ | STARTDMATH ENDMATH {/* ditto */}
299
+ | STARTMATH compoundTermList ENDMATH {
300
+ char ** r = (char **) ret_str;
301
+ char * s = itex2MML_copy3("<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'>", $2, "</math>");
302
+ itex2MML_free_string($2);
303
+ if (r) {
304
+ (*r) = (s == itex2MML_empty_string) ? 0 : s;
305
+ }
306
+ else {
307
+ if (itex2MML_write_mathml)
308
+ (*itex2MML_write_mathml) (s);
309
+ itex2MML_free_string(s);
310
+ }
311
+ }
312
+ | STARTDMATH compoundTermList ENDMATH {
313
+ char ** r = (char **) ret_str;
314
+ char * s = itex2MML_copy3("<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'>", $2, "</math>");
315
+ itex2MML_free_string($2);
316
+ if (r) {
317
+ (*r) = (s == itex2MML_empty_string) ? 0 : s;
318
+ }
319
+ else {
320
+ if (itex2MML_write_mathml)
321
+ (*itex2MML_write_mathml) (s);
322
+ itex2MML_free_string(s);
323
+ }
324
+ };
325
+
326
+ compoundTermList: compoundTerm {
327
+ $$ = itex2MML_copy_string($1);
328
+ itex2MML_free_string($1);
329
+ }
330
+ | compoundTermList compoundTerm {
331
+ $$ = itex2MML_copy2($1, $2);
332
+ itex2MML_free_string($1);
333
+ itex2MML_free_string($2);
334
+ };
335
+
336
+ compoundTerm: mob SUB closedTerm SUP closedTerm {
337
+ if (itex2MML_displaymode == 1) {
338
+ char * s1 = itex2MML_copy3("<munderover>", $1, " ");
339
+ char * s2 = itex2MML_copy3($3, " ", $5);
340
+ $$ = itex2MML_copy3(s1, s2, "</munderover>");
341
+ itex2MML_free_string(s1);
342
+ itex2MML_free_string(s2);
343
+ }
344
+ else {
345
+ char * s1 = itex2MML_copy3("<msubsup>", $1, " ");
346
+ char * s2 = itex2MML_copy3($3, " ", $5);
347
+ $$ = itex2MML_copy3(s1, s2, "</msubsup>");
348
+ itex2MML_free_string(s1);
349
+ itex2MML_free_string(s2);
350
+ }
351
+ itex2MML_free_string($1);
352
+ itex2MML_free_string($3);
353
+ itex2MML_free_string($5);
354
+ }
355
+ | mob SUB closedTerm {
356
+ if (itex2MML_displaymode == 1) {
357
+ char * s1 = itex2MML_copy3("<munder>", $1, " ");
358
+ $$ = itex2MML_copy3(s1, $3, "</munder>");
359
+ itex2MML_free_string(s1);
360
+ }
361
+ else {
362
+ char * s1 = itex2MML_copy3("<msub>", $1, " ");
363
+ $$ = itex2MML_copy3(s1, $3, "</msub>");
364
+ itex2MML_free_string(s1);
365
+ }
366
+ itex2MML_free_string($1);
367
+ itex2MML_free_string($3);
368
+ }
369
+ | mob SUP closedTerm SUB closedTerm {
370
+ if (itex2MML_displaymode == 1) {
371
+ char * s1 = itex2MML_copy3("<munderover>", $1, " ");
372
+ char * s2 = itex2MML_copy3($5, " ", $3);
373
+ $$ = itex2MML_copy3(s1, s2, "</munderover>");
374
+ itex2MML_free_string(s1);
375
+ itex2MML_free_string(s2);
376
+ }
377
+ else {
378
+ char * s1 = itex2MML_copy3("<msubsup>", $1, " ");
379
+ char * s2 = itex2MML_copy3($5, " ", $3);
380
+ $$ = itex2MML_copy3(s1, s2, "</msubsup>");
381
+ itex2MML_free_string(s1);
382
+ itex2MML_free_string(s2);
383
+ }
384
+ itex2MML_free_string($1);
385
+ itex2MML_free_string($3);
386
+ itex2MML_free_string($5);
387
+ }
388
+ | mob SUP closedTerm {
389
+ if (itex2MML_displaymode == 1) {
390
+ char * s1 = itex2MML_copy3("<mover>", $1, " ");
391
+ $$ = itex2MML_copy3(s1, $3, "</mover>");
392
+ itex2MML_free_string(s1);
393
+ }
394
+ else {
395
+ char * s1 = itex2MML_copy3("<msup>", $1, " ");
396
+ $$ = itex2MML_copy3(s1, $3, "</msup>");
397
+ itex2MML_free_string(s1);
398
+ }
399
+ itex2MML_free_string($1);
400
+ itex2MML_free_string($3);
401
+ }
402
+ |mib SUB closedTerm SUP closedTerm {
403
+ if (itex2MML_displaymode == 1) {
404
+ char * s1 = itex2MML_copy3("<munderover>", $1, " ");
405
+ char * s2 = itex2MML_copy3($3, " ", $5);
406
+ $$ = itex2MML_copy3(s1, s2, "</munderover>");
407
+ itex2MML_free_string(s1);
408
+ itex2MML_free_string(s2);
409
+ }
410
+ else {
411
+ char * s1 = itex2MML_copy3("<msubsup>", $1, " ");
412
+ char * s2 = itex2MML_copy3($3, " ", $5);
413
+ $$ = itex2MML_copy3(s1, s2, "</msubsup>");
414
+ itex2MML_free_string(s1);
415
+ itex2MML_free_string(s2);
416
+ }
417
+ itex2MML_free_string($1);
418
+ itex2MML_free_string($3);
419
+ itex2MML_free_string($5);
420
+ }
421
+ | mib SUB closedTerm {
422
+ if (itex2MML_displaymode == 1) {
423
+ char * s1 = itex2MML_copy3("<munder>", $1, " ");
424
+ $$ = itex2MML_copy3(s1, $3, "</munder>");
425
+ itex2MML_free_string(s1);
426
+ }
427
+ else {
428
+ char * s1 = itex2MML_copy3("<msub>", $1, " ");
429
+ $$ = itex2MML_copy3(s1, $3, "</msub>");
430
+ itex2MML_free_string(s1);
431
+ }
432
+ itex2MML_free_string($1);
433
+ itex2MML_free_string($3);
434
+ }
435
+ | mib SUP closedTerm SUB closedTerm {
436
+ if (itex2MML_displaymode == 1) {
437
+ char * s1 = itex2MML_copy3("<munderover>", $1, " ");
438
+ char * s2 = itex2MML_copy3($5, " ", $3);
439
+ $$ = itex2MML_copy3(s1, s2, "</munderover>");
440
+ itex2MML_free_string(s1);
441
+ itex2MML_free_string(s2);
442
+ }
443
+ else {
444
+ char * s1 = itex2MML_copy3("<msubsup>", $1, " ");
445
+ char * s2 = itex2MML_copy3($5, " ", $3);
446
+ $$ = itex2MML_copy3(s1, s2, "</msubsup>");
447
+ itex2MML_free_string(s1);
448
+ itex2MML_free_string(s2);
449
+ }
450
+ itex2MML_free_string($1);
451
+ itex2MML_free_string($3);
452
+ itex2MML_free_string($5);
453
+ }
454
+ | mib SUP closedTerm {
455
+ if (itex2MML_displaymode == 1) {
456
+ char * s1 = itex2MML_copy3("<mover>", $1, " ");
457
+ $$ = itex2MML_copy3(s1, $3, "</mover>");
458
+ itex2MML_free_string(s1);
459
+ }
460
+ else {
461
+ char * s1 = itex2MML_copy3("<msup>", $1, " ");
462
+ $$ = itex2MML_copy3(s1, $3, "</msup>");
463
+ itex2MML_free_string(s1);
464
+ }
465
+ itex2MML_free_string($1);
466
+ itex2MML_free_string($3);
467
+ }
468
+ | closedTerm SUB closedTerm SUP closedTerm {
469
+ char * s1 = itex2MML_copy3("<msubsup>", $1, " ");
470
+ char * s2 = itex2MML_copy3($3, " ", $5);
471
+ $$ = itex2MML_copy3(s1, s2, "</msubsup>");
472
+ itex2MML_free_string(s1);
473
+ itex2MML_free_string(s2);
474
+ itex2MML_free_string($1);
475
+ itex2MML_free_string($3);
476
+ itex2MML_free_string($5);
477
+ }
478
+ | closedTerm SUP closedTerm SUB closedTerm {
479
+ char * s1 = itex2MML_copy3("<msubsup>", $1, " ");
480
+ char * s2 = itex2MML_copy3($5, " ", $3);
481
+ $$ = itex2MML_copy3(s1, s2, "</msubsup>");
482
+ itex2MML_free_string(s1);
483
+ itex2MML_free_string(s2);
484
+ itex2MML_free_string($1);
485
+ itex2MML_free_string($3);
486
+ itex2MML_free_string($5);
487
+ }
488
+ | closedTerm SUB closedTerm {
489
+ char * s1 = itex2MML_copy3("<msub>", $1, " ");
490
+ $$ = itex2MML_copy3(s1, $3, "</msub>");
491
+ itex2MML_free_string(s1);
492
+ itex2MML_free_string($1);
493
+ itex2MML_free_string($3);
494
+ }
495
+ | closedTerm SUP closedTerm {
496
+ char * s1 = itex2MML_copy3("<msup>", $1, " ");
497
+ $$ = itex2MML_copy3(s1, $3, "</msup>");
498
+ itex2MML_free_string(s1);
499
+ itex2MML_free_string($1);
500
+ itex2MML_free_string($3);
501
+ }
502
+ | SUB closedTerm {
503
+ $$ = itex2MML_copy3("<msub><mo></mo>", $2, "</msub>");
504
+ itex2MML_free_string($2);
505
+ }
506
+ | SUP closedTerm {
507
+ $$ = itex2MML_copy3("<msup><mo></mo>", $2, "</msup>");
508
+ itex2MML_free_string($2);
509
+ }
510
+ | closedTerm {
511
+ $$ = itex2MML_copy_string($1);
512
+ itex2MML_free_string($1);
513
+ };
514
+
515
+ closedTerm: array
516
+ | unaryminus
517
+ | unaryplus
518
+ | mib
519
+ | mi {
520
+ $$ = itex2MML_copy3("<mi>", $1, "</mi>");
521
+ itex2MML_free_string($1);
522
+ }
523
+ | mn {
524
+ $$ = itex2MML_copy3("<mn>", $1, "</mn>");
525
+ itex2MML_free_string($1);
526
+ }
527
+ | mo
528
+ | tensor
529
+ | multi
530
+ | mfrac
531
+ | binom
532
+ | msqrt
533
+ | mroot
534
+ | munder
535
+ | mover
536
+ | bar
537
+ | vec
538
+ | hat
539
+ | dot
540
+ | ddot
541
+ | dddot
542
+ | ddddot
543
+ | check
544
+ | tilde
545
+ | moverbrace
546
+ | munderbrace
547
+ | munderline
548
+ | munderover
549
+ | emptymrow
550
+ | mathclap
551
+ | mathllap
552
+ | mathrlap
553
+ | displaystyle
554
+ | textstyle
555
+ | textsize
556
+ | scriptsize
557
+ | scriptscriptsize
558
+ | italics
559
+ | bold
560
+ | roman
561
+ | rmchars
562
+ | bbold
563
+ | frak
564
+ | slashed
565
+ | boxed
566
+ | cal
567
+ | space
568
+ | textstring
569
+ | thinspace
570
+ | medspace
571
+ | thickspace
572
+ | quad
573
+ | qquad
574
+ | negspace
575
+ | phantom
576
+ | href
577
+ | statusline
578
+ | tooltip
579
+ | toggle
580
+ | fghighlight
581
+ | bghighlight
582
+ | color
583
+ | texover
584
+ | texatop
585
+ | MROWOPEN closedTerm MROWCLOSE {
586
+ $$ = itex2MML_copy_string($2);
587
+ itex2MML_free_string($2);
588
+ }
589
+ | MROWOPEN compoundTermList MROWCLOSE {
590
+ $$ = itex2MML_copy3("<mrow>", $2, "</mrow>");
591
+ itex2MML_free_string($2);
592
+ }
593
+ | left compoundTermList right {
594
+ char * s1 = itex2MML_copy3("<mrow>", $1, $2);
595
+ $$ = itex2MML_copy3(s1, $3, "</mrow>");
596
+ itex2MML_free_string(s1);
597
+ itex2MML_free_string($1);
598
+ itex2MML_free_string($2);
599
+ itex2MML_free_string($3);
600
+ }
601
+ | mathenv
602
+ | substack
603
+ | pmod
604
+ | unrecognized;
605
+
606
+ left: LEFT LEFTDELIM {
607
+ itex2MML_rowposn = 2;
608
+ $$ = itex2MML_copy3("<mo>", $2, "</mo>");
609
+ itex2MML_free_string($2);
610
+ }
611
+ | LEFT OTHERDELIM {
612
+ itex2MML_rowposn = 2;
613
+ $$ = itex2MML_copy3("<mo>", $2, "</mo>");
614
+ itex2MML_free_string($2);
615
+ }
616
+ | LEFT PERIODDELIM {
617
+ itex2MML_rowposn = 2;
618
+ $$ = itex2MML_copy_string("");
619
+ itex2MML_free_string($2);
620
+ };
621
+
622
+ right: RIGHT RIGHTDELIM {
623
+ $$ = itex2MML_copy3("<mo>", $2, "</mo>");
624
+ itex2MML_free_string($2);
625
+ }
626
+ | RIGHT OTHERDELIM {
627
+ $$ = itex2MML_copy3("<mo>", $2, "</mo>");
628
+ itex2MML_free_string($2);
629
+ }
630
+ | RIGHT PERIODDELIM {
631
+ $$ = itex2MML_copy_string("");
632
+ itex2MML_free_string($2);
633
+ };
634
+
635
+ bigdelim: BIG LEFTDELIM {
636
+ itex2MML_rowposn = 2;
637
+ $$ = itex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
638
+ itex2MML_free_string($2);
639
+ }
640
+ | BIG RIGHTDELIM {
641
+ $$ = itex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
642
+ itex2MML_free_string($2);
643
+ }
644
+ | BIG OTHERDELIM {
645
+ $$ = itex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
646
+ itex2MML_free_string($2);
647
+ }
648
+ | BBIG LEFTDELIM {
649
+ itex2MML_rowposn = 2;
650
+ $$ = itex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
651
+ itex2MML_free_string($2);
652
+ }
653
+ | BBIG RIGHTDELIM {
654
+ $$ = itex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
655
+ itex2MML_free_string($2);
656
+ }
657
+ | BBIG OTHERDELIM {
658
+ $$ = itex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
659
+ itex2MML_free_string($2);
660
+ }
661
+ | BIGG LEFTDELIM {
662
+ itex2MML_rowposn = 2;
663
+ $$ = itex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
664
+ itex2MML_free_string($2);
665
+ }
666
+ | BIGG RIGHTDELIM {
667
+ $$ = itex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
668
+ itex2MML_free_string($2);
669
+ }
670
+ | BIGG OTHERDELIM {
671
+ $$ = itex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
672
+ itex2MML_free_string($2);
673
+ }
674
+ | BBIGG LEFTDELIM {
675
+ itex2MML_rowposn = 2;
676
+ $$ = itex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
677
+ itex2MML_free_string($2);
678
+ }
679
+ | BBIGG RIGHTDELIM {
680
+ $$ = itex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
681
+ itex2MML_free_string($2);
682
+ }
683
+ | BBIGG OTHERDELIM {
684
+ $$ = itex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
685
+ itex2MML_free_string($2);
686
+ }
687
+ |BIGL LEFTDELIM {
688
+ itex2MML_rowposn = 2;
689
+ $$ = itex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
690
+ itex2MML_free_string($2);
691
+ }
692
+ | BIGL OTHERDELIM {
693
+ itex2MML_rowposn = 2;
694
+ $$ = itex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
695
+ itex2MML_free_string($2);
696
+ }
697
+ | BBIGL LEFTDELIM {
698
+ itex2MML_rowposn = 2;
699
+ $$ = itex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
700
+ itex2MML_free_string($2);
701
+ }
702
+ | BBIGL OTHERDELIM {
703
+ itex2MML_rowposn = 2;
704
+ $$ = itex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
705
+ itex2MML_free_string($2);
706
+ }
707
+ | BIGGL LEFTDELIM {
708
+ itex2MML_rowposn = 2;
709
+ $$ = itex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
710
+ itex2MML_free_string($2);
711
+ }
712
+ | BIGGL OTHERDELIM {
713
+ itex2MML_rowposn = 2;
714
+ $$ = itex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
715
+ itex2MML_free_string($2);
716
+ }
717
+ | BBIGGL LEFTDELIM {
718
+ itex2MML_rowposn = 2;
719
+ $$ = itex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
720
+ itex2MML_free_string($2);
721
+ }
722
+ | BBIGGL OTHERDELIM {
723
+ itex2MML_rowposn = 2;
724
+ $$ = itex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
725
+ itex2MML_free_string($2);
726
+ };
727
+
728
+ unrecognized: UNKNOWNCHAR {
729
+ $$ = itex2MML_copy_string("<merror><mtext>Unknown character</mtext></merror>");
730
+ };
731
+
732
+ unaryminus: UNARYMINUS {
733
+ $$ = itex2MML_copy_string("<mo lspace=\"verythinmathspace\" rspace=\"0em\">&minus;</mo>");
734
+ };
735
+
736
+ unaryplus: UNARYPLUS {
737
+ $$ = itex2MML_copy_string("<mo lspace=\"verythinmathspace\" rspace=\"0em\">+</mo>");
738
+ };
739
+
740
+ mi: MI;
741
+
742
+ mib: MIB {
743
+ itex2MML_rowposn=2;
744
+ $$ = itex2MML_copy3("<mi>", $1, "</mi>");
745
+ itex2MML_free_string($1);
746
+ };
747
+
748
+ mn: MN;
749
+
750
+ mob: MOB {
751
+ itex2MML_rowposn = 2;
752
+ $$ = itex2MML_copy3("<mo lspace=\"thinmathspace\" rspace=\"thinmathspace\">", $1, "</mo>");
753
+ itex2MML_free_string($1);
754
+ };
755
+
756
+ mo: mob
757
+ | bigdelim
758
+ | MO {
759
+ itex2MML_rowposn = 2;
760
+ $$ = itex2MML_copy3("<mo>", $1, "</mo>");
761
+ itex2MML_free_string($1);
762
+ }
763
+ | MOL {
764
+ itex2MML_rowposn = 2;
765
+ $$ = itex2MML_copy3("<mo>", $1, "</mo>");
766
+ itex2MML_free_string($1);
767
+ }
768
+ | MOLL {
769
+ itex2MML_rowposn = 2;
770
+ $$ = itex2MML_copy3("<mstyle scriptlevel=\"0\"><mo>", $1, "</mo></mstyle>");
771
+ itex2MML_free_string($1);
772
+ }
773
+ | RIGHTDELIM {
774
+ $$ = itex2MML_copy3("<mo stretchy=\"false\">", $1, "</mo>");
775
+ itex2MML_free_string($1);
776
+ }
777
+ | LEFTDELIM {
778
+ itex2MML_rowposn = 2;
779
+ $$ = itex2MML_copy3("<mo stretchy=\"false\">", $1, "</mo>");
780
+ itex2MML_free_string($1);
781
+ }
782
+ | OTHERDELIM {
783
+ $$ = itex2MML_copy3("<mo stretchy=\"false\">", $1, "</mo>");
784
+ itex2MML_free_string($1);
785
+ }
786
+ | MOF {
787
+ $$ = itex2MML_copy3("<mo stretchy=\"false\">", $1, "</mo>");
788
+ itex2MML_free_string($1);
789
+ }
790
+ | PERIODDELIM {
791
+ $$ = itex2MML_copy3("<mo>", $1, "</mo>");
792
+ itex2MML_free_string($1);
793
+ }
794
+ | MOS {
795
+ itex2MML_rowposn=2;
796
+ $$ = itex2MML_copy3("<mo lspace=\"mediummathspace\" rspace=\"mediummathspace\">", $1, "</mo>");
797
+ itex2MML_free_string($1);
798
+ }
799
+ | MOP {
800
+ itex2MML_rowposn = 2;
801
+ $$ = itex2MML_copy3("<mo lspace=\"0em\" rspace=\"thinmathspace\">", $1, "</mo>");
802
+ itex2MML_free_string($1);
803
+ }
804
+ | MOR {
805
+ itex2MML_rowposn = 2;
806
+ $$ = itex2MML_copy3("<mo lspace=\"verythinmathspace\">", $1, "</mo>");
807
+ itex2MML_free_string($1);
808
+ }
809
+ | OPERATORNAME TEXTSTRING {
810
+ itex2MML_rowposn = 2;
811
+ $$ = itex2MML_copy3("<mo lspace=\"0em\" rspace=\"thinmathspace\">", $2, "</mo>");
812
+ itex2MML_free_string($2);
813
+ }
814
+ | MATHOP TEXTSTRING {
815
+ itex2MML_rowposn = 2;
816
+ $$ = itex2MML_copy3("<mo lspace=\"thinmathspace\" rspace=\"thinmathspace\">", $2, "</mo>");
817
+ itex2MML_free_string($2);
818
+ }
819
+ | MATHBIN TEXTSTRING {
820
+ itex2MML_rowposn = 2;
821
+ $$ = itex2MML_copy3("<mo lspace=\"mediummathspace\" rspace=\"mediummathspace\">", $2, "</mo>");
822
+ itex2MML_free_string($2);
823
+ }
824
+ | MATHREL TEXTSTRING {
825
+ itex2MML_rowposn = 2;
826
+ $$ = itex2MML_copy3("<mo lspace=\"thickmathspace\" rspace=\"thickmathspace\">", $2, "</mo>");
827
+ itex2MML_free_string($2);
828
+ };
829
+
830
+ space: SPACE ST INTONE END ST INTTWO END ST INTTHREE END {
831
+ char * s1 = itex2MML_copy3("<mspace height=\"", $3, "ex\" depth=\"");
832
+ char * s2 = itex2MML_copy3($6, "ex\" width=\"", $9);
833
+ $$ = itex2MML_copy3(s1, s2, "em\"></mspace>");
834
+ itex2MML_free_string(s1);
835
+ itex2MML_free_string(s2);
836
+ itex2MML_free_string($3);
837
+ itex2MML_free_string($6);
838
+ itex2MML_free_string($9);
839
+ };
840
+
841
+ statusline: STATLINE TEXTSTRING closedTerm {
842
+ char * s1 = itex2MML_copy3("<maction actiontype=\"statusline\">", $3, "<mtext>");
843
+ $$ = itex2MML_copy3(s1, $2, "</mtext></maction>");
844
+ itex2MML_free_string(s1);
845
+ itex2MML_free_string($2);
846
+ itex2MML_free_string($3);
847
+ };
848
+
849
+ tooltip: TOOLTIP TEXTSTRING closedTerm {
850
+ char * s1 = itex2MML_copy3("<maction actiontype=\"tooltip\">", $3, "<mtext>");
851
+ $$ = itex2MML_copy3(s1, $2, "</mtext></maction>");
852
+ itex2MML_free_string(s1);
853
+ itex2MML_free_string($2);
854
+ itex2MML_free_string($3);
855
+ };
856
+
857
+ toggle: TOGGLE closedTerm closedTerm {
858
+ char * s1 = itex2MML_copy3("<maction actiontype=\"toggle\" selection=\"2\">", $2, " ");
859
+ $$ = itex2MML_copy3(s1, $3, "</maction>");
860
+ itex2MML_free_string(s1);
861
+ itex2MML_free_string($2);
862
+ itex2MML_free_string($3);
863
+ };
864
+
865
+ fghighlight: FGHIGHLIGHT ATTRLIST closedTerm {
866
+ char * s1 = itex2MML_copy3("<maction actiontype=\"highlight\" other='color=", $2, "'>");
867
+ $$ = itex2MML_copy3(s1, $3, "</maction>");
868
+ itex2MML_free_string(s1);
869
+ itex2MML_free_string($2);
870
+ itex2MML_free_string($3);
871
+ };
872
+
873
+ bghighlight: BGHIGHLIGHT ATTRLIST closedTerm {
874
+ char * s1 = itex2MML_copy3("<maction actiontype=\"highlight\" other='background=", $2, "'>");
875
+ $$ = itex2MML_copy3(s1, $3, "</maction>");
876
+ itex2MML_free_string(s1);
877
+ itex2MML_free_string($2);
878
+ itex2MML_free_string($3);
879
+ };
880
+
881
+ color: COLOR ATTRLIST compoundTermList {
882
+ char * s1 = itex2MML_copy3("<mstyle mathcolor=", $2, ">");
883
+ $$ = itex2MML_copy3(s1, $3, "</mstyle>");
884
+ itex2MML_free_string(s1);
885
+ itex2MML_free_string($2);
886
+ itex2MML_free_string($3);
887
+ }
888
+ | BGCOLOR ATTRLIST compoundTermList {
889
+ char * s1 = itex2MML_copy3("<mstyle mathbackground=", $2, ">");
890
+ $$ = itex2MML_copy3(s1, $3, "</mstyle>");
891
+ itex2MML_free_string(s1);
892
+ itex2MML_free_string($2);
893
+ itex2MML_free_string($3);
894
+ };
895
+
896
+ mathrlap: RLAP closedTerm {
897
+ $$ = itex2MML_copy3("<mpadded width=\"0\">", $2, "</mpadded>");
898
+ itex2MML_free_string($2);
899
+ };
900
+
901
+ mathllap: LLAP closedTerm {
902
+ $$ = itex2MML_copy3("<mpadded width=\"0\" lspace=\"-100%width\">", $2, "</mpadded>");
903
+ itex2MML_free_string($2);
904
+ };
905
+
906
+ mathclap: CLAP closedTerm {
907
+ $$ = itex2MML_copy3("<mpadded width=\"0\" lspace=\"-50%width\">", $2, "</mpadded>");
908
+ itex2MML_free_string($2);
909
+ };
910
+
911
+ textstring: TEXTBOX TEXTSTRING {
912
+ $$ = itex2MML_copy3("<mtext>", $2, "</mtext>");
913
+ itex2MML_free_string($2);
914
+ };
915
+
916
+ displaystyle: DISPLAY closedTerm {
917
+ $$ = itex2MML_copy3("<mstyle displaystyle=\"true\">", $2, "</mstyle>");
918
+ itex2MML_free_string($2);
919
+ };
920
+
921
+ textstyle: TEXTSTY closedTerm {
922
+ $$ = itex2MML_copy3("<mstyle displaystyle=\"false\">", $2, "</mstyle>");
923
+ itex2MML_free_string($2);
924
+ };
925
+
926
+ textsize: TEXTSIZE closedTerm {
927
+ $$ = itex2MML_copy3("<mstyle scriptlevel=\"0\">", $2, "</mstyle>");
928
+ itex2MML_free_string($2);
929
+ };
930
+
931
+ scriptsize: SCSIZE closedTerm {
932
+ $$ = itex2MML_copy3("<mstyle scriptlevel=\"1\">", $2, "</mstyle>");
933
+ itex2MML_free_string($2);
934
+ };
935
+
936
+ scriptscriptsize: SCSCSIZE closedTerm {
937
+ $$ = itex2MML_copy3("<mstyle scriptlevel=\"2\">", $2, "</mstyle>");
938
+ itex2MML_free_string($2);
939
+ };
940
+
941
+ italics: ITALICS closedTerm {
942
+ $$ = itex2MML_copy3("<mstyle mathvariant=\"italic\">", $2, "</mstyle>");
943
+ itex2MML_free_string($2);
944
+ };
945
+
946
+ slashed: SLASHED closedTerm {
947
+ $$ = itex2MML_copy3("<menclose notation=\"updiagonalstrike\">", $2, "</menclose>");
948
+ itex2MML_free_string($2);
949
+ };
950
+
951
+ boxed: BOXED closedTerm {
952
+ $$ = itex2MML_copy3("<menclose notation=\"box\">", $2, "</menclose>");
953
+ itex2MML_free_string($2);
954
+ };
955
+
956
+ bold: BOLD closedTerm {
957
+ $$ = itex2MML_copy3("<mstyle mathvariant=\"bold\">", $2, "</mstyle>");
958
+ itex2MML_free_string($2);
959
+ };
960
+
961
+ roman: RM ST rmchars END {
962
+ $$ = itex2MML_copy3("<mi mathvariant=\"normal\">", $3, "</mi>");
963
+ itex2MML_free_string($3);
964
+ };
965
+
966
+ rmchars: RMCHAR {
967
+ $$ = itex2MML_copy_string($1);
968
+ itex2MML_free_string($1);
969
+ }
970
+ | rmchars RMCHAR {
971
+ $$ = itex2MML_copy2($1, $2);
972
+ itex2MML_free_string($1);
973
+ itex2MML_free_string($2);
974
+ };
975
+
976
+ bbold: BB ST bbchars END {
977
+ $$ = itex2MML_copy3("<mi>", $3, "</mi>");
978
+ itex2MML_free_string($3);
979
+ };
980
+
981
+ bbchars: bbchar {
982
+ $$ = itex2MML_copy_string($1);
983
+ itex2MML_free_string($1);
984
+ }
985
+ | bbchars bbchar {
986
+ $$ = itex2MML_copy2($1, $2);
987
+ itex2MML_free_string($1);
988
+ itex2MML_free_string($2);
989
+ };
990
+
991
+ bbchar: BBLOWERCHAR {
992
+ $$ = itex2MML_copy3("&", $1, "opf;");
993
+ itex2MML_free_string($1);
994
+ }
995
+ | BBUPPERCHAR {
996
+ $$ = itex2MML_copy3("&", $1, "opf;");
997
+ itex2MML_free_string($1);
998
+ }
999
+ | BBDIGIT {
1000
+ /* Blackboard digits 0-9 correspond to Unicode characters 0x1D7D8-0x1D7E1 */
1001
+ char * end = $1 + 1;
1002
+ int code = 0x1D7D8 + strtoul($1, &end, 10);
1003
+ $$ = itex2MML_character_reference(code);
1004
+ itex2MML_free_string($1);
1005
+ };
1006
+
1007
+ frak: FRAK ST frakletters END {
1008
+ $$ = itex2MML_copy3("<mi>", $3, "</mi>");
1009
+ itex2MML_free_string($3);
1010
+ };
1011
+
1012
+ frakletters: frakletter {
1013
+ $$ = itex2MML_copy_string($1);
1014
+ itex2MML_free_string($1);
1015
+ }
1016
+ | frakletters frakletter {
1017
+ $$ = itex2MML_copy2($1, $2);
1018
+ itex2MML_free_string($1);
1019
+ itex2MML_free_string($2);
1020
+ };
1021
+
1022
+ frakletter: FRAKCHAR {
1023
+ $$ = itex2MML_copy3("&", $1, "fr;");
1024
+ itex2MML_free_string($1);
1025
+ };
1026
+
1027
+ cal: CAL ST calletters END {
1028
+ $$ = itex2MML_copy3("<mi>", $3, "</mi>");
1029
+ itex2MML_free_string($3);
1030
+ };
1031
+
1032
+ calletters: calletter {
1033
+ $$ = itex2MML_copy_string($1);
1034
+ itex2MML_free_string($1);
1035
+ }
1036
+ | calletters calletter {
1037
+ $$ = itex2MML_copy2($1, $2);
1038
+ itex2MML_free_string($1);
1039
+ itex2MML_free_string($2);
1040
+ };
1041
+
1042
+ calletter: CALCHAR {
1043
+ $$ = itex2MML_copy3("&", $1, "scr;");
1044
+ itex2MML_free_string($1);
1045
+ };
1046
+
1047
+ thinspace: THINSPACE {
1048
+ $$ = itex2MML_copy_string("<mspace width=\"thinmathspace\"></mspace>");
1049
+ };
1050
+
1051
+ medspace: MEDSPACE {
1052
+ $$ = itex2MML_copy_string("<mspace width=\"mediummathspace\"></mspace>");
1053
+ };
1054
+
1055
+ thickspace: THICKSPACE {
1056
+ $$ = itex2MML_copy_string("<mspace width=\"thickmathspace\"></mspace>");
1057
+ };
1058
+
1059
+ quad: QUAD {
1060
+ $$ = itex2MML_copy_string("<mspace width=\"1em\"></mspace>");
1061
+ };
1062
+
1063
+ qquad: QQUAD {
1064
+ $$ = itex2MML_copy_string("<mspace width=\"2em\"></mspace>");
1065
+ };
1066
+
1067
+ negspace: NEGSPACE {
1068
+ $$ = itex2MML_copy_string("<mspace width=\"-0.1667 em\"></mspace>");
1069
+ };
1070
+
1071
+ phantom: PHANTOM closedTerm {
1072
+ $$ = itex2MML_copy3("<mphantom>", $2, "</mphantom>");
1073
+ itex2MML_free_string($2);
1074
+ };
1075
+
1076
+ href: HREF TEXTSTRING closedTerm {
1077
+ char * s1 = itex2MML_copy3("<mrow xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\"", $2, "\">");
1078
+ $$ = itex2MML_copy3(s1, $3, "</mrow>");
1079
+ itex2MML_free_string(s1);
1080
+ itex2MML_free_string($2);
1081
+ itex2MML_free_string($3);
1082
+ };
1083
+
1084
+ tensor: TENSOR closedTerm MROWOPEN subsupList MROWCLOSE {
1085
+ char * s1 = itex2MML_copy3("<mmultiscripts>", $2, $4);
1086
+ $$ = itex2MML_copy2(s1, "</mmultiscripts>");
1087
+ itex2MML_free_string(s1);
1088
+ itex2MML_free_string($2);
1089
+ itex2MML_free_string($4);
1090
+ }
1091
+ | TENSOR closedTerm subsupList {
1092
+ char * s1 = itex2MML_copy3("<mmultiscripts>", $2, $3);
1093
+ $$ = itex2MML_copy2(s1, "</mmultiscripts>");
1094
+ itex2MML_free_string(s1);
1095
+ itex2MML_free_string($2);
1096
+ itex2MML_free_string($3);
1097
+ };
1098
+
1099
+ multi: MULTI MROWOPEN subsupList MROWCLOSE closedTerm MROWOPEN subsupList MROWCLOSE {
1100
+ char * s1 = itex2MML_copy3("<mmultiscripts>", $5, $7);
1101
+ char * s2 = itex2MML_copy3("<mprescripts></mprescripts>", $3, "</mmultiscripts>");
1102
+ $$ = itex2MML_copy2(s1, s2);
1103
+ itex2MML_free_string(s1);
1104
+ itex2MML_free_string(s2);
1105
+ itex2MML_free_string($3);
1106
+ itex2MML_free_string($5);
1107
+ itex2MML_free_string($7);
1108
+ }
1109
+ | MULTI MROWOPEN subsupList MROWCLOSE closedTerm EMPTYMROW {
1110
+ char * s1 = itex2MML_copy2("<mmultiscripts>", $5);
1111
+ char * s2 = itex2MML_copy3("<mprescripts></mprescripts>", $3, "</mmultiscripts>");
1112
+ $$ = itex2MML_copy2(s1, s2);
1113
+ itex2MML_free_string(s1);
1114
+ itex2MML_free_string(s2);
1115
+ itex2MML_free_string($3);
1116
+ itex2MML_free_string($5);
1117
+ }
1118
+ | MULTI EMPTYMROW closedTerm MROWOPEN subsupList MROWCLOSE {
1119
+ char * s1 = itex2MML_copy3("<mmultiscripts>", $3, $5);
1120
+ $$ = itex2MML_copy2(s1, "</mmultiscripts>");
1121
+ itex2MML_free_string(s1);
1122
+ itex2MML_free_string($3);
1123
+ itex2MML_free_string($5);
1124
+ };
1125
+
1126
+ subsupList: subsupTerm {
1127
+ $$ = itex2MML_copy_string($1);
1128
+ itex2MML_free_string($1);
1129
+ }
1130
+ | subsupList subsupTerm {
1131
+ $$ = itex2MML_copy3($1, " ", $2);
1132
+ itex2MML_free_string($1);
1133
+ itex2MML_free_string($2);
1134
+ };
1135
+
1136
+ subsupTerm: SUB closedTerm SUP closedTerm {
1137
+ $$ = itex2MML_copy3($2, " ", $4);
1138
+ itex2MML_free_string($2);
1139
+ itex2MML_free_string($4);
1140
+ }
1141
+ | SUB closedTerm {
1142
+ $$ = itex2MML_copy2($2, " <none></none>");
1143
+ itex2MML_free_string($2);
1144
+ }
1145
+ | SUP closedTerm {
1146
+ $$ = itex2MML_copy2("<none></none> ", $2);
1147
+ itex2MML_free_string($2);
1148
+ }
1149
+ | SUB SUP closedTerm {
1150
+ $$ = itex2MML_copy2("<none></none> ", $3);
1151
+ itex2MML_free_string($3);
1152
+ };
1153
+
1154
+ mfrac: FRAC closedTerm closedTerm {
1155
+ char * s1 = itex2MML_copy3("<mfrac>", $2, $3);
1156
+ $$ = itex2MML_copy2(s1, "</mfrac>");
1157
+ itex2MML_free_string(s1);
1158
+ itex2MML_free_string($2);
1159
+ itex2MML_free_string($3);
1160
+ }
1161
+ | TFRAC closedTerm closedTerm {
1162
+ char * s1 = itex2MML_copy3("<mstyle displaystyle=\"false\"><mfrac>", $2, $3);
1163
+ $$ = itex2MML_copy2(s1, "</mfrac></mstyle>");
1164
+ itex2MML_free_string(s1);
1165
+ itex2MML_free_string($2);
1166
+ itex2MML_free_string($3);
1167
+ };
1168
+
1169
+ pmod: PMOD closedTerm {
1170
+ $$ = itex2MML_copy3( "<mo lspace=\"mediummathspace\">(</mo><mo rspace=\"thinmathspace\">mod</mo>", $2, "<mo rspace=\"mediummathspace\">)</mo>");
1171
+ itex2MML_free_string($2);
1172
+ }
1173
+
1174
+ texover: MROWOPEN compoundTermList TEXOVER compoundTermList MROWCLOSE {
1175
+ char * s1 = itex2MML_copy3("<mfrac><mrow>", $2, "</mrow><mrow>");
1176
+ $$ = itex2MML_copy3(s1, $4, "</mrow></mfrac>");
1177
+ itex2MML_free_string(s1);
1178
+ itex2MML_free_string($2);
1179
+ itex2MML_free_string($4);
1180
+ }
1181
+ | left compoundTermList TEXOVER compoundTermList right {
1182
+ char * s1 = itex2MML_copy3("<mrow>", $1, "<mfrac><mrow>");
1183
+ char * s2 = itex2MML_copy3($2, "</mrow><mrow>", $4);
1184
+ char * s3 = itex2MML_copy3("</mrow></mfrac>", $5, "</mrow>");
1185
+ $$ = itex2MML_copy3(s1, s2, s3);
1186
+ itex2MML_free_string(s1);
1187
+ itex2MML_free_string(s2);
1188
+ itex2MML_free_string(s3);
1189
+ itex2MML_free_string($1);
1190
+ itex2MML_free_string($2);
1191
+ itex2MML_free_string($4);
1192
+ itex2MML_free_string($5);
1193
+ };
1194
+
1195
+ texatop: MROWOPEN compoundTermList TEXATOP compoundTermList MROWCLOSE {
1196
+ char * s1 = itex2MML_copy3("<mfrac linethickness=\"0\"><mrow>", $2, "</mrow><mrow>");
1197
+ $$ = itex2MML_copy3(s1, $4, "</mrow></mfrac>");
1198
+ itex2MML_free_string(s1);
1199
+ itex2MML_free_string($2);
1200
+ itex2MML_free_string($4);
1201
+ }
1202
+ | left compoundTermList TEXATOP compoundTermList right {
1203
+ char * s1 = itex2MML_copy3("<mrow>", $1, "<mfrac linethickness=\"0\"><mrow>");
1204
+ char * s2 = itex2MML_copy3($2, "</mrow><mrow>", $4);
1205
+ char * s3 = itex2MML_copy3("</mrow></mfrac>", $5, "</mrow>");
1206
+ $$ = itex2MML_copy3(s1, s2, s3);
1207
+ itex2MML_free_string(s1);
1208
+ itex2MML_free_string(s2);
1209
+ itex2MML_free_string(s3);
1210
+ itex2MML_free_string($1);
1211
+ itex2MML_free_string($2);
1212
+ itex2MML_free_string($4);
1213
+ itex2MML_free_string($5);
1214
+ };
1215
+
1216
+ binom: BINOM closedTerm closedTerm {
1217
+ char * s1 = itex2MML_copy3("<mrow><mo>(</mo><mfrac linethickness=\"0\">", $2, $3);
1218
+ $$ = itex2MML_copy2(s1, "</mfrac><mo>)</mo></mrow>");
1219
+ itex2MML_free_string(s1);
1220
+ itex2MML_free_string($2);
1221
+ itex2MML_free_string($3);
1222
+ }
1223
+ | TBINOM closedTerm closedTerm {
1224
+ char * s1 = itex2MML_copy3("<mrow><mo>(</mo><mstyle displaystyle=\"false\"><mfrac linethickness=\"0\">", $2, $3);
1225
+ $$ = itex2MML_copy2(s1, "</mfrac></mstyle><mo>)</mo></mrow>");
1226
+ itex2MML_free_string(s1);
1227
+ itex2MML_free_string($2);
1228
+ itex2MML_free_string($3);
1229
+ };
1230
+
1231
+ munderbrace: UNDERBRACE closedTerm {
1232
+ $$ = itex2MML_copy3("<munder>", $2, "<mo>&UnderBrace;</mo></munder>");
1233
+ itex2MML_free_string($2);
1234
+ };
1235
+
1236
+ munderline: UNDERLINE closedTerm {
1237
+ $$ = itex2MML_copy3("<munder>", $2, "<mo>&#x00332;</mo></munder>");
1238
+ itex2MML_free_string($2);
1239
+ };
1240
+
1241
+ moverbrace: OVERBRACE closedTerm {
1242
+ $$ = itex2MML_copy3("<mover>", $2, "<mo>&OverBrace;</mo></mover>");
1243
+ itex2MML_free_string($2);
1244
+ };
1245
+
1246
+ bar: BAR closedTerm {
1247
+ $$ = itex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x000AF;</mo></mover>");
1248
+ itex2MML_free_string($2);
1249
+ }
1250
+ | WIDEBAR closedTerm {
1251
+ $$ = itex2MML_copy3("<mover>", $2, "<mo>&#x000AF;</mo></mover>");
1252
+ itex2MML_free_string($2);
1253
+ };
1254
+
1255
+ vec: VEC closedTerm {
1256
+ $$ = itex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&RightVector;</mo></mover>");
1257
+ itex2MML_free_string($2);
1258
+ }
1259
+ | WIDEVEC closedTerm {
1260
+ $$ = itex2MML_copy3("<mover>", $2, "<mo>&RightVector;</mo></mover>");
1261
+ itex2MML_free_string($2);
1262
+ };
1263
+
1264
+ dot: DOT closedTerm {
1265
+ $$ = itex2MML_copy3("<mover>", $2, "<mo>&dot;</mo></mover>");
1266
+ itex2MML_free_string($2);
1267
+ };
1268
+
1269
+ ddot: DDOT closedTerm {
1270
+ $$ = itex2MML_copy3("<mover>", $2, "<mo>&Dot;</mo></mover>");
1271
+ itex2MML_free_string($2);
1272
+ };
1273
+
1274
+ dddot: DDDOT closedTerm {
1275
+ $$ = itex2MML_copy3("<mover>", $2, "<mo>&tdot;</mo></mover>");
1276
+ itex2MML_free_string($2);
1277
+ };
1278
+
1279
+ ddddot: DDDDOT closedTerm {
1280
+ $$ = itex2MML_copy3("<mover>", $2, "<mo>&DotDot;</mo></mover>");
1281
+ itex2MML_free_string($2);
1282
+ };
1283
+
1284
+ tilde: TILDE closedTerm {
1285
+ $$ = itex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&tilde;</mo></mover>");
1286
+ itex2MML_free_string($2);
1287
+ }
1288
+ | WIDETILDE closedTerm {
1289
+ $$ = itex2MML_copy3("<mover>", $2, "<mo>&tilde;</mo></mover>");
1290
+ itex2MML_free_string($2);
1291
+ };
1292
+
1293
+ check: CHECK closedTerm {
1294
+ $$ = itex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x2c7;</mo></mover>");
1295
+ itex2MML_free_string($2);
1296
+ }
1297
+ | WIDECHECK closedTerm {
1298
+ $$ = itex2MML_copy3("<mover>", $2, "<mo>&#x2c7;</mo></mover>");
1299
+ itex2MML_free_string($2);
1300
+ };
1301
+
1302
+ hat: HAT closedTerm {
1303
+ $$ = itex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x5E;</mo></mover>");
1304
+ itex2MML_free_string($2);
1305
+ }
1306
+ | WIDEHAT closedTerm {
1307
+ $$ = itex2MML_copy3("<mover>", $2, "<mo>&#x5E;</mo></mover>");
1308
+ itex2MML_free_string($2);
1309
+ };
1310
+
1311
+ msqrt: SQRT closedTerm {
1312
+ $$ = itex2MML_copy3("<msqrt>", $2, "</msqrt>");
1313
+ itex2MML_free_string($2);
1314
+ };
1315
+
1316
+ mroot: SQRT OPTARGOPEN compoundTermList OPTARGCLOSE closedTerm {
1317
+ char * s1 = itex2MML_copy3("<mroot>", $5, $3);
1318
+ $$ = itex2MML_copy2(s1, "</mroot>");
1319
+ itex2MML_free_string(s1);
1320
+ itex2MML_free_string($3);
1321
+ itex2MML_free_string($5);
1322
+ }
1323
+ | ROOT closedTerm closedTerm {
1324
+ char * s1 = itex2MML_copy3("<mroot>", $3, $2);
1325
+ $$ = itex2MML_copy2(s1, "</mroot>");
1326
+ itex2MML_free_string(s1);
1327
+ itex2MML_free_string($2);
1328
+ itex2MML_free_string($3);
1329
+ };
1330
+
1331
+ munder: XARROW OPTARGOPEN compoundTermList OPTARGCLOSE EMPTYMROW {
1332
+ char * s1 = itex2MML_copy3("<munder><mo>", $1, "</mo><mrow>");
1333
+ $$ = itex2MML_copy3(s1, $3, "</mrow></munder>");
1334
+ itex2MML_free_string(s1);
1335
+ itex2MML_free_string($1);
1336
+ itex2MML_free_string($3);
1337
+ }
1338
+ | UNDER closedTerm closedTerm {
1339
+ char * s1 = itex2MML_copy3("<munder>", $3, $2);
1340
+ $$ = itex2MML_copy2(s1, "</munder>");
1341
+ itex2MML_free_string(s1);
1342
+ itex2MML_free_string($2);
1343
+ itex2MML_free_string($3);
1344
+ };
1345
+
1346
+ mover: XARROW closedTerm {
1347
+ char * s1 = itex2MML_copy3("<mover><mo>", $1, "</mo>");
1348
+ $$ = itex2MML_copy3(s1, $2, "</mover>");
1349
+ itex2MML_free_string(s1);
1350
+ itex2MML_free_string($1);
1351
+ itex2MML_free_string($2);
1352
+ }
1353
+ | OVER closedTerm closedTerm {
1354
+ char * s1 = itex2MML_copy3("<mover>", $3, $2);
1355
+ $$ = itex2MML_copy2(s1, "</mover>");
1356
+ itex2MML_free_string(s1);
1357
+ itex2MML_free_string($2);
1358
+ itex2MML_free_string($3);
1359
+ };
1360
+
1361
+ munderover: XARROW OPTARGOPEN compoundTermList OPTARGCLOSE closedTerm {
1362
+ char * s1 = itex2MML_copy3("<munderover><mo>", $1, "</mo><mrow>");
1363
+ char * s2 = itex2MML_copy3(s1, $3, "</mrow>");
1364
+ $$ = itex2MML_copy3(s2, $5, "</munderover>");
1365
+ itex2MML_free_string(s1);
1366
+ itex2MML_free_string(s2);
1367
+ itex2MML_free_string($1);
1368
+ itex2MML_free_string($3);
1369
+ itex2MML_free_string($5);
1370
+ }
1371
+ | UNDEROVER closedTerm closedTerm closedTerm {
1372
+ char * s1 = itex2MML_copy3("<munderover>", $4, $2);
1373
+ $$ = itex2MML_copy3(s1, $3, "</munderover>");
1374
+ itex2MML_free_string(s1);
1375
+ itex2MML_free_string($2);
1376
+ itex2MML_free_string($3);
1377
+ itex2MML_free_string($4);
1378
+ };
1379
+
1380
+ emptymrow: EMPTYMROW {
1381
+ $$ = itex2MML_copy_string("<mrow></mrow>");
1382
+ };
1383
+
1384
+ mathenv: BEGINENV MATRIX tableRowList ENDENV MATRIX {
1385
+ $$ = itex2MML_copy3("<mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow>");
1386
+ itex2MML_free_string($3);
1387
+ }
1388
+ | BEGINENV GATHERED tableRowList ENDENV GATHERED {
1389
+ $$ = itex2MML_copy3("<mrow><mtable rowspacing=\"1.0ex\">", $3, "</mtable></mrow>");
1390
+ itex2MML_free_string($3);
1391
+ }
1392
+ | BEGINENV PMATRIX tableRowList ENDENV PMATRIX {
1393
+ $$ = itex2MML_copy3("<mrow><mo>(</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>)</mo></mrow>");
1394
+ itex2MML_free_string($3);
1395
+ }
1396
+ | BEGINENV BMATRIX tableRowList ENDENV BMATRIX {
1397
+ $$ = itex2MML_copy3("<mrow><mo>[</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>]</mo></mrow>");
1398
+ itex2MML_free_string($3);
1399
+ }
1400
+ | BEGINENV VMATRIX tableRowList ENDENV VMATRIX {
1401
+ $$ = itex2MML_copy3("<mrow><mo>&VerticalBar;</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>&VerticalBar;</mo></mrow>");
1402
+ itex2MML_free_string($3);
1403
+ }
1404
+ | BEGINENV BBMATRIX tableRowList ENDENV BBMATRIX {
1405
+ $$ = itex2MML_copy3("<mrow><mo>{</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>}</mo></mrow>");
1406
+ itex2MML_free_string($3);
1407
+ }
1408
+ | BEGINENV VVMATRIX tableRowList ENDENV VVMATRIX {
1409
+ $$ = itex2MML_copy3("<mrow><mo>&DoubleVerticalBar;</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>&DoubleVerticalBar;</mo></mrow>");
1410
+ itex2MML_free_string($3);
1411
+ }
1412
+ | BEGINENV SMALLMATRIX tableRowList ENDENV SMALLMATRIX {
1413
+ $$ = itex2MML_copy3("<mstyle scriptlevel=\"2\"><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow></mstyle>");
1414
+ itex2MML_free_string($3);
1415
+ }
1416
+ | BEGINENV CASES tableRowList ENDENV CASES {
1417
+ $$ = itex2MML_copy3("<mrow><mo>{</mo><mrow><mtable columnalign=\"left left\">", $3, "</mtable></mrow></mrow>");
1418
+ itex2MML_free_string($3);
1419
+ }
1420
+ | BEGINENV ALIGNED tableRowList ENDENV ALIGNED {
1421
+ $$ = itex2MML_copy3("<mrow><mtable columnalign=\"right left right left right left right left right left\" columnspacing=\"0em\">", $3, "</mtable></mrow>");
1422
+ itex2MML_free_string($3);
1423
+ }
1424
+ | BEGINENV ARRAY ARRAYALIGN ST columnAlignList END tableRowList ENDENV ARRAY {
1425
+ char * s1 = itex2MML_copy3("<mtable rowspacing=\"0.5ex\" align=\"", $3, "\" columnalign=\"");
1426
+ char * s2 = itex2MML_copy3(s1, $5, "\">");
1427
+ $$ = itex2MML_copy3(s2, $7, "</mtable>");
1428
+ itex2MML_free_string(s1);
1429
+ itex2MML_free_string(s2);
1430
+ itex2MML_free_string($3);
1431
+ itex2MML_free_string($5);
1432
+ itex2MML_free_string($7);
1433
+ }
1434
+ | BEGINENV ARRAY ST columnAlignList END tableRowList ENDENV ARRAY {
1435
+ char * s1 = itex2MML_copy3("<mtable rowspacing=\"0.5ex\" columnalign=\"", $4, "\">");
1436
+ $$ = itex2MML_copy3(s1, $6, "</mtable>");
1437
+ itex2MML_free_string(s1);
1438
+ itex2MML_free_string($4);
1439
+ itex2MML_free_string($6);
1440
+ }
1441
+ | BEGINENV SVG XMLSTRING ENDSVG {
1442
+ $$ = itex2MML_copy3("<semantics><annotation-xml encoding=\"SVG1.1\">", $3, "</annotation-xml></semantics>");
1443
+ itex2MML_free_string($3);
1444
+ }
1445
+ | BEGINENV SVG ENDSVG {
1446
+ $$ = itex2MML_copy_string(" ");
1447
+ };
1448
+
1449
+ columnAlignList: columnAlignList COLUMNALIGN {
1450
+ $$ = itex2MML_copy3($1, " ", $2);
1451
+ itex2MML_free_string($1);
1452
+ itex2MML_free_string($2);
1453
+ }
1454
+ | COLUMNALIGN {
1455
+ $$ = itex2MML_copy_string($1);
1456
+ itex2MML_free_string($1);
1457
+ };
1458
+
1459
+ substack: SUBSTACK MROWOPEN tableRowList MROWCLOSE {
1460
+ $$ = itex2MML_copy3("<mrow><mtable columnalign=\"center\" rowspacing=\"0.5ex\">", $3, "</mtable></mrow>");
1461
+ itex2MML_free_string($3);
1462
+ };
1463
+
1464
+ array: ARRAY MROWOPEN tableRowList MROWCLOSE {
1465
+ $$ = itex2MML_copy3("<mrow><mtable>", $3, "</mtable></mrow>");
1466
+ itex2MML_free_string($3);
1467
+ }
1468
+ | ARRAY MROWOPEN ARRAYOPTS MROWOPEN arrayopts MROWCLOSE tableRowList MROWCLOSE {
1469
+ char * s1 = itex2MML_copy3("<mrow><mtable ", $5, ">");
1470
+ $$ = itex2MML_copy3(s1, $7, "</mtable></mrow>");
1471
+ itex2MML_free_string(s1);
1472
+ itex2MML_free_string($5);
1473
+ itex2MML_free_string($7);
1474
+ };
1475
+
1476
+ arrayopts: anarrayopt {
1477
+ $$ = itex2MML_copy_string($1);
1478
+ itex2MML_free_string($1);
1479
+ }
1480
+ | arrayopts anarrayopt {
1481
+ $$ = itex2MML_copy3($1, " ", $2);
1482
+ itex2MML_free_string($1);
1483
+ itex2MML_free_string($2);
1484
+ };
1485
+
1486
+ anarrayopt: collayout {
1487
+ $$ = itex2MML_copy_string($1);
1488
+ itex2MML_free_string($1);
1489
+ }
1490
+ | colalign {
1491
+ $$ = itex2MML_copy_string($1);
1492
+ itex2MML_free_string($1);
1493
+ }
1494
+ | rowalign {
1495
+ $$ = itex2MML_copy_string($1);
1496
+ itex2MML_free_string($1);
1497
+ }
1498
+ | align {
1499
+ $$ = itex2MML_copy_string($1);
1500
+ itex2MML_free_string($1);
1501
+ }
1502
+ | eqrows {
1503
+ $$ = itex2MML_copy_string($1);
1504
+ itex2MML_free_string($1);
1505
+ }
1506
+ | eqcols {
1507
+ $$ = itex2MML_copy_string($1);
1508
+ itex2MML_free_string($1);
1509
+ }
1510
+ | rowlines {
1511
+ $$ = itex2MML_copy_string($1);
1512
+ itex2MML_free_string($1);
1513
+ }
1514
+ | collines {
1515
+ $$ = itex2MML_copy_string($1);
1516
+ itex2MML_free_string($1);
1517
+ }
1518
+ | frame {
1519
+ $$ = itex2MML_copy_string($1);
1520
+ itex2MML_free_string($1);
1521
+ }
1522
+ | padding {
1523
+ $$ = itex2MML_copy_string($1);
1524
+ itex2MML_free_string($1);
1525
+ };
1526
+
1527
+ collayout: COLLAYOUT ATTRLIST {
1528
+ $$ = itex2MML_copy2("columnalign=", $2);
1529
+ itex2MML_free_string($2);
1530
+ };
1531
+
1532
+ colalign: COLALIGN ATTRLIST {
1533
+ $$ = itex2MML_copy2("columnalign=", $2);
1534
+ itex2MML_free_string($2);
1535
+ };
1536
+
1537
+ rowalign: ROWALIGN ATTRLIST {
1538
+ $$ = itex2MML_copy2("rowalign=", $2);
1539
+ itex2MML_free_string($2);
1540
+ };
1541
+
1542
+ align: ALIGN ATTRLIST {
1543
+ $$ = itex2MML_copy2("align=", $2);
1544
+ itex2MML_free_string($2);
1545
+ };
1546
+
1547
+ eqrows: EQROWS ATTRLIST {
1548
+ $$ = itex2MML_copy2("equalrows=", $2);
1549
+ itex2MML_free_string($2);
1550
+ };
1551
+
1552
+ eqcols: EQCOLS ATTRLIST {
1553
+ $$ = itex2MML_copy2("equalcolumns=", $2);
1554
+ itex2MML_free_string($2);
1555
+ };
1556
+
1557
+ rowlines: ROWLINES ATTRLIST {
1558
+ $$ = itex2MML_copy2("rowlines=", $2);
1559
+ itex2MML_free_string($2);
1560
+ };
1561
+
1562
+ collines: COLLINES ATTRLIST {
1563
+ $$ = itex2MML_copy2("columnlines=", $2);
1564
+ itex2MML_free_string($2);
1565
+ };
1566
+
1567
+ frame: FRAME ATTRLIST {
1568
+ $$ = itex2MML_copy2("frame=", $2);
1569
+ itex2MML_free_string($2);
1570
+ };
1571
+
1572
+ padding: PADDING ATTRLIST {
1573
+ char * s1 = itex2MML_copy3("rowspacing=", $2, " columnspacing=");
1574
+ $$ = itex2MML_copy2(s1, $2);
1575
+ itex2MML_free_string(s1);
1576
+ itex2MML_free_string($2);
1577
+ };
1578
+
1579
+ tableRowList: tableRow {
1580
+ $$ = itex2MML_copy_string($1);
1581
+ itex2MML_free_string($1);
1582
+ }
1583
+ | tableRowList ROWSEP tableRow {
1584
+ $$ = itex2MML_copy3($1, " ", $3);
1585
+ itex2MML_free_string($1);
1586
+ itex2MML_free_string($3);
1587
+ };
1588
+
1589
+ tableRow: simpleTableRow {
1590
+ $$ = itex2MML_copy3("<mtr>", $1, "</mtr>");
1591
+ itex2MML_free_string($1);
1592
+ }
1593
+ | optsTableRow {
1594
+ $$ = itex2MML_copy_string($1);
1595
+ itex2MML_free_string($1);
1596
+ };
1597
+
1598
+ simpleTableRow: tableCell {
1599
+ $$ = itex2MML_copy_string($1);
1600
+ itex2MML_free_string($1);
1601
+ }
1602
+ | simpleTableRow COLSEP tableCell {
1603
+ $$ = itex2MML_copy3($1, " ", $3);
1604
+ itex2MML_free_string($1);
1605
+ itex2MML_free_string($3);
1606
+ };
1607
+
1608
+ optsTableRow: ROWOPTS MROWOPEN rowopts MROWCLOSE simpleTableRow {
1609
+ char * s1 = itex2MML_copy3("<mtr ", $3, ">");
1610
+ $$ = itex2MML_copy3(s1, $5, "</mtr>");
1611
+ itex2MML_free_string(s1);
1612
+ itex2MML_free_string($3);
1613
+ itex2MML_free_string($5);
1614
+ };
1615
+
1616
+ rowopts: arowopt {
1617
+ $$ = itex2MML_copy_string($1);
1618
+ itex2MML_free_string($1);
1619
+ }
1620
+ | rowopts arowopt {
1621
+ $$ = itex2MML_copy3($1, " ", $2);
1622
+ itex2MML_free_string($1);
1623
+ itex2MML_free_string($2);
1624
+ };
1625
+
1626
+ arowopt: colalign {
1627
+ $$ = itex2MML_copy_string($1);
1628
+ itex2MML_free_string($1);
1629
+ }
1630
+ | rowalign {
1631
+ $$ = itex2MML_copy_string($1);
1632
+ itex2MML_free_string($1);
1633
+ };
1634
+
1635
+ tableCell: {
1636
+ $$ = itex2MML_copy_string("<mtd></mtd>");
1637
+ }
1638
+ | compoundTermList {
1639
+ $$ = itex2MML_copy3("<mtd>", $1, "</mtd>");
1640
+ itex2MML_free_string($1);
1641
+ }
1642
+ | CELLOPTS MROWOPEN cellopts MROWCLOSE compoundTermList {
1643
+ char * s1 = itex2MML_copy3("<mtd ", $3, ">");
1644
+ $$ = itex2MML_copy3(s1, $5, "</mtd>");
1645
+ itex2MML_free_string(s1);
1646
+ itex2MML_free_string($3);
1647
+ itex2MML_free_string($5);
1648
+ };
1649
+
1650
+ cellopts: acellopt {
1651
+ $$ = itex2MML_copy_string($1);
1652
+ itex2MML_free_string($1);
1653
+ }
1654
+ | cellopts acellopt {
1655
+ $$ = itex2MML_copy3($1, " ", $2);
1656
+ itex2MML_free_string($1);
1657
+ itex2MML_free_string($2);
1658
+ };
1659
+
1660
+ acellopt: colalign {
1661
+ $$ = itex2MML_copy_string($1);
1662
+ itex2MML_free_string($1);
1663
+ }
1664
+ | rowalign {
1665
+ $$ = itex2MML_copy_string($1);
1666
+ itex2MML_free_string($1);
1667
+ }
1668
+ | rowspan {
1669
+ $$ = itex2MML_copy_string($1);
1670
+ itex2MML_free_string($1);
1671
+ }
1672
+ | colspan {
1673
+ $$ = itex2MML_copy_string($1);
1674
+ itex2MML_free_string($1);
1675
+ };
1676
+
1677
+ rowspan: ROWSPAN ATTRLIST {
1678
+ $$ = itex2MML_copy2("rowspan=", $2);
1679
+ itex2MML_free_string($2);
1680
+ };
1681
+
1682
+ colspan: COLSPAN ATTRLIST {
1683
+ $$ = itex2MML_copy2("columnspan=", $2);
1684
+ itex2MML_free_string($2);
1685
+ };
1686
+
1687
+ %%
1688
+
1689
+ char * itex2MML_parse (const char * buffer, unsigned long length)
1690
+ {
1691
+ char * mathml = 0;
1692
+
1693
+ int result;
1694
+
1695
+ itex2MML_setup (buffer, length);
1696
+ itex2MML_restart ();
1697
+
1698
+ result = itex2MML_yyparse (&mathml);
1699
+
1700
+ if (result && mathml) /* shouldn't happen? */
1701
+ {
1702
+ itex2MML_free_string (mathml);
1703
+ mathml = 0;
1704
+ }
1705
+ return mathml;
1706
+ }
1707
+
1708
+ int itex2MML_filter (const char * buffer, unsigned long length)
1709
+ {
1710
+ itex2MML_setup (buffer, length);
1711
+ itex2MML_restart ();
1712
+
1713
+ return itex2MML_yyparse (0);
1714
+ }
1715
+
1716
+ #define ITEX_DELIMITER_DOLLAR 0
1717
+ #define ITEX_DELIMITER_DOUBLE 1
1718
+ #define ITEX_DELIMITER_SQUARE 2
1719
+
1720
+ static char * itex2MML_last_error = 0;
1721
+
1722
+ static void itex2MML_keep_error (const char * msg)
1723
+ {
1724
+ if (itex2MML_last_error)
1725
+ {
1726
+ itex2MML_free_string (itex2MML_last_error);
1727
+ itex2MML_last_error = 0;
1728
+ }
1729
+ itex2MML_last_error = itex2MML_copy_escaped (msg);
1730
+ }
1731
+
1732
+ static int itex2MML_do_html_filter (const char * buffer, unsigned long length, const int forbid_markup)
1733
+ {
1734
+ int result = 0;
1735
+
1736
+ int type = 0;
1737
+ int skip = 0;
1738
+ int match = 0;
1739
+
1740
+ const char * ptr1 = buffer;
1741
+ const char * ptr2 = 0;
1742
+
1743
+ const char * end = buffer + length;
1744
+
1745
+ char * mathml = 0;
1746
+
1747
+ void (*save_error_fn) (const char * msg) = itex2MML_error;
1748
+
1749
+ itex2MML_error = itex2MML_keep_error;
1750
+
1751
+ _until_math:
1752
+ ptr2 = ptr1;
1753
+
1754
+ while (ptr2 < end)
1755
+ {
1756
+ if (*ptr2 == '$') break;
1757
+ if ((*ptr2 == '\\') && (ptr2 + 1 < end))
1758
+ {
1759
+ if (*(ptr2+1) == '[') break;
1760
+ }
1761
+ ++ptr2;
1762
+ }
1763
+ if (itex2MML_write && ptr2 > ptr1)
1764
+ (*itex2MML_write) (ptr1, ptr2 - ptr1);
1765
+
1766
+ if (ptr2 == end) goto _finish;
1767
+
1768
+ ptr1 = ptr2;
1769
+
1770
+ if (ptr2 + 1 < end)
1771
+ {
1772
+ if ((*ptr2 == '\\') && (*(ptr2+1) == '['))
1773
+ {
1774
+ type = ITEX_DELIMITER_SQUARE;
1775
+ ptr2 += 2;
1776
+ }
1777
+ else if ((*ptr2 == '$') && (*(ptr2+1) == '$'))
1778
+ {
1779
+ type = ITEX_DELIMITER_DOUBLE;
1780
+ ptr2 += 2;
1781
+ }
1782
+ else
1783
+ {
1784
+ type = ITEX_DELIMITER_DOLLAR;
1785
+ ptr2 += 2;
1786
+ }
1787
+ }
1788
+ else goto _finish;
1789
+
1790
+ skip = 0;
1791
+ match = 0;
1792
+
1793
+ while (ptr2 < end)
1794
+ {
1795
+ switch (*ptr2)
1796
+ {
1797
+ case '<':
1798
+ case '>':
1799
+ if (forbid_markup == 1) skip = 1;
1800
+ break;
1801
+
1802
+ case '\\':
1803
+ if (ptr2 + 1 < end)
1804
+ {
1805
+ if (*(ptr2 + 1) == '[')
1806
+ {
1807
+ skip = 1;
1808
+ }
1809
+ else if (*(ptr2 + 1) == ']')
1810
+ {
1811
+ if (type == ITEX_DELIMITER_SQUARE)
1812
+ {
1813
+ ptr2 += 2;
1814
+ match = 1;
1815
+ }
1816
+ else
1817
+ {
1818
+ skip = 1;
1819
+ }
1820
+ }
1821
+ }
1822
+ break;
1823
+
1824
+ case '$':
1825
+ if (type == ITEX_DELIMITER_SQUARE)
1826
+ {
1827
+ skip = 1;
1828
+ }
1829
+ else if (ptr2 + 1 < end)
1830
+ {
1831
+ if (*(ptr2 + 1) == '$')
1832
+ {
1833
+ if (type == ITEX_DELIMITER_DOLLAR)
1834
+ {
1835
+ ptr2++;
1836
+ match = 1;
1837
+ }
1838
+ else
1839
+ {
1840
+ ptr2 += 2;
1841
+ match = 1;
1842
+ }
1843
+ }
1844
+ else
1845
+ {
1846
+ if (type == ITEX_DELIMITER_DOLLAR)
1847
+ {
1848
+ ptr2++;
1849
+ match = 1;
1850
+ }
1851
+ else
1852
+ {
1853
+ skip = 1;
1854
+ }
1855
+ }
1856
+ }
1857
+ else
1858
+ {
1859
+ if (type == ITEX_DELIMITER_DOLLAR)
1860
+ {
1861
+ ptr2++;
1862
+ match = 1;
1863
+ }
1864
+ else
1865
+ {
1866
+ skip = 1;
1867
+ }
1868
+ }
1869
+ break;
1870
+
1871
+ default:
1872
+ break;
1873
+ }
1874
+ if (skip || match) break;
1875
+
1876
+ ++ptr2;
1877
+ }
1878
+ if (skip)
1879
+ {
1880
+ if (type == ITEX_DELIMITER_DOLLAR)
1881
+ {
1882
+ if (itex2MML_write)
1883
+ (*itex2MML_write) (ptr1, 1);
1884
+ ptr1++;
1885
+ }
1886
+ else
1887
+ {
1888
+ if (itex2MML_write)
1889
+ (*itex2MML_write) (ptr1, 2);
1890
+ ptr1 += 2;
1891
+ }
1892
+ goto _until_math;
1893
+ }
1894
+ if (match)
1895
+ {
1896
+ mathml = itex2MML_parse (ptr1, ptr2 - ptr1);
1897
+
1898
+ if (mathml)
1899
+ {
1900
+ if (itex2MML_write_mathml)
1901
+ (*itex2MML_write_mathml) (mathml);
1902
+ itex2MML_free_string (mathml);
1903
+ mathml = 0;
1904
+ }
1905
+ else
1906
+ {
1907
+ ++result;
1908
+ if (itex2MML_write)
1909
+ {
1910
+ if (type == ITEX_DELIMITER_DOLLAR)
1911
+ (*itex2MML_write) ("<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><merror><mtext>", 0);
1912
+ else
1913
+ (*itex2MML_write) ("<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><merror><mtext>", 0);
1914
+
1915
+ (*itex2MML_write) (itex2MML_last_error, 0);
1916
+ (*itex2MML_write) ("</mtext></merror></math>", 0);
1917
+ }
1918
+ }
1919
+ ptr1 = ptr2;
1920
+
1921
+ goto _until_math;
1922
+ }
1923
+ if (itex2MML_write)
1924
+ (*itex2MML_write) (ptr1, ptr2 - ptr1);
1925
+
1926
+ _finish:
1927
+ if (itex2MML_last_error)
1928
+ {
1929
+ itex2MML_free_string (itex2MML_last_error);
1930
+ itex2MML_last_error = 0;
1931
+ }
1932
+ itex2MML_error = save_error_fn;
1933
+
1934
+ return result;
1935
+ }
1936
+
1937
+ int itex2MML_html_filter (const char * buffer, unsigned long length)
1938
+ {
1939
+ return itex2MML_do_html_filter (buffer, length, 0);
1940
+ }
1941
+
1942
+ int itex2MML_strict_html_filter (const char * buffer, unsigned long length)
1943
+ {
1944
+ return itex2MML_do_html_filter (buffer, length, 1);
1945
+ }