Update templates/math.html
Browse files- templates/math.html +76 -34
templates/math.html
CHANGED
@@ -11,33 +11,6 @@
|
|
11 |
<!-- Marked.js pour le Markdown -->
|
12 |
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/marked/9.1.6/marked.min.js"></script>
|
13 |
|
14 |
-
<!-- MathJax -->
|
15 |
-
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
|
16 |
-
<script>
|
17 |
-
window.MathJax = {
|
18 |
-
tex: {
|
19 |
-
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
20 |
-
displayMath: [['$$', '$$'], ['\\[', '\\]']],
|
21 |
-
processEscapes: true,
|
22 |
-
macros: {
|
23 |
-
R: "{\\mathbb{R}}",
|
24 |
-
N: "{\\mathbb{N}}",
|
25 |
-
Z: "{\\mathbb{Z}}",
|
26 |
-
vecv: ["\\begin{pmatrix}#1\\\\#2\\\\#3\\end{pmatrix}", 3] // Macro pour vecteur vertical
|
27 |
-
}
|
28 |
-
},
|
29 |
-
svg: {
|
30 |
-
fontCache: 'global'
|
31 |
-
},
|
32 |
-
options: {
|
33 |
-
renderActions: {
|
34 |
-
addMenu: []
|
35 |
-
}
|
36 |
-
}
|
37 |
-
};
|
38 |
-
|
39 |
-
</script>
|
40 |
-
|
41 |
<!-- Font Awesome pour les icônes -->
|
42 |
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
43 |
|
@@ -76,7 +49,64 @@
|
|
76 |
font-size: 0.9em;
|
77 |
}
|
78 |
}
|
|
|
|
|
|
|
|
|
79 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
</head>
|
81 |
|
82 |
<body class="min-h-screen bg-gradient-to-br from-blue-50 to-white">
|
@@ -121,7 +151,7 @@
|
|
121 |
<div id="response" class="hidden">
|
122 |
<div class="bg-white rounded-lg shadow-lg p-6 mb-8">
|
123 |
<h2 class="text-2xl font-semibold text-blue-800 mb-4">Solution</h2>
|
124 |
-
<div id="latexContent" class="prose max-w-none math-content">
|
125 |
<!-- Le contenu sera inséré ici -->
|
126 |
</div>
|
127 |
</div>
|
@@ -147,6 +177,12 @@
|
|
147 |
const errorText = document.getElementById('errorText');
|
148 |
const submitButton = uploadForm.querySelector('button[type="submit"]');
|
149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
// Configuration de marked
|
151 |
marked.setOptions({
|
152 |
breaks: true,
|
@@ -167,20 +203,25 @@
|
|
167 |
// Fonction pour rendre le contenu mathématique
|
168 |
async function renderMathContent(text) {
|
169 |
try {
|
|
|
|
|
|
|
|
|
|
|
170 |
// Nettoyer le contenu précédent
|
171 |
latexContent.innerHTML = '';
|
|
|
172 |
|
173 |
// Convertir le Markdown en HTML
|
174 |
const htmlContent = marked.parse(text);
|
175 |
latexContent.innerHTML = htmlContent;
|
176 |
|
177 |
// Rendre les formules mathématiques avec MathJax
|
178 |
-
MathJax.typesetPromise([latexContent])
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
});
|
184 |
|
185 |
} catch (error) {
|
186 |
console.error('Erreur lors du rendu:', error);
|
@@ -190,6 +231,7 @@
|
|
190 |
<div class="text-red-600 mb-4">Une erreur s'est produite lors du rendu. Voici le texte brut :</div>
|
191 |
<pre class="bg-gray-100 p-4 rounded-lg overflow-x-auto">${text}</pre>
|
192 |
`;
|
|
|
193 |
}
|
194 |
}
|
195 |
|
|
|
11 |
<!-- Marked.js pour le Markdown -->
|
12 |
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/marked/9.1.6/marked.min.js"></script>
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
<!-- Font Awesome pour les icônes -->
|
15 |
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
16 |
|
|
|
49 |
font-size: 0.9em;
|
50 |
}
|
51 |
}
|
52 |
+
/* Style pour masquer le contenu pendant le chargement de MathJax */
|
53 |
+
.math-hidden {
|
54 |
+
visibility: hidden;
|
55 |
+
}
|
56 |
</style>
|
57 |
+
|
58 |
+
<!-- Configuration de MathJax -->
|
59 |
+
<script>
|
60 |
+
window.MathJax = {
|
61 |
+
tex: {
|
62 |
+
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
63 |
+
displayMath: [['$$', '$$'], ['\\[', '\\]']],
|
64 |
+
processEscapes: true,
|
65 |
+
macros: {
|
66 |
+
R: "{\\mathbb{R}}",
|
67 |
+
N: "{\\mathbb{N}}",
|
68 |
+
Z: "{\\mathbb{Z}}",
|
69 |
+
vecv: ["\\begin{pmatrix}#1\\\\#2\\\\#3\\end{pmatrix}", 3]
|
70 |
+
}
|
71 |
+
},
|
72 |
+
svg: {
|
73 |
+
fontCache: 'global'
|
74 |
+
},
|
75 |
+
startup: {
|
76 |
+
pageReady: () => {
|
77 |
+
return Promise.resolve();
|
78 |
+
}
|
79 |
+
},
|
80 |
+
options: {
|
81 |
+
renderActions: {
|
82 |
+
addMenu: [],
|
83 |
+
checkLoading: [150, () => {
|
84 |
+
document.querySelectorAll('.math-content').forEach(el => {
|
85 |
+
el.classList.remove('math-hidden');
|
86 |
+
});
|
87 |
+
}]
|
88 |
+
}
|
89 |
+
}
|
90 |
+
};
|
91 |
+
</script>
|
92 |
+
|
93 |
+
<!-- Chargement de MathJax -->
|
94 |
+
<script>
|
95 |
+
function loadMathJax() {
|
96 |
+
return new Promise((resolve, reject) => {
|
97 |
+
const script = document.createElement('script');
|
98 |
+
script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
|
99 |
+
script.async = true;
|
100 |
+
script.id = 'MathJax-script';
|
101 |
+
script.onload = resolve;
|
102 |
+
script.onerror = reject;
|
103 |
+
document.head.appendChild(script);
|
104 |
+
});
|
105 |
+
}
|
106 |
+
|
107 |
+
// Charger MathJax immédiatement
|
108 |
+
loadMathJax().catch(console.error);
|
109 |
+
</script>
|
110 |
</head>
|
111 |
|
112 |
<body class="min-h-screen bg-gradient-to-br from-blue-50 to-white">
|
|
|
151 |
<div id="response" class="hidden">
|
152 |
<div class="bg-white rounded-lg shadow-lg p-6 mb-8">
|
153 |
<h2 class="text-2xl font-semibold text-blue-800 mb-4">Solution</h2>
|
154 |
+
<div id="latexContent" class="prose max-w-none math-content math-hidden">
|
155 |
<!-- Le contenu sera inséré ici -->
|
156 |
</div>
|
157 |
</div>
|
|
|
177 |
const errorText = document.getElementById('errorText');
|
178 |
const submitButton = uploadForm.querySelector('button[type="submit"]');
|
179 |
|
180 |
+
// Attendre que MathJax soit complètement chargé
|
181 |
+
let mathJaxReady = false;
|
182 |
+
window.MathJax.startup.promise.then(() => {
|
183 |
+
mathJaxReady = true;
|
184 |
+
});
|
185 |
+
|
186 |
// Configuration de marked
|
187 |
marked.setOptions({
|
188 |
breaks: true,
|
|
|
203 |
// Fonction pour rendre le contenu mathématique
|
204 |
async function renderMathContent(text) {
|
205 |
try {
|
206 |
+
// Attendre que MathJax soit prêt
|
207 |
+
if (!mathJaxReady) {
|
208 |
+
await window.MathJax.startup.promise;
|
209 |
+
}
|
210 |
+
|
211 |
// Nettoyer le contenu précédent
|
212 |
latexContent.innerHTML = '';
|
213 |
+
latexContent.classList.add('math-hidden');
|
214 |
|
215 |
// Convertir le Markdown en HTML
|
216 |
const htmlContent = marked.parse(text);
|
217 |
latexContent.innerHTML = htmlContent;
|
218 |
|
219 |
// Rendre les formules mathématiques avec MathJax
|
220 |
+
await MathJax.typesetPromise([latexContent]);
|
221 |
+
|
222 |
+
// Afficher le contenu
|
223 |
+
response.classList.remove('hidden');
|
224 |
+
latexContent.classList.remove('math-hidden');
|
|
|
225 |
|
226 |
} catch (error) {
|
227 |
console.error('Erreur lors du rendu:', error);
|
|
|
231 |
<div class="text-red-600 mb-4">Une erreur s'est produite lors du rendu. Voici le texte brut :</div>
|
232 |
<pre class="bg-gray-100 p-4 rounded-lg overflow-x-auto">${text}</pre>
|
233 |
`;
|
234 |
+
latexContent.classList.remove('math-hidden');
|
235 |
}
|
236 |
}
|
237 |
|