Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
escape-latex
Advanced tools
Escape LaTeX special characters with Javascript in NodeJS (>= 4.x) environment.
npm install escape-latex
var lescape = require('escape-latex');
lescape("String to be escaped here #yolo");
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
npm test
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.MIT
FAQs
Escape LaTeX special characters with Javascript
The npm package escape-latex receives a total of 929,937 weekly downloads. As such, escape-latex popularity was classified as popular.
We found that escape-latex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.