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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mathjaxjs

v3.0.10

Published

MathJax loading utilities

Readme

mathjaxjs

Pure HTML5 MathJax loading utilities without React dependencies. This package provides a simple way to load and configure MathJax v3 for LaTeX mathematical notation rendering in web applications.

Installation

npm install mathjaxjs

Features

  • Framework Agnostic: Works with any JavaScript framework or vanilla HTML
  • Async Loading: Non-blocking MathJax loading from CDN
  • Configurable: Customizable MathJax configuration
  • Lightweight: Minimal dependencies

API Reference

loadMathJax()

Asynchronously loads MathJax from CDN with configuration:

import { loadMathJax } from 'mathjaxjs';

// Load with default configuration
await loadMathJax();

// Load with custom configuration
await loadMathJax({
  tex: {
    inlineMath: [['$', '$'], ['\\(', '\\)']],
    displayMath: [['$$', '$$'], ['\\[', '\\]']],
    macros: {
      RR: "\\mathbb{R}",
      ZZ: "\\mathbb{Z}"
    }
  },
  svg: {
    fontCache: 'global'
  }
});

getMathJax()

Returns the current MathJax instance:

import { getMathJax } from 'mathjaxjs';

// Get MathJax instance (after loading)
const MathJax = getMathJax();

if (MathJax) {
  // Manually typeset content
  MathJax.typesetPromise([element]);
  
  // Re-render all math
  MathJax.typesetPromise();
}

DEFAULT_CONFIG

The default MathJax configuration object:

import { DEFAULT_CONFIG } from 'mathjaxjs';

console.log(DEFAULT_CONFIG);
// Output: Default MathJax v3 configuration

Usage Examples

Basic Usage

<!DOCTYPE html>
<html>
<head>
  <title>MathJax Example</title>
</head>
<body>
  <div id="math-content">
    <p>Inline math: $E = mc^2$</p>
    <p>Display math: $$\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}$$</p>
  </div>

  <script type="module">
    import { loadMathJax } from 'mathjaxjs';
    
    // Load MathJax and automatically typeset page
    await loadMathJax();
  </script>
</body>
</html>

Dynamic Content

import { loadMathJax, getMathJax } from 'mathjaxjs';

// Initialize MathJax
await loadMathJax();

// Function to add mathematical content dynamically
function addMathContent(container, latexString) {
  const mathElement = document.createElement('div');
  mathElement.innerHTML = `$$${latexString}$$`;
  container.appendChild(mathElement);
  
  // Typeset the new content
  const MathJax = getMathJax();
  if (MathJax) {
    MathJax.typesetPromise([mathElement]);
  }
}

// Usage
const container = document.getElementById('math-container');
addMathContent(container, '\\sum_{n=1}^{\\infty} \\frac{1}{n^2} = \\frac{\\pi^2}{6}');

Custom Configuration

import { loadMathJax } from 'mathjaxjs';

const customConfig = {
  tex: {
    // Enable additional packages
    packages: ['base', 'ams', 'physics', 'color'],
    
    // Custom macros
    macros: {
      // Vectors
      'vb': ['\\mathbf{#1}', 1],
      'va': ['\\vec{#1}', 1],
      
      // Common sets
      'R': '\\mathbb{R}',
      'N': '\\mathbb{N}',
      'Z': '\\mathbb{Z}',
      'Q': '\\mathbb{Q}',
      'C': '\\mathbb{C}',
      
      // Derivatives
      'dd': ['\\,\\mathrm{d}#1', 1],
      'dv': ['\\frac{\\mathrm{d}#1}{\\mathrm{d}#2}', 2],
      'pdv': ['\\frac{\\partial#1}{\\partial#2}', 2]
    },
    
    // Enable tags and labels
    tags: 'ams',
    
    // Process dollar delimiters
    processEscapes: true
  },
  
  // SVG output configuration
  svg: {
    fontCache: 'global',
    displayAlign: 'center',
    displayIndent: '0em'
  },
  
  // Startup configuration
  startup: {
    ready: () => {
      console.log('MathJax is ready!');
    }
  }
};

await loadMathJax(customConfig);