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

@caporeista/math-latex

v1.0.4

Published

A powerful and lightweight React component to render complex LaTeX, MathML, and HTML content seamlessly with Markdown support.

Downloads

333

Readme

Math-Latex

This package was created to render mixed HTML and LaTeX expressions within a single, powerful React component. It uses KaTeX for fast and beautiful mathematical typesetting.

This package is designed to parse a single string containing mixed content (text, LaTeX, and HTML tags like <img>) and render it correctly in your React application.

Tested and working with Next.js 14 and 15.

Features

  • Mixed Content Rendering: Renders strings containing plain text, LaTeX, and HTML tags in the correct order.
  • High-Quality Typesetting: Uses KaTeX for beautiful and fast math rendering.
  • HTML Support: Renders HTML tags like <img> directly, allowing you to embed images and other HTML content alongside your formulas.
  • SSR Friendly: Works seamlessly with Server-Side Rendering (SSR) frameworks like Next.js.
  • Lightweight and Simple API: A single component is all you need.

Installation

Using yarn:

yarn add @caporeista/math-latex

Using npm:

npm install @caporeista/math-latex

Usage

Simply import the MathLatex component and pass your content string as a child.

import React from 'react';
import MathLatex from '@caporeista/math-latex';
import 'katex/dist/katex.min.css'; // Don't forget to import KaTeX styles

const content = `
  The solution to the equation $$x^2+y^2=z^2$$ is a Pythagorean triple.
  Here is an image related to the topic:
  <img src="https://res.cloudinary.com/dgkk9picj/image/upload/v1752141385/ocr-images/file_fbcfqr.jpg" alt="example" width="300" />
  And here is an inline formula: $E=mc^2$.
`;

function MyComponent() {
  return (
    <div>
      <h1>My Document</h1>
      <MathLatex>{content}</MathLatex>
    </div>
  );
}

export default MyComponent;

Important: You must import the KaTeX CSS file (katex/dist/katex.min.css) in your application's entry point (e.g., _app.tsx in Next.js or index.js in Create React App) for the mathematical formulas to be styled correctly.

How It Works

The component intelligently parses the input string, splitting it into three types of parts:

  1. LaTeX expressions (e.g., $E=mc^2$ or $$...$$)
  2. HTML tags (e.g., <img>)
  3. Plain text

It then renders each part accordingly, using KaTeX for the math and standard React elements for the rest. This ensures that all content appears in the correct order and format.

Support

If you find this project helpful, consider supporting me with a coffee!