Rev 6525 | Rev 8155 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6525 | Rev 7673 | ||
---|---|---|---|
Line 29... | Line 29... | ||
29 | /* check whether the same tex source has already been produced */ |
29 | /* check whether the same tex source has already been produced */ |
30 | int instex_ready(char *p, char *n) |
30 | int instex_ready(char *p, char *n) |
31 | { |
31 | { |
32 | int i; |
32 | int i; |
33 | char *cl, buf[MAX_LINELEN+1]; |
33 | char *cl, buf[MAX_LINELEN+1]; |
34 | 34 | ||
35 | if(strlen(p)>=124) return 0; |
35 | if(strlen(p)>=124) return 0; |
36 | cl=getvar("instex_color"); if(cl!=NULL && *cl!=0) return 0; |
36 | cl=getvar("instex_color"); if(cl!=NULL && *cl!=0) return 0; |
37 | mystrncpy(buf,p,sizeof(buf)); tex_nospace(buf); |
37 | mystrncpy(buf,p,sizeof(buf)); tex_nospace(buf); |
38 | for(i=0;i<oldtexcnt;i++) { |
38 | for(i=0;i<oldtexcnt;i++) { |
39 | if(oldinstex[i].size==current_tex_size && |
39 | if(oldinstex[i].size==current_tex_size && |
Line 68... | Line 68... | ||
68 | char alignbak[2048]; |
68 | char alignbak[2048]; |
69 | char *pp, buf[MAX_LINELEN+1]; |
69 | char *pp, buf[MAX_LINELEN+1]; |
70 | ovlstrcpy(buf,p); |
70 | ovlstrcpy(buf,p); |
71 | instex_style="$$"; |
71 | instex_style="$$"; |
72 | if(!ts) texmath(buf); |
72 | if(!ts) texmath(buf); |
73 | /* ts=0 but there is some computer matrix to transform |
73 | /* ts=0 but there is some computer matrix to transform |
74 | * done by texmath, but it does much more as replacing strings in tmathfn |
74 | * done by texmath, but it does much more as replacing strings in tmathfn |
75 | * OK if buf contains " math computer-syntax" ; if not, the result may be bad |
75 | * OK if buf contains " math computer-syntax" ; if not, the result may be bad |
76 | */ |
76 | */ |
77 | else {// seems tex : need to interpret names of variables as \x or \calB |
77 | else {// seems tex : need to interpret names of variables as \x or \calB |
78 | //if (mathalign_base < 2) { //to check |
78 | //if (mathalign_base < 2) { //to check |
Line 87... | Line 87... | ||
87 | } |
87 | } |
88 | } |
88 | } |
89 | // } |
89 | // } |
90 | } |
90 | } |
91 | /* send to mathml */ |
91 | /* send to mathml */ |
92 | if (mathalign_base == 2 && mathml(buf,0)) { *p=0 ;return 1; } |
92 | if (mathalign_base == 2 && mathml(buf,0)) { *p=0 ;return 1; } |
93 | /* end if mathml option in case ts=1 or "computer matrix" */ |
93 | /* end if mathml option in case ts=1 or "computer matrix" */ |
94 | 94 | ||
95 | /* creating images*/ |
95 | /* creating images*/ |
96 | pp=getvar("ins_align"); |
96 | pp=getvar("ins_align"); |
97 | if(pp!=NULL) mystrncpy(alignbak,pp,sizeof(alignbak)); |
97 | if(pp!=NULL) mystrncpy(alignbak,pp,sizeof(alignbak)); |
98 | setvar("ins_align","middle"); |
98 | setvar("ins_align","middle"); |
99 | mystrncpy(ins_alt,buf,sizeof(ins_alt)); |
99 | mystrncpy(ins_alt,buf,sizeof(ins_alt)); |
100 | if(f==NULL) { |
100 | if(f==NULL) { |
101 | calc_instexst(buf); output("%s",buf); |
101 | calc_instexst(buf); output("%s",buf); |
102 | } |
102 | } |
103 | else { |
103 | else { |
104 | instex_usedynamic=1; exec_instex(buf); instex_usedynamic=0; |
104 | instex_usedynamic=1; exec_instex(buf); instex_usedynamic=0; |
105 | } |
105 | } |
106 | instex_style=""; |
106 | instex_style=""; |
107 | if(alignbak[0]) setvar("ins_align",alignbak); |
107 | if(alignbak[0]) setvar("ins_align",alignbak); |
108 | *p=0; return 0; |
108 | *p=0; return 0; |
109 | } |
109 | } |
110 | 110 | ||
111 | /* Intelligent insertion of math formulas, kernel */ |
111 | /* Intelligent insertion of math formulas, kernel */ |
112 | void __insmath(char *p) |
112 | void __insmath(char *p) |
113 | { |
113 | { |
114 | char *f, *pp, *pe, *p1, buf[MAX_LINELEN+1], nbuf[256]; |
114 | char *f, *pp, *pe, *p1, buf[MAX_LINELEN+1], nbuf[256]; |
115 | int ts, n, rawmathready; |
115 | int ts, n, rawmathready; |
116 | 116 | ||
117 | ovlstrcpy(buf,p); strip_trailing_spaces(buf); singlespace(buf); |
117 | ovlstrcpy(buf,p); strip_trailing_spaces(buf); singlespace(buf); |
118 | p1=getvar("insmath_slashsubst"); |
118 | p1=getvar("insmath_slashsubst"); |
119 | if(p1!=NULL && strstr(p1,"yes")!=NULL) slashsubst(buf); // substitute backslash parameters |
119 | if(p1!=NULL && strstr(p1,"yes")!=NULL) slashsubst(buf); // substitute backslash parameters |
120 | f=instex_check_static(buf); //decide if image already exists |
120 | f=instex_check_static(buf); //decide if image already exists |
121 | substit(buf);//substitute the variables |
121 | substit(buf);//substitute the variables |
122 | /* here replace .. by , : i=1 .. 5 -> i=1, 5 !*/ |
122 | /* here replace .. by , : i=1 .. 5 -> i=1, 5 !*/ |
123 | for(pp=strstr(buf,".."); pp!=NULL; pp=strstr(pp,"..")) { |
123 | for(pp=strstr(buf,".."); pp!=NULL; pp=strstr(pp,"..")) { |
124 | if(*(pp+2)=='.' || *(pp+2)==',') { |
124 | if(*(pp+2)=='.' || *(pp+2)==',') { |
Line 127... | Line 127... | ||
127 | *pp=','; *(pp+1)=' '; |
127 | *pp=','; *(pp+1)=' '; |
128 | } |
128 | } |
129 | /* decide if it should be tex */ |
129 | /* decide if it should be tex */ |
130 | ts=0; if(strchr(buf,'\\') || strchr(buf,'}')) ts=1; |
130 | ts=0; if(strchr(buf,'\\') || strchr(buf,'}')) ts=1; |
131 | /* if not and if variable insmath_rawmath is there, do rawmath */ |
131 | /* if not and if variable insmath_rawmath is there, do rawmath */ |
132 | rawmathready=0; |
132 | rawmathready=0; |
133 | if(!ts) { /* not tex, looking if rawmath is asked */ |
133 | if(!ts) { /* not tex, looking if rawmath is asked */ |
134 | pp=getvar("insmath_rawmath"); |
134 | pp=getvar("insmath_rawmath"); |
135 | if(pp!=NULL && strstr(pp,"yes")!=NULL) { |
135 | if(pp!=NULL && strstr(pp,"yes")!=NULL) { |
136 | rawmath(buf); rawmathready=1; |
136 | rawmath(buf); rawmathready=1; |
137 | } |
137 | } |
Line 139... | Line 139... | ||
139 | if(ts) { |
139 | if(ts) { |
140 | _replace_matrix (buf,"\\matrix{","matrix"); //could be done in any case if ts=1 |
140 | _replace_matrix (buf,"\\matrix{","matrix"); //could be done in any case if ts=1 |
141 | _replace_matrix (buf,"\\pmatrix{","pmatrix"); |
141 | _replace_matrix (buf,"\\pmatrix{","pmatrix"); |
142 | } |
142 | } |
143 | /* if ts=1 (it should be a tex formula) or if there is a [ , ; ] matrix */ |
143 | /* if ts=1 (it should be a tex formula) or if there is a [ , ; ] matrix */ |
144 | if(ts || |
144 | if(ts || |
145 | (strchr(buf,'[')!=NULL && (strchr(buf,',')!=NULL || strchr(buf,';')!=NULL))) { |
145 | (strchr(buf,'[')!=NULL && (strchr(buf,',')!=NULL || strchr(buf,';')!=NULL))) { |
146 | if(__gototex(buf, f, ts)) return; |
146 | if(__gototex(buf, f, ts)) return; |
147 | } |
147 | } |
148 | 148 | ||
149 | /* end creating images |
149 | /* end creating images |
150 | * we are now in the case where ts=0 and no need of tex for matrix */ |
150 | * we are now in the case where ts=0 and no need of tex for matrix */ |
151 | 151 | ||
152 | /* find math variables */ |
152 | /* find math variables */ |
153 | for(pp=find_mathvar_start(buf); *pp; pp=find_mathvar_start(pe)) { |
153 | for(pp=find_mathvar_start(buf); *pp; pp=find_mathvar_start(pe)) { |
154 | pe=find_mathvar_end(pp); n=pe-pp; |
154 | pe=find_mathvar_end(pp); n=pe-pp; |
155 | /* non alpha variable or too short or too long to be interpreted as tnames */ |
155 | /* non alpha variable or too short or too long to be interpreted as tnames */ |
156 | if(!isalpha(*pp) || n<3 || n>16) continue; |
156 | if(!isalpha(*pp) || n<3 || n>16) continue; |
157 | memmove(nbuf,pp,n); nbuf[n]=0; |
157 | memmove(nbuf,pp,n); nbuf[n]=0; |
158 | if(wordchr(tnames,nbuf)!=NULL) { if(__gototex(buf, f, 0)) return;} |
158 | if(wordchr(tnames,nbuf)!=NULL) { if(__gototex(buf, f, 0)) return;} |
159 | /* find sqrt int integrate sum prod product Int Sum Prod conj abs, |
159 | /* find sqrt int integrate sum prod product Int Sum Prod conj abs, |
160 | * so must be texmath interpretated ; after going to tex, return in any case |
160 | * so must be texmath interpretated ; after going to tex, return in any case |
161 | */ |
161 | */ |
162 | } |
162 | } |
163 | /* look for / to interpretate as quotients - |
163 | /* look for / to interpretate as quotients - |
164 | * extend the version by accepting something else than ( |
164 | * extend the version by accepting something else than ( |
165 | */ |
165 | */ |
166 | //for(pp=strchr(buf,'/'); pp!=NULL && *find_word_start(pp+1)!='('; pp=strchr(pp+1,'/')); |
166 | //for(pp=strchr(buf,'/'); pp!=NULL && *find_word_start(pp+1)!='('; pp=strchr(pp+1,'/')); |
167 | pp=strchr(buf,'/'); |
167 | pp=strchr(buf,'/'); |
168 | if(pp!=NULL){ if( __gototex(buf,f,0)) return;} /* so a/4 can be reinterpreted as {a over 4 } ; transform also 5/(x+1) */ |
168 | if(pp!=NULL){ if( __gototex(buf,f,0)) return;} /* so a/4 can be reinterpreted as {a over 4 } ; transform also 5/(x+1) */ |
169 | if(rawmathready) rawmath_easy=1; |
169 | if(rawmathready) rawmath_easy=1; |
170 | for(pp=strchr(buf,'<'); pp!=NULL; pp=strchr(pp+1,'<')) |
170 | for(pp=strchr(buf,'<'); pp!=NULL; pp=strchr(pp+1,'<')) |
Line 173... | Line 173... | ||
173 | string_modify(buf,pp,pp+1,">"); |
173 | string_modify(buf,pp,pp+1,">"); |
174 | /* no tex has been introduced - so go to mathmlmath */ |
174 | /* no tex has been introduced - so go to mathmlmath */ |
175 | mathmlmath(buf); output("%s",buf); |
175 | mathmlmath(buf); output("%s",buf); |
176 | rawmath_easy=0; |
176 | rawmath_easy=0; |
177 | } |
177 | } |
178 | 178 | ||
179 | /* the following is not used in modules : no insmath_logic=yes somewhere */ |
179 | /* the following is not used in modules : no insmath_logic=yes somewhere */ |
180 | 180 | ||
181 | char *andor[]={"and","or","not","is","isnot"}; |
181 | char *andor[]={"and","or","not","is","isnot"}; |
182 | #define andorcnt (sizeof(andor)/sizeof(andor[0])) |
182 | #define andorcnt (sizeof(andor)/sizeof(andor[0])) |
183 | char *andorlang[andorcnt], andorlangbuf[1024]; |
183 | char *andorlang[andorcnt], andorlangbuf[1024]; |
Line 218... | Line 218... | ||
218 | else {/*tt=3; */p3=p1+4;} |
218 | else {/*tt=3; */p3=p1+4;} |
219 | if(!isalpha(*p3)) continue; |
219 | if(!isalpha(*p3)) continue; |
220 | p4++; p5=find_matching(p4,')'); |
220 | p4++; p5=find_matching(p4,')'); |
221 | if(*p5!=')') continue; |
221 | if(*p5!=')') continue; |
222 | *p5=0; *p2=0; p2=p5+1; |
222 | *p5=0; *p2=0; p2=p5+1; |
223 | 223 | ||
224 | 224 | ||
225 | continue; |
225 | continue; |
226 | } |
226 | } |
227 | for(i=0;i<andorlangcnt;i++) if(strncmp(p1,andor[i],p2-p1)==0) break; |
227 | for(i=0;i<andorlangcnt;i++) if(strncmp(p1,andor[i],p2-p1)==0) break; |
228 | if(i<andorlangcnt) { |
228 | if(i<andorlangcnt) { |
229 | *p1=0; ps=find_word_start(ps); if(*ps) _put(ps); |
229 | *p1=0; ps=find_word_start(ps); if(*ps) _put(ps); |
Line 238... | Line 238... | ||
238 | { |
238 | { |
239 | char *pt; |
239 | char *pt; |
240 | if(!outputing) goto end; |
240 | if(!outputing) goto end; |
241 | pt=getvar("insmath_logic"); |
241 | pt=getvar("insmath_logic"); |
242 | if(pt==NULL || strstr(pt,"yes")==NULL) { |
242 | if(pt==NULL || strstr(pt,"yes")==NULL) { |
243 | __insmath(p); |
243 | __insmath(p); |
244 | end: *p=0; return; |
244 | end: *p=0; return; |
245 | } |
245 | } |
246 | _mathlogic(p,__insmath); |
246 | _mathlogic(p,__insmath); |
247 | } |
247 | } |