A powerful LaTeX component for rendering mathematical expressions with react-katex, supporting inline and block modes with customizable sizing.
Overview
The LaTeX component provides seamless mathematical expression rendering using react-katex. It supports both inline and block display modes with customizable sizing options, making it perfect for educational content, scientific documentation, and mathematical applications.
Installation
pnpm dlx shadcn@latest add https://deltacomponents.dev/r/latex.json
Usage
1"use client"23import Latex, { LargeBlockMath, LargeInlineMath } from "@/registry/media/latex"45export function Component() {6 return (7 <div className="space-y-4">8 {/* Inline math */}9 <p>10 The famous equation <Latex math="E = mc^2" /> demonstrates mass-energy11 equivalence.12 </p>1314 {/* Block math with custom size */}15 <Latex16 math="\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}"17 block18 size="large"19 />2021 {/* Enhanced components */}22 <p>23 Large inline: <LargeInlineMath math="\sum_{i=1}^{n} x_i" />24 </p>2526 <LargeBlockMath math="\lim_{x \to \infty} \frac{1}{x} = 0" />27 </div>28 )29}
Size Variations
1import Latex from "@/registry/media/latex"23export function SizeExample() {4 return (5 <div className="flex items-center gap-4">6 <Latex math="x^2" size="small" />7 <Latex math="x^2" size="medium" />8 <Latex math="x^2" size="large" />9 <Latex math="x^2" size="x-large" />10 </div>11 )12}
Block vs Inline Display
1import Latex from "@/registry/media/latex"23export function DisplayExample() {4 return (5 <div className="space-y-4">6 <p>7 Inline math appears within text: <Latex math="\frac{dy}{dx}" />8 </p>910 <Latex11 math="\frac{dy}{dx} = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}"12 block13 />14 </div>15 )16}
API Reference
Latex
Name | Type | Default | Description |
---|---|---|---|
math | string | - | The LaTeX mathematical expression to render |
block | boolean | false | Whether to render as block-level (centered) |
size | "small" | "medium" | "large" | "x-large" | "medium" | Size scaling for the rendered math |
className | string | - | Additional CSS classes |
LargeInlineMath
Name | Type | Default | Description |
---|---|---|---|
math | string | - | The LaTeX mathematical expression to render |
className | string | - | Additional CSS classes |
LargeBlockMath
Name | Type | Default | Description |
---|---|---|---|
math | string | - | The LaTeX mathematical expression to render |
className | string | - | Additional CSS classes |
Size Mapping
The component uses the following size scaling:
small
: 1em (base font size)medium
: 1.2em (20% larger)large
: 1.5em (50% larger)x-large
: 2em (double size)
Examples
Basic Math Expressions
Simple mathematical expressions with inline and block display modes.
Complex Equations
Advanced mathematical expressions including integrals, matrices, and series.
Enhanced Components
Demonstrates the enhanced LargeInlineMath and LargeBlockMath components with various mathematical notations.
Features
Comprehensive LaTeX Support
- Full LaTeX mathematical notation support via KaTeX
- Greek letters, operators, and special symbols
- Fractions, integrals, summations, and limits
- Matrices, vectors, and set theory notation
Flexible Display Options
- Inline Mode: Seamlessly integrates with text flow
- Block Mode: Centered display for prominent equations
- Size Control: Four preset sizes for different contexts
- Custom Styling: Supports additional CSS classes
Enhanced Components
- LargeInlineMath: Pre-configured large inline math for emphasis
- LargeBlockMath: Pre-configured large block math for important equations
- Consistent Styling: Follows design system patterns
Accessibility
- Proper semantic HTML structure
- Screen reader compatible via KaTeX rendering
- Keyboard navigation support
- High contrast support for visual accessibility
LaTeX Syntax Examples
Basic Operations
1x + y - z = 02x \cdot y \times z3\frac{a}{b}4x^2 + y^{10}5\sqrt{x} + \sqrt[3]{y}
Greek Letters
1\alpha, \beta, \gamma, \delta, \epsilon2\pi, \sigma, \tau, \phi, \psi, \omega3\Gamma, \Delta, \Theta, \Lambda, \Pi, \Sigma
Calculus
1\lim_{x \to \infty} f(x)2\int_0^1 x^2 dx3\frac{d}{dx} f(x)4\frac{\partial f}{\partial x}5\nabla \cdot \vec{F}
Linear Algebra
1\begin{bmatrix} a & b \\ c & d \end{bmatrix}2\begin{pmatrix} x \\ y \end{pmatrix}3\det(A) = |A|4A^{-1}
Set Theory
1A \cup B \cap C2A \subseteq B \subset C3x \in S, y \notin T4\emptyset, \mathbb{N}, \mathbb{R}
Common Use Cases
Educational Content
Perfect for math courses, tutorials, and educational materials where clear mathematical notation is essential.
Scientific Documentation
Ideal for research papers, technical documentation, and scientific applications requiring precise mathematical expressions.
Engineering Applications
Suitable for engineering calculations, formulas, and technical specifications that need mathematical clarity.
Interactive Learning
Great for interactive math applications, calculators, and educational tools where dynamic math rendering is needed.