# @comark/plugin-katex
[](https://npmx.dev/@comark/plugin-katex)
[](https://npm.chart.dev/@comark/plugin-katex)
[](https://github.com/comarkdown/comark/actions/workflows/ci.yml)
[](https://comark.dev/plugins/official/katex)
[](https://github.com/comarkdown/comark/blob/main/LICENSE)
KaTeX plugin for [Comark](https://comark.dev). Parses inline `$...$` and display `$$...$$` expressions and renders them with [KaTeX](https://katex.org/), in HTML, terminal, Vue, React, Svelte and Angular.
## Features
- `katex` ships as a dependency, so there is nothing else to install
- Inline and display math, plus optional `\(...\)` and `\[...\]` delimiters for LLM output
- Auto-closes incomplete math while streaming
- `Math` components for Vue, React, Svelte, Angular, HTML and ANSI
- KaTeX loads on first use, so pages without math never load it
- Full TypeScript support
## Installation
```bash
npm install @comark/plugin-katex
# or
pnpm add @comark/plugin-katex
```
## Usage
```ts
import { parseMarkdown } from 'comark'
import math from '@comark/plugin-katex'
const result = await parseMarkdown('Inline $x^2$ and display $$E = mc^2$$', {
plugins: [math()],
})
```
The plugin stores the LaTeX source as plain text. Rendering needs a `Math` component and the KaTeX stylesheet:
```ts
import '@comark/plugin-katex/katex.css'
```
```vue
{{ content }}
```
```tsx
import { Markdown } from '@comark/react'
import math from '@comark/plugin-katex'
import { Math } from '@comark/plugin-katex/react'
{content}
```
```svelte
```
Each component entry exports only its component, so the plugin always comes from the package root. The Angular adapter (`@comark/plugin-katex/angular`) and the HTML and ANSI render functions (`@comark/plugin-katex/html`, `@comark/plugin-katex/ansi`) follow the same rule.
## API
- `math(options?)` returns the plugin. Options: `brackets` (also parse `\(...\)` and `\[...\]`), `options` (KaTeX render options).
- `loadKatex()` loads KaTeX on demand; `getKatex()` returns it once loaded; `typesetMath(tex, displayMode)` renders to HTML.
- `Math` components are exported from `./vue`, `./react`, `./svelte`, `./angular`, `./html` and `./ansi`.
## Documentation
Full guide and API reference at [comark.dev/plugins/official/katex](https://comark.dev/plugins/official/katex).
## License
Made with ❤️
Published under [MIT License](https://github.com/comarkdown/comark/blob/main/LICENSE).