-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
index.html
291 lines (264 loc) · 8.19 KB
/
index.html
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<html>
<head>
<title>Math API</title>
<meta name="viewport" content="width=device-width" />
<style>
:root {
--bg: white;
--text: black;
--accent: rgb(94, 5, 255);
}
/* @media (prefers-color-scheme: dark) {
:root {
--bg: #040b31;
--text: white;
--accent: rgb(75 196 255);
}
} */
body {
background: var(--bg);
color: var(--text);
padding: 15px;
}
a:link,
a:visited,
a:hover,
a:active {
color: var(--text);
}
@media screen and (max-width: 600px) {
#heading {
width: 100%;
}
}
.main {
max-width: 800px;
margin: 0 auto 80px auto;
}
.notation {
font-weight: bold;
color: rgb(239, 83, 81);
}
.equation {
font-weight: bold;
color: var(--accent);
}
h1,
h2 {
margin-top: 80px;
}
h3 {
margin-top: 30px;
}
.input-field {
padding: 16px;
font-size: 15px;
border: none;
background: var(--accent);
color: var(--bg) !important;
border-radius: 4px;
}
#request {
width: 100%;
height: 120px;
}
.responseField {
display: block;
width: 100%;
padding: 16px;
font-size: 14px;
font-family: monospace;
border: 2px solid var(--accent);
background: var(--bg);
color: var(--accent);
}
</style>
<script
async
defer
data-website-id="77d81656-31f9-4892-b510-0ea2044298e5"
src="https://analytics.uechi.io/umami.js"
></script>
</head>
<body style="font-family: monospace">
<div class="main">
<h1>Math API</h1>
<p>
<img
src="/?from=\xrightarrow{\infty}%5Ctext%7BPlace%20%7D%20%5CLaTeX%20%5Ctext%7B%20Math%20equation%20on%20anywhere%20as%20%7D%20%5Ctexttt%7B%3Cimg%3E%7D%20%5Ctext%7B%20tag.%7D"
id="heading"
/>
</p>
<h2>Usage</h2>
<p style="font-size: 20px">
https://math.vercel.app?from=<span class="equation"
>[LaTeX Math Equation]</span
>
</p>
<h3>Block notation</h3>
<p>
https://math.vercel.app?<span class="notation">from</span>=<span
class="equation"
>\frac{1}{\Gamma(s)}\int_{0}^{\infty}\frac{u^{s-1}}{e^{u}-1}\mathrm{d}u</span
>
</p>
<img
src="/?from=%5Cfrac%7B1%7D%7B%5CGamma(s)%7D%5Cint_%7B0%7D%5E%7B%5Cinfty%7D%5Cfrac%7Bu%5E%7Bs-1%7D%7D%7Be%5E%7Bu%7D-1%7D%5Cmathrm%7Bd%7Du"
/>
<h3>Inline notation</h3>
<p>
https://math.vercel.app?<span class="notation">inline</span>=<span
class="equation"
>\frac{1}{\Gamma(s)}\int_{0}^{\infty}\frac{u^{s-1}}{e^{u}-1}\mathrm{d}u</span
>
</p>
<img
src="/?inline=%5Cfrac%7B1%7D%7B%5CGamma(s)%7D%5Cint_%7B0%7D%5E%7B%5Cinfty%7D%5Cfrac%7Bu%5E%7Bs-1%7D%7D%7Be%5E%7Bu%7D-1%7D%5Cmathrm%7Bd%7Du"
/>
<h3>Color</h3>
<p>
By default, the text color is black. You can manually change this
behavior by passing `color` parameter.
</p>
<p>
https://math.vercel.app?<span class="equation">color</span>=<span
class="notation"
>red</span
>&from=\frac{1}{\Gamma(s)}\int_{0}^{\infty}\frac{u^{s-1}}{e^{u}-1}\mathrm{d}u
</p>
<img
src="/?from=\frac{1}{\Gamma(s)}\int_{0}^{\infty}\frac{u^{s-1}}{e^{u}-1}\mathrm{d}u&color=red"
/>
<h3>Background Color</h3>
<p>
By default, the background is transparent. You can manually change this
behavior by passing `bgcolor` parameter. `auto` or any CSS color name
can be used.
</p>
<p>
https://math.vercel.app?<span class="equation">color</span>=<span
class="notation"
>white</span
>&<span class="equation">bgcolor</span>=<span class="notation"
>auto</span
>&from=\frac{1}{\Gamma(s)}\int_{0}^{\infty}\frac{u^{s-1}}{e^{u}-1}\mathrm{d}u
</p>
<img
src="/?from=\frac{1}{\Gamma(s)}\int_{0}^{\infty}\frac{u^{s-1}}{e^{u}-1}\mathrm{d}u&color=white&bgcolor=auto"
/>
<h2 id="online-editor">Online Editor</h2>
<textarea id="request" class="input-field" onKeyup="onTextChanged(this)">
\text{Edit this}\ \LaTeX</textarea
><br /><br />
<div style="text-align: right">
<label>Text: </label
><input
id="color"
class="input-field"
onKeyup="onColorChanged(this)"
placeholder="CSS color name"
/><br /><br />
<label>Background: </label
><input
id="bgColor"
class="input-field"
onKeyup="onBackgroundColorChanged(this)"
value="auto"
placeholder="auto or CSS color name"
/>
</div>
<div>
<h3>Preview</h3>
<img id="responseImage" src="/?from=\text{Edit this}\%20\LaTeX.svg" />
<h3>HTML</h3>
<input
id="responseHTML"
class="responseField"
readonly="true"
onClick="this.select();"
/>
<h3>Markdown</h3>
<input
id="responseMarkdown"
class="responseField"
readonly="true"
onClick="this.select();"
/>
<h3>URL</h3>
<input
id="responseURL"
class="responseField"
readonly="true"
onClick="this.select();"
/>
</div>
<script>
var equation = "\\text{Edit this}\\ \\LaTeX";
var color = "";
var bgColor = "";
const responseHTML = document.querySelector("#responseHTML");
const responseMarkdown = document.querySelector("#responseMarkdown");
const responseImage = document.querySelector("#responseImage");
const colorElement = document.querySelector("#color");
const bgColorElement = document.querySelector("#bgColor");
var timer;
function render() {
const purifiedURL =
location.origin +
"/?" +
(color ? "color=" + encodeURIComponent(color) + "&" : "") +
(bgColor ? "bgcolor=" + encodeURIComponent(bgColor) + "&" : "") +
"from=" +
encodeURIComponent(equation)
.replace(/\(/g, "%28")
.replace(/\)/g, "%29") +
".svg";
responseHTML.value = '<img src="' + purifiedURL + '" />';
responseMarkdown.value = "![Equation](" + purifiedURL + ")";
responseURL.value = purifiedURL;
responseImage.src = purifiedURL;
}
function onTextChanged(e) {
equation = e.value;
clearTimeout(timer);
timer = setTimeout(() => render(), 1000);
}
function onColorChanged(e) {
color = e.value;
clearTimeout(timer);
timer = setTimeout(() => render(), 1000);
}
function onBackgroundColorChanged(e) {
bgColor = e.value;
clearTimeout(timer);
timer = setTimeout(() => render(), 1000);
}
document.addEventListener("DOMContentLoaded", () => {
// const isSafari =
// /Safari/.test(navigator.userAgent) &&
// !/Chrome/.test(navigator.userAgent);
// if (isSafari) {
// const style = document.createElement("style");
// style.innerHTML = `
// :root {
// --bg: white;
// --text: black;
// --accent: rgb(94, 5, 255);
// }`;
// document.body.appendChild(style);
// }
color = colorElement.value;
bgColor = bgColorElement.value;
render();
});
</script>
<h2>Resources</h2>
<a href="https://github.com/uetchy/math-api">Source Code (GitHub)</a
><br />
<a href="https://twitter.com/uechz">Author (Twitter)</a><br />
<a href="https://dev.to/uetchy/math-api-latex-math-as-svg-image-m4p"
>Math API: LaTeX Math as SVG image - DEV Community 👩💻👨💻</a
><br />
</div>
</body>
</html>