amelioration latex
This commit is contained in:
@ -243,13 +243,71 @@ async loadHelpRemaining() {
|
||||
}
|
||||
|
||||
ajouterMessage(texte, type) {
|
||||
const msgDiv = document.createElement('div');
|
||||
msgDiv.className = `message message-${type}`;
|
||||
msgDiv.textContent = texte;
|
||||
this.chatMessages.appendChild(msgDiv);
|
||||
this.scrollToBottom();
|
||||
const msgDiv = document.createElement('div');
|
||||
msgDiv.className = `message message-${type}`;
|
||||
|
||||
// Convertir le texte brut en HTML avec support LaTeX
|
||||
const htmlContent = this.formatMathText(texte);
|
||||
msgDiv.innerHTML = htmlContent;
|
||||
|
||||
this.chatMessages.appendChild(msgDiv);
|
||||
|
||||
// Rendre les formules mathématiques avec KaTeX
|
||||
if (typeof renderMathInElement !== 'undefined') {
|
||||
renderMathInElement(msgDiv, {
|
||||
delimiters: [
|
||||
{left: '$$', right: '$$', display: true}, // Mode display (centré)
|
||||
{left: '$', right: '$', display: false}, // Mode inline
|
||||
{left: '\\(', right: '\\)', display: false},
|
||||
{left: '\\[', right: '\\]', display: true}
|
||||
],
|
||||
throwOnError: false,
|
||||
trust: true
|
||||
});
|
||||
}
|
||||
|
||||
this.scrollToBottom();
|
||||
}
|
||||
|
||||
// NOUVELLE MÉTHODE : Formater le texte avec support maths
|
||||
formatMathText(texte) {
|
||||
// Convertir les retours à la ligne en <br>
|
||||
let html = texte.replace(/\n/g, '<br>');
|
||||
|
||||
// Détecter et convertir les fractions communes
|
||||
// 1/2 → $\frac{1}{2}$
|
||||
html = html.replace(/(\d+)\/(\d+)/g, '$\\frac{$1}{$2}$');
|
||||
|
||||
// Convertir les puissances
|
||||
// x^2 → $x^2$
|
||||
html = html.replace(/([a-z0-9]+)\^([0-9]+)/gi, '$$$1^{$2}$$');
|
||||
|
||||
// Convertir les indices
|
||||
// x_1 → $x_1$
|
||||
html = html.replace(/([a-z0-9]+)_([0-9]+)/gi, '$$$1_{$2}$$');
|
||||
|
||||
// Symboles mathématiques courants
|
||||
const symbols = {
|
||||
'×': '\\times',
|
||||
'÷': '\\div',
|
||||
'≤': '\\leq',
|
||||
'≥': '\\geq',
|
||||
'≠': '\\neq',
|
||||
'≈': '\\approx',
|
||||
'∞': '\\infty',
|
||||
'√': '\\sqrt',
|
||||
'π': '\\pi',
|
||||
'∑': '\\sum',
|
||||
'∫': '\\int'
|
||||
};
|
||||
|
||||
for (let [symbol, latex] of Object.entries(symbols)) {
|
||||
html = html.replace(new RegExp(symbol, 'g'), '$' + latex + '$');
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
afficherTypingIndicator() {
|
||||
const typingDiv = document.createElement('div');
|
||||
typingDiv.className = 'typing-indicator';
|
||||
|
||||
Reference in New Issue
Block a user