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,3726 @@
1
+ %parse-param {char **ret_str}
2
+
3
+ %{
4
+ #include <stdio.h>
5
+ #include <string.h>
6
+ #include <stdlib.h>
7
+
8
+ #include "mtex2MML.h"
9
+ #include "parse_extras.h"
10
+ #include "string_extras.h"
11
+
12
+ #include "../deps/uthash/uthash.h"
13
+
14
+ struct css_colors *colors = NULL;
15
+
16
+ #define YYSTYPE char *
17
+ #define YYPARSE_PARAM_TYPE char **
18
+ #define YYPARSE_PARAM ret_str
19
+ /* set max nesting. utterly arbitrary number determined from http://git.io/FlWHfw */
20
+ #define YYMAXDEPTH 430
21
+
22
+ // #define YYDEBUG 1
23
+ // yydebug = 1;
24
+
25
+ #define YYERROR_VERBOSE 1
26
+
27
+ #define yytext mtex2MML_yytext
28
+
29
+ UT_array *environment_data_stack;
30
+
31
+ encaseType * encase = NONE;
32
+
33
+ extern int yylex ();
34
+
35
+ extern char * yytext;
36
+
37
+ global_label = 1;
38
+ line_counter = 1;
39
+
40
+ static void mtex2MML_default_error (const char * msg)
41
+ {
42
+ if (msg)
43
+ fprintf(stderr, "Line: %d Error: %s\n", mtex2MML_lineno, msg);
44
+ }
45
+
46
+ void (*mtex2MML_error) (const char * msg) = mtex2MML_default_error;
47
+
48
+ static void yyerror (char **ret_str, char * s)
49
+ {
50
+ char * msg = mtex2MML_copy3 (s, " at token ", yytext);
51
+ if (mtex2MML_error)
52
+ (*mtex2MML_error) (msg);
53
+ mtex2MML_free_string (msg);
54
+ }
55
+
56
+ /* Note: If length is 0, then buffer is treated like a string; otherwise only length bytes are written.
57
+ */
58
+ static void mtex2MML_default_write (const char * buffer, unsigned long length)
59
+ {
60
+ if (buffer)
61
+ {
62
+ if (length)
63
+ fwrite (buffer, 1, length, stdout);
64
+ else
65
+ fputs (buffer, stdout);
66
+ }
67
+ }
68
+
69
+ static void mtex2MML_default_write_mathml (const char * mathml)
70
+ {
71
+ if (mtex2MML_write)
72
+ (*mtex2MML_write) (mathml, 0);
73
+ }
74
+
75
+ #ifdef mtex2MML_CAPTURE
76
+ static char * mtex2MML_output_string = "" ;
77
+
78
+ const char * mtex2MML_output ()
79
+ {
80
+ char * copy = (char *) malloc((mtex2MML_output_string ? strlen(mtex2MML_output_string) : 0) + 1);
81
+ if (copy)
82
+ {
83
+ if (mtex2MML_output_string)
84
+ {
85
+ strcpy(copy, mtex2MML_output_string);
86
+ if (*mtex2MML_output_string != '\0')
87
+ mtex2MML_free_string(mtex2MML_output_string);
88
+ }
89
+ else
90
+ copy[0] = 0;
91
+ mtex2MML_output_string = "";
92
+ }
93
+ return copy;
94
+ }
95
+
96
+ static void mtex2MML_capture (const char * buffer, unsigned long length)
97
+ {
98
+ if (buffer)
99
+ {
100
+ if (length)
101
+ {
102
+ unsigned long first_length = mtex2MML_output_string ? strlen(mtex2MML_output_string) : 0;
103
+ char * copy = (char *) malloc(first_length + length + 1);
104
+ if (copy)
105
+ {
106
+ if (mtex2MML_output_string)
107
+ {
108
+ strcpy(copy, mtex2MML_output_string);
109
+ if (*mtex2MML_output_string != '\0')
110
+ mtex2MML_free_string(mtex2MML_output_string);
111
+ }
112
+ else
113
+ copy[0] = 0;
114
+ strncat(copy, buffer, length);
115
+ mtex2MML_output_string = copy;
116
+ }
117
+ }
118
+ else
119
+ {
120
+ char * copy = mtex2MML_copy2(mtex2MML_output_string, buffer);
121
+ if (*mtex2MML_output_string != '\0')
122
+ mtex2MML_free_string(mtex2MML_output_string);
123
+ mtex2MML_output_string = copy;
124
+ }
125
+ }
126
+ }
127
+
128
+ static void mtex2MML_capture_mathml (const char * buffer)
129
+ {
130
+ char * temp = mtex2MML_copy2(mtex2MML_output_string, buffer);
131
+ if (*mtex2MML_output_string != '\0')
132
+ mtex2MML_free_string(mtex2MML_output_string);
133
+ mtex2MML_output_string = temp;
134
+ }
135
+ void (*mtex2MML_write) (const char * buffer, unsigned long length) = mtex2MML_capture;
136
+ void (*mtex2MML_write_mathml) (const char * mathml) = mtex2MML_capture_mathml;
137
+ #else
138
+ void (*mtex2MML_write) (const char * buffer, unsigned long length) = mtex2MML_default_write;
139
+ void (*mtex2MML_write_mathml) (const char * mathml) = mtex2MML_default_write_mathml;
140
+ #endif
141
+
142
+ char * mtex2MML_empty_string = (char *) "";
143
+
144
+ /* Create a copy of a string, adding space for extra chars
145
+ */
146
+ char * mtex2MML_copy_string_extra (const char * str, unsigned extra)
147
+ {
148
+ char * copy = (char *) malloc(extra + (str ? strlen (str) : 0) + 1);
149
+ if (copy)
150
+ {
151
+ if (str)
152
+ strcpy(copy, str);
153
+ else
154
+ copy[0] = 0;
155
+ }
156
+ return copy ? copy : mtex2MML_empty_string;
157
+ }
158
+
159
+ /* Create a copy of a string, appending two strings
160
+ */
161
+ char * mtex2MML_copy3 (const char * first, const char * second, const char * third)
162
+ {
163
+ int first_length = first ? strlen( first) : 0;
164
+ int second_length = second ? strlen(second) : 0;
165
+ int third_length = third ? strlen( third) : 0;
166
+
167
+ char * copy = (char *) malloc(first_length + second_length + third_length + 1);
168
+
169
+ if (copy)
170
+ {
171
+ if (first)
172
+ strcpy(copy, first);
173
+ else
174
+ copy[0] = 0;
175
+
176
+ if (second) strcat(copy, second);
177
+ if ( third) strcat(copy, third);
178
+ }
179
+ return copy ? copy : mtex2MML_empty_string;
180
+ }
181
+
182
+ /* Create a copy of a string, appending a second string
183
+ */
184
+ char * mtex2MML_copy2 (const char * first, const char * second)
185
+ {
186
+ return mtex2MML_copy3(first, second, 0);
187
+ }
188
+
189
+ /* Create a copy of a string
190
+ */
191
+ char * mtex2MML_copy_string (const char * str)
192
+ {
193
+ return mtex2MML_copy3(str, 0, 0);
194
+ }
195
+
196
+ /* Create a copy of a string, escaping unsafe characters for XML
197
+ */
198
+ char * mtex2MML_copy_escaped (const char * str)
199
+ {
200
+ unsigned long length = 0;
201
+
202
+ const char * ptr1 = str;
203
+
204
+ char * ptr2 = 0;
205
+ char * copy = 0;
206
+
207
+ if ( str == 0) return mtex2MML_empty_string;
208
+ if (*str == 0) return mtex2MML_empty_string;
209
+
210
+ while (*ptr1)
211
+ {
212
+ switch (*ptr1)
213
+ {
214
+ case '<': /* &lt; */
215
+ case '>': /* &gt; */
216
+ length += 4;
217
+ break;
218
+ case '&': /* &amp; */
219
+ length += 5;
220
+ break;
221
+ case '\'': /* &apos; */
222
+ case '"': /* &quot; */
223
+ case '-': /* &#x2d; */
224
+ length += 6;
225
+ break;
226
+ default:
227
+ length += 1;
228
+ break;
229
+ }
230
+ ++ptr1;
231
+ }
232
+
233
+ copy = (char *) malloc (length + 1);
234
+
235
+ if (copy)
236
+ {
237
+ ptr1 = str;
238
+ ptr2 = copy;
239
+
240
+ while (*ptr1)
241
+ {
242
+ switch (*ptr1)
243
+ {
244
+ case '<':
245
+ strcpy (ptr2, "&lt;");
246
+ ptr2 += 4;
247
+ break;
248
+ case '>':
249
+ strcpy (ptr2, "&gt;");
250
+ ptr2 += 4;
251
+ break;
252
+ case '&': /* &amp; */
253
+ strcpy (ptr2, "&amp;");
254
+ ptr2 += 5;
255
+ break;
256
+ case '\'': /* &apos; */
257
+ strcpy (ptr2, "&apos;");
258
+ ptr2 += 6;
259
+ break;
260
+ case '"': /* &quot; */
261
+ strcpy (ptr2, "&quot;");
262
+ ptr2 += 6;
263
+ break;
264
+ case '-': /* &#x2d; */
265
+ strcpy (ptr2, "&#x2d;");
266
+ ptr2 += 6;
267
+ break;
268
+ default:
269
+ *ptr2++ = *ptr1;
270
+ break;
271
+ }
272
+ ++ptr1;
273
+ }
274
+ *ptr2 = 0;
275
+ }
276
+ return copy ? copy : mtex2MML_empty_string;
277
+ }
278
+
279
+ /* Returns a string representation of the global_label, and increments the label */
280
+ char * mtex2MML_global_label() {
281
+ char * n = (char *) malloc(256);
282
+ snprintf(n, 256, "%d", global_label);
283
+ global_label++;
284
+ char *prefix = mtex2MML_copy3("</mtd><mtd><mtext>(", n, ")</mtext></mtd></mlabeledtr></mtable>");
285
+ mtex2MML_free_string(n);
286
+
287
+ return prefix;
288
+ }
289
+
290
+ /* Create a hex character reference string corresponding to code
291
+ */
292
+ char * mtex2MML_character_reference (unsigned long int code)
293
+ {
294
+ #define ENTITY_LENGTH 10
295
+ char * entity = (char *) malloc(ENTITY_LENGTH);
296
+ sprintf(entity, "&#x%05lx;", code);
297
+ return entity;
298
+ }
299
+
300
+ void mtex2MML_free_string (char * str)
301
+ {
302
+ if (str && str != mtex2MML_empty_string)
303
+ free(str);
304
+ }
305
+
306
+ %}
307
+
308
+ %left TEXOVER TEXOVERWITHDELIMS TEXATOP TEXATOPWITHDELIMS TEXABOVE TEXABOVEWITHDELIMS
309
+ %token CHAR STARTMATH STARTDMATH ENDMATH MTEXT MI MIB MN MO LIMITS NOLIMITS SUP SUB MROWOPEN MROWCLOSE MATHOPEN MATHCLOSE MATHORD MATHPUNCT VCENTER LEFT RIGHT BIG BBIG BIGG BBIGG BIGL BBIGL BIGGL BBIGGL BIGM BBIGM BIGGM BBIGGM FRAC TFRAC DFRAC CFRAC GENFRAC OPERATORNAME MATHOP MATHBIN MATHREL MATHINNER MOP MOL MOLL MOF MOR PERIODDELIM COMMADELIM OTHERDELIM LEFTDELIM RIGHTDELIM MOS MOB SQRT ROOT OF LEFTROOT UPROOT BINOM TBINOM BRACE BRACK CHOOSE DBINOM UNDER BUILDREL OVER OVERBRACE OVERBRACKET UNDERLINE UNDERBRACE UNDERBRACKET UNDEROVER TENSOR MULTI ALIGNATVALUE ARRAYALIGN COLUMNALIGN ARRAY SPACECUBE HSPACE MOVELEFT MOVERIGHT RAISE LOWER PXSTRING COLSEP ROWSEP ARRAYOPTS COLLAYOUT COLALIGN ROWALIGN ALIGN EQROWS EQCOLS ROWLINES COLLINES FRAME PADDING ATTRLIST ITALICS SANS TT ENCLOSE ENCLOSENOTATION ENCLOSEATTR ENCLOSETEXT BOLD BOXED FBOX HBOX MBOX BCANCELED XCANCELED CANCELEDTO NOT SLASHED PMB SCR RM BB ST END BBLOWERCHAR BBUPPERCHAR BBDIGIT CALCHAR FRAKCHAR CAL FRAK CLAP LLAP RLAP ROWOPTS TEXTSIZE OLDSTYLE SCSTY SCSIZE SCSCSIZE TINY TTINY SMALL NORMALSIZE LARGE LLARGE LLLARGE HUGE HHUGE DISPLAY TEXTSTY TEXTBOX TEXTSTRING COLORSTRING STYLESTRING VERBBOX VERBSTRING ACUTE GRAVE BREVE MATHRING XMLSTRING CELLOPTS ROWSPAN COLSPAN THINSPACE ENSPACE MEDSPACE THICKSPACE QUAD QQUAD NEGSPACE NEGMEDSPACE NEGTHICKSPACE STRUT MATHSTRUT SMASH PHANTOM HPHANTOM VPHANTOM HREF UNKNOWNCHAR EMPTYMROW STATLINE TOOLTIP TOGGLE TOGGLESTART TOGGLEEND FGHIGHLIGHT BGHIGHLIGHT COLORBOX SPACE NUMBER INTONE INTTWO INTTHREE OVERLEFTARROW OVERLEFTRIGHTARROW OVERRIGHTARROW UNDERLEFTARROW UNDERLEFTRIGHTARROW UNDERRIGHTARROW BAR WIDEBAR SKEW VEC WIDEVEC HAT WIDEHAT CHECK WIDECHECK TILDE WIDETILDE DOT DDOT DDDOT DDDDOT UNARYMINUS UNARYPLUS BEGINENV ENDENV EQUATION EQUATION_STAR EQALIGN EQALIGNNO MATRIX PMATRIX BMATRIX BBMATRIX VMATRIX VVMATRIX SUBARRAY SVG ENDSVG SMALLMATRIX CASES ALIGNED ALIGNENV ALIGNENV_STAR ALIGNAT ALIGNAT_STAR ALIGNEDAT GATHERED EQNARRAY EQNARRAY_STAR MULTLINE MULTLINE_STAR GATHER_STAR GATHER SUBSTACK SIDESET BMOD PMOD POD RMCHAR SCRCHAR PMBCHAR COLOR BGCOLOR BBOX XARROW OPTARGOPEN OPTARGCLOSE MTEXNUM RAISEBOX NEG LATEXSYMBOL TEXSYMBOL VARINJLIM VARLIMINF VARLIMSUP VARPROJLIM
310
+
311
+ %%
312
+
313
+ doc: xmlmmlTermList {/* all processing done in body*/};
314
+
315
+ xmlmmlTermList:
316
+ {/* nothing - do nothing*/}
317
+ | char {/* proc done in body*/}
318
+ | expression {/* all proc. in body*/}
319
+ | xmlmmlTermList char {/* all proc. in body*/}
320
+ | xmlmmlTermList expression {/* all proc. in body*/};
321
+
322
+ char: CHAR { mtex2MML_free_string($1); /* Do nothing...but what did this used to do? printf("%s", $1); */ };
323
+
324
+ expression: STARTMATH ENDMATH {/* empty math group - ignore*/}
325
+ | STARTDMATH ENDMATH {/* ditto */}
326
+ | STARTMATH compoundTermList ENDMATH {
327
+ char ** r = (char **) ret_str;
328
+ char * p = mtex2MML_copy3("<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow>", $2, "</mrow><annotation encoding='application/x-tex'>");
329
+ char * s = mtex2MML_copy3(p, $3, "</annotation></semantics></math>");
330
+ mtex2MML_free_string(p);
331
+ mtex2MML_free_string($2);
332
+ mtex2MML_free_string($3);
333
+ if (r) {
334
+ (*r) = (s == mtex2MML_empty_string) ? 0 : s;
335
+ }
336
+ else {
337
+ if (mtex2MML_write_mathml)
338
+ (*mtex2MML_write_mathml) (s);
339
+ mtex2MML_free_string(s);
340
+ }
341
+ }
342
+ | STARTDMATH compoundTermList ENDMATH {
343
+ char ** r = (char **) ret_str;
344
+ char * p = mtex2MML_copy3("<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow>", $2, "</mrow><annotation encoding='application/x-tex'>");
345
+ char * s = mtex2MML_copy3(p, $3, "</annotation></semantics></math>");
346
+ mtex2MML_free_string(p);
347
+ mtex2MML_free_string($2);
348
+ mtex2MML_free_string($3);
349
+ if (r) {
350
+ (*r) = (s == mtex2MML_empty_string) ? 0 : s;
351
+ }
352
+ else {
353
+ if (mtex2MML_write_mathml)
354
+ (*mtex2MML_write_mathml) (s);
355
+ mtex2MML_free_string(s);
356
+ }
357
+ }
358
+ /* plugs away some memory leaks when errors occur */
359
+ | compoundTermList error { mtex2MML_free_string($1); mtex2MML_free_string($2); YYABORT; }
360
+ | compoundTerm error { mtex2MML_free_string($1); mtex2MML_free_string($2); YYABORT; }
361
+ | error { YYABORT; }; /* tosses away the final token so that future parses are not affected */
362
+
363
+ compoundTermList: compoundTerm {
364
+ $$ = mtex2MML_copy_string($1);
365
+ mtex2MML_free_string($1);
366
+ }
367
+ | compoundTermList compoundTerm {
368
+ $$ = mtex2MML_copy2($1, $2);
369
+ mtex2MML_free_string($1);
370
+ mtex2MML_free_string($2);
371
+ };
372
+
373
+ compoundTerm: mob SUB closedTerm SUP closedTerm {
374
+ if (mtex2MML_displaymode == 1) {
375
+ char * s1 = mtex2MML_copy3("<munderover>", $1, " ");
376
+ char * s2 = mtex2MML_copy3($3, " ", $5);
377
+ $$ = mtex2MML_copy3(s1, s2, "</munderover>");
378
+ mtex2MML_free_string(s1);
379
+ mtex2MML_free_string(s2);
380
+ }
381
+ else {
382
+ char * s1 = mtex2MML_copy3("<msubsup>", $1, " ");
383
+ char * s2 = mtex2MML_copy3($3, " ", $5);
384
+ $$ = mtex2MML_copy3(s1, s2, "</msubsup>");
385
+ mtex2MML_free_string(s1);
386
+ mtex2MML_free_string(s2);
387
+ }
388
+ mtex2MML_free_string($1);
389
+ mtex2MML_free_string($3);
390
+ mtex2MML_free_string($5);
391
+ }
392
+ | MATHOP closedTerm SUB closedTerm SUP closedTerm {
393
+ char * s1 = mtex2MML_copy3("<munderover><mrow>", $2, "</mrow>");
394
+ char * s2 = mtex2MML_copy3(s1, $4, $6);
395
+ $$ = mtex2MML_copy2(s2, "</munderover>");
396
+ mtex2MML_free_string(s1);
397
+ mtex2MML_free_string(s2);
398
+
399
+ mtex2MML_free_string($2);
400
+ mtex2MML_free_string($4);
401
+ mtex2MML_free_string($6);
402
+ }
403
+ | OPERATORNAME closedTerm closedTerm {
404
+ char * s1 = mtex2MML_copy3("<mi>", $2, "</mi>");
405
+ $$ = mtex2MML_copy2(s1, $3);
406
+
407
+ mtex2MML_free_string(s1);
408
+ mtex2MML_free_string($2);
409
+ mtex2MML_free_string($3);
410
+ }
411
+ | OPERATORNAME closedTerm SUB closedTerm SUP closedTerm closedTerm {
412
+ char *s1 = mtex2MML_copy3("<msubsup><mi>", $2, "</mi>");
413
+ char *s2 = mtex2MML_copy3(s1, $4, $6);
414
+ $$ = mtex2MML_copy3(s2, "</msubsup><mo>&#x2061;</mo>", $7);
415
+
416
+ mtex2MML_free_string(s1);
417
+ mtex2MML_free_string(s2);
418
+ mtex2MML_free_string($2);
419
+ mtex2MML_free_string($4);
420
+ mtex2MML_free_string($6);
421
+ mtex2MML_free_string($7);
422
+ }
423
+ | mob SUB closedTerm {
424
+ if (mtex2MML_displaymode == 1) {
425
+ char * s1 = mtex2MML_copy3("<munder>", $1, " ");
426
+ $$ = mtex2MML_copy3(s1, $3, "</munder>");
427
+ mtex2MML_free_string(s1);
428
+ }
429
+ else {
430
+ char * s1 = mtex2MML_copy3("<msub>", $1, " ");
431
+ $$ = mtex2MML_copy3(s1, $3, "</msub>");
432
+ mtex2MML_free_string(s1);
433
+ }
434
+ mtex2MML_free_string($1);
435
+ mtex2MML_free_string($3);
436
+ }
437
+ | mob SUP closedTerm SUB closedTerm {
438
+ char * s1 = mtex2MML_copy3("<munderover>", $1, " ");
439
+ char * s2 = mtex2MML_copy3($5, " ", $3);
440
+ $$ = mtex2MML_copy3(s1, s2, "</munderover>");
441
+
442
+ mtex2MML_free_string(s1);
443
+ mtex2MML_free_string(s2);
444
+ mtex2MML_free_string($1);
445
+ mtex2MML_free_string($3);
446
+ mtex2MML_free_string($5);
447
+ }
448
+ | mob SUP closedTerm {
449
+ if (mtex2MML_displaymode == 1) {
450
+ char * s1 = mtex2MML_copy3("<mover>", $1, " ");
451
+ $$ = mtex2MML_copy3(s1, $3, "</mover>");
452
+ mtex2MML_free_string(s1);
453
+ }
454
+ else {
455
+ char * s1 = mtex2MML_copy3("<msup>", $1, " ");
456
+ $$ = mtex2MML_copy3(s1, $3, "</msup>");
457
+ mtex2MML_free_string(s1);
458
+ }
459
+ mtex2MML_free_string($1);
460
+ mtex2MML_free_string($3);
461
+ }
462
+ | mob SUP closedTerm LIMITS SUB closedTerm {
463
+ char * mo = str_replace($1, "<mo>", "<mo movablelimits=\"false\">");
464
+ char * s1 = mtex2MML_copy2("<munderover>", mo);
465
+ char * s2 = mtex2MML_copy3($6, " ", $3);
466
+ $$ = mtex2MML_copy3(s1, s2, "</munderover>");
467
+
468
+ mtex2MML_free_string(mo);
469
+ mtex2MML_free_string(s1);
470
+ mtex2MML_free_string(s2);
471
+ mtex2MML_free_string($1);
472
+ mtex2MML_free_string($3);
473
+ mtex2MML_free_string($6);
474
+ }
475
+ | mob SUP closedTerm NOLIMITS SUB closedTerm {
476
+ char * mo = str_replace($1, "<mo>", "<mo movablelimits=\"false\">");
477
+ char * s1 = mtex2MML_copy2("<msubsup>", mo);
478
+ char * s2 = mtex2MML_copy3($6, " ", $3);
479
+ $$ = mtex2MML_copy3(s1, s2, "</msubsup>");
480
+
481
+ mtex2MML_free_string(mo);
482
+ mtex2MML_free_string(s1);
483
+ mtex2MML_free_string(s2);
484
+ mtex2MML_free_string($1);
485
+ mtex2MML_free_string($3);
486
+ mtex2MML_free_string($6);
487
+ }
488
+ | mib SUB closedTerm SUP closedTerm {
489
+ if (mtex2MML_displaymode == 1) {
490
+ char * s1 = mtex2MML_copy3("<munderover>", $1, " ");
491
+ char * s2 = mtex2MML_copy3($3, " ", $5);
492
+ $$ = mtex2MML_copy3(s1, s2, "</munderover>");
493
+ mtex2MML_free_string(s1);
494
+ mtex2MML_free_string(s2);
495
+ }
496
+ else {
497
+ char * s1 = mtex2MML_copy3("<msubsup>", $1, " ");
498
+ char * s2 = mtex2MML_copy3($3, " ", $5);
499
+ $$ = mtex2MML_copy3(s1, s2, "</msubsup>");
500
+ mtex2MML_free_string(s1);
501
+ mtex2MML_free_string(s2);
502
+ }
503
+ mtex2MML_free_string($1);
504
+ mtex2MML_free_string($3);
505
+ mtex2MML_free_string($5);
506
+ }
507
+ | mib SUB closedTerm {
508
+ if (mtex2MML_displaymode == 1) {
509
+ char * s1 = mtex2MML_copy3("<munder>", $1, " ");
510
+ $$ = mtex2MML_copy3(s1, $3, "</munder>");
511
+ mtex2MML_free_string(s1);
512
+ }
513
+ else {
514
+ char * s1 = mtex2MML_copy3("<msub>", $1, " ");
515
+ $$ = mtex2MML_copy3(s1, $3, "</msub>");
516
+ mtex2MML_free_string(s1);
517
+ }
518
+ mtex2MML_free_string($1);
519
+ mtex2MML_free_string($3);
520
+ }
521
+ | mib SUP closedTerm SUB closedTerm {
522
+ if (mtex2MML_displaymode == 1) {
523
+ char * s1 = mtex2MML_copy3("<munderover>", $1, " ");
524
+ char * s2 = mtex2MML_copy3($5, " ", $3);
525
+ $$ = mtex2MML_copy3(s1, s2, "</munderover>");
526
+ mtex2MML_free_string(s1);
527
+ mtex2MML_free_string(s2);
528
+ }
529
+ else {
530
+ char * s1 = mtex2MML_copy3("<msubsup>", $1, " ");
531
+ char * s2 = mtex2MML_copy3($5, " ", $3);
532
+ $$ = mtex2MML_copy3(s1, s2, "</msubsup>");
533
+ mtex2MML_free_string(s1);
534
+ mtex2MML_free_string(s2);
535
+ }
536
+ mtex2MML_free_string($1);
537
+ mtex2MML_free_string($3);
538
+ mtex2MML_free_string($5);
539
+ }
540
+ | mib SUP closedTerm {
541
+ if (mtex2MML_displaymode == 1) {
542
+ char * s1 = mtex2MML_copy3("<mover>", $1, " ");
543
+ $$ = mtex2MML_copy3(s1, $3, "</mover>");
544
+ mtex2MML_free_string(s1);
545
+ }
546
+ else {
547
+ char * s1 = mtex2MML_copy3("<msup>", $1, " ");
548
+ $$ = mtex2MML_copy3(s1, $3, "</msup>");
549
+ mtex2MML_free_string(s1);
550
+ }
551
+ mtex2MML_free_string($1);
552
+ mtex2MML_free_string($3);
553
+ }
554
+ | mib LIMITS SUB closedTerm {
555
+ char * s1 = mtex2MML_copy3("<munder>", $1, " ");
556
+ $$ = mtex2MML_copy3(s1, $4, "</munder>");
557
+ mtex2MML_free_string(s1);
558
+
559
+ mtex2MML_free_string($1);
560
+ mtex2MML_free_string($4);
561
+ }
562
+ | closedTerm SUB closedTerm SUP closedTerm {
563
+ char * s1 = mtex2MML_copy3("<msubsup>", $1, " ");
564
+ char * s2 = mtex2MML_copy3($3, " ", $5);
565
+ $$ = mtex2MML_copy3(s1, s2, "</msubsup>");
566
+ mtex2MML_free_string(s1);
567
+ mtex2MML_free_string(s2);
568
+ mtex2MML_free_string($1);
569
+ mtex2MML_free_string($3);
570
+ mtex2MML_free_string($5);
571
+ }
572
+ | closedTerm NOLIMITS SUB closedTerm SUP closedTerm {
573
+ char * s1 = mtex2MML_copy3("<msubsup>", $1, " ");
574
+ char * s2 = mtex2MML_copy3($4, " ", $6);
575
+ $$ = mtex2MML_copy3(s1, s2, "</msubsup>");
576
+ mtex2MML_free_string(s1);
577
+ mtex2MML_free_string(s2);
578
+ mtex2MML_free_string($1);
579
+ mtex2MML_free_string($4);
580
+ mtex2MML_free_string($6);
581
+ }
582
+ | closedTerm SUP closedTerm SUB closedTerm {
583
+ char * s1 = mtex2MML_copy3("<msubsup>", $1, " ");
584
+ char * s2 = mtex2MML_copy3($5, " ", $3);
585
+ $$ = mtex2MML_copy3(s1, s2, "</msubsup>");
586
+ mtex2MML_free_string(s1);
587
+ mtex2MML_free_string(s2);
588
+ mtex2MML_free_string($1);
589
+ mtex2MML_free_string($3);
590
+ mtex2MML_free_string($5);
591
+ }
592
+ | closedTerm SUB closedTerm {
593
+ char * s1 = mtex2MML_copy3("<msub>", $1, " ");
594
+ $$ = mtex2MML_copy3(s1, $3, "</msub>");
595
+ mtex2MML_free_string(s1);
596
+ mtex2MML_free_string($1);
597
+ mtex2MML_free_string($3);
598
+ }
599
+ | closedTerm SUP closedTerm {
600
+ char * s1 = mtex2MML_copy3("<msup>", $1, " ");
601
+ $$ = mtex2MML_copy3(s1, $3, "</msup>");
602
+ mtex2MML_free_string(s1);
603
+ mtex2MML_free_string($1);
604
+ mtex2MML_free_string($3);
605
+ }
606
+ | SUB closedTerm {
607
+ $$ = mtex2MML_copy3("<msub><mo/>", $2, "</msub>");
608
+ mtex2MML_free_string($2);
609
+ }
610
+ | SUP closedTerm {
611
+ $$ = mtex2MML_copy3("<msup><mo/>", $2, "</msup>");
612
+ mtex2MML_free_string($2);
613
+ }
614
+ | closedTerm {
615
+ $$ = mtex2MML_copy_string($1);
616
+ mtex2MML_free_string($1);
617
+ };
618
+
619
+ closedTerm: array
620
+ | cases
621
+ | eqalign
622
+ | eqalignno
623
+ | unaryminus
624
+ | unaryplus
625
+ | mib
626
+ | mtext {
627
+ $$ = mtex2MML_copy3("<mtext>", $1, "</mtext>");
628
+ mtex2MML_free_string($1);
629
+ }
630
+ | mi {
631
+ $$ = mtex2MML_copy3("<mi>", $1, "</mi>");
632
+ mtex2MML_free_string($1);
633
+ }
634
+ | mn {
635
+ $$ = mtex2MML_copy3("<mn>", $1, "</mn>");
636
+ mtex2MML_free_string($1);
637
+ }
638
+ | mo
639
+ | tensor
640
+ | multi
641
+ | mfrac
642
+ | mathopen
643
+ | mathclose
644
+ | mathord
645
+ | mathpunct
646
+ | vcenter
647
+ | enclose
648
+ | binom
649
+ | brace
650
+ | brack
651
+ | choose
652
+ | msqrt
653
+ | mroot
654
+ | leftroot
655
+ | uproot
656
+ | raisebox
657
+ | munder
658
+ | mover
659
+ | bar
660
+ | vec
661
+ | hat
662
+ | skew
663
+ | acute
664
+ | grave
665
+ | breve
666
+ | mathring
667
+ | dot
668
+ | ddot
669
+ | dddot
670
+ | ddddot
671
+ | check
672
+ | tilde
673
+ | overleftarrow
674
+ | overleftrightarrow
675
+ | overrightarrow
676
+ | underleftarrow
677
+ | underleftrightarrow
678
+ | underrightarrow
679
+ | moverbrace
680
+ | moverbracket
681
+ | munderbrace
682
+ | munderbracket
683
+ | munderline
684
+ | munderover
685
+ | emptymrow
686
+ | mathclap
687
+ | mathllap
688
+ | mathrlap
689
+ | displaystyle
690
+ | textstyle
691
+ | textsize
692
+ | scriptstyle
693
+ | scriptsize
694
+ | tiny
695
+ | ttiny
696
+ | small
697
+ | normalsize
698
+ | large
699
+ | llarge
700
+ | lllarge
701
+ | huge
702
+ | hhuge
703
+ | scriptscriptsize
704
+ | oldstyle
705
+ | moveleft
706
+ | moveright
707
+ | raise
708
+ | lower
709
+ | italics
710
+ | sans
711
+ | mono
712
+ | bold
713
+ | roman
714
+ | rmchars
715
+ | script
716
+ | scrchars
717
+ | pmb
718
+ | pmbchars
719
+ | bbold
720
+ | frak
721
+ | not
722
+ | slashed
723
+ | bcanceled
724
+ | xcanceled
725
+ | canceledto
726
+ | boxed
727
+ | fbox
728
+ | hbox
729
+ | mbox
730
+ | cal
731
+ | space
732
+ | textstring
733
+ | verbstring
734
+ | thinspace
735
+ | medspace
736
+ | thickspace
737
+ | enspace
738
+ | spacecube
739
+ | quad
740
+ | qquad
741
+ | negspace
742
+ | negmedspace
743
+ | negthickspace
744
+ | strut
745
+ | mathstrut
746
+ | smash
747
+ | phantom
748
+ | hphantom
749
+ | vphantom
750
+ | tex
751
+ | latex
752
+ | varinjlim
753
+ | varliminf
754
+ | varlimsup
755
+ | varprojlm
756
+ | href
757
+ | statusline
758
+ | tooltip
759
+ | toggle
760
+ | fghighlight
761
+ | bghighlight
762
+ | colorbox
763
+ | color
764
+ | hspace
765
+ | buildrel
766
+ | texover
767
+ | texoverwithdelims
768
+ | texatop
769
+ | texatopwithdelims
770
+ | texabove
771
+ | texabovewithdelims
772
+ | MROWOPEN closedTerm MROWCLOSE {
773
+ $$ = mtex2MML_copy_string($2);
774
+ mtex2MML_free_string($2);
775
+ }
776
+ | MROWOPEN compoundTermList MROWCLOSE {
777
+ $$ = mtex2MML_copy3("<mrow>", $2, "</mrow>");
778
+ mtex2MML_free_string($2);
779
+ }
780
+ | left compoundTermList right {
781
+ char * s1 = mtex2MML_copy3("<mrow>", $1, $2);
782
+ $$ = mtex2MML_copy3(s1, $3, "</mrow>");
783
+ mtex2MML_free_string(s1);
784
+ mtex2MML_free_string($1);
785
+ mtex2MML_free_string($2);
786
+ mtex2MML_free_string($3);
787
+ }
788
+ | mathenv
789
+ | substack
790
+ | sideset
791
+ | bmod
792
+ | pmod
793
+ | pod
794
+ | unrecognized;
795
+
796
+ left: LEFT LEFTDELIM {
797
+ mtex2MML_rowposn = 2;
798
+ $$ = mtex2MML_copy3("<mo>", $2, "</mo>");
799
+ mtex2MML_free_string($2);
800
+ }
801
+ | LEFT OTHERDELIM {
802
+ mtex2MML_rowposn = 2;
803
+ $$ = mtex2MML_copy3("<mo>", $2, "</mo>");
804
+ mtex2MML_free_string($2);
805
+ }
806
+ | LEFT PERIODDELIM {
807
+ mtex2MML_rowposn = 2;
808
+ $$ = mtex2MML_copy_string("");
809
+ mtex2MML_free_string($2);
810
+ };
811
+
812
+ right: RIGHT RIGHTDELIM {
813
+ $$ = mtex2MML_copy3("<mo>", $2, "</mo>");
814
+ mtex2MML_free_string($2);
815
+ }
816
+ | RIGHT OTHERDELIM {
817
+ $$ = mtex2MML_copy3("<mo>", $2, "</mo>");
818
+ mtex2MML_free_string($2);
819
+ }
820
+ | RIGHT PERIODDELIM {
821
+ $$ = mtex2MML_copy_string("");
822
+ mtex2MML_free_string($2);
823
+ };
824
+
825
+ bigdelim: BIG LEFTDELIM {
826
+ mtex2MML_rowposn = 2;
827
+ $$ = mtex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
828
+ mtex2MML_free_string($2);
829
+ }
830
+ | BIG RIGHTDELIM {
831
+ $$ = mtex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
832
+ mtex2MML_free_string($2);
833
+ }
834
+ | BIG OTHERDELIM {
835
+ $$ = mtex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
836
+ mtex2MML_free_string($2);
837
+ }
838
+ | BBIG LEFTDELIM {
839
+ mtex2MML_rowposn = 2;
840
+ $$ = mtex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
841
+ mtex2MML_free_string($2);
842
+ }
843
+ | BBIG RIGHTDELIM {
844
+ $$ = mtex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
845
+ mtex2MML_free_string($2);
846
+ }
847
+ | BBIG OTHERDELIM {
848
+ $$ = mtex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
849
+ mtex2MML_free_string($2);
850
+ }
851
+ | BIGG LEFTDELIM {
852
+ mtex2MML_rowposn = 2;
853
+ $$ = mtex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
854
+ mtex2MML_free_string($2);
855
+ }
856
+ | BIGG RIGHTDELIM {
857
+ $$ = mtex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
858
+ mtex2MML_free_string($2);
859
+ }
860
+ | BIGG OTHERDELIM {
861
+ $$ = mtex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
862
+ mtex2MML_free_string($2);
863
+ }
864
+ | BBIGG LEFTDELIM {
865
+ mtex2MML_rowposn = 2;
866
+ $$ = mtex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
867
+ mtex2MML_free_string($2);
868
+ }
869
+ | BBIGG RIGHTDELIM {
870
+ $$ = mtex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
871
+ mtex2MML_free_string($2);
872
+ }
873
+ | BBIGG OTHERDELIM {
874
+ $$ = mtex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
875
+ mtex2MML_free_string($2);
876
+ }
877
+ | BIGL LEFTDELIM {
878
+ mtex2MML_rowposn = 2;
879
+ $$ = mtex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
880
+ mtex2MML_free_string($2);
881
+ }
882
+ | BIGL OTHERDELIM {
883
+ mtex2MML_rowposn = 2;
884
+ $$ = mtex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
885
+ mtex2MML_free_string($2);
886
+ }
887
+ | BBIGL LEFTDELIM {
888
+ mtex2MML_rowposn = 2;
889
+ $$ = mtex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
890
+ mtex2MML_free_string($2);
891
+ }
892
+ | BBIGL OTHERDELIM {
893
+ mtex2MML_rowposn = 2;
894
+ $$ = mtex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
895
+ mtex2MML_free_string($2);
896
+ }
897
+ | BIGGL LEFTDELIM {
898
+ mtex2MML_rowposn = 2;
899
+ $$ = mtex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
900
+ mtex2MML_free_string($2);
901
+ }
902
+ | BIGGL OTHERDELIM {
903
+ mtex2MML_rowposn = 2;
904
+ $$ = mtex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
905
+ mtex2MML_free_string($2);
906
+ }
907
+ | BBIGGL LEFTDELIM {
908
+ mtex2MML_rowposn = 2;
909
+ $$ = mtex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
910
+ mtex2MML_free_string($2);
911
+ }
912
+ | BBIGGL OTHERDELIM {
913
+ mtex2MML_rowposn = 2;
914
+ $$ = mtex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
915
+ mtex2MML_free_string($2);
916
+ }
917
+ | BIGM LEFTDELIM {
918
+ mtex2MML_rowposn = 2;
919
+ $$ = mtex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\" fence=\"true\" stretchy=\"true\" symmetric=\"true\">", $2, "</mo>");
920
+ mtex2MML_free_string($2);
921
+ }
922
+ | BIGM OTHERDELIM {
923
+ mtex2MML_rowposn = 2;
924
+ $$ = mtex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\" fence=\"true\" stretchy=\"true\" symmetric=\"true\">", $2, "</mo>");
925
+ mtex2MML_free_string($2);
926
+ }
927
+ | BBIGM LEFTDELIM {
928
+ mtex2MML_rowposn = 2;
929
+ $$ = mtex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\" fence=\"true\" stretchy=\"true\" symmetric=\"true\">", $2, "</mo>");
930
+ mtex2MML_free_string($2);
931
+ }
932
+ | BBIGM OTHERDELIM {
933
+ mtex2MML_rowposn = 2;
934
+ $$ = mtex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\" fence=\"true\" stretchy=\"true\" symmetric=\"true\">", $2, "</mo>");
935
+ mtex2MML_free_string($2);
936
+ }
937
+ | BIGGM LEFTDELIM {
938
+ mtex2MML_rowposn = 2;
939
+ $$ = mtex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\" fence=\"true\" stretchy=\"true\" symmetric=\"true\">", $2, "</mo>");
940
+ mtex2MML_free_string($2);
941
+ }
942
+ | BIGGM OTHERDELIM {
943
+ mtex2MML_rowposn = 2;
944
+ $$ = mtex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\" fence=\"true\" stretchy=\"true\" symmetric=\"true\">", $2, "</mo>");
945
+ mtex2MML_free_string($2);
946
+ }
947
+ | BBIGGM LEFTDELIM {
948
+ mtex2MML_rowposn = 2;
949
+ $$ = mtex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\" fence=\"true\" stretchy=\"true\" symmetric=\"true\">", $2, "</mo>");
950
+ mtex2MML_free_string($2);
951
+ }
952
+ | BBIGGM OTHERDELIM {
953
+ mtex2MML_rowposn = 2;
954
+ $$ = mtex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\" fence=\"true\" stretchy=\"true\" symmetric=\"true\">", $2, "</mo>");
955
+ mtex2MML_free_string($2);
956
+ };
957
+
958
+ unrecognized: UNKNOWNCHAR {
959
+ $$ = mtex2MML_copy_string("<merror><mtext>Unknown character</mtext></merror>");
960
+ };
961
+
962
+ unaryminus: UNARYMINUS {
963
+ $$ = mtex2MML_copy_string("<mo lspace=\"verythinmathspace\" rspace=\"0em\">&minus;</mo>");
964
+ };
965
+
966
+ unaryplus: UNARYPLUS {
967
+ $$ = mtex2MML_copy_string("<mo lspace=\"verythinmathspace\" rspace=\"0em\">+</mo>");
968
+ };
969
+
970
+ varinjlim: VARINJLIM {
971
+ $$ = mtex2MML_copy_string("<munder>lim<mo>&#x2192;</mo></munder>");
972
+ };
973
+
974
+ varliminf: VARLIMINF {
975
+ $$ = mtex2MML_copy_string("<munder>lim<mo>_</mo></munder>");
976
+ };
977
+
978
+ varlimsup: VARLIMSUP {
979
+ $$ = mtex2MML_copy_string("<mover>lim<mo>&#xAF;</mo></mover>");
980
+ };
981
+
982
+ varprojlm: VARPROJLIM {
983
+ $$ = mtex2MML_copy_string("<munder>lim<mo>&#x2190;</mo></munder>");
984
+ };
985
+
986
+ mi: MI;
987
+
988
+ mtext: MTEXT;
989
+
990
+ mib: MIB {
991
+ mtex2MML_rowposn=2;
992
+ $$ = mtex2MML_copy3("<mi>", $1, "</mi>");
993
+ mtex2MML_free_string($1);
994
+ };
995
+
996
+ mn: MN
997
+ | MTEXNUM TEXTSTRING {
998
+ mtex2MML_rowposn = 2;
999
+ $$ = mtex2MML_copy_string($2);
1000
+ mtex2MML_free_string($2);
1001
+ };
1002
+
1003
+ mob: MOB {
1004
+ mtex2MML_rowposn = 2;
1005
+ $$ = mtex2MML_copy3("<mo>", $1, "</mo>");
1006
+ mtex2MML_free_string($1);
1007
+ };
1008
+
1009
+ mo: mob
1010
+ | bigdelim
1011
+ | MO {
1012
+ mtex2MML_rowposn = 2;
1013
+ $$ = mtex2MML_copy3("<mo>", $1, "</mo>");
1014
+ mtex2MML_free_string($1);
1015
+ }
1016
+ | MOL {
1017
+ mtex2MML_rowposn = 2;
1018
+ $$ = mtex2MML_copy3("<mo>", $1, "</mo>");
1019
+ mtex2MML_free_string($1);
1020
+ }
1021
+ | MOLL {
1022
+ mtex2MML_rowposn = 2;
1023
+ $$ = mtex2MML_copy3("<mstyle scriptlevel=\"0\"><mo>", $1, "</mo></mstyle>");
1024
+ mtex2MML_free_string($1);
1025
+ }
1026
+ | MOL LIMITS SUB closedTerm SUP closedTerm {
1027
+ if (mtex2MML_displaymode == 1) {
1028
+ char * s1 = mtex2MML_copy3("<munderover>", $1, " ");
1029
+ char * s2 = mtex2MML_copy3($4, " ", $6);
1030
+ $$ = mtex2MML_copy3(s1, s2, "</munderover>");
1031
+ mtex2MML_free_string(s1);
1032
+ mtex2MML_free_string(s2);
1033
+ }
1034
+ else {
1035
+ char * s1 = mtex2MML_copy3("<msubsup>", $1, " ");
1036
+ char * s2 = mtex2MML_copy3($4, " ", $6);
1037
+ $$ = mtex2MML_copy3(s1, s2, "</msubsup>");
1038
+ mtex2MML_free_string(s1);
1039
+ mtex2MML_free_string(s2);
1040
+ }
1041
+ mtex2MML_free_string($1);
1042
+ mtex2MML_free_string($4);
1043
+ mtex2MML_free_string($6);
1044
+ }
1045
+ | RIGHTDELIM {
1046
+ $$ = mtex2MML_copy3("<mo stretchy=\"false\">", $1, "</mo>");
1047
+ mtex2MML_free_string($1);
1048
+ }
1049
+ | LEFTDELIM {
1050
+ mtex2MML_rowposn = 2;
1051
+ $$ = mtex2MML_copy3("<mo stretchy=\"false\">", $1, "</mo>");
1052
+ mtex2MML_free_string($1);
1053
+ }
1054
+ | OTHERDELIM {
1055
+ $$ = mtex2MML_copy3("<mo stretchy=\"false\">", $1, "</mo>");
1056
+ mtex2MML_free_string($1);
1057
+ }
1058
+ | MOF {
1059
+ $$ = mtex2MML_copy3("<mo stretchy=\"false\">", $1, "</mo>");
1060
+ mtex2MML_free_string($1);
1061
+ }
1062
+ | PERIODDELIM {
1063
+ $$ = mtex2MML_copy3("<mo>", $1, "</mo>");
1064
+ mtex2MML_free_string($1);
1065
+ }
1066
+ | COMMADELIM {
1067
+ $$ = mtex2MML_copy3("<mo>", $1, "</mo>");
1068
+ mtex2MML_free_string($1);
1069
+ }
1070
+ | MOS {
1071
+ mtex2MML_rowposn=2;
1072
+ $$ = mtex2MML_copy3("<mo lspace=\"mediummathspace\" rspace=\"mediummathspace\">", $1, "</mo>");
1073
+ mtex2MML_free_string($1);
1074
+ }
1075
+ | MOP {
1076
+ mtex2MML_rowposn = 2;
1077
+ $$ = mtex2MML_copy3("<mo lspace=\"0em\" rspace=\"thinmathspace\">", $1, "</mo>");
1078
+ mtex2MML_free_string($1);
1079
+ }
1080
+ | MOR {
1081
+ mtex2MML_rowposn = 2;
1082
+ $$ = mtex2MML_copy3("<mo lspace=\"verythinmathspace\">", $1, "</mo>");
1083
+ mtex2MML_free_string($1);
1084
+ }
1085
+ | MATHBIN TEXTSTRING {
1086
+ mtex2MML_rowposn = 2;
1087
+ $$ = mtex2MML_copy3("<mo lspace=\"mediummathspace\" rspace=\"mediummathspace\">", $2, "</mo>");
1088
+ mtex2MML_free_string($2);
1089
+ }
1090
+ | MATHINNER TEXTSTRING {
1091
+ mtex2MML_rowposn = 2;
1092
+ $$ = mtex2MML_copy3("<mo lspace=\"mediummathspace\" rspace=\"mediummathspace\">", $2, "</mo>");
1093
+ mtex2MML_free_string($2);
1094
+ }
1095
+ | MATHREL TEXTSTRING {
1096
+ mtex2MML_rowposn = 2;
1097
+ $$ = mtex2MML_copy3("<mo lspace=\"thickmathspace\" rspace=\"thickmathspace\">", $2, "</mo>");
1098
+ mtex2MML_free_string($2);
1099
+ };
1100
+
1101
+ space: SPACE ST INTONE END ST INTTWO END ST INTTHREE END {
1102
+ char * s1 = mtex2MML_copy3("<mspace height=\"", $3, "ex\" depth=\"");
1103
+ char * s2 = mtex2MML_copy3($6, "ex\" width=\"", $9);
1104
+ $$ = mtex2MML_copy3(s1, s2, "em\"/>");
1105
+ mtex2MML_free_string(s1);
1106
+ mtex2MML_free_string(s2);
1107
+ mtex2MML_free_string($3);
1108
+ mtex2MML_free_string($6);
1109
+ mtex2MML_free_string($9);
1110
+ };
1111
+
1112
+ statusline: STATLINE TEXTSTRING closedTerm {
1113
+ char * s1 = mtex2MML_copy3("<maction actiontype=\"statusline\">", $3, "<mtext>");
1114
+ $$ = mtex2MML_copy3(s1, $2, "</mtext></maction>");
1115
+ mtex2MML_free_string(s1);
1116
+ mtex2MML_free_string($2);
1117
+ mtex2MML_free_string($3);
1118
+ };
1119
+
1120
+ tooltip: TOOLTIP TEXTSTRING closedTerm {
1121
+ char * s1 = mtex2MML_copy3("<maction actiontype=\"tooltip\">", $3, "<mtext>");
1122
+ $$ = mtex2MML_copy3(s1, $2, "</mtext></maction>");
1123
+ mtex2MML_free_string(s1);
1124
+ mtex2MML_free_string($2);
1125
+ mtex2MML_free_string($3);
1126
+ };
1127
+
1128
+ toggle: TOGGLE closedTerm closedTerm {
1129
+ char * s1 = mtex2MML_copy3("<maction actiontype=\"toggle\" selection=\"2\">", $2, " ");
1130
+ $$ = mtex2MML_copy3(s1, $3, "</maction>");
1131
+ mtex2MML_free_string(s1);
1132
+ mtex2MML_free_string($2);
1133
+ mtex2MML_free_string($3);
1134
+ }
1135
+ | TOGGLESTART compoundTermList TOGGLEEND {
1136
+ $$ = mtex2MML_copy3("<maction actiontype=\"toggle\">", $2, "</maction>");
1137
+ mtex2MML_free_string($2);
1138
+ };
1139
+
1140
+ fghighlight: FGHIGHLIGHT ATTRLIST closedTerm {
1141
+ char * s1 = mtex2MML_copy3("<maction actiontype=\"highlight\" other='color=", $2, "'>");
1142
+ $$ = mtex2MML_copy3(s1, $3, "</maction>");
1143
+ mtex2MML_free_string(s1);
1144
+ mtex2MML_free_string($2);
1145
+ mtex2MML_free_string($3);
1146
+ };
1147
+
1148
+ bghighlight: BGHIGHLIGHT ATTRLIST closedTerm {
1149
+ char * s1 = mtex2MML_copy3("<maction actiontype=\"highlight\" other='background=", $2, "'>");
1150
+ $$ = mtex2MML_copy3(s1, $3, "</maction>");
1151
+ mtex2MML_free_string(s1);
1152
+ mtex2MML_free_string($2);
1153
+ mtex2MML_free_string($3);
1154
+ };
1155
+
1156
+ colorbox: COLORBOX ATTRLIST closedTerm {
1157
+ char * s1 = mtex2MML_copy3("<mpadded width=\"+10px\" height=\"+5px\" depth=\"+5px\" lspace=\"5px\" mathbackground=", $2, ">");
1158
+ $$ = mtex2MML_copy3(s1, $3, "</mpadded>");
1159
+ mtex2MML_free_string(s1);
1160
+ mtex2MML_free_string($2);
1161
+ mtex2MML_free_string($3);
1162
+ };
1163
+
1164
+ color: COLOR ATTRLIST compoundTermList {
1165
+ char * s1;
1166
+ struct css_colors *c = NULL;
1167
+
1168
+ HASH_FIND_STR( colors, $2, c );
1169
+
1170
+ if (HASH_COUNT(c) > 0)
1171
+ s1 = mtex2MML_copy3("<mstyle mathcolor=", c->color, ">");
1172
+ else
1173
+ s1 = mtex2MML_copy3("<mstyle mathcolor=", $2, ">");
1174
+
1175
+ $$ = mtex2MML_copy3(s1, $3, "</mstyle>");
1176
+ mtex2MML_free_string(s1);
1177
+ mtex2MML_free_string($2);
1178
+ mtex2MML_free_string($3);
1179
+ }
1180
+ | BGCOLOR ATTRLIST compoundTermList {
1181
+ char * s1 = mtex2MML_copy3("<mstyle mathbackground=", $2, ">");
1182
+ $$ = mtex2MML_copy3(s1, $3, "</mstyle>");
1183
+ mtex2MML_free_string(s1);
1184
+ mtex2MML_free_string($2);
1185
+ mtex2MML_free_string($3);
1186
+ }
1187
+ | BBOX ST PXSTRING END closedTerm {
1188
+ float padding = extract_number_from_pxstring($3);
1189
+ char *px = extract_string_from_pxstring($3);
1190
+ char *dbl_px = double_pixel(padding, px);
1191
+
1192
+ char *s1 = mtex2MML_copy3("<mpadded width=\"+", dbl_px, "\" height=\"+");
1193
+ char *s2 = mtex2MML_copy3(s1, $3, "\" depth=\"+");
1194
+ char *s3 = mtex2MML_copy3(s2, $3, "\" lspace=\"");
1195
+ char *s4 = mtex2MML_copy3(s3, $3, "\">");
1196
+ $$ = mtex2MML_copy3(s4, $5, "</mpadded>");
1197
+
1198
+ mtex2MML_free_string(px);
1199
+ mtex2MML_free_string(dbl_px);
1200
+ mtex2MML_free_string(s1);
1201
+ mtex2MML_free_string(s2);
1202
+ mtex2MML_free_string(s3);
1203
+ mtex2MML_free_string(s4);
1204
+ mtex2MML_free_string($3);
1205
+ mtex2MML_free_string($5);
1206
+ }
1207
+ | BBOX ST COLORSTRING END closedTerm {
1208
+ char *s1 = mtex2MML_copy3("<mstyle mathbackground=\"", $3, "\">");
1209
+ $$ = mtex2MML_copy3(s1, $5, "</mstyle>");
1210
+
1211
+ mtex2MML_free_string(s1);
1212
+ mtex2MML_free_string($3);
1213
+ mtex2MML_free_string($5);
1214
+ }
1215
+ | BBOX ST COLORSTRING PXSTRING END closedTerm {
1216
+ char *s1 = mtex2MML_copy3("<mstyle mathbackground=\"", $3, "\">");
1217
+
1218
+ float padding = extract_number_from_pxstring($4);
1219
+ char *px = extract_string_from_pxstring($4);
1220
+ char *dbl_px = double_pixel(padding, px);
1221
+
1222
+ char *s2 = mtex2MML_copy3(s1, "<mpadded width=\"+", dbl_px);
1223
+ char *s3 = mtex2MML_copy3(s2, "\" height=\"+", $4);
1224
+ char *s4 = mtex2MML_copy3(s3, "\" depth=\"+", $4);
1225
+ char *s5 = mtex2MML_copy3(s4, "\" lspace=\"", $4);
1226
+ char *s6 = mtex2MML_copy3(s5, "\">", $6);
1227
+ $$ = mtex2MML_copy2(s6, "</mpadded>");
1228
+
1229
+ mtex2MML_free_string(px);
1230
+ mtex2MML_free_string(dbl_px);
1231
+ mtex2MML_free_string(s1);
1232
+ mtex2MML_free_string(s2);
1233
+ mtex2MML_free_string(s3);
1234
+ mtex2MML_free_string(s4);
1235
+ mtex2MML_free_string(s5);
1236
+ mtex2MML_free_string(s6);
1237
+ mtex2MML_free_string($3);
1238
+ mtex2MML_free_string($4);
1239
+ mtex2MML_free_string($6);
1240
+ }
1241
+ | BBOX ST COLORSTRING STYLESTRING PXSTRING END closedTerm {
1242
+ char *s1 = mtex2MML_copy3("<mstyle mathbackground=\"", $3, "\" style=\"");
1243
+ char *s2 = mtex2MML_copy3(s1, $4, "\">");
1244
+
1245
+ float padding = extract_number_from_pxstring($5);
1246
+ char *px = extract_string_from_pxstring($5);
1247
+ char *dbl_px = double_pixel(padding, px);
1248
+
1249
+ char *s3 = mtex2MML_copy3(s2, "<mpadded width=\"+", dbl_px);
1250
+ char *s4 = mtex2MML_copy3(s3, "\" height=\"+", $5);
1251
+ char *s5 = mtex2MML_copy3(s4, "\" depth=\"+", $5);
1252
+ char *s6 = mtex2MML_copy3(s5, "\" lspace=\"", $5);
1253
+ char *s7 = mtex2MML_copy3(s6, "\">", $7);
1254
+ $$ = mtex2MML_copy2(s7, "</mpadded>");
1255
+
1256
+ mtex2MML_free_string(px);
1257
+ mtex2MML_free_string(dbl_px);
1258
+ mtex2MML_free_string(s1);
1259
+ mtex2MML_free_string(s2);
1260
+ mtex2MML_free_string(s3);
1261
+ mtex2MML_free_string(s4);
1262
+ mtex2MML_free_string(s5);
1263
+ mtex2MML_free_string(s6);
1264
+ mtex2MML_free_string(s7);
1265
+ mtex2MML_free_string($3);
1266
+ mtex2MML_free_string($4);
1267
+ mtex2MML_free_string($5);
1268
+ mtex2MML_free_string($7);
1269
+ };
1270
+
1271
+ mathrlap: RLAP closedTerm {
1272
+ $$ = mtex2MML_copy3("<mpadded width=\"0\">", $2, "</mpadded>");
1273
+ mtex2MML_free_string($2);
1274
+ };
1275
+
1276
+ mathllap: LLAP closedTerm {
1277
+ $$ = mtex2MML_copy3("<mpadded width=\"0\" lspace=\"-100%width\">", $2, "</mpadded>");
1278
+ mtex2MML_free_string($2);
1279
+ };
1280
+
1281
+ mathclap: CLAP closedTerm {
1282
+ $$ = mtex2MML_copy3("<mpadded width=\"0\" lspace=\"-50%width\">", $2, "</mpadded>");
1283
+ mtex2MML_free_string($2);
1284
+ };
1285
+
1286
+ textstring: TEXTBOX TEXTSTRING {
1287
+ $$ = mtex2MML_copy3("<mtext>", $2, "</mtext>");
1288
+ mtex2MML_free_string($2);
1289
+ };
1290
+
1291
+ verbstring: VERBBOX VERBSTRING {
1292
+ $$ = mtex2MML_copy3("<mstyle mathvariant=\"monospace\"><mtext>", $2, "</mtext></mstyle>");
1293
+ mtex2MML_free_string($2);
1294
+ };
1295
+
1296
+ displaystyle: DISPLAY MROWOPEN texover MROWCLOSE {
1297
+ $$ = mtex2MML_copy3("<mstyle displaystyle=\"true\" scriptlevel=\"0\"><mrow>", $3, "</mrow></mstyle>");
1298
+ mtex2MML_free_string($3);
1299
+ }
1300
+ | DISPLAY compoundTermList {
1301
+ $$ = mtex2MML_copy3("<mstyle displaystyle=\"true\" scriptlevel=\"0\"><mrow>", $2, "</mrow></mstyle>");
1302
+ mtex2MML_free_string($2);
1303
+ };
1304
+
1305
+ textstyle: TEXTSTY compoundTermList {
1306
+ $$ = mtex2MML_copy3("<mstyle displaystyle=\"false\" scriptlevel=\"0\">", $2, "</mstyle>");
1307
+ mtex2MML_free_string($2);
1308
+ };
1309
+
1310
+ textsize: TEXTSIZE compoundTermList {
1311
+ $$ = mtex2MML_copy3("<mstyle scriptlevel=\"0\">", $2, "</mstyle>");
1312
+ mtex2MML_free_string($2);
1313
+ };
1314
+
1315
+ scriptstyle: SCSTY compoundTermList {
1316
+ $$ = mtex2MML_copy3("<mstyle displaystyle=\"false\" scriptlevel=\"1\">", $2, "</mstyle>");
1317
+ mtex2MML_free_string($2);
1318
+ };
1319
+
1320
+ scriptsize: SCSIZE compoundTermList {
1321
+ $$ = mtex2MML_copy3("<mstyle mathsize=\"0.7em\">", $2, "</mstyle>");
1322
+ mtex2MML_free_string($2);
1323
+ };
1324
+
1325
+ scriptscriptsize: SCSCSIZE compoundTermList {
1326
+ $$ = mtex2MML_copy3("<mstyle displaystyle=\"false\" scriptlevel=\"2\">", $2, "</mstyle>");
1327
+ mtex2MML_free_string($2);
1328
+ };
1329
+
1330
+ oldstyle: OLDSTYLE compoundTermList {
1331
+ $$ = mtex2MML_copy3("<mi mathvariant=\"normal\">", $2, "</mi>");
1332
+ mtex2MML_free_string($2);
1333
+ };
1334
+
1335
+ tiny: TINY compoundTermList {
1336
+ $$ = mtex2MML_copy3("<mstyle mathsize=\"0.5em\">", $2, "</mstyle>");
1337
+ mtex2MML_free_string($2);
1338
+ };
1339
+
1340
+ ttiny: TTINY compoundTermList {
1341
+ $$ = mtex2MML_copy3("<mstyle mathsize=\"0.6em\">", $2, "</mstyle>");
1342
+ mtex2MML_free_string($2);
1343
+ };
1344
+
1345
+ small: SMALL compoundTermList {
1346
+ $$ = mtex2MML_copy3("<mstyle mathsize=\"0.85em\">", $2, "</mstyle>");
1347
+ mtex2MML_free_string($2);
1348
+ };
1349
+
1350
+ normalsize: NORMALSIZE compoundTermList {
1351
+ $$ = mtex2MML_copy3("<mstyle mathsize=\"1em\">", $2, "</mstyle>");
1352
+ mtex2MML_free_string($2);
1353
+ };
1354
+
1355
+ large: LARGE compoundTermList {
1356
+ $$ = mtex2MML_copy3("<mstyle mathsize=\"1.2em\">", $2, "</mstyle>");
1357
+ mtex2MML_free_string($2);
1358
+ };
1359
+
1360
+ llarge: LLARGE compoundTermList {
1361
+ $$ = mtex2MML_copy3("<mstyle mathsize=\"1.44em\">", $2, "</mstyle>");
1362
+ mtex2MML_free_string($2);
1363
+ };
1364
+
1365
+ lllarge: LLLARGE compoundTermList {
1366
+ $$ = mtex2MML_copy3("<mstyle mathsize=\"1.73em\">", $2, "</mstyle>");
1367
+ mtex2MML_free_string($2);
1368
+ };
1369
+
1370
+ huge: HUGE compoundTermList {
1371
+ $$ = mtex2MML_copy3("<mstyle mathsize=\"2.07em\">", $2, "</mstyle>");
1372
+ mtex2MML_free_string($2);
1373
+ };
1374
+
1375
+ hhuge: HHUGE compoundTermList {
1376
+ $$ = mtex2MML_copy3("<mstyle mathsize=\"2.49em\">", $2, "</mstyle>");
1377
+ mtex2MML_free_string($2);
1378
+ };
1379
+
1380
+ lower: LOWER MROWOPEN PXSTRING MROWCLOSE closedTerm {
1381
+ char * s1 = mtex2MML_copy3("<mpadded height=\"-", $3, "\" depth=\"+");
1382
+ char * s2 = mtex2MML_copy3(s1, $3, "\" voffset=\"-");
1383
+ char * s3 = mtex2MML_copy3(s2, $3, "\">");
1384
+ $$ = mtex2MML_copy3(s3, $5, "</mpadded>");
1385
+ mtex2MML_free_string(s1);
1386
+ mtex2MML_free_string(s2);
1387
+ mtex2MML_free_string(s3);
1388
+ mtex2MML_free_string($3);
1389
+ mtex2MML_free_string($5);
1390
+ }
1391
+ | LOWER PXSTRING closedTerm {
1392
+ char * s1 = mtex2MML_copy3("<mpadded height=\"-", $2, "\" depth=\"+");
1393
+ char * s2 = mtex2MML_copy3(s1, $2, "\" voffset=\"-");
1394
+ char * s3 = mtex2MML_copy3(s2, $2, "\">");
1395
+ $$ = mtex2MML_copy3(s3, $3, "</mpadded>");
1396
+ mtex2MML_free_string(s1);
1397
+ mtex2MML_free_string(s2);
1398
+ mtex2MML_free_string(s3);
1399
+ mtex2MML_free_string($2);
1400
+ mtex2MML_free_string($3);
1401
+ };
1402
+
1403
+ moveleft: MOVELEFT MROWOPEN PXSTRING MROWCLOSE closedTerm {
1404
+ char * s1 = mtex2MML_copy3("<mspace width=\"-", $3, "\"/>");
1405
+ char * s2 = mtex2MML_copy3(s1, $5, "<mspace width=\"");
1406
+ $$ = mtex2MML_copy3(s2, $3, "\"/>");
1407
+
1408
+ mtex2MML_free_string(s1);
1409
+ mtex2MML_free_string(s2);
1410
+ mtex2MML_free_string($3);
1411
+ mtex2MML_free_string($5);
1412
+ }
1413
+ | MOVELEFT PXSTRING closedTerm {
1414
+ char * s1 = mtex2MML_copy3("<mspace width=\"-", $2, "\"/>");
1415
+ char * s2 = mtex2MML_copy3(s1, $3, "<mspace width=\"");
1416
+ $$ = mtex2MML_copy3(s2, $2, "\"/>");
1417
+
1418
+ mtex2MML_free_string(s1);
1419
+ mtex2MML_free_string(s2);
1420
+ mtex2MML_free_string($2);
1421
+ mtex2MML_free_string($3);
1422
+ };
1423
+
1424
+ moveright: MOVERIGHT MROWOPEN PXSTRING MROWCLOSE closedTerm {
1425
+ char * s1 = mtex2MML_copy3("<mspace width=\"", $3, "\"/>");
1426
+ char * s2 = mtex2MML_copy3(s1, $5, "<mspace width=\"-");
1427
+ $$ = mtex2MML_copy3(s2, $3, "\"/>");
1428
+
1429
+ mtex2MML_free_string(s1);
1430
+ mtex2MML_free_string(s2);
1431
+ mtex2MML_free_string($3);
1432
+ mtex2MML_free_string($5);
1433
+ }
1434
+ | MOVERIGHT PXSTRING closedTerm {
1435
+ char * s1 = mtex2MML_copy3("<mspace width=\"", $2, "\"/>");
1436
+ char * s2 = mtex2MML_copy3(s1, $3, "<mspace width=\"-");
1437
+ $$ = mtex2MML_copy3(s2, $2, "\"/>");
1438
+
1439
+ mtex2MML_free_string(s1);
1440
+ mtex2MML_free_string(s2);
1441
+ mtex2MML_free_string($2);
1442
+ mtex2MML_free_string($3);
1443
+ };
1444
+
1445
+ raise: RAISE MROWOPEN PXSTRING MROWCLOSE closedTerm {
1446
+ char * s1 = mtex2MML_copy3("<mpadded height=\"+", $3, "\" depth=\"-");
1447
+ char * s2 = mtex2MML_copy3(s1, $3, "\" voffset=\"+");
1448
+ char * s3 = mtex2MML_copy3(s2, $3, "\">");
1449
+ $$ = mtex2MML_copy3(s3, $5, "</mpadded>");
1450
+ mtex2MML_free_string(s1);
1451
+ mtex2MML_free_string(s2);
1452
+ mtex2MML_free_string(s3);
1453
+ mtex2MML_free_string($3);
1454
+ mtex2MML_free_string($5);
1455
+ }
1456
+ | RAISE PXSTRING closedTerm {
1457
+ char * s1 = mtex2MML_copy3("<mpadded height=\"+", $2, "\" depth=\"-");
1458
+ char * s2 = mtex2MML_copy3(s1, $2, "\" voffset=\"+");
1459
+ char * s3 = mtex2MML_copy3(s2, $2, "\">");
1460
+ $$ = mtex2MML_copy3(s3, $3, "</mpadded>");
1461
+ mtex2MML_free_string(s1);
1462
+ mtex2MML_free_string(s2);
1463
+ mtex2MML_free_string(s3);
1464
+ mtex2MML_free_string($2);
1465
+ mtex2MML_free_string($3);
1466
+ };
1467
+
1468
+ italics: ITALICS closedTerm {
1469
+ $$ = mtex2MML_copy3("<mstyle mathvariant=\"italic\">", $2, "</mstyle>");
1470
+ mtex2MML_free_string($2);
1471
+ };
1472
+
1473
+ sans: SANS closedTerm {
1474
+ $$ = mtex2MML_copy3("<mstyle mathvariant=\"sans-serif\">", $2, "</mstyle>");
1475
+ mtex2MML_free_string($2);
1476
+ };
1477
+
1478
+ mono: TT closedTerm {
1479
+ $$ = mtex2MML_copy3("<mstyle mathvariant=\"monospace\">", $2, "</mstyle>");
1480
+ mtex2MML_free_string($2);
1481
+ };
1482
+
1483
+ not: NOT closedTerm {
1484
+ $$ = mtex2MML_copy3("<mi>", $2, "&#x0338;</mi>");
1485
+ mtex2MML_free_string($2);
1486
+ };
1487
+
1488
+ slashed: SLASHED closedTerm {
1489
+ $$ = mtex2MML_copy3("<menclose notation=\"updiagonalstrike\">", $2, "</menclose>");
1490
+ mtex2MML_free_string($2);
1491
+ };
1492
+
1493
+ bcanceled: BCANCELED closedTerm {
1494
+ $$ = mtex2MML_copy3("<menclose notation=\"downdiagonalstrike\">", $2, "</menclose>");
1495
+ mtex2MML_free_string($2);
1496
+ };
1497
+
1498
+ xcanceled: XCANCELED closedTerm {
1499
+ $$ = mtex2MML_copy3("<menclose notation=\"updiagonalstrike downdiagonalstrike\">", $2, "</menclose>");
1500
+ mtex2MML_free_string($2);
1501
+ };
1502
+
1503
+ canceledto: CANCELEDTO closedTerm closedTerm {
1504
+ char * s1 = mtex2MML_copy3("<msup><menclose notation=\"updiagonalstrike updiagonalarrow\"><mn>", $3, "</mn></menclose><mpadded height=\"+.1em\" depth=\"-.1em\" voffset=\".1em\"><mn>");
1505
+ $$ = mtex2MML_copy3(s1, $2, "</mn></mpadded></msup>");
1506
+
1507
+ mtex2MML_free_string($2);
1508
+ mtex2MML_free_string($3);
1509
+ mtex2MML_free_string(s1);
1510
+ };
1511
+
1512
+ mathopen: MATHOPEN closedTerm {
1513
+ $$ = mtex2MML_copy3("<mrow>", $2, "</mrow>");
1514
+
1515
+ mtex2MML_free_string($2);
1516
+ };
1517
+
1518
+ mathclose: MATHCLOSE closedTerm {
1519
+ $$ = mtex2MML_copy3("<mrow>", $2, "</mrow>");
1520
+
1521
+ mtex2MML_free_string($2);
1522
+ };
1523
+
1524
+ mathord: MATHORD closedTerm {
1525
+ $$ = mtex2MML_copy3("<mrow>", $2, "</mrow>");
1526
+
1527
+ mtex2MML_free_string($2);
1528
+ };
1529
+
1530
+ mathpunct: MATHPUNCT closedTerm {
1531
+ $$ = mtex2MML_copy3("<mrow>", $2, "<mspace width=\"0.3em\"/></mrow>");
1532
+
1533
+ mtex2MML_free_string($2);
1534
+ };
1535
+
1536
+ enclose: ENCLOSE ST ENCLOSENOTATION ST ENCLOSETEXT ST {
1537
+ char * notation = str_replace($3, ",", " ");
1538
+ char * s1 = mtex2MML_copy3("<menclose notation=\"", notation, "\"><mi>");
1539
+ $$ = mtex2MML_copy3(s1, $5, "</mi></menclose>");
1540
+ mtex2MML_free_string(notation);
1541
+ mtex2MML_free_string(s1);
1542
+ mtex2MML_free_string($3);
1543
+ mtex2MML_free_string($5);
1544
+ }
1545
+ | ENCLOSE ST ENCLOSENOTATION ST ENCLOSEATTR ST ENCLOSETEXT ST {
1546
+ char * notation = str_replace($3, ",", " ");
1547
+ char * attr = str_replace($5, ",", " ");
1548
+ if (strstr(attr, "arrow=1") != NULL) {
1549
+ mtex2MML_free_string(attr);
1550
+ attr = str_replace($5, "arrow=1", "");
1551
+
1552
+ char *t = mtex2MML_copy_string(notation);
1553
+ mtex2MML_free_string(notation);
1554
+ notation = mtex2MML_copy2(t, " updiagonalarrow");
1555
+ mtex2MML_free_string(t);
1556
+ }
1557
+ char * s1 = mtex2MML_copy3("<menclose notation=\"", notation, "\" ");
1558
+ char * s2 = mtex2MML_copy3(s1, attr, "><mi>");
1559
+ $$ = mtex2MML_copy3(s2, $7, "</mi></menclose>");
1560
+ mtex2MML_free_string(notation);
1561
+ mtex2MML_free_string(attr);
1562
+ mtex2MML_free_string(s1);
1563
+ mtex2MML_free_string(s2);
1564
+ mtex2MML_free_string($3);
1565
+ mtex2MML_free_string($5);
1566
+ mtex2MML_free_string($7);
1567
+ };
1568
+
1569
+ vcenter: VCENTER compoundTerm {
1570
+ $$ = mtex2MML_copy3("<mrow>", $2, "</mrow>");
1571
+ mtex2MML_free_string($2);
1572
+ };
1573
+
1574
+ boxed: BOXED closedTerm {
1575
+ $$ = mtex2MML_copy3("<menclose notation=\"box\">", $2, "</menclose>");
1576
+ mtex2MML_free_string($2);
1577
+ };
1578
+
1579
+ fbox: FBOX closedTerm {
1580
+ $$ = mtex2MML_copy3("<menclose notation=\"box\"><mtext>", $2, "</mtext></menclose>");
1581
+ mtex2MML_free_string($2);
1582
+ };
1583
+
1584
+ hbox: HBOX closedTerm {
1585
+ $$ = mtex2MML_copy3("<mtext>", $2, "</mtext>");
1586
+ mtex2MML_free_string($2);
1587
+ };
1588
+
1589
+ mbox: MBOX closedTerm {
1590
+ $$ = mtex2MML_copy3("<mtext>", $2, "</mtext>");
1591
+ mtex2MML_free_string($2);
1592
+ };
1593
+
1594
+ bold: BOLD closedTerm {
1595
+ $$ = mtex2MML_copy3("<mstyle mathvariant=\"bold\">", $2, "</mstyle>");
1596
+ mtex2MML_free_string($2);
1597
+ };
1598
+
1599
+ roman: RM ST rmchars END {
1600
+ $$ = mtex2MML_copy3("<mi mathvariant=\"normal\">", $3, "</mi>");
1601
+ mtex2MML_free_string($3);
1602
+ }
1603
+ | RM rmchars {
1604
+ $$ = mtex2MML_copy3("<mi mathvariant=\"normal\">", $2, "</mi>");
1605
+ mtex2MML_free_string($2);
1606
+ };
1607
+
1608
+ rmchars: RMCHAR {
1609
+ $$ = mtex2MML_copy_string($1);
1610
+ mtex2MML_free_string($1);
1611
+ }
1612
+ | rmchars RMCHAR {
1613
+ $$ = mtex2MML_copy2($1, $2);
1614
+ mtex2MML_free_string($1);
1615
+ mtex2MML_free_string($2);
1616
+ };
1617
+
1618
+ script: SCR ST scrchars END {
1619
+ $$ = mtex2MML_copy3("<mi mathvariant=\"script\">", $3, "</mi>");
1620
+ mtex2MML_free_string($3);
1621
+ }
1622
+ | SCR scrchars {
1623
+ $$ = mtex2MML_copy3("<mi mathvariant=\"script\">", $2, "</mi>");
1624
+ mtex2MML_free_string($2);
1625
+ };
1626
+
1627
+ scrchars: SCRCHAR {
1628
+ $$ = mtex2MML_copy_string($1);
1629
+ mtex2MML_free_string($1);
1630
+ }
1631
+ | scrchars SCRCHAR {
1632
+ $$ = mtex2MML_copy2($1, $2);
1633
+ mtex2MML_free_string($1);
1634
+ mtex2MML_free_string($2);
1635
+ };
1636
+
1637
+ pmb: PMB ST pmbchars END {
1638
+ char * s1 = mtex2MML_copy3("<mpadded width=\"0\"><mi>", $3, "</mi></mpadded>");
1639
+ char * s2 = mtex2MML_copy3(s1, "<mspace width=\"1px\"></mspace><mrow><mi>", $3);
1640
+ $$ = mtex2MML_copy2(s2, "</mi></mrow>");
1641
+ mtex2MML_free_string($3);
1642
+ mtex2MML_free_string(s1);
1643
+ mtex2MML_free_string(s2);
1644
+ }
1645
+ | PMB pmbchars {
1646
+ char * s1 = mtex2MML_copy3("<mpadded width=\"0\"><mi>", $2, "</mi></mpadded>");
1647
+ char * s2 = mtex2MML_copy3(s1, "<mspace width=\"1px\"></mspace><mrow><mi>", $2);
1648
+ $$ = mtex2MML_copy2(s2, "</mi></mrow>");
1649
+ mtex2MML_free_string($2);
1650
+ mtex2MML_free_string(s1);
1651
+ mtex2MML_free_string(s2);
1652
+ };
1653
+
1654
+ pmbchars: PMBCHAR {
1655
+ $$ = mtex2MML_copy_string($1);
1656
+ mtex2MML_free_string($1);
1657
+ }
1658
+ | pmbchars PMBCHAR {
1659
+ $$ = mtex2MML_copy2($1, $2);
1660
+ mtex2MML_free_string($1);
1661
+ mtex2MML_free_string($2);
1662
+ };
1663
+
1664
+ bbold: BB ST bbchars END {
1665
+ $$ = mtex2MML_copy3("<mi>", $3, "</mi>");
1666
+ mtex2MML_free_string($3);
1667
+ }
1668
+ | BB bbchars {
1669
+ $$ = mtex2MML_copy3("<mi>", $2, "</mi>");
1670
+ mtex2MML_free_string($2);
1671
+ };
1672
+
1673
+ bbchars: bbchar {
1674
+ $$ = mtex2MML_copy_string($1);
1675
+ mtex2MML_free_string($1);
1676
+ }
1677
+ | bbchars bbchar {
1678
+ $$ = mtex2MML_copy2($1, $2);
1679
+ mtex2MML_free_string($1);
1680
+ mtex2MML_free_string($2);
1681
+ };
1682
+
1683
+ bbchar: BBLOWERCHAR {
1684
+ $$ = mtex2MML_copy3("&", $1, "opf;");
1685
+ mtex2MML_free_string($1);
1686
+ }
1687
+ | BBUPPERCHAR {
1688
+ $$ = mtex2MML_copy3("&", $1, "opf;");
1689
+ mtex2MML_free_string($1);
1690
+ }
1691
+ | BBDIGIT {
1692
+ /* Blackboard digits 0-9 correspond to Unicode characters 0x1D7D8-0x1D7E1 */
1693
+ char * end = $1 + 1;
1694
+ int code = 0x1D7D8 + strtoul($1, &end, 10);
1695
+ $$ = mtex2MML_character_reference(code);
1696
+ mtex2MML_free_string($1);
1697
+ };
1698
+
1699
+ frak: FRAK ST frakletters END {
1700
+ $$ = mtex2MML_copy3("<mi>", $3, "</mi>");
1701
+ mtex2MML_free_string($3);
1702
+ }
1703
+ | FRAK frakletters {
1704
+ $$ = mtex2MML_copy3("<mi>", $2, "</mi>");
1705
+ mtex2MML_free_string($2);
1706
+ };
1707
+
1708
+ frakletters: frakletter {
1709
+ $$ = mtex2MML_copy_string($1);
1710
+ mtex2MML_free_string($1);
1711
+ }
1712
+ | frakletters frakletter {
1713
+ $$ = mtex2MML_copy2($1, $2);
1714
+ mtex2MML_free_string($1);
1715
+ mtex2MML_free_string($2);
1716
+ };
1717
+
1718
+ frakletter: FRAKCHAR {
1719
+ $$ = mtex2MML_copy3("&", $1, "fr;");
1720
+ mtex2MML_free_string($1);
1721
+ };
1722
+
1723
+ cal: CAL ST calletters END {
1724
+ $$ = mtex2MML_copy3("<mi>", $3, "</mi>");
1725
+ mtex2MML_free_string($3);
1726
+ }
1727
+ | CAL calletters {
1728
+ $$ = mtex2MML_copy3("<mi>", $2, "</mi>");
1729
+ mtex2MML_free_string($2);
1730
+ };
1731
+
1732
+ calletters: calletter {
1733
+ $$ = mtex2MML_copy_string($1);
1734
+ mtex2MML_free_string($1);
1735
+ }
1736
+ | calletters calletter {
1737
+ $$ = mtex2MML_copy2($1, $2);
1738
+ mtex2MML_free_string($1);
1739
+ mtex2MML_free_string($2);
1740
+ };
1741
+
1742
+ calletter: CALCHAR {
1743
+ $$ = mtex2MML_copy3("&", $1, "scr;");
1744
+ mtex2MML_free_string($1);
1745
+ };
1746
+
1747
+ thinspace: THINSPACE {
1748
+ $$ = mtex2MML_copy_string("<mspace width=\"thinmathspace\"/>");
1749
+ };
1750
+
1751
+ medspace: MEDSPACE {
1752
+ $$ = mtex2MML_copy_string("<mspace width=\"mediummathspace\"/>");
1753
+ };
1754
+
1755
+ thickspace: THICKSPACE {
1756
+ $$ = mtex2MML_copy_string("<mspace width=\"thickmathspace\"/>");
1757
+ };
1758
+
1759
+ enspace: ENSPACE {
1760
+ $$ = mtex2MML_copy_string("<mspace width=\".5em\"/>");
1761
+ };
1762
+
1763
+ hspace: HSPACE MROWOPEN PXSTRING MROWCLOSE {
1764
+ $$ = mtex2MML_copy3("<mspace width=\"", $3, "\"/>");
1765
+ mtex2MML_free_string($3);
1766
+ }
1767
+ | HSPACE PXSTRING {
1768
+ $$ = mtex2MML_copy3("<mspace width=\"", $2, "\"/>");
1769
+ mtex2MML_free_string($2);
1770
+ };
1771
+
1772
+ spacecube: SPACECUBE ST PXSTRING ST ST PXSTRING ST ST PXSTRING ST {
1773
+ char * s1 = mtex2MML_copy3("<mspace width=\"", $3, "\" height=\"");
1774
+ char * s2 = mtex2MML_copy3(s1, $6, "\" depth=\"");
1775
+ $$ = mtex2MML_copy3(s2, $9, "\"/>");
1776
+ mtex2MML_free_string(s1);
1777
+ mtex2MML_free_string(s2);
1778
+ mtex2MML_free_string($3);
1779
+ mtex2MML_free_string($6);
1780
+ mtex2MML_free_string($9);
1781
+ };
1782
+
1783
+ quad: QUAD {
1784
+ $$ = mtex2MML_copy_string("<mspace width=\"1em\"/>");
1785
+ };
1786
+
1787
+ qquad: QQUAD {
1788
+ $$ = mtex2MML_copy_string("<mspace width=\"2em\"/>");
1789
+ };
1790
+
1791
+ negspace: NEGSPACE {
1792
+ $$ = mtex2MML_copy_string("<mspace width=\"negativethinmathspace\"/>");
1793
+ };
1794
+
1795
+ negmedspace: NEGMEDSPACE {
1796
+ $$ = mtex2MML_copy_string("<mspace width=\"negativemediummathspace\"/>");
1797
+ };
1798
+
1799
+ negthickspace: NEGTHICKSPACE {
1800
+ $$ = mtex2MML_copy_string("<mspace width=\"negativethickmathspace\"/>");
1801
+ };
1802
+
1803
+ strut: STRUT {
1804
+ $$ = mtex2MML_copy_string("<mpadded width=\"0\" height=\"8.6pt\" depth=\"3pt\"><mrow /></mpadded>");
1805
+ };
1806
+
1807
+ mathstrut: MATHSTRUT {
1808
+ $$ = mtex2MML_copy_string("<mpadded width=\"0\"><mphantom><mo stretchy=\"false\">(</mo></mphantom></mpadded>");
1809
+ };
1810
+
1811
+ smash: SMASH closedTerm {
1812
+ $$ = mtex2MML_copy3("<mpadded height=\"0\" depth=\"0\">", $2, "</mpadded>");
1813
+ mtex2MML_free_string($2);
1814
+ };
1815
+
1816
+ phantom: PHANTOM closedTerm {
1817
+ $$ = mtex2MML_copy3("<mphantom>", $2, "</mphantom>");
1818
+ mtex2MML_free_string($2);
1819
+ };
1820
+
1821
+ hphantom: HPHANTOM closedTerm {
1822
+ $$ = mtex2MML_copy3("<mpadded height=\"0\" depth=\"0\"><mphantom>", $2, "</mphantom></mpadded>");
1823
+ mtex2MML_free_string($2);
1824
+ };
1825
+
1826
+ vphantom: VPHANTOM closedTerm {
1827
+ $$ = mtex2MML_copy3("<mpadded width=\"0\"><mphantom>", $2, "</mphantom></mpadded>");
1828
+ mtex2MML_free_string($2);
1829
+ };
1830
+
1831
+ tex: TEXSYMBOL {
1832
+ $$ = mtex2MML_copy_string("<mi>T</mi><mspace width=\"-.14em\"></mspace><mpadded height=\"-.5ex\" depth=\"+.5ex\" voffset=\"-.5ex\"><mrow><mi>E</mi></mrow></mpadded><mspace width=\"-.115em\"></mspace><mi>X</mi>");
1833
+ };
1834
+
1835
+ latex: LATEXSYMBOL {
1836
+ $$ = mtex2MML_copy_string("<mi>L</mi><mspace width=\"-.325em\"></mspace><mpadded height=\"+.21em\" depth=\"-.21em\" voffset=\"+.21em\"><mrow><mstyle scriptlevel=\"1\" displaystyle=\"false\"><mrow><mi>A</mi></mrow></mstyle></mrow></mpadded><mspace width=\"-.17em\"></mspace><mi>T</mi><mspace width=\"-.14em\"></mspace><mpadded height=\"-.5ex\" depth=\"+.5ex\" voffset=\"-.5ex\"><mrow><mi>E</mi></mrow></mpadded><mspace width=\"-.115em\"></mspace><mi>X</mi>");
1837
+ };
1838
+
1839
+ href: HREF TEXTSTRING closedTerm {
1840
+ char * s1 = mtex2MML_copy3("<mrow href=\"", $2, "\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\"");
1841
+ char * s2 = mtex2MML_copy3(s1, $2, "\">");
1842
+ $$ = mtex2MML_copy3(s2, $3, "</mrow>");
1843
+ mtex2MML_free_string(s1);
1844
+ mtex2MML_free_string(s2);
1845
+ mtex2MML_free_string($2);
1846
+ mtex2MML_free_string($3);
1847
+ };
1848
+
1849
+ tensor: TENSOR closedTerm MROWOPEN subsupList MROWCLOSE {
1850
+ char * s1 = mtex2MML_copy3("<mmultiscripts>", $2, $4);
1851
+ $$ = mtex2MML_copy2(s1, "</mmultiscripts>");
1852
+ mtex2MML_free_string(s1);
1853
+ mtex2MML_free_string($2);
1854
+ mtex2MML_free_string($4);
1855
+ }
1856
+ | TENSOR closedTerm subsupList {
1857
+ char * s1 = mtex2MML_copy3("<mmultiscripts>", $2, $3);
1858
+ $$ = mtex2MML_copy2(s1, "</mmultiscripts>");
1859
+ mtex2MML_free_string(s1);
1860
+ mtex2MML_free_string($2);
1861
+ mtex2MML_free_string($3);
1862
+ };
1863
+
1864
+ multi: MULTI MROWOPEN subsupList MROWCLOSE closedTerm MROWOPEN subsupList MROWCLOSE {
1865
+ char * s1 = mtex2MML_copy3("<mmultiscripts>", $5, $7);
1866
+ char * s2 = mtex2MML_copy3("<mprescripts/>", $3, "</mmultiscripts>");
1867
+ $$ = mtex2MML_copy2(s1, s2);
1868
+ mtex2MML_free_string(s1);
1869
+ mtex2MML_free_string(s2);
1870
+ mtex2MML_free_string($3);
1871
+ mtex2MML_free_string($5);
1872
+ mtex2MML_free_string($7);
1873
+ }
1874
+ | MULTI MROWOPEN subsupList MROWCLOSE closedTerm EMPTYMROW {
1875
+ char * s1 = mtex2MML_copy2("<mmultiscripts>", $5);
1876
+ char * s2 = mtex2MML_copy3("<mprescripts/>", $3, "</mmultiscripts>");
1877
+ $$ = mtex2MML_copy2(s1, s2);
1878
+ mtex2MML_free_string(s1);
1879
+ mtex2MML_free_string(s2);
1880
+ mtex2MML_free_string($3);
1881
+ mtex2MML_free_string($5);
1882
+ }
1883
+ | MULTI EMPTYMROW closedTerm MROWOPEN subsupList MROWCLOSE {
1884
+ char * s1 = mtex2MML_copy3("<mmultiscripts>", $3, $5);
1885
+ $$ = mtex2MML_copy2(s1, "</mmultiscripts>");
1886
+ mtex2MML_free_string(s1);
1887
+ mtex2MML_free_string($3);
1888
+ mtex2MML_free_string($5);
1889
+ };
1890
+
1891
+ subsupList: subsupTerm {
1892
+ $$ = mtex2MML_copy_string($1);
1893
+ mtex2MML_free_string($1);
1894
+ }
1895
+ | subsupList subsupTerm {
1896
+ $$ = mtex2MML_copy3($1, " ", $2);
1897
+ mtex2MML_free_string($1);
1898
+ mtex2MML_free_string($2);
1899
+ };
1900
+
1901
+ subsupTerm: SUB closedTerm SUP closedTerm {
1902
+ $$ = mtex2MML_copy3($2, " ", $4);
1903
+ mtex2MML_free_string($2);
1904
+ mtex2MML_free_string($4);
1905
+ }
1906
+ | SUB closedTerm {
1907
+ $$ = mtex2MML_copy2($2, " <none/>");
1908
+ mtex2MML_free_string($2);
1909
+ }
1910
+ | SUP closedTerm {
1911
+ $$ = mtex2MML_copy2("<none/> ", $2);
1912
+ mtex2MML_free_string($2);
1913
+ }
1914
+ | SUB SUP closedTerm {
1915
+ $$ = mtex2MML_copy2("<none/> ", $3);
1916
+ mtex2MML_free_string($3);
1917
+ };
1918
+
1919
+ mfrac: FRAC closedTerm closedTerm {
1920
+ char * s1 = mtex2MML_copy3("<mfrac>", $2, $3);
1921
+ $$ = mtex2MML_copy2(s1, "</mfrac>");
1922
+ mtex2MML_free_string(s1);
1923
+ mtex2MML_free_string($2);
1924
+ mtex2MML_free_string($3);
1925
+ }
1926
+ | TFRAC closedTerm closedTerm {
1927
+ char * s1 = mtex2MML_copy3("<mstyle displaystyle=\"false\"><mfrac>", $2, $3);
1928
+ $$ = mtex2MML_copy2(s1, "</mfrac></mstyle>");
1929
+ mtex2MML_free_string(s1);
1930
+ mtex2MML_free_string($2);
1931
+ mtex2MML_free_string($3);
1932
+ }
1933
+ | DFRAC closedTerm closedTerm {
1934
+ char * s1 = mtex2MML_copy3("<mstyle displaystyle=\"true\" scriptlevel=\"0\"><mfrac>", $2, $3);
1935
+ $$ = mtex2MML_copy2(s1, "</mfrac></mstyle>");
1936
+ mtex2MML_free_string(s1);
1937
+ mtex2MML_free_string($2);
1938
+ mtex2MML_free_string($3);
1939
+ }
1940
+ | CFRAC closedTerm closedTerm {
1941
+ char * s1 = mtex2MML_copy3("<mfrac><mrow><mpadded width=\"0\" height=\"8.6pt\" depth=\"3pt\"><mrow /></mpadded><mstyle displaystyle=\"false\" scriptlevel=\"0\"><mrow>", $2, "</mrow></mstyle></mrow><mrow><mpadded width=\"0\" height=\"8.6pt\" depth=\"3pt\"><mrow /></mpadded><mstyle displaystyle=\"false\" scriptlevel=\"0\"><mrow>");
1942
+ $$ = mtex2MML_copy3(s1, $3, "</mrow></mstyle></mrow></mfrac>");
1943
+
1944
+ mtex2MML_free_string(s1);
1945
+ mtex2MML_free_string($2);
1946
+ mtex2MML_free_string($3);
1947
+ }
1948
+ | GENFRAC MROWOPEN LEFTDELIM MROWCLOSE MROWOPEN RIGHTDELIM MROWCLOSE MROWOPEN PXSTRING MROWCLOSE compoundTermList compoundTermList compoundTermList {
1949
+ char *s1, *s2, *s3, *s4;
1950
+ int style = 0;
1951
+ sscanf ($11,"%d", &style);
1952
+
1953
+ switch (style) {
1954
+ case 0:
1955
+ s1 = mtex2MML_copy3("<mrow><mstyle displaystyle=\"true\" scriptlevel=\"0\"><mrow><mrow><mo maxsize=\"2.047em\" minsize=\"2.047em\">", $3, "</mo></mrow><mfrac linethickness=\"");
1956
+ s2 = mtex2MML_copy3(s1, $9, "\">");
1957
+ s3 = mtex2MML_copy3(s2, $12 , $13);
1958
+ s4 = mtex2MML_copy3(s3, "</mfrac><mrow>", "<mo maxsize=\"2.047em\" minsize=\"2.047em\">");
1959
+ break;
1960
+ case 1:
1961
+ s1 = mtex2MML_copy3("<mrow><mstyle displaystyle=\"false\" scriptlevel=\"0\"><mrow><mrow><mo maxsize=\"1.2em\" minsize=\"1.2em\">", $3, "</mo></mrow><mfrac linethickness=\"");
1962
+ s2 = mtex2MML_copy3(s1, $9, "\">");
1963
+ s3 = mtex2MML_copy3(s2, $12 , $13);
1964
+ s4 = mtex2MML_copy3(s3, "</mfrac><mrow>", "<mo maxsize=\"1.2em\" minsize=\"1.2em\">");
1965
+ break;
1966
+ case 2:
1967
+ s1 = mtex2MML_copy3("<mrow><mstyle displaystyle=\"false\" scriptlevel=\"1\"><mrow><mrow><mo maxsize=\"1.2em\" minsize=\"1.2em\">", $3, "</mo></mrow><mfrac linethickness=\"");
1968
+ s2 = mtex2MML_copy3(s1, $9, "\">");
1969
+ s3 = mtex2MML_copy3(s2, $12 , $13);
1970
+ s4 = mtex2MML_copy3(s3, "</mfrac><mrow>", "<mo maxsize=\"1.2em\" minsize=\"1.2em\">");
1971
+ break;
1972
+ case 3:
1973
+ s1 = mtex2MML_copy3("<mrow><mstyle displaystyle=\"false\" scriptlevel=\"2\"><mrow><mrow><mo maxsize=\"1.2em\" minsize=\"1.2em\">", $3, "</mo></mrow><mfrac linethickness=\"");
1974
+ s2 = mtex2MML_copy3(s1, $9, "\">");
1975
+ s3 = mtex2MML_copy3(s2, $12 , $13);
1976
+ s4 = mtex2MML_copy3(s3, "</mfrac><mrow>", "<mo maxsize=\"1.2em\" minsize=\"1.2em\">");
1977
+ break;
1978
+ }
1979
+
1980
+ $$ = mtex2MML_copy3(s4, $6, "</mo></mrow></mrow></mstyle></mrow>");
1981
+
1982
+ mtex2MML_free_string(s1);
1983
+ mtex2MML_free_string(s2);
1984
+ mtex2MML_free_string(s3);
1985
+ mtex2MML_free_string(s4);
1986
+ mtex2MML_free_string($3);
1987
+ mtex2MML_free_string($6);
1988
+ mtex2MML_free_string($9);
1989
+ mtex2MML_free_string($11);
1990
+ mtex2MML_free_string($12);
1991
+ mtex2MML_free_string($13);
1992
+ };
1993
+
1994
+ pod: POD closedTerm {
1995
+ $$ = mtex2MML_copy3( "<mrow><mo lspace=\"mediummathspace\">(</mo>", $2, "<mo rspace=\"mediummathspace\">)</mo></mrow>");
1996
+ mtex2MML_free_string($2);
1997
+ };
1998
+
1999
+ pmod: PMOD closedTerm {
2000
+ $$ = mtex2MML_copy3( "<mrow><mo lspace=\"mediummathspace\">(</mo><mo rspace=\"thinmathspace\">mod</mo>", $2, "<mo rspace=\"mediummathspace\">)</mo></mrow>");
2001
+ mtex2MML_free_string($2);
2002
+ };
2003
+
2004
+ bmod: BMOD closedTerm {
2005
+ $$ = mtex2MML_copy3( "<mrow><mo lspace=\"thickmathspace\" rspace=\"thickmathspace\">mod</mo>", $2, "</mrow>");
2006
+ mtex2MML_free_string($2);
2007
+ };
2008
+
2009
+ buildrel: BUILDREL closedTerm TEXOVER closedTerm {
2010
+ char *s1 = mtex2MML_copy3("<mrow><mover>", $4, $2);
2011
+ $$ = mtex2MML_copy2(s1, "</mover></mrow>");
2012
+
2013
+ mtex2MML_free_string(s1);
2014
+ mtex2MML_free_string($2);
2015
+ mtex2MML_free_string($4);
2016
+ };
2017
+
2018
+ texover: closedTerm TEXOVER closedTerm {
2019
+ char * s1 = mtex2MML_copy3("<mfrac>", $1, $3);
2020
+ $$ = mtex2MML_copy2(s1, "</mfrac>");
2021
+ mtex2MML_free_string(s1);
2022
+ mtex2MML_free_string($1);
2023
+ mtex2MML_free_string($3);
2024
+ }
2025
+ | left compoundTermList TEXOVER compoundTermList right {
2026
+ char * s1 = mtex2MML_copy3("<mrow>", $1, "<mfrac><mrow>");
2027
+ char * s2 = mtex2MML_copy3($2, "</mrow><mrow>", $4);
2028
+ char * s3 = mtex2MML_copy3("</mrow></mfrac>", $5, "</mrow>");
2029
+ $$ = mtex2MML_copy3(s1, s2, s3);
2030
+ mtex2MML_free_string(s1);
2031
+ mtex2MML_free_string(s2);
2032
+ mtex2MML_free_string(s3);
2033
+ mtex2MML_free_string($1);
2034
+ mtex2MML_free_string($2);
2035
+ mtex2MML_free_string($4);
2036
+ mtex2MML_free_string($5);
2037
+ };
2038
+
2039
+ texoverwithdelims: closedTerm TEXOVERWITHDELIMS LEFTDELIM RIGHTDELIM closedTerm {
2040
+ char * s1 = mtex2MML_copy3("<mo fence=\"true\" stretchy=\"true\">", $3, "</mo><mfrac>");
2041
+ char * s2 = mtex2MML_copy3(s1, $1, $5);
2042
+ char * s3 = mtex2MML_copy2(s2, "</mfrac><mo fence=\"true\" stretchy=\"true\">");
2043
+ $$ = mtex2MML_copy3(s3, $4, "</mo>");
2044
+ mtex2MML_free_string(s1);
2045
+ mtex2MML_free_string(s2);
2046
+ mtex2MML_free_string(s3);
2047
+ mtex2MML_free_string($1);
2048
+ mtex2MML_free_string($3);
2049
+ mtex2MML_free_string($4);
2050
+ mtex2MML_free_string($5);
2051
+ };
2052
+
2053
+ texatop: MROWOPEN compoundTermList TEXATOP compoundTermList MROWCLOSE {
2054
+ char * s1 = mtex2MML_copy3("<mfrac linethickness=\"0\"><mrow>", $2, "</mrow><mrow>");
2055
+ $$ = mtex2MML_copy3(s1, $4, "</mrow></mfrac>");
2056
+ mtex2MML_free_string(s1);
2057
+ mtex2MML_free_string($2);
2058
+ mtex2MML_free_string($4);
2059
+ }
2060
+ | closedTerm TEXATOP closedTerm {
2061
+ char * s1 = mtex2MML_copy3("<mfrac linethickness=\"0\">", $1, $3);
2062
+ $$ = mtex2MML_copy2(s1, "</mfrac>");
2063
+ mtex2MML_free_string(s1);
2064
+ mtex2MML_free_string($1);
2065
+ mtex2MML_free_string($3);
2066
+ };
2067
+
2068
+ texatopwithdelims: closedTerm TEXATOPWITHDELIMS LEFTDELIM RIGHTDELIM closedTerm {
2069
+ char * s1 = mtex2MML_copy3("<mo fence=\"true\" stretchy=\"true\">", $3, "</mo><mfrac linethickness=\"0\">");
2070
+ char * s2 = mtex2MML_copy3(s1, $1, $5);
2071
+ char * s3 = mtex2MML_copy2(s2, "</mfrac><mo fence=\"true\" stretchy=\"true\">");
2072
+ $$ = mtex2MML_copy3(s3, $4, "</mo>");
2073
+ mtex2MML_free_string(s1);
2074
+ mtex2MML_free_string(s2);
2075
+ mtex2MML_free_string(s3);
2076
+ mtex2MML_free_string($1);
2077
+ mtex2MML_free_string($3);
2078
+ mtex2MML_free_string($4);
2079
+ mtex2MML_free_string($5);
2080
+ };
2081
+
2082
+ texabove: closedTerm TEXABOVE MROWOPEN PXSTRING MROWCLOSE closedTerm {
2083
+ char * s1 = mtex2MML_copy3("<mfrac linethickness=\"", $4, "\">");
2084
+ char * s2 = mtex2MML_copy3(s1, $1, $6);
2085
+ $$ = mtex2MML_copy2(s2, "</mfrac>");
2086
+ mtex2MML_free_string(s1);
2087
+ mtex2MML_free_string(s2);
2088
+ mtex2MML_free_string($1);
2089
+ mtex2MML_free_string($4);
2090
+ mtex2MML_free_string($6);
2091
+ };
2092
+
2093
+ texabovewithdelims: closedTerm TEXABOVEWITHDELIMS LEFTDELIM RIGHTDELIM PXSTRING closedTerm {
2094
+ char * s1 = mtex2MML_copy3("<mo fence=\"true\" stretchy=\"true\">", $3, "</mo>");
2095
+ char * s2 = mtex2MML_copy3(s1, "<mfrac linethickness=\"", $5);
2096
+ char * s3 = mtex2MML_copy3(s2, "\">", $1);
2097
+ char * s4 = mtex2MML_copy3(s3, $6, "</mfrac><mo fence=\"true\" stretchy=\"true\">");
2098
+ $$ = mtex2MML_copy3(s4, $4, "</mo>");
2099
+ mtex2MML_free_string(s1);
2100
+ mtex2MML_free_string(s2);
2101
+ mtex2MML_free_string(s3);
2102
+ mtex2MML_free_string(s4);
2103
+ mtex2MML_free_string($1);
2104
+ mtex2MML_free_string($3);
2105
+ mtex2MML_free_string($4);
2106
+ mtex2MML_free_string($5);
2107
+ mtex2MML_free_string($6);
2108
+ };
2109
+
2110
+ binom: BINOM closedTerm closedTerm {
2111
+ char * s1 = mtex2MML_copy3("<mrow><mo maxsize=\"2.047em\" minsize=\"2.047em\">(</mo><mfrac linethickness=\"0\">", $2, $3);
2112
+ $$ = mtex2MML_copy2(s1, "</mfrac><mo maxsize=\"2.047em\" minsize=\"2.047em\">)</mo></mrow>");
2113
+ mtex2MML_free_string(s1);
2114
+ mtex2MML_free_string($2);
2115
+ mtex2MML_free_string($3);
2116
+ }
2117
+ | TBINOM closedTerm closedTerm {
2118
+ char * s1 = mtex2MML_copy3("<mrow><mo maxsize=\"2.047em\" minsize=\"2.047em\">(</mo><mstyle displaystyle=\"false\"><mfrac linethickness=\"0\">", $2, $3);
2119
+ $$ = mtex2MML_copy2(s1, "</mfrac></mstyle><mo maxsize=\"2.047em\" minsize=\"2.047em\">)</mo></mrow>");
2120
+ mtex2MML_free_string(s1);
2121
+ mtex2MML_free_string($2);
2122
+ mtex2MML_free_string($3);
2123
+ }
2124
+ | DBINOM closedTerm closedTerm {
2125
+ char * s1 = mtex2MML_copy3("<mstyle displaystyle=\"true\" scriptlevel=\"0\"><mrow><mo maxsize=\"2.047em\" minsize=\"2.047em\">(</mo><mfrac linethickness=\"0\">", $2, $3);
2126
+ $$ = mtex2MML_copy2(s1, "</mfrac><mo maxsize=\"2.047em\" minsize=\"2.047em\">)</mo></mrow></mstyle>");
2127
+ mtex2MML_free_string(s1);
2128
+ mtex2MML_free_string($2);
2129
+ mtex2MML_free_string($3);
2130
+ };
2131
+
2132
+ brace: closedTerm BRACE closedTerm {
2133
+ char * s1 = mtex2MML_copy3("<mrow><mo maxsize=\"2.047em\" minsize=\"2.047em\">{</mo><mfrac linethickness=\"0\">", $1, $3);
2134
+ $$ = mtex2MML_copy2(s1, "</mfrac><mo maxsize=\"2.047em\" minsize=\"2.047em\">}</mo></mrow>");
2135
+ mtex2MML_free_string(s1);
2136
+ mtex2MML_free_string($1);
2137
+ mtex2MML_free_string($3);
2138
+ };
2139
+
2140
+ brack: closedTerm BRACK closedTerm {
2141
+ char * s1 = mtex2MML_copy3("<mrow><mo maxsize=\"2.047em\" minsize=\"2.047em\">[</mo><mfrac linethickness=\"0\">", $1, $3);
2142
+ $$ = mtex2MML_copy2(s1, "</mfrac><mo maxsize=\"2.047em\" minsize=\"2.047em\">]</mo></mrow>");
2143
+ mtex2MML_free_string(s1);
2144
+ mtex2MML_free_string($1);
2145
+ mtex2MML_free_string($3);
2146
+ };
2147
+
2148
+ choose: closedTerm CHOOSE closedTerm {
2149
+ char * s1 = mtex2MML_copy3("<mrow><mrow><mo maxsize=\"2.047em\" minsize=\"2.047em\">(</mo></mrow><mfrac linethickness=\"0\">", $1, $3);
2150
+ $$ = mtex2MML_copy2(s1, "</mfrac><mrow><mo maxsize=\"2.047em\" minsize=\"2.047em\">)</mo></mrow></mrow>");
2151
+
2152
+ mtex2MML_free_string(s1);
2153
+ mtex2MML_free_string($1);
2154
+ mtex2MML_free_string($3);
2155
+ };
2156
+
2157
+ underleftarrow: UNDERLEFTARROW closedTerm {
2158
+ $$ = mtex2MML_copy3("<munder>", $2, "<mo>&larr;</mo></munder>");
2159
+ mtex2MML_free_string($2);
2160
+ };
2161
+
2162
+ underleftrightarrow: UNDERLEFTRIGHTARROW closedTerm {
2163
+ $$ = mtex2MML_copy3("<munder>", $2, "<mo>&harr;</mo></munder>");
2164
+ mtex2MML_free_string($2);
2165
+ };
2166
+
2167
+ underrightarrow: UNDERRIGHTARROW closedTerm {
2168
+ $$ = mtex2MML_copy3("<munder>", $2, "<mo>&rarr;</mo></munder>");
2169
+ mtex2MML_free_string($2);
2170
+ };
2171
+
2172
+ munderbrace: UNDERBRACE closedTerm {
2173
+ $$ = mtex2MML_copy3("<munder>", $2, "<mo>&UnderBrace;</mo></munder>");
2174
+ mtex2MML_free_string($2);
2175
+ }
2176
+ | UNDERBRACE closedTerm SUB closedTerm {
2177
+ char * s1 = mtex2MML_copy3("<munder><munder>", $2, "<mo>&UnderBrace;</mo></munder>");
2178
+ $$ = mtex2MML_copy3(s1, $4, "</munder>");
2179
+
2180
+ mtex2MML_free_string(s1);
2181
+ mtex2MML_free_string($2);
2182
+ mtex2MML_free_string($4);
2183
+ }
2184
+ | UNDERBRACE closedTerm LIMITS SUB closedTerm {
2185
+ char * s1 = mtex2MML_copy3("<munder><munder>", $2, "<mo>&UnderBrace;</mo></munder>");
2186
+ $$ = mtex2MML_copy3(s1, $5, "</munder>");
2187
+
2188
+ mtex2MML_free_string(s1);
2189
+ mtex2MML_free_string($2);
2190
+ mtex2MML_free_string($5);
2191
+ }
2192
+ | UNDERBRACE closedTerm NOLIMITS SUB closedTerm {
2193
+ char * s1 = mtex2MML_copy3("<msub><munder>", $2, "<mo>&UnderBrace;</mo></munder>");
2194
+ $$ = mtex2MML_copy3(s1, $5, "</msub>");
2195
+
2196
+ mtex2MML_free_string(s1);
2197
+ mtex2MML_free_string($2);
2198
+ mtex2MML_free_string($5);
2199
+ };
2200
+
2201
+ munderbracket: UNDERBRACKET closedTerm {
2202
+ $$ = mtex2MML_copy3("<munder>", $2, "<mo>&#9183;</mo></munder>");
2203
+ mtex2MML_free_string($2);
2204
+ };
2205
+
2206
+ munderline: UNDERLINE closedTerm {
2207
+ $$ = mtex2MML_copy3("<munder>", $2, "<mo>&#x00332;</mo></munder>");
2208
+ mtex2MML_free_string($2);
2209
+ };
2210
+
2211
+ moverbrace: OVERBRACE closedTerm {
2212
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo>&OverBrace;</mo></mover>");
2213
+ mtex2MML_free_string($2);
2214
+ };
2215
+
2216
+ moverbracket: OVERBRACKET closedTerm {
2217
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo>&#9183;</mo></mover>");
2218
+ mtex2MML_free_string($2);
2219
+ };
2220
+
2221
+ overleftarrow: OVERLEFTARROW closedTerm {
2222
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&larr;</mo></mover>");
2223
+ mtex2MML_free_string($2);
2224
+ };
2225
+
2226
+ overleftrightarrow: OVERLEFTRIGHTARROW closedTerm {
2227
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&harr;</mo></mover>");
2228
+ mtex2MML_free_string($2);
2229
+ };
2230
+
2231
+ overrightarrow: OVERRIGHTARROW closedTerm {
2232
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&rarr;</mo></mover>");
2233
+ mtex2MML_free_string($2);
2234
+ };
2235
+
2236
+ bar: BAR closedTerm {
2237
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x000AF;</mo></mover>");
2238
+ mtex2MML_free_string($2);
2239
+ }
2240
+ | WIDEBAR closedTerm {
2241
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo>&#x000AF;</mo></mover>");
2242
+ mtex2MML_free_string($2);
2243
+ };
2244
+
2245
+ vec: VEC closedTerm {
2246
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x2192;</mo></mover>");
2247
+ mtex2MML_free_string($2);
2248
+ }
2249
+ | WIDEVEC closedTerm {
2250
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo>&#x2192;</mo></mover>");
2251
+ mtex2MML_free_string($2);
2252
+ };
2253
+
2254
+ acute: ACUTE closedTerm {
2255
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&acute;</mo></mover>");
2256
+ mtex2MML_free_string($2);
2257
+ };
2258
+
2259
+ grave: GRAVE closedTerm {
2260
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x60;</mo></mover>");
2261
+ mtex2MML_free_string($2);
2262
+ };
2263
+
2264
+ breve: BREVE closedTerm {
2265
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x2d8;</mo></mover>");
2266
+ mtex2MML_free_string($2);
2267
+ };
2268
+
2269
+ mathring: MATHRING closedTerm {
2270
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&#730;</mo></mover>");
2271
+ mtex2MML_free_string($2);
2272
+ };
2273
+
2274
+ dot: DOT closedTerm {
2275
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo>&dot;</mo></mover>");
2276
+ mtex2MML_free_string($2);
2277
+ };
2278
+
2279
+ ddot: DDOT closedTerm {
2280
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo>&Dot;</mo></mover>");
2281
+ mtex2MML_free_string($2);
2282
+ };
2283
+
2284
+ dddot: DDDOT closedTerm {
2285
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo>&tdot;</mo></mover>");
2286
+ mtex2MML_free_string($2);
2287
+ };
2288
+
2289
+ ddddot: DDDDOT closedTerm {
2290
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo>&DotDot;</mo></mover>");
2291
+ mtex2MML_free_string($2);
2292
+ };
2293
+
2294
+ tilde: TILDE closedTerm {
2295
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&tilde;</mo></mover>");
2296
+ mtex2MML_free_string($2);
2297
+ }
2298
+ | WIDETILDE closedTerm {
2299
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo>&tilde;</mo></mover>");
2300
+ mtex2MML_free_string($2);
2301
+ };
2302
+
2303
+ check: CHECK closedTerm {
2304
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x2c7;</mo></mover>");
2305
+ mtex2MML_free_string($2);
2306
+ }
2307
+ | WIDECHECK closedTerm {
2308
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo>&#x2c7;</mo></mover>");
2309
+ mtex2MML_free_string($2);
2310
+ };
2311
+
2312
+ hat: HAT closedTerm {
2313
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x5E;</mo></mover>");
2314
+ mtex2MML_free_string($2);
2315
+ }
2316
+ | WIDEHAT closedTerm {
2317
+ $$ = mtex2MML_copy3("<mover>", $2, "<mo>&#x5E;</mo></mover>");
2318
+ mtex2MML_free_string($2);
2319
+ };
2320
+
2321
+ skew: SKEW closedTerm ACUTE closedTerm {
2322
+ char * em_skew = dbl2em($2);
2323
+
2324
+ $$ = implement_skew($4, em_skew, "&acute;");
2325
+
2326
+ mtex2MML_free_string(em_skew);
2327
+ mtex2MML_free_string($2);
2328
+ mtex2MML_free_string($4);
2329
+ }
2330
+ | SKEW closedTerm BAR closedTerm {
2331
+ char * em_skew = dbl2em($2);
2332
+
2333
+ $$ = implement_skew($4, em_skew, "&#x000AF;");
2334
+
2335
+ mtex2MML_free_string(em_skew);
2336
+ mtex2MML_free_string($2);
2337
+ mtex2MML_free_string($4);
2338
+ }
2339
+ | SKEW closedTerm BREVE closedTerm {
2340
+ char * em_skew = dbl2em($2);
2341
+
2342
+ $$ = implement_skew($4, em_skew, "&#x2d8;");
2343
+
2344
+ mtex2MML_free_string(em_skew);
2345
+ mtex2MML_free_string($2);
2346
+ mtex2MML_free_string($4);
2347
+ }
2348
+ | SKEW closedTerm CHECK closedTerm {
2349
+ char * em_skew = dbl2em($2);
2350
+
2351
+ $$ = implement_skew($4, em_skew, "&#x2c7;");
2352
+
2353
+ mtex2MML_free_string(em_skew);
2354
+ mtex2MML_free_string($2);
2355
+ mtex2MML_free_string($4);
2356
+ }
2357
+ | SKEW closedTerm DOT closedTerm {
2358
+ char * em_skew = dbl2em($2);
2359
+
2360
+ $$ = implement_skew($4, em_skew, "&dot;");
2361
+
2362
+ mtex2MML_free_string(em_skew);
2363
+ mtex2MML_free_string($2);
2364
+ mtex2MML_free_string($4);
2365
+ }
2366
+ | SKEW closedTerm DDOT closedTerm {
2367
+ char * em_skew = dbl2em($2);
2368
+
2369
+ $$ = implement_skew($4, em_skew, "&Dot;");
2370
+
2371
+ mtex2MML_free_string(em_skew);
2372
+ mtex2MML_free_string($2);
2373
+ mtex2MML_free_string($4);
2374
+ }
2375
+ | SKEW closedTerm DDDOT closedTerm {
2376
+ char * em_skew = dbl2em($2);
2377
+
2378
+ $$ = implement_skew($4, em_skew, "&tdot;");
2379
+
2380
+ mtex2MML_free_string(em_skew);
2381
+ mtex2MML_free_string($2);
2382
+ mtex2MML_free_string($4);
2383
+ }
2384
+ | SKEW closedTerm DDDDOT closedTerm {
2385
+ char * em_skew = dbl2em($2);
2386
+
2387
+ $$ = implement_skew($4, em_skew, "&DotDot;");
2388
+
2389
+ mtex2MML_free_string(em_skew);
2390
+ mtex2MML_free_string($2);
2391
+ mtex2MML_free_string($4);
2392
+ }
2393
+ | SKEW closedTerm GRAVE closedTerm {
2394
+ char * em_skew = dbl2em($2);
2395
+
2396
+ $$ = implement_skew($4, em_skew, "&#x60;");
2397
+
2398
+ mtex2MML_free_string(em_skew);
2399
+ mtex2MML_free_string($2);
2400
+ mtex2MML_free_string($4);
2401
+ }
2402
+ | SKEW closedTerm HAT closedTerm {
2403
+ char * em_skew = dbl2em($2);
2404
+
2405
+ $$ = implement_skew($4, em_skew, "&#x5E;");
2406
+
2407
+ mtex2MML_free_string(em_skew);
2408
+ mtex2MML_free_string($2);
2409
+ mtex2MML_free_string($4);
2410
+ }
2411
+ | SKEW closedTerm TILDE closedTerm {
2412
+ char * em_skew = dbl2em($2);
2413
+
2414
+ $$ = implement_skew($4, em_skew, "&tilde;");
2415
+
2416
+ mtex2MML_free_string(em_skew);
2417
+ mtex2MML_free_string($2);
2418
+ mtex2MML_free_string($4);
2419
+ }
2420
+ | SKEW closedTerm WIDEHAT closedTerm {
2421
+ char * em_skew = dbl2em($2);
2422
+
2423
+ $$ = implement_skew($4, em_skew, "&#x5E;");
2424
+
2425
+ mtex2MML_free_string(em_skew);
2426
+ mtex2MML_free_string($2);
2427
+ mtex2MML_free_string($4);
2428
+ }
2429
+ | SKEW closedTerm WIDETILDE closedTerm {
2430
+ char * em_skew = dbl2em($2);
2431
+
2432
+ $$ = implement_skew($4, em_skew, "&#x5E;");
2433
+
2434
+ mtex2MML_free_string(em_skew);
2435
+ mtex2MML_free_string($2);
2436
+ mtex2MML_free_string($4);
2437
+ };
2438
+
2439
+ msqrt: SQRT closedTerm {
2440
+ $$ = mtex2MML_copy3("<msqrt>", $2, "</msqrt>");
2441
+ mtex2MML_free_string($2);
2442
+ };
2443
+
2444
+ mroot: SQRT OPTARGOPEN compoundTermList OPTARGCLOSE closedTerm {
2445
+ char * s1 = mtex2MML_copy3("<mroot>", $5, $3);
2446
+ $$ = mtex2MML_copy2(s1, "</mroot>");
2447
+ mtex2MML_free_string(s1);
2448
+ mtex2MML_free_string($3);
2449
+ mtex2MML_free_string($5);
2450
+ }
2451
+ | ROOT closedTerm OF closedTerm {
2452
+ char * s1 = mtex2MML_copy3("<mroot>", $4, $2);
2453
+ $$ = mtex2MML_copy2(s1, "</mroot>");
2454
+ mtex2MML_free_string(s1);
2455
+ mtex2MML_free_string($2);
2456
+ mtex2MML_free_string($4);
2457
+ };
2458
+
2459
+ leftroot: LEFTROOT ST NUMBER END closedTerm {
2460
+ char * spacing = root_pos_to_em($3);
2461
+
2462
+ char *s1 = mtex2MML_copy3("<mpadded width=\"", spacing, "\"><mrow>");
2463
+ $$ = mtex2MML_copy3(s1, $5, "</mrow></mpadded>");
2464
+
2465
+ mtex2MML_free_string(s1);
2466
+ mtex2MML_free_string(spacing);
2467
+ mtex2MML_free_string($3);
2468
+ mtex2MML_free_string($5);
2469
+ };
2470
+
2471
+ uproot: UPROOT ST NUMBER END closedTerm {
2472
+ char * spacing = root_pos_to_em($3);
2473
+
2474
+ char *s1 = mtex2MML_copy3("<mpadded height=\"", spacing, "\" voffset=\"");
2475
+ char *s2 = mtex2MML_copy3(s1, spacing, "\"><mrow>");
2476
+ $$ = mtex2MML_copy3(s2, $5, "</mrow></mpadded>");
2477
+
2478
+ mtex2MML_free_string(s1);
2479
+ mtex2MML_free_string(s2);
2480
+ mtex2MML_free_string(spacing);
2481
+ mtex2MML_free_string($3);
2482
+ mtex2MML_free_string($5);
2483
+ };
2484
+
2485
+ raisebox: RAISEBOX TEXTSTRING TEXTSTRING TEXTSTRING closedTerm {
2486
+ char * s1 = mtex2MML_copy3("<mpadded voffset='", $2, "' height='");
2487
+ char * s2 = mtex2MML_copy3(s1, $3, "' depth='");
2488
+ char * s3 = mtex2MML_copy3(s2, $4, "'>");
2489
+ $$ = mtex2MML_copy3(s3, $5, "</mpadded>");
2490
+ mtex2MML_free_string(s1);
2491
+ mtex2MML_free_string(s2);
2492
+ mtex2MML_free_string(s3);
2493
+ mtex2MML_free_string($2);
2494
+ mtex2MML_free_string($3);
2495
+ mtex2MML_free_string($4);
2496
+ mtex2MML_free_string($5);
2497
+ }
2498
+ | RAISEBOX NEG TEXTSTRING TEXTSTRING TEXTSTRING closedTerm {
2499
+ char * s1 = mtex2MML_copy3("<mpadded voffset='-", $3, "' height='");
2500
+ char * s2 = mtex2MML_copy3(s1, $4, "' depth='");
2501
+ char * s3 = mtex2MML_copy3(s2, $5, "'>");
2502
+ $$ = mtex2MML_copy3(s3, $6, "</mpadded>");
2503
+ mtex2MML_free_string(s1);
2504
+ mtex2MML_free_string(s2);
2505
+ mtex2MML_free_string(s3);
2506
+ mtex2MML_free_string($3);
2507
+ mtex2MML_free_string($4);
2508
+ mtex2MML_free_string($5);
2509
+ mtex2MML_free_string($6);
2510
+ }
2511
+ | RAISEBOX TEXTSTRING TEXTSTRING closedTerm {
2512
+ char * s1 = mtex2MML_copy3("<mpadded voffset='", $2, "' height='");
2513
+ char * s2 = mtex2MML_copy3(s1, $3, "' depth='depth'>");
2514
+ $$ = mtex2MML_copy3(s2, $4, "</mpadded>");
2515
+ mtex2MML_free_string(s1);
2516
+ mtex2MML_free_string(s2);
2517
+ mtex2MML_free_string($2);
2518
+ mtex2MML_free_string($3);
2519
+ mtex2MML_free_string($4);
2520
+ }
2521
+ | RAISEBOX NEG TEXTSTRING TEXTSTRING closedTerm {
2522
+ char * s1 = mtex2MML_copy3("<mpadded voffset='-", $3, "' height='");
2523
+ char * s2 = mtex2MML_copy3(s1, $4, "' depth='+");
2524
+ char * s3 = mtex2MML_copy3(s2, $3, "'>");
2525
+ $$ = mtex2MML_copy3(s3, $5, "</mpadded>");
2526
+ mtex2MML_free_string(s1);
2527
+ mtex2MML_free_string(s2);
2528
+ mtex2MML_free_string(s3);
2529
+ mtex2MML_free_string($3);
2530
+ mtex2MML_free_string($4);
2531
+ mtex2MML_free_string($5);
2532
+ }
2533
+ | RAISEBOX TEXTSTRING closedTerm {
2534
+ char * s1 = mtex2MML_copy3("<mpadded voffset='", $2, "' height='+");
2535
+ char * s2 = mtex2MML_copy3(s1, $2, "' depth='depth'>");
2536
+ $$ = mtex2MML_copy3(s2, $3, "</mpadded>");
2537
+ mtex2MML_free_string(s1);
2538
+ mtex2MML_free_string(s2);
2539
+ mtex2MML_free_string($2);
2540
+ mtex2MML_free_string($3);
2541
+ }
2542
+ | RAISEBOX NEG TEXTSTRING closedTerm {
2543
+ char * s1 = mtex2MML_copy3("<mpadded voffset='-", $3, "' height='0pt' depth='+");
2544
+ char * s2 = mtex2MML_copy3(s1, $3, "'>");
2545
+ $$ = mtex2MML_copy3(s2, $4, "</mpadded>");
2546
+ mtex2MML_free_string(s1);
2547
+ mtex2MML_free_string(s2);
2548
+ mtex2MML_free_string($3);
2549
+ mtex2MML_free_string($4);
2550
+ };
2551
+
2552
+ munder: XARROW OPTARGOPEN compoundTermList OPTARGCLOSE EMPTYMROW {
2553
+ char * s1 = mtex2MML_copy3("<munder><mo>", $1, "</mo><mrow>");
2554
+ $$ = mtex2MML_copy3(s1, $3, "</mrow></munder>");
2555
+ mtex2MML_free_string(s1);
2556
+ mtex2MML_free_string($1);
2557
+ mtex2MML_free_string($3);
2558
+ }
2559
+ | UNDER closedTerm closedTerm {
2560
+ char * s1 = mtex2MML_copy3("<munder>", $3, $2);
2561
+ $$ = mtex2MML_copy2(s1, "</munder>");
2562
+ mtex2MML_free_string(s1);
2563
+ mtex2MML_free_string($2);
2564
+ mtex2MML_free_string($3);
2565
+ };
2566
+
2567
+ mover: XARROW closedTerm {
2568
+ char * s1 = mtex2MML_copy3("<mover><mo>", $1, "</mo>");
2569
+ $$ = mtex2MML_copy3(s1, $2, "</mover>");
2570
+ mtex2MML_free_string(s1);
2571
+ mtex2MML_free_string($1);
2572
+ mtex2MML_free_string($2);
2573
+ }
2574
+ | OVER closedTerm closedTerm {
2575
+ char * s1 = mtex2MML_copy3("<mover>", $3, $2);
2576
+ $$ = mtex2MML_copy2(s1, "</mover>");
2577
+ mtex2MML_free_string(s1);
2578
+ mtex2MML_free_string($2);
2579
+ mtex2MML_free_string($3);
2580
+ };
2581
+
2582
+ munderover: XARROW OPTARGOPEN compoundTermList OPTARGCLOSE closedTerm {
2583
+ char * s1 = mtex2MML_copy3("<munderover><mo>", $1, "</mo><mrow>");
2584
+ char * s2 = mtex2MML_copy3(s1, $3, "</mrow>");
2585
+ $$ = mtex2MML_copy3(s2, $5, "</munderover>");
2586
+ mtex2MML_free_string(s1);
2587
+ mtex2MML_free_string(s2);
2588
+ mtex2MML_free_string($1);
2589
+ mtex2MML_free_string($3);
2590
+ mtex2MML_free_string($5);
2591
+ }
2592
+ | UNDEROVER closedTerm closedTerm closedTerm {
2593
+ char * s1 = mtex2MML_copy3("<munderover>", $4, $2);
2594
+ $$ = mtex2MML_copy3(s1, $3, "</munderover>");
2595
+ mtex2MML_free_string(s1);
2596
+ mtex2MML_free_string($2);
2597
+ mtex2MML_free_string($3);
2598
+ mtex2MML_free_string($4);
2599
+ };
2600
+
2601
+ emptymrow: EMPTYMROW {
2602
+ $$ = mtex2MML_copy_string("<mrow/>");
2603
+ };
2604
+
2605
+ mathenv: BEGINENV EQUATION compoundTermList ENDENV EQUATION {
2606
+ char * n = mtex2MML_global_label();
2607
+ $$ = mtex2MML_copy3("<mtable><mlabeledtr><mtd>", $3, n);
2608
+
2609
+ mtex2MML_free_string($3);
2610
+ mtex2MML_free_string(n);
2611
+ }
2612
+ | BEGINENV EQUATION_STAR compoundTermList ENDENV EQUATION_STAR {
2613
+ $$ = mtex2MML_copy3("<mtable><mlabeledtr><mtd><mtext>&#8239;</mtext></mtd><mtd>", $3, "</mtd></mlabeledtr></mtable>");
2614
+
2615
+ mtex2MML_free_string($3);
2616
+ }
2617
+ | BEGINENV MATRIX tableRowList ENDENV MATRIX {
2618
+ char *row_data = combine_row_data(&environment_data_stack);
2619
+
2620
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"false\" ", row_data, ">");
2621
+ if (encase == TOPENCLOSE) {
2622
+ char *t = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2623
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2624
+ mtex2MML_free_string(t);
2625
+ }
2626
+ else
2627
+ $$ = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2628
+
2629
+ mtex2MML_free_string($3);
2630
+ mtex2MML_free_string(s1);
2631
+ mtex2MML_free_string(row_data);
2632
+ }
2633
+ | BEGINENV GATHERED ARRAYALIGN END tableRowList ENDENV GATHERED {
2634
+ char *row_data = combine_row_data(&environment_data_stack);
2635
+
2636
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"true\" align=\"", $3, "\" ");
2637
+ char * s2 = mtex2MML_copy3(s1, row_data, ">");
2638
+ if (encase == TOPENCLOSE) {
2639
+ char *t = mtex2MML_copy3(s2, $5, "</mtable></mrow>");
2640
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2641
+ mtex2MML_free_string(t);
2642
+ }
2643
+ else
2644
+ $$ = mtex2MML_copy3(s2, $5, "</mtable></mrow>");
2645
+
2646
+ mtex2MML_free_string($3);
2647
+ mtex2MML_free_string($5);
2648
+ mtex2MML_free_string(s1);
2649
+ mtex2MML_free_string(s2);
2650
+ mtex2MML_free_string(row_data);
2651
+ }
2652
+ | BEGINENV GATHERED tableRowList ENDENV GATHERED {
2653
+ char *row_data = combine_row_data(&environment_data_stack);
2654
+
2655
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"true\" ", row_data, ">");
2656
+ if (encase == TOPENCLOSE) {
2657
+ char *t = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2658
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2659
+ mtex2MML_free_string(t);
2660
+ }
2661
+ else
2662
+ $$ = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2663
+
2664
+ mtex2MML_free_string($3);
2665
+ mtex2MML_free_string(s1);
2666
+ mtex2MML_free_string(row_data);
2667
+ }
2668
+ | BEGINENV EQNARRAY tableRowList ENDENV EQNARRAY {
2669
+ char *row_data = combine_row_data(&environment_data_stack);
2670
+
2671
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"true\" columnalign=\"right center left\" columnspacing=\"thickmathspace\" ", row_data, ">");
2672
+ char * s2 = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2673
+ char * n = mtex2MML_global_label();
2674
+
2675
+ if (encase == TOPENCLOSE) {
2676
+ char *t = mtex2MML_copy3("<mtable><mlabeledtr><mtd>", s2, n);
2677
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2678
+ mtex2MML_free_string(t);
2679
+ }
2680
+ else
2681
+ $$ = mtex2MML_copy3("<mtable><mlabeledtr><mtd>", s2, n);
2682
+
2683
+ mtex2MML_free_string($3);
2684
+ mtex2MML_free_string(n);
2685
+ mtex2MML_free_string(s1);
2686
+ mtex2MML_free_string(s2);
2687
+ mtex2MML_free_string(row_data);
2688
+ }
2689
+ | BEGINENV EQNARRAY_STAR tableRowList ENDENV EQNARRAY_STAR {
2690
+ char *row_data = combine_row_data(&environment_data_stack);
2691
+
2692
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"true\" columnalign=\"right center left\" columnspacing=\"thickmathspace\" ", row_data, ">");
2693
+ if (encase == TOPENCLOSE) {
2694
+ char *t = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2695
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2696
+ mtex2MML_free_string(t);
2697
+ }
2698
+ else
2699
+ $$ = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2700
+
2701
+ mtex2MML_free_string($3);
2702
+ mtex2MML_free_string(s1);
2703
+ mtex2MML_free_string(row_data);
2704
+ }
2705
+ | BEGINENV GATHER tableRowList ENDENV GATHER {
2706
+ char *row_data = combine_row_data(&environment_data_stack);
2707
+
2708
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"true\" ", row_data, ">");
2709
+ char * s2 = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2710
+ char * n = mtex2MML_global_label();
2711
+
2712
+ if (encase == TOPENCLOSE) {
2713
+ char *t = mtex2MML_copy3("<mtable><mlabeledtr><mtd>", s2, n);
2714
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2715
+ mtex2MML_free_string(t);
2716
+ }
2717
+ else
2718
+ $$ = mtex2MML_copy3("<mtable><mlabeledtr><mtd>", s2, n);
2719
+
2720
+ mtex2MML_free_string($3);
2721
+ mtex2MML_free_string(n);
2722
+ mtex2MML_free_string(s1);
2723
+ mtex2MML_free_string(s2);
2724
+ mtex2MML_free_string(row_data);
2725
+ }
2726
+ | BEGINENV GATHER_STAR tableRowList ENDENV GATHER_STAR {
2727
+ char *row_data = combine_row_data(&environment_data_stack);
2728
+
2729
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"true\" ", row_data, ">");
2730
+ if (encase == TOPENCLOSE) {
2731
+ char *t = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2732
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2733
+ mtex2MML_free_string(t);
2734
+ }
2735
+ else
2736
+ $$ = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2737
+
2738
+ mtex2MML_free_string($3);
2739
+ mtex2MML_free_string(s1);
2740
+ mtex2MML_free_string(row_data);
2741
+ }
2742
+ | BEGINENV MULTLINE tableRowList ENDENV MULTLINE {
2743
+ char *row_data = combine_row_data(&environment_data_stack);
2744
+
2745
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"true\" ", row_data, ">");
2746
+ char * s2 = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2747
+ char * n = mtex2MML_global_label();
2748
+
2749
+ if (encase == TOPENCLOSE) {
2750
+ char *t = mtex2MML_copy3("<mtable><mlabeledtr><mtd>", s2, n);
2751
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2752
+ mtex2MML_free_string(t);
2753
+ }
2754
+ else
2755
+ $$ = mtex2MML_copy3("<mtable><mlabeledtr><mtd>", s2, n);
2756
+
2757
+ mtex2MML_free_string($3);
2758
+ mtex2MML_free_string(n);
2759
+ mtex2MML_free_string(s1);
2760
+ mtex2MML_free_string(s2);
2761
+ mtex2MML_free_string(row_data);
2762
+ }
2763
+ | BEGINENV MULTLINE_STAR tableRowList ENDENV MULTLINE_STAR {
2764
+ char *row_data = combine_row_data(&environment_data_stack);
2765
+
2766
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"true\" columnwidth=\"100%\" width=\"85%\" ", row_data, ">");
2767
+ if (encase == TOPENCLOSE) {
2768
+ char *t = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2769
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2770
+ mtex2MML_free_string(t);
2771
+ }
2772
+ else
2773
+ $$ = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2774
+
2775
+ mtex2MML_free_string($3);
2776
+ mtex2MML_free_string(s1);
2777
+ mtex2MML_free_string(row_data);
2778
+ }
2779
+ | BEGINENV PMATRIX tableRowList ENDENV PMATRIX {
2780
+ char *row_data = combine_row_data(&environment_data_stack);
2781
+
2782
+ char * s1 = mtex2MML_copy3("<mrow><mo>(</mo><mrow><mtable displaystyle=\"false\" ", row_data, ">");
2783
+
2784
+ if (encase == TOPENCLOSE) {
2785
+ char *t = mtex2MML_copy3(s1, $3, "</mtable></mrow><mo>)</mo></mrow>");
2786
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2787
+ mtex2MML_free_string(t);
2788
+ }
2789
+ else
2790
+ $$ = mtex2MML_copy3(s1, $3, "</mtable></mrow><mo>)</mo></mrow>");
2791
+
2792
+ mtex2MML_free_string($3);
2793
+ mtex2MML_free_string(s1);
2794
+ mtex2MML_free_string(row_data);
2795
+ }
2796
+ | BEGINENV BMATRIX tableRowList ENDENV BMATRIX {
2797
+ char *row_data = combine_row_data(&environment_data_stack);
2798
+
2799
+ char * s1 = mtex2MML_copy3("<mrow><mo>[</mo><mrow><mtable displaystyle=\"false\" ", row_data, ">");
2800
+
2801
+ if (encase == TOPENCLOSE) {
2802
+ char *t = mtex2MML_copy3(s1, $3, "</mtable></mrow><mo>]</mo></mrow>");
2803
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2804
+ mtex2MML_free_string(t);
2805
+ }
2806
+ else
2807
+ $$ = mtex2MML_copy3(s1, $3, "</mtable></mrow><mo>]</mo></mrow>");
2808
+
2809
+ mtex2MML_free_string($3);
2810
+ mtex2MML_free_string(s1);
2811
+ mtex2MML_free_string(row_data);
2812
+ }
2813
+ | BEGINENV VMATRIX tableRowList ENDENV VMATRIX {
2814
+ char *row_data = combine_row_data(&environment_data_stack);
2815
+
2816
+ char * s1 = mtex2MML_copy3("<mrow><mo>&VerticalBar;</mo><mrow><mtable displaystyle=\"false\" ", row_data, ">");
2817
+
2818
+ if (encase == TOPENCLOSE) {
2819
+ char *t = mtex2MML_copy3(s1, $3, "</mtable></mrow><mo>&VerticalBar;</mo></mrow>");
2820
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2821
+ mtex2MML_free_string(t);
2822
+ }
2823
+ else
2824
+ $$ = mtex2MML_copy3(s1, $3, "</mtable></mrow><mo>&VerticalBar;</mo></mrow>");
2825
+
2826
+ mtex2MML_free_string($3);
2827
+ mtex2MML_free_string(s1);
2828
+ mtex2MML_free_string(row_data);
2829
+ }
2830
+ | BEGINENV BBMATRIX tableRowList ENDENV BBMATRIX {
2831
+ char *row_data = combine_row_data(&environment_data_stack);
2832
+
2833
+ char * s1 = mtex2MML_copy3("<mrow><mo>{</mo><mrow><mtable displaystyle=\"false\" ", row_data, ">");
2834
+
2835
+ if (encase == TOPENCLOSE) {
2836
+ char *t = mtex2MML_copy3(s1, $3, "</mtable></mrow><mo>}</mo></mrow>");
2837
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2838
+ mtex2MML_free_string(t);
2839
+ }
2840
+ else
2841
+ $$ = mtex2MML_copy3(s1, $3, "</mtable></mrow><mo>}</mo></mrow>");
2842
+
2843
+ mtex2MML_free_string($3);
2844
+ mtex2MML_free_string(s1);
2845
+ mtex2MML_free_string(row_data);
2846
+ }
2847
+ | BEGINENV VVMATRIX tableRowList ENDENV VVMATRIX {
2848
+ char *row_data = combine_row_data(&environment_data_stack);
2849
+
2850
+ char * s1 = mtex2MML_copy3("<mrow><mo>&DoubleVerticalBar;</mo><mrow><mtable displaystyle=\"false\" ", row_data, ">");
2851
+
2852
+ if (encase == TOPENCLOSE) {
2853
+ char *t = mtex2MML_copy3(s1, $3, "</mtable></mrow><mo>&DoubleVerticalBar;</mo></mrow>");
2854
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2855
+ mtex2MML_free_string(t);
2856
+ }
2857
+ else
2858
+ $$ = mtex2MML_copy3(s1, $3, "</mtable></mrow><mo>&DoubleVerticalBar;</mo></mrow>");
2859
+
2860
+ mtex2MML_free_string($3);
2861
+ mtex2MML_free_string(s1);
2862
+ mtex2MML_free_string(row_data);
2863
+ }
2864
+ | BEGINENV SMALLMATRIX tableRowList ENDENV SMALLMATRIX {
2865
+ char *row_data = combine_row_data(&environment_data_stack);
2866
+
2867
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"false\" columnspacing=\"0.333em\" ", row_data, ">");
2868
+ if (encase == TOPENCLOSE) {
2869
+ char *t = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2870
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2871
+ mtex2MML_free_string(t);
2872
+ }
2873
+ else
2874
+ $$ = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2875
+
2876
+ mtex2MML_free_string($3);
2877
+ mtex2MML_free_string(s1);
2878
+ mtex2MML_free_string(row_data);
2879
+ }
2880
+ | BEGINENV CASES tableRowList ENDENV CASES {
2881
+ char *row_data = combine_row_data(&environment_data_stack);
2882
+
2883
+ char * s1 = mtex2MML_copy3("<mrow><mo>{</mo><mrow><mtable displaystyle=\"false\" columnalign=\"left left\" ", row_data, ">");
2884
+
2885
+ if (encase == TOPENCLOSE) {
2886
+ char *t = mtex2MML_copy3(s1, $3, "</mtable></mrow></mrow>");
2887
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2888
+ mtex2MML_free_string(t);
2889
+ }
2890
+ else
2891
+ $$ = mtex2MML_copy3(s1, $3, "</mtable></mrow></mrow>");
2892
+
2893
+ mtex2MML_free_string($3);
2894
+ mtex2MML_free_string(s1);
2895
+ mtex2MML_free_string(row_data);
2896
+ }
2897
+ | BEGINENV ALIGNED ARRAYALIGN END tableRowList ENDENV ALIGNED {
2898
+ char *row_data = combine_row_data(&environment_data_stack);
2899
+
2900
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"true\" align=\"", $3, "\" columnspacing=\"0em 2em 0em 2em 0em 2em 0em 2em 0em 2em 0em\" columnalign=\"right left right left right left right left right left\" ");
2901
+ char * s2 = mtex2MML_copy3(s1, row_data, ">");
2902
+
2903
+ if (encase == TOPENCLOSE) {
2904
+ char *t = mtex2MML_copy3(s2, $5, "</mtable></mrow>");
2905
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2906
+ mtex2MML_free_string(t);
2907
+ }
2908
+ else
2909
+ $$ = mtex2MML_copy3(s2, $5, "</mtable></mrow>");
2910
+
2911
+ mtex2MML_free_string($3);
2912
+ mtex2MML_free_string($5);
2913
+ mtex2MML_free_string(s1);
2914
+ mtex2MML_free_string(s2);
2915
+ mtex2MML_free_string(row_data);
2916
+ }
2917
+ | BEGINENV ALIGNED tableRowList ENDENV ALIGNED {
2918
+ char *row_data = combine_row_data(&environment_data_stack);
2919
+
2920
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"true\" columnspacing=\"0em 2em 0em 2em 0em 2em 0em 2em 0em 2em 0em\" columnalign=\"right left right left right left right left right left\" ", row_data, ">");
2921
+
2922
+ if (encase == TOPENCLOSE) {
2923
+ char *t = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2924
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2925
+ mtex2MML_free_string(t);
2926
+ }
2927
+ else
2928
+ $$ = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2929
+
2930
+ mtex2MML_free_string($3);
2931
+ mtex2MML_free_string(s1);
2932
+ mtex2MML_free_string(row_data);
2933
+ }
2934
+ | BEGINENV ALIGNENV tableRowList ENDENV ALIGNENV {
2935
+ char *row_data = combine_row_data(&environment_data_stack);
2936
+
2937
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"true\" columnspacing=\"0em 2em 0em 2em 0em 2em 0em 2em 0em 2em 0em\" columnalign=\"right left right left right left right left right left\" ", row_data, ">");
2938
+ char * s2 = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2939
+ char * n = mtex2MML_global_label();
2940
+
2941
+ if (encase == TOPENCLOSE) {
2942
+ char *t = mtex2MML_copy3("<mtable><mlabeledtr><mtd>", s2, n);
2943
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2944
+ mtex2MML_free_string(t);
2945
+ }
2946
+ else
2947
+ $$ = mtex2MML_copy3("<mtable><mlabeledtr><mtd>", s2, n);
2948
+
2949
+ mtex2MML_free_string($3);
2950
+ mtex2MML_free_string(n);
2951
+ mtex2MML_free_string(s1);
2952
+ mtex2MML_free_string(s2);
2953
+ mtex2MML_free_string(row_data);
2954
+ }
2955
+ | BEGINENV ALIGNENV_STAR tableRowList ENDENV ALIGNENV_STAR {
2956
+ char *row_data = combine_row_data(&environment_data_stack);
2957
+
2958
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"true\" columnspacing=\"0em 2em 0em 2em 0em 2em 0em 2em 0em 2em 0em\" columnalign=\"right left right left right left right left right left\" ", row_data, ">");
2959
+
2960
+ if (encase == TOPENCLOSE) {
2961
+ char *t = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2962
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2963
+ mtex2MML_free_string(t);
2964
+ }
2965
+ else
2966
+ $$ = mtex2MML_copy3(s1, $3, "</mtable></mrow>");
2967
+
2968
+ mtex2MML_free_string($3);
2969
+ mtex2MML_free_string(s1);
2970
+ mtex2MML_free_string(row_data);
2971
+ }
2972
+ | BEGINENV ALIGNAT ALIGNATVALUE END tableRowList ENDENV ALIGNAT {
2973
+ char *row_data = combine_row_data(&environment_data_stack);
2974
+
2975
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"true\" columnalign=\"right left right left right left right left right left\" columnspacing=\"0em\" ", row_data, ">");
2976
+ char * s2 = mtex2MML_copy3(s1, $5, "</mtable></mrow>");
2977
+ char * n = mtex2MML_global_label();
2978
+
2979
+ if (encase == TOPENCLOSE) {
2980
+ char *t = mtex2MML_copy3("<mtable><mlabeledtr><mtd>", s2, n);
2981
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
2982
+ mtex2MML_free_string(t);
2983
+ }
2984
+ else
2985
+ $$ = mtex2MML_copy3("<mtable><mlabeledtr><mtd>", s2, n);
2986
+
2987
+ mtex2MML_free_string($3);
2988
+ mtex2MML_free_string($5);
2989
+ mtex2MML_free_string(n);
2990
+ mtex2MML_free_string(s1);
2991
+ mtex2MML_free_string(s2);
2992
+ mtex2MML_free_string(row_data);
2993
+ }
2994
+ | BEGINENV ALIGNAT_STAR ALIGNATVALUE END tableRowList ENDENV ALIGNAT_STAR {
2995
+ char *row_data = combine_row_data(&environment_data_stack);
2996
+
2997
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"true\" columnalign=\"right left right left right left right left right left\" columnspacing=\"0em\" ", row_data, ">");
2998
+
2999
+ if (encase == TOPENCLOSE) {
3000
+ char *t = mtex2MML_copy3(s1, $5, "</mtable></mrow>");
3001
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
3002
+ mtex2MML_free_string(t);
3003
+ }
3004
+ else
3005
+ $$ = mtex2MML_copy3(s1, $5, "</mtable></mrow>");
3006
+
3007
+ mtex2MML_free_string($3);
3008
+ mtex2MML_free_string($5);
3009
+ mtex2MML_free_string(s1);
3010
+ mtex2MML_free_string(row_data);
3011
+ }
3012
+ | BEGINENV ALIGNEDAT ALIGNATVALUE END tableRowList ENDENV ALIGNEDAT {
3013
+ char *row_data = combine_row_data(&environment_data_stack);
3014
+
3015
+ char * s1 = mtex2MML_copy3("<mrow><mtable displaystyle=\"true\" columnalign=\"right left right left right left right left right left\" columnspacing=\"0em\" ", row_data, ">");
3016
+
3017
+ if (encase == TOPENCLOSE) {
3018
+ char *t = mtex2MML_copy3(s1, $5, "</mtable></mrow>");
3019
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
3020
+ mtex2MML_free_string(t);
3021
+ }
3022
+ else
3023
+ $$ = mtex2MML_copy3(s1, $5, "</mtable></mrow>");
3024
+
3025
+ mtex2MML_free_string($3);
3026
+ mtex2MML_free_string($5);
3027
+ mtex2MML_free_string(s1);
3028
+ mtex2MML_free_string(row_data);
3029
+ }
3030
+ | BEGINENV ARRAY ARRAYALIGN ST columnAlignList END tableRowList ENDENV ARRAY {
3031
+ const char *pipe_chars = vertical_pipe_extract($5);
3032
+ const char *column_align = remove_excess_pipe_chars($5);
3033
+ char *row_data = combine_row_data(&environment_data_stack);
3034
+
3035
+ char * s1 = mtex2MML_copy3("<mtable displaystyle=\"false\" align=\"", $3, "\" ");
3036
+ char * s2 = mtex2MML_copy3(s1, row_data, " columnalign=\"");
3037
+ char * s3 = mtex2MML_copy3(s2, column_align, "\" ");
3038
+ char * s4 = mtex2MML_copy3(s3, pipe_chars, "\">");
3039
+
3040
+ if (encase == TOPENCLOSE) {
3041
+ char *t = mtex2MML_copy3(s4, $7, "</mtable>");
3042
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
3043
+ mtex2MML_free_string(t);
3044
+ }
3045
+ else
3046
+ $$ = mtex2MML_copy3(s4, $7, "</mtable>");
3047
+
3048
+ mtex2MML_free_string(s1);
3049
+ mtex2MML_free_string(s2);
3050
+ mtex2MML_free_string(s3);
3051
+ mtex2MML_free_string(s4);
3052
+ mtex2MML_free_string($3);
3053
+ mtex2MML_free_string($5);
3054
+ mtex2MML_free_string($7);
3055
+ mtex2MML_free_string(pipe_chars);
3056
+ mtex2MML_free_string(column_align);
3057
+ mtex2MML_free_string(row_data);
3058
+ }
3059
+ | BEGINENV ARRAY ST columnAlignList END tableRowList ENDENV ARRAY {
3060
+ char *pipe_chars = vertical_pipe_extract($4);
3061
+ char *column_align = remove_excess_pipe_chars($4);
3062
+ char *row_data = combine_row_data(&environment_data_stack);
3063
+
3064
+ char * s1 = mtex2MML_copy3("<mtable displaystyle=\"false\" ", row_data, " columnalign=\"");
3065
+ char * s2 = mtex2MML_copy3(s1, column_align, "\" ");
3066
+ char * s3 = mtex2MML_copy3(s2, pipe_chars, "\">");
3067
+
3068
+ if (encase == TOPENCLOSE) {
3069
+ char *t = mtex2MML_copy3(s3, $6, "</mtable>");
3070
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
3071
+ mtex2MML_free_string(t);
3072
+ }
3073
+ else
3074
+ $$ = mtex2MML_copy3(s3, $6, "</mtable>");
3075
+
3076
+ mtex2MML_free_string(s1);
3077
+ mtex2MML_free_string(s2);
3078
+ mtex2MML_free_string(s3);
3079
+ mtex2MML_free_string($4);
3080
+ mtex2MML_free_string($6);
3081
+ mtex2MML_free_string(pipe_chars);
3082
+ mtex2MML_free_string(column_align);
3083
+ mtex2MML_free_string(row_data);
3084
+ }
3085
+ | BEGINENV SUBARRAY ST columnAlignList END tableRowList ENDENV SUBARRAY {
3086
+ char *pipe_chars = vertical_pipe_extract($4);
3087
+ char *column_align = remove_excess_pipe_chars($4);
3088
+
3089
+ char * s1 = mtex2MML_copy3("<mtable displaystyle=\"false\" columnspacing=\"0em 0em 0em 0em\" rowspacing=\"0.1em\" columnalign=\"", column_align, "\" ");
3090
+ char * s2 = mtex2MML_copy3(s1, pipe_chars, "\">");
3091
+
3092
+ if (encase == TOPENCLOSE) {
3093
+ char *t = mtex2MML_copy3(s2, $6, "</mtable>");
3094
+ $$ = mtex2MML_copy3("<menclose notation=\"top\">", t, "</menclose>");
3095
+ mtex2MML_free_string(t);
3096
+ }
3097
+ else
3098
+ $$ = mtex2MML_copy3(s2, $6, "</mtable>");
3099
+
3100
+ mtex2MML_free_string(s1);
3101
+ mtex2MML_free_string(s2);
3102
+ mtex2MML_free_string($4);
3103
+ mtex2MML_free_string($6);
3104
+ mtex2MML_free_string(pipe_chars);
3105
+ mtex2MML_free_string(column_align);
3106
+ }
3107
+ | BEGINENV SVG XMLSTRING ENDSVG {
3108
+ $$ = mtex2MML_copy3("<semantics><annotation-xml encoding=\"SVG1.1\">", $3, "</annotation-xml></semantics>");
3109
+ mtex2MML_free_string($3);
3110
+ }
3111
+ | BEGINENV SVG ENDSVG {
3112
+ $$ = mtex2MML_copy_string(" ");
3113
+ };
3114
+
3115
+ columnAlignList: columnAlignList COLUMNALIGN {
3116
+ $$ = mtex2MML_copy3($1, " ", $2);
3117
+ mtex2MML_free_string($1);
3118
+ mtex2MML_free_string($2);
3119
+ }
3120
+ | COLUMNALIGN {
3121
+ $$ = mtex2MML_copy_string($1);
3122
+ mtex2MML_free_string($1);
3123
+ };
3124
+
3125
+ substack: SUBSTACK MROWOPEN tableRowList MROWCLOSE {
3126
+ $$ = mtex2MML_copy3("<mrow><mtable columnalign=\"center\" rowspacing=\"0.5ex\">", $3, "</mtable></mrow>");
3127
+ mtex2MML_free_string($3);
3128
+ };
3129
+
3130
+ sideset: SIDESET MROWOPEN SUB closedTerm SUP closedTerm MROWCLOSE MROWOPEN SUB closedTerm SUP closedTerm MROWCLOSE closedTerm {
3131
+ char *s1 = mtex2MML_copy2("<msubsup><mphantom>", "</mphantom><mrow>");
3132
+ char *s2 = mtex2MML_copy3(s1, $4, "</mrow>");
3133
+ char *s3 = mtex2MML_copy3(s2, $6, "</msubsup><mspace width=\"negativethinmathspace\" /><msubsup><mrow>");
3134
+ char *s4 = mtex2MML_copy3(s3, $14, "</mrow>");
3135
+ char *s5 = mtex2MML_copy3(s4, $10, $12);
3136
+ $$ = mtex2MML_copy2(s5, "</msubsup>");
3137
+
3138
+ mtex2MML_free_string(s1);
3139
+ mtex2MML_free_string(s2);
3140
+ mtex2MML_free_string(s3);
3141
+ mtex2MML_free_string(s4);
3142
+ mtex2MML_free_string(s5);
3143
+ mtex2MML_free_string($4);
3144
+ mtex2MML_free_string($6);
3145
+ mtex2MML_free_string($10);
3146
+ mtex2MML_free_string($12);
3147
+ mtex2MML_free_string($14);
3148
+ };
3149
+
3150
+ array: ARRAY MROWOPEN tableRowList MROWCLOSE {
3151
+ $$ = mtex2MML_copy3("<mrow><mtable>", $3, "</mtable></mrow>");
3152
+ mtex2MML_free_string($3);
3153
+ }
3154
+ | ARRAY MROWOPEN ARRAYOPTS MROWOPEN arrayopts MROWCLOSE tableRowList MROWCLOSE {
3155
+ char * s1 = mtex2MML_copy3("<mrow><mtable ", $5, ">");
3156
+ $$ = mtex2MML_copy3(s1, $7, "</mtable></mrow>");
3157
+ mtex2MML_free_string(s1);
3158
+ mtex2MML_free_string($5);
3159
+ mtex2MML_free_string($7);
3160
+ };
3161
+
3162
+ cases: CASES MROWOPEN tableRowList MROWCLOSE {
3163
+ $$ = mtex2MML_copy3("<mrow><mo>{</mo><mrow><mtable displaystyle=\"false\" columnalign=\"left left\">", $3, "</mtable></mrow></mrow>");
3164
+ mtex2MML_free_string($3);
3165
+ };
3166
+
3167
+ eqalign: EQALIGN MROWOPEN tableRowList MROWCLOSE {
3168
+ $$ = mtex2MML_copy3("<mtable columnalign=\"right left\" rowspacing=\".5em\" columnspacing=\"thickmathspace\" displaystyle=\"true\">", $3, "</mtable></mrow></mrow>");
3169
+ mtex2MML_free_string($3);
3170
+ };
3171
+
3172
+ eqalignno: EQALIGNNO MROWOPEN tableRowList MROWCLOSE {
3173
+ $$ = mtex2MML_copy3("<mtable columnalign=\"right left right\" rowspacing=\".5em\" columnspacing=\"thickmathspace 3em\" displaystyle=\"true\">", $3, "</mtable></mrow></mrow>");
3174
+ mtex2MML_free_string($3);
3175
+ };
3176
+
3177
+ arrayopts: anarrayopt {
3178
+ $$ = mtex2MML_copy_string($1);
3179
+ mtex2MML_free_string($1);
3180
+ }
3181
+ | arrayopts anarrayopt {
3182
+ $$ = mtex2MML_copy3($1, " ", $2);
3183
+ mtex2MML_free_string($1);
3184
+ mtex2MML_free_string($2);
3185
+ };
3186
+
3187
+ anarrayopt: collayout {
3188
+ $$ = mtex2MML_copy_string($1);
3189
+ mtex2MML_free_string($1);
3190
+ }
3191
+ | colalign {
3192
+ $$ = mtex2MML_copy_string($1);
3193
+ mtex2MML_free_string($1);
3194
+ }
3195
+ | rowalign {
3196
+ $$ = mtex2MML_copy_string($1);
3197
+ mtex2MML_free_string($1);
3198
+ }
3199
+ | align {
3200
+ $$ = mtex2MML_copy_string($1);
3201
+ mtex2MML_free_string($1);
3202
+ }
3203
+ | eqrows {
3204
+ $$ = mtex2MML_copy_string($1);
3205
+ mtex2MML_free_string($1);
3206
+ }
3207
+ | eqcols {
3208
+ $$ = mtex2MML_copy_string($1);
3209
+ mtex2MML_free_string($1);
3210
+ }
3211
+ | rowlines {
3212
+ $$ = mtex2MML_copy_string($1);
3213
+ mtex2MML_free_string($1);
3214
+ }
3215
+ | collines {
3216
+ $$ = mtex2MML_copy_string($1);
3217
+ mtex2MML_free_string($1);
3218
+ }
3219
+ | frame {
3220
+ $$ = mtex2MML_copy_string($1);
3221
+ mtex2MML_free_string($1);
3222
+ }
3223
+ | padding {
3224
+ $$ = mtex2MML_copy_string($1);
3225
+ mtex2MML_free_string($1);
3226
+ };
3227
+
3228
+ collayout: COLLAYOUT ATTRLIST {
3229
+ $$ = mtex2MML_copy2("columnalign=", $2);
3230
+ mtex2MML_free_string($2);
3231
+ };
3232
+
3233
+ colalign: COLALIGN ATTRLIST {
3234
+ $$ = mtex2MML_copy2("columnalign=", $2);
3235
+ mtex2MML_free_string($2);
3236
+ };
3237
+
3238
+ rowalign: ROWALIGN ATTRLIST {
3239
+ $$ = mtex2MML_copy2("rowalign=", $2);
3240
+ mtex2MML_free_string($2);
3241
+ };
3242
+
3243
+ align: ALIGN ATTRLIST {
3244
+ $$ = mtex2MML_copy2("align=", $2);
3245
+ mtex2MML_free_string($2);
3246
+ };
3247
+
3248
+ eqrows: EQROWS ATTRLIST {
3249
+ $$ = mtex2MML_copy2("equalrows=", $2);
3250
+ mtex2MML_free_string($2);
3251
+ };
3252
+
3253
+ eqcols: EQCOLS ATTRLIST {
3254
+ $$ = mtex2MML_copy2("equalcolumns=", $2);
3255
+ mtex2MML_free_string($2);
3256
+ };
3257
+
3258
+ rowlines: ROWLINES ATTRLIST {
3259
+ $$ = mtex2MML_copy2("rowlines=", $2);
3260
+ mtex2MML_free_string($2);
3261
+ };
3262
+
3263
+ collines: COLLINES ATTRLIST {
3264
+ $$ = mtex2MML_copy2("columnlines=", $2);
3265
+ mtex2MML_free_string($2);
3266
+ };
3267
+
3268
+ frame: FRAME ATTRLIST {
3269
+ $$ = mtex2MML_copy2("frame=", $2);
3270
+ mtex2MML_free_string($2);
3271
+ };
3272
+
3273
+ padding: PADDING ATTRLIST {
3274
+ char * s1 = mtex2MML_copy3("rowspacing=", $2, " columnspacing=");
3275
+ $$ = mtex2MML_copy2(s1, $2);
3276
+ mtex2MML_free_string(s1);
3277
+ mtex2MML_free_string($2);
3278
+ };
3279
+
3280
+ tableRowList: tableRow {
3281
+ $$ = mtex2MML_copy_string($1);
3282
+ mtex2MML_free_string($1);
3283
+ }
3284
+ | tableRowList ROWSEP tableRow {
3285
+ $$ = mtex2MML_copy3($1, " ", $3);
3286
+ mtex2MML_free_string($1);
3287
+ mtex2MML_free_string($3);
3288
+ };
3289
+
3290
+ tableRow: simpleTableRow {
3291
+ $$ = mtex2MML_copy3("<mtr>", $1, "</mtr>");
3292
+ mtex2MML_free_string($1);
3293
+ }
3294
+ | optsTableRow {
3295
+ $$ = mtex2MML_copy_string($1);
3296
+ mtex2MML_free_string($1);
3297
+ };
3298
+
3299
+ simpleTableRow: tableCell {
3300
+ $$ = mtex2MML_copy_string($1);
3301
+ mtex2MML_free_string($1);
3302
+ }
3303
+ | simpleTableRow COLSEP tableCell {
3304
+ $$ = mtex2MML_copy3($1, " ", $3);
3305
+ mtex2MML_free_string($1);
3306
+ mtex2MML_free_string($3);
3307
+ };
3308
+
3309
+ optsTableRow: ROWOPTS MROWOPEN rowopts MROWCLOSE simpleTableRow {
3310
+ char * s1 = mtex2MML_copy3("<mtr ", $3, ">");
3311
+ $$ = mtex2MML_copy3(s1, $5, "</mtr>");
3312
+ mtex2MML_free_string(s1);
3313
+ mtex2MML_free_string($3);
3314
+ mtex2MML_free_string($5);
3315
+ };
3316
+
3317
+ rowopts: arowopt {
3318
+ $$ = mtex2MML_copy_string($1);
3319
+ mtex2MML_free_string($1);
3320
+ }
3321
+ | rowopts arowopt {
3322
+ $$ = mtex2MML_copy3($1, " ", $2);
3323
+ mtex2MML_free_string($1);
3324
+ mtex2MML_free_string($2);
3325
+ };
3326
+
3327
+ arowopt: colalign {
3328
+ $$ = mtex2MML_copy_string($1);
3329
+ mtex2MML_free_string($1);
3330
+ }
3331
+ | rowalign {
3332
+ $$ = mtex2MML_copy_string($1);
3333
+ mtex2MML_free_string($1);
3334
+ };
3335
+
3336
+ tableCell: {
3337
+ $$ = mtex2MML_copy_string("<mtd/>");
3338
+ }
3339
+ | compoundTermList {
3340
+ if (current_env_type(&environment_data_stack) != ENV_MULTLINE) {
3341
+ $$ = mtex2MML_copy3("<mtd>", $1, "</mtd>");
3342
+ }
3343
+ else {
3344
+ int total_lines = current_env_line_count(&environment_data_stack);
3345
+ if (line_counter == 1) {
3346
+ $$ = mtex2MML_copy3("<mtd columnalign=\"left\">", $1, "</mtd>");
3347
+ line_counter++;
3348
+ }
3349
+ else if (line_counter == total_lines) {
3350
+ $$ = mtex2MML_copy3("<mtd columnalign=\"right\">", $1, "</mtd>");
3351
+ }
3352
+ else {
3353
+ $$ = mtex2MML_copy3("<mtd columnalign=\"center\">", $1, "</mtd>");
3354
+ line_counter++;
3355
+ }
3356
+ }
3357
+
3358
+ mtex2MML_free_string($1);
3359
+ }
3360
+ | CELLOPTS MROWOPEN cellopts MROWCLOSE compoundTermList {
3361
+ char * s1 = mtex2MML_copy3("<mtd ", $3, ">");
3362
+ $$ = mtex2MML_copy3(s1, $5, "</mtd>");
3363
+ mtex2MML_free_string(s1);
3364
+ mtex2MML_free_string($3);
3365
+ mtex2MML_free_string($5);
3366
+ };
3367
+
3368
+ cellopts: acellopt {
3369
+ $$ = mtex2MML_copy_string($1);
3370
+ mtex2MML_free_string($1);
3371
+ }
3372
+ | cellopts acellopt {
3373
+ $$ = mtex2MML_copy3($1, " ", $2);
3374
+ mtex2MML_free_string($1);
3375
+ mtex2MML_free_string($2);
3376
+ };
3377
+
3378
+ acellopt: colalign {
3379
+ $$ = mtex2MML_copy_string($1);
3380
+ mtex2MML_free_string($1);
3381
+ }
3382
+ | rowalign {
3383
+ $$ = mtex2MML_copy_string($1);
3384
+ mtex2MML_free_string($1);
3385
+ }
3386
+ | rowspan {
3387
+ $$ = mtex2MML_copy_string($1);
3388
+ mtex2MML_free_string($1);
3389
+ }
3390
+ | colspan {
3391
+ $$ = mtex2MML_copy_string($1);
3392
+ mtex2MML_free_string($1);
3393
+ };
3394
+
3395
+ rowspan: ROWSPAN ATTRLIST {
3396
+ $$ = mtex2MML_copy2("rowspan=", $2);
3397
+ mtex2MML_free_string($2);
3398
+ };
3399
+
3400
+ colspan: COLSPAN ATTRLIST {
3401
+ $$ = mtex2MML_copy2("columnspan=", $2);
3402
+ mtex2MML_free_string($2);
3403
+ };
3404
+
3405
+ %%
3406
+
3407
+ // see https://troydhanson.github.io/uthash/utarray.html#_structures
3408
+ void envdata_copy(void *_dst, const void *_src)
3409
+ {
3410
+ envdata_t *dst = (envdata_t*)_dst, *src = (envdata_t*)_src;
3411
+ dst->rowspacing = src->rowspacing ? strdup(src->rowspacing) : NULL;
3412
+ dst->rowlines = src->rowlines ? strdup(src->rowlines) : NULL;
3413
+ dst->environmentType = src->environmentType;
3414
+ dst->line_count = src->line_count;
3415
+ }
3416
+
3417
+ void envdata_dtor(void *_elt)
3418
+ {
3419
+ envdata_t *elt = (envdata_t*)_elt;
3420
+ if (elt->rowspacing) { free(elt->rowspacing); }
3421
+ if (elt->rowlines) { free(elt->rowlines); }
3422
+ }
3423
+
3424
+ UT_icd envdata_icd = {sizeof(envdata_t), NULL, envdata_copy, envdata_dtor};
3425
+
3426
+ const char *format_additions(const char *buffer)
3427
+ {
3428
+ utarray_new(environment_data_stack, &envdata_icd);
3429
+
3430
+ if (colors == NULL)
3431
+ create_css_colors(&colors);
3432
+
3433
+ encase = NONE;
3434
+ line_counter = 1;
3435
+ env_replacements(&environment_data_stack, &encase, buffer);
3436
+ }
3437
+
3438
+ void free_additions()
3439
+ {
3440
+ utarray_free(environment_data_stack);
3441
+
3442
+ struct css_colors *c = NULL, *tmp;
3443
+
3444
+ HASH_ITER(hh, colors, c, tmp) {
3445
+ HASH_DEL(colors, c);
3446
+ free(c);
3447
+ }
3448
+ }
3449
+
3450
+ char * mtex2MML_global_parse (const char * buffer, unsigned long length, int global_start)
3451
+ {
3452
+ global_label = global_start;
3453
+ return mtex2MML_parse(buffer, length);
3454
+ }
3455
+
3456
+ char * mtex2MML_parse (const char * buffer, unsigned long length)
3457
+ {
3458
+ char * mathml = 0;
3459
+
3460
+ int result;
3461
+
3462
+ format_additions(buffer);
3463
+ mtex2MML_setup (buffer, length);
3464
+ mtex2MML_restart ();
3465
+
3466
+ result = mtex2MML_yyparse (&mathml);
3467
+
3468
+ free_additions();
3469
+
3470
+ /* See Bison documentation/maliciousness test: http://bit.ly/1IbpOja
3471
+ 1 if parse error, 2 if memory exhuastion, etc. */
3472
+ if (result > 0) {
3473
+ if (mathml) {
3474
+ mtex2MML_free_string (mathml);
3475
+ mathml = 0;
3476
+ }
3477
+ return NULL;
3478
+ }
3479
+
3480
+ return mathml;
3481
+ }
3482
+
3483
+ int mtex2MML_filter (const char * buffer, unsigned long length)
3484
+ {
3485
+ global_label = 1;
3486
+ format_additions(buffer);
3487
+ mtex2MML_setup (buffer, length);
3488
+ mtex2MML_restart ();
3489
+
3490
+ int result = mtex2MML_yyparse (0);
3491
+ free_additions();
3492
+
3493
+ return result;
3494
+ }
3495
+
3496
+ #define MTEX_DELIMITER_DOLLAR 0
3497
+ #define MTEX_DELIMITER_DOUBLE 1
3498
+ #define MTEX_DELIMITER_SQUARE 2
3499
+
3500
+ static char * mtex2MML_last_error = 0;
3501
+
3502
+ static void mtex2MML_keep_error (const char * msg)
3503
+ {
3504
+ if (mtex2MML_last_error)
3505
+ {
3506
+ mtex2MML_free_string (mtex2MML_last_error);
3507
+ mtex2MML_last_error = 0;
3508
+ }
3509
+ mtex2MML_last_error = mtex2MML_copy_escaped (msg);
3510
+ }
3511
+
3512
+ int mtex2MML_html_filter (const char * buffer, unsigned long length)
3513
+ {
3514
+ mtex2MML_do_html_filter (buffer, length, 0);
3515
+ }
3516
+
3517
+ int mtex2MML_strict_html_filter (const char * buffer, unsigned long length)
3518
+ {
3519
+ mtex2MML_do_html_filter (buffer, length, 1);
3520
+ }
3521
+
3522
+ int mtex2MML_do_html_filter (const char * buffer, unsigned long length, const int forbid_markup)
3523
+ {
3524
+ int result = 0;
3525
+
3526
+ int type = 0;
3527
+ int skip = 0;
3528
+ int match = 0;
3529
+
3530
+ const char * ptr1 = buffer;
3531
+ const char * ptr2 = 0;
3532
+
3533
+ const char * end = buffer + length;
3534
+
3535
+ char * mathml = 0;
3536
+
3537
+ void (*save_error_fn) (const char * msg) = mtex2MML_error;
3538
+
3539
+ mtex2MML_error = mtex2MML_keep_error;
3540
+
3541
+ _until_math:
3542
+ ptr2 = ptr1;
3543
+
3544
+ while (ptr2 < end)
3545
+ {
3546
+ if (*ptr2 == '$') break;
3547
+ if ((*ptr2 == '\\') && (ptr2 + 1 < end))
3548
+ {
3549
+ if (*(ptr2+1) == '[') break;
3550
+ }
3551
+ ++ptr2;
3552
+ }
3553
+ if (mtex2MML_write && ptr2 > ptr1)
3554
+ (*mtex2MML_write) (ptr1, ptr2 - ptr1);
3555
+
3556
+ if (ptr2 == end) goto _finish;
3557
+
3558
+ _until_html:
3559
+ ptr1 = ptr2;
3560
+
3561
+ if (ptr2 + 1 < end)
3562
+ {
3563
+ if ((*ptr2 == '\\') && (*(ptr2+1) == '['))
3564
+ {
3565
+ type = MTEX_DELIMITER_SQUARE;
3566
+ ptr2 += 2;
3567
+ }
3568
+ else if ((*ptr2 == '$') && (*(ptr2+1) == '$'))
3569
+ {
3570
+ type = MTEX_DELIMITER_DOUBLE;
3571
+ ptr2 += 2;
3572
+ }
3573
+ else
3574
+ {
3575
+ type = MTEX_DELIMITER_DOLLAR;
3576
+ ptr2 += 2;
3577
+ }
3578
+ }
3579
+ else goto _finish;
3580
+
3581
+ skip = 0;
3582
+ match = 0;
3583
+
3584
+ while (ptr2 < end)
3585
+ {
3586
+ switch (*ptr2)
3587
+ {
3588
+ case '<':
3589
+ case '>':
3590
+ if (forbid_markup == 1) skip = 1;
3591
+ break;
3592
+
3593
+ case '\\':
3594
+ if (ptr2 + 1 < end)
3595
+ {
3596
+ if (*(ptr2 + 1) == '[')
3597
+ {
3598
+ skip = 1;
3599
+ }
3600
+ else if (*(ptr2 + 1) == ']')
3601
+ {
3602
+ if (type == MTEX_DELIMITER_SQUARE)
3603
+ {
3604
+ ptr2 += 2;
3605
+ match = 1;
3606
+ }
3607
+ else
3608
+ {
3609
+ skip = 1;
3610
+ }
3611
+ }
3612
+ }
3613
+ break;
3614
+
3615
+ case '$':
3616
+ if (type == MTEX_DELIMITER_SQUARE)
3617
+ {
3618
+ skip = 1;
3619
+ }
3620
+ else if (ptr2 + 1 < end)
3621
+ {
3622
+ if (*(ptr2 + 1) == '$')
3623
+ {
3624
+ if (type == MTEX_DELIMITER_DOLLAR)
3625
+ {
3626
+ ptr2++;
3627
+ match = 1;
3628
+ }
3629
+ else
3630
+ {
3631
+ ptr2 += 2;
3632
+ match = 1;
3633
+ }
3634
+ }
3635
+ else
3636
+ {
3637
+ if (type == MTEX_DELIMITER_DOLLAR)
3638
+ {
3639
+ ptr2++;
3640
+ match = 1;
3641
+ }
3642
+ else
3643
+ {
3644
+ skip = 1;
3645
+ }
3646
+ }
3647
+ }
3648
+ else
3649
+ {
3650
+ if (type == MTEX_DELIMITER_DOLLAR)
3651
+ {
3652
+ ptr2++;
3653
+ match = 1;
3654
+ }
3655
+ else
3656
+ {
3657
+ skip = 1;
3658
+ }
3659
+ }
3660
+ break;
3661
+
3662
+ default:
3663
+ break;
3664
+ }
3665
+ if (skip || match) break;
3666
+
3667
+ ++ptr2;
3668
+ }
3669
+ if (skip)
3670
+ {
3671
+ if (type == MTEX_DELIMITER_DOLLAR)
3672
+ {
3673
+ if (mtex2MML_write)
3674
+ (*mtex2MML_write) (ptr1, 1);
3675
+ ptr1++;
3676
+ }
3677
+ else
3678
+ {
3679
+ if (mtex2MML_write)
3680
+ (*mtex2MML_write) (ptr1, 2);
3681
+ ptr1 += 2;
3682
+ }
3683
+ goto _until_math;
3684
+ }
3685
+ if (match)
3686
+ {
3687
+ mathml = mtex2MML_parse (ptr1, ptr2 - ptr1);
3688
+
3689
+ if (mathml)
3690
+ {
3691
+ if (mtex2MML_write_mathml)
3692
+ (*mtex2MML_write_mathml) (mathml);
3693
+ mtex2MML_free_string (mathml);
3694
+ mathml = 0;
3695
+ }
3696
+ else
3697
+ {
3698
+ ++result;
3699
+ if (mtex2MML_write)
3700
+ {
3701
+ if (type == MTEX_DELIMITER_DOLLAR)
3702
+ (*mtex2MML_write) ("<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><merror><mtext>", 0);
3703
+ else
3704
+ (*mtex2MML_write) ("<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><merror><mtext>", 0);
3705
+
3706
+ (*mtex2MML_write) (mtex2MML_last_error, 0);
3707
+ (*mtex2MML_write) ("</mtext></merror></math>", 0);
3708
+ }
3709
+ }
3710
+ ptr1 = ptr2;
3711
+
3712
+ goto _until_math;
3713
+ }
3714
+ if (mtex2MML_write)
3715
+ (*mtex2MML_write) (ptr1, ptr2 - ptr1);
3716
+
3717
+ _finish:
3718
+ if (mtex2MML_last_error)
3719
+ {
3720
+ mtex2MML_free_string (mtex2MML_last_error);
3721
+ mtex2MML_last_error = 0;
3722
+ }
3723
+ mtex2MML_error = save_error_fn;
3724
+
3725
+ return result;
3726
+ }