Skip to content

Commit 4f4e8e2

Browse files
committed
chore: remove redundant comments, update README with run instructions, and add new demo images.
1 parent 8164353 commit 4f4e8e2

6 files changed

Lines changed: 19 additions & 32 deletions

File tree

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# num2math
2-
Generate a complicated math expression that results in a number. If you wanna do this for some reason.
2+
3+
A simple web app that generates a complicated math expression that results in a number. If you wanna do this for some reason.
34

45
Try it: https://enjeck.com/num2math/
56

67
![](demo.gif)
8+
9+
## Run the app
10+
To run the app locally:
11+
12+
```bash
13+
git clone https://github.com/enjeck/num2math.git
14+
cd num2math
15+
npm install
16+
npm run dev
17+
```

demo.gif

3.03 MB
Loading

num2math1.png

239 KB
Loading

num2math2.png

273 KB
Loading

src/download-png.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,16 @@ document.addEventListener('DOMContentLoaded', function () {
3636

3737
const number = document.getElementById('input').value;
3838

39-
// Increase SVG dimensions for better quality
4039
const w = parseInt(svg.getAttribute('width')) * 3;
4140
const h = parseInt(svg.getAttribute('height')) * 3;
4241

43-
// Clone the SVG to avoid modifying the displayed version
4442
const clonedSvg = svg.cloneNode(true);
4543
clonedSvg.setAttribute('width', `${w}ex`);
4644
clonedSvg.setAttribute('height', `${h}ex`);
4745

48-
// Convert SVG to string data
4946
const data = new XMLSerializer().serializeToString(clonedSvg);
5047

5148
const canvas = document.createElement('canvas');
52-
53-
// Render SVG to canvas and convert to PNG
5449
canvg(canvas, data, {
5550
renderCallback: function () {
5651
canvas.toBlob(function (blob) {

src/script.js

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,32 @@ document.addEventListener('DOMContentLoaded', function () {
1515
const downloadBtn = document.getElementById('download-img');
1616
const shareBtn = document.getElementById('share-btn');
1717

18-
// Event listeners
1918
form.addEventListener('submit', handleFormSubmit);
2019
displayCheckbox.addEventListener('change', convert);
2120
closeButton.addEventListener('click', () => {
2221
document.getElementById('mobile-notice').style.display = 'none';
2322
});
2423
shareBtn.addEventListener('click', handleShare);
2524

26-
// Load state from URL if present (wait for MathJax to be ready)
2725
loadStateFromURL();
2826

2927
function loadStateFromURL() {
3028
const state = getStateFromURL();
3129
if (state) {
32-
// Set input value
3330
inputField.value = state.number;
34-
35-
// Set checkboxes
31+
3632
document.getElementById('gamma-function').checked = state.config.gammaFunction;
3733
document.getElementById('eulers-identity').checked = state.config.eulersIdentity;
3834
document.getElementById('limits-exponential').checked = state.config.limitExponential;
3935
document.getElementById('limits-polynomial').checked = state.config.limitPolynomial;
4036
document.getElementById('trig').checked = state.config.trig;
4137
document.getElementById('geometric-series').checked = state.config.geometricSeries;
42-
43-
// Wait for MathJax to be ready before rendering
38+
4439
if (window.MathJax && window.MathJax.startup) {
4540
MathJax.startup.promise.then(() => {
4641
convert();
4742
});
4843
} else {
49-
// MathJax not loaded yet, wait for it
5044
window.addEventListener('load', () => {
5145
if (window.MathJax && window.MathJax.startup) {
5246
MathJax.startup.promise.then(() => {
@@ -66,14 +60,12 @@ document.addEventListener('DOMContentLoaded', function () {
6660
function convert() {
6761
const number = inputField.value;
6862

69-
// Validate input
7063
const validation = validateInput(number);
7164
if (!validation.valid) {
7265
showError(validation.error);
7366
return;
7467
}
7568

76-
// Get configuration from checkboxes
7769
const config = {
7870
gammaFunction: document.getElementById('gamma-function').checked,
7971
eulersIdentity: document.getElementById('eulers-identity').checked,
@@ -83,20 +75,17 @@ document.addEventListener('DOMContentLoaded', function () {
8375
geometricSeries: document.getElementById('geometric-series').checked,
8476
};
8577

86-
// Generate the LaTeX expression
8778
const input = generateEquation(Number(number), config);
8879

89-
// Render with MathJax
9080
renderEquation(input);
91-
92-
// Update URL with current state (for sharing)
81+
9382
updateURL(Number(number), config);
9483
}
9584

9685
function handleShare() {
9786
const number = inputField.value;
9887
const validation = validateInput(number);
99-
88+
10089
if (!validation.valid) {
10190
showError('Please generate an equation first before sharing!');
10291
return;
@@ -112,7 +101,7 @@ document.addEventListener('DOMContentLoaded', function () {
112101
};
113102

114103
const shareableURL = generateShareableURL(Number(number), config);
115-
104+
116105
// Try to use native share API if available (mobile devices)
117106
if (navigator.share) {
118107
navigator.share({
@@ -125,24 +114,21 @@ document.addEventListener('DOMContentLoaded', function () {
125114
}
126115
});
127116
} else {
128-
// Fallback to clipboard
129117
copyToClipboard(shareableURL);
130118
}
131119
}
132120

133121
function copyToClipboard(text) {
134122
navigator.clipboard.writeText(text).then(() => {
135-
// Show feedback
136123
const originalText = shareBtn.textContent;
137124
shareBtn.textContent = '✓ Link copied!';
138125
shareBtn.style.backgroundColor = '#28a745';
139-
126+
140127
setTimeout(() => {
141128
shareBtn.textContent = originalText;
142129
shareBtn.style.backgroundColor = '';
143130
}, 2000);
144131
}).catch(() => {
145-
// Fallback for older browsers
146132
const textarea = document.createElement('textarea');
147133
textarea.value = text;
148134
textarea.style.position = 'fixed';
@@ -151,7 +137,7 @@ document.addEventListener('DOMContentLoaded', function () {
151137
textarea.select();
152138
document.execCommand('copy');
153139
document.body.removeChild(textarea);
154-
140+
155141
const originalText = shareBtn.textContent;
156142
shareBtn.textContent = '✓ Link copied!';
157143
setTimeout(() => {
@@ -165,18 +151,13 @@ document.addEventListener('DOMContentLoaded', function () {
165151
}
166152

167153
function renderEquation(latexExpression) {
168-
// Disable buttons while rendering
169154
renderButton.disabled = displayCheckbox.disabled = true;
170155

171-
// Clear previous output
172156
outputDiv.innerHTML = '';
173157

174-
// Configure MathJax rendering
175158
MathJax.texReset();
176159
const options = MathJax.getMetricsFor(outputDiv);
177160
options.display = displayCheckbox.checked;
178-
179-
// Render the LaTeX expression
180161
MathJax.tex2svgPromise(latexExpression, options)
181162
.then((node) => {
182163
outputDiv.appendChild(node);

0 commit comments

Comments
 (0)