Subversion Repositories wimsdev

Rev

Rev 5512 | Rev 5544 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5512 Rev 5523
Line 23... Line 23...
23
struct {
23
struct {
24
    char src[124], name[128];
24
    char src[124], name[128];
25
    int size;
25
    int size;
26
} oldinstex[100];
26
} oldinstex[100];
27
int oldtexcnt=0;
27
int oldtexcnt=0;
28
 
-
 
29
    /* Use mathml to output TeX formula.
-
 
30
     * Returns 1 if OK, 0 if unknown. */
-
 
31
    /* It doesn't work yet. */
-
 
32
int mathml(char *p)
-
 
33
{
-
 
34
/*    char *p1, buf[MAX_LINELEN+1];
-
 
35
    if(strlen(p)==1 && isalpha(*p)) {
-
 
36
    output("<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n");
-
 
37
    snprintf(buf,sizeof(buf),
-
 
38
         "<mrow><mi>%c</mi></mrow></math>\n",*p);
-
 
39
    output("%s",buf); return 1;
-
 
40
    }
-
 
41
    output("<pre>%s</pre>\n",p); return 1;
-
 
42
*/    
-
 
43
    return 0;
-
 
44
}
-
 
45
 
28
 
46
    /* check whether the same tex source has already been produced */
29
    /* check whether the same tex source has already been produced */
47
int instex_ready(char *p, char *n)
30
int instex_ready(char *p, char *n)
48
{
31
{
49
    int i;
32
    int i;
Line 77... Line 60...
77
    return f;
60
    return f;
78
}
61
}
79
 
62
 
80
char tnames[]="sqrt int integrate sum prod product \
63
char tnames[]="sqrt int integrate sum prod product \
81
Int Sum Prod conj abs";
64
Int Sum Prod conj abs";
82
 
65
 
83
    /* Intelligent insertion of math formulas, kernel */
66
    /* Intelligent insertion of math formulas, kernel */
84
void __insmath(char *p)
67
void __insmath(char *p)
85
{
68
{
86
    char *f, *pp, *pe, *p1, buf[MAX_LINELEN+1], nbuf[256];
69
    char *f, *pp, *pe, *p1, buf[MAX_LINELEN+1], nbuf[256];
87
    int ts, n, rawmathready;
70
    int ts, n, rawmathready;
Line 100... Line 83...
100
    }
83
    }
101
    /* decide if it should be tex */
84
    /* decide if it should be tex */
102
    ts=0; if(strchr(buf,'\\') || strchr(buf,'}')) ts=1;
85
    ts=0; if(strchr(buf,'\\') || strchr(buf,'}')) ts=1;
103
    /* if not and if variable insmath_rawmath is there, do rawmath */
86
    /* if not and if variable insmath_rawmath is there, do rawmath */
104
    rawmathready=0;
87
    rawmathready=0;
105
    if(!ts) { /* should not be tex, looking if rawmath is asked */
88
    if(!ts) { /* not tex, looking if rawmath is asked */
106
      pp=getvar("insmath_rawmath");
89
      pp=getvar("insmath_rawmath");
107
      if(pp!=NULL && strstr(pp,"yes")!=NULL) {
90
      if(pp!=NULL && strstr(pp,"yes")!=NULL) {
108
        rawmath(buf); rawmathready=1;
91
        rawmath(buf); rawmathready=1;
109
      }
92
      }
110
    }
93
    }
111
    if(ts || mathalign_base==2 ||
94
    if(ts) {
-
 
95
         _replace_matrix (buf,"\\matrix{","matrix"); //could be done in any case if ts=1
112
       (strchr(buf,'[')!=NULL &&
96
         _replace_matrix (buf,"\\pmatrix{","pmatrix");
-
 
97
    }
-
 
98
/* if ts=1 (it should be a tex formula)  or if there is a [ ,  ; ] matrix */
-
 
99
    if(ts ||
113
    (strchr(buf,',')!=NULL || strchr(buf,';')!=NULL))) {
100
      (strchr(buf,'[')!=NULL && (strchr(buf,',')!=NULL || strchr(buf,';')!=NULL))) {
114
      char alignbak[2048];
101
      char alignbak[2048];
115
      tex: instex_style="$$";
102
      tex: instex_style="$$";
-
 
103
      if(!ts) texmath(buf);
-
 
104
         /* ts=0 but there is some computer matrix to transform
116
      if(!ts) texmath(buf); // possibly tex - in particular, reinterpret variables and some fonts or functions as alpha pi cos 
105
          * done by texmath, but it does much more as replacing strings in tmathfn
117
    // see list in texmath.c : tmathfn 
106
          * OK if buf contains " math computer-syntax" ; if not, the result may be bad
-
 
107
        */
118
      else {// need to interpret x y z 
108
      else {// seems tex : need to interpret names of variables as \x or \calB
-
 
109
       if (mathalign_base < 2) { //to check
119
        char *p1;
110
        char *p1;
120
        p1=find_word_start(buf);
111
        p1=find_word_start(buf);
121
        if(*p1=='\\') {
112
        if(*p1=='\\') {
122
          int i;
113
          int i;
123
          char *pt;
114
          char *pt;
124
          for(i=1;isalnum(p1[i]);i++); /* find an alphanumeric string beginning by \\ */
115
          for(i=1;isalnum(p1[i]);i++); /* find an alphanumeric string beginning by \\ */
125
          if(p1[i]==0 && (pt=mathfont(p1))!=NULL) { /* find some mathfont as \calB */
116
          if(p1[i]==0 && (pt=mathfont(p1))!=NULL) { /* find some mathfont as \calB */
126
            _output_(pt); *p=0; return;
117
            _output_(pt); *p=0; return;
127
          }
118
          }
128
        }
119
        }
-
 
120
       }
129
      }
121
      }
-
 
122
      /* send to mathml */
130
      if(mathalign_base==2 && mathml(buf)) {*p=0; return;}
123
      if (mathalign_base == 2 && mathml(buf,0)) { *p=0 ; return;}
-
 
124
/* end if mathml option in case ts=1 or "computer matrix" */
-
 
125
 
131
/* only for images*/
126
/* creating images*/
132
      pp=getvar("ins_align");
127
      pp=getvar("ins_align");
133
      if(pp!=NULL) mystrncpy(alignbak,pp,sizeof(alignbak));
128
      if(pp!=NULL) mystrncpy(alignbak,pp,sizeof(alignbak));
134
      setvar("ins_align","middle");
129
      setvar("ins_align","middle");
135
      mystrncpy(ins_alt,buf,sizeof(ins_alt));
130
      mystrncpy(ins_alt,buf,sizeof(ins_alt));
136
      if(f==NULL) {
131
      if(f==NULL) {
137
        calc_instexst(buf); output("%s",buf);
132
        calc_instexst(buf); output("%s",buf);
138
      }
133
      }
139
      else {
134
      else {
140
        instex_usedynamic=1; exec_instex(buf); instex_usedynamic=0;
135
        instex_usedynamic=1; exec_instex(buf); instex_usedynamic=0;
141
      }
136
      }
142
      instex_style="";
137
      instex_style="";
143
      if(alignbak[0]) setvar("ins_align",alignbak);
138
      if(alignbak[0]) setvar("ins_align",alignbak);
144
      return;
139
      return;
145
    }
140
    }
