New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

latex2js

Package Overview
Dependencies
Maintainers
0
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

latex2js

LaTeX and PSTricks rendering & components for the Web

latest
Source
npmnpm
Version
3.1.4
Version published
Maintainers
0
Created
Source

latex2js

The core LaTeX parsing and rendering engine for LaTeX2JS. This package provides the fundamental LaTeX-to-HTML conversion functionality with support for mathematical notation, environments, and PSTricks graphics.

Installation

npm install latex2js

Features

  • Mathematical Notation: Seamless integration with MathJax for math rendering
  • PSTricks Graphics: Support for interactive PSTricks diagrams
  • Environment Support: Built-in support for common LaTeX environments

API Reference

LaTeX2HTML5 Class

The main parser class for converting LaTeX to HTML:

import { LaTeX2HTML5 } from 'latex2js';

const parser = new LaTeX2HTML5();
const html = parser.parse(latexContent);

Methods

// Parse LaTeX content to HTML
parse(latex: string): string

// Add custom macros
addMacros(macros: string): void

// Parse specific environments
parseEnvironment(envName: string, content: string): string

// Process headers and metadata
processHeaders(latex: string): HeaderInfo

Usage Examples

Basic Document Parsing

import { LaTeX2HTML5 } from 'latex2js';

const parser = new LaTeX2HTML5();

const latexDocument = `
The quadratic formula is:
$$x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}$$

\\begin{pspicture}(-1,-1)(1,1)
  \\pscircle(0,0){0.8}
  \\rput(0,0){Circle}
\\end{pspicture}
`;

const parsed = parser.parse(latexDocument);

Custom Macros Integration

import { LaTeX2HTML5 } from 'latex2js';
import macros from '@latex2js/macros';

const parser = new LaTeX2HTML5();

// Add predefined macros
parser.addMacros(macros);

// Add custom macros
const customMacros = `
\\newcommand{\\R}{\\mathbb{R}}
\\newcommand{\\norm}[1]{\\left\\|#1\\right\\|}
\\newcommand{\\abs}[1]{\\left|#1\\right|}
`;

parser.addMacros(customMacros);

const content = `
For any vector $\\vec{v} \\in \\R^n$, we have:
$$\\norm{\\vec{v}} = \\sqrt{\\sum_{i=1}^n v_i^2}$$

And for any real number $x \\in \\R$:
$$\\abs{x} = \\begin{cases}
x & \\text{if } x \\geq 0 \\\\
-x & \\text{if } x < 0
\\end{cases}$$
`;

const result = parser.parse(content);

Keywords

latex

FAQs

Package last updated on 22 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts