escape-latex

WebJar for escape-latex

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

escape-latex
Last Version

Last Version

1.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

escape-latex
WebJar for escape-latex
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/dangmai/escape-latex

Download escape-latex

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/escape-latex/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>escape-latex</artifactId>
    <version>1.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/escape-latex/
implementation 'org.webjars.npm:escape-latex:1.2.0'
// https://jarcasting.com/artifacts/org.webjars.npm/escape-latex/
implementation ("org.webjars.npm:escape-latex:1.2.0")
'org.webjars.npm:escape-latex:jar:1.2.0'
<dependency org="org.webjars.npm" name="escape-latex" rev="1.2.0">
  <artifact name="escape-latex" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='escape-latex', version='1.2.0')
)
libraryDependencies += "org.webjars.npm" % "escape-latex" % "1.2.0"
[org.webjars.npm/escape-latex "1.2.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

escape-latex

Build Status codecov

Escape LaTeX special characters with Javascript in NodeJS (>= 10.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

Versions

Version
1.2.0
1.0.3