Registry / web-framework / vue-katex

vue-katex

JSON →
library0.5.0jsnpmunverified

vue-katex is a lightweight Vue plugin designed to integrate KaTeX, a fast math typesetting library, into Vue applications. The current stable version is 0.5.0, which notably adds support for KaTeX 0.12.0. The project's release cadence appears to be driven by updates to its peer dependency, KaTeX, ensuring compatibility with newer versions of the typesetting library. Key differentiators include its dual approach to usage, offering both a `v-katex` directive for inline or display-mode rendering and a `<katex-element>` component for more structured integration. It also supports KaTeX's auto-render functionality, simplifying the display of math expressions embedded directly in HTML. This package streamlines the process of rendering complex mathematical formulas within Vue ecosystems.

npm install vue-katex
INSTALL
IMPORT
SIG · VUE-KATEX
V
vue-katex
web-frameworkjavascriptv0.5.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Vue
import Vue from 'vue'
const Vue = require('vue')
Essential peer dependency for initializing the Vue plugin.
VueKatex
import VueKatex from 'vue-katex'
import { VueKatex } from 'vue-katex'
The main plugin is a default export and is registered with `Vue.use()`.
katex.min.css
import 'katex/dist/katex.min.css'
require('katex/dist/katex.min.css')
Crucial stylesheet for correct KaTeX rendering; must be imported separately.

This quickstart demonstrates the setup of `vue-katex` by registering it globally with `Vue.use()`, including the necessary stylesheet. It then showcases both the `v-katex` directive for rendering inline and display math with options, including `auto-render` functionality, and the `<katex-element>` component for declarative TeX expression rendering.

import Vue from 'vue'; import VueKatex from 'vue-katex'; import 'katex/dist/katex.min.css'; Vue.use(VueKatex, { globalOptions: { displayMode: true, // Default to display mode globally throwOnError: false, errorColor: '#FF0000' } }); new Vue({ el: '#app', data: { inlineMath: '\\frac{a_i}{1+x^2}', displayMath: '\\int_0^1 x^2 dx = \\frac{1}{3}', autoRenderContent: 'The quadratic formula is \\(x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}\\) and then some display math: $$ E=mc^2 $$' }, template: ` <div id="app"> <h1>Vue KaTeX Example</h1> <h2>Using v-katex directive</h2> <p>Inline: <span v-katex="inlineMath"></span></p> <p>Display mode (local override): <div v-katex:display="displayMath"></div></p> <p>With options: <div v-katex="{ expression: '\\sqrt{2}', options: { throwOnError: false, errorColor: '#00F' } }"></div></p> <h2>Using v-katex:auto directive</h2> <div v-katex:auto> {{ autoRenderContent }} </div> <h2>Using KatexElement component</h2> <katex-element :expression="displayMath" :display-mode="false" /> <katex-element expression="\\sum_{n=1}^\\infty \\frac{1}{n^2} = \\frac{\\pi^2}{6}" :display-mode="true" :throw-on-error="false" error-color="#00A" /> <p>Check the console for any KaTeX errors if throwOnError is false.</p> </div> ` });
Debug
Known issues
gotchaEnsure KaTeX peer dependency matches `vue-katex` version support. `vue-katex@0.5.0` is specifically designed for KaTeX `0.12.0`.
fix
Check `vue-katex` releases for specific KaTeX version compatibility and install the appropriate `katex` version (e.g., `npm i katex@^0.12.0`).
affects: >=0.5.0
gotchaKaTeX's essential stylesheet (`katex.min.css`) is not automatically bundled or injected by `vue-katex`. Failure to import it will result in unstyled or incorrectly rendered math expressions.
fix
Explicitly import the stylesheet in your entry point: `import 'katex/dist/katex.min.css';` or include it via an HTML `<link>` tag.
affects: >=0.1.0
gotchaWhen using the `v-katex` directive with string literals in Vue templates, remember to escape all backslashes (`\`) in your TeX expressions, as single backslashes are interpreted as JavaScript escape sequences.
fix
Use double backslashes for all TeX commands (e.g., `'\\frac{a_i}{1+x}'` instead of `'\frac{a_i}{1+x}'`).
affects: >=0.1.0
gotchaLocal KaTeX options provided to `v-katex` or `KatexElement` will override globally defined options, except for `object` or `array` type options, which are merged.
fix
Be aware of the merging behavior when defining global and local options. For full control, provide complete option objects locally or manage global options carefully.
affects: >=0.1.0
Errors
Common errors & fixes
KaTeX parse error: Undefined control sequence: \frac at position 1
Incorrect TeX syntax or unescaped backslashes in a template string.
fix
Double-check your TeX expression for syntax errors and ensure all backslashes are escaped (e.g., `v-katex="'\\frac{a}{b}'"`).
Failed to resolve component: katex-element
The `vue-katex` plugin (which registers `KatexElement` and `v-katex`) has not been registered with Vue.
fix
Ensure you have called `Vue.use(VueKatex)` in your application's entry point after importing `Vue` and `VueKatex`.
Math expressions appear unstyled, in plain text, or with incorrect fonts.
KaTeX stylesheet `katex.min.css` is not loaded in your application.
fix
Import `katex/dist/katex.min.css` in your main JavaScript file or include it via a `<link>` tag in your `index.html`.
Upgrade
Version history
0.5.0latest on npm
Audit
Dependencies
vuerequiredPeer dependency required by the Vue plugin.
katexrequiredPeer dependency providing the core math typesetting functionality.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
vue-katex — npm install vue-katex · libregistry