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

html-to-latex

v0.8.0

Published

convert html to latex

Readme

[IN DEVELOPMENT]

Install

$ npm install html-to-latex

Usage

Converting html text:

import { convertText } from 'html-to-latex';

const html = `<p>Styled <b>Text</b></p>`;
const tex = await convertText(html);

console.log(tex)
//\documentclass{article}
//
//\begin{document}
//
//Styled \textbf{Text}
//
//\end{document}

Converting html file:

import { convertFile } from 'html-to-latex';

const html = 'filePath.html';

await convertFile(html);

API

convertText(htmlText, options?)

Returns: Promise<string>

Converts the input htmlText to a valid latex string.

htmlString

Type: string

options

Type: object

ignoreBreaks

Type: boolean Default: true CLI Options: -ib or --ignore-breaks

Instead of replacing <br/> with //, ending the line, a simple space character is inserted instead.

preferDollarInlineMath

Type: boolean Default: false CLI Options: -dm or --prefer-dollar-inline-math

Replace \( and \) with $.

skipWrappingEquations

Type: boolean Default: false CLI Options: -swe or --skip-wrapping-equations

Is an equation is defined in a p tag without any other content besides that equation, it will automatically be wrapped in \[ and \].

includeDocumentWrapper

Type: boolean Default: false CLI Options: -dw or --include-document-wrapper

Adds a latex document wrapper around the converted text. This is required to have a valid latex file:

\documentclass{article}

\begin{document}
%...converted text
\end{document}
documentClass

Type: string Default: article CLI Options: -dc or --document-class

If a document wrapper is added, the document class will be set.

\documentclass{article}
%...
includePackages

Type: string[] Default: []* CLI Options: -ip or --include-packages

If the document wrapper is added, a list of used packages will be set.

\documentclass{article}

\usepackage{packagename}

\begin{document}
%...converted text
\end{document}

*If nothing is specified, the list of includes packages will be inferred from the html:

| Tag | Added Package | |--------|---------------| | \cfrac | amsmath | | \img | graphicx | | \therefore | amssymb |

title

Type: string Default: undefined CLI Options: -t or --title

If a document wrapper is added, the title will be set.

\documentclass{article}

\title{Altered Carbon}

\begin{document}
%...converted text
\end{document}
author

Type: string Default: undefined CLI Options: -a or --author

If a document wrapper is added, the author will be set.

\documentclass{article}

\author{Takashi Kovacs}

\begin{document}
%...converted text
\end{document}
includeDate

Type: boolean Default: false CLI Options: -d or --incude-date

If a document wrapper is added, the current date will be set.

\documentclass{article}

\date{\today}

\begin{document}
%...converted text
\end{document}
compilationDir

Type: string Default: process.cwd CLI Options: -cdr or --compilation-dir

If any images need to be downloaded for the latex compilation, they will be places in a 'images' subdirectory inside this directory.

autoGenImageNames

Type: boolean Default: true CLI Options: -ain or --autogen-image-names

To avoid any weird file names, image files that are downloaded are automatically given a random Id with the extension of the original file. This can be turned off by passing a false value.

imageWidth

Type: string Default: undefined CLI Options: -iw or --image-width

Allows you to set a image width. This would be in the form normally accepted by latex such as: 2cm

imageHeight

Type: string Default: undefined CLI Options: -ih or --image-height

Allows you to set a image height. This would be in the form normally accepted by latex such as: 2cm

keepImageAspectRatio

Type: boolean Default: undefined CLI Options: -kar or --keep-aspect-ratio

Allows you to maintain the aspect ratio of the image. This also requires either the image width property or image height property to be set.

debug

Type: boolean Default: false CLI Options: --debug

Prints error messages when they occur such as when an image cannot be found at the given url.

convertFile(filepath, options?)

CLI: available (see options for cli option names) Returns: Promise

Converts the input file to a valid latex file.

filepath

Type: string CLI Option: Positional, or -ifp

Path of html file

options

Type: object

All options included in .... and

includeDocumentWrapper option is defaulted to true for this function, as it would make more sense to do so

outputFilepath

Type: string Default: filepath (The input file path) CLI Option: -ofp or --output-file-path

The output filepath of the converted file. By default it will overwrite the input file.

CLI API

The same arguments are valid for the cli. The cli is exposed under html-to-latex executable and has the functions: convert-file and convert-text. Run html-to-latex --help for more information.

Improving output

Ignoring br tags

Instead designate new sections/paragraphs using the proper html tag such as a <p>