A Desmos-like math equation editor component library for React. Build beautiful, interactive math input experiences for educational platforms.
- 🎨 Beautiful UI - Desmos-inspired design with light and dark themes
- ⌨️ On-Screen Keyboard - Full math keyboard with symbols, functions, and operators
- 📱 Context-Aware - Multi-input support with automatic keyboard routing
- 🔢 13 Function Categories - Complete set of math functions from Trig to Calculus
- ⚡ TypeScript - Full type safety and IntelliSense support
- 🎯 Lightweight - Tree-shakeable and optimized for production
npm install mathex-editorimport { MathProvider, MathInput, MathKeyboard } from 'mathex';
function App() {
const [latex, setLatex] = useState('x^2 + 3x + 1');
return (
<MathProvider theme="light">
<MathInput
value={latex}
onChange={setLatex}
placeholder="Enter equation..."
/>
<MathKeyboard />
</MathProvider>
);
}Mathex supports both light and dark themes out of the box.
<MathProvider theme="light">
<MathInput />
<MathKeyboard />
</MathProvider><MathProvider theme="dark">
<MathInput />
<MathKeyboard />
</MathProvider>function App() {
const [theme, setTheme] = useState<'light' | 'dark'>('light');
const toggleTheme = () => {
setTheme(current => current === 'light' ? 'dark' : 'light');
};
return (
<MathProvider theme={theme}>
<button onClick={toggleTheme}>
{theme === 'light' ? '🌙 Dark Mode' : '☀️ Light Mode'}
</button>
<MathInput />
<MathKeyboard />
</MathProvider>
);
}You can customize the theme by providing a ThemeConfig object:
const customTheme = {
colors: {
primary: '#FF5722',
background: '#FFF',
text: '#000',
border: '#CCC',
},
// ... more customization options
};
<MathProvider theme={customTheme}>
<MathInput />
<MathKeyboard />
</MathProvider>The context provider that manages global state and communication between components.
Props:
theme-'light' | 'dark' | ThemeConfig- Theme configuration (default:'light')children- React components to wrap
An input field for entering and displaying mathematical equations.
Props:
value-string- LaTeX string (controlled mode)defaultValue-string- LaTeX string (uncontrolled mode)onChange-(latex: string) => void- Callback when value changesplaceholder-string- Placeholder textdisabled-boolean- Disable inputclassName-string- Additional CSS classesstyle-CSSProperties- Inline stylesonError-(error: Error) => void- Error callback
An on-screen keyboard for entering math symbols and functions.
Props:
isVisible-boolean- Control keyboard visibilityonVisibilityChange-(visible: boolean) => void- Visibility change callbackclassName-string- Additional CSS classesstyle-CSSProperties- Inline styles
Mathex automatically handles multiple inputs - the keyboard routes input to whichever field is focused:
<MathProvider theme="light">
<div>
<label>Equation 1:</label>
<MathInput value={latex1} onChange={setLatex1} />
</div>
<div>
<label>Equation 2:</label>
<MathInput value={latex2} onChange={setLatex2} />
</div>
<div>
<label>Equation 3:</label>
<MathInput value={latex3} onChange={setLatex3} />
</div>
{/* One keyboard routes to all inputs */}
<MathKeyboard />
</MathProvider>The keyboard includes all 13 function categories from Desmos:
- Trig Functions - sin, cos, tan, csc, sec, cot
- Inverse Trig - sin⁻¹, cos⁻¹, tan⁻¹, csc⁻¹, sec⁻¹, cot⁻¹
- Calculus - exp, ln, log, d/dx, ∫, Σ, Π
- Number Theory - lcm, gcd, mod, ceil, floor, round, ⁿ√, nPr, nCr
- Hyperbolic Trig - sinh, cosh, tanh, csch, sech, coth
- Statistics - mean, median, min, max, stdev, var, corr, and more
- Probability - normaldist, tdist, binomialdist, pdf, cdf, random
- Inference - ztest, ttest, chisqtest, confidence intervals
- List Operations - repeat, join, sort, shuffle, unique
- Visualizations - histogram, dotplot, boxplot
- Geometry - polygon, distance, midpoint
- Custom Colors - rgb, hsv, oklab, oklch
- Sound - tone
- Default Mode - Numbers, operators, variables, and common symbols
- ABC Mode - QWERTY keyboard for entering letters and Greek symbols
MIT
Contributions welcome! Please open an issue or PR on GitHub.
For questions or issues, please visit our GitHub Issues.