evo-frontend / web /src /test-math.html
fraudTech's picture
Change to use MathJax
ceea2c9
Raw History Blame Contribute Delete
2.59 kB
<!DOCTYPE html>
<html>
<head>
<title>Math Rendering Test</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.27/dist/katex.min.css">
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.27/dist/katex.min.js"></script>
<style>
body {
font-family: monospace;
background: #1a1614;
color: #d4c5b9;
padding: 2rem;
}
.test-case {
border: 1px solid #3a342e;
margin: 1rem 0;
padding: 1rem;
background: #211d1a;
}
.test-label {
color: #8b7355;
font-size: 0.8rem;
margin-bottom: 0.5rem;
}
.katex { color: #e8d4c0; }
.error { color: #d49999; }
</style>
</head>
<body>
<h2>LaTeX Rendering Test Cases</h2>
<div class="test-case">
<div class="test-label">Test 1: Inline Math ($...$)</div>
<div id="test1"></div>
</div>
<div class="test-case">
<div class="test-label">Test 2: Display Math ($$...$$)</div>
<div id="test2"></div>
</div>
<div class="test-case">
<div class="test-label">Test 3: Fractions in Display Mode</div>
<div id="test3"></div>
</div>
<div class="test-case">
<div class="test-label">Test 4: Matrix</div>
<div id="test4"></div>
</div>
<div class="test-case">
<div class="test-label">Test 5: Currency (should NOT render as math)</div>
<div id="test5"></div>
</div>
<script>
const tests = [
{ id: 'test1', tex: 'x^2 + y^2 = r^2', display: false },
{ id: 'test2', tex: 'E = mc^2', display: true },
{ id: 'test3', tex: '\\frac{d}{dx}\\left( \\frac{x^2}{1+x} \\right) = \\frac{2x(1+x) - x^2}{(1+x)^2}', display: true },
{ id: 'test4', tex: '\\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix}', display: true },
{ id: 'test5', tex: 'The price is $123.45 and the budget is $1,000', display: false },
];
tests.forEach(test => {
const el = document.getElementById(test.id);
try {
// Preprocess currency protection
let processed = test.tex.replace(/(?<!\\)\$(\d+(?:\.\d{2})?)/g, '\\$$1');
if (test.id === 'test5') {
// For currency test, show raw text
el.innerHTML = `<span style="color: #7d9d7a;">${processed}</span>`;
} else {
katex.render(processed, el, {
throwOnError: false,
strict: false,
displayMode: test.display,
errorColor: '#d49999'
});
}
} catch (e) {
el.innerHTML = `<span class="error">Error: ${e.message}</span>`;
}
});
</script>
</body>
</html>