@mathzetta/inlinemath 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -50
- package/dist/cas.external.js +2 -2
- package/dist/cas.js +2 -2
- package/dist/chunks/calculate-BGMEvf3f.js +2 -0
- package/dist/chunks/draw-q86mDDWm.js +2 -0
- package/dist/chunks/edit-CTMRUElt.js +2 -0
- package/dist/chunks/edit-D2RO7fg0.js +2 -0
- package/dist/chunks/html-1wCO6EpZ.js +2 -0
- package/dist/chunks/html-D5QiXGXD.js +2 -0
- package/dist/chunks/lite-Bo8THzyq.js +2 -0
- package/dist/fonts/README-inlinemath-greek.txt +15 -0
- package/dist/fonts/fonts.css +19 -1
- package/dist/fonts/inlinemath-greek-italic.woff2 +0 -0
- package/dist/fonts/inlinemath-greek-regular.woff2 +0 -0
- package/dist/inlinemath-cas.external.global.min.js +2 -2
- package/dist/inlinemath-cas.global.min.js +2 -2
- package/dist/inlinemath-lite-calc.global.min.js +2 -2
- package/dist/inlinemath-lite.external.global.min.js +2 -2
- package/dist/inlinemath-lite.global.min.js +2 -2
- package/dist/inlinemath.css +48 -7
- package/dist/inlinemath.external.global.min.js +2 -2
- package/dist/inlinemath.external.js +2 -2
- package/dist/inlinemath.global.min.js +2 -2
- package/dist/inlinemath.js +2 -2
- package/dist/lite-calc.js +2 -2
- package/dist/lite.external.js +2 -2
- package/dist/lite.js +2 -2
- package/dist/markdown.external.js +2 -2
- package/dist/markdown.js +2 -2
- package/fonts/README-inlinemath-greek.txt +15 -0
- package/fonts/fonts.css +19 -1
- package/fonts/inlinemath-greek-italic.woff2 +0 -0
- package/fonts/inlinemath-greek-regular.woff2 +0 -0
- package/inlinemath.css +48 -7
- package/package.json +6 -6
- package/src/cas.d.ts +1 -1
- package/src/cas.js +38 -17
- package/src/draw.js +13 -9
- package/src/edit.js +103 -0
- package/src/glyphs.js +2 -0
- package/src/html.js +1 -1
- package/src/index.d.ts +2 -2
- package/src/index.js +2 -2
- package/src/layout.js +142 -41
- package/src/lite.js +1 -1
- package/src/markdown.d.ts +3 -3
- package/src/markdown.js +476 -79
- package/src/mathzetta.js +3 -2
- package/src/select.js +7 -0
- package/src/types.d.ts +86 -13
- package/src/variables.js +262 -0
- package/src/view.js +286 -15
- package/dist/chunks/calculate-BX9lJ7Ff.js +0 -2
- package/dist/chunks/draw-Cm4exbg7.js +0 -2
- package/dist/chunks/html-CvuSyhzk.js +0 -2
- package/dist/chunks/html-DWtfytjA.js +0 -2
- package/dist/chunks/lite-Bj_L6w2g.js +0 -2
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Inline Math
|
|
2
2
|
|
|
3
|
-
Draws calculus-level
|
|
3
|
+
Draws calculus-level math as plain HTML and CSS (the `@mathzetta/inlinemath` package, at inlinemath.com). The input is anything
|
|
4
4
|
[MathZetta](https://github.com/triplelog/mathzetta/tree/main/packages/mathzetta) reads (`sin^2 x`, `\frac{d}{dx}(x^2)`, `x**2/2`, `√x`).
|
|
5
|
-
Every part of the drawing can be found,
|
|
5
|
+
Every part of the drawing can be found, colored, clicked and animated.
|
|
6
6
|
|
|
7
7
|
Inline Math is not a LaTeX engine. It covers what a Calculus course writes:
|
|
8
8
|
- fractions, exponents and subscripts, radicals, brackets that grow;
|
|
@@ -29,11 +29,28 @@ toHTML('\\int_0^1 x^2\\,dx'); // HTML string; works in Node too
|
|
|
29
29
|
const view = render(div, 'x^2 + 2x'); // a live view
|
|
30
30
|
view.highlight('2x'); // name a part by writing it
|
|
31
31
|
view.color('x^2', 'crimson');
|
|
32
|
-
view.on('click', ({ node, id, path }) => …);
|
|
33
|
-
view.set('2x + x^2', { animate: true }); // the next step: matching parts glide over
|
|
32
|
+
view.on('click', ({ node, id, path }) => …); // also from the keyboard: Tab to it, arrows walk the parts, Enter picks one
|
|
33
|
+
view.set('2x + x^2', { animate: true }); // the next step: matching parts glide over (instant under reduced motion; 'always' to insist)
|
|
34
|
+
render(div, 'x^2', { announce: true }); // read each new step to a screen reader (a polite live region after the div)
|
|
35
|
+
view.announce('Step 2: expand'); // your own words, through the same region
|
|
34
36
|
view.segments(); // [{ text: 'x', id: 3 }, { text: 'squared', id: 5 }, …]
|
|
37
|
+
view.editable({ toText, onEdit: ({ text }) => … }); // double-click a part (or F2 on it) to edit it in place
|
|
38
|
+
view.destroy(); // stop listening (handlers, keys, editing) before drawing a new view into el
|
|
35
39
|
```
|
|
36
40
|
|
|
41
|
+
**Editing a part.** `view.editable({ toText })` (`import { toText } from 'mathzetta/text'`; in the
|
|
42
|
+
`<script>` build it is `InlineMath.toText`) opens a text box over a part when it is double-clicked,
|
|
43
|
+
or when F2 is pressed on the part the keyboard is on, holding that part as text. Enter puts what
|
|
44
|
+
was typed in its place (the rest of the expression glides over), Escape leaves it as it was, and
|
|
45
|
+
text that doesn't read keeps the box open, marked. `onEdit` gets the new expression as a tree and
|
|
46
|
+
as text, the edited part's path and what was typed; `view.edit(target)` opens the box from code.
|
|
47
|
+
|
|
48
|
+
**Keyboard and screen readers.** Every drawing has an accessible name (`role="math"`, its spoken form for a listener
|
|
49
|
+
who can't see it). Once a view listens for `'click'`, the drawing is one tab stop: the arrow keys walk its parts (Down
|
|
50
|
+
into a part, Up out, Left/Right between neighbors, Home or Escape back to the whole), each part is spoken through a
|
|
51
|
+
polite live region and ringed, and Enter or Space calls the click listener for the current part (`event` is then the
|
|
52
|
+
KeyboardEvent). `view.focusPart(node)` moves there from code.
|
|
53
|
+
|
|
37
54
|
Inline Math needs its stylesheet on the page (the fonts are optional):
|
|
38
55
|
|
|
39
56
|
```js
|
|
@@ -43,13 +60,13 @@ import '@mathzetta/inlinemath/fonts/fonts.css'; // optional: Latin Modern, th
|
|
|
43
60
|
|
|
44
61
|
```html
|
|
45
62
|
<!-- or from the CDN -->
|
|
46
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.
|
|
47
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.
|
|
63
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/inlinemath.css">
|
|
64
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/fonts/fonts.css"> <!-- optional -->
|
|
48
65
|
```
|
|
49
66
|
|
|
50
67
|
### Lite: drawing only
|
|
51
68
|
|
|
52
|
-
`@mathzetta/inlinemath/lite` is `toHTML()` and nothing live: the same layout, glyphs,
|
|
69
|
+
`@mathzetta/inlinemath/lite` is `toHTML()` and nothing live: the same layout, glyphs, colors, highlights and
|
|
53
70
|
spoken labels for screen readers, without the live view (`render`, step animation, events), Markdown
|
|
54
71
|
or the CAS — about a third smaller. `{{…}}` blocks are worked out only if MathZetta's calculator is
|
|
55
72
|
loaded too (`import 'mathzetta/calculate'`, or `@mathzetta/inlinemath/lite-calc`, which brings it); otherwise
|
|
@@ -78,14 +95,14 @@ npm test # 253 checks; every input in mathzetta/test/cases/calculus.tsv
|
|
|
78
95
|
| `src/layout.js` | Turns a tree into HTML. All notation choices live here. |
|
|
79
96
|
| `src/glyphs.js` | SVG paths for `( ) { } √ ∫ ∑ ∏`. Change a shape here. |
|
|
80
97
|
| `src/select.js` | Picks parts by id, expression, path or test. Also `numberTree`. |
|
|
81
|
-
| `src/view.js` | The live view: highlight,
|
|
98
|
+
| `src/view.js` | The live view: highlight, color, events, speech segments, step animation. |
|
|
82
99
|
| `src/html.js` | `toHTML`, `treeOf`, and the `colors` / `highlight` options. |
|
|
83
100
|
| `inlinemath.css` | All the styling. The numbers marked *metric* must match the constants in layout.js. |
|
|
84
101
|
|
|
85
|
-
## How it lays
|
|
102
|
+
## How it lays math out
|
|
86
103
|
|
|
87
104
|
- **Estimated, not measured.** Each piece knows roughly how far it reaches above and below the baseline, in em.
|
|
88
|
-
- From that, `layout.js` writes `vertical-align` values that put fraction bars on the
|
|
105
|
+
- From that, `layout.js` writes `vertical-align` values that put fraction bars on the math axis, lift exponents above tall bases, and size `∫` to its integrand.
|
|
89
106
|
- The same string comes out in Node, in a browser or in a video frame, with no layout pass after rendering.
|
|
90
107
|
- **Self-stretching delimiters.** Brackets, bars, floors and braces are drawn at `height: 100%` of what they enclose (SVG or CSS borders), so they need no estimate at all.
|
|
91
108
|
- This is the best idea from inline-math's imcss renderer. Inline Math fixes its aspect-ratio bug: shapes use `preserveAspectRatio="none"` with a fixed width.
|
|
@@ -105,10 +122,12 @@ These go to `toHTML(input, options)` and `render(el, input, options)`.
|
|
|
105
122
|
| `derivativeBrackets` | `'['` | `'('` for d/dx (x² + 1) |
|
|
106
123
|
| `scriptFractions` | `'slash'` | x^{3/2} written with a slash. `'stack'` stacks it. |
|
|
107
124
|
| `cases` | `true` | `c ? a : b` drawn as a piecewise brace |
|
|
108
|
-
|
|
|
125
|
+
| | | A product typed with `·` (`\cdot`) or `×` (`\times`) is drawn with that sign (MathZetta's `node.written`); other products get a sign only where one is needed. Postfix input has no such marks. |
|
|
126
|
+
| `colors` | | `{ 'x^2': 'red', 5: 'blue' }` (number keys are ids) or `[[target, color]]` |
|
|
109
127
|
| `highlight` | | target(s) that get the `mv-hl` class |
|
|
110
128
|
| `attributes`, `style` | | `(node) => ({…})` / `(node) => 'css'` for each node's element |
|
|
111
|
-
| `
|
|
129
|
+
| `mathml` | | MathZetta's `toMathML` (`import { toMathML } from 'mathzetta/mathml'`): also write the expression as visually hidden MathML (no ids), which screen readers can step through part by part and show in math braille; the drawing stays hidden from them and the label is dropped (MathML carries the meaning). A keyboard-enabled view keeps its label on the focusable element |
|
|
130
|
+
| `label` | `true` | the accessible name of the expression (`role="math" aria-label`): `true` = its spoken form for a listener who can't see it (MathZetta's `toAudioSpeech`: "the square root of the quantity x plus 1, end root, plus 2"), or a string, `(tree) => string`, or `false` |
|
|
112
131
|
| `prefix` | `'mv'` | class prefix |
|
|
113
132
|
|
|
114
133
|
A *target* can be any of these:
|
|
@@ -127,8 +146,8 @@ npm run build # dist/ (a few seconds)
|
|
|
127
146
|
|
|
128
147
|
- **`dist/`** — Inline Math with everything inside, no import map or `node_modules` needed:
|
|
129
148
|
- `inlinemath.js`, `markdown.js`, `cas.js` — ES modules (shared code in `dist/chunks/`);
|
|
130
|
-
- `inlinemath.global.min.js` (
|
|
131
|
-
- `inlinemath-cas.global.min.js` (
|
|
149
|
+
- `inlinemath.global.min.js` (183 KB, 62 KB gzipped) — a classic `<script>`: `window.InlineMath`, with Inline Math and the Markdown;
|
|
150
|
+
- `inlinemath-cas.global.min.js` (323 KB, 104 KB gzipped) — the same plus the CAS (`InlineMath.mathCAS`, `casBlocks`, `stepsHTML`);
|
|
132
151
|
- `inlinemath.css` and `fonts/` — put both on the page.
|
|
133
152
|
|
|
134
153
|
```html
|
|
@@ -150,48 +169,50 @@ Every npm release's `dist/` is on jsDelivr (and unpkg); the bundles carry MathZe
|
|
|
150
169
|
page needs nothing else:
|
|
151
170
|
|
|
152
171
|
```html
|
|
153
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.
|
|
154
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.
|
|
172
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/dist/fonts/fonts.css">
|
|
173
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/dist/inlinemath.css">
|
|
155
174
|
|
|
156
175
|
<!-- a script tag: window.InlineMath -->
|
|
157
|
-
<script src="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.
|
|
176
|
+
<script src="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/dist/inlinemath.global.min.js"></script>
|
|
158
177
|
<script>document.getElementById('out').innerHTML = InlineMath.toHTML('\\frac{d}{dx} x^2');</script>
|
|
159
178
|
|
|
160
179
|
<!-- or modules: inlinemath.js, markdown.js, cas.js (the CAS one holds MathZetta CAS too) -->
|
|
161
180
|
<script type="module">
|
|
162
|
-
import { toHTML } from 'https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.
|
|
163
|
-
import { markdownToHTML } from 'https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.
|
|
181
|
+
import { toHTML } from 'https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/dist/inlinemath.js';
|
|
182
|
+
import { markdownToHTML } from 'https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/dist/markdown.js';
|
|
164
183
|
</script>
|
|
165
184
|
```
|
|
166
185
|
|
|
167
|
-
`@0.
|
|
186
|
+
`@0.2` follows the latest 0.2.x; `@0.2.0` pins a release.
|
|
168
187
|
|
|
169
|
-
**The stylesheet is required** — the drawing is HTML laid out by `inlinemath.css` (
|
|
188
|
+
**The stylesheet is required** — the drawing is HTML laid out by `inlinemath.css` (10.4 KB, 3.2 KB
|
|
170
189
|
gzipped): without it fractions, radicals and brackets don't line up. The classic builds
|
|
171
190
|
(`*.global.min.js`) carry it and add it to the page themselves (`<style id="inlinemath-css">`; a
|
|
172
191
|
`<link>` to `dist/inlinemath.css` is still fine, it is only added when absent); the ES modules
|
|
173
192
|
don't, so a page using them links `dist/inlinemath.css`. **The fonts are optional**: `fonts/fonts.css`
|
|
174
|
-
declares Latin Modern Roman (the TeX look) in two files, regular 45 KB and italic 47 KB (woff2),
|
|
175
|
-
|
|
193
|
+
declares Latin Modern Roman (the TeX look) in two files, regular 45 KB and italic 47 KB (woff2), and
|
|
194
|
+
its Greek letters, which Latin Modern lacks, from New Computer Modern in the same design (10 KB each,
|
|
195
|
+
`fonts/README-inlinemath-greek.txt`). Each file is downloaded only when text uses it, so a page without
|
|
196
|
+
Greek never fetches those two; without the link the math is drawn in the system serif.
|
|
176
197
|
|
|
177
198
|
Every build comes **with MathZetta inside, or without it** (`*.external.*`), with or without the
|
|
178
199
|
CAS (MathZetta CAS). Sizes, gzipped:
|
|
179
200
|
|
|
180
201
|
| | ES module | classic `<script>` (`window.InlineMath`) |
|
|
181
202
|
|---|---|---|
|
|
182
|
-
| Lite (drawing only), MathZetta inside | `lite.js`
|
|
183
|
-
| Lite with the calculator (`{{…}}` worked out) | `lite-calc.js`
|
|
184
|
-
| Lite without MathZetta | `lite.external.js`
|
|
185
|
-
| Inline Math (+ Markdown in the classic build), MathZetta inside | `inlinemath.js`
|
|
186
|
-
| …without MathZetta | `inlinemath.external.js` **
|
|
187
|
-
| with the CAS, MathZetta inside | `cas.js`
|
|
188
|
-
| with the CAS, without MathZetta | `cas.external.js`
|
|
203
|
+
| Lite (drawing only), MathZetta inside | `lite.js` 35 KB | `inlinemath-lite.global.min.js` 38 KB |
|
|
204
|
+
| Lite with the calculator (`{{…}}` worked out) | `lite-calc.js` 48 KB | `inlinemath-lite-calc.global.min.js` 52 KB |
|
|
205
|
+
| Lite without MathZetta | `lite.external.js` 8 KB | `inlinemath-lite.external.global.min.js` 11 KB |
|
|
206
|
+
| Inline Math (+ Markdown in the classic build), MathZetta inside | `inlinemath.js` 51 KB, `markdown.js` 55 KB | `inlinemath.global.min.js` 62 KB |
|
|
207
|
+
| …without MathZetta | `inlinemath.external.js` **12 KB**, `markdown.external.js` 15 KB | `inlinemath.external.global.min.js` 21 KB |
|
|
208
|
+
| with the CAS, MathZetta inside | `cas.js` 90 KB | `inlinemath-cas.global.min.js` 104 KB |
|
|
209
|
+
| with the CAS, without MathZetta | `cas.external.js` 50 KB | `inlinemath-cas.external.global.min.js` 63 KB |
|
|
189
210
|
|
|
190
211
|
Without MathZetta, the page loads it once itself: a classic page puts a MathZetta `<script>` first —
|
|
191
|
-
`mathzetta.min.js`, or the `maths-display`
|
|
212
|
+
`mathzetta.min.js`, or the `maths-display` flavor, since speech, text and calculate are used (for
|
|
192
213
|
lite, `display`, or `maths-display` to work out `{{…}}`) — and
|
|
193
214
|
the external classic build reads `window.MathZetta`; a module page maps the names with an import
|
|
194
|
-
map (every name can point at the one MathZetta bundle). The fonts are 94 KB more, only if linked.
|
|
215
|
+
map (every name can point at the one MathZetta bundle). The fonts are 94 KB more (and 20 KB for Greek, only where it appears), only if linked.
|
|
195
216
|
|
|
196
217
|
```html
|
|
197
218
|
<script type="importmap">
|
|
@@ -200,13 +221,13 @@ map (every name can point at the one MathZetta bundle). The fonts are 94 KB more
|
|
|
200
221
|
"mathzetta/calculate": "https://cdn.jsdelivr.net/npm/mathzetta@1/build/mathzetta.esm.min.js" } }
|
|
201
222
|
</script>
|
|
202
223
|
<script type="module">
|
|
203
|
-
import { toHTML } from 'https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.
|
|
224
|
+
import { toHTML } from 'https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/dist/inlinemath.external.js';
|
|
204
225
|
</script>
|
|
205
226
|
```
|
|
206
227
|
|
|
207
228
|
Publishing is `npm publish` (`prepublishOnly` runs the tests and the build).
|
|
208
229
|
|
|
209
|
-
## Markdown with
|
|
230
|
+
## Markdown with math: `@mathzetta/inlinemath/markdown`
|
|
210
231
|
|
|
211
232
|
```js
|
|
212
233
|
import { markdownToHTML } from '@mathzetta/inlinemath/markdown';
|
|
@@ -214,20 +235,49 @@ el.innerHTML = markdownToHTML(text); // needs inlinemat
|
|
|
214
235
|
el.innerHTML = markdownToHTML(text, { blocks: casBlocks() }); // {{solve(…)}}, {{diff(…)}} too
|
|
215
236
|
```
|
|
216
237
|
|
|
217
|
-
- **
|
|
238
|
+
- **Math:** `$…$` inline, `$$…$$` or a ` ```math ` fence on its own (centered), and
|
|
218
239
|
`\(…\)` / `\[…\]`. MathZetta reads it, so LaTeX, plain text (`$sqrt(x)/2$`) and
|
|
219
240
|
code all work.
|
|
220
|
-
- **Working out:** `{{…}}` inside
|
|
221
|
-
`blocks`). A definition like `$r = 3$`
|
|
222
|
-
|
|
223
|
-
- **
|
|
241
|
+
- **Working out:** `{{…}}` inside math is worked out (the calculator, or the CAS with
|
|
242
|
+
`blocks`). A definition like `$r = 3$` is remembered, exactly, for the `{{…}}` after it
|
|
243
|
+
(`define: false` turns that off; `scope: { r: 3 }` gives values).
|
|
244
|
+
- **Saved variables:** `$A := 2+2$` saves A (drawn A ≔ 2 + 2), and `$_A := 2+2$` saves it
|
|
245
|
+
without drawing anything. After that, A in any math is drawn as its expression and `{{A}}`
|
|
246
|
+
is its value, so `$A = {{A}}$` draws 2 + 2 = 4 and `$3A$` draws 3(2 + 2). A name is a letter
|
|
247
|
+
(Greek too), optionally with a subscript (`A_1`); a variable may use the ones before it
|
|
248
|
+
(`$_B := 2A$`), and saving it again replaces it from there on. A plain `$r = 3$` still only
|
|
249
|
+
remembers the number: r keeps being drawn as r.
|
|
250
|
+
- **Matrices:** `\begin{pmatrix}…`, `bmatrix`, `vmatrix` (and `[[1, 2], [3, 4]]`) are drawn as
|
|
251
|
+
a grid in brackets as tall as it, and worked out exactly: `{{A^2}}`, `{{A^{-1}}}`, `{{A^T}}`,
|
|
252
|
+
`{{det(A)}}`, `{{A [5, 6]}}`, `{{linsolve(A, b)}}`. A saved variable can hold one:
|
|
253
|
+
`$_M := [[2, 1], [1, 3]]$` then `$M^2 = {{M^2}}$`.
|
|
254
|
+
- **With the CAS:** `{ blocks: casBlocks() }` works out `{{der(x^2, x)}}` (also `diff`,
|
|
255
|
+
`derivative`, `d/dx …`), `{{integral(x^2, x)}}`, `{{solve(…, x)}}`, `{{factor(…)}}` …, and a
|
|
256
|
+
saved variable stands for its expression there: after `$_f := x^3 + 2x$`, `{{der(f, x)}}` is
|
|
257
|
+
3x² + 2.
|
|
258
|
+
- **Inputs:** `$A := [[2+2]]$` is a textbox that sets A, `$f := [[x^2 | sin(x) | 2x]]$` a
|
|
259
|
+
dropdown, `$n := [[1..10]]$` a slider (`[[0..1 step 0.05 = 0.5]]`: a step and a starting
|
|
260
|
+
value); with `$_…$` only the input is shown. `renderMarkdownInto(el, text)` makes them live:
|
|
261
|
+
every part of the page drawn with it shares the page's store (`variables`), so a variable
|
|
262
|
+
saved in one part is used in the others, and changing an input redraws everything that uses
|
|
263
|
+
it. `variables.set('A', 'x^2')` sets one from code, `variables.get('A')` reads it;
|
|
264
|
+
`{ variables: createVariables() }` gives a part a store of its own, `{ variables: false }` none.
|
|
265
|
+
`markdownToHTML` is static: inputs drawn at their starting values.
|
|
266
|
+
- **Editing by double-click:** in `renderMarkdownInto`, a part drawn from a textbox variable is
|
|
267
|
+
edited where it is drawn with `{ editable: { toText } }` (the whole variable is written back
|
|
268
|
+
into its textbox, so everything using it redraws); without `toText` the textbox is focused.
|
|
269
|
+
Double-clicking any other part fires `inlinemath:select` on the element with where that math
|
|
270
|
+
is in the Markdown (`detail.start`, `detail.end`, `detail.raw`; for a part drawn from a
|
|
271
|
+
variable saved in the same text, where it was saved), so an editor beside it can select it.
|
|
272
|
+
`extractMath` gives every piece's `start` and `end` too.
|
|
273
|
+
- **Dollars:** a `$` is math only when it looks like it (Pandoc's rule): "$5 and $10"
|
|
224
274
|
stays text, and `\$` is a dollar sign. Code spans and fences are left alone.
|
|
225
|
-
- **Bad
|
|
275
|
+
- **Bad math:** math that doesn't read is shown as written, marked, with the reason as
|
|
226
276
|
its tooltip.
|
|
227
277
|
- **The Markdown:** a small built-in renderer — headings, emphasis, links, images, lists,
|
|
228
278
|
quotes, code, tables, rules. Raw HTML is shown as text unless `html: true`, and
|
|
229
279
|
`javascript:` links are dropped. `render: (md) => html` uses another renderer
|
|
230
|
-
(marked, markdown-it); the
|
|
280
|
+
(marked, markdown-it); the math is taken out first and put back into its output.
|
|
231
281
|
- **Options:** `math` passes options to every drawing (`fnParens`, `colors` …);
|
|
232
282
|
`delimiters` picks which marks count.
|
|
233
283
|
- **Playground:** [inlinemath.com/markdown.html](https://inlinemath.com/markdown.html), an editor with a live preview.
|
|
@@ -235,14 +285,14 @@ el.innerHTML = markdownToHTML(text, { blocks: casBlocks() }); // {{solve(…)}},
|
|
|
235
285
|
## The CAS: `@mathzetta/inlinemath/cas`
|
|
236
286
|
|
|
237
287
|
MathZetta CAS (exact simplify, factor, solve, d/dx, ∫ …; @mathzetta/cas's docs/cas.md)
|
|
238
|
-
in drawn
|
|
288
|
+
in drawn math:
|
|
239
289
|
|
|
240
290
|
```js
|
|
241
291
|
import { toHTML } from '@mathzetta/inlinemath';
|
|
242
292
|
import { casBlocks, stepsHTML, mathCAS } from '@mathzetta/inlinemath/cas';
|
|
243
293
|
|
|
244
294
|
toHTML("f'(x) = {{diff(x^3 sin(x), x)}}", { blocks: casBlocks() })
|
|
245
|
-
toHTML('{{solve(x^2 - 5x + 6 = 0, x)}}', { blocks: casBlocks() }) // x = 2
|
|
295
|
+
toHTML('{{solve(x^2 - 5x + 6 = 0, x)}}', { blocks: casBlocks() }) // x = 2 or x = 3
|
|
246
296
|
el.innerHTML = stepsHTML(mathCAS().solve('sqrt(x + 1) = x - 1', 'x', { steps: 'brief' }).steps)
|
|
247
297
|
```
|
|
248
298
|
|
|
@@ -260,7 +310,6 @@ playground: any input, any operation, detail level, and a live rule editor).
|
|
|
260
310
|
|
|
261
311
|
**Notation MathZetta doesn't read yet** (Inline Math can only draw what parses):
|
|
262
312
|
- **Evaluation bars:** `[F(x)]_0^1` reads as a power of a subscript, and `\left. F \right|_0^1` is rejected.
|
|
263
|
-
- **Matrices:** `\begin{pmatrix}` becomes nested lists.
|
|
264
313
|
- **Partial derivatives:** `\partial f / \partial x` becomes products.
|
|
265
314
|
- **Derivative orders:** `f^{(4)}` becomes a power.
|
|
266
315
|
- **Lists of answers:** `x = 2, x = -3` is rejected.
|
|
@@ -270,14 +319,13 @@ playground: any input, any operation, detail level, and a live rule editor).
|
|
|
270
319
|
1. **Exit animation.** Parts that disappear in a step should fade out where they were (ghost copies). Today they vanish, and new signs and bars just appear.
|
|
271
320
|
2. **Step-diff helper.** Given `step.before`, `step.after` and `step.path`, return what changed, then highlight → animate → un-highlight in one call. That would be the video's main move.
|
|
272
321
|
3. **Narration sync.** Something like `view.follow(segments, timings)`: drive highlights from a text-to-speech engine's word timings (`words: [{start, end, i, j}]`).
|
|
273
|
-
4. **
|
|
274
|
-
5. **
|
|
275
|
-
6. **
|
|
276
|
-
7. **
|
|
277
|
-
8. **Spacing table.** Move the per-operator spacing (bin, rel, thin) into one table so a house style is one edit.
|
|
322
|
+
4. **Copy as LaTeX or text** from a selection.
|
|
323
|
+
5. **Line breaking and alignment.** Multi-line derivations with the `=` signs lined up (an `align` helper), and breaking long sums.
|
|
324
|
+
6. **A DOM refine pass, optional.** Measure once after fonts load, to nudge fraction bars and script heights where the em estimates are off with unusual fonts.
|
|
325
|
+
7. **Spacing table.** Move the per-operator spacing (bin, rel, thin) into one table so a house style is one edit.
|
|
278
326
|
|
|
279
327
|
## Known rough edges
|
|
280
328
|
|
|
281
329
|
- **Fonts.** The placement estimates are tuned for Latin Modern and Times-like serifs. Fonts with unusual ascent and descent will sit a little off.
|
|
282
|
-
- **Accents.** `\vec
|
|
330
|
+
- **Accents.** `\vec`, `\hat`, `\tilde`, `\dot` and the overline are placed for Latin Modern: lower over a letter with no ascender (x, u, α), and leaning right over an italic letter. Other fonts can leave them a little high or low.
|
|
283
331
|
- **Unbalanced fractions.** Taller-than-usual numerators on fractions are placed from estimates. Very deep nesting can drift by a few hundredths of an em.
|