Docs
LaTeX
LaTeX

A powerful LaTeX component for rendering mathematical expressions with react-katex, supporting inline and block modes with customizable sizing.

20 views
0 downloads
Loading...

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"
2
3import Latex, { LargeBlockMath, LargeInlineMath } from "@/registry/media/latex"
4
5export 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-energy
11 equivalence.
12 </p>
13
14 {/* Block math with custom size */}
15 <Latex
16 math="\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}"
17 block
18 size="large"
19 />
20
21 {/* Enhanced components */}
22 <p>
23 Large inline: <LargeInlineMath math="\sum_{i=1}^{n} x_i" />
24 </p>
25
26 <LargeBlockMath math="\lim_{x \to \infty} \frac{1}{x} = 0" />
27 </div>
28 )
29}

Size Variations

1import Latex from "@/registry/media/latex"
2
3export 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"
2
3export 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>
9
10 <Latex
11 math="\frac{dy}{dx} = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}"
12 block
13 />
14 </div>
15 )
16}

API Reference

Latex

NameTypeDefaultDescription
mathstring-The LaTeX mathematical expression to render
blockbooleanfalseWhether to render as block-level (centered)
size"small" | "medium" | "large" | "x-large""medium"Size scaling for the rendered math
classNamestring-Additional CSS classes

LargeInlineMath

NameTypeDefaultDescription
mathstring-The LaTeX mathematical expression to render
classNamestring-Additional CSS classes

LargeBlockMath

NameTypeDefaultDescription
mathstring-The LaTeX mathematical expression to render
classNamestring-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.

Loading...

Complex Equations

Advanced mathematical expressions including integrals, matrices, and series.

Loading...

Enhanced Components

Demonstrates the enhanced LargeInlineMath and LargeBlockMath components with various mathematical notations.

Loading...

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 = 0
2x \cdot y \times z
3\frac{a}{b}
4x^2 + y^{10}
5\sqrt{x} + \sqrt[3]{y}

Greek Letters

1\alpha, \beta, \gamma, \delta, \epsilon
2\pi, \sigma, \tau, \phi, \psi, \omega
3\Gamma, \Delta, \Theta, \Lambda, \Pi, \Sigma

Calculus

1\lim_{x \to \infty} f(x)
2\int_0^1 x^2 dx
3\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 C
2A \subseteq B \subset C
3x \in S, y \notin T
4\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.