katex-parser

    A port of the KaTeX parser: lexing and parsing LaTeX math expressions with macro expansion into a typed AST, plus a Unicode rendering backend

    katex
    latex
    math
    parser
    tex
    Download zip
    Author
    Version
    0.5.1
    License
    AGPL-3.0
    Last updated
    yesterday
    Downloads
    115

    #KaTeX Parser

    A port of the KaTeX parser, lexing LaTeX math expressions into a typed AST with macro expansion support.

    #Builtin command completions

    builtin_commands() returns a fresh Array[CommandInfo], sorted by command name. builtin_commands_json() exports the same catalogue as a JSON array. Import kokic/katex-parser as @katex in a consumer package:

    ///|
    let commands = @katex.builtin_commands()

    ///|
    let json = @katex.builtin_commands_json().stringify()

    Write json to a file in your build process, or return it from a JavaScript binding. The catalogue includes public symbols, functions, builtin macros, implicit commands and supported starred forms. It excludes internal helpers and bare Unicode aliases. Exporting never executes a macro or a function handler.

    Each entry has these fields:

    FieldMeaning
    nameCommand spelling, including the leading backslash and any star.
    kindSymbolCommand, FunctionCommand, MacroCommand, or ImplicitCommand.
    syntaxA CommandSyntax constructor name, such as RegularCommand, InfixCommand or DelimiterCommand.
    argsExplicit arguments in input order, each with optional and, when known, arg_type.
    modesKnown allowed modes (Math/Text); omitted for macros whose restrictions are not declared.
    unicode, groupRegistered symbol replacement/category; omitted when unavailable. Math metadata is preferred when a symbol has both modes.
    templatesInsertion templates with CodeMirror-compatible ${field} placeholders.

    The metadata types use derive(ToJson) directly. JSON keys match the MoonBit fields and enum values retain their constructor names. Optional struct fields are omitted for None; Some(value) serializes as value.

    Argument types are ColorArg, SizeArg, UrlArg, RawArg, OriginalArg, HboxArg, PrimitiveArg, MathArg and TextArg. A macro without a declared type omits arg_type. OriginalArg preserves the current parsing mode. For functions with optional arguments, the optional positions precede the required ones; special syntax can interleave them.

    Only RegularCommand commands can be completed by simply appending bracketed arguments. Other commands may consume tokens, delimiters, infix operands or the rest of a group. Their templates describe usable editing forms. For example, \color has one explicit color argument but its template also provides a scoped body. \begin templates include matching \end commands and the environment's arguments, including alignment for starred matrices.

    Example JSON entry:

    { "name": "\\sqrt", "kind": "FunctionCommand", "syntax": "RegularCommand", "args": [ { "arg_type": "OriginalArg", "optional": true }, { "arg_type": "OriginalArg", "optional": false } ], "modes": ["Math"], "templates": ["\\sqrt{${arg2}}", "\\sqrt[${arg1}]{${arg2}}"] }

    For regular commands, the first template omits optional arguments and a second includes them. Field names are placeholders to replace, not guaranteed valid default values: a size argument needs a measurement such as 1pt. Templates already escape literal TeX \{ and \} for CodeMirror; do not escape them a second time.

    #CodeMirror 6

    Generate the options once from the JSON catalogue:

    import { snippetCompletion } from "@codemirror/autocomplete"; const options = commands.flatMap(command => command.templates.map(template => snippetCompletion(template, { label: command.name, displayLabel: template .replace(/\$\{[^}]*\}/g, "") .replace(/\\([{}])/g, "$1") .split("\n")[0], type: "keyword", detail: command.unicode ?? command.syntax, })) ); function supplyKaTeXCompletions(context) { const token = context.matchBefore(/\\(?:[A-Za-z]*\*?|[^A-Za-z\s])/); if (!token) return null; return { from: token.from, options }; }

    Pass this source to autocompletion({ override: [supplyKaTeXCompletions] }). Parameter fields support Tab navigation. For another editor, adapt args and syntax, or translate the template placeholder and escaping convention.

    The catalogue describes default builtins. User-defined macros, extension specs, settings such as color_is_text_color, and context checks such as display mode, trusted commands, or being inside an array remain the consumer's responsibility. It is a completion vocabulary, not a promise that every command parses at every cursor position.

    EnvironmentHandler

    type EnvironmentHandler = (EnvironmentContext, Array[ParseNode], Array[ParseNode?]) -> ParseNode raise ParseFailure

    FunctionHandler

    type FunctionHandler = (FunctionContext, Array[ParseNode], Array[ParseNode?]) -> ParseNode raise ParseFailure

    StrictHandler

    type StrictHandler = (String, String, SourceLocation?) -> StrictResponse raise ParseFailure

    StrictWarningHandler

    type StrictWarningHandler = (String) -> Unit

    TrustHandler

    type TrustHandler = (TrustContext) -> Bool

    ParseFailure

    pub(all) suberror ParseFailure {
    UnexpectedCharacter(message~ : String, loc~ : SourceLocation?)
    ExpectedToken(expected~ : String, actual~ : Diagnostic)
    UndefinedControlSequence(name~ : String, loc~ : SourceLocation?)
    InvalidArgument(message~ : String, loc~ : SourceLocation?)
    DoubleSuperscript(loc~ : SourceLocation?)
    DoubleSubscript(loc~ : SourceLocation?)
    ExpectedGroupAfter(symbol~ : String, loc~ : SourceLocation?)
    FunctionNotAllowed(func_name~ : String, context~ : String, loc~ : SourceLocation?)
    MissingFunctionHandler(func_name~ : String, loc~ : SourceLocation?)
    TooManyExpansions(limit~ : Int)
    InternalInvariant(message~ : String)
    } derive(Eq, ToJson,
    Debug
    )

    ParseFailure::equal

    ParseFailure::not_equal

    fn ParseFailure::not_equal(x : ParseFailure, y : ParseFailure) -> Bool

    ParseFailure::to_json

    ArgType

    pub(all) enum ArgType {
    ColorArg
    SizeArg
    UrlArg
    RawArg
    OriginalArg
    HboxArg
    PrimitiveArg
    MathArg
    TextArg
    } derive(ToJson)

    ArgType::to_json

    fn ArgType::to_json(ArgType) -> Json

    ArrayColumn

    pub(all) enum ArrayColumn {
    AlignColumn(alignment~ : String, pre_gap~ : Double, post_gap~ : Double)
    SeparatorColumn(separator~ : String)
    } derive(Eq, ToJson,
    Debug
    )

    ArrayColumn::equal

    fn ArrayColumn::equal(ArrayColumn, ArrayColumn) -> Bool

    ArrayColumn::not_equal

    fn ArrayColumn::not_equal(x : ArrayColumn, y : ArrayColumn) -> Bool

    ArrayColumn::to_json

    fn ArrayColumn::to_json(ArrayColumn) -> Json

    ArrayEnvironmentOptions

    pub(all) struct ArrayEnvironmentOptions {
    columns : Array[ArrayColumn]?
    array_stretch : Double
    hskip_before_and_after : Bool
    cell_style : StyleLevel
    max_columns : Int?
    single_row : Bool
    auto_tag : Bool?
    leqno : Bool
    add_jot : Bool
    column_separation_type : ColumnSeparationType?
    }

    AtomFamily

    pub(all) enum AtomFamily {
    Mord
    Mop
    Mbin
    Mrel
    Mopen
    Mclose
    Mpunct
    Minner
    } derive(Eq, ToJson,
    Debug
    )

    AtomFamily::equal

    fn AtomFamily::equal(AtomFamily, AtomFamily) -> Bool

    AtomFamily::not_equal

    fn AtomFamily::not_equal(x : AtomFamily, y : AtomFamily) -> Bool

    AtomFamily::to_json

    fn AtomFamily::to_json(AtomFamily) -> Json

    ColumnSeparationType

    pub(all) enum ColumnSeparationType {
    AlignSeparation
    AlignAtSeparation
    GatherSeparation
    SmallSeparation
    CdSeparation
    } derive(Eq, ToJson,
    Debug
    )

    ColumnSeparationType::equal

    ColumnSeparationType::not_equal

    ColumnSeparationType::to_json

    CommandArgument

    pub struct CommandArgument {
    arg_type : ArgType?
    optional : Bool
    } derive(ToJson)

    An explicit argument, in input order. A missing arg_type means the builtin macro's argument type is not declared. Optional arguments use square brackets.

    CommandArgument::to_json

    CommandInfo

    pub struct CommandInfo {
    name : String
    kind : CommandKind
    syntax : CommandSyntax
    args : Array[CommandArgument]
    modes : Array[Mode]?
    unicode : String?
    group : String?
    templates : Array[String]
    } derive(ToJson)

    A snapshot of one public builtin command, including its leading backslash. args describes explicit arguments, not an infix operand or an implicit body. modes is absent when a macro's mode restrictions are not statically known. unicode/group describe its registered symbol, when available. templates use named ${field} placeholders, as accepted by CodeMirror's snippetCompletion. Regular commands list the form without optional args first. Templates are editing skeletons, not necessarily valid until fields are filled.

    CommandInfo::to_json

    fn CommandInfo::to_json(CommandInfo) -> Json

    CommandKind

    pub(all) enum CommandKind {
    SymbolCommand
    FunctionCommand
    MacroCommand
    ImplicitCommand
    } derive(ToJson)

    The builtin table from which a completion command originates.

    CommandKind::to_json

    fn CommandKind::to_json(CommandKind) -> Json

    CommandSyntax

    pub(all) enum CommandSyntax {
    RegularCommand
    InfixCommand
    DeclarationCommand
    DelimiterCommand
    EnvironmentCommand
    VerbatimCommand
    DefinitionCommand
    TokenCommand
    GroupCommand
    } derive(ToJson)

    How a command consumes input. Only RegularCommand can be completed by appending bracketed args alone; use templates for the other forms.

    CommandSyntax::to_json

    Diagnostic

    pub(all) struct Diagnostic {
    text : String
    loc : SourceLocation?
    } derive(Eq, ToJson,
    Debug
    )

    Diagnostic::equal

    fn Diagnostic::equal(Diagnostic, Diagnostic) -> Bool

    Diagnostic::not_equal

    fn Diagnostic::not_equal(x : Diagnostic, y : Diagnostic) -> Bool

    Diagnostic::to_json

    fn Diagnostic::to_json(Diagnostic) -> Json

    EnvironmentContext

    pub(all) struct EnvironmentContext {
    mode : Mode
    display_mode : Bool
    leqno : Bool
    env_name : String
    parse_array : (ArrayEnvironmentOptions) -> ParseNode raise ParseFailure
    parse_matrix_alignment : () -> String? raise ParseFailure
    parse_cd : () -> ParseNode raise ParseFailure
    }

    EnvironmentRegistry

    pub(all) struct EnvironmentRegistry {
    entries : Map[String, EnvironmentSpec]
    }

    EnvironmentRegistry::get

    fn EnvironmentRegistry::get(self : EnvironmentRegistry, name : String) -> EnvironmentSpec?

    EnvironmentRegistry::make

    EnvironmentRegistry::register

    fn EnvironmentRegistry::register(self : EnvironmentRegistry, spec : EnvironmentSpec) -> Unit

    EnvironmentSpec

    pub(all) struct EnvironmentSpec {
    names : Array[String]
    num_args : Int
    num_optional_args : Int
    arg_types : Array[ArgType]
    handler : (EnvironmentContext, Array[ParseNode], Array[ParseNode?]) -> ParseNode raise ParseFailure
    }

    EnvironmentSpec::make

    fn EnvironmentSpec::make(names : Array[String], num_args : Int, num_optional_args? : Int, arg_types? : Array[ArgType], handler~ : (EnvironmentContext, Array[ParseNode], Array[ParseNode?]) -> ParseNode raise ParseFailure) -> EnvironmentSpec

    FunctionContext

    pub(all) struct FunctionContext {
    func_name : String
    mode : Mode
    token : Token?
    break_on_token_text : String?
    set_macro : (String, MacroDefinition?) -> Unit
    report_nonstrict : (String, String) -> Unit raise ParseFailure
    is_trusted : (TrustContext) -> Bool
    parse_optional_size : () -> Measurement? raise ParseFailure
    display_mode : Bool
    use_strict_behavior : (String, String) -> Bool
    current_color : () -> String? raise ParseFailure
    in_left_right : () -> Bool
    parse_expression : (Bool, String?) -> Array[ParseNode] raise ParseFailure
    parse_math_mode : (String) -> Array[ParseNode] raise ParseFailure
    parse_left_right : (String) -> ParseNode raise ParseFailure
    pop_token : () -> Token raise ParseFailure
    future_token : () -> Token raise ParseFailure
    push_token : (Token) -> Unit
    consume_spaces : () -> Unit raise ParseFailure
    consume_macro_arg : () -> Array[Token] raise ParseFailure
    expand_tokens : (Array[Token]) -> Array[Token] raise ParseFailure
    get_macro : (String) -> MacroDefinition?
    set_macro_definition : (String, MacroDefinition, Bool) -> Unit
    is_expandable : (String) -> Bool
    parse_prefixed_function : (String) -> ParseNode raise ParseFailure
    parse_environment : (String) -> ParseNode raise ParseFailure
    }

    FunctionRegistry

    pub(all) struct FunctionRegistry {
    entries : Map[String, FunctionSpec]
    }

    FunctionRegistry::get

    fn FunctionRegistry::get(self : FunctionRegistry, name : String) -> FunctionSpec?

    FunctionRegistry::make

    FunctionRegistry::register

    fn FunctionRegistry::register(self : FunctionRegistry, spec : FunctionSpec) -> Unit

    FunctionSpec

    pub(all) struct FunctionSpec {
    names : Array[String]
    num_args : Int
    num_optional_args : Int
    arg_types : Array[ArgType]
    allowed_in_argument : Bool
    allowed_in_text : Bool
    allowed_in_math : Bool
    infix : Bool
    primitive : Bool
    primitive_after_missing_optional : Int?
    handler : (FunctionContext, Array[ParseNode], Array[ParseNode?]) -> ParseNode raise ParseFailure?
    }

    FunctionSpec::make

    fn FunctionSpec::make(names : Array[String], num_args : Int, num_optional_args? : Int, arg_types? : Array[ArgType], allowed_in_argument? : Bool, allowed_in_text? : Bool, allowed_in_math? : Bool, infix? : Bool, primitive? : Bool, primitive_after_missing_optional? : Int, handler? : (FunctionContext, Array[ParseNode], Array[ParseNode?]) -> ParseNode raise ParseFailure) -> FunctionSpec

    LapAlignment

    pub(all) enum LapAlignment {
    LLap
    RLap
    CLap
    } derive(Eq, ToJson,
    Debug
    )

    LapAlignment::equal

    LapAlignment::not_equal

    fn LapAlignment::not_equal(x : LapAlignment, y : LapAlignment) -> Bool

    LapAlignment::to_json

    MacroDefinition

    pub(all) enum MacroDefinition {
    Text(String)
    Expansion(MacroExpansion)
    }

    MacroExpansion

    pub(all) struct MacroExpansion {
    tokens : Array[Token]
    num_args : Int
    delimiters : Array[Array[String]]?
    unexpandable : Bool
    }

    Macros

    pub struct Macros(Map[String, MacroDefinition])

    Macros::make

    fn Macros::make(macros? : Map[String, String]) -> Macros

    Measurement

    pub(all) struct Measurement {
    number : Double
    unit : String
    } derive(Eq, ToJson,
    Debug
    )

    Measurement::equal

    fn Measurement::equal(Measurement, Measurement) -> Bool

    Measurement::not_equal

    fn Measurement::not_equal(x : Measurement, y : Measurement) -> Bool

    Measurement::to_json

    fn Measurement::to_json(Measurement) -> Json

    Mode

    pub(all) enum Mode {
    Math
    Text
    } derive(Eq, ToJson,
    Debug
    )

    Mode::equal

    fn Mode::equal(Mode, Mode) -> Bool

    Mode::not_equal

    fn Mode::not_equal(x : Mode, y : Mode) -> Bool

    Mode::to_json

    fn Mode::to_json(Mode) -> Json

    Mode::to_repr

    OperatorContent

    pub(all) enum OperatorContent {
    SymbolOperator(String)
    BodyOperator(Array[ParseNode])
    NamedOperator(String)
    } derive(Eq, ToJson,
    Debug
    )

    OperatorContent::equal

    OperatorContent::not_equal

    fn OperatorContent::not_equal(x : OperatorContent, y : OperatorContent) -> Bool

    OperatorContent::to_json

    ParseNode

    pub(all) enum ParseNode {
    Internal(mode~ : Mode)
    Raw(mode~ : Mode, string~ : String)
    ColorToken(mode~ : Mode, color~ : String)
    Size(mode~ : Mode, value~ : Measurement, is_blank~ : Bool)
    Url(mode~ : Mode, url~ : String)
    Styling(mode~ : Mode, body~ : Array[ParseNode], style~ : StyleLevel, reset_font~ : Bool)
    Sqrt(mode~ : Mode, body~ : ParseNode, index~ : ParseNode?)
    Infix(mode~ : Mode, replace_with~ : String, size~ : Measurement?, loc~ : SourceLocation?)
    GenFrac(mode~ : Mode, numer~ : ParseNode, denom~ : ParseNode, continued~ : Bool, has_bar_line~ : Bool, bar_size~ : Measurement?, left_delim~ : String?, right_delim~ : String?)
    Text(mode~ : Mode, body~ : Array[ParseNode], font~ : String)
    Font(mode~ : Mode, font~ : String, body~ : ParseNode)
    MClass(mode~ : Mode, mclass~ : AtomFamily, body~ : Array[ParseNode], is_character_box~ : Bool)
    Op(mode~ : Mode, limits~ : Bool, always_handle_sup_sub~ : Bool, parent_is_sup_sub~ : Bool, suppress_base_shift~ : Bool, content~ : OperatorContent)
    OperatorName(mode~ : Mode, body~ : Array[ParseNode], always_handle_sup_sub~ : Bool, limits~ : Bool, parent_is_sup_sub~ : Bool)
    Overline(mode~ : Mode, body~ : ParseNode)
    Underline(mode~ : Mode, body~ : ParseNode)
    Smash(mode~ : Mode, body~ : ParseNode, smash_height~ : Bool, smash_depth~ : Bool)
    Phantom(mode~ : Mode, body~ : Array[ParseNode])
    VPhantom(mode~ : Mode, body~ : ParseNode)
    Pmb(mode~ : Mode, mclass~ : AtomFamily, body~ : Array[ParseNode])
    VCenter(mode~ : Mode, body~ : ParseNode)
    Rule(mode~ : Mode, shift~ : Measurement?, width~ : Measurement, height~ : Measurement)
    RaiseBox(mode~ : Mode, dy~ : Measurement, body~ : ParseNode)
    HBox(mode~ : Mode, body~ : Array[ParseNode])
    Lap(mode~ : Mode, alignment~ : LapAlignment, body~ : ParseNode)
    MathChoice(mode~ : Mode, display~ : Array[ParseNode], text~ : Array[ParseNode], script~ : Array[ParseNode], scriptscript~ : Array[ParseNode])
    Sizing(mode~ : Mode, size~ : Int, body~ : Array[ParseNode])
    HorizBrace(mode~ : Mode, label~ : String, is_over~ : Bool, base~ : ParseNode)
    XArrow(mode~ : Mode, label~ : String, body~ : ParseNode, below~ : ParseNode?)
    AccentUnder(mode~ : Mode, label~ : String, base~ : ParseNode)
    DelimSizing(mode~ : Mode, size~ : Int, mclass~ : AtomFamily, delim~ : String)
    LeftRightRight(mode~ : Mode, delim~ : String, color~ : String?)
    LeftRight(mode~ : Mode, body~ : Array[ParseNode], left~ : String, right~ : String, right_color~ : String?)
    Middle(mode~ : Mode, delim~ : String)
    Kern(mode~ : Mode, dimension~ : Measurement)
    Enclose(mode~ : Mode, body~ : ParseNode, label~ : String, background_color~ : String?, border_color~ : String?)
    Href(mode~ : Mode, href~ : String, body~ : Array[ParseNode])
    Html(mode~ : Mode, attributes~ : Map[String, String], body~ : Array[ParseNode])
    IncludeGraphics(mode~ : Mode, alt~ : String, width~ : Measurement, height~ : Measurement, totalheight~ : Measurement, src~ : String)
    Tag(mode~ : Mode, body~ : Array[ParseNode], tag~ : Array[ParseNode])
    Array(mode~ : Mode, body~ : Array[Array[ParseNode]], add_jot~ : Bool, array_stretch~ : Double, columns~ : Array[ArrayColumn]?, row_gaps~ : Array[Measurement?], hskip_before_and_after~ : Bool, hlines_before_row~ : Array[Array[Bool]], column_separation_type~ : ColumnSeparationType?, tags~ : Array[Array[ParseNode]?]?, auto_tags~ : Array[Bool]?, leqno~ : Bool)
    EnvironmentEnd(mode~ : Mode, name~ : String)
    CdLabel(mode~ : Mode, side~ : String, label~ : ParseNode)
    CdParent(mode~ : Mode, fragment~ : ParseNode)
    Cr(mode~ : Mode, new_line~ : Bool, size~ : Measurement?)
    HtmlMathML(mode~ : Mode, html~ : Array[ParseNode], mathml~ : Array[ParseNode])
    OrdGroup(mode~ : Mode, loc~ : SourceLocation?, body~ : Array[ParseNode], semisimple~ : Bool)
    SupSub(mode~ : Mode, base~ : ParseNode?, sup~ : ParseNode?, sub~ : ParseNode?)
    TextOrd(mode~ : Mode, loc~ : SourceLocation?, text~ : String)
    MathOrd(mode~ : Mode, loc~ : SourceLocation?, text~ : String)
    Spacing(mode~ : Mode, loc~ : SourceLocation?, text~ : String)
    AccentToken(mode~ : Mode, loc~ : SourceLocation?, text~ : String)
    OperatorToken(mode~ : Mode, loc~ : SourceLocation?, text~ : String)
    Accent(mode~ : Mode, loc~ : SourceLocation?, label~ : String, is_stretchy~ : Bool, is_shifty~ : Bool, base~ : ParseNode)
    Verb(mode~ : Mode, loc~ : SourceLocation?, body~ : String, star~ : Bool)
    Atom(mode~ : Mode, loc~ : SourceLocation?, family~ : AtomFamily, text~ : String)
    Color(mode~ : Mode, color~ : String, body~ : Array[ParseNode])
    } derive(Eq, ToJson,
    Debug
    )

    ParseNode::equal

    fn ParseNode::equal(ParseNode, ParseNode) -> Bool

    ParseNode::mode

    fn ParseNode::mode(self : ParseNode) -> Mode

    ParseNode::not_equal

    fn ParseNode::not_equal(x : ParseNode, y : ParseNode) -> Bool

    ParseNode::to_json

    fn ParseNode::to_json(ParseNode) -> Json

    Settings

    pub struct Settings {
    throw_on_error : Bool
    display_mode : Bool
    leqno : Bool
    error_color : String
    color_is_text_color : Bool
    max_expand : Int
    global_group : Bool
    macros : Map[String, String]
    macro_store : Macros?
    strict : Strictness
    strict_warning_handler : (String) -> Unit?
    trust : TrustPolicy
    }

    impl Default for Settings

    Settings::default

    fn Settings::default() -> Settings

    Settings::make

    fn Settings::make(throw_on_error? : Bool, display_mode? : Bool, leqno? : Bool, error_color? : String, color_is_text_color? : Bool, max_expand? : Int, global_group? : Bool, macros? : Map[String, String], macro_store? : Macros, strict? : Strictness, strict_warning_handler? : (String) -> Unit, trust? : TrustPolicy) -> Settings

    SourceLocation

    pub(all) struct SourceLocation {
    input : String
    start : Int
    end : Int
    } derive(Eq, ToJson,
    Debug
    )

    SourceLocation::equal

    SourceLocation::make

    fn SourceLocation::make(input : String, start~ : Int, end~ : Int) -> SourceLocation

    SourceLocation::not_equal

    fn SourceLocation::not_equal(x : SourceLocation, y : SourceLocation) -> Bool

    SourceLocation::to_json

    StrictResponse

    pub(all) enum StrictResponse {
    Ignore
    Warn
    Error
    }

    Strictness

    pub(all) enum Strictness {
    Ignore
    Warn
    Error
    Callback((String, String, SourceLocation?) -> StrictResponse raise ParseFailure)
    }

    StyleLevel

    pub(all) enum StyleLevel {
    DisplayStyle
    TextStyle
    ScriptStyle
    ScriptScriptStyle
    } derive(Eq, ToJson,
    Debug
    )

    StyleLevel::equal

    fn StyleLevel::equal(StyleLevel, StyleLevel) -> Bool

    StyleLevel::not_equal

    fn StyleLevel::not_equal(x : StyleLevel, y : StyleLevel) -> Bool

    StyleLevel::to_json

    fn StyleLevel::to_json(StyleLevel) -> Json

    Token

    pub(all) struct Token {
    text : String
    loc : SourceLocation?
    noexpand : Bool
    treat_as_relax : Bool
    }

    TrustContext

    pub(all) enum TrustContext {
    UrlTrust(command~ : String, url~ : String, protocol~ : String?)
    HtmlClass(class~ : String)
    HtmlId(id~ : String)
    HtmlStyle(style~ : String)
    HtmlData(attributes~ : Map[String, String])
    }

    TrustPolicy

    pub(all) enum TrustPolicy {
    Untrusted
    Trusted
    Callback((TrustContext) -> Bool)
    }

    UnicodeScript

    pub struct UnicodeScript {
    replacement : String
    kind : UnicodeScriptKind
    }

    UnicodeScriptKind

    pub(all) enum UnicodeScriptKind {
    UnicodeSubscript
    UnicodeSuperscript
    } derive(Eq)

    UnicodeScriptKind::equal

    UnicodeScriptKind::not_equal

    fn UnicodeScriptKind::not_equal(x : UnicodeScriptKind, y : UnicodeScriptKind) -> Bool

    U00A0

    let U00A0 : String

    build_environment_registry

    fn build_environment_registry(extra_specs : Array[EnvironmentSpec]) -> EnvironmentRegistry

    Builds an environment registry from the builtin specs plus caller-provided extension specs (which override builtins sharing the same name).

    build_function_registry

    fn build_function_registry(extra_specs : Array[FunctionSpec]) -> FunctionRegistry

    Builds a function registry from the builtin specs plus caller-provided extension specs (e.g. \eval registered by the eval package).

    builtin_commands

    fn builtin_commands() -> Array[CommandInfo]

    Returns fresh, name-sorted completion metadata for the parser's builtins. Includes symbols, functions, static/dynamic macros, implicit commands and supported starred command forms. Internal names and raw Unicode aliases are excluded. No handlers are run and no parser state is changed. This describes default builtins, not settings-dependent or user macros.

    builtin_commands_json

    fn builtin_commands_json() -> Json

    Exports the builtin completion catalogue as a JSON array.

    parse

    fn parse(input : String, settings? : Settings, extra_specs? : Array[FunctionSpec], extra_env_specs? : Array[EnvironmentSpec]) -> Array[ParseNode] raise ParseFailure

    supported_codepoint

    fn supported_codepoint(code : Int) -> Bool

    True when the codepoint falls within one of the supported Unicode script blocks. Mirrors KaTeX's supportedCodepoint (unicodeScripts.ts).

    unicode_font_character

    fn unicode_font_character(font : String, char : String) -> String?

    Returns the Unicode mathematical alphanumeric character for a given font style and ASCII letter/digit, or None when no mapping exists.

    Font styles that match LaTeX commands:
    • mathbf / boldsymbol — Bold / Bold Italic
    • mathit — Italic
    • mathbb — Double-struck (blackboard bold)
    • mathcal — Calligraphic / Script
    • mathfrak — Fraktur
    • mathscr — Script (rsfs)
    • mathsf — Sans-serif
    • mathtt — Monospace
    • mathsfit — Sans-serif Italic
    • mathrm / mathnormal — Roman (identity, not handled here) / Italic

    unicode_script_character

    fn unicode_script_character(kind : UnicodeScriptKind, replacement : String) -> String?

    Returns the Unicode superscript or subscript character for replacement.

    The parser and renderers share unicode_scripts as the canonical table.

    unicode_symbol

    fn unicode_symbol(name : String) -> String?

    Returns a registered symbol's Unicode replacement, if it has one.

    Source Files