/itexToMML

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