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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
//! Spacing data constants for KaTeX Rust implementation
//!
//! This module provides precomputed spacing data for mathematical typesetting
//! and layout. It contains spacing relationships between different classes of
//! atoms.
use ;
/// Measurement structure representing a size with number and unit in
/// mathematical typesetting.
///
/// This struct is used to represent dimensions in KaTeX's layout system,
/// equivalent to the JavaScript Measurement type from units.js. It supports
/// various units commonly used in TeX and LaTeX typesetting, particularly for
/// spacing and sizing in mathematical expressions.
///
/// # Units
/// - `"mu"`: Math unit, 1/18 of an em in the current math style
/// - `"em"`: Relative to the current font size
/// - `"ex"`: Relative to the height of the letter 'x'
/// - `"pt"`: Points (absolute unit)
/// - `"px"`: Pixels (for screen rendering)
///
/// # See Also
/// - [LaTeX spacing commands](https://www.overleaf.com/learn/latex/Spacing_in_math_mode)
/// - [`THINSPACE`], [`MEDIUMSPACE`], [`THICKSPACE`] for standard spacing
/// constants
/// Type alias for measurements with owned string units.
///
/// This is useful when creating measurements dynamically or when the unit
/// string needs to be computed at runtime. The owned string allows for
/// flexibility in unit specification but has higher memory overhead compared to
/// static strings.
pub type MeasurementOwned = ;
/// Type alias for measurements with static string slice units.
///
/// This is the preferred type for compile-time constant measurements, as it
/// avoids heap allocation and provides better performance. Most spacing
/// constants in this module use this type.
pub type MeasurementStatic = ;
/// Thin space measurement (3 mu) - corresponds to \, in LaTeX.
///
/// In mathematical typesetting, thin space is used for subtle separation
/// between elements. In LaTeX, this is equivalent to the `\,` command, which
/// inserts a space of 3/18 em (or 1/6 em).
///
/// # LaTeX Equivalent
/// ```latex
/// a\,b % thin space between a and b
/// ```
///
/// # Usage
/// Used in spacing tables for relationships between ordinary atoms and
/// operators, punctuation, and inner atoms.
pub const THINSPACE: MeasurementStatic = MeasurementStatic ;
/// Medium space measurement (4 mu) - corresponds to \: in LaTeX.
///
/// Medium space provides moderate separation in mathematical expressions. In
/// LaTeX, this is equivalent to the `\:` command, which inserts a space of 4/18
/// em.
///
/// # LaTeX Equivalent
/// ```latex
/// a\:b % medium space between a and b
/// ```
///
/// # Usage
/// Used for spacing around binary operators and between certain atom classes
/// in display and text styles.
pub const MEDIUMSPACE: MeasurementStatic = MeasurementStatic ;
/// Thick space measurement (5 mu) - corresponds to \; in LaTeX.
///
/// Thick space provides significant separation in mathematical expressions. In
/// LaTeX, this is equivalent to the `\;` command, which inserts a space of 5/18
/// em.
///
/// # LaTeX Equivalent
/// ```latex
/// a\;b % thick space between a and b
/// ```
///
/// # Usage
/// Used for spacing around relation symbols and between certain atom classes
/// where more pronounced separation is needed.
pub const THICKSPACE: MeasurementStatic = MeasurementStatic ;
/// Atom class types for spacing relationships in mathematical typesetting.
///
/// In TeX and LaTeX, mathematical atoms are classified into different types
/// that determine how much space should be inserted between them. This enum
/// represents the standard atom classes used in KaTeX for spacing calculations.
///
/// The spacing between atoms depends on their classes according to predefined
/// rules in [`SPACINGS`] and [`TIGHT_SPACINGS`]. These rules follow traditional
/// TeX spacing conventions to ensure proper visual appearance of mathematical
/// expressions.
///
/// # Atom Classes
/// - `Mord`: Ordinary symbols (letters, numbers, ordinary operators like +)
/// - `Mop`: Large operators (∑, ∏, ∫, etc.)
/// - `Mbin`: Binary operators (+, -, ×, etc.)
/// - `Mrel`: Relations (=, <, >, ⊂, etc.)
/// - `Mopen`: Opening delimiters ((, [, {, etc.)
/// - `Mclose`: Closing delimiters ), ], }, etc.)
/// - `Mpunct`: Punctuation (,, ;, !, etc.)
/// - `Minner`: Inner expressions (fractions, etc.)
///
/// # See Also
/// - [`SPACINGS`] for display/text style spacing rules
/// - [`TIGHT_SPACINGS`] for script style spacing rules
/// - [TeXbook Chapter 18](https://www.ctan.org/pkg/texbook) for detailed
/// spacing rules
/// Type alias for spacing relationships between atom classes.
///
/// This type represents a nested map structure that defines the spacing rules
/// between different pairs of atom classes. The outer map keys are the left
/// atom classes, and the inner map keys are the right atom classes. The values
/// are the [`MeasurementStatic`] spacing to insert between them.
///
/// # Structure
/// ```text
/// Spacings = Map<LeftAtomClass, Map<RightAtomClass, Spacing>>
/// ```
///
/// # See Also
/// - [`SPACINGS`] for display/text style spacing table
/// - [`TIGHT_SPACINGS`] for script style spacing table
/// - [`AtomClass`] for the atom classification system
pub type Spacings = ;
/// Spacing relationships for display and text styles in mathematical
/// typesetting.
///
/// This constant defines the standard spacing rules between different atom
/// classes in display and text styles (normal-sized math). The spacing values
/// follow traditional TeX conventions and are measured in math units ("mu").
///
/// In LaTeX, these spacings correspond to the automatic spacing inserted
/// between mathematical elements based on their semantic classes. For example:
/// - No space between ordinary symbols: `ab`
/// - Thin space around operators: `a + b` (but actually handled by atom
/// classes)
/// - Medium space around binary operators: `a = b + c`
/// - Thick space around relations: `a < b`
///
/// # Spacing Rules Summary
/// | Left \ Right | Mord | Mop | Mbin | Mrel | Mopen | Mclose | Mpunct | Minner |
/// |--------------|------|------|------|------|-------|--------|--------|--------|
/// | Mord | - | thin | med | thick| - | - | thin | thin |
/// | Mop | thin | thin | - | thick| - | - | - | thin |
/// | Mbin | med | med | - | - | med | - | - | med |
/// | Mrel | thick| thick| - | - | thick | - | - | thick |
/// | Mopen | - | - | - | - | - | - | - | - |
/// | Mclose | - | thin | med | thick| - | - | - | thin |
/// | Mpunct | thin | thin | - | thick| thin | thin | thin | thin |
/// | Minner | thin | thin | med | thick| thin | - | thin | thin |
///
/// # Examples
/// ```
/// use katex::spacing_data::{MEDIUMSPACE, SPACINGS, THICKSPACE, THINSPACE};
///
/// // Spacing between ordinary atom and operator
/// let mord_mop = SPACINGS.get("mord").unwrap().get("mop");
/// assert_eq!(mord_mop, Some(&THINSPACE));
///
/// // Spacing between binary operator and ordinary atom
/// let mbin_mord = SPACINGS.get("mbin").unwrap().get("mord");
/// assert_eq!(mbin_mord, Some(&MEDIUMSPACE));
/// ```
///
/// # See Also
/// - [`TIGHT_SPACINGS`] for script and scriptscript styles
/// - [`AtomClass`] for atom classification details
/// - [TeX spacing rules](https://www.tug.org/TUGboat/tb30-1/tb94vieth.pdf)
pub const SPACINGS: Spacings = phf_map! ;
/// Spacing relationships for script and scriptscript styles in mathematical
/// typesetting.
///
/// This constant defines the reduced spacing rules used in superscript,
/// subscript, and nested script contexts. In these smaller styles, spacing is
/// generally tighter to maintain readability while conserving space.
///
/// In LaTeX, script styles (script and scriptscript) use condensed spacing to
/// prevent expressions from becoming too spread out when rendered in smaller
/// sizes. Most spacing relationships are omitted, leaving only essential
/// separations.
///
/// # Key Differences from Display Style
/// - Binary operators and relations get no spacing in script styles
/// - Only thin spaces around operators and some delimiters remain
/// - Most other combinations have zero spacing
///
/// # See Also
/// - [`SPACINGS`] for display and text style spacing
/// - [`AtomClass`] for atom classification
/// - LaTeX's `\scriptstyle` and `\scriptscriptstyle` commands
pub const TIGHT_SPACINGS: Spacings = phf_map! ;