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

react-tikzjax

v1.1.0

Published

React component for rendering LaTeX TikZ diagrams using TikZJax

Readme

React TikZJax

A React component for rendering LaTeX TikZ diagrams using the TikZJax library.

Installation

npm install react-tikzjax
# or
yarn add react-tikzjax

Prerequisites

Important: This component relies on the TikZJax JavaScript library and fonts. You must include these resources in the <head> of your main index.html file (or equivalent HTML template):

<head>
  <!-- Other head elements -->
  <script src="https://tikzjax-demo.think.somethingorotherwhatever.com/tikzjax.js" defer></script>
</head>

Failure to include these will result in errors, as the component calls the global window.process_tikz function provided by this library.

Usage

Here's a basic example of how to use the TikzJax component in your React application:

import React, { useState } from 'react';
import TikzJax from 'react-tikzjax';

function MyTikzComponent() {
  // State to hold the TikZ commands (without \begin{tikzpicture})
  const [tikzCommands, setTikzCommands] = useState('\\draw (0,0) circle (1in);');

  // Construct the full TikZ environment code
  const fullTikzCode = `\\begin{tikzpicture}
${tikzCommands}
\\end{tikzpicture}`;

  return (
    <div>
      <h2>Edit TikZ Code:</h2>
      <textarea
        value={tikzCommands}
        onChange={(e) => setTikzCommands(e.target.value)}
        rows="6"
        cols="50"
        placeholder="e.g., \\draw (0,0) -- (1,1); \\node at (0.5, 0.5) {Hello};"
      />
      
      <h2>Rendered Diagram:</h2>
      {/* Pass the full TikZ code to the component */}
      <TikzJax
        content={fullTikzCode}
        onError={(error) => {
          console.error("TikZ rendering failed:", error);
          // You could set state here to show an error message to the user
        }}
      />
    </div>
  );
}

export default MyTikzComponent;

Props

| Prop | Type | Required | Description | | :-------- | :------- | :------- | :-------------------------------------------------------------------------- | | content | string | Yes | The complete TikZ code, including the \begin{tikzpicture} and \end{tikzpicture} (or \begin{tikzcd}/\end{tikzcd}) environment. Remember to escape backslashes (\\draw instead of \draw). | | onError | func | No | A callback function (error: Error) => void that is invoked if rendering fails. |

Development (Building the Library with Vite)

If you are contributing to or building this library from source:

  1. Ensure you have Node.js installed.
  2. Clone or download the library source code.
  3. Install dependencies: npm install (or yarn install).
  4. Build the library: npm run build (or yarn build).
    • This uses Vite to bundle the library into the dist/ folder.
    • It produces react-tikzjax.mjs (ES Module) and react-tikzjax.umd.cjs (UMD) bundles, suitable for modern bundlers and direct browser usage, respectively.

Example Project

An example project demonstrating usage is available. Refer to the project structure or documentation for setup instructions.

Notes

  • Backslash Escaping: Because the content prop is a JavaScript string, you must escape backslashes. Use \\ instead of \ in your TikZ code strings.
  • Loading Order: Ensure the TikZJax scripts in your index.html are loaded before the TikzJax component attempts to render for the first time. Using defer on the script tag usually handles this correctly.
  • Cleanup: The component handles the creation and cleanup of the necessary DOM <script> elements internally.
  • Environments: While primarily designed for tikzpicture, it should also work with tikzcd environments as long as the full code is passed via the content prop.