/itexToMML

To download this project, use:
bzr branch http://golem.ph.utexas.edu/~distler/code/itexToMML/
61 by Jacques Distler
itex2MML 1.4.7: \mathraisebox{voffset}[height][depth]{content}
1
/*             itex2MML 1.4.7
2
 *   itex2MML.y last modified 9/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
61 by Jacques Distler
itex2MML 1.4.7: \mathraisebox{voffset}[height][depth]{content}
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 RAISEBOX NEG
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
61 by Jacques Distler
itex2MML 1.4.7: \mathraisebox{voffset}[height][depth]{content}
532
| raisebox
1 by Jacques Distler
Initial commit.
533
| munder
534
| mover
535
| bar
536
| vec
537
| hat
538
| dot
539
| ddot
38 by Jacques Distler
itex2MML 1.3.14: \dddot{} and \ddddot{}
540
| dddot
541
| ddddot
1 by Jacques Distler
Initial commit.
542
| check
543
| tilde
544
| moverbrace
545
| munderbrace
34 by Jacques Distler
itex2MML 1.3.10
546
| munderline
1 by Jacques Distler
Initial commit.
547
| munderover
548
| emptymrow
37 by Jacques Distler
itex2MML 1.3.13
549
| mathclap
550
| mathllap
551
| mathrlap
1 by Jacques Distler
Initial commit.
552
| displaystyle
553
| textstyle
554
| textsize
555
| scriptsize
556
| scriptscriptsize
557
| italics
558
| bold
559
| roman
560
| rmchars
561
| bbold
562
| frak
16 by Jacques Distler
Slashed letters
563
| slashed
50 by Jacques Distler
itex2MML 1.3.25
564
| boxed
1 by Jacques Distler
Initial commit.
565
| cal
566
| space
567
| textstring
568
| thinspace
569
| medspace
570
| thickspace
571
| quad
572
| qquad
573
| negspace
574
| phantom
575
| href
576
| statusline
40 by Jacques Distler
itex2MML 1.3.16: \tooltip{}{}
577
| tooltip
1 by Jacques Distler
Initial commit.
578
| toggle
579
| fghighlight
580
| bghighlight
581
| color
582
| texover
21 by Jacques Distler
\binom
583
| texatop
1 by Jacques Distler
Initial commit.
584
| MROWOPEN closedTerm MROWCLOSE {
585
  $$ = itex2MML_copy_string($2);
586
  itex2MML_free_string($2);
587
}
588
| MROWOPEN compoundTermList MROWCLOSE {
589
  $$ = itex2MML_copy3("<mrow>", $2, "</mrow>");
590
  itex2MML_free_string($2);
591
}
592
| left compoundTermList right {
593
  char * s1 = itex2MML_copy3("<mrow>", $1, $2);
594
  $$ = itex2MML_copy3(s1, $3, "</mrow>");
595
  itex2MML_free_string(s1);
596
  itex2MML_free_string($1);
597
  itex2MML_free_string($2);
598
  itex2MML_free_string($3);
599
}
600
| mathenv
601
| substack
602
| pmod
603
| unrecognized;
604
605
left: LEFT LEFTDELIM {
606
  itex2MML_rowposn = 2;
607
  $$ = itex2MML_copy3("<mo>", $2, "</mo>");
608
  itex2MML_free_string($2);
609
}
610
| LEFT OTHERDELIM {
611
  itex2MML_rowposn = 2;
612
  $$ = itex2MML_copy3("<mo>", $2, "</mo>");
613
  itex2MML_free_string($2);
614
}
615
| LEFT PERIODDELIM {
616
  itex2MML_rowposn = 2;
617
  $$ = itex2MML_copy_string("");
618
  itex2MML_free_string($2);
619
};
620
621
right: RIGHT RIGHTDELIM {
622
  $$ = itex2MML_copy3("<mo>", $2, "</mo>");
623
  itex2MML_free_string($2);
624
}
625
| RIGHT OTHERDELIM {
626
  $$ = itex2MML_copy3("<mo>", $2, "</mo>");
627
  itex2MML_free_string($2);
628
}
629
| RIGHT PERIODDELIM {
630
  $$ = itex2MML_copy_string("");
631
  itex2MML_free_string($2);
632
};
633
634
bigdelim: BIG LEFTDELIM {
635
  itex2MML_rowposn = 2;
636
  $$ = itex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
637
  itex2MML_free_string($2);
638
} 
639
| BIG RIGHTDELIM {
640
  $$ = itex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
641
  itex2MML_free_string($2);
642
}
643
| BIG OTHERDELIM {
644
  $$ = itex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
645
  itex2MML_free_string($2);
646
}
647
| BBIG LEFTDELIM {
648
  itex2MML_rowposn = 2;
649
  $$ = itex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
650
  itex2MML_free_string($2);
651
}
652
| BBIG RIGHTDELIM {
653
  $$ = itex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
654
  itex2MML_free_string($2);
655
}
656
| BBIG OTHERDELIM {
657
  $$ = itex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
658
  itex2MML_free_string($2);
659
}
660
| BIGG LEFTDELIM {
661
  itex2MML_rowposn = 2;
662
  $$ = itex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
663
  itex2MML_free_string($2);
664
} 
665
| BIGG RIGHTDELIM {
666
  $$ = itex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
667
  itex2MML_free_string($2);
668
}
669
| BIGG OTHERDELIM {
670
  $$ = itex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
671
  itex2MML_free_string($2);
672
}
673
| BBIGG LEFTDELIM {
674
  itex2MML_rowposn = 2;
675
  $$ = itex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
676
  itex2MML_free_string($2);
677
}
678
| BBIGG RIGHTDELIM {
679
  $$ = itex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
680
  itex2MML_free_string($2);
681
}
682
| BBIGG OTHERDELIM {
683
  $$ = itex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
684
  itex2MML_free_string($2);
685
}
22 by Jacques Distler
SVG Environment
686
|BIGL LEFTDELIM {
1 by Jacques Distler
Initial commit.
687
  itex2MML_rowposn = 2;
688
  $$ = itex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
689
  itex2MML_free_string($2);
690
}
691
| BIGL OTHERDELIM {
692
  itex2MML_rowposn = 2;
693
  $$ = itex2MML_copy3("<mo maxsize=\"1.2em\" minsize=\"1.2em\">", $2, "</mo>");
694
  itex2MML_free_string($2);
695
}
696
| BBIGL LEFTDELIM {
697
  itex2MML_rowposn = 2;
698
  $$ = itex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
699
  itex2MML_free_string($2);
700
}
701
| BBIGL OTHERDELIM {
702
  itex2MML_rowposn = 2;
703
  $$ = itex2MML_copy3("<mo maxsize=\"1.8em\" minsize=\"1.8em\">", $2, "</mo>");
704
  itex2MML_free_string($2);
705
}
706
| BIGGL LEFTDELIM {
707
  itex2MML_rowposn = 2;
708
  $$ = itex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
709
  itex2MML_free_string($2);
710
} 
711
| BIGGL OTHERDELIM {
712
  itex2MML_rowposn = 2;
713
  $$ = itex2MML_copy3("<mo maxsize=\"2.4em\" minsize=\"2.4em\">", $2, "</mo>");
714
  itex2MML_free_string($2);
715
}
716
| BBIGGL LEFTDELIM {
717
  itex2MML_rowposn = 2;
718
  $$ = itex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
719
  itex2MML_free_string($2);
720
}
721
| BBIGGL OTHERDELIM {
722
  itex2MML_rowposn = 2;
723
  $$ = itex2MML_copy3("<mo maxsize=\"3em\" minsize=\"3em\">", $2, "</mo>");
724
  itex2MML_free_string($2);
725
};
726
727
unrecognized: UNKNOWNCHAR {
728
  $$ = itex2MML_copy_string("<merror><mtext>Unknown character</mtext></merror>");
729
};
730
731
unaryminus: UNARYMINUS {
732
  $$ = itex2MML_copy_string("<mo lspace=\"verythinmathspace\" rspace=\"0em\">&minus;</mo>");
733
};
734
735
unaryplus: UNARYPLUS {
736
  $$ = itex2MML_copy_string("<mo lspace=\"verythinmathspace\" rspace=\"0em\">+</mo>");
737
};
738
739
mi: MI;
740
741
mib: MIB {
742
  itex2MML_rowposn=2;
743
  $$ = itex2MML_copy3("<mi>", $1, "</mi>");
744
  itex2MML_free_string($1);
745
};
746
60 by Jacques Distler
itex2MML 1.4.6
747
mn: MN
748
| ITEXNUM TEXTSTRING {
749
  itex2MML_rowposn = 2;
750
  $$ = itex2MML_copy_string($2);
751
  itex2MML_free_string($2);
752
};
1 by Jacques Distler
Initial commit.
753
754
mob: MOB {
755
  itex2MML_rowposn = 2;
756
  $$ = itex2MML_copy3("<mo lspace=\"thinmathspace\" rspace=\"thinmathspace\">", $1, "</mo>");
757
  itex2MML_free_string($1);
758
};
759
760
mo: mob
761
| bigdelim
762
| MO {
763
  itex2MML_rowposn = 2;
764
  $$ = itex2MML_copy3("<mo>", $1, "</mo>");
765
  itex2MML_free_string($1);
766
}
767
| MOL {
768
  itex2MML_rowposn = 2;
769
  $$ = itex2MML_copy3("<mo>", $1, "</mo>");
770
  itex2MML_free_string($1);
771
}
18 by Jacques Distler
Minor Tweaks
772
| MOLL {
773
  itex2MML_rowposn = 2;
774
  $$ = itex2MML_copy3("<mstyle scriptlevel=\"0\"><mo>", $1, "</mo></mstyle>");
775
  itex2MML_free_string($1);
776
}
1 by Jacques Distler
Initial commit.
777
| RIGHTDELIM {
778
  $$ = itex2MML_copy3("<mo stretchy=\"false\">", $1, "</mo>");
779
  itex2MML_free_string($1);
780
}
781
| LEFTDELIM {
782
  itex2MML_rowposn = 2;
783
  $$ = itex2MML_copy3("<mo stretchy=\"false\">", $1, "</mo>");
784
  itex2MML_free_string($1);
785
}
786
| OTHERDELIM {
787
  $$ = itex2MML_copy3("<mo stretchy=\"false\">", $1, "</mo>");
788
  itex2MML_free_string($1);
789
}
790
| MOF {
791
  $$ = itex2MML_copy3("<mo stretchy=\"false\">", $1, "</mo>");
792
  itex2MML_free_string($1);
793
}
794
| PERIODDELIM {
795
  $$ = itex2MML_copy3("<mo>", $1, "</mo>");
796
  itex2MML_free_string($1);
797
}
798
| MOS {
799
  itex2MML_rowposn=2;
800
  $$ = itex2MML_copy3("<mo lspace=\"mediummathspace\" rspace=\"mediummathspace\">", $1, "</mo>");
801
  itex2MML_free_string($1);
802
}
803
| MOP {
804
  itex2MML_rowposn = 2;
805
  $$ = itex2MML_copy3("<mo lspace=\"0em\" rspace=\"thinmathspace\">", $1, "</mo>");
806
  itex2MML_free_string($1);
807
}
37 by Jacques Distler
itex2MML 1.3.13
808
| MOR {
809
  itex2MML_rowposn = 2;
810
  $$ = itex2MML_copy3("<mo lspace=\"verythinmathspace\">", $1, "</mo>");
811
  itex2MML_free_string($1);
812
}
39 by Jacques Distler
itex2MML 1.3.15: \mathrel and its cousins
813
| OPERATORNAME TEXTSTRING {
814
  itex2MML_rowposn = 2;
815
  $$ = itex2MML_copy3("<mo lspace=\"0em\" rspace=\"thinmathspace\">", $2, "</mo>");
816
  itex2MML_free_string($2);
817
}
1 by Jacques Distler
Initial commit.
818
| MATHOP TEXTSTRING {
819
  itex2MML_rowposn = 2;
39 by Jacques Distler
itex2MML 1.3.15: \mathrel and its cousins
820
  $$ = itex2MML_copy3("<mo lspace=\"thinmathspace\" rspace=\"thinmathspace\">", $2, "</mo>");
821
  itex2MML_free_string($2);
822
}
823
| MATHBIN TEXTSTRING {
824
  itex2MML_rowposn = 2;
825
  $$ = itex2MML_copy3("<mo lspace=\"mediummathspace\" rspace=\"mediummathspace\">", $2, "</mo>");
826
  itex2MML_free_string($2);
827
}
828
| MATHREL TEXTSTRING {
829
  itex2MML_rowposn = 2;
830
  $$ = itex2MML_copy3("<mo lspace=\"thickmathspace\" rspace=\"thickmathspace\">", $2, "</mo>");
1 by Jacques Distler
Initial commit.
831
  itex2MML_free_string($2);
832
};
833
834
space: SPACE ST INTONE END ST INTTWO END ST INTTHREE END {
835
  char * s1 = itex2MML_copy3("<mspace height=\"", $3, "ex\" depth=\"");
836
  char * s2 = itex2MML_copy3($6, "ex\" width=\"", $9);
837
  $$ = itex2MML_copy3(s1, s2, "em\"></mspace>");
838
  itex2MML_free_string(s1);
839
  itex2MML_free_string(s2);
840
  itex2MML_free_string($3);
841
  itex2MML_free_string($6);
842
  itex2MML_free_string($9);
843
};
844
845
statusline: STATLINE TEXTSTRING closedTerm {
846
  char * s1 = itex2MML_copy3("<maction actiontype=\"statusline\">", $3, "<mtext>");
847
  $$ = itex2MML_copy3(s1, $2, "</mtext></maction>");
848
  itex2MML_free_string(s1);
849
  itex2MML_free_string($2);
850
  itex2MML_free_string($3);
851
};
852
40 by Jacques Distler
itex2MML 1.3.16: \tooltip{}{}
853
tooltip: TOOLTIP TEXTSTRING closedTerm {
854
  char * s1 = itex2MML_copy3("<maction actiontype=\"tooltip\">", $3, "<mtext>");
855
  $$ = itex2MML_copy3(s1, $2, "</mtext></maction>");
856
  itex2MML_free_string(s1);
857
  itex2MML_free_string($2);
858
  itex2MML_free_string($3);
859
};
860
1 by Jacques Distler
Initial commit.
861
toggle: TOGGLE closedTerm closedTerm {
862
  char * s1 = itex2MML_copy3("<maction actiontype=\"toggle\" selection=\"2\">", $2, " ");
863
  $$ = itex2MML_copy3(s1, $3, "</maction>");
864
  itex2MML_free_string(s1);
865
  itex2MML_free_string($2);
866
  itex2MML_free_string($3);
867
};
868
869
fghighlight: FGHIGHLIGHT ATTRLIST closedTerm {
870
  char * s1 = itex2MML_copy3("<maction actiontype=\"highlight\" other='color=", $2, "'>");
871
  $$ = itex2MML_copy3(s1, $3, "</maction>");
872
  itex2MML_free_string(s1);
873
  itex2MML_free_string($2);
874
  itex2MML_free_string($3);
875
};
876
877
bghighlight: BGHIGHLIGHT ATTRLIST closedTerm {
878
  char * s1 = itex2MML_copy3("<maction actiontype=\"highlight\" other='background=", $2, "'>");
879
  $$ = itex2MML_copy3(s1, $3, "</maction>");
880
  itex2MML_free_string(s1);
881
  itex2MML_free_string($2);
882
  itex2MML_free_string($3);
883
};
884
885
color: COLOR ATTRLIST compoundTermList {
886
  char * s1 = itex2MML_copy3("<mstyle mathcolor=", $2, ">");
887
  $$ = itex2MML_copy3(s1, $3, "</mstyle>");
888
  itex2MML_free_string(s1);
889
  itex2MML_free_string($2);
890
  itex2MML_free_string($3);
891
}
892
| BGCOLOR ATTRLIST compoundTermList {
893
  char * s1 = itex2MML_copy3("<mstyle mathbackground=", $2, ">");
894
  $$ = itex2MML_copy3(s1, $3, "</mstyle>");
895
  itex2MML_free_string(s1);
896
  itex2MML_free_string($2);
897
  itex2MML_free_string($3);
898
};
899
37 by Jacques Distler
itex2MML 1.3.13
900
mathrlap: RLAP closedTerm {
33 by Jacques Distler
itex2MML 1.3.9: implement \rlap
901
  $$ = itex2MML_copy3("<mpadded width=\"0\">", $2, "</mpadded>");
902
  itex2MML_free_string($2);
903
};
904
37 by Jacques Distler
itex2MML 1.3.13
905
mathllap: LLAP closedTerm {
906
  $$ = itex2MML_copy3("<mpadded width=\"0\" lspace=\"-100%width\">", $2, "</mpadded>");
907
  itex2MML_free_string($2);
908
};
909
910
mathclap: CLAP closedTerm {
911
  $$ = itex2MML_copy3("<mpadded width=\"0\" lspace=\"-50%width\">", $2, "</mpadded>");
912
  itex2MML_free_string($2);
913
};
914
1 by Jacques Distler
Initial commit.
915
textstring: TEXTBOX TEXTSTRING {
916
  $$ = itex2MML_copy3("<mtext>", $2, "</mtext>");
917
  itex2MML_free_string($2);
918
};
919
920
displaystyle: DISPLAY closedTerm {
921
  $$ = itex2MML_copy3("<mstyle displaystyle=\"true\">", $2, "</mstyle>");
922
  itex2MML_free_string($2);
923
};
924
925
textstyle: TEXTSTY closedTerm {
926
  $$ = itex2MML_copy3("<mstyle displaystyle=\"false\">", $2, "</mstyle>");
927
  itex2MML_free_string($2);
928
};
929
930
textsize: TEXTSIZE closedTerm {
931
  $$ = itex2MML_copy3("<mstyle scriptlevel=\"0\">", $2, "</mstyle>");
932
  itex2MML_free_string($2);
933
};
934
935
scriptsize: SCSIZE closedTerm {
936
  $$ = itex2MML_copy3("<mstyle scriptlevel=\"1\">", $2, "</mstyle>");
937
  itex2MML_free_string($2);
938
};
939
940
scriptscriptsize: SCSCSIZE closedTerm {
941
  $$ = itex2MML_copy3("<mstyle scriptlevel=\"2\">", $2, "</mstyle>");
942
  itex2MML_free_string($2);
943
};
944
945
italics: ITALICS closedTerm {
946
  $$ = itex2MML_copy3("<mstyle mathvariant=\"italic\">", $2, "</mstyle>");
947
  itex2MML_free_string($2);
948
};
949
16 by Jacques Distler
Slashed letters
950
slashed: SLASHED closedTerm {
50 by Jacques Distler
itex2MML 1.3.25
951
  $$ = itex2MML_copy3("<menclose notation=\"updiagonalstrike\">", $2, "</menclose>");
952
  itex2MML_free_string($2);
953
};
954
955
boxed: BOXED closedTerm {
956
  $$ = itex2MML_copy3("<menclose notation=\"box\">", $2, "</menclose>");
16 by Jacques Distler
Slashed letters
957
  itex2MML_free_string($2);
958
};
959
1 by Jacques Distler
Initial commit.
960
bold: BOLD closedTerm {
961
  $$ = itex2MML_copy3("<mstyle mathvariant=\"bold\">", $2, "</mstyle>");
962
  itex2MML_free_string($2);
963
};
964
965
roman: RM ST rmchars END {
966
  $$ = itex2MML_copy3("<mi mathvariant=\"normal\">", $3, "</mi>");
967
  itex2MML_free_string($3);
968
};
969
970
rmchars: RMCHAR {
971
  $$ = itex2MML_copy_string($1);
972
  itex2MML_free_string($1);
973
}
974
| rmchars RMCHAR {
975
  $$ = itex2MML_copy2($1, $2);
976
  itex2MML_free_string($1);
977
  itex2MML_free_string($2);
978
};
979
32 by Jacques Distler
itex2MML 1.38: Support for Blackboard Bold Digits
980
bbold: BB ST bbchars END {
1 by Jacques Distler
Initial commit.
981
  $$ = itex2MML_copy3("<mi>", $3, "</mi>");
982
  itex2MML_free_string($3);
983
};
984
32 by Jacques Distler
itex2MML 1.38: Support for Blackboard Bold Digits
985
bbchars: bbchar {
1 by Jacques Distler
Initial commit.
986
  $$ = itex2MML_copy_string($1);
987
  itex2MML_free_string($1);
988
}
32 by Jacques Distler
itex2MML 1.38: Support for Blackboard Bold Digits
989
| bbchars bbchar {
1 by Jacques Distler
Initial commit.
990
  $$ = itex2MML_copy2($1, $2);
991
  itex2MML_free_string($1);
992
  itex2MML_free_string($2);
993
};
994
32 by Jacques Distler
itex2MML 1.38: Support for Blackboard Bold Digits
995
bbchar: BBLOWERCHAR {
26 by Jacques Distler
Lowercase Blackboard Bold Letters
996
  $$ = itex2MML_copy3("&", $1, "opf;");
1 by Jacques Distler
Initial commit.
997
  itex2MML_free_string($1);
998
}
999
| BBUPPERCHAR {
1000
  $$ = itex2MML_copy3("&", $1, "opf;");
1001
  itex2MML_free_string($1);
32 by Jacques Distler
itex2MML 1.38: Support for Blackboard Bold Digits
1002
}
1003
| BBDIGIT {
1004
  /* Blackboard digits 0-9 correspond to Unicode characters 0x1D7D8-0x1D7E1 */
1005
  char * end = $1 + 1;
1006
  int code = 0x1D7D8 + strtoul($1, &end, 10);
1007
  $$ = itex2MML_character_reference(code);
1008
  itex2MML_free_string($1);
1 by Jacques Distler
Initial commit.
1009
};
1010
1011
frak: FRAK ST frakletters END {
1012
  $$ = itex2MML_copy3("<mi>", $3, "</mi>");
1013
  itex2MML_free_string($3);
1014
};
1015
1016
frakletters: frakletter {
1017
  $$ = itex2MML_copy_string($1);
1018
  itex2MML_free_string($1);
1019
}
1020
| frakletters frakletter {
1021
  $$ = itex2MML_copy2($1, $2);
1022
  itex2MML_free_string($1);
1023
  itex2MML_free_string($2);
1024
};
1025
1026
frakletter: FRAKCHAR {
1027
  $$ = itex2MML_copy3("&", $1, "fr;");
1028
  itex2MML_free_string($1);
1029
};
1030
1031
cal: CAL ST calletters END {
1032
  $$ = itex2MML_copy3("<mi>", $3, "</mi>");
1033
  itex2MML_free_string($3);
1034
};
1035
1036
calletters: calletter {
1037
  $$ = itex2MML_copy_string($1);
1038
  itex2MML_free_string($1);
1039
}
1040
| calletters calletter {
1041
  $$ = itex2MML_copy2($1, $2);
1042
  itex2MML_free_string($1);
1043
  itex2MML_free_string($2);
1044
};
1045
1046
calletter: CALCHAR {
1047
  $$ = itex2MML_copy3("&", $1, "scr;");
1048
  itex2MML_free_string($1);
1049
};
1050
1051
thinspace: THINSPACE {
1052
  $$ = itex2MML_copy_string("<mspace width=\"thinmathspace\"></mspace>");
1053
};
1054
1055
medspace: MEDSPACE {
1056
  $$ = itex2MML_copy_string("<mspace width=\"mediummathspace\"></mspace>");
1057
};
1058
1059
thickspace: THICKSPACE {
1060
  $$ = itex2MML_copy_string("<mspace width=\"thickmathspace\"></mspace>");
1061
};
1062
1063
quad: QUAD {
1064
  $$ = itex2MML_copy_string("<mspace width=\"1em\"></mspace>");
1065
};
1066
1067
qquad: QQUAD {
1068
  $$ = itex2MML_copy_string("<mspace width=\"2em\"></mspace>");
1069
};
1070
1071
negspace: NEGSPACE {
1072
  $$ = itex2MML_copy_string("<mspace width=\"-0.1667 em\"></mspace>");
1073
};
1074
1075
phantom: PHANTOM closedTerm {
1076
  $$ = itex2MML_copy3("<mphantom>", $2, "</mphantom>");
1077
  itex2MML_free_string($2);
1078
};
1079
1080
href: HREF TEXTSTRING closedTerm {
60 by Jacques Distler
itex2MML 1.4.6
1081
  char * s1 = itex2MML_copy3("<mrow href=\"", $2, "\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\"");
1082
  char * s2 = itex2MML_copy3(s1, $2, "\">");
1083
  $$ = itex2MML_copy3(s2, $3, "</mrow>");
1 by Jacques Distler
Initial commit.
1084
  itex2MML_free_string(s1);
60 by Jacques Distler
itex2MML 1.4.6
1085
  itex2MML_free_string(s2);
1 by Jacques Distler
Initial commit.
1086
  itex2MML_free_string($2);
1087
  itex2MML_free_string($3);
1088
};
1089
1090
tensor: TENSOR closedTerm MROWOPEN subsupList MROWCLOSE {
1091
  char * s1 = itex2MML_copy3("<mmultiscripts>", $2, $4);
1092
  $$ = itex2MML_copy2(s1, "</mmultiscripts>");
1093
  itex2MML_free_string(s1);
1094
  itex2MML_free_string($2);
1095
  itex2MML_free_string($4);
1096
}
1097
| TENSOR closedTerm subsupList {
1098
  char * s1 = itex2MML_copy3("<mmultiscripts>", $2, $3);
1099
  $$ = itex2MML_copy2(s1, "</mmultiscripts>");
1100
  itex2MML_free_string(s1);
1101
  itex2MML_free_string($2);
1102
  itex2MML_free_string($3);
1103
};
1104
1105
multi: MULTI MROWOPEN subsupList MROWCLOSE closedTerm MROWOPEN subsupList MROWCLOSE {
1106
  char * s1 = itex2MML_copy3("<mmultiscripts>", $5, $7);
1107
  char * s2 = itex2MML_copy3("<mprescripts></mprescripts>", $3, "</mmultiscripts>");
1108
  $$ = itex2MML_copy2(s1, s2);
1109
  itex2MML_free_string(s1);
1110
  itex2MML_free_string(s2);
1111
  itex2MML_free_string($3);
1112
  itex2MML_free_string($5);
1113
  itex2MML_free_string($7);
1114
}
1115
| MULTI MROWOPEN subsupList MROWCLOSE closedTerm EMPTYMROW {
1116
  char * s1 = itex2MML_copy2("<mmultiscripts>", $5);
1117
  char * s2 = itex2MML_copy3("<mprescripts></mprescripts>", $3, "</mmultiscripts>");
1118
  $$ = itex2MML_copy2(s1, s2);
1119
  itex2MML_free_string(s1);
1120
  itex2MML_free_string(s2);
1121
  itex2MML_free_string($3);
1122
  itex2MML_free_string($5);
1123
}
1124
| MULTI EMPTYMROW closedTerm MROWOPEN subsupList MROWCLOSE {
1125
  char * s1 = itex2MML_copy3("<mmultiscripts>", $3, $5);
1126
  $$ = itex2MML_copy2(s1, "</mmultiscripts>");
1127
  itex2MML_free_string(s1);
1128
  itex2MML_free_string($3);
1129
  itex2MML_free_string($5); 
1130
};
1131
1132
subsupList: subsupTerm {
1133
  $$ = itex2MML_copy_string($1);
1134
  itex2MML_free_string($1);
1135
}
1136
| subsupList subsupTerm {
1137
  $$ = itex2MML_copy3($1, " ", $2);
1138
  itex2MML_free_string($1);
1139
  itex2MML_free_string($2);
1140
};
1141
1142
subsupTerm: SUB closedTerm SUP closedTerm {
1143
  $$ = itex2MML_copy3($2, " ", $4);
1144
  itex2MML_free_string($2);
1145
  itex2MML_free_string($4);
1146
}
1147
| SUB closedTerm {
1148
  $$ = itex2MML_copy2($2, " <none></none>");
1149
  itex2MML_free_string($2);
1150
}
1151
| SUP closedTerm {
1152
  $$ = itex2MML_copy2("<none></none> ", $2);
1153
  itex2MML_free_string($2);
1154
}
1155
| SUB SUP closedTerm {
1156
  $$ = itex2MML_copy2("<none></none> ", $3);
1157
  itex2MML_free_string($3);
1158
};
1159
1160
mfrac: FRAC closedTerm closedTerm {
1161
  char * s1 = itex2MML_copy3("<mfrac>", $2, $3);
1162
  $$ = itex2MML_copy2(s1, "</mfrac>");
1163
  itex2MML_free_string(s1);
1164
  itex2MML_free_string($2);
1165
  itex2MML_free_string($3);
1166
}
1167
| TFRAC closedTerm closedTerm {
1168
  char * s1 = itex2MML_copy3("<mstyle displaystyle=\"false\"><mfrac>", $2, $3);
1169
  $$ = itex2MML_copy2(s1, "</mfrac></mstyle>");
1170
  itex2MML_free_string(s1);
1171
  itex2MML_free_string($2);
1172
  itex2MML_free_string($3);
1173
};
1174
1175
pmod: PMOD closedTerm {
1176
  $$ = itex2MML_copy3( "<mo lspace=\"mediummathspace\">(</mo><mo rspace=\"thinmathspace\">mod</mo>", $2, "<mo rspace=\"mediummathspace\">)</mo>");
1177
  itex2MML_free_string($2);
1178
}
1179
1180
texover: MROWOPEN compoundTermList TEXOVER compoundTermList MROWCLOSE {
1181
  char * s1 = itex2MML_copy3("<mfrac><mrow>", $2, "</mrow><mrow>");
1182
  $$ = itex2MML_copy3(s1, $4, "</mrow></mfrac>");
1183
  itex2MML_free_string(s1);
1184
  itex2MML_free_string($2);
1185
  itex2MML_free_string($4);
1186
}
1187
| left compoundTermList TEXOVER compoundTermList right {
1188
  char * s1 = itex2MML_copy3("<mrow>", $1, "<mfrac><mrow>");
1189
  char * s2 = itex2MML_copy3($2, "</mrow><mrow>", $4);
1190
  char * s3 = itex2MML_copy3("</mrow></mfrac>", $5, "</mrow>");
1191
  $$ = itex2MML_copy3(s1, s2, s3);
1192
  itex2MML_free_string(s1);
1193
  itex2MML_free_string(s2);
1194
  itex2MML_free_string(s3);
1195
  itex2MML_free_string($1);
1196
  itex2MML_free_string($2);
1197
  itex2MML_free_string($4);
1198
  itex2MML_free_string($5);
1199
};
1200
21 by Jacques Distler
\binom
1201
texatop: MROWOPEN compoundTermList TEXATOP compoundTermList MROWCLOSE {
1202
  char * s1 = itex2MML_copy3("<mfrac linethickness=\"0\"><mrow>", $2, "</mrow><mrow>");
1203
  $$ = itex2MML_copy3(s1, $4, "</mrow></mfrac>");
1204
  itex2MML_free_string(s1);
1205
  itex2MML_free_string($2);
1206
  itex2MML_free_string($4);
1207
}
1208
| left compoundTermList TEXATOP compoundTermList right {
1209
  char * s1 = itex2MML_copy3("<mrow>", $1, "<mfrac linethickness=\"0\"><mrow>");
1210
  char * s2 = itex2MML_copy3($2, "</mrow><mrow>", $4);
1211
  char * s3 = itex2MML_copy3("</mrow></mfrac>", $5, "</mrow>");
1212
  $$ = itex2MML_copy3(s1, s2, s3);
1213
  itex2MML_free_string(s1);
1214
  itex2MML_free_string(s2);
1215
  itex2MML_free_string(s3);
1216
  itex2MML_free_string($1);
1217
  itex2MML_free_string($2);
1218
  itex2MML_free_string($4);
1219
  itex2MML_free_string($5);
1220
};
1221
1 by Jacques Distler
Initial commit.
1222
binom: BINOM closedTerm closedTerm {
21 by Jacques Distler
\binom
1223
  char * s1 = itex2MML_copy3("<mrow><mo>(</mo><mfrac linethickness=\"0\">", $2, $3);
1224
  $$ = itex2MML_copy2(s1, "</mfrac><mo>)</mo></mrow>");
1 by Jacques Distler
Initial commit.
1225
  itex2MML_free_string(s1);
1226
  itex2MML_free_string($2);
1227
  itex2MML_free_string($3);
59 by Jacques Distler
itex2MML 1.4.5: Array Environment
1228
}
1229
| TBINOM closedTerm closedTerm {
1230
  char * s1 = itex2MML_copy3("<mrow><mo>(</mo><mstyle displaystyle=\"false\"><mfrac linethickness=\"0\">", $2, $3);
1231
  $$ = itex2MML_copy2(s1, "</mfrac></mstyle><mo>)</mo></mrow>");
1232
  itex2MML_free_string(s1);
1233
  itex2MML_free_string($2);
1234
  itex2MML_free_string($3);
1 by Jacques Distler
Initial commit.
1235
};
1236
1237
munderbrace: UNDERBRACE closedTerm {
1238
  $$ = itex2MML_copy3("<munder>", $2, "<mo>&UnderBrace;</mo></munder>");
1239
  itex2MML_free_string($2);
1240
};
1241
34 by Jacques Distler
itex2MML 1.3.10
1242
munderline: UNDERLINE closedTerm {
42 by Jacques Distler
itex2MML 1.3.18
1243
  $$ = itex2MML_copy3("<munder>", $2, "<mo>&#x00332;</mo></munder>");
34 by Jacques Distler
itex2MML 1.3.10
1244
  itex2MML_free_string($2);
1245
};
1246
1 by Jacques Distler
Initial commit.
1247
moverbrace: OVERBRACE closedTerm {
1248
  $$ = itex2MML_copy3("<mover>", $2, "<mo>&OverBrace;</mo></mover>");
1249
  itex2MML_free_string($2);
1250
};
1251
1252
bar: BAR closedTerm {
42 by Jacques Distler
itex2MML 1.3.18
1253
  $$ = itex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x000AF;</mo></mover>");
1 by Jacques Distler
Initial commit.
1254
  itex2MML_free_string($2);
1255
}
1256
| WIDEBAR closedTerm {
42 by Jacques Distler
itex2MML 1.3.18
1257
  $$ = itex2MML_copy3("<mover>", $2, "<mo>&#x000AF;</mo></mover>");
1 by Jacques Distler
Initial commit.
1258
  itex2MML_free_string($2);
1259
};
1260
1261
vec: VEC closedTerm {
1262
  $$ = itex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&RightVector;</mo></mover>");
1263
  itex2MML_free_string($2);
1264
}
1265
| WIDEVEC closedTerm {
1266
  $$ = itex2MML_copy3("<mover>", $2, "<mo>&RightVector;</mo></mover>");
1267
  itex2MML_free_string($2);
1268
};
1269
1270
dot: DOT closedTerm {
1271
  $$ = itex2MML_copy3("<mover>", $2, "<mo>&dot;</mo></mover>");
1272
  itex2MML_free_string($2);
1273
};
1274
1275
ddot: DDOT closedTerm {
1276
  $$ = itex2MML_copy3("<mover>", $2, "<mo>&Dot;</mo></mover>");
1277
  itex2MML_free_string($2);
1278
};
1279
38 by Jacques Distler
itex2MML 1.3.14: \dddot{} and \ddddot{}
1280
dddot: DDDOT closedTerm {
1281
  $$ = itex2MML_copy3("<mover>", $2, "<mo>&tdot;</mo></mover>");
1282
  itex2MML_free_string($2);
1283
};
1284
1285
ddddot: DDDDOT closedTerm {
1286
  $$ = itex2MML_copy3("<mover>", $2, "<mo>&DotDot;</mo></mover>");
1287
  itex2MML_free_string($2);
1288
};
1289
1 by Jacques Distler
Initial commit.
1290
tilde: TILDE closedTerm {
1291
  $$ = itex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&tilde;</mo></mover>");
1292
  itex2MML_free_string($2);
1293
}
1294
| WIDETILDE closedTerm {
1295
  $$ = itex2MML_copy3("<mover>", $2, "<mo>&tilde;</mo></mover>");
1296
  itex2MML_free_string($2);
1297
};
1298
1299
check: CHECK closedTerm {
18 by Jacques Distler
Minor Tweaks
1300
  $$ = itex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x2c7;</mo></mover>");
1 by Jacques Distler
Initial commit.
1301
  itex2MML_free_string($2);
1302
}
1303
| WIDECHECK closedTerm {
18 by Jacques Distler
Minor Tweaks
1304
  $$ = itex2MML_copy3("<mover>", $2, "<mo>&#x2c7;</mo></mover>");
1 by Jacques Distler
Initial commit.
1305
  itex2MML_free_string($2);
1306
};
1307
1308
hat: HAT closedTerm {
49 by Jacques Distler
itex2MML 1.3.24: Fix \hat{} and \widehat{}
1309
  $$ = itex2MML_copy3("<mover>", $2, "<mo stretchy=\"false\">&#x5E;</mo></mover>");
1 by Jacques Distler
Initial commit.
1310
  itex2MML_free_string($2);
1311
}
1312
| WIDEHAT closedTerm {
49 by Jacques Distler
itex2MML 1.3.24: Fix \hat{} and \widehat{}
1313
  $$ = itex2MML_copy3("<mover>", $2, "<mo>&#x5E;</mo></mover>");
1 by Jacques Distler
Initial commit.
1314
  itex2MML_free_string($2);
1315
};
1316
1317
msqrt: SQRT closedTerm {
1318
  $$ = itex2MML_copy3("<msqrt>", $2, "</msqrt>");
1319
  itex2MML_free_string($2);
1320
};
1321
59 by Jacques Distler
itex2MML 1.4.5: Array Environment
1322
mroot: SQRT OPTARGOPEN compoundTermList OPTARGCLOSE closedTerm {
1323
  char * s1 = itex2MML_copy3("<mroot>", $5, $3);
1324
  $$ = itex2MML_copy2(s1, "</mroot>");
1325
  itex2MML_free_string(s1);
1326
  itex2MML_free_string($3);
1327
  itex2MML_free_string($5);
1328
}
1329
| ROOT closedTerm closedTerm {
1 by Jacques Distler
Initial commit.
1330
  char * s1 = itex2MML_copy3("<mroot>", $3, $2);
1331
  $$ = itex2MML_copy2(s1, "</mroot>");
1332
  itex2MML_free_string(s1);
1333
  itex2MML_free_string($2);
1334
  itex2MML_free_string($3);
1335
};
1336
61 by Jacques Distler
itex2MML 1.4.7: \mathraisebox{voffset}[height][depth]{content}
1337
raisebox: RAISEBOX TEXTSTRING TEXTSTRING TEXTSTRING closedTerm {
1338
  char * s1 = itex2MML_copy3("<mpadded voffset='", $2, "' height='");
1339
  char * s2 = itex2MML_copy3(s1, $3, "' depth='");
1340
  char * s3 = itex2MML_copy3(s2, $4, "'>");
1341
  $$ = itex2MML_copy3(s3, $5, "</mpadded>");
1342
  itex2MML_free_string(s1);
1343
  itex2MML_free_string(s2);
1344
  itex2MML_free_string(s3);
1345
  itex2MML_free_string($2);
1346
  itex2MML_free_string($3);
1347
  itex2MML_free_string($4);
1348
  itex2MML_free_string($5);
1349
}
1350
| RAISEBOX NEG TEXTSTRING TEXTSTRING TEXTSTRING closedTerm {
1351
  char * s1 = itex2MML_copy3("<mpadded voffset='-", $3, "' height='");
1352
  char * s2 = itex2MML_copy3(s1, $4, "' depth='");
1353
  char * s3 = itex2MML_copy3(s2, $5, "'>");
1354
  $$ = itex2MML_copy3(s3, $6, "</mpadded>");
1355
  itex2MML_free_string(s1);
1356
  itex2MML_free_string(s2);
1357
  itex2MML_free_string(s3);
1358
  itex2MML_free_string($3);
1359
  itex2MML_free_string($4);
1360
  itex2MML_free_string($5);
1361
  itex2MML_free_string($6);
1362
}
1363
| RAISEBOX TEXTSTRING TEXTSTRING closedTerm {
1364
  char * s1 = itex2MML_copy3("<mpadded voffset='", $2, "' height='");
1365
  char * s2 = itex2MML_copy3(s1, $3, "' depth='depth'>");
1366
  $$ = itex2MML_copy3(s2, $4, "</mpadded>");
1367
  itex2MML_free_string(s1);
1368
  itex2MML_free_string(s2);
1369
  itex2MML_free_string($2);
1370
  itex2MML_free_string($3);
1371
  itex2MML_free_string($4);
1372
}
1373
| RAISEBOX NEG TEXTSTRING TEXTSTRING closedTerm {
1374
  char * s1 = itex2MML_copy3("<mpadded voffset='-", $3, "' height='");
1375
  char * s2 = itex2MML_copy3(s1, $4, "' depth='+");
1376
  char * s3 = itex2MML_copy3(s2, $3, "'>");
1377
  $$ = itex2MML_copy3(s3, $5, "</mpadded>");
1378
  itex2MML_free_string(s1);
1379
  itex2MML_free_string(s2);
1380
  itex2MML_free_string(s3);
1381
  itex2MML_free_string($3);
1382
  itex2MML_free_string($4);
1383
  itex2MML_free_string($5);
1384
}
1385
| RAISEBOX TEXTSTRING closedTerm {
1386
  char * s1 = itex2MML_copy3("<mpadded voffset='", $2, "' height='+");
1387
  char * s2 = itex2MML_copy3(s1, $2, "' depth='depth'>");
1388
  $$ = itex2MML_copy3(s2, $3, "</mpadded>");
1389
  itex2MML_free_string(s1);
1390
  itex2MML_free_string(s2);
1391
  itex2MML_free_string($2);
1392
  itex2MML_free_string($3);
1393
}
1394
| RAISEBOX NEG TEXTSTRING closedTerm {
1395
  char * s1 = itex2MML_copy3("<mpadded voffset='-", $3, "' height='0pt' depth='+");
1396
  char * s2 = itex2MML_copy3(s1, $3, "'>");
1397
  $$ = itex2MML_copy3(s2, $4, "</mpadded>");
1398
  itex2MML_free_string(s1);
1399
  itex2MML_free_string(s2);
1400
  itex2MML_free_string($3);
1401
  itex2MML_free_string($4);
1402
};
1403
56 by Jacques Distler
Extensible Arrows (Again)
1404
munder: XARROW OPTARGOPEN compoundTermList OPTARGCLOSE EMPTYMROW {
57 by Jacques Distler
itex2MML 1.4.3: Better extensible arrows
1405
  char * s1 = itex2MML_copy3("<munder><mo>", $1, "</mo><mrow>");
1406
  $$ = itex2MML_copy3(s1, $3, "</mrow></munder>");
56 by Jacques Distler
Extensible Arrows (Again)
1407
  itex2MML_free_string(s1);
1408
  itex2MML_free_string($1);
1409
  itex2MML_free_string($3);
1410
}
1411
| UNDER closedTerm closedTerm {
1 by Jacques Distler
Initial commit.
1412
  char * s1 = itex2MML_copy3("<munder>", $3, $2);
1413
  $$ = itex2MML_copy2(s1, "</munder>");
1414
  itex2MML_free_string(s1);
1415
  itex2MML_free_string($2);
1416
  itex2MML_free_string($3);
1417
};
1418
54 by Jacques Distler
itex2MML 1.4.0: Extensible Arrows
1419
mover: XARROW closedTerm {
1420
  char * s1 = itex2MML_copy3("<mover><mo>", $1, "</mo>");
1421
  $$ =  itex2MML_copy3(s1, $2, "</mover>");
1422
  itex2MML_free_string(s1);
1423
  itex2MML_free_string($1);
1424
  itex2MML_free_string($2);
1425
}
1426
| OVER closedTerm closedTerm {
1 by Jacques Distler
Initial commit.
1427
  char * s1 = itex2MML_copy3("<mover>", $3, $2);
1428
  $$ = itex2MML_copy2(s1, "</mover>");
1429
  itex2MML_free_string(s1);
1430
  itex2MML_free_string($2);
1431
  itex2MML_free_string($3);
1432
};
1433
56 by Jacques Distler
Extensible Arrows (Again)
1434
munderover: XARROW OPTARGOPEN compoundTermList OPTARGCLOSE closedTerm {
1435
  char * s1 = itex2MML_copy3("<munderover><mo>", $1, "</mo><mrow>");
1436
  char * s2 = itex2MML_copy3(s1, $3, "</mrow>");
1437
  $$ = itex2MML_copy3(s2, $5, "</munderover>");
54 by Jacques Distler
itex2MML 1.4.0: Extensible Arrows
1438
  itex2MML_free_string(s1);
1439
  itex2MML_free_string(s2);
1440
  itex2MML_free_string($1);
1441
  itex2MML_free_string($3);
1442
  itex2MML_free_string($5);
1443
}
1444
| UNDEROVER closedTerm closedTerm closedTerm {
1 by Jacques Distler
Initial commit.
1445
  char * s1 = itex2MML_copy3("<munderover>", $4, $2);
1446
  $$ = itex2MML_copy3(s1, $3, "</munderover>");
1447
  itex2MML_free_string(s1);
1448
  itex2MML_free_string($2);
1449
  itex2MML_free_string($3);
1450
  itex2MML_free_string($4);
1451
};
1452
56 by Jacques Distler
Extensible Arrows (Again)
1453
emptymrow: EMPTYMROW {
1454
  $$ = itex2MML_copy_string("<mrow></mrow>");
1455
};
1456
1 by Jacques Distler
Initial commit.
1457
mathenv: BEGINENV MATRIX tableRowList ENDENV MATRIX {
1458
  $$ = itex2MML_copy3("<mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow>");
1459
  itex2MML_free_string($3);
1460
}
8 by Jacques Distler
itex2MML 1.1.9;
1461
|  BEGINENV GATHERED tableRowList ENDENV GATHERED {
1462
  $$ = itex2MML_copy3("<mrow><mtable rowspacing=\"1.0ex\">", $3, "</mtable></mrow>");
1463
  itex2MML_free_string($3);
1464
}
1 by Jacques Distler
Initial commit.
1465
| BEGINENV PMATRIX tableRowList ENDENV PMATRIX {
1466
  $$ = itex2MML_copy3("<mrow><mo>(</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>)</mo></mrow>");
1467
  itex2MML_free_string($3);
1468
}
1469
| BEGINENV BMATRIX tableRowList ENDENV BMATRIX {
1470
  $$ = itex2MML_copy3("<mrow><mo>[</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>]</mo></mrow>");
1471
  itex2MML_free_string($3);
1472
}
1473
| BEGINENV VMATRIX tableRowList ENDENV VMATRIX {
1474
  $$ = itex2MML_copy3("<mrow><mo>&VerticalBar;</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>&VerticalBar;</mo></mrow>");
1475
  itex2MML_free_string($3);
1476
}
1477
| BEGINENV BBMATRIX tableRowList ENDENV BBMATRIX {
1478
  $$ = itex2MML_copy3("<mrow><mo>{</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>}</mo></mrow>");
1479
  itex2MML_free_string($3);
1480
}
1481
| BEGINENV VVMATRIX tableRowList ENDENV VVMATRIX {
1482
  $$ = itex2MML_copy3("<mrow><mo>&DoubleVerticalBar;</mo><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow><mo>&DoubleVerticalBar;</mo></mrow>");
1483
  itex2MML_free_string($3);
1484
}
1485
| BEGINENV SMALLMATRIX tableRowList ENDENV SMALLMATRIX {
1486
  $$ = itex2MML_copy3("<mstyle scriptlevel=\"2\"><mrow><mtable rowspacing=\"0.5ex\">", $3, "</mtable></mrow></mstyle>");
1487
  itex2MML_free_string($3);
1488
}
1489
| BEGINENV CASES tableRowList ENDENV CASES {
1490
  $$ = itex2MML_copy3("<mrow><mo>{</mo><mrow><mtable columnalign=\"left left\">", $3, "</mtable></mrow></mrow>");
1491
  itex2MML_free_string($3);
1492
}
1493
| BEGINENV ALIGNED tableRowList ENDENV ALIGNED {
8 by Jacques Distler
itex2MML 1.1.9;
1494
  $$ = 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.
1495
  itex2MML_free_string($3);
22 by Jacques Distler
SVG Environment
1496
}
59 by Jacques Distler
itex2MML 1.4.5: Array Environment
1497
| BEGINENV ARRAY ARRAYALIGN ST columnAlignList END tableRowList ENDENV ARRAY {
1498
  char * s1 = itex2MML_copy3("<mtable rowspacing=\"0.5ex\" align=\"", $3, "\" columnalign=\"");
1499
  char * s2 = itex2MML_copy3(s1, $5, "\">");
1500
  $$ = itex2MML_copy3(s2, $7, "</mtable>");
1501
  itex2MML_free_string(s1);
1502
  itex2MML_free_string(s2);
1503
  itex2MML_free_string($3);
1504
  itex2MML_free_string($5);
1505
  itex2MML_free_string($7);
1506
}
1507
| BEGINENV ARRAY ST columnAlignList END tableRowList ENDENV ARRAY {
1508
  char * s1 = itex2MML_copy3("<mtable rowspacing=\"0.5ex\" columnalign=\"", $4, "\">");
1509
  $$ = itex2MML_copy3(s1, $6, "</mtable>");
1510
  itex2MML_free_string(s1);
1511
  itex2MML_free_string($4);
1512
  itex2MML_free_string($6);
1513
}
22 by Jacques Distler
SVG Environment
1514
| BEGINENV SVG XMLSTRING ENDSVG {
1515
  $$ = itex2MML_copy3("<semantics><annotation-xml encoding=\"SVG1.1\">", $3, "</annotation-xml></semantics>");
1516
  itex2MML_free_string($3);
1517
}
1518
| BEGINENV SVG ENDSVG {
1519
  $$ = itex2MML_copy_string(" ");
1 by Jacques Distler
Initial commit.
1520
};
1521
59 by Jacques Distler
itex2MML 1.4.5: Array Environment
1522
columnAlignList: columnAlignList COLUMNALIGN {
1523
  $$ = itex2MML_copy3($1, " ", $2);
1524
  itex2MML_free_string($1);
1525
  itex2MML_free_string($2);
1526
}
1527
| COLUMNALIGN {
1528
  $$ = itex2MML_copy_string($1);
1529
  itex2MML_free_string($1);
1530
};
1531
1 by Jacques Distler
Initial commit.
1532
substack: SUBSTACK MROWOPEN tableRowList MROWCLOSE {
1533
  $$ = itex2MML_copy3("<mrow><mtable columnalign=\"center\" rowspacing=\"0.5ex\">", $3, "</mtable></mrow>");
1534
  itex2MML_free_string($3);
1535
};
1536
1537
array: ARRAY MROWOPEN tableRowList MROWCLOSE {
1538
  $$ = itex2MML_copy3("<mrow><mtable>", $3, "</mtable></mrow>");
1539
  itex2MML_free_string($3);
1540
}
1541
| ARRAY MROWOPEN ARRAYOPTS MROWOPEN arrayopts MROWCLOSE tableRowList MROWCLOSE {
1542
  char * s1 = itex2MML_copy3("<mrow><mtable ", $5, ">");
1543
  $$ = itex2MML_copy3(s1, $7, "</mtable></mrow>");
1544
  itex2MML_free_string(s1);
1545
  itex2MML_free_string($5);
1546
  itex2MML_free_string($7);
1547
};
1548
1549
arrayopts: anarrayopt {
1550
  $$ = itex2MML_copy_string($1);
1551
  itex2MML_free_string($1);
1552
}
1553
| arrayopts anarrayopt {
1554
  $$ = itex2MML_copy3($1, " ", $2);
1555
  itex2MML_free_string($1);
1556
  itex2MML_free_string($2);
1557
};
1558
1559
anarrayopt: collayout {
1560
  $$ = itex2MML_copy_string($1);
1561
  itex2MML_free_string($1);
1562
}
1563
| colalign {
1564
  $$ = itex2MML_copy_string($1);
1565
  itex2MML_free_string($1);
1566
}
1567
| rowalign {
1568
  $$ = itex2MML_copy_string($1);
1569
  itex2MML_free_string($1);
1570
}
1571
| align {
1572
  $$ = itex2MML_copy_string($1);
1573
  itex2MML_free_string($1);
1574
}
1575
| eqrows {
1576
  $$ = itex2MML_copy_string($1);
1577
  itex2MML_free_string($1);
1578
}
1579
| eqcols {
1580
  $$ = itex2MML_copy_string($1);
1581
  itex2MML_free_string($1);
1582
}
1583
| rowlines {
1584
  $$ = itex2MML_copy_string($1);
1585
  itex2MML_free_string($1);
1586
}
1587
| collines {
1588
  $$ = itex2MML_copy_string($1);
1589
  itex2MML_free_string($1);
1590
}
1591
| frame {
1592
  $$ = itex2MML_copy_string($1);
1593
  itex2MML_free_string($1);
1594
}
1595
| padding {
1596
  $$ = itex2MML_copy_string($1);
1597
  itex2MML_free_string($1);
1598
};
1599
1600
collayout: COLLAYOUT ATTRLIST {
1601
  $$ = itex2MML_copy2("columnalign=", $2);
1602
  itex2MML_free_string($2);
1603
};
1604
1605
colalign: COLALIGN ATTRLIST {
1606
  $$ = itex2MML_copy2("columnalign=", $2);
1607
  itex2MML_free_string($2);
1608
};
1609
1610
rowalign: ROWALIGN ATTRLIST {
1611
  $$ = itex2MML_copy2("rowalign=", $2);
1612
  itex2MML_free_string($2);
1613
};
1614
1615
align: ALIGN ATTRLIST {
1616
  $$ = itex2MML_copy2("align=", $2);
1617
  itex2MML_free_string($2);
1618
};
1619
1620
eqrows: EQROWS ATTRLIST {
1621
  $$ = itex2MML_copy2("equalrows=", $2);
1622
  itex2MML_free_string($2);
1623
};
1624
1625
eqcols: EQCOLS ATTRLIST {
1626
  $$ = itex2MML_copy2("equalcolumns=", $2);
1627
  itex2MML_free_string($2);
1628
};
1629
1630
rowlines: ROWLINES ATTRLIST {
1631
  $$ = itex2MML_copy2("rowlines=", $2);
1632
  itex2MML_free_string($2);
1633
};
1634
1635
collines: COLLINES ATTRLIST {
1636
  $$ = itex2MML_copy2("columnlines=", $2);
1637
  itex2MML_free_string($2);
1638
};
1639
1640
frame: FRAME ATTRLIST {
1641
  $$ = itex2MML_copy2("frame=", $2);
1642
  itex2MML_free_string($2);
1643
};
1644
1645
padding: PADDING ATTRLIST {
1646
  char * s1 = itex2MML_copy3("rowspacing=", $2, " columnspacing=");
1647
  $$ = itex2MML_copy2(s1, $2);
1648
  itex2MML_free_string(s1);
1649
  itex2MML_free_string($2);
1650
};
1651
1652
tableRowList: tableRow {
1653
  $$ = itex2MML_copy_string($1);
1654
  itex2MML_free_string($1);
1655
}
1656
| tableRowList ROWSEP tableRow {
1657
  $$ = itex2MML_copy3($1, " ", $3);
1658
  itex2MML_free_string($1);
1659
  itex2MML_free_string($3);
1660
};
1661
1662
tableRow: simpleTableRow {
1663
  $$ = itex2MML_copy3("<mtr>", $1, "</mtr>");
1664
  itex2MML_free_string($1);
1665
}
1666
| optsTableRow {
1667
  $$ = itex2MML_copy_string($1);
1668
  itex2MML_free_string($1);
1669
};
1670
1671
simpleTableRow: tableCell {
1672
  $$ = itex2MML_copy_string($1);
1673
  itex2MML_free_string($1);
1674
}
1675
| simpleTableRow COLSEP tableCell {
1676
  $$ = itex2MML_copy3($1, " ", $3);
1677
  itex2MML_free_string($1);
1678
  itex2MML_free_string($3);
1679
};
1680
1681
optsTableRow: ROWOPTS MROWOPEN rowopts MROWCLOSE simpleTableRow {
1682
  char * s1 = itex2MML_copy3("<mtr ", $3, ">");
1683
  $$ = itex2MML_copy3(s1, $5, "</mtr>");
1684
  itex2MML_free_string(s1);
1685
  itex2MML_free_string($3);
1686
  itex2MML_free_string($5);
1687
};
1688
1689
rowopts: arowopt {
1690
  $$ = itex2MML_copy_string($1);
1691
  itex2MML_free_string($1);
1692
}
1693
| rowopts arowopt {
1694
  $$ = itex2MML_copy3($1, " ", $2);
1695
  itex2MML_free_string($1);
1696
  itex2MML_free_string($2);
1697
};
1698
1699
arowopt: colalign {
1700
  $$ = itex2MML_copy_string($1);
1701
  itex2MML_free_string($1);
1702
}
1703
| rowalign {
1704
  $$ = itex2MML_copy_string($1);
1705
  itex2MML_free_string($1);
1706
};
1707
1708
tableCell:   {
1709
  $$ = itex2MML_copy_string("<mtd></mtd>");
1710
}
1711
| compoundTermList {
1712
  $$ = itex2MML_copy3("<mtd>", $1, "</mtd>");
1713
  itex2MML_free_string($1);
1714
}
1715
| CELLOPTS MROWOPEN cellopts MROWCLOSE compoundTermList {
1716
  char * s1 = itex2MML_copy3("<mtd ", $3, ">");
1717
  $$ = itex2MML_copy3(s1, $5, "</mtd>");
1718
  itex2MML_free_string(s1);
1719
  itex2MML_free_string($3);
1720
  itex2MML_free_string($5);
1721
};
1722
1723
cellopts: acellopt {
1724
  $$ = itex2MML_copy_string($1);
1725
  itex2MML_free_string($1);
1726
}
1727
| cellopts acellopt {
1728
  $$ = itex2MML_copy3($1, " ", $2);
1729
  itex2MML_free_string($1);
1730
  itex2MML_free_string($2);
1731
};
1732
1733
acellopt: colalign {
1734
  $$ = itex2MML_copy_string($1);
1735
  itex2MML_free_string($1);
1736
}
1737
| rowalign {
1738
  $$ = itex2MML_copy_string($1);
1739
  itex2MML_free_string($1);
1740
}
1741
| rowspan {
1742
  $$ = itex2MML_copy_string($1);
1743
  itex2MML_free_string($1);
1744
}
1745
| colspan {
1746
  $$ = itex2MML_copy_string($1);
1747
  itex2MML_free_string($1);
1748
};
1749
1750
rowspan: ROWSPAN ATTRLIST {
1751
  $$ = itex2MML_copy2("rowspan=", $2);
1752
  itex2MML_free_string($2);
1753
};
1754
1755
colspan: COLSPAN ATTRLIST {
8 by Jacques Distler
itex2MML 1.1.9;
1756
  $$ = itex2MML_copy2("columnspan=", $2);
1 by Jacques Distler
Initial commit.
1757
  itex2MML_free_string($2);
1758
};
1759
1760
%%
1761
1762
char * itex2MML_parse (const char * buffer, unsigned long length)
1763
{
1764
  char * mathml = 0;
1765
1766
  int result;
1767
1768
  itex2MML_setup (buffer, length);
1769
  itex2MML_restart ();
1770
1771
  result = itex2MML_yyparse (&mathml);
1772
1773
  if (result && mathml) /* shouldn't happen? */
1774
    {
1775
      itex2MML_free_string (mathml);
1776
      mathml = 0;
1777
    }
1778
  return mathml;
1779
}
1780
1781
int itex2MML_filter (const char * buffer, unsigned long length)
1782
{
1783
  itex2MML_setup (buffer, length);
1784
  itex2MML_restart ();
1785
1786
  return itex2MML_yyparse (0);
1787
}
1788
1789
#define ITEX_DELIMITER_DOLLAR 0
1790
#define ITEX_DELIMITER_DOUBLE 1
1791
#define ITEX_DELIMITER_SQUARE 2
1792
1793
static char * itex2MML_last_error = 0;
1794
1795
static void itex2MML_keep_error (const char * msg)
1796
{
1797
  if (itex2MML_last_error)
1798
    {
1799
      itex2MML_free_string (itex2MML_last_error);
1800
      itex2MML_last_error = 0;
1801
    }
1802
  itex2MML_last_error = itex2MML_copy_escaped (msg);
1803
}
1804
1805
int itex2MML_html_filter (const char * buffer, unsigned long length)
1806
{
23 by Jacques Distler
Angle Brackets
1807
  itex2MML_do_html_filter (buffer, length, 0);
1808
}
1809
1810
int itex2MML_strict_html_filter (const char * buffer, unsigned long length)
1811
{
1812
  itex2MML_do_html_filter (buffer, length, 1);
1813
}
1814
1815
int itex2MML_do_html_filter (const char * buffer, unsigned long length, const int forbid_markup)
1816
{
1 by Jacques Distler
Initial commit.
1817
  int result = 0;
1818
1819
  int type = 0;
1820
  int skip = 0;
1821
  int match = 0;
1822
1823
  const char * ptr1 = buffer;
1824
  const char * ptr2 = 0;
1825
1826
  const char * end = buffer + length;
1827
1828
  char * mathml = 0;
1829
1830
  void (*save_error_fn) (const char * msg) = itex2MML_error;
1831
1832
  itex2MML_error = itex2MML_keep_error;
1833
1834
 _until_math:
1835
  ptr2 = ptr1;
1836
1837
  while (ptr2 < end)
1838
    {
1839
      if (*ptr2 == '$') break;
1840
      if ((*ptr2 == '\\') && (ptr2 + 1 < end))
1841
	{
1842
	  if (*(ptr2+1) == '[') break;
1843
	}
1844
      ++ptr2;
1845
    }
45 by Jacques Distler
Fix a bug in itex2MML_html_filter
1846
  if (itex2MML_write && ptr2 > ptr1)
1 by Jacques Distler
Initial commit.
1847
    (*itex2MML_write) (ptr1, ptr2 - ptr1);
1848
1849
  if (ptr2 == end) goto _finish;
1850
1851
 _until_html:
1852
  ptr1 = ptr2;
1853
1854
  if (ptr2 + 1 < end)
1855
    {
1856
      if ((*ptr2 == '\\') && (*(ptr2+1) == '['))
1857
	{
1858
	  type = ITEX_DELIMITER_SQUARE;
1859
	  ptr2 += 2;
1860
	}
1861
      else if ((*ptr2 == '$') && (*(ptr2+1) == '$'))
1862
	{
1863
	  type = ITEX_DELIMITER_DOUBLE;
1864
	  ptr2 += 2;
1865
	}
1866
      else
1867
	{
1868
	  type = ITEX_DELIMITER_DOLLAR;
1869
	  ptr2 += 2;
1870
	}
1871
    }
1872
  else goto _finish;
1873
1874
  skip = 0;
1875
  match = 0;
1876
1877
  while (ptr2 < end)
1878
    {
1879
      switch (*ptr2)
1880
	{
1881
	case '<':
1882
	case '>':
23 by Jacques Distler
Angle Brackets
1883
	  if (forbid_markup == 1) skip = 1;
1 by Jacques Distler
Initial commit.
1884
	  break;
1885
1886
	case '\\':
1887
	  if (ptr2 + 1 < end)
1888
	    {
1889
	      if (*(ptr2 + 1) == '[')
1890
		{
1891
		  skip = 1;
1892
		}
1893
	      else if (*(ptr2 + 1) == ']')
1894
		{
1895
		  if (type == ITEX_DELIMITER_SQUARE)
1896
		    {
1897
		      ptr2 += 2;
1898
		      match = 1;
1899
		    }
1900
		  else
1901
		    {
1902
		      skip = 1;
1903
		    }
1904
		}
1905
	    }
1906
	  break;
1907
1908
	case '$':
1909
	  if (type == ITEX_DELIMITER_SQUARE)
1910
	    {
1911
	      skip = 1;
1912
	    }
1913
	  else if (ptr2 + 1 < end)
1914
	    {
1915
	      if (*(ptr2 + 1) == '$')
1916
		{
1917
		  if (type == ITEX_DELIMITER_DOLLAR)
1918
		    {
1919
		      ptr2++;
1920
		      match = 1;
1921
		    }
1922
		  else
1923
		    {
1924
		      ptr2 += 2;
1925
		      match = 1;
1926
		    }
1927
		}
1928
	      else
1929
		{
1930
		  if (type == ITEX_DELIMITER_DOLLAR)
1931
		    {
1932
		      ptr2++;
1933
		      match = 1;
1934
		    }
1935
		  else
1936
		    {
1937
		      skip = 1;
1938
		    }
1939
		}
1940
	    }
1941
	  else
1942
	    {
1943
	      if (type == ITEX_DELIMITER_DOLLAR)
1944
		{
1945
		  ptr2++;
1946
		  match = 1;
1947
		}
1948
	      else
1949
		{
1950
		  skip = 1;
1951
		}
1952
	    }
1953
	  break;
1954
1955
	default:
1956
	  break;
1957
	}
1958
      if (skip || match) break;
1959
1960
      ++ptr2;
1961
    }
1962
  if (skip)
1963
    {
1964
      if (type == ITEX_DELIMITER_DOLLAR)
1965
	{
1966
	  if (itex2MML_write)
1967
	    (*itex2MML_write) (ptr1, 1);
1968
	  ptr1++;
1969
	}
1970
      else
1971
	{
1972
	  if (itex2MML_write)
1973
	    (*itex2MML_write) (ptr1, 2);
1974
	  ptr1 += 2;
1975
	}
1976
      goto _until_math;
1977
    }
1978
  if (match)
1979
    {
1980
      mathml = itex2MML_parse (ptr1, ptr2 - ptr1);
1981
1982
      if (mathml)
1983
	{
1984
	  if (itex2MML_write_mathml)
1985
	    (*itex2MML_write_mathml) (mathml);
1986
	  itex2MML_free_string (mathml);
1987
	  mathml = 0;
1988
	}
1989
      else
1990
	{
1991
	  ++result;
1992
	  if (itex2MML_write)
1993
	    {
1994
	      if (type == ITEX_DELIMITER_DOLLAR)
1995
		(*itex2MML_write) ("<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><merror><mtext>", 0);
1996
	      else
1997
		(*itex2MML_write) ("<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><merror><mtext>", 0);
1998
1999
	      (*itex2MML_write) (itex2MML_last_error, 0);
2000
	      (*itex2MML_write) ("</mtext></merror></math>", 0);
2001
	    }
2002
	}
2003
      ptr1 = ptr2;
2004
2005
      goto _until_math;
2006
    }
2007
  if (itex2MML_write)
2008
    (*itex2MML_write) (ptr1, ptr2 - ptr1);
2009
2010
 _finish:
2011
  if (itex2MML_last_error)
2012
    {
2013
      itex2MML_free_string (itex2MML_last_error);
2014
      itex2MML_last_error = 0;
2015
    }
2016
  itex2MML_error = save_error_fn;
2017
2018
  return result;
2019
}