/itexToMML

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