@mathzetta/inlinemath 0.2.0 → 0.4.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 +37 -33
- package/dist/cas.external.js +2 -2
- package/dist/cas.js +2 -2
- package/dist/chunks/calculate-DHvovDQK.js +2 -0
- package/dist/chunks/draw-Bw547gEd.js +2 -0
- package/dist/chunks/edit-BC9D1cIE.js +2 -0
- package/dist/chunks/edit-CCe3uoyk.js +2 -0
- package/dist/chunks/html-6HJlblNm.js +2 -0
- package/dist/chunks/html-DzjcaM8w.js +2 -0
- package/dist/chunks/lite-6yr4ed_k.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 +21 -9
- 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 +21 -9
- package/package.json +6 -6
- package/src/cas.d.ts +1 -1
- package/src/cas.js +71 -13
- package/src/draw.js +13 -9
- package/src/edit.js +11 -4
- package/src/glyphs.js +3 -2
- package/src/html.js +1 -1
- package/src/index.js +1 -1
- package/src/layout.js +117 -37
- package/src/lite.js +1 -1
- package/src/markdown.d.ts +1 -1
- package/src/markdown.js +139 -57
- package/src/mathzetta.js +2 -2
- package/src/select.js +7 -0
- package/src/types.d.ts +12 -10
- package/src/variables.js +44 -10
- package/src/view.js +69 -18
- package/dist/chunks/calculate-Cz87Lt0N.js +0 -2
- package/dist/chunks/draw-Bev17BJJ.js +0 -2
- package/dist/chunks/edit-C65xXzo8.js +0 -2
- package/dist/chunks/edit-M68aRA5o.js +0 -2
- package/dist/chunks/html-BimAqn7x.js +0 -2
- package/dist/chunks/html-CupluJSh.js +0 -2
- package/dist/chunks/lite-3Fb-OHbt.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;
|
|
@@ -35,6 +35,7 @@ render(div, 'x^2', { announce: true }); // read each new step to a screen re
|
|
|
35
35
|
view.announce('Step 2: expand'); // your own words, through the same region
|
|
36
36
|
view.segments(); // [{ text: 'x', id: 3 }, { text: 'squared', id: 5 }, …]
|
|
37
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
|
|
38
39
|
```
|
|
39
40
|
|
|
40
41
|
**Editing a part.** `view.editable({ toText })` (`import { toText } from 'mathzetta/text'`; in the
|
|
@@ -46,7 +47,7 @@ as text, the edited part's path and what was typed; `view.edit(target)` opens th
|
|
|
46
47
|
|
|
47
48
|
**Keyboard and screen readers.** Every drawing has an accessible name (`role="math"`, its spoken form for a listener
|
|
48
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
|
|
49
|
-
into a part, Up out, Left/Right between
|
|
50
|
+
into a part, Up out, Left/Right between neighbors, Home or Escape back to the whole), each part is spoken through a
|
|
50
51
|
polite live region and ringed, and Enter or Space calls the click listener for the current part (`event` is then the
|
|
51
52
|
KeyboardEvent). `view.focusPart(node)` moves there from code.
|
|
52
53
|
|
|
@@ -65,7 +66,7 @@ import '@mathzetta/inlinemath/fonts/fonts.css'; // optional: Latin Modern, th
|
|
|
65
66
|
|
|
66
67
|
### Lite: drawing only
|
|
67
68
|
|
|
68
|
-
`@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
|
|
69
70
|
spoken labels for screen readers, without the live view (`render`, step animation, events), Markdown
|
|
70
71
|
or the CAS — about a third smaller. `{{…}}` blocks are worked out only if MathZetta's calculator is
|
|
71
72
|
loaded too (`import 'mathzetta/calculate'`, or `@mathzetta/inlinemath/lite-calc`, which brings it); otherwise
|
|
@@ -94,14 +95,14 @@ npm test # 253 checks; every input in mathzetta/test/cases/calculus.tsv
|
|
|
94
95
|
| `src/layout.js` | Turns a tree into HTML. All notation choices live here. |
|
|
95
96
|
| `src/glyphs.js` | SVG paths for `( ) { } √ ∫ ∑ ∏`. Change a shape here. |
|
|
96
97
|
| `src/select.js` | Picks parts by id, expression, path or test. Also `numberTree`. |
|
|
97
|
-
| `src/view.js` | The live view: highlight,
|
|
98
|
+
| `src/view.js` | The live view: highlight, color, events, speech segments, step animation. |
|
|
98
99
|
| `src/html.js` | `toHTML`, `treeOf`, and the `colors` / `highlight` options. |
|
|
99
100
|
| `inlinemath.css` | All the styling. The numbers marked *metric* must match the constants in layout.js. |
|
|
100
101
|
|
|
101
|
-
## How it lays
|
|
102
|
+
## How it lays math out
|
|
102
103
|
|
|
103
104
|
- **Estimated, not measured.** Each piece knows roughly how far it reaches above and below the baseline, in em.
|
|
104
|
-
- 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.
|
|
105
106
|
- The same string comes out in Node, in a browser or in a video frame, with no layout pass after rendering.
|
|
106
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.
|
|
107
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.
|
|
@@ -121,7 +122,8 @@ These go to `toHTML(input, options)` and `render(el, input, options)`.
|
|
|
121
122
|
| `derivativeBrackets` | `'['` | `'('` for d/dx (x² + 1) |
|
|
122
123
|
| `scriptFractions` | `'slash'` | x^{3/2} written with a slash. `'stack'` stacks it. |
|
|
123
124
|
| `cases` | `true` | `c ? a : b` drawn as a piecewise brace |
|
|
124
|
-
|
|
|
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]]` |
|
|
125
127
|
| `highlight` | | target(s) that get the `mv-hl` class |
|
|
126
128
|
| `attributes`, `style` | | `(node) => ({…})` / `(node) => 'css'` for each node's element |
|
|
127
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 |
|
|
@@ -144,8 +146,8 @@ npm run build # dist/ (a few seconds)
|
|
|
144
146
|
|
|
145
147
|
- **`dist/`** — Inline Math with everything inside, no import map or `node_modules` needed:
|
|
146
148
|
- `inlinemath.js`, `markdown.js`, `cas.js` — ES modules (shared code in `dist/chunks/`);
|
|
147
|
-
- `inlinemath.global.min.js` (
|
|
148
|
-
- `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`);
|
|
149
151
|
- `inlinemath.css` and `fonts/` — put both on the page.
|
|
150
152
|
|
|
151
153
|
```html
|
|
@@ -183,32 +185,34 @@ page needs nothing else:
|
|
|
183
185
|
|
|
184
186
|
`@0.2` follows the latest 0.2.x; `@0.2.0` pins a release.
|
|
185
187
|
|
|
186
|
-
**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
|
|
187
189
|
gzipped): without it fractions, radicals and brackets don't line up. The classic builds
|
|
188
190
|
(`*.global.min.js`) carry it and add it to the page themselves (`<style id="inlinemath-css">`; a
|
|
189
191
|
`<link>` to `dist/inlinemath.css` is still fine, it is only added when absent); the ES modules
|
|
190
192
|
don't, so a page using them links `dist/inlinemath.css`. **The fonts are optional**: `fonts/fonts.css`
|
|
191
|
-
declares Latin Modern Roman (the TeX look) in two files, regular 45 KB and italic 47 KB (woff2),
|
|
192
|
-
|
|
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.
|
|
193
197
|
|
|
194
198
|
Every build comes **with MathZetta inside, or without it** (`*.external.*`), with or without the
|
|
195
199
|
CAS (MathZetta CAS). Sizes, gzipped:
|
|
196
200
|
|
|
197
201
|
| | ES module | classic `<script>` (`window.InlineMath`) |
|
|
198
202
|
|---|---|---|
|
|
199
|
-
| Lite (drawing only), MathZetta inside | `lite.js`
|
|
200
|
-
| Lite with the calculator (`{{…}}` worked out) | `lite-calc.js`
|
|
201
|
-
| Lite without MathZetta | `lite.external.js`
|
|
202
|
-
| Inline Math (+ Markdown in the classic build), MathZetta inside | `inlinemath.js`
|
|
203
|
-
| …without MathZetta | `inlinemath.external.js` **
|
|
204
|
-
| with the CAS, MathZetta inside | `cas.js`
|
|
205
|
-
| 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 |
|
|
206
210
|
|
|
207
211
|
Without MathZetta, the page loads it once itself: a classic page puts a MathZetta `<script>` first —
|
|
208
|
-
`mathzetta.min.js`, or the `maths-display`
|
|
212
|
+
`mathzetta.min.js`, or the `maths-display` flavor, since speech, text and calculate are used (for
|
|
209
213
|
lite, `display`, or `maths-display` to work out `{{…}}`) — and
|
|
210
214
|
the external classic build reads `window.MathZetta`; a module page maps the names with an import
|
|
211
|
-
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.
|
|
212
216
|
|
|
213
217
|
```html
|
|
214
218
|
<script type="importmap">
|
|
@@ -223,7 +227,7 @@ map (every name can point at the one MathZetta bundle). The fonts are 94 KB more
|
|
|
223
227
|
|
|
224
228
|
Publishing is `npm publish` (`prepublishOnly` runs the tests and the build).
|
|
225
229
|
|
|
226
|
-
## Markdown with
|
|
230
|
+
## Markdown with math: `@mathzetta/inlinemath/markdown`
|
|
227
231
|
|
|
228
232
|
```js
|
|
229
233
|
import { markdownToHTML } from '@mathzetta/inlinemath/markdown';
|
|
@@ -231,14 +235,14 @@ el.innerHTML = markdownToHTML(text); // needs inlinemat
|
|
|
231
235
|
el.innerHTML = markdownToHTML(text, { blocks: casBlocks() }); // {{solve(…)}}, {{diff(…)}} too
|
|
232
236
|
```
|
|
233
237
|
|
|
234
|
-
- **
|
|
238
|
+
- **Math:** `$…$` inline, `$$…$$` or a ` ```math ` fence on its own (centered), and
|
|
235
239
|
`\(…\)` / `\[…\]`. MathZetta reads it, so LaTeX, plain text (`$sqrt(x)/2$`) and
|
|
236
240
|
code all work.
|
|
237
|
-
- **Working out:** `{{…}}` inside
|
|
241
|
+
- **Working out:** `{{…}}` inside math is worked out (the calculator, or the CAS with
|
|
238
242
|
`blocks`). A definition like `$r = 3$` is remembered, exactly, for the `{{…}}` after it
|
|
239
243
|
(`define: false` turns that off; `scope: { r: 3 }` gives values).
|
|
240
244
|
- **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
|
|
245
|
+
without drawing anything. After that, A in any math is drawn as its expression and `{{A}}`
|
|
242
246
|
is its value, so `$A = {{A}}$` draws 2 + 2 = 4 and `$3A$` draws 3(2 + 2). A name is a letter
|
|
243
247
|
(Greek too), optionally with a subscript (`A_1`); a variable may use the ones before it
|
|
244
248
|
(`$_B := 2A$`), and saving it again replaces it from there on. A plain `$r = 3$` still only
|
|
@@ -262,18 +266,18 @@ el.innerHTML = markdownToHTML(text, { blocks: casBlocks() }); // {{solve(…)}},
|
|
|
262
266
|
- **Editing by double-click:** in `renderMarkdownInto`, a part drawn from a textbox variable is
|
|
263
267
|
edited where it is drawn with `{ editable: { toText } }` (the whole variable is written back
|
|
264
268
|
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
|
|
269
|
+
Double-clicking any other part fires `inlinemath:select` on the element with where that math
|
|
266
270
|
is in the Markdown (`detail.start`, `detail.end`, `detail.raw`; for a part drawn from a
|
|
267
271
|
variable saved in the same text, where it was saved), so an editor beside it can select it.
|
|
268
272
|
`extractMath` gives every piece's `start` and `end` too.
|
|
269
|
-
- **Dollars:** a `$` is
|
|
273
|
+
- **Dollars:** a `$` is math only when it looks like it (Pandoc's rule): "$5 and $10"
|
|
270
274
|
stays text, and `\$` is a dollar sign. Code spans and fences are left alone.
|
|
271
|
-
- **Bad
|
|
275
|
+
- **Bad math:** math that doesn't read is shown as written, marked, with the reason as
|
|
272
276
|
its tooltip.
|
|
273
277
|
- **The Markdown:** a small built-in renderer — headings, emphasis, links, images, lists,
|
|
274
278
|
quotes, code, tables, rules. Raw HTML is shown as text unless `html: true`, and
|
|
275
279
|
`javascript:` links are dropped. `render: (md) => html` uses another renderer
|
|
276
|
-
(marked, markdown-it); the
|
|
280
|
+
(marked, markdown-it); the math is taken out first and put back into its output.
|
|
277
281
|
- **Options:** `math` passes options to every drawing (`fnParens`, `colors` …);
|
|
278
282
|
`delimiters` picks which marks count.
|
|
279
283
|
- **Playground:** [inlinemath.com/markdown.html](https://inlinemath.com/markdown.html), an editor with a live preview.
|
|
@@ -281,14 +285,14 @@ el.innerHTML = markdownToHTML(text, { blocks: casBlocks() }); // {{solve(…)}},
|
|
|
281
285
|
## The CAS: `@mathzetta/inlinemath/cas`
|
|
282
286
|
|
|
283
287
|
MathZetta CAS (exact simplify, factor, solve, d/dx, ∫ …; @mathzetta/cas's docs/cas.md)
|
|
284
|
-
in drawn
|
|
288
|
+
in drawn math:
|
|
285
289
|
|
|
286
290
|
```js
|
|
287
291
|
import { toHTML } from '@mathzetta/inlinemath';
|
|
288
292
|
import { casBlocks, stepsHTML, mathCAS } from '@mathzetta/inlinemath/cas';
|
|
289
293
|
|
|
290
294
|
toHTML("f'(x) = {{diff(x^3 sin(x), x)}}", { blocks: casBlocks() })
|
|
291
|
-
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
|
|
292
296
|
el.innerHTML = stepsHTML(mathCAS().solve('sqrt(x + 1) = x - 1', 'x', { steps: 'brief' }).steps)
|
|
293
297
|
```
|
|
294
298
|
|
|
@@ -323,5 +327,5 @@ playground: any input, any operation, detail level, and a live rule editor).
|
|
|
323
327
|
## Known rough edges
|
|
324
328
|
|
|
325
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.
|
|
326
|
-
- **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.
|
|
327
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.
|