Socket
Socket
Sign inDemoInstall

katex

Package Overview
Dependencies
Maintainers
7
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

katex - npm Package Compare versions

Comparing version 0.14.0 to 0.14.1

63

cli.js

@@ -23,47 +23,14 @@ #!/usr/bin/env node

const program = require("commander")
.version(version)
.option("-d, --display-mode",
"Render math in display mode, which puts the math in display style " +
"(so \\int and \\sum are large, for example), and centers the math " +
"on the page on its own line.")
.option("--leqno",
"Render display math in leqno style (left-justified tags).")
.option("--fleqn",
"Render display math flush left.")
.option("-t, --no-throw-on-error",
"Render errors (in the color given by --error-color) instead of " +
"throwing a ParseError exception when encountering an error.")
.option("-c, --error-color <color>",
"A color string given in the format 'rgb' or 'rrggbb' (no #). " +
"This option determines the color of errors rendered by the -t option.",
"#cc0000",
(color) => "#" + color)
.option("-b, --color-is-text-color",
"Makes \\color behave like LaTeX's 2-argument \\textcolor, " +
"instead of LaTeX's one-argument \\color mode change.")
.option("-S, --strict",
"Turn on strict / LaTeX faithfulness mode, which throws an error " +
"if the input uses features that are not supported by LaTeX.")
.option("-s, --max-size <n>",
"If non-zero, all user-specified sizes, e.g. in " +
"\\rule{500em}{500em}, will be capped to maxSize ems. " +
"Otherwise, elements and spaces can be arbitrarily large",
Infinity, parseInt)
.option("-e, --max-expand <n>",
"Limit the number of macro expansions to the specified number, to " +
"prevent e.g. infinite macro loops. If set to Infinity, the macro " +
"expander will try to fully expand as in LaTeX.",
(n) => (n === "Infinity" ? Infinity : parseInt(n)))
.option("-m, --macro <def>",
"Define custom macro of the form '\\foo:expansion' (use multiple -m " +
"arguments for multiple macros).",
(def, defs) => {
defs.push(def);
return defs;
}, [])
.option("-f, --macro-file <path>",
const program = require("commander").version(version);
for (const prop in katex.SETTINGS_SCHEMA) {
if (katex.SETTINGS_SCHEMA.hasOwnProperty(prop)) {
const opt = katex.SETTINGS_SCHEMA[prop];
if (opt.cli !== false) {
program.option(opt.cli || "--" + prop, opt.cliDescription ||
opt.description, opt.cliProcessor, opt.cliDefault);
}
}
}
program.option("-f, --macro-file <path>",
"Read macro definitions, one per line, from the given file.")
.option("-T, --trust",
"Trust the input, enabling all HTML features such as \\url.")
.option("-i, --input <path>", "Read LaTeX input from the given file.")

@@ -129,6 +96,10 @@ .option("-o, --output <path>", "Write html output to the given file.");

function writeOutput(input) {
// --format specifies the KaTeX output
const outputFile = options.output;
options.output = options.format;
const output = katex.renderToString(input, options) + "\n";
if (options.output) {
fs.writeFile(options.output, output, function(err) {
if (outputFile) {
fs.writeFile(outputFile, output, function(err) {
if (err) {

@@ -135,0 +106,0 @@ return console.log(err);

@@ -24,4 +24,4 @@ # Copy-tex extension

```html
<link href="https://cdn.jsdelivr.net/npm/katex@0.14.0/dist/contrib/copy-tex.css" rel="stylesheet" type="text/css">
<script src="https://cdn.jsdelivr.net/npm/katex@0.14.0/dist/contrib/copy-tex.min.js" integrity="sha384-Ep9Es0VCjVn9dFeaN2uQxgGcGmG+pfZ4eBaHxUpxXDORrrVACZVOpywyzvFRGbmv" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/katex@0.14.1/dist/contrib/copy-tex.css" rel="stylesheet" type="text/css">
<script src="https://cdn.jsdelivr.net/npm/katex@0.14.1/dist/contrib/copy-tex.min.js" integrity="sha384-Ep9Es0VCjVn9dFeaN2uQxgGcGmG+pfZ4eBaHxUpxXDORrrVACZVOpywyzvFRGbmv" crossorigin="anonymous"></script>
```

@@ -41,3 +41,3 @@

```html
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.14.0/dist/contrib/copy-tex.mjs" integrity="sha384-+gSYJ3yzY30+a6FGYJXOx9swmWs5oPKEi1AeCsAxsLexABlUXgHXkOkEZCj0Lz8U" crossorigin="anonymous"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.14.1/dist/contrib/copy-tex.mjs" integrity="sha384-+gSYJ3yzY30+a6FGYJXOx9swmWs5oPKEi1AeCsAxsLexABlUXgHXkOkEZCj0Lz8U" crossorigin="anonymous"></script>
```

@@ -44,0 +44,0 @@

@@ -14,3 +14,3 @@ # `math/tex` Custom Script Type Extension

```html
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.14.0/dist/contrib/mathtex-script-type.min.js" integrity="sha384-jiBVvJ8NGGj5n7kJaiWwWp9AjC+Yh8rhZY3GtAX8yU28azcLgoRo4oukO87g7zDT" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.14.1/dist/contrib/mathtex-script-type.min.js" integrity="sha384-jiBVvJ8NGGj5n7kJaiWwWp9AjC+Yh8rhZY3GtAX8yU28azcLgoRo4oukO87g7zDT" crossorigin="anonymous"></script>
```

@@ -27,5 +27,5 @@ You can download the script and use it locally, or from a local KaTeX installation instead.

<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.14.0/dist/katex.min.css" integrity="sha384-3XGqzlo+LecQmisZRaN2PyqKjEqiUrqliTjdV44NMwknt6bwCB86kqxXVKJn1Vy8" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/katex@0.14.0/dist/katex.min.js" integrity="sha384-uo6U/HIvh6QTbZVnCC/GMFnQHrNArO2ZBframC7vU/vju5N3Em3sTJg4TldoSiS7" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.14.0/dist/contrib/mathtex-script-type.min.js" integrity="sha384-jiBVvJ8NGGj5n7kJaiWwWp9AjC+Yh8rhZY3GtAX8yU28azcLgoRo4oukO87g7zDT" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.14.1/dist/katex.min.css" integrity="sha384-2zx8BdwKFuNSCN7GLgJQsaHE2O069/0DdWh3ijV8LXacwoIjXgZXc6GDcyPdiUTy" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/katex@0.14.1/dist/katex.min.js" integrity="sha384-G4iZzF9Q1vvkqA9laXwSt2Ny6DcbB5aeNHFpuGFdmXKHLaQw73gnLC5VFSavZoof" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.14.1/dist/contrib/mathtex-script-type.min.js" integrity="sha384-jiBVvJ8NGGj5n7kJaiWwWp9AjC+Yh8rhZY3GtAX8yU28azcLgoRo4oukO87g7zDT" crossorigin="anonymous"></script>
</head>

@@ -40,2 +40,2 @@ <body>

```html
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.14.0/dist/contrib/mathtex-script-type.mjs" integrity="sha384-4EJvC5tvqq9XJxXvdD4JutBokuFw/dCe2AB4gZ9sRpwFFXECpL3qT43tmE0PkpVg" crossorigin="anonymous"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.14.1/dist/contrib/mathtex-script-type.mjs" integrity="sha384-4EJvC5tvqq9XJxXvdD4JutBokuFw/dCe2AB4gZ9sRpwFFXECpL3qT43tmE0PkpVg" crossorigin="anonymous"></script>

@@ -10,3 +10,3 @@ # mhchem extension

```html
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.14.0/dist/contrib/mhchem.min.js" integrity="sha384-UEY9IRPkV+TTTY7nK1wSrfhWPDJy9wr4PmYg3DLPcN5F4NDlIwGZkWtWveKR/45c" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.14.1/dist/contrib/mhchem.min.js" integrity="sha384-UEY9IRPkV+TTTY7nK1wSrfhWPDJy9wr4PmYg3DLPcN5F4NDlIwGZkWtWveKR/45c" crossorigin="anonymous"></script>
```

@@ -13,0 +13,0 @@

@@ -34,9 +34,9 @@ # [<img src="https://katex.org/img/katex-logo-black.svg" width="130" alt="KaTeX">](https://katex.org/)

<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.14.0/dist/katex.min.css" integrity="sha384-3XGqzlo+LecQmisZRaN2PyqKjEqiUrqliTjdV44NMwknt6bwCB86kqxXVKJn1Vy8" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.14.1/dist/katex.min.css" integrity="sha384-2zx8BdwKFuNSCN7GLgJQsaHE2O069/0DdWh3ijV8LXacwoIjXgZXc6GDcyPdiUTy" crossorigin="anonymous">
<!-- The loading of KaTeX is deferred to speed up page rendering -->
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.14.0/dist/katex.min.js" integrity="sha384-uo6U/HIvh6QTbZVnCC/GMFnQHrNArO2ZBframC7vU/vju5N3Em3sTJg4TldoSiS7" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.14.1/dist/katex.min.js" integrity="sha384-G4iZzF9Q1vvkqA9laXwSt2Ny6DcbB5aeNHFpuGFdmXKHLaQw73gnLC5VFSavZoof" crossorigin="anonymous"></script>
<!-- To automatically render math in text elements, include the auto-render extension: -->
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.14.0/dist/contrib/auto-render.min.js" integrity="sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR" crossorigin="anonymous"
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.14.1/dist/contrib/auto-render.min.js" integrity="sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR" crossorigin="anonymous"
onload="renderMathInElement(document.body);"></script>

@@ -43,0 +43,0 @@ </head>

@@ -12,3 +12,3 @@ // @flow

import ParseError from "./src/ParseError";
import Settings from "./src/Settings";
import Settings, {SETTINGS_SCHEMA} from "./src/Settings";

@@ -161,2 +161,6 @@ import {buildTree, buildHTMLTree} from "./src/buildTree";

/**
* The shema of Settings
*/
SETTINGS_SCHEMA,
/**
* Parses the given LaTeX into KaTeX's internal parse tree structure,

@@ -163,0 +167,0 @@ * without rendering to HTML or MathML.

{
"name": "katex",
"version": "0.14.0",
"version": "0.14.1",
"description": "Fast math typesetting for the web.",

@@ -5,0 +5,0 @@ "main": "dist/katex.js",

@@ -34,9 +34,9 @@ # [<img src="https://katex.org/img/katex-logo-black.svg" width="130" alt="KaTeX">](https://katex.org/)

<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.14.0/dist/katex.min.css" integrity="sha384-3XGqzlo+LecQmisZRaN2PyqKjEqiUrqliTjdV44NMwknt6bwCB86kqxXVKJn1Vy8" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.14.1/dist/katex.min.css" integrity="sha384-2zx8BdwKFuNSCN7GLgJQsaHE2O069/0DdWh3ijV8LXacwoIjXgZXc6GDcyPdiUTy" crossorigin="anonymous">
<!-- The loading of KaTeX is deferred to speed up page rendering -->
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.14.0/dist/katex.min.js" integrity="sha384-uo6U/HIvh6QTbZVnCC/GMFnQHrNArO2ZBframC7vU/vju5N3Em3sTJg4TldoSiS7" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.14.1/dist/katex.min.js" integrity="sha384-G4iZzF9Q1vvkqA9laXwSt2Ny6DcbB5aeNHFpuGFdmXKHLaQw73gnLC5VFSavZoof" crossorigin="anonymous"></script>
<!-- To automatically render math in text elements, include the auto-render extension: -->
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.14.0/dist/contrib/auto-render.min.js" integrity="sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR" crossorigin="anonymous"
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.14.1/dist/contrib/auto-render.min.js" integrity="sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR" crossorigin="anonymous"
onload="renderMathInElement(document.body);"></script>

@@ -43,0 +43,0 @@ </head>

@@ -55,19 +55,176 @@ // @flow

export type SettingsOptions = {
displayMode?: boolean;
output?: "html" | "mathml" | "htmlAndMathml";
leqno?: boolean;
fleqn?: boolean;
throwOnError?: boolean;
errorColor?: string;
macros?: MacroMap;
minRuleThickness?: number;
colorIsTextColor?: boolean;
strict?: boolean | "ignore" | "warn" | "error" | StrictFunction;
trust?: boolean | TrustFunction;
maxSize?: number;
maxExpand?: number;
globalGroup?: boolean;
export type SettingsOptions = $Shape<Settings>;
type EnumType = {| enum: string[] |};
type Type = "boolean" | "string" | "number" | "object" | "function" | EnumType;
type Schema = {
[$Keys<SettingsOptions>]: {
/**
* Allowed type(s) of the value.
*/
type: Type | Type[];
/**
* The default value. If not specified, false for boolean, an empty string
* for string, 0 for number, an empty object for object, or the first item
* for enum will be used. If multiple types are allowed, the first allowed
* type will be used for determining the default value.
*/
default?: any;
/**
* The description.
*/
description?: string;
/**
* The function to process the option.
*/
processor?: (any) => any,
/**
* The command line argument. See Commander.js docs for more information.
* If not specified, the name prefixed with -- will be used. Set false not
* to add to the CLI.
*/
cli?: string | false;
/**
* The default value for the CLI.
*/
cliDefault?: any;
/**
* The description for the CLI. If not specified, the description for the
* option will be used.
*/
cliDescription?: string;
/**
* The custom argument processor for the CLI. See Commander.js docs for
* more information.
*/
cliProcessor?: (any, any) => any;
};
};
// TODO: automatically generate documentation
// TODO: check all properties on Settings exist
// TODO: check the type of a property on Settings matches
export const SETTINGS_SCHEMA: Schema = {
displayMode: {
type: "boolean",
description: "Render math in display mode, which puts the math in " +
"display style (so \\int and \\sum are large, for example), and " +
"centers the math on the page on its own line.",
cli: "-d, --display-mode",
},
output: {
type: {enum: ["htmlAndMathml", "html", "mathml"]},
description: "Determines the markup language of the output.",
cli: "-F, --format <type>",
},
leqno: {
type: "boolean",
description: "Render display math in leqno style (left-justified tags).",
},
fleqn: {
type: "boolean",
description: "Render display math flush left.",
},
throwOnError: {
type: "boolean",
default: true,
cli: "-t, --no-throw-on-error",
cliDescription: "Render errors (in the color given by --error-color) ins" +
"tead of throwing a ParseError exception when encountering an error.",
},
errorColor: {
type: "string",
default: "#cc0000",
cli: "-c, --error-color <color>",
cliDescription: "A color string given in the format 'rgb' or 'rrggbb' " +
"(no #). This option determines the color of errors rendered by the " +
"-t option.",
cliProcessor: (color) => "#" + color,
},
macros: {
type: "object",
cli: "-m, --macro <def>",
cliDescription: "Define custom macro of the form '\\foo:expansion' (use " +
"multiple -m arguments for multiple macros).",
cliDefault: [],
cliProcessor: (def, defs) => {
defs.push(def);
return defs;
},
},
minRuleThickness: {
type: "number",
description: "Specifies a minimum thickness, in ems, for fraction lines," +
" `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, " +
"`\\hdashline`, `\\underline`, `\\overline`, and the borders of " +
"`\\fbox`, `\\boxed`, and `\\fcolorbox`.",
processor: (t) => Math.max(0, t),
cli: "--min-rule-thickness <size>",
cliProcessor: parseFloat,
},
colorIsTextColor: {
type: "boolean",
description: "Makes \\color behave like LaTeX's 2-argument \\textcolor, " +
"instead of LaTeX's one-argument \\color mode change.",
cli: "-b, --color-is-text-color",
},
strict: {
type: [{enum: ["warn", "ignore", "error"]}, "boolean", "function"],
description: "Turn on strict / LaTeX faithfulness mode, which throws an " +
"error if the input uses features that are not supported by LaTeX.",
cli: "-S, --strict",
cliDefault: false,
},
trust: {
type: ["boolean", "function"],
description: "Trust the input, enabling all HTML features such as \\url.",
cli: "-T, --trust",
},
maxSize: {
type: "number",
default: Infinity,
description: "If non-zero, all user-specified sizes, e.g. in " +
"\\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, " +
"elements and spaces can be arbitrarily large",
processor: (s) => Math.max(0, s),
cli: "-s, --max-size <n>",
cliProcessor: parseInt,
},
maxExpand: {
type: "number",
default: 1000,
description: "Limit the number of macro expansions to the specified " +
"number, to prevent e.g. infinite macro loops. If set to Infinity, " +
"the macro expander will try to fully expand as in LaTeX.",
processor: (n) => Math.max(0, n),
cli: "-e, --max-expand <n>",
cliProcessor: (n) => (n === "Infinity" ? Infinity : parseInt(n)),
},
globalGroup: {
type: "boolean",
cli: false,
},
};
function getDefaultValue(schema): any {
if (schema.default) {
return schema.default;
}
const type = schema.type;
const defaultType = Array.isArray(type) ? type[0] : type;
if (typeof defaultType !== 'string') {
return defaultType.enum[0];
}
switch (defaultType) {
case 'boolean':
return false;
case 'string':
return '';
case 'number':
return 0;
case 'object':
return {};
}
}
/**

@@ -102,19 +259,13 @@ * The main Settings object

options = options || {};
this.displayMode = utils.deflt(options.displayMode, false);
this.output = utils.deflt(options.output, "htmlAndMathml");
this.leqno = utils.deflt(options.leqno, false);
this.fleqn = utils.deflt(options.fleqn, false);
this.throwOnError = utils.deflt(options.throwOnError, true);
this.errorColor = utils.deflt(options.errorColor, "#cc0000");
this.macros = options.macros || {};
this.minRuleThickness = Math.max(
0,
utils.deflt(options.minRuleThickness, 0)
);
this.colorIsTextColor = utils.deflt(options.colorIsTextColor, false);
this.strict = utils.deflt(options.strict, "warn");
this.trust = utils.deflt(options.trust, false);
this.maxSize = Math.max(0, utils.deflt(options.maxSize, Infinity));
this.maxExpand = Math.max(0, utils.deflt(options.maxExpand, 1000));
this.globalGroup = utils.deflt(options.globalGroup, false);
for (const prop in SETTINGS_SCHEMA) {
if (SETTINGS_SCHEMA.hasOwnProperty(prop)) {
// $FlowFixMe
const schema = SETTINGS_SCHEMA[prop];
// TODO: validate options
// $FlowFixMe
this[prop] = options[prop] !== undefined ? (schema.processor
? schema.processor(options[prop]) : options[prop])
: getDefaultValue(schema);
}
}
}

@@ -121,0 +272,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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