Skip to content

Commit 438e68e

Browse files
committed
Some more math stuff
1 parent 7f36ac8 commit 438e68e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+620
-989
lines changed

olmocr/bench/katex/render.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,15 @@ def render_equation(
6969
eq_hash = get_equation_hash(equation, bg_color, text_color, font_size)
7070
cache_dir = get_cache_dir()
7171
cache_file = cache_dir / f"{eq_hash}.png"
72+
cache_error_file = cache_dir / f"{eq_hash}_error"
7273

7374
# Check if the equation is already cached
74-
if use_cache and cache_file.exists():
75-
return Image.open(cache_file)
75+
if use_cache:
76+
if cache_error_file.exists():
77+
return None
78+
79+
if cache_file.exists():
80+
return Image.open(cache_file)
7681

7782
# We need to escape backslashes for JavaScript string
7883
escaped_equation = equation.replace("\\", "\\\\")
@@ -86,9 +91,6 @@ def render_equation(
8691
if not os.path.exists(katex_css_path) or not os.path.exists(katex_js_path):
8792
raise FileNotFoundError(f"KaTeX files not found. Please ensure katex.min.css and katex.min.js are in {script_dir}")
8893

89-
# Temporary file to save the screenshot
90-
temp_path = str(cache_file)
91-
9294
with sync_playwright() as p:
9395
# Launch a headless browser
9496
browser = p.chromium.launch()
@@ -155,9 +157,7 @@ def render_equation(
155157

156158
if has_error:
157159
print(f"Error rendering equation: '{equation}'")
158-
# Clean up any partially created cache file
159-
if os.path.exists(temp_path):
160-
os.remove(temp_path)
160+
cache_error_file.touch()
161161
browser.close()
162162
return None
163163

@@ -168,13 +168,13 @@ def render_equation(
168168
container = page.query_selector("#equation-container")
169169

170170
# Take the screenshot
171-
container.screenshot(path=temp_path)
171+
container.screenshot(path=str(cache_file))
172172

173173
# Close the browser
174174
browser.close()
175175

176176
# Return the image as a Pillow Image
177-
return Image.open(temp_path)
177+
return Image.open(cache_file)
178178

179179
def main():
180180
# Example equation: Einstein's famous equation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
The 20 Most Important Mathematical Equations
2+
3+
A journey through the most elegant and influential formulas in mathematics
4+
5+
1. Euler's Identity
6+
7+
\[ e^{i\pi} + 1 = 0 \]
8+
9+
Connects five fundamental constants \((e, i, \pi, 1, 0)\), revealing the profound relationship between exponential functions and trigonometry.
10+
11+
2. Pythagorean Theorem
12+
13+
\[ a^2 + b^2 = c^2 \]
14+
15+
In right triangles, the hypotenuse squared equals the sum of the squares of the other sides. Cornerstone of geometry with applications in navigation and architecture.
16+
17+
3. The Fundamental Theorem of Calculus
18+
19+
\[ \int_{a}^{b} f(x) \, dx = F(b) - F(a) \]
20+
21+
Establishes that differentiation and integration are inverse operations. If \( F \) is an antiderivative of \( f \), the definite integral equals \( F(b) - F(a) \). Revolutionized mathematical problem-solving.
22+
23+
4. Maxwell's Equations
24+
25+
\[ \nabla \cdot \mathbf{E} = \frac{\rho}{\varepsilon_0} \]
26+
\[ \nabla \cdot \mathbf{B} = 0 \]
27+
\[ \nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t} \]
28+
\[ \nabla \times \mathbf{B} = \mu_0 \mathbf{J} + \mu_0 \varepsilon_0 \frac{\partial \mathbf{E}}{\partial t} \]
29+
30+
Unified electricity and magnetism as manifestations of the same force. Describes electromagnetic field behavior, predicting waves traveling at light speed. Enabled technologies from radio to smartphones.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The 20 Most Important Mathematical Equations
2+
3+
A journey through the most elegant and influential formulas in mathematics
4+
5+
1. Euler's Identity
6+
\[ e^{i\pi} + 1 = 0 \]
7+
Connects five fundamental constants (e, i, π, 1, 0), revealing the profound relationship between exponential functions and trigonometry.
8+
9+
2. Pythagorean Theorem
10+
\[ a^2 + b^2 = c^2 \]
11+
In right triangles, the hypotenuse squared equals the sum of the squares of the other sides. Cornerstone of geometry with applications in navigation and architecture.
12+
13+
3. The Fundamental Theorem of Calculus
14+
\[ \int_{a}^{b} f(x)\,dx = F(b) - F(a) \]
15+
Establishes that differentiation and integration are inverse operations. If F is an antiderivative of f, the definite integral equals F(b) - F(a). Revolutionized mathematical problem-solving.
16+
17+
4. Maxwell's Equations
18+
\[ \nabla \cdot \mathbf{E} = \frac{\rho}{\varepsilon_0} \]
19+
\[ \nabla \cdot \mathbf{B} = 0 \]
20+
\[ \nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t} \]
21+
\[ \nabla \times \mathbf{B} = \mu_0 \mathbf{J} + \mu_0 \varepsilon_0 \frac{\partial \mathbf{E}}{\partial t} \]
22+
Unified electricity and magnetism as manifestations of the same force. Describes electromagnetic field behavior, predicting waves traveling at light speed. Enabled technologies from radio to smartphones.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Made with
2+
The 20 Most Important Mathematical Equations
3+
A journey through the most elegant and influential formulas in mathematics
4+
1. Euler’s Identity
5+
2. Pythagorean Theorem
6+
e
7+
iττ + 1 = 0
8+
a2 + b2 = c2
9+
3. The Fundamental Theorem of Calculus
10+
4. Maxwell’s Equations
11+
Establishes that differentiation and integration are inverse
12+
operations. If F is an antiderivative of f, the definite integral
13+
equals F(b) - F(a). Revolutionized mathematical problem-
14+
solving.
15+
In right triangles, the hypotenuse squared equals the sum of
16+
the squares of the other sides. Cornerstone of geometry with
17+
applications in navigation and architecture.
18+
∇· E = ∂
19+
ε0
20+
∇· B = 0
21+
∇× E = −∂B
22+
∂t
23+
∇× B = µ0J + µ0ε0 ∂E
24+
∂t
25+
Unified electricity and magnetism as manifestations of the
26+
same force. Describes electromagnetic field behavior, predicting
27+
waves traveling at light speed. Enabled technologies from radio
28+
to smartphones.
29+
1. Euler’s Identity
30+
2. Pythagorean Theorem
31+
e
32+
iττ
33+
+ 1 = 0
34+
a2 + b2 = c2
35+
3. The Fundamental THEorem of Calculus
36+
4. Maxwell’s Equations
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## **The 20 Most Important Mathematical Equations**
2+
3+
A journey through the most elegant and influential formulas in mathematics
4+
5+
**1. Euler's Identity** Connects five fundamental constants (e, i, π, 1, 0), revealing the profound relationship between exponential functions and trigonometry. **2. Pythagorean Theorem** In right triangles, the hypotenuse squared equals the sum of the squares of the other sides. Cornerstone of geometry with applications in navigation and architecture. *e* + ** 1 = 0 *a* + <sup>2</sup> *b* = <sup>2</sup> *c* 2
6+
7+
## **3. The Fundamental Theorem of Calculus**
8+
9+
## **4. Maxwell's Equations**
10+
11+
$$\int\_{a}^{b} f(\mathbf{x}) \, d\mathbf{x} = F(b) - F(a)$$
12+
13+
Establishes that differentiation and integration are inverse operations. If F is an antiderivative of f, the definite integral equals F(b) - F(a). Revolutionized mathematical problemsolving.
14+
15+
∇ ⋅ **E** = *ε*0 *ρ* ∇ ⋅ **B** = 0 ∇ × **E** = − ∂*t***B** ∇ × **B** = *μ*0**J** + *μ*0*ε*<sup>0</sup> ∂*t***E**
16+
17+
Unified electricity and magnetism as manifestations of the same force. Describes electromagnetic field behavior, predicting waves traveling at light speed. Enabled technologies from radio to smartphones.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## **The 20 Most Important Mathematical Equations**
2+
3+
A journey through the most elegant and influential formulas in mathematics
4+
5+
**1. Euler's Identity** Connects five fundamental constants (e, i, π, 1, 0), revealing the profound relationship between exponential functions and trigonometry. **2. Pythagorean Theorem** In right triangles, the hypotenuse squared equals the sum of the squares of the other sides. Cornerstone of geometry with applications in navigation and architecture. *e* + ** 1 = 0 *a* + <sup>2</sup> *b* = <sup>2</sup> *c* 2
6+
7+
## **3. The Fundamental Theorem of Calculus**
8+
9+
## **4. Maxwell's Equations**
10+
11+
$$\int\_{a}^{b} f(\mathbf{x}) \, d\mathbf{x} = F(b) - F(a)$$
12+
13+
Establishes that differentiation and integration are inverse operations. If F is an antiderivative of f, the definite integral equals F(b) - F(a). Revolutionized mathematical problemsolving.
14+
15+
∇ ⋅ **E** = *ε*0 *ρ* ∇ ⋅ **B** = 0 ∇ × **E** = − ∂*t***B** ∇ × **B** = *μ*0**J** + *μ*0*ε*<sup>0</sup> ∂*t***E**
16+
17+
Unified electricity and magnetism as manifestations of the same force. Describes electromagnetic field behavior, predicting waves traveling at light speed. Enabled technologies from radio to smartphones.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## **The 20 Most Important Mathematical Equations**
2+
3+
A journey through the most elegant and influential formulas in mathematics
4+
5+
**1. Euler's Identity** Connects five fundamental constants (e, i, π, 1, 0), revealing the profound relationship between exponential functions and trigonometry. **2. Pythagorean Theorem** In right triangles, the hypotenuse squared equals the sum of the squares of the other sides. Cornerstone of geometry with applications in navigation and architecture. *e* + ** 1 = 0 *a* + <sup>2</sup> *b* = <sup>2</sup> *c* 2
6+
7+
## **3. The Fundamental Theorem of Calculus**
8+
9+
## **4. Maxwell's Equations**
10+
11+
$$\int\_{a}^{b} f(\mathbf{x}) \, d\mathbf{x} = F(b) - F(a)$$
12+
13+
Establishes that differentiation and integration are inverse operations. If F is an antiderivative of f, the definite integral equals F(b) - F(a). Revolutionized mathematical problemsolving.
14+
15+
∇ ⋅ **E** = *ε*0 *ρ* ∇ ⋅ **B** = 0 ∇ × **E** = − ∂*t***B** ∇ × **B** = *μ*0**J** + *μ*0*ε*<sup>0</sup> ∂*t***E**
16+
17+
Unified electricity and magnetism as manifestations of the same force. Describes electromagnetic field behavior, predicting waves traveling at light speed. Enabled technologies from radio to smartphones.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## **The 20 Most Important Mathematical Equations**
2+
3+
A journey through the most elegant and influential formulas in mathematics
4+
5+
**1. Euler's Identity** Connects five fundamental constants (e, i, π, 1, 0), revealing the profound relationship between exponential functions and trigonometry. **2. Pythagorean Theorem** In right triangles, the hypotenuse squared equals the sum of the squares of the other sides. Cornerstone of geometry with applications in navigation and architecture. *e* + ** 1 = 0 *a* + <sup>2</sup> *b* = <sup>2</sup> *c* 2
6+
7+
## **3. The Fundamental Theorem of Calculus**
8+
9+
## **4. Maxwell's Equations**
10+
11+
$$\int\_{a}^{b} f(\mathbf{x}) \, d\mathbf{x} = F(b) - F(a)$$
12+
13+
Establishes that differentiation and integration are inverse operations. If F is an antiderivative of f, the definite integral equals F(b) - F(a). Revolutionized mathematical problemsolving.
14+
15+
∇ ⋅ **E** = *ε*0 *ρ* ∇ ⋅ **B** = 0 ∇ × **E** = − ∂*t***B** ∇ × **B** = *μ*0**J** + *μ*0*ε*<sup>0</sup> ∂*t***E**
16+
17+
Unified electricity and magnetism as manifestations of the same force. Describes electromagnetic field behavior, predicting waves traveling at light speed. Enabled technologies from radio to smartphones.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## **The 20 Most Important Mathematical Equations**
2+
3+
A journey through the most elegant and influential formulas in mathematics
4+
5+
**1. Euler's Identity** Connects five fundamental constants (e, i, π, 1, 0), revealing the profound relationship between exponential functions and trigonometry. **2. Pythagorean Theorem** In right triangles, the hypotenuse squared equals the sum of the squares of the other sides. Cornerstone of geometry with applications in navigation and architecture. *e* + ** 1 = 0 *a* + <sup>2</sup> *b* = <sup>2</sup> *c* 2
6+
7+
## **3. The Fundamental Theorem of Calculus**
8+
9+
## **4. Maxwell's Equations**
10+
11+
$$\int\_{a}^{b} f(\mathbf{x}) \, d\mathbf{x} = F(b) - F(a)$$
12+
13+
Establishes that differentiation and integration are inverse operations. If F is an antiderivative of f, the definite integral equals F(b) - F(a). Revolutionized mathematical problemsolving.
14+
15+
∇ ⋅ **E** = *ε*0 *ρ* ∇ ⋅ **B** = 0 ∇ × **E** = − ∂*t***B** ∇ × **B** = *μ*0**J** + *μ*0*ε*<sup>0</sup> ∂*t***E**
16+
17+
Unified electricity and magnetism as manifestations of the same force. Describes electromagnetic field behavior, predicting waves traveling at light speed. Enabled technologies from radio to smartphones.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# The 20 Most Important Mathematical Equations
2+
3+
A journey through the most elegant and influential formulas in mathematics
4+
5+
| 1. Euler's Identity | 2. Pythagorean Theorem |
6+
|--------------------|------------------------|
7+
| \( e^{i\pi} + 1 = 0 \) | \( a^2 + b^2 = c^2 \) |
8+
9+
Connects five fundamental constants (e, i, π, 1, 0), revealing the profound relationship between exponential functions and trigonometry.
10+
11+
In right triangles, the hypotenuse squared equals the sum of the squares of the other sides. Cornerstone of geometry with applications in navigation and architecture.
12+
13+
| 3. The Fundamental Theorem of Calculus | 4. Maxwell's Equations |
14+
|----------------------------------------|------------------------|
15+
| \( \int_{a}^{b} f(x) \, dx = F(b) - F(a) \) | \( \nabla \cdot \mathbf{E} = \frac{Q}{\varepsilon_0} \) |
16+
17+
Establishes that differentiation and integration are inverse operations. If \( F \) is an antiderivative of \( f \), the definite integral equals \( F(b) - F(a) \). Revolutionized mathematical problem-solving.
18+
19+
Unified electricity and magnetism as manifestations of the same force. Describes electromagnetic field behavior, predicting waves traveling at light speed. Enabled technologies from radio to smartphones.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# The 20 Most Important Mathematical Equations
2+
3+
A journey through the most elegant and influential formulas in mathematics
4+
5+
| 1. Euler's Identity | 2. Pythagorean Theorem |
6+
|---------------------|------------------------|
7+
| \( e^{i\pi} + 1 = 0 \) | \( a^2 + b^2 = c^2 \) |
8+
9+
Connects five fundamental constants (e, i, π, 1, 0), revealing the profound relationship between exponential functions and trigonometry.
10+
11+
In right triangles, the hypotenuse squared equals the sum of the squares of the other sides. Cornerstone of geometry with applications in navigation and architecture.
12+
13+
| 3. The Fundamental Theorem of Calculus | 4. Maxwell's Equations |
14+
|----------------------------------------|------------------------|
15+
| \[ \int_{a}^{b} f(x) \, dx = F(b) - F(a) \] | \[ \nabla \cdot \mathbf{E} = \frac{Q}{\varepsilon_0} \] |
16+
17+
Establishes that differentiation and integration are inverse operations. If \( F \) is an antiderivative of \( f \), the definite integral equals \( F(b) - F(a) \). Revolutionized mathematical problem-solving.
18+
19+
Unified electricity and magnetism as manifestations of the same force. Describes electromagnetic field behavior, predicting waves traveling at light speed. Enabled technologies from radio to smartphones.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# The 20 Most Important Mathematical Equations
2+
3+
A journey through the most elegant and influential formulas in mathematics
4+
5+
| 1. Euler's Identity | 2. Pythagorean Theorem |
6+
|--------------------|------------------------|
7+
| \( e^{i\pi} + 1 = 0 \) | \( a^2 + b^2 = c^2 \) |
8+
9+
Connects five fundamental constants (e, i, π, 1, 0), revealing the profound relationship between exponential functions and trigonometry.
10+
11+
In right triangles, the hypotenuse squared equals the sum of the squares of the other sides. Cornerstone of geometry with applications in navigation and architecture.
12+
13+
| 3. The Fundamental Theorem of Calculus | 4. Maxwell's Equations |
14+
|----------------------------------------|------------------------|
15+
| \( \int_{a}^{b} f(x) \, dx = F(b) - F(a) \) | \( \nabla \cdot \mathbf{E} = \frac{Q}{\varepsilon_0} \) |
16+
17+
Establishes that differentiation and integration are inverse operations. If \( F \) is an antiderivative of \( f \), the definite integral equals \( F(b) - F(a) \). Revolutionized mathematical problem-solving.
18+
19+
Unified electricity and magnetism as manifestations of the same force. Describes electromagnetic field behavior, predicting waves traveling at light speed. Enabled technologies from radio to smartphones.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# The 20 Most Important Mathematical Equations
2+
3+
A journey through the most elegant and influential formulas in mathematics
4+
5+
| 1. Euler's Identity | 2. Pythagorean Theorem |
6+
|--------------------|------------------------|
7+
| \( e^{i\pi} + 1 = 0 \) | \( a^2 + b^2 = c^2 \) |
8+
9+
Connects five fundamental constants (e, i, π, 1, 0), revealing the profound relationship between exponential functions and trigonometry.
10+
11+
In right triangles, the hypotenuse squared equals the sum of the squares of the other sides. Cornerstone of geometry with applications in navigation and architecture.
12+
13+
| 3. The Fundamental Theorem of Calculus | 4. Maxwell's Equations |
14+
|----------------------------------------|------------------------|
15+
| \( \int_{a}^{b} f(x) \, dx = F(b) - F(a) \) | \( \nabla \cdot \mathbf{E} = \frac{Q}{\varepsilon_0} \) |
16+
17+
Establishes that differentiation and integration are inverse operations. If F is an antiderivative of f, the definite integral equals F(b) - F(a). Revolutionized mathematical problem-solving.
18+
19+
Unified electricity and magnetism as manifestations of the same force. Describes electromagnetic field behavior, predicting waves traveling at light speed. Enabled technologies from radio to smartphones.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# The 20 Most Important Mathematical Equations
2+
3+
A journey through the most elegant and influential formulas in mathematics
4+
5+
| 1. Euler's Identity | 2. Pythagorean Theorem |
6+
|--------------------|------------------------|
7+
| \( e^{i\pi} + 1 = 0 \) | \( a^2 + b^2 = c^2 \) |
8+
9+
Connects five fundamental constants (e, i, π, 1, 0), revealing the profound relationship between exponential functions and trigonometry.
10+
11+
In right triangles, the hypotenuse squared equals the sum of the squares of the other sides. Cornerstone of geometry with applications in navigation and architecture.
12+
13+
| 3. The Fundamental Theorem of Calculus | 4. Maxwell's Equations |
14+
|----------------------------------------|------------------------|
15+
| \( \int_{a}^{b} f(x) \, dx = F(b) - F(a) \) | \( \nabla \cdot \mathbf{E} = \frac{Q}{\varepsilon_0} \) |
16+
17+
Establishes that differentiation and integration are inverse operations. If \( F \) is an antiderivative of \( f \), the definite integral equals \( F(b) - F(a) \). Revolutionized mathematical problem-solving.
18+
19+
Unified electricity and magnetism as manifestations of the same force. Describes electromagnetic field behavior, predicting waves traveling at light speed. Enabled technologies from radio to smartphones.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# The 20 Most Important Mathematical Equations
2+
3+
A journey through the most elegant and influential formulas in mathematics
4+
5+
---
6+
7+
**1. Euler's Identity**
8+
9+
\[ e^{i\pi} + 1 = 0 \]
10+
11+
Connects five fundamental constants (\(e, i, \pi, 1, 0\)), revealing the profound relationship between exponential functions and trigonometry.
12+
13+
---
14+
15+
**2. Pythagorean Theorem**
16+
17+
\[ a^2 + b^2 = c^2 \]
18+
19+
In right triangles, the hypotenuse squared equals the sum of the squares of the other sides. Cornerstone of geometry with applications in navigation and architecture.
20+
21+
---
22+
23+
**3. The Fundamental Theorem of Calculus**
24+
25+
\[ \int_a^b f(x) \, dx = F(b) - F(a) \]
26+
27+
Establishes that differentiation and integration are inverse operations. If \(F\) is an antiderivative of \(f\), the definite integral equals \(F(b) - F(a)\). Revolutionized mathematical problem-solving.
28+
29+
---
30+
31+
**4. Maxwell's Equations**
32+
33+
\[
34+
\begin{align*}
35+
\nabla \cdot \mathbf{E} &= \frac{Q}{\varepsilon_0} \\
36+
\nabla \cdot \mathbf{B} &= 0 \\
37+
\n\nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t} \\
38+
\n\nabla \times \mathbf{B} &= \mu_0 \mathbf{J} + \mu_0 \varepsilon_0 \frac{\partial \mathbf{E}}{\partial t}
39+
\end{align*}
40+
\]
41+
42+
Unified electricity and magnetism as manifestations of the same force. Describes electromagnetic field behavior, predicting waves traveling at light speed. Enabled technologies from radio to smartphones.

0 commit comments

Comments
 (0)