Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

escape-latex

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

escape-latex

Escape LaTeX special characters with Javascript

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1M
increased by4.54%
Maintainers
1
Weekly downloads
 
Created
Source

escape-latex

Greenkeeper badge

Build Status

Escape LaTeX special characters with Javascript in NodeJS (>= 4.x) environment.

Usage

npm install escape-latex
var lescape = require('escape-latex');
lescape("String to be escaped here #yolo");

API

lescape((input: String), {
  preserveFormatting: Boolean,
  escapeMapFn: Function,
});

By default, escape-latex only escapes characters that would result in malformed LaTeX. These characters include # $ % & \ ^ _ { }.

This means that the final LaTeX output might not look the same as your input Javascript string. For example, multiple spaces are kept as-is, which may be truncated to 1 space by your LaTeX software.

If you want the final output string to be as similar to your input Javascript string as possible, you can set the preserveFormatting param to true, like so:

lescape("Hello   World", { preserveFormatting: true });
// Hello~~~World

Which will be converted to three non-breaking spaces by your LaTeX software.

The list of format characters that are escaped include space, \t (tab), – (en-dash), — (em-dash).

There is also the param escapeMapFn to modify the mapping of escaped characters, so you can add/modify/remove your own escapes if necessary.

It accepts a callback function that takes in the default character escapes and the formatting escapes as parameters, and returns a complete escape mapping. Here's an example:

lescape("Hello   World", {
  preseveFormatting: true,
  escapeMapFn: function(defaultEscapes, formattingEscapes) {
    formattingEscapes[" "] = "\\\\";
    return Object.assign({}, defaultEscapes, formattingEscapes);
  },
});
// Hello\\\\\\world

Testing

npm test

Notes

  • If you are updating from escape-latex < 1.0.0, the en-dash and em-dash are no longer escaped by default. Please use preserveFormatting to turn them on if necessary.

License

MIT

Keywords

FAQs

Package last updated on 27 Oct 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc