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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
//! KaTeX Rust implementation - Fast math typesetting for the web
//!
//! This is a Rust port of the KaTeX JavaScript library, providing
//! fast LaTeX math rendering capabilities.
extern crate alloc;
/// Utilities for working with parse trees and converting them to ParseNode
/// Core parsing logic for LaTeX mathematical expressions.
/// Shared web context for DOM operation
pub use crateClassList;
/// Global context for KaTeX operations, containing all registered functions,
/// HTML/MathML builders, symbols, environments, and macros. This context is
/// essential for parsing and rendering mathematical expressions and provides
/// the foundation for KaTeX's extensibility.
///
/// The context manages:
/// - Functions: All registered LaTeX commands and their parsing behavior
/// - Builders: HTML and MathML generation functions for different node types
/// - Symbols: Character mappings for mathematical symbols across different
/// modes
/// - Environments: Support for LaTeX environments like matrices and arrays
/// - Macros: User-defined and system macros for expression expansion
///
/// # Examples
///
/// ```rust
/// use katex::*;
///
/// let mut ctx = KatexContext::default();
/// // Context is now ready with default functions and symbols
/// ```
pub use crateKatexContext;
/// Parses and renders a LaTeX mathematical expression to an HTML string.
///
/// This function takes a LaTeX math expression and converts it into HTML markup
/// that can be displayed in web browsers. It handles the complete pipeline from
/// parsing to HTML generation, including symbol lookup, layout calculations,
/// and CSS styling.
///
/// # Parameters
///
/// * `ctx` - The [`KatexContext`] containing registered functions and symbols
/// * `expression` - The LaTeX mathematical expression to render
/// * `settings` - Rendering configuration controlling output format, strict
/// mode, custom macros, and other behaviour
///
/// # Returns
///
/// Returns `Result<String, ParseError>` where:
/// - `Ok(html_string)` contains the rendered HTML markup
/// - `Err(error)` contains detailed parsing or rendering error information
///
/// # Examples
///
/// Basic usage:
/// ```rust
/// use katex::{KatexContext, Settings, render_to_string};
///
/// fn main() -> Result<(), katex::ParseError> {
/// let ctx = KatexContext::default();
/// let settings = Settings::default();
///
/// let html = render_to_string(&ctx, r"x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}", &settings)?;
/// println!("{html}");
/// Ok(())
/// }
/// ```
///
/// With custom settings:
/// ```rust
/// use katex::{KatexContext, Settings, render_to_string};
///
/// let ctx = KatexContext::default();
/// let mut settings = Settings::default();
/// settings.display_mode = true; // Render in display/block mode
///
/// let html = render_to_string(&ctx, r"\sum_{i=1}^{n} x_i", &settings).unwrap();
/// println!("{html}");
/// ```
///
/// Here's an example that triggers an error:
///
/// The function provides detailed error messages with position information:
/// ```rust
/// use katex::{KatexContext, Settings, render_to_string};
///
/// let ctx = KatexContext::default();
/// let settings = Settings::default();
///
/// match render_to_string(&ctx, r"\frac{a}{", &settings) {
/// Ok(_) => println!("Success"),
/// Err(e) => println!("Error at position {}: {}", e.position().unwrap_or(0), e),
/// }
/// ```
///
/// # Performance
///
/// For optimal performance in high-throughput applications, consider reusing
/// [`Settings`] objects rather than creating new ones for each render call.
pub use craterender_to_string;
/// Parse an expression and return the parse tree
///
/// This function parses a LaTeX expression and returns the raw parse tree,
/// equivalent to the `__parse` function in the JavaScript KaTeX API.
///
/// NOTE: This method is not currently recommended for public use.
/// The internal tree representation is unstable and is very likely
/// to change. Use at your own risk.
///
/// # Parameters
/// * `ctx` - The KaTeX context
/// * `expression` - The LaTeX expression to parse
/// * `settings` - Optional settings for parsing
///
/// # Returns
/// A `Result` containing the parse tree as a vector of `AnyParseNode`s or a
/// `ParseError`
pub use crateparse;
/// Render an expression to a DOM tree
///
/// This function parses and builds a LaTeX expression, returning the DOM tree
/// representation, equivalent to the `__renderToDomTree` function in the
/// JavaScript KaTeX API.
///
/// NOTE: This method is not currently recommended for public use.
/// The internal tree representation is unstable and is very likely
/// to change. Use at your own risk.
///
/// # Parameters
/// * `ctx` - The KaTeX context
/// * `expression` - The LaTeX expression to render
/// * `settings` - Optional settings for rendering
///
/// # Returns
/// A `Result` containing the DOM tree or a `ParseError`
pub use craterender_to_dom_tree;
/// Render an expression to an HTML-only DOM tree
///
/// This function parses and builds a LaTeX expression, returning the HTML-only
/// DOM tree representation, equivalent to the `__renderToHTMLTree` function in
/// the JavaScript KaTeX API.
///
/// NOTE: This method is not currently recommended for public use.
/// The internal tree representation is unstable and is very likely
/// to change. Use at your own risk.
///
/// # Parameters
/// * `ctx` - The KaTeX context
/// * `expression` - The LaTeX expression to render
/// * `settings` - Optional settings for rendering
///
/// # Returns
/// A `Result` containing the HTML DOM tree or a `ParseError`
pub use craterender_to_html_tree;
/// Retrieves character metrics for a specific character in a given font family
/// and mode.
///
/// This function provides access to detailed font metrics used in mathematical
/// typesetting, including character dimensions, spacing, and positioning
/// information. The metrics are essential for proper alignment and spacing in
/// mathematical expressions.
///
/// # Parameters
///
/// * `ctx` - Shared [`KatexContext`] containing font metric tables
/// * `character` - The character or symbol to look up
/// * `font` - The font family name (e.g., "Main-Regular", "AMS-Regular",
/// "Caligraphic-Regular")
/// * `mode` - The mathematical mode (Mode::Math or Mode::Text) affecting metric
/// selection
///
/// # Returns
///
/// Returns `Result<Option<&CharacterMetrics>, ParseError>`.
/// - `Ok(Some(metrics))` contains the character dimensions
/// - `Ok(None)` indicates that no metrics are available for the requested
/// character/font combination
/// - `Err(error)` indicates that the font family itself was unknown
///
/// # Examples
///
/// ```rust
/// use katex::types::Mode;
/// use katex::{KatexContext, ParseError, get_character_metrics};
///
/// fn main() -> Result<(), ParseError> {
/// let ctx = KatexContext::default();
///
/// if let Some(m) = get_character_metrics(&ctx, 'A', "Main-Regular", Mode::Math)? {
/// println!("Character width: {}", m.width);
/// println!("Character height: {}", m.height);
/// }
///
/// Ok(())
/// }
/// ```
///
/// # Font Families
///
/// Supported font families include:
/// - `Main-Regular`: Primary mathematical symbols and Latin letters
/// - `AMS-Regular`: Additional mathematical symbols from AMS
/// - `Caligraphic-Regular`: Calligraphic/script style letters
/// - `Fraktur-Regular`: Fraktur/Gothic style letters
/// - `SansSerif-Regular`: Sans-serif mathematical symbols
/// - And many others for specialized mathematical notation
///
/// # Notes
///
/// Character metrics are pre-computed from TeX font files and stored at compile
/// time. For characters not directly available, the function may use fallback
/// approximations or character mappings to provide reasonable spacing
/// estimates.
pub use crateget_character_metrics;
/// Font metrics structure containing TeX font parameters for mathematical
/// typesetting.
///
/// This struct encapsulates the complete set of font metrics derived from TeX's
/// font parameters, providing all the spacing, sizing, and positioning
/// information needed for high-quality mathematical rendering. The metrics are
/// organized by font size index and include both general layout parameters and
/// size-specific measurements.
///
/// # Fields
///
/// * `css_em_per_mu` - Conversion factor from CSS em units to mathematical mu
/// units
/// * `metrics` - KeyMap containing named metric values indexed by parameter
/// name
///
/// # Available Metrics
///
/// The metrics include TeX parameters such as:
/// - **Spacing**: `slant`, `space`, `stretch`, `shrink`, `extraSpace`
/// - **Sizing**: `xHeight`, `quad`, `ptPerEm`
/// - **Superscripts**: `sup1`, `sup2`, `sup3`, `supDrop`
/// - **Subscripts**: `sub1`, `sub2`, `subDrop`
/// - **Fractions**: `num1`, `num2`, `num3`, `denom1`, `denom2`
/// - **Delimiters**: `delim1`, `delim2`
/// - **Rules**: `axisHeight`, `defaultRuleThickness`, `sqrtRuleThickness`
/// - **Operators**: `bigOpSpacing1` through `bigOpSpacing5`
///
/// # Size Indices
///
/// Font metrics are available for three size indices:
/// - Index 0: Text style (normal size, >= 9pt)
/// - Index 1: Script style (medium size, 7-8pt)
/// - Index 2: Scriptscript style (small size, 5-6pt)
///
/// Use `get_global_metrics()` to obtain the appropriate metrics for a given
/// font size.
pub use crateCharacterMetrics;
/// Font metrics data structure providing access to character-specific
/// measurements.
///
/// This struct serves as the main interface for accessing pre-computed font
/// metrics for individual characters across different font families. The
/// metrics are generated at compile time from KaTeX's data files and stored in
/// perfect hash tables for efficient lookup during rendering.
///
/// # Examples
///
/// ```rust
/// use katex::{FontMetricsData, ParseError};
///
/// fn main() -> Result<(), ParseError> {
/// let data = FontMetricsData::default();
///
/// if let Some(metrics) = data.get_metric("Main-Regular", 'A' as u32)? {
/// println!("Width: {}", metrics.width);
/// }
///
/// Ok(())
/// }
/// ```
pub use crateFontMetricsData;
/// Error type for parsing and rendering failures in KaTeX expressions.
///
/// This struct represents errors that occur during the parsing or rendering of
/// LaTeX mathematical expressions. It provides detailed context about what went
/// wrong, including the error message, position in the source string, and
/// surrounding context for debugging.
///
/// `ParseError` implements the standard `Error` and `Display` traits, making
/// it compatible with Rust's error handling ecosystem.
///
/// # Examples
///
/// ```rust
/// use katex::{KatexContext, ParseError, Settings, render_to_string};
///
/// fn try_render() -> Result<(), ParseError> {
/// let ctx = KatexContext::default();
/// let settings = Settings::default();
///
/// render_to_string(&ctx, r"\frac{a}{", &settings)?;
/// Ok(())
/// }
///
/// fn main() {
/// if let Err(err) = try_render() {
/// println!("Parse error: {}", err);
/// if let Some(pos) = err.position() {
/// println!("Error at position: {pos}");
/// }
/// println!("Error kind: {:?}", err.kind);
/// }
/// }
/// ```
///
/// # Error Context
///
/// When created with location information (via [`ParseError::with_token`]),
/// the error message includes:
/// - The position in the source string (1-indexed)
/// - The high-level error category via [`ParseError::kind`]
/// - Surrounding context with the problematic text underlined
///
/// # Integration
///
/// `ParseError` integrates seamlessly with the `?` operator and standard
/// error handling patterns.
pub use crateParseError;
pub use crateOutputFormat;
/// Main configuration structure for KaTeX rendering behavior.
///
/// This struct contains all the settings that control how mathematical
/// expressions are parsed and rendered. It provides comprehensive control over
/// display modes, error handling, font options, macro definitions, and other
/// rendering parameters.
///
/// [`Settings`] exposes the same configuration knobs as the JavaScript KaTeX
/// API, including display mode, output format, strict-mode validation, trust
/// callbacks, and custom macro definitions. All fields are public, so they can
/// be adjusted directly or via the generated builder (`Settings::builder()`).
///
/// # Examples
///
/// ```rust
/// use katex::Settings;
///
/// let mut settings = Settings::default();
/// settings.display_mode = true;
/// settings.throw_on_error = false;
/// ```
///
/// Using the builder for ergonomic construction:
/// ```rust
/// use katex::Settings;
///
/// let settings = Settings::builder()
/// .display_mode(true)
/// .throw_on_error(false)
/// .build();
/// assert!(settings.display_mode);
/// assert!(!settings.throw_on_error);
/// ```
///
/// # Default Values
///
/// - `display_mode`: `false` (inline mode)
/// - `output`: [`OutputFormat::HtmlAndMathml`]
/// - `throw_on_error`: `true`
/// - `error_color`: `"#cc0000"` (red)
/// - `max_size`: `f64::INFINITY`
/// - `max_expand`: `1000`
/// - Other fields have appropriate defaults
///
/// # Performance Considerations
///
/// For high-performance applications, create [`Settings`] objects once and
/// reuse them rather than creating new ones for each render operation.
pub use crateSettings;
/// Strictness and trust configuration types used by [`Settings`].
///
/// These enums and callback types mirror KaTeX's JavaScript configuration and
/// control validation of potentially unsafe commands (`trust`) as well as how
/// strictly to enforce LaTeX syntax (`strict`).
pub use crate;
// Build utilities for advanced users creating custom DOM structures
/// Creates a line span with the given className, options, and thickness.
/// See [`build_common::make_line_span`] for detailed documentation.
pub use cratemake_line_span;
/// Creates an anchor element with the given href, classes, children, and
/// options. See [`build_common::make_anchor`] for detailed documentation.
pub use cratemake_anchor;
/// Creates a document fragment with the given list of children.
/// See [`build_common::make_fragment`] for detailed documentation.
pub use cratemake_fragment;
/// Wraps a group in a span if it's a document fragment.
/// See [`build_common::wrap_fragment`] for detailed documentation.
pub use cratewrap_fragment;
/// Current version of the KaTeX Rust implementation
pub const VERSION: &str = env!;