
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-latex-editor
Advanced tools
A professional React rich text editor with mathematical equation support, built on TipTap with MathLive integration. Production-ready with TypeScript support, accessibility features, and industrial-grade error handling.
A powerful React rich text editor with mathematical equation support, built on TipTap with MathLive integration. This package provides a comprehensive WYSIWYG editor that supports mathematical equations, tables, images, and more.
📖 Documentation • 🚀 Quick Start • 🎯 Examples • 🔧 API Reference • 🎨 Customization
npm install react-latex-editor
This package requires React 18+ and React DOM 18+ as peer dependencies:
npm install react react-dom
This package is fully compatible with Next.js (both App Router and Pages Router).
⚠️ Important for Next.js users: Due to server-side rendering (SSR), you need to use client-side only imports. See our comprehensive Next.js guide for:
Quick Solution:
For App Router (Next.js 13+), use the 'use client' directive:
"use client";
import { Editor, Viewer } from "react-latex-editor";
import "react-latex-editor/styles";
export default function MyEditor() {
const [content, setContent] = useState("<p>Start typing...</p>");
return <Editor initialContent={content} onChange={setContent} />;
}
For Pages Router, use dynamic imports:
import dynamic from "next/dynamic";
const Editor = dynamic(
() => import("react-latex-editor").then((mod) => mod.Editor),
{ ssr: false },
);
For detailed instructions and complete examples, see NEXTJS.md.
import React, { useRef, useState } from "react";
import { Editor, Viewer, type EditorRef } from "react-latex-editor";
import "react-latex-editor/styles";
const App = () => {
const [content, setContent] = useState(
"<p>Start typing your content here...</p>",
);
const editorRef = useRef<EditorRef>(null);
return (
<div style={{ width: "60%", height: "100vh", margin: "0 auto" }}>
<Editor
ref={editorRef}
initialContent={content}
onChange={setContent}
placeholder="Type your content..."
autoFocus={true}
/>
<Viewer content={content} />
</div>
);
};
export default App;
The main Editor component provides a full-featured rich text editor:
import { Editor, EditorRef } from "react-latex-editor";
interface EditorProps {
initialContent?: string; // Initial HTML content
onChange?: (content: string) => void; // Content change callback
placeholder?: string; // Placeholder text
readOnly?: boolean; // Read-only mode
autoFocus?: boolean; // Auto-focus on mount
className?: string; // Additional CSS classes
onImageSelectionRequest?: () => void; // Image selection callback
minHeight?: string; // Minimum height (default: "300px")
maxHeight?: string; // Maximum height for scrolling
showCharacterCount?: boolean; // Show character count (default: true)
showTableControls?: boolean; // Show table controls (default: true)
}
Access editor methods through the ref:
const editorRef = useRef<EditorRef>(null);
// Get current HTML content
const html = editorRef.current?.getHTML();
// Set content programmatically
editorRef.current?.setContent("<p>New content</p>");
// Add images programmatically
editorRef.current?.addImage(["https://example.com/image.jpg"]);
Display content in read-only mode with math rendering:
import { Viewer } from "react-latex-editor";
function ContentViewer({ content }: { content: string }) {
return (
<Viewer
content={content}
className="my-viewer"
contentClassName="custom-content"
enableMath={true}
mathJaxConfig={{
inlineMath: [["$", "$"]],
displayMath: [["$$", "$$"]],
packages: ["base", "ams"],
}}
/>
);
}
The Viewer component supports two ways to apply custom classes:
className: Applied to the outer wrapper containercontentClassName: Applied directly to the content div (recommended for
text styling)Using Tailwind CSS:
<Viewer
content={content}
contentClassName="text-2xl font-serif leading-relaxed"
/>
Using Custom CSS:
<Viewer content={content} contentClassName="my-custom-content" />
.my-custom-content {
font-size: 1.5rem;
font-family: "Georgia", serif;
line-height: 1.8;
color: #333;
}
/* Style specific elements */
.my-custom-content h1 {
font-size: 2.5rem;
color: #1a1a1a;
}
.my-custom-content p {
margin-bottom: 1.5rem;
}
Common Customization Examples:
// Large text with custom font
<Viewer
content={content}
contentClassName="text-xl font-mono"
/>
// Custom spacing and colors
<Viewer
content={content}
contentClassName="text-lg leading-loose text-gray-800"
/>
// Combine wrapper and content styling
<Viewer
content={content}
className="bg-gray-50 p-8 rounded-lg"
contentClassName="text-base font-sans"
/>
The editor includes a comprehensive toolbar with:
Insert mathematical equations using the math button in the toolbar:
// Inline math: $x^2 + y^2 = z^2$
// Block math: $$\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}$$
The editor supports both inline and block math equations with a comprehensive symbol palette powered by MathLive.
Create tables with the table button:
Insert images with:
Embed YouTube videos with:
import { Editor } from "react-latex-editor";
function BasicEditor() {
return (
<Editor
placeholder="Start writing your content..."
onChange={(content) => console.log(content)}
/>
);
}
import { Viewer } from "react-latex-editor";
function ContentViewer({ content }: { content: string }) {
return <Viewer content={content} />;
}
import { Viewer } from "react-latex-editor";
function CustomStyledViewer({ content }: { content: string }) {
return (
<Viewer
content={content}
contentClassName="text-xl font-serif text-gray-900"
/>
);
}
import { Editor } from "react-latex-editor";
function CustomHeightEditor() {
return (
<Editor
minHeight="400px"
maxHeight="600px"
placeholder="Content with custom height..."
/>
);
}
import { Editor } from "react-latex-editor";
function EditorWithImageHandler() {
const handleImageRequest = () => {
// Open your image picker/modal here
const imageUrl = prompt("Enter image URL:");
if (imageUrl) {
// Handle image insertion
}
};
return (
<Editor
onImageSelectionRequest={handleImageRequest}
placeholder="Editor with custom image handling..."
/>
);
}
import { Editor } from "react-latex-editor";
function MinimalEditor() {
return (
<Editor
showCharacterCount={false}
showTableControls={false}
placeholder="Minimal editor..."
/>
);
}
import { Editor } from "react-latex-editor";
function DarkModeEditor() {
return (
<div className="dark-theme">
<Editor
placeholder="Dark mode editor..."
onChange={(content) => console.log(content)}
/>
</div>
);
}
import { Editor } from "react-latex-editor";
function MathEditor() {
return (
<Editor
initialContent="<p>Solve the equation: $x^2 + 5x + 6 = 0$</p>"
placeholder="Write mathematical content..."
onChange={(content) => console.log(content)}
/>
);
}
Import the default styles:
import "react-latex-editor/styles";
| Prop | Type | Default | Description |
|---|---|---|---|
initialContent | string | "<p>Start typing something...</p>" | Initial HTML content |
onChange | (content: string) => void | - | Content change callback |
placeholder | string | "Start typing..." | Placeholder text |
readOnly | boolean | false | Read-only mode |
autoFocus | boolean | false | Auto-focus on mount |
className | string | "" | Additional CSS classes |
onImageSelectionRequest | () => void | - | Image selection callback |
minHeight | string | "300px" | Minimum height |
maxHeight | string | - | Maximum height for scrolling |
showCharacterCount | boolean | true | Show character count |
showTableControls | boolean | true | Show table controls |
| Method | Parameters | Description |
|---|---|---|
getHTML | - | Get current HTML content |
setContent | content: string | Set editor content |
addImage | urls: string[] | Add images programmatically |
| Prop | Type | Default | Description |
|---|---|---|---|
content | string | - | HTML content to display |
className | string | "" | CSS classes for wrapper container |
contentClassName | string | "" | CSS classes for content div (text styling) |
enableMath | boolean | true | Enable MathJax rendering |
mathJaxConfig | object | {} | Custom MathJax configuration |
Styles not loading: Make sure to import the styles:
import "react-latex-editor/styles";
Math equations not rendering: Ensure MathJax is properly configured in the Viewer component.
TypeScript errors: Make sure you're using React 18+ and have the latest TypeScript definitions.
Images not uploading: Implement the onImageSelectionRequest callback
for custom image handling.
If you encounter any issues:
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
MIT License - see the LICENSE file for details.
Made with ❤️ by Bablu Mia
FAQs
A professional React rich text editor with mathematical equation support, built on TipTap with MathLive integration. Production-ready with TypeScript support, accessibility features, and industrial-grade error handling.
The npm package react-latex-editor receives a total of 106 weekly downloads. As such, react-latex-editor popularity was classified as not popular.
We found that react-latex-editor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.