File size: 2,589 Bytes
ceea2c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!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>