Rev 5544 | Rev 7415 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5544 | Rev 5551 | ||
---|---|---|---|
Line 397... | Line 397... | ||
397 | string_modify(p,pp,pp+1,">"); |
397 | string_modify(p,pp,pp+1,">"); |
398 | } |
398 | } |
399 | } |
399 | } |
400 | 400 | ||
401 | /* exponents or indices : |
401 | /* exponents or indices : |
402 | |
402 | * all digits or + or - following a ^ or _ are considered as in exponent/subscript |
403 | |
403 | * expression with ( ) following a ^ or _ are considered as in exponent/subscript |
404 | |
404 | * the parenthesis are suppressed except in case of exponent and only digits. |
405 | |
- | |
406 | */ |
- | |
- | 405 | * if int n != 0, use html code, else use tex code */ |
|
407 | void __replace_exponent(char *p) |
406 | void __replace_exponent(char *p, int n) |
408 | { |
407 | { |
409 | char *p1; |
408 | char *p1; |
410 | char *SUPBEG, *SUPEND; |
409 | char *SUPBEG, *SUPEND; |
411 | if ( |
410 | if (n) { SUPBEG = "<sup>"; SUPEND = "</sup>";} |
412 | else { SUPBEG = "^{"; SUPEND = "}";} |
411 | else { SUPBEG = "^{"; SUPEND = "}";} |
413 | 412 | ||
414 | for(p1=strchr(p,'^');p1!=NULL;p1=strchr(p1+1,'^')) { |
413 | for(p1=strchr(p,'^');p1!=NULL;p1=strchr(p1+1,'^')) { |
415 | char *p2, *p3, *pp; |
414 | char *p2, *p3, *pp; |
416 | char c; |
415 | char c; |
Line 457... | Line 456... | ||
457 | /* replace ^<exponent group>. Add back missing character 'c' */ |
456 | /* replace ^<exponent group>. Add back missing character 'c' */ |
458 | string_modify(p,p1,p2, "%s%s%s%c",SUPBEG,p3,SUPEND,c); |
457 | string_modify(p,p1,p2, "%s%s%s%c",SUPBEG,p3,SUPEND,c); |
459 | } |
458 | } |
460 | } |
459 | } |
461 | 460 | ||
- | 461 | /* if int n != 0, use html code, else use tex code */ |
|
462 | void __replace_subscript(char *p) |
462 | void __replace_subscript(char *p, int n) |
463 | { |
463 | { |
464 | char *p1, *p2; |
464 | char *p1, *p2; |
465 | char *SUBBEG, *SUBEND; |
465 | char *SUBBEG, *SUBEND; |
466 | if ( |
466 | if (n) {SUBBEG = "<sub>"; SUBEND = "</sub>";} |
467 | else {SUBBEG = "_{"; SUBEND = "}";} |
467 | else {SUBBEG = "_{"; SUBEND = "}";} |
468 | for(p1=strchr(p,'_');p1!=NULL;p1=strchr(p1+1,'_')) { |
468 | for(p1=strchr(p,'_');p1!=NULL;p1=strchr(p1+1,'_')) { |
469 | char buff[256]; |
469 | char buff[256]; |
470 | p2=p1+1; |
470 | p2=p1+1; |
471 | if(*p2=='(') p2=find_matching(p2+1,')'); |
471 | if(*p2=='(') p2=find_matching(p2+1,')'); |
Line 521... | Line 521... | ||
521 | ovlstrcpy(p1,p1+1);p1--; |
521 | ovlstrcpy(p1,p1+1);p1--; |
522 | } |
522 | } |
523 | } |
523 | } |
524 | } |
524 | } |
525 | 525 | ||
526 |
|
526 | /* <=, >=, ->, =>, <=> |
- | 527 | * if int n != 0, use html code, else use tex code */ |
|
- | 528 | ||
527 | void __replace_arrow ( char *p) |
529 | void __replace_arrow ( char *p, int n) |
528 | { char *p1, *p2, *m_prefix; |
530 | { char *p1, *p2, *m_prefix; |
529 | if ( |
531 | if (n) m_prefix="$m_"; else m_prefix="\\"; |
530 | 532 | ||
531 | for(p1=strstr(p,"<="); p1!=NULL; p1=strstr(p1+1,"<=")) { |
533 | for(p1=strstr(p,"<="); p1!=NULL; p1=strstr(p1+1,"<=")) { |
532 | if(*(p1+5)!='&' && *(p1+5)!='=') |
534 | if(*(p1+5)!='&' && *(p1+5)!='=') |
533 | string_modify(p,p1,p1+5, "%sle",m_prefix); |
535 | string_modify(p,p1,p1+5, "%sle",m_prefix); |
534 | else { |
536 | else { |
Line 563... | Line 565... | ||
563 | } |
565 | } |
564 | 566 | ||
565 | /* why <tt> is used sometimes ? replace single characters by italics one |
567 | /* why <tt> is used sometimes ? replace single characters by italics one |
566 | * is it useful in mathml ? |
568 | * is it useful in mathml ? |
567 | */ |
569 | */ |
568 | void __replace_italics (char *p) |
570 | void __replace_italics (char *p, int n) |
569 | { char *p1, *p2, *p3, pbuf[16]; |
571 | { char *p1, *p2, *p3, pbuf[16]; |
570 | char *ITBEG, *ITEND, *ITtBEG, *ITtEND; |
572 | char *ITBEG, *ITEND, *ITtBEG, *ITtEND; |
571 | if ( |
573 | if (n) { |
572 | ITBEG = "<i>";ITtBEG = "<i><tt>"; |
574 | ITBEG = "<i>";ITtBEG = "<i><tt>"; |
573 | ITEND = "</i>";ITtEND = "</tt></i>"; |
575 | ITEND = "</i>";ITtEND = "</tt></i>"; |
574 | } else {; |
576 | } else {; |
575 | ITBEG = "" ; ITtBEG = ""; |
577 | ITBEG = "" ; ITtBEG = ""; |
576 | ITEND = ""; ITtEND = ""; |
578 | ITEND = ""; ITtEND = ""; |
Line 603... | Line 605... | ||
603 | string_modify(p,p1,p2,"%s%s%s",ITBEG,pbuf,ITEND); |
605 | string_modify(p,p1,p2,"%s%s%s",ITBEG,pbuf,ITEND); |
604 | p1=p2+strlen(ITBEG)+strlen(ITEND)-1; |
606 | p1=p2+strlen(ITBEG)+strlen(ITEND)-1; |
605 | } |
607 | } |
606 | } |
608 | } |
607 | 609 | ||
608 | /* float (1.2 E-03) : 3E+021 -> 3 × 10^{21} - 3E-21 -> 3 × 10^{-21} |
610 | /* float (1.2 E-03) : 3E+021 -> 3 × 10^{21} - 3E-21 -> 3 × 10^{-21} |
609 | * or replace variable name (alpha) |
611 | * or replace variable name (alpha) |
- | 612 | * if int n != 0, use html code, else use tex code */ |
|
610 | void __replace_mathvar(char *p) |
613 | void __replace_mathvar(char *p,int n) |
611 | { char *p1, *p2, *p3; |
614 | { char *p1, *p2, *p3; |
612 | char *EXPBEG, *EXPEND, *EXPBEGMINUS, *SUBBEG, *SUBEND, *m_prefix; |
615 | char *EXPBEG, *EXPEND, *EXPBEGMINUS, *SUBBEG, *SUBEND, *m_prefix; |
613 | 616 | ||
614 | if ( |
617 | if ( n ) { |
615 | EXPBEG = " × 10<sup>"; |
618 | EXPBEG = " × 10<sup>"; |
616 | EXPBEGMINUS = " × 10<sup>-"; |
619 | EXPBEGMINUS = " × 10<sup>-"; |
617 | EXPEND = "</sup>"; |
620 | EXPEND = "</sup>"; |
618 | SUBBEG = "<sub>"; |
621 | SUBBEG = "<sub>"; |
619 | SUBEND = "</sub>"; |
622 | SUBEND = "</sub>"; |
Line 623... | Line 626... | ||
623 | EXPBEGMINUS = " \\times 10^{-" ; |
626 | EXPBEGMINUS = " \\times 10^{-" ; |
624 | EXPEND = "}"; |
627 | EXPEND = "}"; |
625 | SUBBEG = "_{"; |
628 | SUBBEG = "_{"; |
626 | SUBEND = "}"; |
629 | SUBEND = "}"; |
627 | m_prefix="\\"; |
630 | m_prefix="\\"; |
628 | } |
631 | } |
629 | for (p1=find_mathvar_start(p);*p1!=0;p1=find_mathvar_start(p2)) { |
632 | for (p1=find_mathvar_start(p);*p1!=0;p1=find_mathvar_start(p2)) { |
630 | char buf[MAX_LINELEN+1]; |
633 | char buf[MAX_LINELEN+1]; |
631 | /* if the variable is preceded by \ do nothing - in fact this should not arrive |
634 | /* if the variable is preceded by \ do nothing - in fact this should not arrive |
632 | */ |
635 | */ |
633 | if (p1>p && *(p1-1) == '\\' ) break ; |
636 | if (p1>p && *(p1-1) == '\\' ) break ; |
Line 676... | Line 679... | ||
676 | } |
679 | } |
677 | } |
680 | } |
678 | } |
681 | } |
679 | } |
682 | } |
680 | 683 | ||
681 | /* translate raw math expression coming from calculators into best html way |
684 | /* translate raw math expression coming from calculators into best html way |
- | 685 | * if int n != 0, use html code, else use tex code */ |
|
682 | void __htmlmath(char *p) |
686 | void __htmlmath(char *p,int n) |
683 | { |
687 | { |
684 | if(!rawmath_easy) { rawmath_easy=1; rawmath(p); rawmath_easy=0;} |
688 | if(!rawmath_easy) { rawmath_easy=1; rawmath(p); rawmath_easy=0;} |
685 | __replace_htmlmath_gtlt(p); //only used in deductio |
689 | __replace_htmlmath_gtlt(p); //only used in deductio |
686 | __replace_exponent(p); |
690 | __replace_exponent(p,n); |
687 | __replace_subscript(p); |
691 | __replace_subscript(p,n); |
688 | __replace_getrid1(p); |
692 | __replace_getrid1(p); |
689 | __replace_mathvar(p); |
693 | __replace_mathvar(p,n); |
690 | __replace_getridstar(p); |
694 | __replace_getridstar(p); |
691 | __replace_arrow(p); |
695 | __replace_arrow(p,n); |
692 | /* Now make substitutions */ |
696 | /* Now make substitutions */ |
693 | substit(p); |
697 | substit(p); |
694 | /* Make single names italic - done automatically by mathml */ |
698 | /* Make single names italic - done automatically by mathml */ |
695 | __replace_italics(p); |
699 | __replace_italics(p,n); |
696 | strip_trailing_spaces(p); |
700 | strip_trailing_spaces(p); |
697 | } |
701 | } |
698 | 702 | ||
699 | void htmlmath(char *p) |
703 | void htmlmath(char *p) |
700 | { |
704 | { |
701 | __htmlmath(p) ; |
705 | __htmlmath(p,1) ; |
702 | } |
706 | } |
703 | 707 | ||
704 | /* if mathml is closed, it will be just htmlmath*/ |
708 | /* if mathml is closed, it will be just htmlmath*/ |
705 | 709 | ||
706 | void mathmlmath(char *p) |
710 | void mathmlmath(char *p) |
707 | { |
711 | { |
708 |
|
712 | if (mathalign_base == 2) { __htmlmath(p,0) ; mathml(p,1);} else { __htmlmath(p,1) ;} |
709 | } |
713 | } |