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

kern-typ

v0.2.0

Published

Fast, zero-dependency Typst math renderer for the browser

Readme

kern

A fast, zero-dependency JavaScript library that renders Typst math syntax to HTML/CSS/MathML in the browser. Drop-in alternative to KaTeX for projects that prefer Typst's cleaner math syntax.

kern.render('frac(x^2 + 1, 2 x)', document.getElementById('math'));
kern.render('sum_(i=0)^n i = frac(n(n+1), 2)', el);

Installation

npm install kern-typ
# or
pnpm add kern-typ

The npm package is kern-typ because kern was already registered. The library still calls itself kern everywhere else: CSS class prefix kern-, UMD global kern, import path kern-typ.

Quick start

Browser (CDN)

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/kern-typ/styles/kern.css">
<script src="https://cdn.jsdelivr.net/npm/kern-typ/dist/kern.min.js"></script>

<div id="math"></div>
<script>
  kern.render('frac(a, b)', document.getElementById('math'));
</script>

ESM

import { render, renderToString } from 'kern-typ';
import 'kern-typ/kern.css';  // for HTML output

render('x^2 + y^2 = r^2', el);
const html = renderToString('e^(i pi) + 1 = 0');

Auto-render

Automatically render all math in a page:

import renderMathInElement from 'kern-typ/auto-render';

renderMathInElement(document.body, {
  delimiters: [
    { left: '$$', right: '$$', display: true },
    { left: '$', right: '$', display: false },
  ],
});

API

kern.render(source, element, options?)

Renders source into element, replacing its contents.

kern.renderToString(source, options?)

Returns the rendered HTML string.

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | displayMode | boolean | false | Display (block) vs inline mode | | output | 'mathml' \| 'html' \| 'htmlAndMathml' | 'mathml' | Output format | | throwOnError | boolean | true | Throw ParseError on invalid input | | errorColor | string | '#cc0000' | Color for error messages when throwOnError is false | | macros | Record<string, string> | {} | Custom macro definitions | | strict | boolean \| 'ignore' \| 'warn' \| 'error' | 'warn' | Strictness level | | trust | boolean \| function | false | Trust level for security-sensitive features |

Typst math syntax

Kern implements Typst's math mode syntax. Key differences from LaTeX:

| Feature | LaTeX | Typst | |---------|-------|-------| | Fraction | \frac{a}{b} | frac(a, b) or a/b | | Square root | \sqrt{x} | sqrt(x) | | Subscript | x_{n+1} | x_(n+1) | | Superscript | x^{2} | x^2 | | Bold | \mathbf{x} | bold(x) | | Calligraphic | \mathcal{A} | cal(A) | | Blackboard bold | \mathbb{R} | bb(R) | | Vector | \begin{pmatrix}a\\b\end{pmatrix} | vec(a, b) | | Matrix | \begin{pmatrix}1&0\\0&1\end{pmatrix} | mat(1,0;0,1) | | Text | \text{hello} | "hello" |

Symbols

Multi-letter identifiers are rendered as upright operator names (sin, cos, lim), single letters are italic variables (x, y, z).

Named symbols:

alpha  beta  gamma  delta  epsilon  pi  omega
infinity  partial  nabla  forall  exists
arrow.r  arrow.l  arrow.r.long  arrow.r.double
eq.not  lt.eq  gt.eq  approx  sim
sum  product  integral

Dotted modifiers: arrow.r.long, eq.not, lt.eq.not, etc.

Math functions

frac(a, b)       – fraction
sqrt(x)          – square root
root(3, x)       – nth root
binom(n, k)      – binomial coefficient
vec(a, b, c)     – column vector
mat(1,0; 0,1)    – matrix
cases(x, y)      – case expression
lr((expr))       – auto-sized delimiters
abs(x)           – absolute value |x|
norm(x)          – norm ‖x‖
cal(A)           – calligraphic style
bb(R)            – blackboard bold
frak(g)          – fraktur
bold(x)          – bold
italic(x)        – italic
upright(d)       – upright/roman

Spacing

thin, med, thick, quad, qquad

Fonts

By default, kern uses KaTeX's web fonts (loaded from cdnjs). For Typst visual parity, include kern-newcm.css instead:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/kern-typ/styles/kern-newcm.css">

Migration from KaTeX

The API is intentionally identical to KaTeX's:

// KaTeX
katex.render('\\frac{a}{b}', el);

// kern
kern.render('frac(a, b)', el);

Main differences:

  • Source syntax is Typst, not LaTeX
  • No backslash commands; use function call syntax instead
  • Spaces separate atoms (no {} grouping required for single-character args)

License

MIT