@mathzetta/inlinemath 0.1.0 → 0.2.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 +64 -20
- package/dist/cas.external.js +2 -2
- package/dist/cas.js +2 -2
- package/dist/chunks/calculate-Cz87Lt0N.js +2 -0
- package/dist/chunks/draw-Bev17BJJ.js +2 -0
- package/dist/chunks/edit-C65xXzo8.js +2 -0
- package/dist/chunks/edit-M68aRA5o.js +2 -0
- package/dist/chunks/{html-CvuSyhzk.js → html-BimAqn7x.js} +2 -2
- package/dist/chunks/html-CupluJSh.js +2 -0
- package/dist/chunks/lite-3Fb-OHbt.js +2 -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 +32 -1
- 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/inlinemath.css +32 -1
- package/package.json +3 -3
- package/src/cas.js +25 -15
- package/src/edit.js +96 -0
- package/src/glyphs.js +2 -0
- package/src/index.d.ts +2 -2
- package/src/index.js +1 -1
- package/src/layout.js +55 -11
- package/src/markdown.d.ts +2 -2
- package/src/markdown.js +354 -39
- package/src/mathzetta.js +2 -1
- package/src/types.d.ts +77 -6
- package/src/variables.js +228 -0
- package/src/view.js +226 -6
- package/dist/chunks/calculate-BX9lJ7Ff.js +0 -2
- package/dist/chunks/draw-Cm4exbg7.js +0 -2
- package/dist/chunks/html-DWtfytjA.js +0 -2
- package/dist/chunks/lite-Bj_L6w2g.js +0 -2
package/README.md
CHANGED
|
@@ -29,11 +29,27 @@ 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
|
|
35
38
|
```
|
|
36
39
|
|
|
40
|
+
**Editing a part.** `view.editable({ toText })` (`import { toText } from 'mathzetta/text'`; in the
|
|
41
|
+
`<script>` build it is `InlineMath.toText`) opens a text box over a part when it is double-clicked,
|
|
42
|
+
or when F2 is pressed on the part the keyboard is on, holding that part as text. Enter puts what
|
|
43
|
+
was typed in its place (the rest of the expression glides over), Escape leaves it as it was, and
|
|
44
|
+
text that doesn't read keeps the box open, marked. `onEdit` gets the new expression as a tree and
|
|
45
|
+
as text, the edited part's path and what was typed; `view.edit(target)` opens the box from code.
|
|
46
|
+
|
|
47
|
+
**Keyboard and screen readers.** Every drawing has an accessible name (`role="math"`, its spoken form for a listener
|
|
48
|
+
who can't see it). Once a view listens for `'click'`, the drawing is one tab stop: the arrow keys walk its parts (Down
|
|
49
|
+
into a part, Up out, Left/Right between neighbours, Home or Escape back to the whole), each part is spoken through a
|
|
50
|
+
polite live region and ringed, and Enter or Space calls the click listener for the current part (`event` is then the
|
|
51
|
+
KeyboardEvent). `view.focusPart(node)` moves there from code.
|
|
52
|
+
|
|
37
53
|
Inline Math needs its stylesheet on the page (the fonts are optional):
|
|
38
54
|
|
|
39
55
|
```js
|
|
@@ -43,8 +59,8 @@ import '@mathzetta/inlinemath/fonts/fonts.css'; // optional: Latin Modern, th
|
|
|
43
59
|
|
|
44
60
|
```html
|
|
45
61
|
<!-- 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.
|
|
62
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/inlinemath.css">
|
|
63
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/fonts/fonts.css"> <!-- optional -->
|
|
48
64
|
```
|
|
49
65
|
|
|
50
66
|
### Lite: drawing only
|
|
@@ -108,7 +124,8 @@ These go to `toHTML(input, options)` and `render(el, input, options)`.
|
|
|
108
124
|
| `colors` | | `{ 'x^2': 'red', 5: 'blue' }` (number keys are ids) or `[[target, colour]]` |
|
|
109
125
|
| `highlight` | | target(s) that get the `mv-hl` class |
|
|
110
126
|
| `attributes`, `style` | | `(node) => ({…})` / `(node) => 'css'` for each node's element |
|
|
111
|
-
| `
|
|
127
|
+
| `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 |
|
|
128
|
+
| `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
129
|
| `prefix` | `'mv'` | class prefix |
|
|
113
130
|
|
|
114
131
|
A *target* can be any of these:
|
|
@@ -150,21 +167,21 @@ Every npm release's `dist/` is on jsDelivr (and unpkg); the bundles carry MathZe
|
|
|
150
167
|
page needs nothing else:
|
|
151
168
|
|
|
152
169
|
```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.
|
|
170
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/dist/fonts/fonts.css">
|
|
171
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/dist/inlinemath.css">
|
|
155
172
|
|
|
156
173
|
<!-- a script tag: window.InlineMath -->
|
|
157
|
-
<script src="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.
|
|
174
|
+
<script src="https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/dist/inlinemath.global.min.js"></script>
|
|
158
175
|
<script>document.getElementById('out').innerHTML = InlineMath.toHTML('\\frac{d}{dx} x^2');</script>
|
|
159
176
|
|
|
160
177
|
<!-- or modules: inlinemath.js, markdown.js, cas.js (the CAS one holds MathZetta CAS too) -->
|
|
161
178
|
<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.
|
|
179
|
+
import { toHTML } from 'https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/dist/inlinemath.js';
|
|
180
|
+
import { markdownToHTML } from 'https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/dist/markdown.js';
|
|
164
181
|
</script>
|
|
165
182
|
```
|
|
166
183
|
|
|
167
|
-
`@0.
|
|
184
|
+
`@0.2` follows the latest 0.2.x; `@0.2.0` pins a release.
|
|
168
185
|
|
|
169
186
|
**The stylesheet is required** — the drawing is HTML laid out by `inlinemath.css` (6.9 KB, 2.1 KB
|
|
170
187
|
gzipped): without it fractions, radicals and brackets don't line up. The classic builds
|
|
@@ -200,7 +217,7 @@ map (every name can point at the one MathZetta bundle). The fonts are 94 KB more
|
|
|
200
217
|
"mathzetta/calculate": "https://cdn.jsdelivr.net/npm/mathzetta@1/build/mathzetta.esm.min.js" } }
|
|
201
218
|
</script>
|
|
202
219
|
<script type="module">
|
|
203
|
-
import { toHTML } from 'https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.
|
|
220
|
+
import { toHTML } from 'https://cdn.jsdelivr.net/npm/@mathzetta/inlinemath@0.2/dist/inlinemath.external.js';
|
|
204
221
|
</script>
|
|
205
222
|
```
|
|
206
223
|
|
|
@@ -218,8 +235,37 @@ el.innerHTML = markdownToHTML(text, { blocks: casBlocks() }); // {{solve(…)}},
|
|
|
218
235
|
`\(…\)` / `\[…\]`. MathZetta reads it, so LaTeX, plain text (`$sqrt(x)/2$`) and
|
|
219
236
|
code all work.
|
|
220
237
|
- **Working out:** `{{…}}` inside maths is worked out (the calculator, or the CAS with
|
|
221
|
-
`blocks`). A definition like `$r = 3$`
|
|
222
|
-
|
|
238
|
+
`blocks`). A definition like `$r = 3$` is remembered, exactly, for the `{{…}}` after it
|
|
239
|
+
(`define: false` turns that off; `scope: { r: 3 }` gives values).
|
|
240
|
+
- **Saved variables:** `$A := 2+2$` saves A (drawn A ≔ 2 + 2), and `$_A := 2+2$` saves it
|
|
241
|
+
without drawing anything. After that, A in any maths is drawn as its expression and `{{A}}`
|
|
242
|
+
is its value, so `$A = {{A}}$` draws 2 + 2 = 4 and `$3A$` draws 3(2 + 2). A name is a letter
|
|
243
|
+
(Greek too), optionally with a subscript (`A_1`); a variable may use the ones before it
|
|
244
|
+
(`$_B := 2A$`), and saving it again replaces it from there on. A plain `$r = 3$` still only
|
|
245
|
+
remembers the number: r keeps being drawn as r.
|
|
246
|
+
- **Matrices:** `\begin{pmatrix}…`, `bmatrix`, `vmatrix` (and `[[1, 2], [3, 4]]`) are drawn as
|
|
247
|
+
a grid in brackets as tall as it, and worked out exactly: `{{A^2}}`, `{{A^{-1}}}`, `{{A^T}}`,
|
|
248
|
+
`{{det(A)}}`, `{{A [5, 6]}}`, `{{linsolve(A, b)}}`. A saved variable can hold one:
|
|
249
|
+
`$_M := [[2, 1], [1, 3]]$` then `$M^2 = {{M^2}}$`.
|
|
250
|
+
- **With the CAS:** `{ blocks: casBlocks() }` works out `{{der(x^2, x)}}` (also `diff`,
|
|
251
|
+
`derivative`, `d/dx …`), `{{integral(x^2, x)}}`, `{{solve(…, x)}}`, `{{factor(…)}}` …, and a
|
|
252
|
+
saved variable stands for its expression there: after `$_f := x^3 + 2x$`, `{{der(f, x)}}` is
|
|
253
|
+
3x² + 2.
|
|
254
|
+
- **Inputs:** `$A := [[2+2]]$` is a textbox that sets A, `$f := [[x^2 | sin(x) | 2x]]$` a
|
|
255
|
+
dropdown, `$n := [[1..10]]$` a slider (`[[0..1 step 0.05 = 0.5]]`: a step and a starting
|
|
256
|
+
value); with `$_…$` only the input is shown. `renderMarkdownInto(el, text)` makes them live:
|
|
257
|
+
every part of the page drawn with it shares the page's store (`variables`), so a variable
|
|
258
|
+
saved in one part is used in the others, and changing an input redraws everything that uses
|
|
259
|
+
it. `variables.set('A', 'x^2')` sets one from code, `variables.get('A')` reads it;
|
|
260
|
+
`{ variables: createVariables() }` gives a part a store of its own, `{ variables: false }` none.
|
|
261
|
+
`markdownToHTML` is static: inputs drawn at their starting values.
|
|
262
|
+
- **Editing by double-click:** in `renderMarkdownInto`, a part drawn from a textbox variable is
|
|
263
|
+
edited where it is drawn with `{ editable: { toText } }` (the whole variable is written back
|
|
264
|
+
into its textbox, so everything using it redraws); without `toText` the textbox is focused.
|
|
265
|
+
Double-clicking any other part fires `inlinemath:select` on the element with where that maths
|
|
266
|
+
is in the Markdown (`detail.start`, `detail.end`, `detail.raw`; for a part drawn from a
|
|
267
|
+
variable saved in the same text, where it was saved), so an editor beside it can select it.
|
|
268
|
+
`extractMath` gives every piece's `start` and `end` too.
|
|
223
269
|
- **Dollars:** a `$` is maths only when it looks like it (Pandoc's rule): "$5 and $10"
|
|
224
270
|
stays text, and `\$` is a dollar sign. Code spans and fences are left alone.
|
|
225
271
|
- **Bad maths:** maths that doesn't read is shown as written, marked, with the reason as
|
|
@@ -260,7 +306,6 @@ playground: any input, any operation, detail level, and a live rule editor).
|
|
|
260
306
|
|
|
261
307
|
**Notation MathZetta doesn't read yet** (Inline Math can only draw what parses):
|
|
262
308
|
- **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
309
|
- **Partial derivatives:** `\partial f / \partial x` becomes products.
|
|
265
310
|
- **Derivative orders:** `f^{(4)}` becomes a power.
|
|
266
311
|
- **Lists of answers:** `x = 2, x = -3` is rejected.
|
|
@@ -270,11 +315,10 @@ playground: any input, any operation, detail level, and a live rule editor).
|
|
|
270
315
|
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
316
|
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
317
|
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.
|
|
318
|
+
4. **Copy as LaTeX or text** from a selection.
|
|
319
|
+
5. **Line breaking and alignment.** Multi-line derivations with the `=` signs lined up (an `align` helper), and breaking long sums.
|
|
320
|
+
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.
|
|
321
|
+
7. **Spacing table.** Move the per-operator spacing (bin, rel, thin) into one table so a house style is one edit.
|
|
278
322
|
|
|
279
323
|
## Known rough edges
|
|
280
324
|
|