import type { MathRenderer } from '../engine/plugins/math-view'; /** * The slice of the KaTeX module this helper needs. Declared locally so the * design system never imports `katex` itself — you bundle KaTeX from your own * app's install and pass the instance in. */ export interface KatexLike { renderToString(latex: string, options?: Record): string; } export interface KatexRendererOptions { /** * Extra options merged into every `katex.renderToString` call (after the * `displayMode` / `throwOnError` defaults). See the KaTeX options reference. */ katexOptions?: Record; } /** * Builds a {@link MathRenderer} backed by KaTeX for the editor's `mathRenderer` * property. KaTeX is **not** bundled by the design system — install it in your * app and hand the instance to this helper so your bundler ships it (no CDN): * * ```ts * import katex from 'katex'; * import 'katex/dist/katex.min.css'; * import { createKatexRenderer } from '@aquera/nile-elements'; * * editor.mathRenderer = createKatexRenderer(katex); * // or with overrides: * editor.mathRenderer = createKatexRenderer(katex, { * katexOptions: { macros: { '\\RR': '\\mathbb{R}' } }, * }); * ``` * * Called with no instance it falls back to a global `katex` (e.g. a CDN * `