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

prosemirror-equation

v0.8.0

Published

Render and edit math equations (TeX) in ProseMirror.

Downloads

31

Readme

prosemirror-equation

🚧 Work in progress 🚧

NPM version

Write math equations with LaTeX in ProseMirror — this module provides block and inline node schemas, rendering with KaTeX, editing with CodeMirror in a popover UI, and an input rule to create inline equation nodes.

Design Principles

  • Opening or closing the equation editor should not cause any layout shift.
  • Users should be able to see the rendered equation while they edit the TeX.
  • Users should be able to open or close the editor—and start or finish editing—without taking their hands off the keyboard.

Key Features (try it yourself)

We’ve taken a lot of inspiration from how Notion designs its math equation experience.

  • Opens a popover editor next to the equation for editing TeX.
  • Uses CodeMirror to provide syntax highlighting in the editor.
  • Updates the rendered equation in real time as you type.
  • Lets you move into and out of an inline equation with the arrow keys.

In addition to user-facing features, we also offer the following developer-friendly benefits:

  • Unstyled, framework-agnostic, fully customizable UI.
  • Load KaTeX (264kB) and CodeMirror (242kB) dynamically—only when they’re actually needed—to keep your main JS bundle small.

Getting Started

We will walk you through the process of integrating prosemirror-equation into an existing ProseMirror project.

Install packages

npm i prosemirror-equation katex

You will import katex's CSS files in your project, so you need to install it as a dependency.

Set up CSS

Make sure you include the CSS files for katex and prosemirror-equation on any pages that will need them. They can be found at the following paths:

node_modules/katex/dist/katex.min.css
node_modules/prosemirror-equation/style/equation.css

If you are using a bundler like vite, you may be able to include the CSS files in your JavaScript entry point like this:

import 'katex/dist/katex.min.css'
import 'prosemirror-equation/style/equation.css'

Or in your CSS entry point like this:

@import 'katex/dist/katex.min.css';
@import 'prosemirror-equation/style/equation.css';

Set up schema

Add equation nodes to your ProseMirror schema.

For example, if you are using the schema from prosemirror-schema-basic:

import { Schema } from 'prosemirror-model'
import { schema as baseSchema } from 'prosemirror-schema-basic'
import { equationNodes } from 'prosemirror-equation'

const schema = new Schema({
  nodes: baseSchema.spec.nodes.append(
    equationNodes({
      blockEquationGroup: 'block',
      inlineEquationGroup: 'inline',
    })
  ),
  marks: baseSchema.spec.marks,
})

Set up plugins

Add the pre-configured equation plugin to your ProseMirror state:

import { EditorState } from 'prosemirror-state'
import { equationExampleSetup } from 'prosemirror-equation/example-setup'

const state = EditorState.create({
  schema,
  plugins: [equationExampleSetup()],
})

The pre-configured plugin includes default UI components for rendering and editing math equations.

Optional: Set up input rules

We provide an input rule that lets you type $$...$$ to create inline equation nodes. You can add it to your editor setup with the inputRules plugin from prosemirror-inputrules.

import { EditorState } from 'prosemirror-state'
+import { inputRules } from 'prosemirror-inputrules'
+import { inlineEquationInputRule } from 'prosemirror-equation'
import { equationExampleSetup } from 'prosemirror-equation/example-setup'

const state = EditorState.create({
  schema,
  plugins: [
    equationExampleSetup(),
+   inputRules({
+     rules: [
+       inlineEquationInputRule(),
+     ],
+   }),
  ],
})

Next steps

Congratulations, you're all set up with the math equation functionality! In the next section, we'll guide you through how to further customize it to fit your needs.

If you want to have a clearer picture of how to put the pieces together, check out our demo code in demo/demo.ts or tinker with it live in the online code editor:

Open in StackBlitz

Customizing

Styling

You can copy style/equation.css to your project and modify it.

Modifying element structures and behaviors

Instead of using the pre-configured equationExampleSetup() function from prosemirror-equation/example-setup, you can use equation() function from prosemirror-equation to provide your own implementations of renderEditor and renderNode.

For example, below is how the equationExampleSetup() function is implemented:

import { equation } from 'prosemirror-equation'
import { createEquationEditorRenderer } from 'prosemirror-equation/components/equation-editor'
import { renderEquationNode } from 'prosemirror-equation/components/equation-node'

export function equationExampleSetup() {
  return equation({
    renderEditor: createEquationEditorRenderer({
      loadTexEditorTheme: async () =>
        (await import('prosemirror-equation/components/tex-editor-codemirror'))
          .editorTheme,
    }),
    renderNode: renderEquationNode,
  })
}

You can reuse the components that come with the prosemirror-equation package by importing them from prosemirror-equation/components/*.

Styling our CodeMirror-based TeX editor

You can replace loadTexEditorTheme in the previous snippet with your own implementation to provide your own CodeMirror theme.

Syntax highlighting

Modify the .cm-line .token.xxx classes in style/equation.css.

Ready-made CodeMirror themes

Prior Art

ProseMirror-based alternatives

Not ProseMirror-based — for UX reference

About This Repository

The important files in this repository are:

  • demo/: The demo website.
  • src/
    • schema.ts: Schemas of block and inline equation nodes.
    • equation.ts: A ProseMirror Plugin that registers NodeViews and enables opening equation editor programmatically.
    • equationNodeView.ts: A NodeView which renders TeX equations and provides interactivity.
    • equationInputRules.ts: Contains an InputRule that lets user create inline equation nodes by typing $$equation$$.

To-do

Development

Install dependencies

pnpm install

Develop the library with demo

pnpm run dev

Run the unit tests

pnpm run test

Build the library

pnpm run build

Build the demo

pnpm run build:demo

Analyze bundle with demo

pnpm run analyzeBundle

and navigate to http://localhost:8888/

Other notes

  • This repository uses gh:@googleapis/release-please to create releases automatically. Add Release-As: x.y.z to the commit body to mark the version of the commit.

License

MIT

Closing Note

Chat with DeepWiki about anything not covered in the documentation or that needs more clarification:

Ask DeepWiki