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

hast-latex

v0.1.0

Published

Converts HAST to Unified LaTeX AST

Readme

hast-latex

A small unifiedJS plugin that turns an HTML/HAST tree into a LaTeX AST (see unified-latex) so you can render, lint, or emit .tex from HTML sources. Designed for book-like documents (ebooks, etc.) where you want headings, chapters, metadata, and inline formatting to map cleanly into LaTeX.

Installation

npm install hast-latex rehype-parse unified @unified-latex/unified-latex-util-to-string

Quick start

The plugin consumes a HAST tree (e.g., from rehype-parse) and returns a unified-latex AST you can stringify with @unified-latex/unified-latex-util-to-string.

import { unified } from 'unified'
import rehypeParse from 'rehype-parse'
import { hastLatex } from 'hast-latex'
import { unifiedLatexStringCompiler } from '@unified-latex/unified-latex-util-to-string'

const html = `<html><head><meta name="title" content="Example" /></head><body><h1>Hello</h1><p>World.</p></body></html>`

// Build HAST from HTML
const rehypeProcessor = unified()
  .use(rehypeParse)
  .use(hastLatex, { documentClass: 'book' })

const hast = rehypeProcessor.parse(html)
const latexAst = rehypeProcessor.runSync(hast)

// Turn LaTeX AST into a .tex string
const latex = unified().use(unifiedLatexStringCompiler).stringify(latexAst)

console.log(latex)

API

hastLatex(options?)

Unified plugin that converts HAST → unified-latex AST.

Options:

  • documentClass: 'article' | 'report' | 'book' (default: 'book'). Used for the emitted \documentclass{...} macro.
  • makeTitle: boolean (default: false). When true, inserts \maketitle and uses metadata from the HTML <head> (e.g., <meta name="title">, <meta name="author">, dc.title, dc.creator) to populate \title{} and \author{}.
  • macroReplacements: Record<string, string> mapping CSS selectors to LaTeX macro names for inline styling (e.g., { 'b,strong': 'textbf', 'i,em': 'textit' }). This lets you customize how inline HTML is converted to LaTeX commands.

Default macroReplacements:

{
  'b,strong': 'textbf',
  'i,em': 'textit',
  u: 'underline',
  's,strike,del': 'sout',
}

Advanced usage

import { unified } from 'unified'
import rehypeParse from 'rehype-parse'
import { hastLatex } from 'hast-latex'
import { unifiedLatexStringCompiler } from '@unified-latex/unified-latex-util-to-string'

const html = `<!doctype html><html><head>
  <meta name="title" content="My Book" />
  <meta name="author" content="Jane Doe" />
</head><body>
  <h1 class="starred">Intro</h1>
  <p><span class="smcap">Small Caps</span> and <u>underline</u>.</p>
</body></html>`

const processor = unified()
  .use(rehypeParse)
  .use(hastLatex, {
    documentClass: 'book',
    makeTitle: true,
    macroReplacements: {
      'span.smcap': 'textsc',
      u: 'underline',
    },
  })

const hast = processor.parse(html)
const latexAst = processor.runSync(hast as any)
const latex = unified().use(unifiedLatexStringCompiler).stringify(latexAst)

console.log(latex)

Notes & limitations

  • Currently focused on book-like prose from ebook sources. Lists, images, tables, math, footnotes, etc., are not yet mapped.
  • HTML must include a <html><head>...</head><body>...</body></html> structure for metadata extraction.
  • Output is a LaTeX AST; you choose when/how to stringify or compile it.
  • API and output shape will change; pinned at 0.x while iterating.