Subversion Repositories wimsdev

Rev

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

Rev 5544 Rev 5611
Line 60... Line 60...
60
    return f;
60
    return f;
61
}
61
}
62
 
62
 
63
char tnames[]="sqrt int integrate sum prod product \
63
char tnames[]="sqrt int integrate sum prod product \
64
Int Sum Prod conj abs";
64
Int Sum Prod conj abs";
-
 
65
 
-
 
66
int __gototex (char *buf,char *f, int ts)
-
 
67
{
-
 
68
      char alignbak[2048];
-
 
69
      char *pp;
-
 
70
      instex_style="$$";
-
 
71
      if(!ts) texmath(buf);
-
 
72
         /* ts=0 but there is some computer matrix to transform
-
 
73
          * done by texmath, but it does much more as replacing strings in tmathfn
-
 
74
          * OK if buf contains " math computer-syntax" ; if not, the result may be bad
-
 
75
        */
-
 
76
      else {// seems tex : need to interpret names of variables as \x or \calB
-
 
77
       //if (mathalign_base < 2) { //to check
-
 
78
        char *p1;
-
 
79
        p1=find_word_start(buf);
-
 
80
        if(*p1=='\\') {
-
 
81
          int i;
-
 
82
          char *pt;
-
 
83
          for(i=1;isalnum(p1[i]);i++); /* find an alphanumeric string beginning by \\ */
-
 
84
          if(p1[i]==0 && (pt=mathfont(p1))!=NULL) {
-
 
85
            _output_(pt); *buf=0; return 1;
-
 
86
          }
-
 
87
        }
-
 
88
      // }
-
 
89
      }
-
 
90
      /* send to mathml */
-
 
91
      if (mathalign_base == 2 && mathml(buf,0)) { *buf=0 ;return 1; }
-
 
92
/* end if mathml option in case ts=1 or "computer matrix" */
-
 
93
 
-
 
94
/* creating images*/
-
 
95
      pp=getvar("ins_align");
-
 
96
      if(pp!=NULL) mystrncpy(alignbak,pp,sizeof(alignbak));
-
 
97
      setvar("ins_align","middle");
-
 
98
      mystrncpy(ins_alt,buf,sizeof(ins_alt));
-
 
99
      if(f==NULL) {
-
 
100
        calc_instexst(buf); output("%s",buf);
-
 
101
      }
-
 
102
      else {
-
 
103
        instex_usedynamic=1; exec_instex(buf); instex_usedynamic=0;
-
 
104
      }
-
 
105
      instex_style="";
-
 
106
      if(alignbak[0]) setvar("ins_align",alignbak);
-
 
107
      *buf=0; return 0;
-
 
108
}
65
 
109
 
66
    /* Intelligent insertion of math formulas, kernel */
110
    /* Intelligent insertion of math formulas, kernel */
67
void __insmath(char *p)
111
void __insmath(char *p)
68
{
112
{
69
    char *f, *pp, *pe, *p1, buf[MAX_LINELEN+1], nbuf[256];
113
    char *f, *pp, *pe, *p1, buf[MAX_LINELEN+1], nbuf[256];
Line 96... Line 140...
96
         _replace_matrix (buf,"\\pmatrix{","pmatrix");
140
         _replace_matrix (buf,"\\pmatrix{","pmatrix");
97
    }
141
    }
98
/* if ts=1 (it should be a tex formula)  or if there is a [ ,  ; ] matrix */
142
/* if ts=1 (it should be a tex formula)  or if there is a [ ,  ; ] matrix */
99
    if(ts ||
143
    if(ts ||
100
      (strchr(buf,'[')!=NULL && (strchr(buf,',')!=NULL || strchr(buf,';')!=NULL))) {
144
      (strchr(buf,'[')!=NULL && (strchr(buf,',')!=NULL || strchr(buf,';')!=NULL))) {
101
      char alignbak[2048];
-
 
102
      tex: instex_style="$$";
-
 
103
      if(!ts) texmath(buf);
-
 
104
         /* ts=0 but there is some computer matrix to transform
-
 
105
          * done by texmath, but it does much more as replacing strings in tmathfn
-
 
106
          * OK if buf contains " math computer-syntax" ; if not, the result may be bad
-
 
107
        */
-
 
108
      else {// seems tex : need to interpret names of variables as \x or \calB
-
 
109
       if (mathalign_base < 2) { //to check
-
 
110
        char *p1;
-
 
111
        p1=find_word_start(buf);
-
 
112
        if(*p1=='\\') {
-
 
113
          int i;
-
 
114
          char *pt;
-
 
115
          for(i=1;isalnum(p1[i]);i++); /* find an alphanumeric string beginning by \\ */
-
 
116
          if(p1[i]==0 && (pt=mathfont(p1))!=NULL) { /* find some mathfont as \calB */
-
 
117
            _output_(pt); *p=0; return;
145
       if(__gototex(buf, f, ts)) return;
118
          }
-
 
119
        }
-
 
120
       }
-
 
121
      }
-
 
122
      /* send to mathml */
-
 
123
      if (mathalign_base == 2 && mathml(buf,0)) { *p=0 ; return;}
-
 
124
/* end if mathml option in case ts=1 or "computer matrix" */
-
 
125
 
-
 
126
/* creating images*/
-
 
127
      pp=getvar("ins_align");
-
 
128
      if(pp!=NULL) mystrncpy(alignbak,pp,sizeof(alignbak));
-
 
129
      setvar("ins_align","middle");
-
 
130
      mystrncpy(ins_alt,buf,sizeof(ins_alt));
-
 
131
      if(f==NULL) {
-
 
132
        calc_instexst(buf); output("%s",buf);
-
 
133
      }
-
 
134
      else {
-
 
135
        instex_usedynamic=1; exec_instex(buf); instex_usedynamic=0;
-
 
136
      }
-
 
137
      instex_style="";
-
 
138
      if(alignbak[0]) setvar("ins_align",alignbak);
-
 
139
      return;
-
 
140
    }
146
    }
