Skip to content

Equation ​

A math formula component (self-developed simplified LaTeX subset, zero third-party formula engine) covering common high-school / university formulas: superscripts/subscripts, fractions, square roots, summation/integration (with limits), Greek letters, and common operators.

Superscripts and Subscripts ​

Superscript / subscript

^ superscript, _ subscript; both single characters x^2 and braced forms z_{max} work.

Fractions ​

Fraction

\frac{numerator}{denominator} renders as a vertical fraction (numerator/denominator stacked with a horizontal line).

Square Roots ​

Square root

\sqrt{radicand}; an optional root index \sqrt[3]{y} is supported.

Summation / Integration ​

Summation / integration (with limits)



\sum_{lower}^{upper} / \int_{lower}^{upper} automatically typesets the limits.

Greek Letters and Operators ​

Greek letters + operators

Greek letters like \alpha and common operators such as \times \div \pm \cdot \leq \geq \neq \approx \infty are mapped automatically.

Unknown Commands ​

Unknown commands shown literally

Unknown commands are displayed literally without errors.

Block Formula ​

display=block (centered display line)

Use display="block" for display math (centered standalone line with vertical margin); font size is not enlarged and follows the outer context.

Live Edit Preview ​

editable (boolean attribute, off by default — non-editing rendering stays byte-identical to pure display) enables click-to-edit (or Enter/Space when focused): typing LaTeX source renders a live preview (200ms throttled); Enter or blur commits the value back to code and emits oas-change (detail { value }); Esc cancels and restores the original value, emitting oas-cancel; entering/leaving edit mode emits oas-editing (detail { editing }) — including a false notification when editable is removed mid-edit. If an injected engine fails to render, the preview falls back to showing the raw source with a one-time devWarn (once per source). The value property is a dual channel: it reads the live text while editing and code otherwise; writing reflects to the code attribute (no event emitted). While editing, a host-side controlled write to code does not refresh the editor — the editor content wins on commit.

editable live edit preview

Click the formula to edit: Enter commits / Esc cancels

Injecting a Rendering Engine ​

engine injection (thin-shell delegation)

Once a TeX-compatible engine object (the engine property, renderToString protocol) is injected, the component becomes a thin shell delegating rendering — this demo uses a mock engine to demonstrate the protocol (the dashed box is the engine output). Without an injection, the self-developed subset renderer is used with zero dependencies.

Boundaries between the engine path and the self-developed path:

  • DOM: engine output is written as innerHTML (the engine's own classes/fonts apply inside it); the self-developed path uses stacked spans + CSS layout. Both paths set aria-label to the raw LaTeX.
  • Error state: both degrade silently — unknown commands render literally in the self-developed path; if the engine throws, rendering falls back to the self-developed subset (no blank output).
  • SSR: the snapshot only carries attribute channels — engine is a property, so SSR output is always the self-developed subset; for engine SSR, inject the same engine object on the server.

Font Size ​

Font size follows the outer context (inherited) by default; override with the CSS variable --oas-equation-font (e.g. 18px).

API ​

oas-equation ​

Attributes ​

AttributeDescriptionTypeDefault
codeLaTeX subset source textstring—
displayDisplay mode: inline (default, in-flow) / block (standalone centered block with margin-block)string—
editableLive edit preview (enabled when present): click/Enter enters edit mode with throttled live preview while typing LaTeX source; Enter/blur commits back to code, Esc cancels and restores the original valueboolean—

Property (JS property; see each row for attribute reflection) ​

PropertyDescriptionTypeDefault
valueFormula source (two-way, same source as the code attribute; reads the new source after an edit submit, or the live editor text while editing)string—

Events ​

EventDescription
oas-cancelEmitted when Esc cancels editing; detail { value: original source }
oas-changeEmitted when an edit commit changes the source; detail { value: new source }
oas-editingEmitted when entering/leaving edit mode; detail { editing: boolean } — removing the editable attribute mid-edit also emits editing: false

CSS Variables ​

CSS VariableDefault
--oas-equation-block-marginvar(--oas-space-4)
--oas-equation-fontinherit

ARIA ​

The container's aria-label equals the raw LaTeX source text, so screen readers read the formula source directly. With editable, the display-state container is the edit entry (role="button" + aria-label "Edit formula"); while editing, the preview region's aria-label follows the current source and the field is labeled as the editing state ("Editing formula source").

Boundaries ​

  • All text is HTML-escaped to prevent injection
  • Empty code renders an empty container without errors

Released under the MIT OR Apache-2.0 License.