# escape-latex

> Escape LaTeX special characters with Javascript

Latest version **1.2.0** (published 2018-10-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install escape-latex
pnpm add escape-latex
yarn add escape-latex
bun add escape-latex
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2018-10-27 |
| First published | 2012-10-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/escape-latex) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dang Mai |
| Maintainers | dangmai |
| Keywords | latex, escape |

## Links

- npm: https://www.npmjs.com/package/escape-latex
- Repository: https://github.com/dangmai/escape-latex
- Homepage: https://github.com/dangmai/escape-latex#readme
- Issues: https://github.com/dangmai/escape-latex/issues
- npm.io page: https://npm.io/package/escape-latex

## Recent versions

- 1.2.0 (latest) — 2018-10-27
- 1.0.0-beta.3 (next) — 2018-01-24
- 1.1.1 — 2018-08-20
- 1.1.0 — 2018-06-04
- 1.0.3 — 2018-05-03
- 1.0.1 — 2018-05-03
- 1.0.0 — 2018-01-25
- 1.0.0-beta.2 — 2018-01-23
- 1.0.0-beta.1 — 2018-01-16
- 0.1.5 — 2017-02-22
- 0.1.4 — 2017-02-22
- 0.1.3 — 2016-03-10
- 0.1.2 — 2012-10-30
- 0.1.1 — 2012-10-28
- 0.1.0 — 2012-10-27
- … 1 more at https://npm.io/package/escape-latex/versions

## README

# escape-latex

[![Build Status](https://github.com/dangmai/escape-latex/workflows/Tests/badge.svg)](https://github.com/dangmai/escape-latex/actions?query=workflow%3A%22Tests%22)
[![codecov](https://codecov.io/gh/dangmai/escape-latex/branch/master/graph/badge.svg?token=LGfqdKlTqM)](https://codecov.io/gh/dangmai/escape-latex)

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

## Usage

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

## API

```javascript
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:

```javascript
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:

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

## Testing

```
pnpm 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

---
_Source: https://npm.io/package/escape-latex · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