141
 
147
 
142
/* end creating images
148
/* end creating images
143
 * we are now in the case where ts=0 and no need of tex for matrix */
149
 * we are now in the case where ts=0 and no need of tex for matrix */
144
 
150
 
Line 146... Line 152...
146
    for(pp=find_mathvar_start(buf); *pp; pp=find_mathvar_start(pe)) {
152
    for(pp=find_mathvar_start(buf); *pp; pp=find_mathvar_start(pe)) {
147
      pe=find_mathvar_end(pp); n=pe-pp;
153
      pe=find_mathvar_end(pp); n=pe-pp;
148
      /* non alpha variable or too short or too long to be interpreted as tnames */
154
      /* non alpha variable or too short or too long to be interpreted as tnames */
149
      if(!isalpha(*pp) || n<3 || n>16) continue;
155
      if(!isalpha(*pp) || n<3 || n>16) continue;
150
      memmove(nbuf,pp,n); nbuf[n]=0;
156
      memmove(nbuf,pp,n); nbuf[n]=0;
151
      if(wordchr(tnames,nbuf)!=NULL) goto tex;
157
      if(wordchr(tnames,nbuf)!=NULL) { if(__gototex(buf, f, 0)) return;}
152
      /* find sqrt int integrate sum prod product Int Sum Prod conj abs,
158
      /* 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
159
       * so must be texmath interpretated ; after going to tex, return in any case
154
       */
160
       */
155
    }
161
    }
156
/* look for  /  to interpretate as quotients -
162
/* look for  /  to interpretate as quotients -
157
 * extend the version by accepting something else than (
163
 * extend the version by accepting something else than (
158
*/  
164
*/  
159
    //for(pp=strchr(buf,'/'); pp!=NULL && *find_word_start(pp+1)!='('; pp=strchr(pp+1,'/'));
165
    //for(pp=strchr(buf,'/'); pp!=NULL && *find_word_start(pp+1)!='('; pp=strchr(pp+1,'/'));
160
    pp=strchr(buf,'/');
166
    pp=strchr(buf,'/');
161
    if(pp!=NULL) goto tex;  /* so a/4 can be reinterpreted as {a over 4 } ; transform also 5/(x+1) */
167
    if(pp!=NULL){ if( __gototex(buf,f,0)) return;} /* so a/4 can be reinterpreted as {a over 4 } ; transform also 5/(x+1) */
162
    if(rawmathready) rawmath_easy=1;
168
    if(rawmathready) rawmath_easy=1;
163
    for(pp=strchr(buf,'<'); pp!=NULL; pp=strchr(pp+1,'<'))
169
    for(pp=strchr(buf,'<'); pp!=NULL; pp=strchr(pp+1,'<'))
164
      string_modify(buf,pp,pp+1,"&lt;");
170
      string_modify(buf,pp,pp+1,"&lt;");
165
    for(pp=strchr(buf,'>'); pp!=NULL; pp=strchr(pp+1,'>'))
171
    for(pp=strchr(buf,'>'); pp!=NULL; pp=strchr(pp+1,'>'))
166
      string_modify(buf,pp,pp+1,"&gt;");
172
      string_modify(buf,pp,pp+1,"&gt;");
167
/* no tex has been introduced - so go to mathmlmath */
173
/* no tex has been introduced - so go to mathmlmath */
168
    mathmlmath(buf); output("%s",buf);
174
    mathmlmath(buf); output("%s",buf);
169
    rawmath_easy=0;
175
    rawmath_easy=0;
170
}
176
}
171
 
177
 
172
/* the following is not used in modules : no insmath_logic=yes somewhere */
178
/* the following is not used in modules : no insmath_logic=yes somewhere */
173
 
179