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

@notatki/math

v0.10.0

Published

A collection of tools for creating and syncing Anki notes from simple text files.

Downloads

132

Readme

@notatki/math

A formatter for LaTeX math source, with no dependencies. It works on one math expression at a time, without its $ or \[ delimiters, and rewrites it to follow a consistent style. It is used by notatki format for math in notes, and by mathfmt for .tex files.

The formatter is a lenient parser and a printer, not a TeX engine. It does not expand macros, and it only changes things that it knows TeX reads the same way: optional whitespace, braces around single-token arguments, and \left/\right around parentheses. Formatting is idempotent.

Usage

import { format } from "@notatki/math";

format("x=1,\\int_0^1f\\,dx", { spacing: "padded" });
// "x = 1, \\int_0^1 f\\,dx"

format(src, options?) returns the formatted source. If src cannot be parsed, it is returned unchanged.

Options

All options default to "unchanged", so format(src) returns src as it was written.

| Option | Values | Effect | | --------------- | -------------------------------- | ------------------------------------------------ | | parens | add, normalize, unchanged | \left and \right around parentheses | | braceCommands | add, remove, unchanged | braces around arguments of \frac, \sqrt, ... | | braceScripts | add, remove, unchanged | braces around arguments of ^ and _ | | spacing | compact, padded, unchanged | whitespace that TeX ignores in math |

The values are also exported as the PARENS, BRACES and SPACINGS arrays.

parens

  • add wraps plain parentheses around tall content such as fractions, integrals and sums: (\frac12) becomes \left(\frac12\right).
  • normalize also removes \left and \right where they are not needed: \left(x\right)+\left(x^2\right) becomes (x)+\left(x^2\right). It is conservative: they stay unless the content is only letters, digits, punctuation and plain commands. Explicit sizes such as \bigl are never touched.

braceCommands and braceScripts

  • add: \frac12 becomes \frac{1}{2}, and x^2 becomes x^{2}.
  • remove: \frac{1}{2} becomes \frac12. Braces are removed only where TeX reads the argument the same way without them, that is around a single letter, digit or control word. x^{10} and x^{-1} keep theirs, and a space is added where a control word would swallow the next letter.

spacing

  • compact removes optional whitespace: 1 + 2 = 3, (a, b) becomes 1+2=3,(a,b).
  • padded removes it, then puts one space after commas and around relations, binary operators (not + and -) and \quad, and after \int-like operators and named functions: x=1,\int_0^1f becomes x = 1, \int_0^1 f. Scripts stay compact, and a&=b becomes a &= b.

Whitespace that matters is always kept: between a control word and a letter (\alpha x), between digits, around line breaks, and inside \text-like arguments.

Lower-level API

format is print(rewrite(parse(src), options)). These pieces are exported too:

  • tokenize(src) splits the source into tokens, and throws LatexParseError on malformed input.
  • parse(src) builds a tree of the node types in nodes.ts. print(parse(src)) reproduces src exactly.
  • rewrite(tree, options) applies the options to a tree.
  • resolveOptions(options) validates the options and fills in the defaults.