/itexToMML

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