npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

peach-math-field

v0.0.2

Published

A shadcn-native, highly customizable math editor

Readme

peach-math-field

A shadcn-native, highly customizable math editor for React. LaTeX-based with KaTeX rendering.

Features

  • shadcn-native styling: Uses CSS variables, automatically inherits your theme
  • LaTeX in/out: Accepts and outputs standard LaTeX
  • Virtual keyboard: Built-in math keyboard with Greek letters, operators, matrices
  • Accessible: Full keyboard navigation, ARIA labels, screen reader support
  • Composable: Use MathField, MathDisplay, and MathKeyboard independently

Installation

npm install peach-math-field

You also need KaTeX CSS for proper rendering:

import 'katex/dist/katex.min.css';
import 'peach-math-field/styles.css';

Quick Start

import { useState } from 'react';
import { MathField, MathDisplay } from 'peach-math-field';
import 'katex/dist/katex.min.css';
import 'peach-math-field/styles.css';

function App() {
  const [latex, setLatex] = useState('x^2 + y^2 = z^2');

  return (
    <div>
      <MathField
        value={latex}
        onChange={setLatex}
        placeholder="Enter math..."
      />
      <MathDisplay latex={latex} />
    </div>
  );
}

Components

MathField

Interactive math editor with cursor navigation and editing.

<MathField
  value={latex}                    // Controlled LaTeX string
  onChange={setLatex}              // Called on edit
  onSelectionChange={handleSel}    // Selection updates
  placeholder="Enter math..."
  readOnly={false}
  autoFocus={false}
  className="my-class"
/>

Ref methods:

  • focus() - Focus the field
  • blur() - Blur the field
  • insertLatex(latex: string) - Insert LaTeX at cursor

MathDisplay

Read-only math renderer.

<MathDisplay
  latex="\\frac{a}{b}"
  displayMode={false}              // true for block-level display
  errorColor="#cc0000"
  className="my-class"
/>

Convenience aliases:

  • <InlineMath latex="..." /> - Inline math
  • <BlockMath latex="..." /> - Block-level math

MathKeyboard

Virtual keyboard for touch devices or toolbar use.

<MathKeyboard
  mathFieldRef={mathFieldRef}      // Ref to MathField to control
  visible={true}
  onVisibilityChange={setVisible}
  defaultTab="basic"               // "basic" | "greek" | "operators" | "matrices"
/>

Keyboard Shortcuts

| Shortcut | Action | |----------|--------| | Tab | Move to next placeholder | | Shift+Tab | Move to previous placeholder | | Ctrl+Z / Cmd+Z | Undo | | Ctrl+Y / Cmd+Shift+Z | Redo | | Ctrl+A / Cmd+A | Select all | | Ctrl+C / Cmd+C | Copy selection or all | | Ctrl+V / Cmd+V | Paste LaTeX | | Arrow keys | Navigate cursor |

Theming

peach-math-field uses CSS variables that inherit from shadcn themes:

.math-field {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
}

.math-field:focus-within {
  outline: 2px solid hsl(var(--ring));
}

Define these variables in your app (or use a shadcn theme) and peach-math-field will match automatically.

Supported LaTeX

  • Fractions: \frac{a}{b}
  • Powers: x^{2}, x^2
  • Subscripts: x_{i}, x_i
  • Roots: \sqrt{x}, \sqrt[3]{x}
  • Parentheses: \left( \right), (), [], \{}
  • Greek letters: \alpha, \beta, \pi, etc.
  • Operators: +, -, \times, \div, =, \pm, \cdot
  • Functions: \sin, \cos, \log, etc.
  • Matrices: \begin{matrix}...\end{matrix}, \begin{pmatrix}, \begin{bmatrix}

Integration Examples

With Tiptap

See the examples/tiptap-demo directory for a complete Tiptap 3 integration with inline math support.

API Reference

Parser

import { parseLatex, serializeToLatex } from 'peach-math-field';

// Parse LaTeX to AST
const ast = parseLatex('\\frac{1}{2}');

// Serialize AST back to LaTeX
const latex = serializeToLatex(ast);

Commands

For programmatic editing, use commands:

import {
  insertFraction,
  insertSuperscript,
  moveLeft,
  deleteBackward,
  executeCommand,
} from 'peach-math-field';

// Execute a command on editor state
const newState = executeCommand(insertFraction(), currentState);

License

MIT