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

@latex2js/utils

v3.0.12

Published

latex2js utilities

Downloads

135

Readme

@latex2js/utils

Core utility functions for LaTeX parsing, SVG manipulation, and mathematical computations used throughout the LaTeX2JS ecosystem.

Installation

npm install @latex2js/utils

Features

  • String Processing: Advanced pattern matching and replacement utilities
  • Unit Conversion: Convert between different measurement units (px, em, pt, cm, etc.)
  • Coordinate Transformation: Mathematical coordinate system transformations
  • Mathematical Evaluation: Safe evaluation of mathematical expressions
  • SVG Manipulation: D3-like interface for SVG DOM manipulation
  • LaTeX Parsing: Utilities for parsing LaTeX options and arrows

API Reference

String Utilities

import { simplerepl, matchrepl } from '@latex2js/utils';

// Simple string replacement
const result = simplerepl(text, 'pattern', 'replacement');

// Pattern matching with capture groups
const result = matchrepl(text, /(\w+)=(\w+)/, (match, key, value) => {
  return `${key}: ${value}`;
});

Unit Conversion

import { convertUnits } from '@latex2js/utils';

// Convert units to pixels
const pixels = convertUnits('2cm'); // Returns pixel equivalent
const pixels2 = convertUnits('12pt'); // Returns pixel equivalent

Coordinate Transformation

import { X, Y, Xinv, Yinv } from '@latex2js/utils';

// Transform coordinates based on current coordinate system
const screenX = X(mathematicalX);
const screenY = Y(mathematicalY);

// Inverse transformations
const mathX = Xinv(screenX);
const mathY = Yinv(screenY);

Mathematical Expression Evaluation

import { evaluate } from '@latex2js/utils';

// Safely evaluate mathematical expressions
const result = evaluate('2 * pi + sin(pi/4)');
const result2 = evaluate('sqrt(16) + log(e)');

SVG Manipulation

import { select, SVGSelection } from '@latex2js/utils';

// D3-like interface for SVG manipulation
const svg = select(svgElement);

svg.append('line')
   .attr('x1', 0)
   .attr('y1', 0)
   .attr('x2', 100)
   .attr('y2', 100)
   .attr('stroke', 'black');

svg.append('circle')
   .attr('cx', 50)
   .attr('cy', 50)
   .attr('r', 25)
   .attr('fill', 'red');

LaTeX Parsing Utilities

import { parseOptions, parseArrows } from '@latex2js/utils';

// Parse LaTeX command options
const options = parseOptions('[linecolor=red, fillcolor=blue]');
// Returns: { linecolor: 'red', fillcolor: 'blue' }

// Parse arrow specifications
const arrows = parseArrows('->');
// Returns arrow configuration object

Usage in LaTeX2JS Ecosystem

This package serves as the foundation for all other LaTeX2JS packages:

  • @latex2js/settings: Uses utilities for option parsing and unit conversion
  • @latex2js/pstricks: Heavily relies on coordinate transformation and SVG manipulation
  • latex2js: Uses string processing utilities for LaTeX parsing
  • latex2html5: Uses SVG utilities for rendering graphics