-
 
141
 
146
/* end of the only for images*/
142
/* end creating images
-
 
143
 * we are now in the case where ts=0 and no need of tex for matrix */
-
 
144
 
-
 
145
/* find math variables */
147
    for(pp=find_mathvar_start(buf); *pp; pp=find_mathvar_start(pe)) {
146
    for(pp=find_mathvar_start(buf); *pp; pp=find_mathvar_start(pe)) {
148
      pe=find_mathvar_end(pp); n=pe-pp;
147
      pe=find_mathvar_end(pp); n=pe-pp;
-
 
148
      /* non alpha variable or too short or too long to be interpreted as tnames */
149
      if(!isalpha(*pp) || n<3 || n>16) continue;
149
      if(!isalpha(*pp) || n<3 || n>16) continue;
150
      memmove(nbuf,pp,n); nbuf[n]=0;
150
      memmove(nbuf,pp,n); nbuf[n]=0;
151
      if(wordchr(tnames,nbuf)!=NULL) goto tex;
151
      if(wordchr(tnames,nbuf)!=NULL) goto tex;
-
 
152
      /* find sqrt int integrate sum prod product Int Sum Prod conj abs,
-
 
153
       * so must be texmath interpretated ; after going to tex, return in any case
-
 
154
       */
152
    }
155
    }
153
/* only for html in case where gifs is activated ?? look for  / ?? */  
156
/* look for  /  to interpretate as quotients -
-
 
157
 * extend the version by accepting something else than (
-
 
158
*/  
154
    for(pp=strchr(buf,'/'); pp!=NULL && *find_word_start(pp+1)!='(';
159
    //for(pp=strchr(buf,'/'); pp!=NULL && *find_word_start(pp+1)!='('; pp=strchr(pp+1,'/'));
155
    pp=strchr(pp+1,'/'));
160
    pp=strchr(buf,'/');
156
    if(pp!=NULL) goto tex;  /* so a/4 can be reinterpreted as {1 over 4 } a */
161
    if(pp!=NULL) goto tex;  /* so a/4 can be reinterpreted as {a over 4 } ; transform also 5/(x+1) */
157
    if(rawmathready) rawmath_easy=1;
162
    if(rawmathready) rawmath_easy=1;
158
    for(pp=strchr(buf,'<'); pp!=NULL; pp=strchr(pp+1,'<'))
163
    for(pp=strchr(buf,'<'); pp!=NULL; pp=strchr(pp+1,'<'))
159
      string_modify(buf,pp,pp+1,"&lt;");
164
      string_modify(buf,pp,pp+1,"&lt;");
160
    for(pp=strchr(buf,'>'); pp!=NULL; pp=strchr(pp+1,'>'))
165
    for(pp=strchr(buf,'>'); pp!=NULL; pp=strchr(pp+1,'>'))
161
      string_modify(buf,pp,pp+1,"&gt;");
166
      string_modify(buf,pp,pp+1,"&gt;");
-
 
167
/* no tex has been introduced - so go to htmlmath */
162
    htmlmath(buf); output("%s",buf);
168
    htmlmath(buf); output("%s",buf);
163
    rawmath_easy=0;
169
    rawmath_easy=0;
164
}
170
}
-
 
171
 
-
 
172
/* the following is not used in modules : no insmath_logic=yes somewhere */
165
 
173
 
166
char *andor[]={"and","or","not","is","isnot"};
174
char *andor[]={"and","or","not","is","isnot"};
167
#define andorcnt (sizeof(andor)/sizeof(andor[0]))
175
#define andorcnt (sizeof(andor)/sizeof(andor[0]))
168
char *andorlang[andorcnt], andorlangbuf[1024];
176
char *andorlang[andorcnt], andorlangbuf[1024];
169
int andorlangcnt=-1;
177
int andorlangcnt=-1;