@shiueo/react-katex
v1.0.4
Published
A React component for rendering LaTeX math expressions using KaTeX
Readme
@shiueo/react-katex
A React component for rendering LaTeX math expressions using KaTeX.
Installation
To install the package, run:
npm install @shiueo/react-katexUsage
// Import KaTeX CSS once in your project, before using this component
import 'katex/dist/katex.min.css'
import KaTeXComponent from '@shiueo/react-katex';Then use the component in your application:
<KaTeXComponent block={true} math="x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}" />Advanced Usage
The component accepts several props to customize its behavior:
math: stringThe LaTeX string to render.block?: booleanA boolean indicating whether to render as a block-level element (default: false).renderError?: (error: ParseError | TypeError) => ReactElement: A function to handle errors during parsing (optional).settings?: KatexOptions: Custom settings for KaTeX rendering (optional).as?: ElementType: The component type to render (default: span for inline, div for block-level).
💡 Example usage: See nextjs/page.tsx for comprehensive examples.
Features
- Optimized rendering: The component now utilizes useMemo to cache rendering options, improving performance by preventing unnecessary recalculations on each render.
Changelog
See CHANGELOG.md for a list of changes and version history.
License
MIT License. See LICENSE for more details.
