1 | <?php |
---|
2 | |
---|
3 | function jsMath_accents ($texte) { |
---|
4 | $acc_tex = array(); $acc_html = array(); |
---|
5 | |
---|
6 | $acc_tex[] = '\`a'; $acc_html[] = 'à'; |
---|
7 | $acc_tex[] = '\`e'; $acc_html[] = 'è'; |
---|
8 | $acc_tex[] = '\`i'; $acc_html[] = 'ì'; |
---|
9 | $acc_tex[] = '\`o'; $acc_html[] = 'ò'; |
---|
10 | $acc_tex[] = '\`u'; $acc_html[] = 'ù'; |
---|
11 | $acc_tex[] = '\`y'; $acc_html[] = '&ygrave;'; |
---|
12 | |
---|
13 | $acc_tex[] = '\\\'a'; $acc_html[] = 'á'; |
---|
14 | $acc_tex[] = '\\\'e'; $acc_html[] = 'é'; |
---|
15 | $acc_tex[] = '\\\'i'; $acc_html[] = 'í'; |
---|
16 | $acc_tex[] = '\\\'o'; $acc_html[] = 'ó'; |
---|
17 | $acc_tex[] = '\\\'u'; $acc_html[] = 'ú'; |
---|
18 | $acc_tex[] = '\\\'y'; $acc_html[] = 'ý'; |
---|
19 | |
---|
20 | $acc_tex[] = '\^a'; $acc_html[] = 'â'; |
---|
21 | $acc_tex[] = '\^e'; $acc_html[] = 'ê'; |
---|
22 | $acc_tex[] = '\^i'; $acc_html[] = 'î'; |
---|
23 | $acc_tex[] = '\^o'; $acc_html[] = 'ô'; |
---|
24 | $acc_tex[] = '\^u'; $acc_html[] = 'û'; |
---|
25 | $acc_tex[] = '\^y'; $acc_html[] = 'ŷ'; |
---|
26 | |
---|
27 | $acc_tex[] = '\"a'; $acc_html[] = 'ä'; |
---|
28 | $acc_tex[] = '\"e'; $acc_html[] = 'ë'; |
---|
29 | $acc_tex[] = '\"i'; $acc_html[] = 'ï'; |
---|
30 | $acc_tex[] = '\"o'; $acc_html[] = 'ö'; |
---|
31 | $acc_tex[] = '\"u'; $acc_html[] = 'ü'; |
---|
32 | $acc_tex[] = '\"y'; $acc_html[] = 'ÿ'; |
---|
33 | |
---|
34 | $acc_tex[] = '\`A'; $acc_html[] = 'À'; |
---|
35 | $acc_tex[] = '\`E'; $acc_html[] = 'È'; |
---|
36 | $acc_tex[] = '\`I'; $acc_html[] = 'Ì'; |
---|
37 | $acc_tex[] = '\`O'; $acc_html[] = 'Ò'; |
---|
38 | $acc_tex[] = '\`U'; $acc_html[] = 'Ù'; |
---|
39 | $acc_tex[] = '\`Y'; $acc_html[] = '&Ygrave;'; |
---|
40 | |
---|
41 | $acc_tex[] = '\\\'A'; $acc_html[] = 'Á'; |
---|
42 | $acc_tex[] = '\\\'E'; $acc_html[] = 'É'; |
---|
43 | $acc_tex[] = '\\\'I'; $acc_html[] = 'Í'; |
---|
44 | $acc_tex[] = '\\\'O'; $acc_html[] = 'Ó'; |
---|
45 | $acc_tex[] = '\\\'U'; $acc_html[] = 'Ú'; |
---|
46 | $acc_tex[] = '\\\'Y'; $acc_html[] = 'Ý'; |
---|
47 | |
---|
48 | $acc_tex[] = '\^A'; $acc_html[] = 'Â'; |
---|
49 | $acc_tex[] = '\^E'; $acc_html[] = 'Ê'; |
---|
50 | $acc_tex[] = '\^I'; $acc_html[] = 'Î'; |
---|
51 | $acc_tex[] = '\^O'; $acc_html[] = 'Ô'; |
---|
52 | $acc_tex[] = '\^U'; $acc_html[] = 'Û'; |
---|
53 | $acc_tex[] = '\^Y'; $acc_html[] = 'Ŷ'; |
---|
54 | |
---|
55 | $acc_tex[] = '\"A'; $acc_html[] = 'Ä'; |
---|
56 | $acc_tex[] = '\"E'; $acc_html[] = 'Ë'; |
---|
57 | $acc_tex[] = '\"I'; $acc_html[] = 'Ï'; |
---|
58 | $acc_tex[] = '\"O'; $acc_html[] = 'Ö'; |
---|
59 | $acc_tex[] = '\"U'; $acc_html[] = 'Ü'; |
---|
60 | $acc_tex[] = '\"Y'; $acc_html[] = 'Ÿ'; |
---|
61 | |
---|
62 | $acc_tex[] = '\`{\i}'; $acc_html[] = 'ì'; |
---|
63 | $acc_tex[] = '\\\'{\i}'; $acc_html[] = 'í'; |
---|
64 | $acc_tex[] = '\^{\i}'; $acc_html[] = 'î'; |
---|
65 | $acc_tex[] = '\"{\i}'; $acc_html[] = 'ï'; |
---|
66 | |
---|
67 | return str_replace ($acc_tex, $acc_html, $texte); |
---|
68 | } |
---|
69 | |
---|
70 | function jsMath_typo ($texte) { |
---|
71 | $texte = preg_replace ('/\\\head\{([^{}]+)\}/s', '{{{\1}}}', $texte); |
---|
72 | $texte = preg_replace ('/\\\textbf\{([^{}]+)\}/s', '{{\1}}', $texte); |
---|
73 | $texte = preg_replace ('/\\\section\{([^{}]+)\}/s', '{{{\1}}}', $texte); |
---|
74 | |
---|
75 | $texte = str_replace ('\ldots', '...', $texte); |
---|
76 | $texte = str_replace ('\medskip', '', $texte); |
---|
77 | $texte = str_replace ('\newblock', '', $texte); |
---|
78 | $texte = str_replace ('\noindent', '', $texte); |
---|
79 | $texte = str_replace ('\emph', '', $texte); |
---|
80 | $texte = str_replace ('\em', '', $texte); |
---|
81 | $texte = str_replace ('\it', '', $texte); |
---|
82 | |
---|
83 | return $texte; |
---|
84 | } |
---|
85 | |
---|
86 | function jsMath_protect_TeX ($texte) { |
---|
87 | $texte = echappe_html ($texte); // To make example code easier. |
---|
88 | |
---|
89 | $texte = str_replace ('\[', '$$', $texte); |
---|
90 | $texte = str_replace ('\]', '$$', $texte); |
---|
91 | $texte = str_replace ('\(', '$', $texte); |
---|
92 | $texte = str_replace ('\)', '$', $texte); |
---|
93 | |
---|
94 | $texte = preg_replace ('/\$\$([^$]+)\$\$/s', '<html>\[\1\]</html>', $texte); |
---|
95 | $texte = preg_replace ('/\$([^$]+)\$/s', '<html>$\1$</html>', $texte); |
---|
96 | $texte = str_replace ('\[', '$$', $texte); |
---|
97 | $texte = str_replace ('\]', '$$', $texte); |
---|
98 | |
---|
99 | while (preg_match ('/<html>[$]+[^$]+</s', $texte)) { |
---|
100 | $texte = preg_replace ('/(<html>[$]+[^$]+)</s', '\1<', $texte); |
---|
101 | } |
---|
102 | |
---|
103 | $texte = str_replace ('<html>$$', '<html><div class="math">', $texte); |
---|
104 | $texte = str_replace ('$$</html>', '</div></html>', $texte); |
---|
105 | $texte = str_replace ('<html>$', '<html><span class="math">', $texte); |
---|
106 | $texte = str_replace ('$</html>', '</span></html>', $texte); |
---|
107 | |
---|
108 | return echappe_html ($texte); |
---|
109 | } |
---|
110 | |
---|
111 | function jsMath_pre_typo ($texte) { |
---|
112 | $texte = jsMath_protect_TeX ($texte); |
---|
113 | $texte = jsMath_accents ($texte); |
---|
114 | $texte = jsMath_typo ($texte); |
---|
115 | |
---|
116 | return $texte; |
---|
117 | } |
---|
118 | |
---|
119 | function jsMath_insert_head ($texte) { |
---|
120 | $texte .= '<script type="text/javascript" src="' . generer_url_public('jsMath_easy_load.js') . '"></script>' . "\n"; |
---|
121 | return $texte; |
---|
122 | } |
---|
123 | |
---|
124 | function jsMath_header_prive ($texte) { |
---|
125 | return jsMath_insert_head ($texte); |
---|
126 | } |
---|
127 | |
---|
128 | function jsMath_affiche_milieu ($texte) { |
---|
129 | return jsMath_pre_typo ($texte); |
---|
130 | } |
---|
131 | |
---|
132 | ?> |
---|