NativeElixirPdfUtilities.Validators.MathOperatorValidator (native_elixir_pdf_utilities v1.1.0)

View Source

Prepares operator semantics and Chromium-compatible authored MathML lengths.

The source is the 24 June 2025 MathML Core snapshot, sections 3.2.4.1, 3.2.4.2 and B.1. Invalid authored attribute syntax uses Core's dictionary fallback. Invalid API arguments and exceeded resource limits return diagnostics. This module does not render MathML or select stretch glyphs.

Summary

Types

Validated operator properties for a prepared MathML core operator.

Point lengths, glyph-height percentages, or the unbounded Core maximum.

Functions

Prepares the dictionary and authored properties of an mo core operator.

Types

semantics()

@type semantics() :: %{
  text: String.t(),
  form: :infix | :prefix | :postfix,
  explicit_form: boolean(),
  category: atom(),
  lspace: number(),
  rspace: number(),
  stretchy: boolean(),
  symmetric: boolean(),
  fence: boolean(),
  separator: boolean(),
  largeop: boolean(),
  movablelimits: boolean(),
  minsize: size_constraint(),
  maxsize: size_constraint(),
  stretch_axis: :horizontal | :vertical,
  single_character: boolean(),
  invisible: boolean()
}

Validated operator properties for a prepared MathML core operator.

size_constraint()

@type size_constraint() :: number() | {:percentage, number()} | :infinity

Point lengths, glyph-height percentages, or the unbounded Core maximum.

Functions

prepare(text, attributes, context \\ %{})

@spec prepare(term(), term(), term()) ::
  {:ok, semantics()}
  | {:error, {atom(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Prepares the dictionary and authored properties of an mo core operator.

attributes is a map of binary attribute names and values. text is preserved exactly, including invisible operators, combining overlays and ASCII pairs. The caller supplies the already prepared token text, without further cleanup.

context describes the outer embellished operator, not an inner wrapper:

  • parent is the MathML parent tag name, or nil for a detached operator. Use :grouping for prepared unknown MathML elements or anonymous rows.
  • index and count describe in-flow siblings excluding space-like children. They default to zero and one. Empty sibling lists use index zero/count zero.
  • child_index is the index amongst all in-flow siblings and defaults to index. It determines postfix form for a script child that is not the base.
  • font_size defaults to 12 points; root_font_size defaults to font_size. These sizes belong to the core operator. Optional x_height supplies the selected core font's x-height in points for ex lengths. cap_height, zero_advance and line_height supply the selected-font cap height, zero advance and computed line height for cap, ch and lh lengths.
  • text_only defaults to true. Set false when the core contains element children, so it cannot use the text-keyed dictionary or single-glyph layout.

Spacing is returned in points. Percentage spacing uses the dictionary spacing as its base. Percentage min/max sizes remain tagged until natural glyph height is available. These are parsed constraints, not stretch targets. Negative constraints are valid Core values. Follow-up stretch preparation in the math validator must resolve percentages and clamp min/max against natural glyph height; consumers must not independently reinterpret these constraints. Fence and separator are semantic metadata and do not change Core geometry. Numeric percentages and absolute, em, rem, ex, cap, ch and lh lengths are resolved against the core operator's selected font and computed style. Authored MathML length attributes using calc, min, max, or clamp use the dictionary fallback, matching Chromium's ParseMathLength rejection of calculated values. Ordinary CSS calculations are unaffected. Optional viewport_width and viewport_height are point dimensions of the actual CSS viewport. Root font units use the corresponding root_* metric. Missing geometry is diagnosed. stretch_axis uses the names accepted by MathLayout.stretch/6, even when stretchy is false. Multi-character operators need text layout, not stretch/6.