@dskripchenko/math 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +75 -2
- package/dist/index.cjs +1875 -0
- package/dist/index.d.ts +149 -0
- package/dist/index.mjs +1868 -0
- package/package.json +70 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/** Whether a formula can be read: null when it can, the error (with its place) when not. */
|
|
2
|
+
export declare function checkMath(tex: string, options?: ParseOptions): MathError | null;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Letter styles (`\mathbf`, `\mathbb`, `\mathcal`…) as the characters
|
|
6
|
+
* Unicode has for them: MathML Core has no `mathvariant` beyond `normal`, and
|
|
7
|
+
* the Mathematical Alphanumeric Symbols draw the same in any math font.
|
|
8
|
+
*/
|
|
9
|
+
export declare type Font = 'normal' | 'bold' | 'italic' | 'bold-italic' | 'double-struck' | 'script' | 'bold-script' | 'fraktur' | 'bold-fraktur' | 'sans-serif' | 'bold-sans-serif' | 'sans-serif-italic' | 'monospace';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The page's part: a math font for the formulas (only a font with an OpenType
|
|
13
|
+
* MATH table lets fences, roots and big operators stretch — STIX Two Math on
|
|
14
|
+
* macOS, Cambria Math on Windows; elsewhere one the page provides), a displayed
|
|
15
|
+
* formula's margins, and the look of TeX that could not be read.
|
|
16
|
+
*/
|
|
17
|
+
export declare const MATH_CSS = "math.dsk-math{font-family:\"STIX Two Math\",\"Cambria Math\",\"Latin Modern Math\",\"Noto Sans Math\",math}\nmath.dsk-math[display=\"block\"]{margin:.75em 0}\n.dsk-math-error{color:#d1242f;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;border-bottom:1px dotted}";
|
|
18
|
+
|
|
19
|
+
export declare class MathError extends Error {
|
|
20
|
+
/** Where in the TeX it went wrong (a character offset). */
|
|
21
|
+
readonly position: number;
|
|
22
|
+
constructor(message: string,
|
|
23
|
+
/** Where in the TeX it went wrong (a character offset). */
|
|
24
|
+
position: number);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export declare type MathNode =
|
|
28
|
+
/** An identifier: a letter, a name; `upright` for a name set as text (`sin`, `\mathrm{d}`). */
|
|
29
|
+
{
|
|
30
|
+
type: 'ident';
|
|
31
|
+
text: string;
|
|
32
|
+
upright?: boolean;
|
|
33
|
+
} | {
|
|
34
|
+
type: 'number';
|
|
35
|
+
text: string;
|
|
36
|
+
} | {
|
|
37
|
+
type: 'op';
|
|
38
|
+
text: string;
|
|
39
|
+
kind: OpKind;
|
|
40
|
+
/** Stretches to its content (a fence), or to a fixed height in em (`\big`). */
|
|
41
|
+
stretchy?: boolean;
|
|
42
|
+
size?: number;
|
|
43
|
+
/** A big operator's limits go under and over when the formula is displayed. */
|
|
44
|
+
movableLimits?: boolean;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'text';
|
|
47
|
+
text: string;
|
|
48
|
+
} | {
|
|
49
|
+
type: 'space';
|
|
50
|
+
width: number;
|
|
51
|
+
} | {
|
|
52
|
+
type: 'row';
|
|
53
|
+
children: MathNode[];
|
|
54
|
+
}
|
|
55
|
+
/** Scripts beside the base (`x_1^2`), or under and over it (`\sum_{i}^{n}` displayed, `\overset`). */
|
|
56
|
+
| {
|
|
57
|
+
type: 'scripts';
|
|
58
|
+
base: MathNode;
|
|
59
|
+
sub?: MathNode;
|
|
60
|
+
sup?: MathNode;
|
|
61
|
+
over?: boolean;
|
|
62
|
+
}
|
|
63
|
+
/** A fraction; `thickness: 0` for a binomial's stack, `style` for `\dfrac` and `\tfrac`. */
|
|
64
|
+
| {
|
|
65
|
+
type: 'frac';
|
|
66
|
+
num: MathNode;
|
|
67
|
+
den: MathNode;
|
|
68
|
+
thickness?: 0;
|
|
69
|
+
style?: 'display' | 'text';
|
|
70
|
+
} | {
|
|
71
|
+
type: 'sqrt';
|
|
72
|
+
body: MathNode;
|
|
73
|
+
index?: MathNode;
|
|
74
|
+
}
|
|
75
|
+
/** Content between stretching fences (`\left( … \right)`), with the `\middle` ones inside. */
|
|
76
|
+
| {
|
|
77
|
+
type: 'fenced';
|
|
78
|
+
open: string;
|
|
79
|
+
close: string;
|
|
80
|
+
body: MathNode;
|
|
81
|
+
}
|
|
82
|
+
/** A mark over or under the base: a hat, a bar, a brace. */
|
|
83
|
+
| {
|
|
84
|
+
type: 'accent';
|
|
85
|
+
base: MathNode;
|
|
86
|
+
mark: string;
|
|
87
|
+
under?: boolean;
|
|
88
|
+
stretchy?: boolean;
|
|
89
|
+
}
|
|
90
|
+
/** Rows and cells: a matrix, cases, aligned equations, an array. */
|
|
91
|
+
| {
|
|
92
|
+
type: 'table';
|
|
93
|
+
rows: MathNode[][];
|
|
94
|
+
/** Each column's alignment; the last repeats. */
|
|
95
|
+
align: ('l' | 'c' | 'r')[];
|
|
96
|
+
/** Lines between columns (`array{c|c}`). */
|
|
97
|
+
lines?: ('none' | 'solid')[];
|
|
98
|
+
/** Aligned equations: columns paired right-left, no space between a pair. */
|
|
99
|
+
aligned?: boolean;
|
|
100
|
+
/** A matrix's or cases' own fences. */
|
|
101
|
+
open?: string;
|
|
102
|
+
close?: string;
|
|
103
|
+
small?: boolean;
|
|
104
|
+
} | {
|
|
105
|
+
type: 'style';
|
|
106
|
+
body: MathNode;
|
|
107
|
+
display?: boolean;
|
|
108
|
+
scriptLevel?: number;
|
|
109
|
+
color?: string;
|
|
110
|
+
} | {
|
|
111
|
+
type: 'phantom';
|
|
112
|
+
body: MathNode;
|
|
113
|
+
} | {
|
|
114
|
+
type: 'boxed';
|
|
115
|
+
body: MathNode;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export declare interface MathOptions extends ParseOptions {
|
|
119
|
+
/** A formula on its own line (`$$…$$`): big operators take limits under and over, fractions are full size. */
|
|
120
|
+
display?: boolean;
|
|
121
|
+
/** Throw a `MathError` for TeX that cannot be read, rather than show the TeX marked as an error. */
|
|
122
|
+
throwOnError?: boolean;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** How an operator sits: a binary operation, a relation, a fence, punctuation, a big operator. */
|
|
126
|
+
export declare type OpKind = 'bin' | 'rel' | 'open' | 'close' | 'punct' | 'large' | 'ord' | 'prefix';
|
|
127
|
+
|
|
128
|
+
/** The formula as a tree. Throws `MathError` for TeX it cannot read. */
|
|
129
|
+
export declare function parseMath(tex: string, options?: ParseOptions): MathNode;
|
|
130
|
+
|
|
131
|
+
declare interface ParseOptions {
|
|
132
|
+
/** Commands of the writer's own: `{ R: '\\mathbb{R}', norm: '\\left\\|#1\\right\\|' }`; `#1`…`#9` are arguments. */
|
|
133
|
+
macros?: Record<string, string>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The formula as a `<math>` element: MathML Core, its TeX kept in an
|
|
138
|
+
* annotation (copied with it, read back by `texOf`). TeX it cannot read comes
|
|
139
|
+
* out as a `<span class="dsk-math-error">` with the TeX and the reason in its
|
|
140
|
+
* title — or throws, with `throwOnError`.
|
|
141
|
+
*/
|
|
142
|
+
export declare function renderMath(tex: string, options?: MathOptions): string;
|
|
143
|
+
|
|
144
|
+
/** The TeX a drawn formula was made from (its annotation, or an error's text); null for anything else. */
|
|
145
|
+
export declare function texOf(element: Element): string | null;
|
|
146
|
+
|
|
147
|
+
export declare function toMathML(node: MathNode): string;
|
|
148
|
+
|
|
149
|
+
export { }
|