Rev 12229 | Rev 12249 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 12229 | Rev 12246 | ||
---|---|---|---|
Line 130... | Line 130... | ||
130 | /* add user-defined variables and function names, |
130 | /* add user-defined variables and function names, |
131 | * internal, only called by rawmath(). |
131 | * internal, only called by rawmath(). |
132 | */ |
132 | */ |
133 | void getuservar(void) |
133 | void getuservar(void) |
134 | { |
134 | { |
135 |
|
135 | char *p1, *p2, *p; |
136 |
|
136 | rm_uservars=rm_userfns=0; |
137 |
|
137 | p=getvar("wims_rawmath_variables"); |
138 |
|
138 | if(p!=NULL && *p!=0) { |
139 |
|
139 | ovlstrcpy(rm_vbuf,p); |
140 |
|
140 | for(p=rm_vbuf;*p;p++) if(*p==',') *p=' '; |
141 |
|
141 | for(p1=find_word_start(rm_vbuf);*p1;p1=find_word_start(p2)) { |
142 |
|
142 | rm_uservar[rm_uservars++]=p1; |
143 |
|
143 | p2=find_word_end(p1); |
144 |
|
144 | if(*p2!=0) *(p2++)=0; |
145 |
|
145 | } |
146 |
|
146 | } |
147 |
|
147 | p=getvar("wims_rawmath_functions"); |
148 |
|
148 | if(p!=NULL && *p!=0) { |
149 |
|
149 | ovlstrcpy(rm_fbuf,p); |
150 |
|
150 | for(p=rm_fbuf;*p;p++) if(*p==',') *p=' '; |
151 |
|
151 | for(p1=find_word_start(rm_fbuf);*p1;p1=find_word_start(p2)) { |
152 |
|
152 | rm_userfn[rm_userfns++]=p1; |
153 |
|
153 | p2=find_word_end(p1); |
154 |
|
154 | if(*p2!=0) *(p2++)=0; |
155 |
|
155 | } |
156 |
|
156 | } |
157 | } |
157 | } |
158 | 158 | ||
159 | /* Try to split a word into recognizable variables */ |
159 | /* Try to split a word into recognizable variables */ |
160 | char *mathname_split(char *p) |
160 | char *mathname_split(char *p) |
161 | { |
161 | { |
162 |
|
162 | int c,i,j,type; |
163 | 163 | ||
164 |
|
164 | c=0; |
165 |
|
165 | beg: for(i=get_evalcnt()-1; |
166 |
|
166 | i>=0 && strncmp(p,get_evalname(i),strlen(get_evalname(i)))!=0; |
167 |
|
167 | i--); |
168 |
|
168 | if(i>=0 && get_evaltype(i)>0) { |
169 |
|
169 | type=RM_FN; |
170 |
|
170 | j=strlen(get_evalname(i)); |
171 |
|
171 | gotit: |
172 |
|
172 | if(!*(p+j)) return p; |
173 |
|
173 | if(myisdigit(*(p+j)) && type!=RM_FN) return NULL; |
174 |
|
174 | if(!c) {string_modify(p,p+j,p+j," "); p+=j+1;} |
175 |
|
175 | else p+=j; |
176 |
|
176 | c++; goto beg; |
177 |
|
177 | } |
178 |
|
178 | for(i=mathname_no-1; |
179 | i>=0 && |
179 | i>=0 && |
180 | (strncmp(p,mathname[i].name,strlen(mathname[i].name))!=0 |
180 | (strncmp(p,mathname[i].name,strlen(mathname[i].name))!=0 |
181 | || mathname[i].style==RM_PREFIX); |
181 | || mathname[i].style==RM_PREFIX); |
182 |
|
182 | i--); |
183 |
|
183 | if(i>=0) { |
184 |
|
184 | type=mathname[i].style; |
185 |
|
185 | j=strlen(mathname[i].name); |
186 |
|
186 | goto gotit; |
187 |
|
187 | } |
188 |
|
188 | for(i=0;i<rm_uservars && |
189 |
|
189 | strncmp(rm_uservar[i],p,strlen(rm_uservar[i]));i++); |
190 |
|
190 | if(i<rm_uservars) { |
191 |
|
191 | type=RM_VAR; |
192 |
|
192 | j=strlen(rm_uservar[i]); goto gotit; |
193 |
|
193 | } |
194 |
|
194 | for(i=0;i<rm_userfns && |
195 | strncmp(p,rm_userfn[i],strlen(rm_userfn[i]));i++); |
195 | strncmp(p,rm_userfn[i],strlen(rm_userfn[i]));i++); |
196 | if(i<rm_userfns) { |
196 | if(i<rm_userfns) { |
197 | type=RM_FN; |
197 | type=RM_FN; |
198 | j=strlen(rm_userfn[i]); goto gotit; |
198 | j=strlen(rm_userfn[i]); goto gotit; |
199 | } |
199 | } |
200 |
|
200 | return NULL; |
201 | } |
201 | } |
202 | 202 | ||
203 | int __replace_badchar (char *p, char *old, char *new) |
203 | int __replace_badchar (char *p, char *old, char *new) |
- | 204 | { |
|
204 |
|
205 | int cnt = 0; |
205 | char *p1 ; |
206 | char *p1 ; |
206 | while((p1=strstr(p,old))!=NULL) { |
207 | while((p1=strstr(p,old))!=NULL) { |
207 | string_modify(p,p1,p1+strlen(old),"%s",new); |
208 | string_modify(p,p1,p1+strlen(old),"%s",new); |
208 | cnt++; |
209 | cnt++; |
209 | } |
210 | } |
210 | return cnt ; |
211 | return cnt ; |
211 | } |
212 | } |
212 | 213 | ||
213 | /* translate |x| into abs(x)*/ |
214 | /* translate |x| into abs(x)*/ |
214 | int __replace_abs ( char *p ) |
215 | int __replace_abs ( char *p ) |
215 | { |
216 | { |
216 |
|
217 | char *p1, *p2 ; |
217 |
|
218 | while((p1=strchr(p,'|'))!=NULL) { |
218 |
|
219 | p2=find_matching(p1+1,'|'); |
219 |
|
220 | if(p2==NULL) { return 1; break;} /* error; drop it. */ |
220 |
|
221 | *p2=')'; string_modify(p,p1,p1+1,"abs("); |
221 |
|
222 | } |
222 |
|
223 | return 0; |
223 | } |
224 | } |
224 | 225 | ||
225 | /* signs: translate ++, +-, -+, ... into one sign. */ |
226 | /* signs: translate ++, +-, -+, ... into one sign. */ |
226 | void __replace_plusminus ( char *p ) |
227 | void __replace_plusminus ( char *p ) |
227 | { |
228 | { |
228 |
|
229 | char *p1, *p2; |
229 |
|
230 | for(p1=p;*p1!=0;p1++) { |
230 |
|
231 | int sign, redundant; |
231 |
|
232 | if(*p1!='+' && *p1!='-') continue; |
232 |
|
233 | if(*p1=='+') sign=1; else sign=-1; |
233 |
|
234 | redundant=0; |
234 |
|
235 | for(p2=find_word_start(p1+1);*p2=='+' || *p2=='-'; |
235 |
|
236 | p2=find_word_start(p2+1)) { |
236 |
|
237 | if(*p2=='-') sign*=-1; |
237 |
|
238 | redundant=1; |
238 |
|
239 | } |
239 |
|
240 | if(redundant && *p2!='>' && strncmp(p2,">",4)!=0) { |
240 |
|
241 | if(sign==1) *p1='+'; else *p1='-'; |
241 |
|
242 | ovlstrcpy(p1+1,p2); |
242 |
|
243 | } |
243 |
|
244 | } |
244 | } |
245 | } |
245 | 246 | ||
246 | /* dangling decimal points |
247 | /* dangling decimal points |
247 | * 4. --> 4.0 4.x -> 4.0x |
248 | * 4. --> 4.0 4.x -> 4.0x |
248 | * .5 -> 0.5 |
249 | * .5 -> 0.5 |
249 | * another treatment is done in insmath (will replace .. by , ) |
250 | * another treatment is done in insmath (will replace .. by , ) |
250 | */ |
251 | */ |
251 | void __treat_decimal(char *p) |
252 | void __treat_decimal(char *p) |
- | 253 | { |
|
252 |
|
254 | char *p1 ; |
253 | for(p1=strchr(p,'.'); p1!=NULL; p1=strchr(p1+1,'.')) { |
255 | for(p1=strchr(p,'.'); p1!=NULL; p1=strchr(p1+1,'.')) { |
254 | /* multiple .. is conserved */ |
256 | /* multiple .. is conserved */ |
255 | if(*(p1+1)=='.') { |
257 | if(*(p1+1)=='.') { |
256 |
|
258 | do p1++; while(*p1=='.'); continue; |
257 | } |
259 | } |
258 | if(p1>p && myisdigit(*(p1-1)) && myisdigit(*(p1+1))) continue; |
260 | if(p1>p && myisdigit(*(p1-1)) && myisdigit(*(p1+1))) continue; |
259 | /* Non-digit dangling '.' is removed */ |
261 | /* Non-digit dangling '.' is removed */ |
260 | if((p1<=p || !myisdigit(*(p1-1))) && !myisdigit(*(p1+1))) { |
262 | if((p1<=p || !myisdigit(*(p1-1))) && !myisdigit(*(p1+1))) { |
261 |
|
263 | ovlstrcpy(p1,p1+1); p1--; continue; |
262 | } |
264 | } |
263 | if(p1==p || !myisdigit(*(p1-1))) { // nondigit.digit |
265 | if(p1==p || !myisdigit(*(p1-1))) { // nondigit.digit |
264 |
|
266 | string_modify(p,p1,p1,"0"); p1++; //add zero before point |
265 | } |
267 | } |
266 | if(!myisdigit(*(p1+1))) string_modify(p,p1+1,p1+1,"0"); //add zero after point |
268 | if(!myisdigit(*(p1+1))) string_modify(p,p1+1,p1+1,"0"); //add zero after point |
267 | } |
269 | } |
268 | } |
270 | } |
269 | 271 | ||
270 | /* replace new-lines, tabs, " */ |
272 | /* replace new-lines, tabs, " */ |
271 | void __replace_space(char *p) |
273 | void __replace_space(char *p) |
272 | { |
274 | { |
273 | char *p1 ; |
275 | char *p1 ; |
274 | for(p1=p;*p1!=0; p1++) { |
276 | for(p1=p;*p1!=0; p1++) { |
275 | if(*p1=='\\' || isspace(*p1)) *p1=' ';// replace \ and all spaces by a simple space - |
277 | if(*p1=='\\' || isspace(*p1)) *p1=' ';// replace \ and all spaces by a simple space - |
276 | if(*p1=='\"') { string_modify(p,p1,p1+1,"''"); p1++;} // replace " by '' |
278 | if(*p1=='\"') { string_modify(p,p1,p1+1,"''"); p1++;} // replace " by '' |
277 | } |
279 | } |
278 | } |
280 | } |
279 | 281 | ||
Line 281... | Line 283... | ||
281 | * Translate error-laden raw math into machine-understandable form. |
283 | * Translate error-laden raw math into machine-understandable form. |
282 | * do nothing if there is some { or \\ |
284 | * do nothing if there is some { or \\ |
283 | */ |
285 | */ |
284 | void rawmath(char *p) |
286 | void rawmath(char *p) |
285 | { |
287 | { |
286 |
|
288 | char *p1, *p2, *p3, *p4; |
287 |
|
289 | char warnbuf[1024]; |
288 |
|
290 | int ambiguous=0,unknown=0,flatpower=0,badprec=0,unmatch=0;// for warning |
289 | 291 | ||
290 | /* looks like a TeX source : do nothing */ |
292 | /* looks like a TeX source : do nothing */ |
291 |
|
293 | if( (strchr(p,'\\')!=NULL || strchr(p,'{')!=NULL)) return; |
292 |
|
294 | if(strchr(p,'^')==NULL) flatpower=-1; |
293 |
|
295 | if(strlen(p)>=MAX_LINELEN) {*p=0; return;} |
294 |
|
296 | p1=find_word_start(p);if(*p1==0) return; |
295 |
|
297 | while(*p1=='+') p1++; |
296 |
|
298 | if(p1>p) ovlstrcpy(p,p1); |
297 |
|
299 | (void)__replace_badchar(p,"**", "^"); |
298 |
|
300 | (void)__replace_badchar(p,"\xa0", " "); |
299 |
|
301 | if (__replace_badchar(p,"²", "^2 ")) flatpower=1; |
300 |
|
302 | if (__replace_badchar(p,"³", "^3 ")) flatpower=1; |
301 |
|
303 | unmatch=__replace_abs(p); |
302 |
|
304 | __replace_plusminus(p) ; |
303 |
|
305 | __replace_space(p); |
304 |
|
306 | __treat_decimal(p); |
305 |
|
307 | if (rawmath_easy) return; |
306 | 308 | ||
307 | /* Principal translation: justapositions to multiplications */ |
309 | /* Principal translation: justapositions to multiplications */ |
308 |
|
310 | if(strstr(p,"^1/")!=NULL) badprec=1; |
309 |
|
311 | getuservar(); |
310 |
|
312 | for(p1=p;*p1;p1++) { |
311 |
|
313 | if(!isalnum(*p1) && *p1!=')' && *p1!=']') continue; |
312 |
|
314 | if(*p1==')' || *p1==']') { |
313 |
|
315 | p2=find_word_start(++p1); |
314 |
|
316 | add_star: |
315 |
|
317 | if(isalnum(*p2) || *p2=='(' || *p2=='[') { |
316 | if(*p2=='(' && *p1==')') ambiguous=1; |
318 | if(*p2=='(' && *p1==')') ambiguous=1; |
317 | if(p2>p1) *p1='*'; |
319 | if(p2>p1) *p1='*'; |
318 | else string_modify(p,p1,p1,"*"); |
320 | else string_modify(p,p1,p1,"*"); |
319 |
|
321 | } |
320 |
|
322 | p1--;continue; |
321 | } |
323 | } |
322 | p2=find_mathvar_end(p1); p3=find_word_start(p2); |
324 | p2=find_mathvar_end(p1); p3=find_word_start(p2); |
323 | if(myisdigit(*p1)) { |
325 | if(myisdigit(*p1)) { |
324 |
|
326 | p1=p2; p2=p3; goto add_star; |
325 | } |
327 | } |
326 | else { |
328 | else { |
327 |
|
329 | char buf[MAX_LINELEN+1]; |
328 |
|
330 | int i; |
329 |
|
331 | if(p2-p2>30) goto ambig; |
330 |
|
332 | memcpy(buf,p1,p2-p1);buf[p2-p1]=0; |
331 |
|
333 | i=search_evaltab(buf); |
332 |
|
334 | if(i>=0 && get_evaltype(i)>0) { |
333 |
|
335 | fnname1: |
334 |
|
336 | p1=p2;p2=p3; |
335 | /*fnname:*/ |
337 | /*fnname:*/ |
336 |
|
338 | if(*p2 && *p2!='(' && *p2!='*' && *p2!='/') { |
337 |
|
339 | char hatbuf[MAX_LINELEN+1]; |
338 |
|
340 | hatbuf[0]=')'; hatbuf[1]=0; |
339 |
|
341 | if(*p2=='^') { |
340 |
|
342 | p3=p2+1;while(*p3==' ' || *p3=='+' || *p3=='-') p3++; |
341 |
|
343 | if(*p3=='(') { |
342 |
|
344 | p3=find_matching(p3+1,')'); |
343 |
|
345 | if(p3==NULL) {unmatch=1; p3=p+strlen(p);} |
344 |
|
346 | else p3++; |
345 |
|
347 | } |
346 |
|
348 | else p3=find_mathvar_end(p3); |
347 |
|
349 | memmove(hatbuf+1,p2,p3-p2);hatbuf[p3-p2+1]=0; |
348 |
|
350 | ovlstrcpy(p2,p3); |
349 |
|
351 | while(*p2==' ') p2++; |
350 |
|
352 | if(*p2=='*' || *p2=='/') { |
351 |
|
353 | p1--;continue; |
352 | } |
- | |
353 | if(*p2=='(') { |
- | |
354 | p3=find_matching(p2+1,')'); |
- | |
355 | if(p3==NULL) {unmatch=1; p3=p+strlen(p);} |
- | |
356 | else p3++; |
- | |
357 | string_modify(p,p3,p3,"%s",hatbuf+1); |
- | |
358 | goto dd2; |
- | |
359 | } |
- | |
360 | } |
354 | } |
361 |
|
355 | if(*p2=='(') { |
362 | while(isalnum(*p3) || *p3=='*' || *p3=='/' || *p3=='.') |
- | |
363 | p3+ |
356 | p3=find_matching(p2+1,')'); |
364 |
|
357 | if(p3==NULL) {unmatch=1; p3=p+strlen(p);} |
365 |
|
358 | else p3++; |
366 |
|
359 | string_modify(p,p3,p3,"%s",hatbuf+1); |
- | 360 | goto dd2; |
|
367 | } |
361 | } |
368 | else { |
- | |
369 | string_modify(p,p3,p3,"%s",hatbuf); |
- | |
370 | if(p1==p2) string_modify(p,p2,p2,"("); |
- | |
371 | else *p1='('; |
- | |
372 | } |
- | |
373 | dd2: |
- | |
374 | ambiguous=1; |
- | |
375 | } |
- | |
376 | p1--;continue; |
- | |
377 | } |
- | |
378 | i=search_list(mathname,mathname_no,sizeof(mathname[0]),buf); |
- | |
379 | if(i>=0) { |
- | |
380 | if(mathname[i].replace[0]!=0) { |
- | |
381 | string_modify(p,p1,p2,mathname[i].replace); |
- | |
382 | p2=p1+strlen(mathname[i].replace); |
- | |
383 | p3=find_word_start(p2); |
- | |
384 | } |
362 | } |
385 |
|
363 | p3=p2;if(*p3=='+' || *p3=='-') p3++; |
386 | case RM_FN: |
- | |
387 | goto fnname1; |
- | |
388 | - | ||
389 | case RM_VAR: |
- | |
390 |
|
364 | while(isalnum(*p3) || *p3=='*' || *p3=='/' || *p3=='.') |
391 | - | ||
392 |
|
365 | p3++; |
393 | if(*p3!='c' && *p3!='s' && *p3!='t' && |
- | |
394 |
|
366 | for(p4=p2; p4<p3 && !isalnum(*p4); p4++); |
395 |
|
367 | if(p4>=p3) { |
396 |
|
368 | if(hatbuf[1]) string_modify(p,p2,p2,"%s",hatbuf+1); |
397 | } |
369 | } |
398 | } |
- | |
399 | i=search_list(hmname,hmname_no,sizeof(hmname[0]),buf); |
- | |
400 | if(i>=0) { |
- | |
401 | p1=p2; p2=p3; goto add_star; |
- | |
402 | } |
- | |
403 | for(i=0;i<rm_uservars && strcmp(buf,rm_uservar[i]);i++); |
- | |
404 | if(i<rm_uservars) { |
- | |
405 | p1=p2;p2=p3;goto add_star; |
- | |
406 | } |
- | |
407 | for(i=0;i<rm_userfns && strcmp(buf,rm_userfn[i]);i++); |
- | |
408 | if(i<rm_userfns) goto fnname1; |
- | |
409 | if(p2-p1>8) goto ambig; |
- | |
410 | if(mathname_split(buf)!=NULL) { |
- | |
411 | ambiguous=1; |
- | |
412 | string_modify(p,p1,p2,"%s",buf); |
- | |
413 | p1--; continue; |
- | |
414 | } |
- | |
415 | /* unknown name */ |
- | |
416 | ambig: p1=p2;p2=p3; |
- | |
417 | if(strlen(buf)>1) { |
- | |
418 | for(p3=buf;*p3!=0 && !myisdigit(*p3);p3++); |
- | |
419 | if(*p3!=0 && flatpower!=0) flatpower=1; |
- | |
420 | else { |
370 | else { |
421 |
|
371 | string_modify(p,p3,p3,"%s",hatbuf); |
422 |
|
372 | if(p1==p2) string_modify(p,p2,p2,"("); |
- | 373 | else *p1='('; |
|
423 | } |
374 | } |
- | 375 | dd2: |
|
- | 376 | ambiguous=1; |
|
- | 377 | } |
|
- | 378 | p1--;continue; |
|
- | 379 | } |
|
- | 380 | i=search_list(mathname,mathname_no,sizeof(mathname[0]),buf); |
|
- | 381 | if(i>=0) { |
|
- | 382 | if(mathname[i].replace[0]!=0) { |
|
- | 383 | string_modify(p,p1,p2,mathname[i].replace); |
|
- | 384 | p2=p1+strlen(mathname[i].replace); |
|
- | 385 | p3=find_word_start(p2); |
|
- | 386 | } |
|
- | 387 | switch(mathname[i].style) { |
|
- | 388 | case RM_FN: |
|
- | 389 | goto fnname1; |
|
- | 390 | ||
- | 391 | case RM_VAR: |
|
- | 392 | p1=p2;p2=p3; goto add_star; |
|
- | 393 | ||
- | 394 | case RM_PREFIX: |
|
- | 395 | if(*p3!='c' && *p3!='s' && *p3!='t' && |
|
- | 396 | *p3!='C' && *p3!='S' && *p3!='T') break; |
|
- | 397 | ambiguous=1; |
|
- | 398 | ovlstrcpy(p2,p3); p1--; continue; |
|
424 | } |
399 | } |
- | 400 | } |
|
- | 401 | i=search_list(hmname,hmname_no,sizeof(hmname[0]),buf); |
|
425 |
|
402 | if(i>=0) { |
426 |
|
403 | p1=p2; p2=p3; goto add_star; |
427 |
|
404 | } |
- | 405 | for(i=0;i<rm_uservars && strcmp(buf,rm_uservar[i]);i++); |
|
428 |
|
406 | if(i<rm_uservars) { |
- | 407 | p1=p2;p2=p3;goto add_star; |
|
- | 408 | } |
|
- | 409 | for(i=0;i<rm_userfns && strcmp(buf,rm_userfn[i]);i++); |
|
- | 410 | if(i<rm_userfns) goto fnname1; |
|
429 |
|
411 | if(p2-p1>8) goto ambig; |
- | 412 | if(mathname_split(buf)!=NULL) { |
|
- | 413 | ambiguous=1; |
|
430 |
|
414 | string_modify(p,p1,p2,"%s",buf); |
- | 415 | p1--; continue; |
|
- | 416 | } |
|
- | 417 | /* unknown name */ |
|
- | 418 | ambig: p1=p2;p2=p3; |
|
- | 419 | if(strlen(buf)>1) { |
|
- | 420 | for(p3=buf;*p3!=0 && !myisdigit(*p3);p3++); |
|
- | 421 | if(*p3!=0 && flatpower!=0) flatpower=1; |
|
- | 422 | else { |
|
- | 423 | unknown=1; |
|
- | 424 | force_setvar("wims_warn_rawmath_parm",buf); |
|
431 | } |
425 | } |
432 | p1--;continue; |
- | |
433 | } |
426 | } |
- | 427 | else { |
|
- | 428 | if(*p2=='(') ambiguous=1; |
|
- | 429 | } |
|
- | 430 | if(isalnum(*p2)) { |
|
- | 431 | if(p2>p1) *p1='*'; |
|
- | 432 | else string_modify(p,p1,p1,"*"); |
|
- | 433 | } |
|
- | 434 | p1--;continue; |
|
434 | } |
435 | } |
- | 436 | } |
|
435 |
|
437 | warnbuf[0]=0; |
436 |
|
438 | if(ambiguous) strcat(warnbuf," ambiguous"); |
437 |
|
439 | if(unknown) strcat(warnbuf," unknown"); |
438 |
|
440 | if(flatpower>0) strcat(warnbuf," flatpower"); |
439 |
|
441 | if(badprec>0) strcat(warnbuf," badprec"); |
440 |
|
442 | if(unmatch>0) strcat(warnbuf," unmatched_parentheses"); |
441 |
|
443 | if(warnbuf[0]) { |
442 | char buf[MAX_LINELEN+1],*p; |
444 | char buf[MAX_LINELEN+1],*p; |
443 | p=getvar("wims_warn_rawmath"); |
445 | p=getvar("wims_warn_rawmath"); |
444 | if(p!=NULL && *p!=0) { |
446 | if(p!=NULL && *p!=0) { |
445 |
|
447 | snprintf(buf,sizeof(buf),"%s %s",p,warnbuf); |
446 |
|
448 | force_setvar("wims_warn_rawmath",buf); |
447 | } |
449 | } |
448 | else force_setvar("wims_warn_rawmath",warnbuf); |
450 | else force_setvar("wims_warn_rawmath",warnbuf); |
449 |
|
451 | } |
450 | } |
452 | } |
451 | 453 | ||
452 | /* replace < and > by html code if htmlmath_gtlt=yes |
454 | /* replace < and > by html code if htmlmath_gtlt=yes |
453 | * is only used in deduc - not documented |
455 | * is only used in deduc - not documented |
454 | */ |
456 | */ |
455 | void __replace_htmlmath_gtlt (char *p) |
457 | void __replace_htmlmath_gtlt (char *p) |
- | 458 | { |
|
456 |
|
459 | char *pp; |
457 |
|
460 | char *p1=getvar("htmlmath_gtlt"); |
458 |
|
461 | if(p1!=NULL && strcmp(p1,"yes")==0) { |
459 |
|
462 | for(pp=strchr(p,'<'); pp!=NULL; pp=strchr(pp+1,'<')) |
460 | string_modify(p,pp,pp+1,"<"); |
463 | string_modify(p,pp,pp+1,"<"); |
461 |
|
464 | for(pp=strchr(p,'>'); pp!=NULL; pp=strchr(pp+1,'>')) |
462 | string_modify(p,pp,pp+1,">"); |
465 | string_modify(p,pp,pp+1,">"); |
463 |
|
466 | } |
464 | } |
467 | } |
465 | 468 | ||
466 | /* exponents or indices : |
469 | /* exponents or indices : |
467 | * all digits or + or - following a ^ or _ are considered as in exponent/subscript |
470 | * all digits or + or - following a ^ or _ are considered as in exponent/subscript |
468 | * expression with ( ) following a ^ or _ are considered as in exponent/subscript |
471 | * expression with ( ) following a ^ or _ are considered as in exponent/subscript |
469 | * the parenthesis are suppressed except in case of exponent and only digits. |
472 | * the parenthesis are suppressed except in case of exponent and only digits. |
470 | * if int n != 0, use html code, else use tex code |
473 | * if int n != 0, use html code, else use tex code |
471 | */ |
474 | */ |
472 | void __replace_exponent(char *p, int n) |
475 | void __replace_exponent(char *p, int n) |
473 | { |
476 | { |
474 |
|
477 | char *p1; |
475 |
|
478 | char *SUPBEG, *SUPEND; |
476 |
|
479 | if (n) { SUPBEG = "<sup>"; SUPEND = "</sup>";} |
477 |
|
480 | else { SUPBEG = "^{"; SUPEND = "}";} |
478 | 481 | ||
479 |
|
482 | for(p1=strchr(p,'^');p1!=NULL;p1=strchr(p1+1,'^')) { |
480 |
|
483 | char *p2, *p3, *pp; |
481 |
|
484 | char c; |
482 |
|
485 | p3 = p2 = find_word_start(p1+1); |
483 |
|
486 | if(*p2=='+' || *p2=='-') p2++; |
484 |
|
487 | p2 = find_word_start(p2); |
485 | /* add '}' to recognized parenthesis in exponent |
488 | /* add '}' to recognized parenthesis in exponent |
486 | * !mathmlmath 2 \cdot x^{3} will now produce correct exponent... |
489 | * !mathmlmath 2 \cdot x^{3} will now produce correct exponent... |
487 | * !mathmlmath should convert LaTeX input into correct MathML |
490 | * !mathmlmath should convert LaTeX input into correct MathML |
488 | */ |
491 | */ |
489 |
|
492 | if(*p2=='(' || *p2 == '{') { /* ^[+-]( */ |
490 |
|
493 | if(*p2 == '('){ p2 = find_matching(p2+1,')');}else { if(*p2 == '{'){ p2 = find_matching(p2+1,'}');}} |
491 | /* no matching ')' : p2 = end of line; otherwise just after ')' */ |
494 | /* no matching ')' : p2 = end of line; otherwise just after ')' */ |
492 |
|
495 | if (p2==NULL) p2=p+strlen(p); else p2++; |
493 | /* ^( followed by any number of digits/letters, up to p2 |
496 | /* ^( followed by any number of digits/letters, up to p2 |
494 | * [FIXME: no sign?] */ |
497 | * [FIXME: no sign?] */ |
495 | /* do we remove parentheses containing exponent group ? */ |
498 | /* do we remove parentheses containing exponent group ? */ |
496 |
|
499 | if (*p3=='(') for(pp=p3+1;pp<p2-1;pp++) { |
497 |
|
500 | if(!isalnum(*pp)) { |
498 | /* not a digit/letter. Remove (). */ |
501 | /* not a digit/letter. Remove (). */ |
499 |
|
502 | p3++;*(p2-1)=0;break; |
500 |
|
503 | } |
501 | /* x^(2), parentheses not removed */ |
504 | /* x^(2), parentheses not removed */ |
502 |
|
505 | } |
503 | /* p3: start of word after ^ |
506 | /* p3: start of word after ^ |
504 | * matching parentheses from exponent group. : f^(4) 4-derivative |
507 | * matching parentheses from exponent group. : f^(4) 4-derivative |
505 | * don't ignore / remove a leading + sign in exponent group : Cu^+ |
508 | * don't ignore / remove a leading + sign in exponent group : Cu^+ |
506 | */ |
509 | */ |
- | 510 | } |
|
507 |
|
511 | else { /* ^[+-] */ |
508 |
|
512 | char *ptt=p2; |
509 |
|
513 | p2=find_word_start(find_mathvar_end(p2)); |
510 |
|
514 | if(*p2=='(' && isalpha(*ptt)) { |
511 |
|
515 | /* ^[+-]var( */ |
512 |
|
516 | char *p2t; |
513 |
|
517 | p2t=find_matching(p2+1,')'); if(p2t!=NULL) p2=p2t+1; |
514 |
|
518 | /* FIXME: what if no matching ) ? */ |
515 |
|
519 | } |
516 | /* ^[+-]var(...): p2 points after closing ')' |
520 | /* ^[+-]var(...): p2 points after closing ')' |
517 | * FIXME: I don't think this 'else' branch is sensible. One |
521 | * FIXME: I don't think this 'else' branch is sensible. One |
518 | * should NOT accept x^b(c+1) as meaning x^[b(c+1)]. I would |
522 | * should NOT accept x^b(c+1) as meaning x^[b(c+1)]. I would |
519 | * remove it altogether. |
523 | * remove it altogether. |
520 | */ |
524 | */ |
521 |
|
525 | } |
522 | /* p1 points at ^ before exponent group |
526 | /* p1 points at ^ before exponent group |
523 | * p2 points at end of exponent group |
527 | * p2 points at end of exponent group |
524 | * p3 = exponent group (sometimes stripped, without parentheses) |
528 | * p3 = exponent group (sometimes stripped, without parentheses) |
525 | * |
529 | * |
526 | * truncate string p at p2 [ c = char deleted by truncation ] |
530 | * truncate string p at p2 [ c = char deleted by truncation ] |
527 | */ |
531 | */ |
528 |
|
532 | c = *p2;if(c!=0) *p2++=0; |
529 | /* replace ^<exponent group>. Add back missing character 'c' */ |
533 | /* replace ^<exponent group>. Add back missing character 'c' */ |
530 |
|
534 | string_modify(p,p1,p2, "%s%s%s%c",SUPBEG,p3,SUPEND,c); |
531 |
|
535 | } |
532 | } |
536 | } |
533 | 537 | ||
534 | /* if int n != 0, use html code, else use tex code */ |
538 | /* if int n != 0, use html code, else use tex code */ |
535 | void __replace_subscript(char *p, int n) |
539 | void __replace_subscript(char *p, int n) |
536 | { |
540 | { |
Line 550... | Line 554... | ||
550 | string_modify(p,p1,p2,"%s%s%s",SUBBEG,buff,SUBEND);} |
554 | string_modify(p,p1,p2,"%s%s%s",SUBBEG,buff,SUBEND);} |
551 | } |
555 | } |
552 | 556 | ||
553 | /* get rid of 1*.. ..*1 exemple : 1 * x, x/1 */ |
557 | /* get rid of 1*.. ..*1 exemple : 1 * x, x/1 */ |
554 | void __replace_getrid1 (char *p) |
558 | void __replace_getrid1 (char *p) |
- | 559 | { |
|
555 |
|
560 | char *p1, *p2, *p3 ; |
556 |
|
561 | for(p1=p;*p1;p1++) { |
557 |
|
562 | if(*p1!='1') continue; |
558 |
|
563 | if(myisdigit(*(p1+1)) || *(p1+1)=='.' || |
559 |
|
564 | (p1>p && (isalnum(*(p1-1)) || *(p1-1)=='.')) ) continue; |
560 |
|
565 | p2=find_word_start(p1+1); |
561 |
|
566 | if(p1>p+2 && (*(p1-1)=='-' || *(p1-1)=='+')) { |
562 |
|
567 | for(p3=p1-2; p3>p && isspace(*p3); p3--); |
563 |
|
568 | if(p3>p+1 && (*p3=='E' || *p3=='e')) { /* ??? */ |
564 | p3--; while(p3>p && isspace(*p3)) p3--; |
569 | p3--; while(p3>p && isspace(*p3)) p3--; |
565 | if(myisdigit(*p3) || *p3=='.') continue; |
570 | if(myisdigit(*p3) || *p3=='.') continue; |
566 | } |
- | |
567 | } |
571 | } |
- | 572 | } |
|
568 |
|
573 | if(p1==p) p3="+"; |
569 |
|
574 | else for(p3=p1-1;p3>p && isspace(*p3);p3--); |
570 |
|
575 | if(*p2=='*' && *p3!='/') {/* delete 1 if 1* or /1 */ |
571 |
|
576 | ovlstrcpy(p1,p2+1);continue; |
572 |
|
577 | } |
573 |
|
578 | if(isalpha(*p2) && *p3!='/') { |
574 |
|
579 | ovlstrcpy(p1,p2);continue; |
575 |
|
580 | } |
576 |
|
581 | if(*p3=='/' && *p2!='<') ovlstrcpy(p3,p2); |
577 | 582 | ||
578 |
|
583 | } |
579 | } |
584 | } |
580 | 585 | ||
581 | /* get rid of '*' */ |
586 | /* get rid of '*' */ |
582 | void __replace_getridstar (char *p) |
587 | void __replace_getridstar (char *p) |
- | 588 | { |
|
583 |
|
589 | char *p1 ; |
584 | for(p1=strchr(p,'*');p1!=NULL;p1=strchr(p1+1,'*')) { |
590 | for(p1=strchr(p,'*');p1!=NULL;p1=strchr(p1+1,'*')) { |
585 | char *pq; |
591 | char *pq; |
586 | pq=find_word_start(p1+1); |
592 | pq=find_word_start(p1+1); |
587 | if(myisdigit(*pq)) { |
593 | if(myisdigit(*pq)) { |
588 |
|
594 | string_modify(p,p1,pq,"×"); |
589 |
|
595 | continue; |
590 | } |
596 | } |
591 | if(p1>p && (isalpha(*(p1-1)) || *(p1-1)==')' || *(p1-1)=='>') |
597 | if(p1>p && (isalpha(*(p1-1)) || *(p1-1)==')' || *(p1-1)=='>') |
592 | && (isalnum(*pq) || *pq=='$')) *p1=' '; |
598 | && (isalnum(*pq) || *pq=='$')) *p1=' '; |
593 | else { |
599 | else { |
594 | ovlstrcpy(p1,p1+1);p1--; |
600 | ovlstrcpy(p1,p1+1);p1--; |
595 | } |
601 | } |
596 | } |
602 | } |
597 | } |
603 | } |
598 | 604 | ||
599 | /* <=, >=, ->, =>, <=> |
605 | /* <=, >=, ->, =>, <=> |
600 | * if int n != 0, use html code, else use tex code |
606 | * if int n != 0, use html code, else use tex code |
601 | */ |
607 | */ |
602 | 608 | ||
603 | void __replace_arrow ( char *p, int n) |
609 | void __replace_arrow ( char *p, int n) |
- | 610 | { |
|
604 |
|
611 | char *p1, *p2, *m_prefix; |
605 |
|
612 | if (n) m_prefix="$m_"; else m_prefix="\\"; |
606 | 613 | ||
607 |
|
614 | for(p1=strstr(p,"<="); p1!=NULL; p1=strstr(p1+1,"<=")) { |
608 |
|
615 | if(*(p1+5)!='&' && *(p1+5)!='=') |
609 |
|
616 | string_modify(p,p1,p1+5, "%sle",m_prefix); |
610 |
|
617 | else { |
611 |
|
618 | for(p2=p1+5; *p2=='='; p2++); |
612 |
|
619 | if(strncmp(p2,">",4)==0) { |
613 |
|
620 | if(p2>p1+5) { string_modify(p,p1,p2+4,"%sLongleftrightarrow",m_prefix);} |
614 |
|
621 | else { string_modify(p,p1,p2+4,"%sLeftrightarrow",m_prefix);} |
615 | } |
- | |
616 | else { string_modify(p,p1,p2,"%sLongleftarrow",m_prefix);} |
- | |
617 | } |
622 | } |
- | 623 | else { string_modify(p,p1,p2,"%sLongleftarrow",m_prefix);} |
|
618 | } |
624 | } |
- | 625 | } |
|
619 |
|
626 | for(p1=strstr(p,">="); p1!=NULL; p1=strstr(p1+1,">=")) { |
620 |
|
627 | if(*(p1+5)!='=') { string_modify(p,p1,p1+5,"%sge",m_prefix);} |
621 |
|
628 | } |
622 |
|
629 | for(p1=strstr(p,"->"); p1; p1=strstr(p1+1,"->")) { |
623 |
|
630 | for(p2=p1; p2>p && *(p2-1)=='-'; p2--); |
624 |
|
631 | if(p2>p && *(p2-1)==';') continue; |
625 |
|
632 | if(p2<p1) { string_modify(p,p2,p1+5,"%slongrightarrow",m_prefix);} |
626 |
|
633 | else { string_modify(p,p1,p1+5,"%srightarrow",m_prefix);} |
627 |
|
634 | } |
628 |
|
635 | for(p1=strstr(p,"=>"); p1; p1=strstr(p1+1,"=>")) { |
629 |
|
636 | for(p2=p1; p2>p && *(p2-1)=='='; p2--); |
630 |
|
637 | if(p2>p && *(p2-1)==';') continue; |
631 |
|
638 | if(p2<p1) { string_modify(p,p2,p1+5,"%sLongrightarrow",m_prefix);} |
632 |
|
639 | else { string_modify(p,p1,p1+5,"%sRightarrow",m_prefix) ;} |
633 |
|
640 | } |
634 | /* Not equal */ |
641 | /* Not equal */ |
635 |
|
642 | for(p1=strstr(p,"!="); p1; p1=strstr(p1+1,"!=")) { |
636 |
|
643 | if(p1>p && !isspace(*(p1-1))) continue; |
637 |
|
644 | string_modify(p,p1,p1+2,"%sneq",m_prefix); |
638 |
|
645 | } |
639 | } |
646 | } |
640 | 647 | ||
641 | /* why <tt> is used sometimes ? replace single characters by italics one |
648 | /* why <tt> is used sometimes ? replace single characters by italics one |
642 | * is it useful in mathml ? |
649 | * is it useful in mathml ? |
643 | */ |
650 | */ |
644 | void __replace_italics (char *p, int n) |
651 | void __replace_italics (char *p, int n) |
- | 652 | { |
|
645 |
|
653 | char *p1, *p2, *p3, pbuf[16]; |
646 | char *ITBEG, *ITEND, *ITtBEG, *ITtEND; |
654 | char *ITBEG, *ITEND, *ITtBEG, *ITtEND; |
647 | if (n) { |
655 | if (n) { |
648 | ITBEG = "<i>";ITtBEG = "<i><tt>"; |
656 | ITBEG = "<i>";ITtBEG = "<i><tt>"; |
649 | ITEND = "</i>";ITtEND = "</tt></i>"; |
657 | ITEND = "</i>";ITtEND = "</tt></i>"; |
650 | } else {; |
658 | } else {; |
Line 652... | Line 660... | ||
652 | ITEND = ""; ITtEND = ""; |
660 | ITEND = ""; ITtEND = ""; |
653 | } |
661 | } |
654 | 662 | ||
655 | for(p1=p;*p1;p1++) { |
663 | for(p1=p;*p1;p1++) { |
656 | if(*p1=='<') { |
664 | if(*p1=='<') { |
- | 665 | p1=strchr(p1,'>'); |
|
657 |
|
666 | if(p1==NULL) break; //recognize an html tag < > |
658 |
|
667 | else continue; |
659 | } |
668 | } |
660 | if(*p1=='=' && *(p1+1)=='-') { |
669 | if(*p1=='=' && *(p1+1)=='-') { |
661 | string_modify(p,p1+1,p1+1," "); p1+=2; continue; |
670 | string_modify(p,p1+1,p1+1," "); p1+=2; continue; |
662 | } |
671 | } |
663 | if(*p1=='\'') { |
672 | if(*p1=='\'') { |
664 |
|
673 | for(p2=p1+1;*p2=='\'';p2++); |
665 |
|
674 | memmove(pbuf,p1,p2-p1); pbuf[p2-p1]=0; |
666 |
|
675 | string_modify(p,p1,p2,"%s%s%s",ITtBEG,pbuf,ITtEND); |
667 |
|
676 | p1=p2+strlen(ITtBEG)+strlen(ITtEND)-1; |
668 |
|
677 | continue; |
669 | } |
678 | } |
670 | if(!isalpha(*p1)) continue; |
679 | if(!isalpha(*p1)) continue; |
671 | /* unique letter.*/ |
680 | /* unique letter.*/ |
672 | for(p2=p1+1;isalpha(*p2);p2++); |
681 | for(p2=p1+1;isalpha(*p2);p2++); |
673 | p3=find_word_start(p2); |
682 | p3=find_word_start(p2); |
674 | if(p2>p1+5 || |
683 | if(p2>p1+5 || |
675 | (p2>p1+1 && (*p3==';' || *p3=='(' || myisdigit(*p2)))) |
684 | (p2>p1+1 && (*p3==';' || *p3=='(' || myisdigit(*p2)))) |
676 |
|
685 | {p1=p2-1; continue;} |
677 | if(strncasecmp(p3,"</i>",strlen("</i>"))==0) continue; |
686 | if(strncasecmp(p3,"</i>",strlen("</i>"))==0) continue; |
678 | memmove(pbuf,p1,p2-p1); pbuf[p2-p1]=0; |
687 | memmove(pbuf,p1,p2-p1); pbuf[p2-p1]=0; |
679 | string_modify(p,p1,p2,"%s%s%s",ITBEG,pbuf,ITEND); |
688 | string_modify(p,p1,p2,"%s%s%s",ITBEG,pbuf,ITEND); |
680 | p1=p2+strlen(ITBEG)+strlen(ITEND)-1; |
689 | p1=p2+strlen(ITBEG)+strlen(ITEND)-1; |
681 |
|
690 | } |
682 | } |
691 | } |
683 | 692 | ||
684 | /* float (1.2 E-03) : 3E+021 -> 3 × 10^{21} - 3E-21 -> 3 × 10^{-21} |
693 | /* float (1.2 E-03) : 3E+021 -> 3 × 10^{21} - 3E-21 -> 3 × 10^{-21} |
685 | * or replace variable name (alpha) |
694 | * or replace variable name (alpha) |
686 | * if int n != 0, use html code, else use tex code |
695 | * if int n != 0, use html code, else use tex code |
687 | */ |
696 | */ |
688 | void __replace_mathvar(char *p,int n) |
697 | void __replace_mathvar(char *p,int n) |
- | 698 | { |
|
689 |
|
699 | char *p1, *p2, *p3; |
690 | char *EXPBEG, *EXPEND, *EXPBEGMINUS, *SUBBEG, *SUBEND, *m_prefix; |
700 | char *EXPBEG, *EXPEND, *EXPBEGMINUS, *SUBBEG, *SUBEND, *m_prefix; |
691 | 701 | ||
692 | if ( n ) { |
702 | if ( n ) { |
693 |
|
703 | EXPBEG = " × 10<sup>"; |
694 |
|
704 | EXPBEGMINUS = " × 10<sup>-"; |
695 |
|
705 | EXPEND = "</sup>"; |
696 |
|
706 | SUBBEG = "<sub>"; |
697 |
|
707 | SUBEND = "</sub>"; |
698 |
|
708 | m_prefix="$m_"; |
699 | } else { |
709 | } else { |
700 |
|
710 | EXPBEG = " \\times 10^{" ; |
701 |
|
711 | EXPBEGMINUS = " \\times 10^{-" ; |
702 |
|
712 | EXPEND = "}"; |
703 |
|
713 | SUBBEG = "_{"; |
704 |
|
714 | SUBEND = "}"; |
705 |
|
715 | m_prefix="\\"; |
706 | } |
716 | } |
707 | for (p1=find_mathvar_start(p);*p1!=0;p1=find_mathvar_start(p2)) { |
717 | for (p1=find_mathvar_start(p);*p1!=0;p1=find_mathvar_start(p2)) { |
708 | char buf[MAX_LINELEN+1]; |
718 | char buf[MAX_LINELEN+1]; |
709 | /* if the variable is preceded by \ do nothing |
719 | /* if the variable is preceded by \ do nothing |
710 | * in fact this should not arrive |
720 | * in fact this should not arrive |
711 | */ |
721 | */ |
712 | if (p1>p && *(p1-1) == '\\' ) break ; |
722 | if (p1>p && *(p1-1) == '\\' ) break ; |
713 | p2 = find_mathvar_end(p1); |
723 | p2 = find_mathvar_end(p1); |
714 |
|
724 | if (p1 == p2) break; |
715 | memmove(buf,p1,p2-p1);buf[p2-p1]=0; |
725 | memmove(buf,p1,p2-p1);buf[p2-p1]=0; |
716 | 726 | ||
717 | if(myisdigit(buf[0])) { |
727 | if(myisdigit(buf[0])) { |
718 | /* number : 3E+021 -> 3 x 10^{21} - 3E-21 -> 3 x 10^{-21} */ |
728 | /* number : 3E+021 -> 3 x 10^{21} - 3E-21 -> 3 x 10^{-21} */ |
719 |
|
729 | int k = 1, minus = 0; |
720 | 730 | ||
721 | /* see putnumber in texmath.c*/ |
731 | /* see putnumber in texmath.c*/ |
722 |
|
732 | if( (p3 = strpbrk(buf, "Ee")) == NULL) continue; |
723 |
|
733 | p1 += p3-buf; |
724 | //count the number of 0, +, - |
734 | //count the number of 0, +, - |
725 |
|
735 | if (*(p1+k) == '-') { minus = 1; k++; } |
726 |
|
736 | while(*(p1+k)=='0' || *(p1+k)=='+') k++; |
727 | 737 | ||
728 |
|
738 | string_modify(p,p1,p1+k, minus? EXPBEGMINUS: EXPBEG); |
729 |
|
739 | p2 += strlen(minus? EXPBEGMINUS: EXPBEG)-k; |
730 |
|
740 | string_modify(p,p2,p2, EXPEND); |
731 |
|
741 | p2 += strlen(EXPEND); |
- | 742 | } |
|
732 |
|
743 | else { |
733 | /* alphabetic name, replace greek letters and symbols in hmname |
744 | /* alphabetic name, replace greek letters and symbols in hmname |
734 | * not done in texmath.c |
745 | * not done in texmath.c |
735 | */ |
746 | */ |
736 |
|
747 | int i = search_list(hmname,hmname_no,sizeof(hmname[0]),buf); |
737 |
|
748 | char *n, *r; |
738 |
|
749 | if(i<0) { /* not in list */ |
739 |
|
750 | int k = strlen(buf)-1; |
740 |
|
751 | if(myisdigit(buf[k])) { |
741 |
|
752 | while(k>0 && myisdigit(buf[k-1])) k--; |
742 |
|
753 | string_modify(buf,buf+k,buf+k,SUBBEG); |
743 |
|
754 | string_modify(p,p1,p2,"%s%s",buf,SUBEND); |
744 |
|
755 | p2+=strlen(SUBBEG)+strlen(SUBEND); |
745 | } |
- | |
746 | continue; |
- | |
747 | } |
- | |
748 | n = hmname[i].name; |
- | |
749 | r = mathalign_base < 2? hmname[i].replace: hmname[i].replacem; |
- | |
750 | if(r[0]==0) { /* replace = "" */ |
- | |
751 | string_modify(p,p1,p2,"%s%s",m_prefix, n); |
- | |
752 | p2 = p1+strlen(n)+strlen(m_prefix); |
- | |
753 | } else { |
- | |
754 | string_modify(p,p1,p2,"%s",r); |
- | |
755 | p2 = p1+strlen(r); |
- | |
756 | } |
- | |
757 | } |
756 | } |
- | 757 | continue; |
|
- | 758 | } |
|
- | 759 | n = hmname[i].name; |
|
- | 760 | r = mathalign_base < 2? hmname[i].replace: hmname[i].replacem; |
|
- | 761 | if(r[0]==0) { /* replace = "" */ |
|
- | 762 | string_modify(p,p1,p2,"%s%s",m_prefix, n); |
|
- | 763 | p2 = p1+strlen(n)+strlen(m_prefix); |
|
- | 764 | } else { |
|
- | 765 | string_modify(p,p1,p2,"%s",r); |
|
- | 766 | p2 = p1+strlen(r); |
|
- | 767 | } |
|
- | 768 | } |
|
758 | } |
769 | } |
759 | } |
770 | } |
760 | 771 | ||
761 | /* translate raw math expression coming from calculators into best html way |
772 | /* translate raw math expression coming from calculators into best html way |
762 | * if int n != 0, use html code, else use tex code |
773 | * if int n != 0, use html code, else use tex code |
763 | */ |
774 | */ |
764 | void __htmlmath(char *p,int n) |
775 | void __htmlmath(char *p,int n) |
765 | { |
776 | { |
766 |
|
777 | if(!rawmath_easy) { rawmath_easy=1; rawmath(p); rawmath_easy=0;} |
767 |
|
778 | __replace_htmlmath_gtlt(p); //only used in deductio |
768 |
|
779 | __replace_exponent(p,n); |
769 |
|
780 | __replace_subscript(p,n); |
770 |
|
781 | __replace_getrid1(p); |
771 |
|
782 | __replace_mathvar(p,n); |
772 |
|
783 | __replace_getridstar(p); |
773 |
|
784 | __replace_arrow(p,n); |
774 | /* Now make substitutions */ |
785 | /* Now make substitutions */ |
775 |
|
786 | substit(p); |
776 | /* Make single names italic - done automatically by mathml */ |
787 | /* Make single names italic - done automatically by mathml */ |
777 | __replace_italics(p,n); |
788 | __replace_italics(p,n); |
778 | strip_trailing_spaces(p); |
789 | strip_trailing_spaces(p); |
779 | } |
790 | } |
780 | 791 | ||
Line 790... | Line 801... | ||
790 | /* |
801 | /* |
791 | if force_mathml variable is set to "yes", do not (never) use 'htmlmath' |
802 | if force_mathml variable is set to "yes", do not (never) use 'htmlmath' |
792 | in output, so command: !mathmlmath some_LaTeX_string will produce mathml |
803 | in output, so command: !mathmlmath some_LaTeX_string will produce mathml |
793 | (mathml \input inputfields may be included) |
804 | (mathml \input inputfields may be included) |
794 | */ |
805 | */ |
795 |
|
806 | if( strcmp( getvar("force_mathml"),"yes") == 0 ){ mathalign_base = 2;mathml(p,1);return; } |
796 |
|
807 | if (mathalign_base == 2) { __htmlmath(p,0) ; mathml(p,1);} else { __htmlmath(p,1) ;} |
797 | } |
808 | } |