1
0

add initial marp implementation with sample content and build configuration

This commit is contained in:
2025-09-13 18:13:22 +02:00
parent dcacc9b409
commit e5f219507f
10319 changed files with 1402023 additions and 0 deletions

122
node_modules/katex/src/Lexer.js generated vendored Normal file
View File

@@ -0,0 +1,122 @@
// @flow
/**
* The Lexer class handles tokenizing the input in various ways. Since our
* parser expects us to be able to backtrack, the lexer allows lexing from any
* given starting point.
*
* Its main exposed function is the `lex` function, which takes a position to
* lex from and a type of token to lex. It defers to the appropriate `_innerLex`
* function.
*
* The various `_innerLex` functions perform the actual lexing of different
* kinds.
*/
import ParseError from "./ParseError";
import SourceLocation from "./SourceLocation";
import {Token} from "./Token";
import type {LexerInterface} from "./Token";
import type Settings from "./Settings";
/* The following tokenRegex
* - matches typical whitespace (but not NBSP etc.) using its first group
* - does not match any control character \x00-\x1f except whitespace
* - does not match a bare backslash
* - matches any ASCII character except those just mentioned
* - does not match the BMP private use area \uE000-\uF8FF
* - does not match bare surrogate code units
* - matches any BMP character except for those just described
* - matches any valid Unicode surrogate pair
* - matches a backslash followed by one or more whitespace characters
* - matches a backslash followed by one or more letters then whitespace
* - matches a backslash followed by any BMP character
* Capturing groups:
* [1] regular whitespace
* [2] backslash followed by whitespace
* [3] anything else, which may include:
* [4] left character of \verb*
* [5] left character of \verb
* [6] backslash followed by word, excluding any trailing whitespace
* Just because the Lexer matches something doesn't mean it's valid input:
* If there is no matching function or symbol definition, the Parser will
* still reject the input.
*/
const spaceRegexString = "[ \r\n\t]";
const controlWordRegexString = "\\\\[a-zA-Z@]+";
const controlSymbolRegexString = "\\\\[^\uD800-\uDFFF]";
const controlWordWhitespaceRegexString =
`(${controlWordRegexString})${spaceRegexString}*`;
const controlSpaceRegexString = "\\\\(\n|[ \r\t]+\n?)[ \r\t]*";
const combiningDiacriticalMarkString = "[\u0300-\u036f]";
export const combiningDiacriticalMarksEndRegex: RegExp =
new RegExp(`${combiningDiacriticalMarkString}+$`);
const tokenRegexString = `(${spaceRegexString}+)|` + // whitespace
`${controlSpaceRegexString}|` + // \whitespace
"([!-\\[\\]-\u2027\u202A-\uD7FF\uF900-\uFFFF]" + // single codepoint
`${combiningDiacriticalMarkString}*` + // ...plus accents
"|[\uD800-\uDBFF][\uDC00-\uDFFF]" + // surrogate pair
`${combiningDiacriticalMarkString}*` + // ...plus accents
"|\\\\verb\\*([^]).*?\\4" + // \verb*
"|\\\\verb([^*a-zA-Z]).*?\\5" + // \verb unstarred
`|${controlWordWhitespaceRegexString}` + // \macroName + spaces
`|${controlSymbolRegexString})`; // \\, \', etc.
/** Main Lexer class */
export default class Lexer implements LexerInterface {
input: string;
settings: Settings;
tokenRegex: RegExp;
// Category codes. The lexer only supports comment characters (14) for now.
// MacroExpander additionally distinguishes active (13).
catcodes: {[string]: number};
constructor(input: string, settings: Settings) {
// Separate accents from characters
this.input = input;
this.settings = settings;
this.tokenRegex = new RegExp(tokenRegexString, 'g');
this.catcodes = {
"%": 14, // comment character
"~": 13, // active character
};
}
setCatcode(char: string, code: number) {
this.catcodes[char] = code;
}
/**
* This function lexes a single token.
*/
lex(): Token {
const input = this.input;
const pos = this.tokenRegex.lastIndex;
if (pos === input.length) {
return new Token("EOF", new SourceLocation(this, pos, pos));
}
const match = this.tokenRegex.exec(input);
if (match === null || match.index !== pos) {
throw new ParseError(
`Unexpected character: '${input[pos]}'`,
new Token(input[pos], new SourceLocation(this, pos, pos + 1)));
}
const text = match[6] || match[3] || (match[2] ? "\\ " : " ");
if (this.catcodes[text] === 14) { // comment character
const nlIndex = input.indexOf('\n', this.tokenRegex.lastIndex);
if (nlIndex === -1) {
this.tokenRegex.lastIndex = input.length; // EOF
this.settings.reportNonstrict("commentAtEnd",
"% comment has no terminating newline; LaTeX would " +
"fail because of commenting the end of math mode (e.g. $)");
} else {
this.tokenRegex.lastIndex = nlIndex + 1;
}
return this.lex();
}
return new Token(text, new SourceLocation(this, pos,
this.tokenRegex.lastIndex));
}
}

470
node_modules/katex/src/MacroExpander.js generated vendored Normal file
View File

@@ -0,0 +1,470 @@
// @flow
/**
* This file contains the “gullet” where macros are expanded
* until only non-macro tokens remain.
*/
import functions from "./functions";
import symbols from "./symbols";
import Lexer from "./Lexer";
import {Token} from "./Token";
import type {Mode} from "./types";
import ParseError from "./ParseError";
import Namespace from "./Namespace";
import macros from "./macros";
import type {MacroContextInterface, MacroDefinition, MacroExpansion, MacroArg}
from "./defineMacro";
import type Settings from "./Settings";
// List of commands that act like macros but aren't defined as a macro,
// function, or symbol. Used in `isDefined`.
export const implicitCommands = {
"^": true, // Parser.js
"_": true, // Parser.js
"\\limits": true, // Parser.js
"\\nolimits": true, // Parser.js
};
export default class MacroExpander implements MacroContextInterface {
settings: Settings;
expansionCount: number;
lexer: Lexer;
macros: Namespace<MacroDefinition>;
stack: Token[];
mode: Mode;
constructor(input: string, settings: Settings, mode: Mode) {
this.settings = settings;
this.expansionCount = 0;
this.feed(input);
// Make new global namespace
this.macros = new Namespace(macros, settings.macros);
this.mode = mode;
this.stack = []; // contains tokens in REVERSE order
}
/**
* Feed a new input string to the same MacroExpander
* (with existing macros etc.).
*/
feed(input: string) {
this.lexer = new Lexer(input, this.settings);
}
/**
* Switches between "text" and "math" modes.
*/
switchMode(newMode: Mode) {
this.mode = newMode;
}
/**
* Start a new group nesting within all namespaces.
*/
beginGroup() {
this.macros.beginGroup();
}
/**
* End current group nesting within all namespaces.
*/
endGroup() {
this.macros.endGroup();
}
/**
* Ends all currently nested groups (if any), restoring values before the
* groups began. Useful in case of an error in the middle of parsing.
*/
endGroups() {
this.macros.endGroups();
}
/**
* Returns the topmost token on the stack, without expanding it.
* Similar in behavior to TeX's `\futurelet`.
*/
future(): Token {
if (this.stack.length === 0) {
this.pushToken(this.lexer.lex());
}
return this.stack[this.stack.length - 1];
}
/**
* Remove and return the next unexpanded token.
*/
popToken(): Token {
this.future(); // ensure non-empty stack
return this.stack.pop();
}
/**
* Add a given token to the token stack. In particular, this get be used
* to put back a token returned from one of the other methods.
*/
pushToken(token: Token) {
this.stack.push(token);
}
/**
* Append an array of tokens to the token stack.
*/
pushTokens(tokens: Token[]) {
this.stack.push(...tokens);
}
/**
* Find an macro argument without expanding tokens and append the array of
* tokens to the token stack. Uses Token as a container for the result.
*/
scanArgument(isOptional: boolean): ?Token {
let start;
let end;
let tokens;
if (isOptional) {
this.consumeSpaces(); // \@ifnextchar gobbles any space following it
if (this.future().text !== "[") {
return null;
}
start = this.popToken(); // don't include [ in tokens
({tokens, end} = this.consumeArg(["]"]));
} else {
({tokens, start, end} = this.consumeArg());
}
// indicate the end of an argument
this.pushToken(new Token("EOF", end.loc));
this.pushTokens(tokens);
return start.range(end, "");
}
/**
* Consume all following space tokens, without expansion.
*/
consumeSpaces() {
for (;;) {
const token = this.future();
if (token.text === " ") {
this.stack.pop();
} else {
break;
}
}
}
/**
* Consume an argument from the token stream, and return the resulting array
* of tokens and start/end token.
*/
consumeArg(delims?: ?string[]): MacroArg {
// The argument for a delimited parameter is the shortest (possibly
// empty) sequence of tokens with properly nested {...} groups that is
// followed ... by this particular list of non-parameter tokens.
// The argument for an undelimited parameter is the next nonblank
// token, unless that token is {, when the argument will be the
// entire {...} group that follows.
const tokens: Token[] = [];
const isDelimited = delims && delims.length > 0;
if (!isDelimited) {
// Ignore spaces between arguments. As the TeXbook says:
// "After you have said \def\row#1#2{...}, you are allowed to
// put spaces between the arguments (e.g., \row x n), because
// TeX doesnt use single spaces as undelimited arguments."
this.consumeSpaces();
}
const start = this.future();
let tok;
let depth = 0;
let match = 0;
do {
tok = this.popToken();
tokens.push(tok);
if (tok.text === "{") {
++depth;
} else if (tok.text === "}") {
--depth;
if (depth === -1) {
throw new ParseError("Extra }", tok);
}
} else if (tok.text === "EOF") {
throw new ParseError("Unexpected end of input in a macro argument" +
", expected '" + (delims && isDelimited ? delims[match] : "}") +
"'", tok);
}
if (delims && isDelimited) {
if ((depth === 0 || (depth === 1 && delims[match] === "{")) &&
tok.text === delims[match]) {
++match;
if (match === delims.length) {
// don't include delims in tokens
tokens.splice(-match, match);
break;
}
} else {
match = 0;
}
}
} while (depth !== 0 || isDelimited);
// If the argument found ... has the form {<nested tokens>},
// ... the outermost braces enclosing the argument are removed
if (start.text === "{" && tokens[tokens.length - 1].text === "}") {
tokens.pop();
tokens.shift();
}
tokens.reverse(); // to fit in with stack order
return {tokens, start, end: tok};
}
/**
* Consume the specified number of (delimited) arguments from the token
* stream and return the resulting array of arguments.
*/
consumeArgs(numArgs: number, delimiters?: string[][]): Token[][] {
if (delimiters) {
if (delimiters.length !== numArgs + 1) {
throw new ParseError(
"The length of delimiters doesn't match the number of args!");
}
const delims = delimiters[0];
for (let i = 0; i < delims.length; i++) {
const tok = this.popToken();
if (delims[i] !== tok.text) {
throw new ParseError(
"Use of the macro doesn't match its definition", tok);
}
}
}
const args: Token[][] = [];
for (let i = 0; i < numArgs; i++) {
args.push(this.consumeArg(delimiters && delimiters[i + 1]).tokens);
}
return args;
}
/**
* Increment `expansionCount` by the specified amount.
* Throw an error if it exceeds `maxExpand`.
*/
countExpansion(amount: number): void {
this.expansionCount += amount;
if (this.expansionCount > this.settings.maxExpand) {
throw new ParseError("Too many expansions: infinite loop or " +
"need to increase maxExpand setting");
}
}
/**
* Expand the next token only once if possible.
*
* If the token is expanded, the resulting tokens will be pushed onto
* the stack in reverse order, and the number of such tokens will be
* returned. This number might be zero or positive.
*
* If not, the return value is `false`, and the next token remains at the
* top of the stack.
*
* In either case, the next token will be on the top of the stack,
* or the stack will be empty (in case of empty expansion
* and no other tokens).
*
* Used to implement `expandAfterFuture` and `expandNextToken`.
*
* If expandableOnly, only expandable tokens are expanded and
* an undefined control sequence results in an error.
*/
expandOnce(expandableOnly?: boolean): number | boolean {
const topToken = this.popToken();
const name = topToken.text;
const expansion = !topToken.noexpand ? this._getExpansion(name) : null;
if (expansion == null || (expandableOnly && expansion.unexpandable)) {
if (expandableOnly && expansion == null &&
name[0] === "\\" && !this.isDefined(name)) {
throw new ParseError("Undefined control sequence: " + name);
}
this.pushToken(topToken);
return false;
}
this.countExpansion(1);
let tokens = expansion.tokens;
const args = this.consumeArgs(expansion.numArgs, expansion.delimiters);
if (expansion.numArgs) {
// paste arguments in place of the placeholders
tokens = tokens.slice(); // make a shallow copy
for (let i = tokens.length - 1; i >= 0; --i) {
let tok = tokens[i];
if (tok.text === "#") {
if (i === 0) {
throw new ParseError(
"Incomplete placeholder at end of macro body",
tok);
}
tok = tokens[--i]; // next token on stack
if (tok.text === "#") { // ## → #
tokens.splice(i + 1, 1); // drop first #
} else if (/^[1-9]$/.test(tok.text)) {
// replace the placeholder with the indicated argument
tokens.splice(i, 2, ...args[+tok.text - 1]);
} else {
throw new ParseError(
"Not a valid argument number",
tok);
}
}
}
}
// Concatenate expansion onto top of stack.
this.pushTokens(tokens);
return tokens.length;
}
/**
* Expand the next token only once (if possible), and return the resulting
* top token on the stack (without removing anything from the stack).
* Similar in behavior to TeX's `\expandafter\futurelet`.
* Equivalent to expandOnce() followed by future().
*/
expandAfterFuture(): Token {
this.expandOnce();
return this.future();
}
/**
* Recursively expand first token, then return first non-expandable token.
*/
expandNextToken(): Token {
for (;;) {
if (this.expandOnce() === false) { // fully expanded
const token = this.stack.pop();
// the token after \noexpand is interpreted as if its meaning
// were \relax
if (token.treatAsRelax) {
token.text = "\\relax";
}
return token;
}
}
// Flow unable to figure out that this pathway is impossible.
// https://github.com/facebook/flow/issues/4808
throw new Error(); // eslint-disable-line no-unreachable
}
/**
* Fully expand the given macro name and return the resulting list of
* tokens, or return `undefined` if no such macro is defined.
*/
expandMacro(name: string): Token[] | void {
return this.macros.has(name)
? this.expandTokens([new Token(name)]) : undefined;
}
/**
* Fully expand the given token stream and return the resulting list of
* tokens. Note that the input tokens are in reverse order, but the
* output tokens are in forward order.
*/
expandTokens(tokens: Token[]): Token[] {
const output = [];
const oldStackLength = this.stack.length;
this.pushTokens(tokens);
while (this.stack.length > oldStackLength) {
// Expand only expandable tokens
if (this.expandOnce(true) === false) { // fully expanded
const token = this.stack.pop();
if (token.treatAsRelax) {
// the expansion of \noexpand is the token itself
token.noexpand = false;
token.treatAsRelax = false;
}
output.push(token);
}
}
// Count all of these tokens as additional expansions, to prevent
// exponential blowup from linearly many \edef's.
this.countExpansion(output.length);
return output;
}
/**
* Fully expand the given macro name and return the result as a string,
* or return `undefined` if no such macro is defined.
*/
expandMacroAsText(name: string): string | void {
const tokens = this.expandMacro(name);
if (tokens) {
return tokens.map((token) => token.text).join("");
} else {
return tokens;
}
}
/**
* Returns the expanded macro as a reversed array of tokens and a macro
* argument count. Or returns `null` if no such macro.
*/
_getExpansion(name: string): ?MacroExpansion {
const definition = this.macros.get(name);
if (definition == null) { // mainly checking for undefined here
return definition;
}
// If a single character has an associated catcode other than 13
// (active character), then don't expand it.
if (name.length === 1) {
const catcode = this.lexer.catcodes[name];
if (catcode != null && catcode !== 13) {
return;
}
}
const expansion =
typeof definition === "function" ? definition(this) : definition;
if (typeof expansion === "string") {
let numArgs = 0;
if (expansion.indexOf("#") !== -1) {
const stripped = expansion.replace(/##/g, "");
while (stripped.indexOf("#" + (numArgs + 1)) !== -1) {
++numArgs;
}
}
const bodyLexer = new Lexer(expansion, this.settings);
const tokens = [];
let tok = bodyLexer.lex();
while (tok.text !== "EOF") {
tokens.push(tok);
tok = bodyLexer.lex();
}
tokens.reverse(); // to fit in with stack using push and pop
const expanded = {tokens, numArgs};
return expanded;
}
return expansion;
}
/**
* Determine whether a command is currently "defined" (has some
* functionality), meaning that it's a macro (in the current group),
* a function, a symbol, or one of the special commands listed in
* `implicitCommands`.
*/
isDefined(name: string): boolean {
return this.macros.has(name) ||
functions.hasOwnProperty(name) ||
symbols.math.hasOwnProperty(name) ||
symbols.text.hasOwnProperty(name) ||
implicitCommands.hasOwnProperty(name);
}
/**
* Determine whether a command is expandable.
*/
isExpandable(name: string): boolean {
const macro = this.macros.get(name);
return macro != null ? typeof macro === "string"
|| typeof macro === "function" || !macro.unexpandable
: functions.hasOwnProperty(name) && !functions[name].primitive;
}
}

129
node_modules/katex/src/Namespace.js generated vendored Normal file
View File

@@ -0,0 +1,129 @@
// @flow
/**
* A `Namespace` refers to a space of nameable things like macros or lengths,
* which can be `set` either globally or local to a nested group, using an
* undo stack similar to how TeX implements this functionality.
* Performance-wise, `get` and local `set` take constant time, while global
* `set` takes time proportional to the depth of group nesting.
*/
import ParseError from "./ParseError";
export type Mapping<Value> = {[string]: Value};
export default class Namespace<Value> {
current: Mapping<Value>;
builtins: Mapping<Value>;
undefStack: Mapping<?Value>[];
/**
* Both arguments are optional. The first argument is an object of
* built-in mappings which never change. The second argument is an object
* of initial (global-level) mappings, which will constantly change
* according to any global/top-level `set`s done.
*/
constructor(builtins: Mapping<Value> = {},
globalMacros: Mapping<Value> = {}) {
this.current = globalMacros;
this.builtins = builtins;
this.undefStack = [];
}
/**
* Start a new nested group, affecting future local `set`s.
*/
beginGroup() {
this.undefStack.push({});
}
/**
* End current nested group, restoring values before the group began.
*/
endGroup() {
if (this.undefStack.length === 0) {
throw new ParseError("Unbalanced namespace destruction: attempt " +
"to pop global namespace; please report this as a bug");
}
const undefs = this.undefStack.pop();
for (const undef in undefs) {
if (undefs.hasOwnProperty(undef)) {
if (undefs[undef] == null) {
delete this.current[undef];
} else {
this.current[undef] = undefs[undef];
}
}
}
}
/**
* Ends all currently nested groups (if any), restoring values before the
* groups began. Useful in case of an error in the middle of parsing.
*/
endGroups() {
while (this.undefStack.length > 0) {
this.endGroup();
}
}
/**
* Detect whether `name` has a definition. Equivalent to
* `get(name) != null`.
*/
has(name: string): boolean {
return this.current.hasOwnProperty(name) ||
this.builtins.hasOwnProperty(name);
}
/**
* Get the current value of a name, or `undefined` if there is no value.
*
* Note: Do not use `if (namespace.get(...))` to detect whether a macro
* is defined, as the definition may be the empty string which evaluates
* to `false` in JavaScript. Use `if (namespace.get(...) != null)` or
* `if (namespace.has(...))`.
*/
get(name: string): ?Value {
if (this.current.hasOwnProperty(name)) {
return this.current[name];
} else {
return this.builtins[name];
}
}
/**
* Set the current value of a name, and optionally set it globally too.
* Local set() sets the current value and (when appropriate) adds an undo
* operation to the undo stack. Global set() may change the undo
* operation at every level, so takes time linear in their number.
* A value of undefined means to delete existing definitions.
*/
set(name: string, value: ?Value, global: boolean = false) {
if (global) {
// Global set is equivalent to setting in all groups. Simulate this
// by destroying any undos currently scheduled for this name,
// and adding an undo with the *new* value (in case it later gets
// locally reset within this environment).
for (let i = 0; i < this.undefStack.length; i++) {
delete this.undefStack[i][name];
}
if (this.undefStack.length > 0) {
this.undefStack[this.undefStack.length - 1][name] = value;
}
} else {
// Undo this set at end of this group (possibly to `undefined`),
// unless an undo is already in place, in which case that older
// value is the correct one.
const top = this.undefStack[this.undefStack.length - 1];
if (top && !top.hasOwnProperty(name)) {
top[name] = this.current[name];
}
}
if (value == null) {
delete this.current[name];
} else {
this.current[name] = value;
}
}
}

319
node_modules/katex/src/Options.js generated vendored Normal file
View File

@@ -0,0 +1,319 @@
// @flow
/**
* This file contains information about the options that the Parser carries
* around with it while parsing. Data is held in an `Options` object, and when
* recursing, a new `Options` object can be created with the `.with*` and
* `.reset` functions.
*/
import {getGlobalMetrics} from "./fontMetrics";
import type {FontMetrics} from "./fontMetrics";
import type {StyleInterface} from "./Style";
const sizeStyleMap = [
// Each element contains [textsize, scriptsize, scriptscriptsize].
// The size mappings are taken from TeX with \normalsize=10pt.
[1, 1, 1], // size1: [5, 5, 5] \tiny
[2, 1, 1], // size2: [6, 5, 5]
[3, 1, 1], // size3: [7, 5, 5] \scriptsize
[4, 2, 1], // size4: [8, 6, 5] \footnotesize
[5, 2, 1], // size5: [9, 6, 5] \small
[6, 3, 1], // size6: [10, 7, 5] \normalsize
[7, 4, 2], // size7: [12, 8, 6] \large
[8, 6, 3], // size8: [14.4, 10, 7] \Large
[9, 7, 6], // size9: [17.28, 12, 10] \LARGE
[10, 8, 7], // size10: [20.74, 14.4, 12] \huge
[11, 10, 9], // size11: [24.88, 20.74, 17.28] \HUGE
];
const sizeMultipliers = [
// fontMetrics.js:getGlobalMetrics also uses size indexes, so if
// you change size indexes, change that function.
0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.44, 1.728, 2.074, 2.488,
];
const sizeAtStyle = function(size: number, style: StyleInterface): number {
return style.size < 2 ? size : sizeStyleMap[size - 1][style.size - 1];
};
// In these types, "" (empty string) means "no change".
export type FontWeight = "textbf" | "textmd" | "";
export type FontShape = "textit" | "textup" | "";
export type OptionsData = {
style: StyleInterface;
color?: string | void;
size?: number;
textSize?: number;
phantom?: boolean;
font?: string;
fontFamily?: string;
fontWeight?: FontWeight;
fontShape?: FontShape;
sizeMultiplier?: number;
maxSize: number;
minRuleThickness: number;
};
/**
* This is the main options class. It contains the current style, size, color,
* and font.
*
* Options objects should not be modified. To create a new Options with
* different properties, call a `.having*` method.
*/
class Options {
style: StyleInterface;
color: string | void;
size: number;
textSize: number;
phantom: boolean;
// A font family applies to a group of fonts (i.e. SansSerif), while a font
// represents a specific font (i.e. SansSerif Bold).
// See: https://tex.stackexchange.com/questions/22350/difference-between-textrm-and-mathrm
font: string;
fontFamily: string;
fontWeight: FontWeight;
fontShape: FontShape;
sizeMultiplier: number;
maxSize: number;
minRuleThickness: number;
_fontMetrics: FontMetrics | void;
/**
* The base size index.
*/
static BASESIZE: number = 6;
constructor(data: OptionsData) {
this.style = data.style;
this.color = data.color;
this.size = data.size || Options.BASESIZE;
this.textSize = data.textSize || this.size;
this.phantom = !!data.phantom;
this.font = data.font || "";
this.fontFamily = data.fontFamily || "";
this.fontWeight = data.fontWeight || '';
this.fontShape = data.fontShape || '';
this.sizeMultiplier = sizeMultipliers[this.size - 1];
this.maxSize = data.maxSize;
this.minRuleThickness = data.minRuleThickness;
this._fontMetrics = undefined;
}
/**
* Returns a new options object with the same properties as "this". Properties
* from "extension" will be copied to the new options object.
*/
extend(extension: $Shape<OptionsData>): Options {
const data = {
style: this.style,
size: this.size,
textSize: this.textSize,
color: this.color,
phantom: this.phantom,
font: this.font,
fontFamily: this.fontFamily,
fontWeight: this.fontWeight,
fontShape: this.fontShape,
maxSize: this.maxSize,
minRuleThickness: this.minRuleThickness,
};
for (const key in extension) {
if (extension.hasOwnProperty(key)) {
data[key] = extension[key];
}
}
return new Options(data);
}
/**
* Return an options object with the given style. If `this.style === style`,
* returns `this`.
*/
havingStyle(style: StyleInterface): Options {
if (this.style === style) {
return this;
} else {
return this.extend({
style: style,
size: sizeAtStyle(this.textSize, style),
});
}
}
/**
* Return an options object with a cramped version of the current style. If
* the current style is cramped, returns `this`.
*/
havingCrampedStyle(): Options {
return this.havingStyle(this.style.cramp());
}
/**
* Return an options object with the given size and in at least `\textstyle`.
* Returns `this` if appropriate.
*/
havingSize(size: number): Options {
if (this.size === size && this.textSize === size) {
return this;
} else {
return this.extend({
style: this.style.text(),
size: size,
textSize: size,
sizeMultiplier: sizeMultipliers[size - 1],
});
}
}
/**
* Like `this.havingSize(BASESIZE).havingStyle(style)`. If `style` is omitted,
* changes to at least `\textstyle`.
*/
havingBaseStyle(style: StyleInterface): Options {
style = style || this.style.text();
const wantSize = sizeAtStyle(Options.BASESIZE, style);
if (this.size === wantSize && this.textSize === Options.BASESIZE
&& this.style === style) {
return this;
} else {
return this.extend({
style: style,
size: wantSize,
});
}
}
/**
* Remove the effect of sizing changes such as \Huge.
* Keep the effect of the current style, such as \scriptstyle.
*/
havingBaseSizing(): Options {
let size;
switch (this.style.id) {
case 4:
case 5:
size = 3; // normalsize in scriptstyle
break;
case 6:
case 7:
size = 1; // normalsize in scriptscriptstyle
break;
default:
size = 6; // normalsize in textstyle or displaystyle
}
return this.extend({
style: this.style.text(),
size: size,
});
}
/**
* Create a new options object with the given color.
*/
withColor(color: string): Options {
return this.extend({
color: color,
});
}
/**
* Create a new options object with "phantom" set to true.
*/
withPhantom(): Options {
return this.extend({
phantom: true,
});
}
/**
* Creates a new options object with the given math font or old text font.
* @type {[type]}
*/
withFont(font: string): Options {
return this.extend({
font,
});
}
/**
* Create a new options objects with the given fontFamily.
*/
withTextFontFamily(fontFamily: string): Options {
return this.extend({
fontFamily,
font: "",
});
}
/**
* Creates a new options object with the given font weight
*/
withTextFontWeight(fontWeight: FontWeight): Options {
return this.extend({
fontWeight,
font: "",
});
}
/**
* Creates a new options object with the given font weight
*/
withTextFontShape(fontShape: FontShape): Options {
return this.extend({
fontShape,
font: "",
});
}
/**
* Return the CSS sizing classes required to switch from enclosing options
* `oldOptions` to `this`. Returns an array of classes.
*/
sizingClasses(oldOptions: Options): Array<string> {
if (oldOptions.size !== this.size) {
return ["sizing", "reset-size" + oldOptions.size, "size" + this.size];
} else {
return [];
}
}
/**
* Return the CSS sizing classes required to switch to the base size. Like
* `this.havingSize(BASESIZE).sizingClasses(this)`.
*/
baseSizingClasses(): Array<string> {
if (this.size !== Options.BASESIZE) {
return ["sizing", "reset-size" + this.size, "size" + Options.BASESIZE];
} else {
return [];
}
}
/**
* Return the font metrics for this size.
*/
fontMetrics(): FontMetrics {
if (!this._fontMetrics) {
this._fontMetrics = getGlobalMetrics(this.size);
}
return this._fontMetrics;
}
/**
* Gets the CSS color of the current options object
*/
getColor(): string | void {
if (this.phantom) {
return "transparent";
} else {
return this.color;
}
}
}
export default Options;

86
node_modules/katex/src/ParseError.js generated vendored Normal file
View File

@@ -0,0 +1,86 @@
// @flow
import {Token} from "./Token";
import type {AnyParseNode} from "./parseNode";
/**
* This is the ParseError class, which is the main error thrown by KaTeX
* functions when something has gone wrong. This is used to distinguish internal
* errors from errors in the expression that the user provided.
*
* If possible, a caller should provide a Token or ParseNode with information
* about where in the source string the problem occurred.
*/
class ParseError {
name: "ParseError";
position: number | void;
// Error start position based on passed-in Token or ParseNode.
length: number | void;
// Length of affected text based on passed-in Token or ParseNode.
rawMessage: string | void;
// The underlying error message without any context added.
constructor(
message: string, // The error message
token?: ?Token | AnyParseNode, // An object providing position information
): ParseError {
let error = "KaTeX parse error: " + message;
let start;
let end;
const loc = token && token.loc;
if (loc && loc.start <= loc.end) {
// If we have the input and a position, make the error a bit fancier
// Get the input
const input = loc.lexer.input;
// Prepend some information
start = loc.start;
end = loc.end;
if (start === input.length) {
error += " at end of input: ";
} else {
error += " at position " + (start + 1) + ": ";
}
// Underline token in question using combining underscores
const underlined = input.slice(start, end).replace(/[^]/g, "$&\u0332");
// Extract some context from the input and add it to the error
let left;
if (start > 15) {
left = "…" + input.slice(start - 15, start);
} else {
left = input.slice(0, start);
}
let right;
if (end + 15 < input.length) {
right = input.slice(end, end + 15) + "…";
} else {
right = input.slice(end);
}
error += left + underlined + right;
}
// Some hackery to make ParseError a prototype of Error
// See http://stackoverflow.com/a/8460753
// $FlowFixMe
const self: ParseError = new Error(error);
self.name = "ParseError";
// $FlowFixMe
self.__proto__ = ParseError.prototype;
self.position = start;
if (start != null && end != null) {
self.length = end - start;
}
self.rawMessage = message;
return self;
}
}
// $FlowFixMe More hackery
ParseError.prototype.__proto__ = Error.prototype;
export default ParseError;

1041
node_modules/katex/src/Parser.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

360
node_modules/katex/src/Settings.js generated vendored Normal file
View File

@@ -0,0 +1,360 @@
// @flow
/* eslint no-console:0 */
/**
* This is a module for storing settings passed into KaTeX. It correctly handles
* default settings.
*/
import utils from "./utils";
import ParseError from "./ParseError";
import {Token} from "./Token";
import type {AnyParseNode} from "./parseNode";
import type {MacroMap} from "./defineMacro";
export type StrictFunction =
(errorCode: string, errorMsg: string, token?: Token | AnyParseNode) =>
?(boolean | string);
export type TrustContextTypes = {
"\\href": {|
command: "\\href",
url: string,
protocol?: string,
|},
"\\includegraphics": {|
command: "\\includegraphics",
url: string,
protocol?: string,
|},
"\\url": {|
command: "\\url",
url: string,
protocol?: string,
|},
"\\htmlClass": {|
command: "\\htmlClass",
class: string,
|},
"\\htmlId": {|
command: "\\htmlId",
id: string,
|},
"\\htmlStyle": {|
command: "\\htmlStyle",
style: string,
|},
"\\htmlData": {|
command: "\\htmlData",
attributes: {[string]: string},
|},
};
export type AnyTrustContext = $Values<TrustContextTypes>;
export type TrustFunction = (context: AnyTrustContext) => ?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 {};
}
}
/**
* The main Settings object
*
* The current options stored are:
* - displayMode: Whether the expression should be typeset as inline math
* (false, the default), meaning that the math starts in
* \textstyle and is placed in an inline-block); or as display
* math (true), meaning that the math starts in \displaystyle
* and is placed in a block with vertical margin.
*/
export default class Settings {
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;
constructor(options: SettingsOptions) {
// allow null options
options = options || {};
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);
}
}
}
/**
* Report nonstrict (non-LaTeX-compatible) input.
* Can safely not be called if `this.strict` is false in JavaScript.
*/
reportNonstrict(errorCode: string, errorMsg: string,
token?: Token | AnyParseNode) {
let strict = this.strict;
if (typeof strict === "function") {
// Allow return value of strict function to be boolean or string
// (or null/undefined, meaning no further processing).
strict = strict(errorCode, errorMsg, token);
}
if (!strict || strict === "ignore") {
return;
} else if (strict === true || strict === "error") {
throw new ParseError(
"LaTeX-incompatible input and strict mode is set to 'error': " +
`${errorMsg} [${errorCode}]`, token);
} else if (strict === "warn") {
typeof console !== "undefined" && console.warn(
"LaTeX-incompatible input and strict mode is set to 'warn': " +
`${errorMsg} [${errorCode}]`);
} else { // won't happen in type-safe code
typeof console !== "undefined" && console.warn(
"LaTeX-incompatible input and strict mode is set to " +
`unrecognized '${strict}': ${errorMsg} [${errorCode}]`);
}
}
/**
* Check whether to apply strict (LaTeX-adhering) behavior for unusual
* input (like `\\`). Unlike `nonstrict`, will not throw an error;
* instead, "error" translates to a return value of `true`, while "ignore"
* translates to a return value of `false`. May still print a warning:
* "warn" prints a warning and returns `false`.
* This is for the second category of `errorCode`s listed in the README.
*/
useStrictBehavior(errorCode: string, errorMsg: string,
token?: Token | AnyParseNode): boolean {
let strict = this.strict;
if (typeof strict === "function") {
// Allow return value of strict function to be boolean or string
// (or null/undefined, meaning no further processing).
// But catch any exceptions thrown by function, treating them
// like "error".
try {
strict = strict(errorCode, errorMsg, token);
} catch (error) {
strict = "error";
}
}
if (!strict || strict === "ignore") {
return false;
} else if (strict === true || strict === "error") {
return true;
} else if (strict === "warn") {
typeof console !== "undefined" && console.warn(
"LaTeX-incompatible input and strict mode is set to 'warn': " +
`${errorMsg} [${errorCode}]`);
return false;
} else { // won't happen in type-safe code
typeof console !== "undefined" && console.warn(
"LaTeX-incompatible input and strict mode is set to " +
`unrecognized '${strict}': ${errorMsg} [${errorCode}]`);
return false;
}
}
/**
* Check whether to test potentially dangerous input, and return
* `true` (trusted) or `false` (untrusted). The sole argument `context`
* should be an object with `command` field specifying the relevant LaTeX
* command (as a string starting with `\`), and any other arguments, etc.
* If `context` has a `url` field, a `protocol` field will automatically
* get added by this function (changing the specified object).
*/
isTrusted(context: AnyTrustContext): boolean {
if (context.url && !context.protocol) {
const protocol = utils.protocolFromUrl(context.url);
if (protocol == null) {
return false;
}
context.protocol = protocol;
}
const trust = typeof this.trust === "function"
? this.trust(context)
: this.trust;
return Boolean(trust);
}
}

42
node_modules/katex/src/SourceLocation.js generated vendored Normal file
View File

@@ -0,0 +1,42 @@
// @flow
import type {LexerInterface} from "./Token";
/**
* Lexing or parsing positional information for error reporting.
* This object is immutable.
*/
export default class SourceLocation {
// The + prefix indicates that these fields aren't writeable
+lexer: LexerInterface; // Lexer holding the input string.
+start: number; // Start offset, zero-based inclusive.
+end: number; // End offset, zero-based exclusive.
constructor(lexer: LexerInterface, start: number, end: number) {
this.lexer = lexer;
this.start = start;
this.end = end;
}
/**
* Merges two `SourceLocation`s from location providers, given they are
* provided in order of appearance.
* - Returns the first one's location if only the first is provided.
* - Returns a merged range of the first and the last if both are provided
* and their lexers match.
* - Otherwise, returns null.
*/
static range(
first?: {loc: ?SourceLocation},
second?: {loc: ?SourceLocation},
): ?SourceLocation {
if (!second) {
return first && first.loc;
} else if (!first || !first.loc || !second.loc ||
first.loc.lexer !== second.loc.lexer) {
return null;
} else {
return new SourceLocation(
first.loc.lexer, first.loc.start, second.loc.end);
}
}
}

130
node_modules/katex/src/Style.js generated vendored Normal file
View File

@@ -0,0 +1,130 @@
// @flow
/**
* This file contains information and classes for the various kinds of styles
* used in TeX. It provides a generic `Style` class, which holds information
* about a specific style. It then provides instances of all the different kinds
* of styles possible, and provides functions to move between them and get
* information about them.
*/
/**
* The main style class. Contains a unique id for the style, a size (which is
* the same for cramped and uncramped version of a style), and a cramped flag.
*/
class Style implements StyleInterface {
id: number;
size: number;
cramped: boolean;
constructor(id: number, size: number, cramped: boolean) {
this.id = id;
this.size = size;
this.cramped = cramped;
}
/**
* Get the style of a superscript given a base in the current style.
*/
sup(): Style {
return styles[sup[this.id]];
}
/**
* Get the style of a subscript given a base in the current style.
*/
sub(): Style {
return styles[sub[this.id]];
}
/**
* Get the style of a fraction numerator given the fraction in the current
* style.
*/
fracNum(): Style {
return styles[fracNum[this.id]];
}
/**
* Get the style of a fraction denominator given the fraction in the current
* style.
*/
fracDen(): Style {
return styles[fracDen[this.id]];
}
/**
* Get the cramped version of a style (in particular, cramping a cramped style
* doesn't change the style).
*/
cramp(): Style {
return styles[cramp[this.id]];
}
/**
* Get a text or display version of this style.
*/
text(): Style {
return styles[text[this.id]];
}
/**
* Return true if this style is tightly spaced (scriptstyle/scriptscriptstyle)
*/
isTight(): boolean {
return this.size >= 2;
}
}
// Export an interface for type checking, but don't expose the implementation.
// This way, no more styles can be generated.
export interface StyleInterface {
id: number;
size: number;
cramped: boolean;
sup(): StyleInterface;
sub(): StyleInterface;
fracNum(): StyleInterface;
fracDen(): StyleInterface;
cramp(): StyleInterface;
text(): StyleInterface;
isTight(): boolean;
}
// IDs of the different styles
const D = 0;
const Dc = 1;
const T = 2;
const Tc = 3;
const S = 4;
const Sc = 5;
const SS = 6;
const SSc = 7;
// Instances of the different styles
const styles = [
new Style(D, 0, false),
new Style(Dc, 0, true),
new Style(T, 1, false),
new Style(Tc, 1, true),
new Style(S, 2, false),
new Style(Sc, 2, true),
new Style(SS, 3, false),
new Style(SSc, 3, true),
];
// Lookup tables for switching from one style to another
const sup = [S, Sc, S, Sc, SS, SSc, SS, SSc];
const sub = [Sc, Sc, Sc, Sc, SSc, SSc, SSc, SSc];
const fracNum = [T, Tc, S, Sc, SS, SSc, SS, SSc];
const fracDen = [Tc, Tc, Sc, Sc, SSc, SSc, SSc, SSc];
const cramp = [Dc, Dc, Tc, Tc, Sc, Sc, SSc, SSc];
const text = [D, Dc, T, Tc, T, Tc, T, Tc];
// We only export some of the styles.
export default {
DISPLAY: (styles[D]: Style),
TEXT: (styles[T]: Style),
SCRIPT: (styles[S]: Style),
SCRIPTSCRIPT: (styles[SS]: Style),
};

47
node_modules/katex/src/Token.js generated vendored Normal file
View File

@@ -0,0 +1,47 @@
// @flow
import SourceLocation from "./SourceLocation";
/**
* Interface required to break circular dependency between Token, Lexer, and
* ParseError.
*/
export interface LexerInterface {input: string, tokenRegex: RegExp}
/**
* The resulting token returned from `lex`.
*
* It consists of the token text plus some position information.
* The position information is essentially a range in an input string,
* but instead of referencing the bare input string, we refer to the lexer.
* That way it is possible to attach extra metadata to the input string,
* like for example a file name or similar.
*
* The position information is optional, so it is OK to construct synthetic
* tokens if appropriate. Not providing available position information may
* lead to degraded error reporting, though.
*/
export class Token {
text: string;
loc: ?SourceLocation;
noexpand: ?boolean; // don't expand the token
treatAsRelax: ?boolean; // used in \noexpand
constructor(
text: string, // the text of this token
loc: ?SourceLocation,
) {
this.text = text;
this.loc = loc;
}
/**
* Given a pair of tokens (this and endToken), compute a `Token` encompassing
* the whole input range enclosed by these two.
*/
range(
endToken: Token, // last token of the range, inclusive
text: string, // the text of the newly constructed token
): Token {
return new Token(text, SourceLocation.range(this, endToken));
}
}

784
node_modules/katex/src/buildCommon.js generated vendored Normal file
View File

@@ -0,0 +1,784 @@
// @flow
/* eslint no-console:0 */
/**
* This module contains general functions that can be used for building
* different kinds of domTree nodes in a consistent manner.
*/
import {SymbolNode, Anchor, Span, PathNode, SvgNode, createClass} from "./domTree";
import {getCharacterMetrics} from "./fontMetrics";
import symbols, {ligatures} from "./symbols";
import {wideCharacterFont} from "./wide-character";
import {calculateSize, makeEm} from "./units";
import {DocumentFragment} from "./tree";
import type Options from "./Options";
import type {ParseNode} from "./parseNode";
import type {CharacterMetrics} from "./fontMetrics";
import type {FontVariant, Mode} from "./types";
import type {documentFragment as HtmlDocumentFragment} from "./domTree";
import type {HtmlDomNode, DomSpan, SvgSpan, CssStyle} from "./domTree";
import type {Measurement} from "./units";
/**
* Looks up the given symbol in fontMetrics, after applying any symbol
* replacements defined in symbol.js
*/
const lookupSymbol = function(
value: string,
// TODO(#963): Use a union type for this.
fontName: string,
mode: Mode,
): {value: string, metrics: ?CharacterMetrics} {
// Replace the value with its replaced value from symbol.js
if (symbols[mode][value] && symbols[mode][value].replace) {
value = symbols[mode][value].replace;
}
return {
value: value,
metrics: getCharacterMetrics(value, fontName, mode),
};
};
/**
* Makes a symbolNode after translation via the list of symbols in symbols.js.
* Correctly pulls out metrics for the character, and optionally takes a list of
* classes to be attached to the node.
*
* TODO: make argument order closer to makeSpan
* TODO: add a separate argument for math class (e.g. `mop`, `mbin`), which
* should if present come first in `classes`.
* TODO(#953): Make `options` mandatory and always pass it in.
*/
const makeSymbol = function(
value: string,
fontName: string,
mode: Mode,
options?: Options,
classes?: string[],
): SymbolNode {
const lookup = lookupSymbol(value, fontName, mode);
const metrics = lookup.metrics;
value = lookup.value;
let symbolNode;
if (metrics) {
let italic = metrics.italic;
if (mode === "text" || (options && options.font === "mathit")) {
italic = 0;
}
symbolNode = new SymbolNode(
value, metrics.height, metrics.depth, italic, metrics.skew,
metrics.width, classes);
} else {
// TODO(emily): Figure out a good way to only print this in development
typeof console !== "undefined" && console.warn("No character metrics " +
`for '${value}' in style '${fontName}' and mode '${mode}'`);
symbolNode = new SymbolNode(value, 0, 0, 0, 0, 0, classes);
}
if (options) {
symbolNode.maxFontSize = options.sizeMultiplier;
if (options.style.isTight()) {
symbolNode.classes.push("mtight");
}
const color = options.getColor();
if (color) {
symbolNode.style.color = color;
}
}
return symbolNode;
};
/**
* Makes a symbol in Main-Regular or AMS-Regular.
* Used for rel, bin, open, close, inner, and punct.
*/
const mathsym = function(
value: string,
mode: Mode,
options: Options,
classes?: string[] = [],
): SymbolNode {
// Decide what font to render the symbol in by its entry in the symbols
// table.
// Have a special case for when the value = \ because the \ is used as a
// textord in unsupported command errors but cannot be parsed as a regular
// text ordinal and is therefore not present as a symbol in the symbols
// table for text, as well as a special case for boldsymbol because it
// can be used for bold + and -
if (options.font === "boldsymbol" &&
lookupSymbol(value, "Main-Bold", mode).metrics) {
return makeSymbol(value, "Main-Bold", mode, options,
classes.concat(["mathbf"]));
} else if (value === "\\" || symbols[mode][value].font === "main") {
return makeSymbol(value, "Main-Regular", mode, options, classes);
} else {
return makeSymbol(
value, "AMS-Regular", mode, options, classes.concat(["amsrm"]));
}
};
/**
* Determines which of the two font names (Main-Bold and Math-BoldItalic) and
* corresponding style tags (mathbf or boldsymbol) to use for font "boldsymbol",
* depending on the symbol. Use this function instead of fontMap for font
* "boldsymbol".
*/
const boldsymbol = function(
value: string,
mode: Mode,
options: Options,
classes: string[],
type: "mathord" | "textord",
): {| fontName: string, fontClass: string |} {
if (type !== "textord" &&
lookupSymbol(value, "Math-BoldItalic", mode).metrics) {
return {
fontName: "Math-BoldItalic",
fontClass: "boldsymbol",
};
} else {
// Some glyphs do not exist in Math-BoldItalic so we need to use
// Main-Bold instead.
return {
fontName: "Main-Bold",
fontClass: "mathbf",
};
}
};
/**
* Makes either a mathord or textord in the correct font and color.
*/
const makeOrd = function<NODETYPE: "spacing" | "mathord" | "textord">(
group: ParseNode<NODETYPE>,
options: Options,
type: "mathord" | "textord",
): HtmlDocumentFragment | SymbolNode {
const mode = group.mode;
const text = group.text;
const classes = ["mord"];
// Math mode or Old font (i.e. \rm)
const isFont = mode === "math" || (mode === "text" && options.font);
const fontOrFamily = isFont ? options.font : options.fontFamily;
let wideFontName = "";
let wideFontClass = "";
if (text.charCodeAt(0) === 0xD835) {
[wideFontName, wideFontClass] = wideCharacterFont(text, mode);
}
if (wideFontName.length > 0) {
// surrogate pairs get special treatment
return makeSymbol(text, wideFontName, mode, options,
classes.concat(wideFontClass));
} else if (fontOrFamily) {
let fontName;
let fontClasses;
if (fontOrFamily === "boldsymbol") {
const fontData = boldsymbol(text, mode, options, classes, type);
fontName = fontData.fontName;
fontClasses = [fontData.fontClass];
} else if (isFont) {
fontName = fontMap[fontOrFamily].fontName;
fontClasses = [fontOrFamily];
} else {
fontName = retrieveTextFontName(fontOrFamily, options.fontWeight,
options.fontShape);
fontClasses = [fontOrFamily, options.fontWeight, options.fontShape];
}
if (lookupSymbol(text, fontName, mode).metrics) {
return makeSymbol(text, fontName, mode, options,
classes.concat(fontClasses));
} else if (ligatures.hasOwnProperty(text) &&
fontName.slice(0, 10) === "Typewriter") {
// Deconstruct ligatures in monospace fonts (\texttt, \tt).
const parts = [];
for (let i = 0; i < text.length; i++) {
parts.push(makeSymbol(text[i], fontName, mode, options,
classes.concat(fontClasses)));
}
return makeFragment(parts);
}
}
// Makes a symbol in the default font for mathords and textords.
if (type === "mathord") {
return makeSymbol(text, "Math-Italic", mode, options,
classes.concat(["mathnormal"]));
} else if (type === "textord") {
const font = symbols[mode][text] && symbols[mode][text].font;
if (font === "ams") {
const fontName = retrieveTextFontName("amsrm", options.fontWeight,
options.fontShape);
return makeSymbol(
text, fontName, mode, options,
classes.concat("amsrm", options.fontWeight, options.fontShape));
} else if (font === "main" || !font) {
const fontName = retrieveTextFontName("textrm", options.fontWeight,
options.fontShape);
return makeSymbol(
text, fontName, mode, options,
classes.concat(options.fontWeight, options.fontShape));
} else { // fonts added by plugins
const fontName = retrieveTextFontName(font, options.fontWeight,
options.fontShape);
// We add font name as a css class
return makeSymbol(
text, fontName, mode, options,
classes.concat(fontName, options.fontWeight, options.fontShape));
}
} else {
throw new Error("unexpected type: " + type + " in makeOrd");
}
};
/**
* Returns true if subsequent symbolNodes have the same classes, skew, maxFont,
* and styles.
*/
const canCombine = (prev: SymbolNode, next: SymbolNode) => {
if (createClass(prev.classes) !== createClass(next.classes)
|| prev.skew !== next.skew
|| prev.maxFontSize !== next.maxFontSize) {
return false;
}
// If prev and next both are just "mbin"s or "mord"s we don't combine them
// so that the proper spacing can be preserved.
if (prev.classes.length === 1) {
const cls = prev.classes[0];
if (cls === "mbin" || cls === "mord") {
return false;
}
}
for (const style in prev.style) {
if (prev.style.hasOwnProperty(style)
&& prev.style[style] !== next.style[style]) {
return false;
}
}
for (const style in next.style) {
if (next.style.hasOwnProperty(style)
&& prev.style[style] !== next.style[style]) {
return false;
}
}
return true;
};
/**
* Combine consecutive domTree.symbolNodes into a single symbolNode.
* Note: this function mutates the argument.
*/
const tryCombineChars = (chars: HtmlDomNode[]): HtmlDomNode[] => {
for (let i = 0; i < chars.length - 1; i++) {
const prev = chars[i];
const next = chars[i + 1];
if (prev instanceof SymbolNode
&& next instanceof SymbolNode
&& canCombine(prev, next)) {
prev.text += next.text;
prev.height = Math.max(prev.height, next.height);
prev.depth = Math.max(prev.depth, next.depth);
// Use the last character's italic correction since we use
// it to add padding to the right of the span created from
// the combined characters.
prev.italic = next.italic;
chars.splice(i + 1, 1);
i--;
}
}
return chars;
};
/**
* Calculate the height, depth, and maxFontSize of an element based on its
* children.
*/
const sizeElementFromChildren = function(
elem: DomSpan | Anchor | HtmlDocumentFragment,
) {
let height = 0;
let depth = 0;
let maxFontSize = 0;
for (let i = 0; i < elem.children.length; i++) {
const child = elem.children[i];
if (child.height > height) {
height = child.height;
}
if (child.depth > depth) {
depth = child.depth;
}
if (child.maxFontSize > maxFontSize) {
maxFontSize = child.maxFontSize;
}
}
elem.height = height;
elem.depth = depth;
elem.maxFontSize = maxFontSize;
};
/**
* Makes a span with the given list of classes, list of children, and options.
*
* TODO(#953): Ensure that `options` is always provided (currently some call
* sites don't pass it) and make the type below mandatory.
* TODO: add a separate argument for math class (e.g. `mop`, `mbin`), which
* should if present come first in `classes`.
*/
const makeSpan = function(
classes?: string[],
children?: HtmlDomNode[],
options?: Options,
style?: CssStyle,
): DomSpan {
const span = new Span(classes, children, options, style);
sizeElementFromChildren(span);
return span;
};
// SVG one is simpler -- doesn't require height, depth, max-font setting.
// This is also a separate method for typesafety.
const makeSvgSpan = (
classes?: string[],
children?: SvgNode[],
options?: Options,
style?: CssStyle,
): SvgSpan => new Span(classes, children, options, style);
const makeLineSpan = function(
className: string,
options: Options,
thickness?: number,
): DomSpan {
const line = makeSpan([className], [], options);
line.height = Math.max(
thickness || options.fontMetrics().defaultRuleThickness,
options.minRuleThickness,
);
line.style.borderBottomWidth = makeEm(line.height);
line.maxFontSize = 1.0;
return line;
};
/**
* Makes an anchor with the given href, list of classes, list of children,
* and options.
*/
const makeAnchor = function(
href: string,
classes: string[],
children: HtmlDomNode[],
options: Options,
): Anchor {
const anchor = new Anchor(href, classes, children, options);
sizeElementFromChildren(anchor);
return anchor;
};
/**
* Makes a document fragment with the given list of children.
*/
const makeFragment = function(
children: HtmlDomNode[],
): HtmlDocumentFragment {
const fragment = new DocumentFragment(children);
sizeElementFromChildren(fragment);
return fragment;
};
/**
* Wraps group in a span if it's a document fragment, allowing to apply classes
* and styles
*/
const wrapFragment = function(
group: HtmlDomNode,
options: Options,
): HtmlDomNode {
if (group instanceof DocumentFragment) {
return makeSpan([], [group], options);
}
return group;
};
// These are exact object types to catch typos in the names of the optional fields.
export type VListElem = {|
type: "elem",
elem: HtmlDomNode,
marginLeft?: ?string,
marginRight?: string,
wrapperClasses?: string[],
wrapperStyle?: CssStyle,
|};
type VListElemAndShift = {|
type: "elem",
elem: HtmlDomNode,
shift: number,
marginLeft?: ?string,
marginRight?: string,
wrapperClasses?: string[],
wrapperStyle?: CssStyle,
|};
type VListKern = {| type: "kern", size: number |};
// A list of child or kern nodes to be stacked on top of each other (i.e. the
// first element will be at the bottom, and the last at the top).
type VListChild = VListElem | VListKern;
type VListParam = {|
// Each child contains how much it should be shifted downward.
positionType: "individualShift",
children: VListElemAndShift[],
|} | {|
// "top": The positionData specifies the topmost point of the vlist (note this
// is expected to be a height, so positive values move up).
// "bottom": The positionData specifies the bottommost point of the vlist (note
// this is expected to be a depth, so positive values move down).
// "shift": The vlist will be positioned such that its baseline is positionData
// away from the baseline of the first child which MUST be an
// "elem". Positive values move downwards.
positionType: "top" | "bottom" | "shift",
positionData: number,
children: VListChild[],
|} | {|
// The vlist is positioned so that its baseline is aligned with the baseline
// of the first child which MUST be an "elem". This is equivalent to "shift"
// with positionData=0.
positionType: "firstBaseline",
children: VListChild[],
|};
// Computes the updated `children` list and the overall depth.
//
// This helper function for makeVList makes it easier to enforce type safety by
// allowing early exits (returns) in the logic.
const getVListChildrenAndDepth = function(params: VListParam): {
children: (VListChild | VListElemAndShift)[] | VListChild[],
depth: number,
} {
if (params.positionType === "individualShift") {
const oldChildren = params.children;
const children: (VListChild | VListElemAndShift)[] = [oldChildren[0]];
// Add in kerns to the list of params.children to get each element to be
// shifted to the correct specified shift
const depth = -oldChildren[0].shift - oldChildren[0].elem.depth;
let currPos = depth;
for (let i = 1; i < oldChildren.length; i++) {
const diff = -oldChildren[i].shift - currPos -
oldChildren[i].elem.depth;
const size = diff -
(oldChildren[i - 1].elem.height +
oldChildren[i - 1].elem.depth);
currPos = currPos + diff;
children.push({type: "kern", size});
children.push(oldChildren[i]);
}
return {children, depth};
}
let depth;
if (params.positionType === "top") {
// We always start at the bottom, so calculate the bottom by adding up
// all the sizes
let bottom = params.positionData;
for (let i = 0; i < params.children.length; i++) {
const child = params.children[i];
bottom -= child.type === "kern"
? child.size
: child.elem.height + child.elem.depth;
}
depth = bottom;
} else if (params.positionType === "bottom") {
depth = -params.positionData;
} else {
const firstChild = params.children[0];
if (firstChild.type !== "elem") {
throw new Error('First child must have type "elem".');
}
if (params.positionType === "shift") {
depth = -firstChild.elem.depth - params.positionData;
} else if (params.positionType === "firstBaseline") {
depth = -firstChild.elem.depth;
} else {
throw new Error(`Invalid positionType ${params.positionType}.`);
}
}
return {children: params.children, depth};
};
/**
* Makes a vertical list by stacking elements and kerns on top of each other.
* Allows for many different ways of specifying the positioning method.
*
* See VListParam documentation above.
*/
const makeVList = function(params: VListParam, options: Options): DomSpan {
const {children, depth} = getVListChildrenAndDepth(params);
// Create a strut that is taller than any list item. The strut is added to
// each item, where it will determine the item's baseline. Since it has
// `overflow:hidden`, the strut's top edge will sit on the item's line box's
// top edge and the strut's bottom edge will sit on the item's baseline,
// with no additional line-height spacing. This allows the item baseline to
// be positioned precisely without worrying about font ascent and
// line-height.
let pstrutSize = 0;
for (let i = 0; i < children.length; i++) {
const child = children[i];
if (child.type === "elem") {
const elem = child.elem;
pstrutSize = Math.max(pstrutSize, elem.maxFontSize, elem.height);
}
}
pstrutSize += 2;
const pstrut = makeSpan(["pstrut"], []);
pstrut.style.height = makeEm(pstrutSize);
// Create a new list of actual children at the correct offsets
const realChildren = [];
let minPos = depth;
let maxPos = depth;
let currPos = depth;
for (let i = 0; i < children.length; i++) {
const child = children[i];
if (child.type === "kern") {
currPos += child.size;
} else {
const elem = child.elem;
const classes = child.wrapperClasses || [];
const style = child.wrapperStyle || {};
const childWrap = makeSpan(classes, [pstrut, elem], undefined, style);
childWrap.style.top = makeEm(-pstrutSize - currPos - elem.depth);
if (child.marginLeft) {
childWrap.style.marginLeft = child.marginLeft;
}
if (child.marginRight) {
childWrap.style.marginRight = child.marginRight;
}
realChildren.push(childWrap);
currPos += elem.height + elem.depth;
}
minPos = Math.min(minPos, currPos);
maxPos = Math.max(maxPos, currPos);
}
// The vlist contents go in a table-cell with `vertical-align:bottom`.
// This cell's bottom edge will determine the containing table's baseline
// without overly expanding the containing line-box.
const vlist = makeSpan(["vlist"], realChildren);
vlist.style.height = makeEm(maxPos);
// A second row is used if necessary to represent the vlist's depth.
let rows;
if (minPos < 0) {
// We will define depth in an empty span with display: table-cell.
// It should render with the height that we define. But Chrome, in
// contenteditable mode only, treats that span as if it contains some
// text content. And that min-height over-rides our desired height.
// So we put another empty span inside the depth strut span.
const emptySpan = makeSpan([], []);
const depthStrut = makeSpan(["vlist"], [emptySpan]);
depthStrut.style.height = makeEm(-minPos);
// Safari wants the first row to have inline content; otherwise it
// puts the bottom of the *second* row on the baseline.
const topStrut = makeSpan(["vlist-s"], [new SymbolNode("\u200b")]);
rows = [makeSpan(["vlist-r"], [vlist, topStrut]),
makeSpan(["vlist-r"], [depthStrut])];
} else {
rows = [makeSpan(["vlist-r"], [vlist])];
}
const vtable = makeSpan(["vlist-t"], rows);
if (rows.length === 2) {
vtable.classes.push("vlist-t2");
}
vtable.height = maxPos;
vtable.depth = -minPos;
return vtable;
};
// Glue is a concept from TeX which is a flexible space between elements in
// either a vertical or horizontal list. In KaTeX, at least for now, it's
// static space between elements in a horizontal layout.
const makeGlue = (measurement: Measurement, options: Options): DomSpan => {
// Make an empty span for the space
const rule = makeSpan(["mspace"], [], options);
const size = calculateSize(measurement, options);
rule.style.marginRight = makeEm(size);
return rule;
};
// Takes font options, and returns the appropriate fontLookup name
const retrieveTextFontName = function(
fontFamily: string,
fontWeight: string,
fontShape: string,
): string {
let baseFontName = "";
switch (fontFamily) {
case "amsrm":
baseFontName = "AMS";
break;
case "textrm":
baseFontName = "Main";
break;
case "textsf":
baseFontName = "SansSerif";
break;
case "texttt":
baseFontName = "Typewriter";
break;
default:
baseFontName = fontFamily; // use fonts added by a plugin
}
let fontStylesName;
if (fontWeight === "textbf" && fontShape === "textit") {
fontStylesName = "BoldItalic";
} else if (fontWeight === "textbf") {
fontStylesName = "Bold";
} else if (fontWeight === "textit") {
fontStylesName = "Italic";
} else {
fontStylesName = "Regular";
}
return `${baseFontName}-${fontStylesName}`;
};
/**
* Maps TeX font commands to objects containing:
* - variant: string used for "mathvariant" attribute in buildMathML.js
* - fontName: the "style" parameter to fontMetrics.getCharacterMetrics
*/
// A map between tex font commands an MathML mathvariant attribute values
const fontMap: {[string]: {| variant: FontVariant, fontName: string |}} = {
// styles
"mathbf": {
variant: "bold",
fontName: "Main-Bold",
},
"mathrm": {
variant: "normal",
fontName: "Main-Regular",
},
"textit": {
variant: "italic",
fontName: "Main-Italic",
},
"mathit": {
variant: "italic",
fontName: "Main-Italic",
},
"mathnormal": {
variant: "italic",
fontName: "Math-Italic",
},
"mathsfit": {
variant: "sans-serif-italic",
fontName: "SansSerif-Italic",
},
// "boldsymbol" is missing because they require the use of multiple fonts:
// Math-BoldItalic and Main-Bold. This is handled by a special case in
// makeOrd which ends up calling boldsymbol.
// families
"mathbb": {
variant: "double-struck",
fontName: "AMS-Regular",
},
"mathcal": {
variant: "script",
fontName: "Caligraphic-Regular",
},
"mathfrak": {
variant: "fraktur",
fontName: "Fraktur-Regular",
},
"mathscr": {
variant: "script",
fontName: "Script-Regular",
},
"mathsf": {
variant: "sans-serif",
fontName: "SansSerif-Regular",
},
"mathtt": {
variant: "monospace",
fontName: "Typewriter-Regular",
},
};
const svgData: {
[string]: ([string, number, number])
} = {
// path, width, height
vec: ["vec", 0.471, 0.714], // values from the font glyph
oiintSize1: ["oiintSize1", 0.957, 0.499], // oval to overlay the integrand
oiintSize2: ["oiintSize2", 1.472, 0.659],
oiiintSize1: ["oiiintSize1", 1.304, 0.499],
oiiintSize2: ["oiiintSize2", 1.98, 0.659],
};
const staticSvg = function(value: string, options: Options): SvgSpan {
// Create a span with inline SVG for the element.
const [pathName, width, height] = svgData[value];
const path = new PathNode(pathName);
const svgNode = new SvgNode([path], {
"width": makeEm(width),
"height": makeEm(height),
// Override CSS rule `.katex svg { width: 100% }`
"style": "width:" + makeEm(width),
"viewBox": "0 0 " + 1000 * width + " " + 1000 * height,
"preserveAspectRatio": "xMinYMin",
});
const span = makeSvgSpan(["overlay"], [svgNode], options);
span.height = height;
span.style.height = makeEm(height);
span.style.width = makeEm(width);
return span;
};
export default {
fontMap,
makeSymbol,
mathsym,
makeSpan,
makeSvgSpan,
makeLineSpan,
makeAnchor,
makeFragment,
wrapFragment,
makeVList,
makeOrd,
makeGlue,
staticSvg,
svgData,
tryCombineChars,
};

406
node_modules/katex/src/buildHTML.js generated vendored Normal file
View File

@@ -0,0 +1,406 @@
// @flow
/**
* This file does the main work of building a domTree structure from a parse
* tree. The entry point is the `buildHTML` function, which takes a parse tree.
* Then, the buildExpression, buildGroup, and various groupBuilders functions
* are called, to produce a final HTML tree.
*/
import ParseError from "./ParseError";
import Style from "./Style";
import buildCommon from "./buildCommon";
import {Span, Anchor} from "./domTree";
import utils from "./utils";
import {makeEm} from "./units";
import {spacings, tightSpacings} from "./spacingData";
import {_htmlGroupBuilders as groupBuilders} from "./defineFunction";
import {DocumentFragment} from "./tree";
import type Options from "./Options";
import type {AnyParseNode} from "./parseNode";
import type {HtmlDomNode, DomSpan} from "./domTree";
const makeSpan = buildCommon.makeSpan;
// Binary atoms (first class `mbin`) change into ordinary atoms (`mord`)
// depending on their surroundings. See TeXbook pg. 442-446, Rules 5 and 6,
// and the text before Rule 19.
const binLeftCanceller = ["leftmost", "mbin", "mopen", "mrel", "mop", "mpunct"];
const binRightCanceller = ["rightmost", "mrel", "mclose", "mpunct"];
const styleMap = {
"display": Style.DISPLAY,
"text": Style.TEXT,
"script": Style.SCRIPT,
"scriptscript": Style.SCRIPTSCRIPT,
};
type Side = "left" | "right";
const DomEnum = {
mord: "mord",
mop: "mop",
mbin: "mbin",
mrel: "mrel",
mopen: "mopen",
mclose: "mclose",
mpunct: "mpunct",
minner: "minner",
};
type DomType = $Keys<typeof DomEnum>;
/**
* Take a list of nodes, build them in order, and return a list of the built
* nodes. documentFragments are flattened into their contents, so the
* returned list contains no fragments. `isRealGroup` is true if `expression`
* is a real group (no atoms will be added on either side), as opposed to
* a partial group (e.g. one created by \color). `surrounding` is an array
* consisting type of nodes that will be added to the left and right.
*/
export const buildExpression = function(
expression: AnyParseNode[],
options: Options,
isRealGroup: boolean | "root",
surrounding: [?DomType, ?DomType] = [null, null],
): HtmlDomNode[] {
// Parse expressions into `groups`.
const groups: HtmlDomNode[] = [];
for (let i = 0; i < expression.length; i++) {
const output = buildGroup(expression[i], options);
if (output instanceof DocumentFragment) {
const children: $ReadOnlyArray<HtmlDomNode> = output.children;
groups.push(...children);
} else {
groups.push(output);
}
}
// Combine consecutive domTree.symbolNodes into a single symbolNode.
buildCommon.tryCombineChars(groups);
// If `expression` is a partial group, let the parent handle spacings
// to avoid processing groups multiple times.
if (!isRealGroup) {
return groups;
}
let glueOptions = options;
if (expression.length === 1) {
const node = expression[0];
if (node.type === "sizing") {
glueOptions = options.havingSize(node.size);
} else if (node.type === "styling") {
glueOptions = options.havingStyle(styleMap[node.style]);
}
}
// Dummy spans for determining spacings between surrounding atoms.
// If `expression` has no atoms on the left or right, class "leftmost"
// or "rightmost", respectively, is used to indicate it.
const dummyPrev = makeSpan([surrounding[0] || "leftmost"], [], options);
const dummyNext = makeSpan([surrounding[1] || "rightmost"], [], options);
// TODO: These code assumes that a node's math class is the first element
// of its `classes` array. A later cleanup should ensure this, for
// instance by changing the signature of `makeSpan`.
// Before determining what spaces to insert, perform bin cancellation.
// Binary operators change to ordinary symbols in some contexts.
const isRoot = (isRealGroup === "root");
traverseNonSpaceNodes(groups, (node, prev) => {
const prevType = prev.classes[0];
const type = node.classes[0];
if (prevType === "mbin" && utils.contains(binRightCanceller, type)) {
prev.classes[0] = "mord";
} else if (type === "mbin" && utils.contains(binLeftCanceller, prevType)) {
node.classes[0] = "mord";
}
}, {node: dummyPrev}, dummyNext, isRoot);
traverseNonSpaceNodes(groups, (node, prev) => {
const prevType = getTypeOfDomTree(prev);
const type = getTypeOfDomTree(node);
// 'mtight' indicates that the node is script or scriptscript style.
const space = prevType && type ? (node.hasClass("mtight")
? tightSpacings[prevType][type]
: spacings[prevType][type]) : null;
if (space) { // Insert glue (spacing) after the `prev`.
return buildCommon.makeGlue(space, glueOptions);
}
}, {node: dummyPrev}, dummyNext, isRoot);
return groups;
};
// Depth-first traverse non-space `nodes`, calling `callback` with the current and
// previous node as arguments, optionally returning a node to insert after the
// previous node. `prev` is an object with the previous node and `insertAfter`
// function to insert after it. `next` is a node that will be added to the right.
// Used for bin cancellation and inserting spacings.
const traverseNonSpaceNodes = function(
nodes: HtmlDomNode[],
callback: (HtmlDomNode, HtmlDomNode) => ?HtmlDomNode,
prev: {|
node: HtmlDomNode,
insertAfter?: HtmlDomNode => void,
|},
next: ?HtmlDomNode,
isRoot: boolean,
) {
if (next) { // temporarily append the right node, if exists
nodes.push(next);
}
let i = 0;
for (; i < nodes.length; i++) {
const node = nodes[i];
const partialGroup = checkPartialGroup(node);
if (partialGroup) { // Recursive DFS
// $FlowFixMe: make nodes a $ReadOnlyArray by returning a new array
traverseNonSpaceNodes(partialGroup.children,
callback, prev, null, isRoot);
continue;
}
// Ignore explicit spaces (e.g., \;, \,) when determining what implicit
// spacing should go between atoms of different classes
const nonspace = !node.hasClass("mspace");
if (nonspace) {
const result = callback(node, prev.node);
if (result) {
if (prev.insertAfter) {
prev.insertAfter(result);
} else { // insert at front
nodes.unshift(result);
i++;
}
}
}
if (nonspace) {
prev.node = node;
} else if (isRoot && node.hasClass("newline")) {
prev.node = makeSpan(["leftmost"]); // treat like beginning of line
}
prev.insertAfter = (index => n => {
nodes.splice(index + 1, 0, n);
i++;
})(i);
}
if (next) {
nodes.pop();
}
};
// Check if given node is a partial group, i.e., does not affect spacing around.
const checkPartialGroup = function(
node: HtmlDomNode,
): ?(DocumentFragment<HtmlDomNode> | Anchor | DomSpan) {
if (node instanceof DocumentFragment || node instanceof Anchor
|| (node instanceof Span && node.hasClass("enclosing"))) {
return node;
}
return null;
};
// Return the outermost node of a domTree.
const getOutermostNode = function(
node: HtmlDomNode,
side: Side,
): HtmlDomNode {
const partialGroup = checkPartialGroup(node);
if (partialGroup) {
const children = partialGroup.children;
if (children.length) {
if (side === "right") {
return getOutermostNode(children[children.length - 1], "right");
} else if (side === "left") {
return getOutermostNode(children[0], "left");
}
}
}
return node;
};
// Return math atom class (mclass) of a domTree.
// If `side` is given, it will get the type of the outermost node at given side.
export const getTypeOfDomTree = function(
node: ?HtmlDomNode,
side: ?Side,
): ?DomType {
if (!node) {
return null;
}
if (side) {
node = getOutermostNode(node, side);
}
// This makes a lot of assumptions as to where the type of atom
// appears. We should do a better job of enforcing this.
return DomEnum[node.classes[0]] || null;
};
export const makeNullDelimiter = function(
options: Options,
classes: string[],
): DomSpan {
const moreClasses = ["nulldelimiter"].concat(options.baseSizingClasses());
return makeSpan(classes.concat(moreClasses));
};
/**
* buildGroup is the function that takes a group and calls the correct groupType
* function for it. It also handles the interaction of size and style changes
* between parents and children.
*/
export const buildGroup = function(
group: ?AnyParseNode,
options: Options,
baseOptions?: Options,
): HtmlDomNode {
if (!group) {
return makeSpan();
}
if (groupBuilders[group.type]) {
// Call the groupBuilders function
// $FlowFixMe
let groupNode: HtmlDomNode = groupBuilders[group.type](group, options);
// If the size changed between the parent and the current group, account
// for that size difference.
if (baseOptions && options.size !== baseOptions.size) {
groupNode = makeSpan(options.sizingClasses(baseOptions),
[groupNode], options);
const multiplier =
options.sizeMultiplier / baseOptions.sizeMultiplier;
groupNode.height *= multiplier;
groupNode.depth *= multiplier;
}
return groupNode;
} else {
throw new ParseError(
"Got group of unknown type: '" + group.type + "'");
}
};
/**
* Combine an array of HTML DOM nodes (e.g., the output of `buildExpression`)
* into an unbreakable HTML node of class .base, with proper struts to
* guarantee correct vertical extent. `buildHTML` calls this repeatedly to
* make up the entire expression as a sequence of unbreakable units.
*/
function buildHTMLUnbreakable(children, options) {
// Compute height and depth of this chunk.
const body = makeSpan(["base"], children, options);
// Add strut, which ensures that the top of the HTML element falls at
// the height of the expression, and the bottom of the HTML element
// falls at the depth of the expression.
const strut = makeSpan(["strut"]);
strut.style.height = makeEm(body.height + body.depth);
if (body.depth) {
strut.style.verticalAlign = makeEm(-body.depth);
}
body.children.unshift(strut);
return body;
}
/**
* Take an entire parse tree, and build it into an appropriate set of HTML
* nodes.
*/
export default function buildHTML(tree: AnyParseNode[], options: Options): DomSpan {
// Strip off outer tag wrapper for processing below.
let tag = null;
if (tree.length === 1 && tree[0].type === "tag") {
tag = tree[0].tag;
tree = tree[0].body;
}
// Build the expression contained in the tree
const expression = buildExpression(tree, options, "root");
let eqnNum;
if (expression.length === 2 && expression[1].hasClass("tag")) {
// An environment with automatic equation numbers, e.g. {gather}.
eqnNum = expression.pop();
}
const children = [];
// Create one base node for each chunk between potential line breaks.
// The TeXBook [p.173] says "A formula will be broken only after a
// relation symbol like $=$ or $<$ or $\rightarrow$, or after a binary
// operation symbol like $+$ or $-$ or $\times$, where the relation or
// binary operation is on the ``outer level'' of the formula (i.e., not
// enclosed in {...} and not part of an \over construction)."
let parts = [];
for (let i = 0; i < expression.length; i++) {
parts.push(expression[i]);
if (expression[i].hasClass("mbin") ||
expression[i].hasClass("mrel") ||
expression[i].hasClass("allowbreak")) {
// Put any post-operator glue on same line as operator.
// Watch for \nobreak along the way, and stop at \newline.
let nobreak = false;
while (i < expression.length - 1 &&
expression[i + 1].hasClass("mspace") &&
!expression[i + 1].hasClass("newline")) {
i++;
parts.push(expression[i]);
if (expression[i].hasClass("nobreak")) {
nobreak = true;
}
}
// Don't allow break if \nobreak among the post-operator glue.
if (!nobreak) {
children.push(buildHTMLUnbreakable(parts, options));
parts = [];
}
} else if (expression[i].hasClass("newline")) {
// Write the line except the newline
parts.pop();
if (parts.length > 0) {
children.push(buildHTMLUnbreakable(parts, options));
parts = [];
}
// Put the newline at the top level
children.push(expression[i]);
}
}
if (parts.length > 0) {
children.push(buildHTMLUnbreakable(parts, options));
}
// Now, if there was a tag, build it too and append it as a final child.
let tagChild;
if (tag) {
tagChild = buildHTMLUnbreakable(
buildExpression(tag, options, true)
);
tagChild.classes = ["tag"];
children.push(tagChild);
} else if (eqnNum) {
children.push(eqnNum);
}
const htmlNode = makeSpan(["katex-html"], children);
htmlNode.setAttribute("aria-hidden", "true");
// Adjust the strut of the tag to be the maximum height of all children
// (the height of the enclosing htmlNode) for proper vertical alignment.
if (tagChild) {
const strut = tagChild.children[0];
strut.style.height = makeEm(htmlNode.height + htmlNode.depth);
if (htmlNode.depth) {
strut.style.verticalAlign = makeEm(-htmlNode.depth);
}
}
return htmlNode;
}

322
node_modules/katex/src/buildMathML.js generated vendored Normal file
View File

@@ -0,0 +1,322 @@
// @flow
/**
* This file converts a parse tree into a corresponding MathML tree. The main
* entry point is the `buildMathML` function, which takes a parse tree from the
* parser.
*/
import buildCommon from "./buildCommon";
import {getCharacterMetrics} from "./fontMetrics";
import mathMLTree from "./mathMLTree";
import ParseError from "./ParseError";
import symbols, {ligatures} from "./symbols";
import utils from "./utils";
import {_mathmlGroupBuilders as groupBuilders} from "./defineFunction";
import {MathNode, TextNode} from "./mathMLTree";
import type Options from "./Options";
import type {AnyParseNode, SymbolParseNode} from "./parseNode";
import type {DomSpan} from "./domTree";
import type {MathDomNode} from "./mathMLTree";
import type {FontVariant, Mode} from "./types";
/**
* Takes a symbol and converts it into a MathML text node after performing
* optional replacement from symbols.js.
*/
export const makeText = function(
text: string,
mode: Mode,
options?: Options,
): TextNode {
if (symbols[mode][text] && symbols[mode][text].replace &&
text.charCodeAt(0) !== 0xD835 &&
!(ligatures.hasOwnProperty(text) && options &&
((options.fontFamily && options.fontFamily.slice(4, 6) === "tt") ||
(options.font && options.font.slice(4, 6) === "tt")))) {
text = symbols[mode][text].replace;
}
return new mathMLTree.TextNode(text);
};
/**
* Wrap the given array of nodes in an <mrow> node if needed, i.e.,
* unless the array has length 1. Always returns a single node.
*/
export const makeRow = function(body: $ReadOnlyArray<MathDomNode>): MathDomNode {
if (body.length === 1) {
return body[0];
} else {
return new mathMLTree.MathNode("mrow", body);
}
};
/**
* Returns the math variant as a string or null if none is required.
*/
export const getVariant = function(
group: SymbolParseNode,
options: Options,
): ?FontVariant {
// Handle \text... font specifiers as best we can.
// MathML has a limited list of allowable mathvariant specifiers; see
// https://www.w3.org/TR/MathML3/chapter3.html#presm.commatt
if (options.fontFamily === "texttt") {
return "monospace";
} else if (options.fontFamily === "textsf") {
if (options.fontShape === "textit" &&
options.fontWeight === "textbf") {
return "sans-serif-bold-italic";
} else if (options.fontShape === "textit") {
return "sans-serif-italic";
} else if (options.fontWeight === "textbf") {
return "bold-sans-serif";
} else {
return "sans-serif";
}
} else if (options.fontShape === "textit" &&
options.fontWeight === "textbf") {
return "bold-italic";
} else if (options.fontShape === "textit") {
return "italic";
} else if (options.fontWeight === "textbf") {
return "bold";
}
const font = options.font;
if (!font || font === "mathnormal") {
return null;
}
const mode = group.mode;
if (font === "mathit") {
return "italic";
} else if (font === "boldsymbol") {
return group.type === "textord" ? "bold" : "bold-italic";
} else if (font === "mathbf") {
return "bold";
} else if (font === "mathbb") {
return "double-struck";
} else if (font === "mathsfit") {
return "sans-serif-italic";
} else if (font === "mathfrak") {
return "fraktur";
} else if (font === "mathscr" || font === "mathcal") {
// MathML makes no distinction between script and calligraphic
return "script";
} else if (font === "mathsf") {
return "sans-serif";
} else if (font === "mathtt") {
return "monospace";
}
let text = group.text;
if (utils.contains(["\\imath", "\\jmath"], text)) {
return null;
}
if (symbols[mode][text] && symbols[mode][text].replace) {
text = symbols[mode][text].replace;
}
const fontName = buildCommon.fontMap[font].fontName;
if (getCharacterMetrics(text, fontName, mode)) {
return buildCommon.fontMap[font].variant;
}
return null;
};
/**
* Check for <mi>.</mi> which is how a dot renders in MathML,
* or <mo separator="true" lspace="0em" rspace="0em">,</mo>
* which is how a braced comma {,} renders in MathML
*/
function isNumberPunctuation(group: ?MathNode): boolean {
if (!group) {
return false;
}
if (group.type === 'mi' && group.children.length === 1) {
const child = group.children[0];
return child instanceof TextNode && child.text === '.';
} else if (group.type === 'mo' && group.children.length === 1 &&
group.getAttribute('separator') === 'true' &&
group.getAttribute('lspace') === '0em' &&
group.getAttribute('rspace') === '0em'
) {
const child = group.children[0];
return child instanceof TextNode && child.text === ',';
} else {
return false;
}
}
/**
* Takes a list of nodes, builds them, and returns a list of the generated
* MathML nodes. Also combine consecutive <mtext> outputs into a single
* <mtext> tag.
*/
export const buildExpression = function(
expression: AnyParseNode[],
options: Options,
isOrdgroup?: boolean,
): MathNode[] {
if (expression.length === 1) {
const group = buildGroup(expression[0], options);
if (isOrdgroup && group instanceof MathNode && group.type === "mo") {
// When TeX writers want to suppress spacing on an operator,
// they often put the operator by itself inside braces.
group.setAttribute("lspace", "0em");
group.setAttribute("rspace", "0em");
}
return [group];
}
const groups = [];
let lastGroup;
for (let i = 0; i < expression.length; i++) {
const group = buildGroup(expression[i], options);
if (group instanceof MathNode && lastGroup instanceof MathNode) {
// Concatenate adjacent <mtext>s
if (group.type === 'mtext' && lastGroup.type === 'mtext'
&& group.getAttribute('mathvariant') ===
lastGroup.getAttribute('mathvariant')) {
lastGroup.children.push(...group.children);
continue;
// Concatenate adjacent <mn>s
} else if (group.type === 'mn' && lastGroup.type === 'mn') {
lastGroup.children.push(...group.children);
continue;
// Concatenate <mn>...</mn> followed by <mi>.</mi>
} else if (isNumberPunctuation(group) && lastGroup.type === 'mn') {
lastGroup.children.push(...group.children);
continue;
// Concatenate <mi>.</mi> followed by <mn>...</mn>
} else if (group.type === 'mn' && isNumberPunctuation(lastGroup)) {
group.children = [...lastGroup.children, ...group.children];
groups.pop();
// Put preceding <mn>...</mn> or <mi>.</mi> inside base of
// <msup><mn>...base...</mn>...exponent...</msup> (or <msub>)
} else if ((group.type === 'msup' || group.type === 'msub') &&
group.children.length >= 1 &&
(lastGroup.type === 'mn' || isNumberPunctuation(lastGroup))
) {
const base = group.children[0];
if (base instanceof MathNode && base.type === 'mn') {
base.children = [...lastGroup.children, ...base.children];
groups.pop();
}
// \not
} else if (lastGroup.type === 'mi' && lastGroup.children.length === 1) {
const lastChild = lastGroup.children[0];
if (lastChild instanceof TextNode && lastChild.text === '\u0338' &&
(group.type === 'mo' || group.type === 'mi' ||
group.type === 'mn')) {
const child = group.children[0];
if (child instanceof TextNode && child.text.length > 0) {
// Overlay with combining character long solidus
child.text = child.text.slice(0, 1) + "\u0338" +
child.text.slice(1);
groups.pop();
}
}
}
}
groups.push(group);
lastGroup = group;
}
return groups;
};
/**
* Equivalent to buildExpression, but wraps the elements in an <mrow>
* if there's more than one. Returns a single node instead of an array.
*/
export const buildExpressionRow = function(
expression: AnyParseNode[],
options: Options,
isOrdgroup?: boolean,
): MathDomNode {
return makeRow(buildExpression(expression, options, isOrdgroup));
};
/**
* Takes a group from the parser and calls the appropriate groupBuilders function
* on it to produce a MathML node.
*/
export const buildGroup = function(
group: ?AnyParseNode,
options: Options,
): MathNode {
if (!group) {
return new mathMLTree.MathNode("mrow");
}
if (groupBuilders[group.type]) {
// Call the groupBuilders function
// $FlowFixMe
const result: MathDomNode = groupBuilders[group.type](group, options);
// $FlowFixMe
return result;
} else {
throw new ParseError(
"Got group of unknown type: '" + group.type + "'");
}
};
/**
* Takes a full parse tree and settings and builds a MathML representation of
* it. In particular, we put the elements from building the parse tree into a
* <semantics> tag so we can also include that TeX source as an annotation.
*
* Note that we actually return a domTree element with a `<math>` inside it so
* we can do appropriate styling.
*/
export default function buildMathML(
tree: AnyParseNode[],
texExpression: string,
options: Options,
isDisplayMode: boolean,
forMathmlOnly: boolean,
): DomSpan {
const expression = buildExpression(tree, options);
// TODO: Make a pass thru the MathML similar to buildHTML.traverseNonSpaceNodes
// and add spacing nodes. This is necessary only adjacent to math operators
// like \sin or \lim or to subsup elements that contain math operators.
// MathML takes care of the other spacing issues.
// Wrap up the expression in an mrow so it is presented in the semantics
// tag correctly, unless it's a single <mrow> or <mtable>.
let wrapper;
if (expression.length === 1 && expression[0] instanceof MathNode &&
utils.contains(["mrow", "mtable"], expression[0].type)) {
wrapper = expression[0];
} else {
wrapper = new mathMLTree.MathNode("mrow", expression);
}
// Build a TeX annotation of the source
const annotation = new mathMLTree.MathNode(
"annotation", [new mathMLTree.TextNode(texExpression)]);
annotation.setAttribute("encoding", "application/x-tex");
const semantics = new mathMLTree.MathNode(
"semantics", [wrapper, annotation]);
const math = new mathMLTree.MathNode("math", [semantics]);
math.setAttribute("xmlns", "http://www.w3.org/1998/Math/MathML");
if (isDisplayMode) {
math.setAttribute("display", "block");
}
// You can't style <math> nodes, so we wrap the node in a span.
// NOTE: The span class is not typed to have <math> nodes as children, and
// we don't want to make the children type more generic since the children
// of span are expected to have more fields in `buildHtml` contexts.
const wrapperClass = forMathmlOnly ? "katex" : "katex-mathml";
// $FlowFixMe
return buildCommon.makeSpan([wrapperClass], [math]);
}

67
node_modules/katex/src/buildTree.js generated vendored Normal file
View File

@@ -0,0 +1,67 @@
// @flow
import buildHTML from "./buildHTML";
import buildMathML from "./buildMathML";
import buildCommon from "./buildCommon";
import Options from "./Options";
import Settings from "./Settings";
import Style from "./Style";
import type {AnyParseNode} from "./parseNode";
import type {DomSpan} from "./domTree";
const optionsFromSettings = function(settings: Settings) {
return new Options({
style: (settings.displayMode ? Style.DISPLAY : Style.TEXT),
maxSize: settings.maxSize,
minRuleThickness: settings.minRuleThickness,
});
};
const displayWrap = function(node: DomSpan, settings: Settings): DomSpan {
if (settings.displayMode) {
const classes = ["katex-display"];
if (settings.leqno) {
classes.push("leqno");
}
if (settings.fleqn) {
classes.push("fleqn");
}
node = buildCommon.makeSpan(classes, [node]);
}
return node;
};
export const buildTree = function(
tree: AnyParseNode[],
expression: string,
settings: Settings,
): DomSpan {
const options = optionsFromSettings(settings);
let katexNode;
if (settings.output === "mathml") {
return buildMathML(tree, expression, options, settings.displayMode, true);
} else if (settings.output === "html") {
const htmlNode = buildHTML(tree, options);
katexNode = buildCommon.makeSpan(["katex"], [htmlNode]);
} else {
const mathMLNode = buildMathML(tree, expression, options,
settings.displayMode, false);
const htmlNode = buildHTML(tree, options);
katexNode = buildCommon.makeSpan(["katex"], [mathMLNode, htmlNode]);
}
return displayWrap(katexNode, settings);
};
export const buildHTMLTree = function(
tree: AnyParseNode[],
expression: string,
settings: Settings,
): DomSpan {
const options = optionsFromSettings(settings);
const htmlNode = buildHTML(tree, options);
const katexNode = buildCommon.makeSpan(["katex"], [htmlNode]);
return displayWrap(katexNode, settings);
};
export default buildTree;

117
node_modules/katex/src/defineEnvironment.js generated vendored Normal file
View File

@@ -0,0 +1,117 @@
// @flow
import {_htmlGroupBuilders, _mathmlGroupBuilders} from "./defineFunction";
import type Parser from "./Parser";
import type {AnyParseNode} from "./parseNode";
import type {ArgType, Mode} from "./types";
import type {NodeType} from "./parseNode";
import type {HtmlBuilder, MathMLBuilder} from "./defineFunction";
/**
* The context contains the following properties:
* - mode: current parsing mode.
* - envName: the name of the environment, one of the listed names.
* - parser: the parser object.
*/
type EnvContext = {|
mode: Mode,
envName: string,
parser: Parser,
|};
/**
* - context: information and references provided by the parser
* - args: an array of arguments passed to \begin{name}
* - optArgs: an array of optional arguments passed to \begin{name}
*/
type EnvHandler = (
context: EnvContext,
args: AnyParseNode[],
optArgs: (?AnyParseNode)[],
) => AnyParseNode;
/**
* - numArgs: (default 0) The number of arguments after the \begin{name} function.
* - argTypes: (optional) Just like for a function
* - allowedInText: (default false) Whether or not the environment is allowed
* inside text mode (not enforced yet).
* - numOptionalArgs: (default 0) Just like for a function
*/
type EnvProps = {
numArgs: number,
};
/**
* Final environment spec for use at parse time.
* This is almost identical to `EnvDefSpec`, except it
* 1. includes the function handler
* 2. requires all arguments except argType
* It is generated by `defineEnvironment()` below.
*/
export type EnvSpec<NODETYPE: NodeType> = {|
type: NODETYPE, // Need to use the type to avoid error. See NOTES below.
numArgs: number,
argTypes?: ArgType[],
allowedInText: boolean,
numOptionalArgs: number,
handler: EnvHandler,
|};
/**
* All registered environments.
* `environments.js` exports this same dictionary again and makes it public.
* `Parser.js` requires this dictionary via `environments.js`.
*/
export const _environments: {[string]: EnvSpec<*>} = {};
type EnvDefSpec<NODETYPE: NodeType> = {|
// Unique string to differentiate parse nodes.
type: NODETYPE,
// List of functions which use the give handler, htmlBuilder,
// and mathmlBuilder.
names: Array<string>,
// Properties that control how the environments are parsed.
props: EnvProps,
handler: EnvHandler,
// This function returns an object representing the DOM structure to be
// created when rendering the defined LaTeX function.
htmlBuilder: HtmlBuilder<NODETYPE>,
// This function returns an object representing the MathML structure to be
// created when rendering the defined LaTeX function.
mathmlBuilder: MathMLBuilder<NODETYPE>,
|};
export default function defineEnvironment<NODETYPE: NodeType>({
type,
names,
props,
handler,
htmlBuilder,
mathmlBuilder,
}: EnvDefSpec<NODETYPE>) {
// Set default values of environments.
const data = {
type,
numArgs: props.numArgs || 0,
allowedInText: false,
numOptionalArgs: 0,
handler,
};
for (let i = 0; i < names.length; ++i) {
// TODO: The value type of _environments should be a type union of all
// possible `EnvSpec<>` possibilities instead of `EnvSpec<*>`, which is
// an existential type.
_environments[names[i]] = data;
}
if (htmlBuilder) {
_htmlGroupBuilders[type] = htmlBuilder;
}
if (mathmlBuilder) {
_mathmlGroupBuilders[type] = mathmlBuilder;
}
}

223
node_modules/katex/src/defineFunction.js generated vendored Normal file
View File

@@ -0,0 +1,223 @@
// @flow
import type Parser from "./Parser";
import type {ParseNode, AnyParseNode, NodeType, UnsupportedCmdParseNode}
from "./parseNode";
import type Options from "./Options";
import type {ArgType, BreakToken} from "./types";
import type {HtmlDomNode} from "./domTree";
import type {Token} from "./Token";
import type {MathDomNode} from "./mathMLTree";
/** Context provided to function handlers for error messages. */
export type FunctionContext = {|
funcName: string,
parser: Parser,
token?: Token,
breakOnTokenText?: BreakToken,
|};
export type FunctionHandler<NODETYPE: NodeType> = (
context: FunctionContext,
args: AnyParseNode[],
optArgs: (?AnyParseNode)[],
) => UnsupportedCmdParseNode | ParseNode<NODETYPE>;
// Note: reverse the order of the return type union will cause a flow error.
// See https://github.com/facebook/flow/issues/3663.
export type HtmlBuilder<NODETYPE> = (ParseNode<NODETYPE>, Options) => HtmlDomNode;
export type MathMLBuilder<NODETYPE> = (
group: ParseNode<NODETYPE>,
options: Options,
) => MathDomNode;
// More general version of `HtmlBuilder` for nodes (e.g. \sum, accent types)
// whose presence impacts super/subscripting. In this case, ParseNode<"supsub">
// delegates its HTML building to the HtmlBuilder corresponding to these nodes.
export type HtmlBuilderSupSub<NODETYPE> =
(ParseNode<"supsub"> | ParseNode<NODETYPE>, Options) => HtmlDomNode;
export type FunctionPropSpec = {
// The number of arguments the function takes.
numArgs: number,
// An array corresponding to each argument of the function, giving the
// type of argument that should be parsed. Its length should be equal
// to `numOptionalArgs + numArgs`, and types for optional arguments
// should appear before types for mandatory arguments.
argTypes?: ArgType[],
// Whether it expands to a single token or a braced group of tokens.
// If it's grouped, it can be used as an argument to primitive commands,
// such as \sqrt (without the optional argument) and super/subscript.
allowedInArgument?: boolean,
// Whether or not the function is allowed inside text mode
// (default false)
allowedInText?: boolean,
// Whether or not the function is allowed inside text mode
// (default true)
allowedInMath?: boolean,
// (optional) The number of optional arguments the function
// should parse. If the optional arguments aren't found,
// `null` will be passed to the handler in their place.
// (default 0)
numOptionalArgs?: number,
// Must be true if the function is an infix operator.
infix?: boolean,
// Whether or not the function is a TeX primitive.
primitive?: boolean,
};
type FunctionDefSpec<NODETYPE: NodeType> = {|
// Unique string to differentiate parse nodes.
// Also determines the type of the value returned by `handler`.
type: NODETYPE,
// The first argument to defineFunction is a single name or a list of names.
// All functions named in such a list will share a single implementation.
names: Array<string>,
// Properties that control how the functions are parsed.
props: FunctionPropSpec,
// The handler is called to handle these functions and their arguments and
// returns a `ParseNode`.
handler: ?FunctionHandler<NODETYPE>,
// This function returns an object representing the DOM structure to be
// created when rendering the defined LaTeX function.
// This should not modify the `ParseNode`.
htmlBuilder?: HtmlBuilder<NODETYPE>,
// This function returns an object representing the MathML structure to be
// created when rendering the defined LaTeX function.
// This should not modify the `ParseNode`.
mathmlBuilder?: MathMLBuilder<NODETYPE>,
|};
/**
* Final function spec for use at parse time.
* This is almost identical to `FunctionPropSpec`, except it
* 1. includes the function handler, and
* 2. requires all arguments except argTypes.
* It is generated by `defineFunction()` below.
*/
export type FunctionSpec<NODETYPE: NodeType> = {|
type: NODETYPE, // Need to use the type to avoid error. See NOTES below.
numArgs: number,
argTypes?: ArgType[],
allowedInArgument: boolean,
allowedInText: boolean,
allowedInMath: boolean,
numOptionalArgs: number,
infix: boolean,
primitive: boolean,
// FLOW TYPE NOTES: Doing either one of the following two
//
// - removing the NODETYPE type parameter in FunctionSpec above;
// - using ?FunctionHandler<NODETYPE> below;
//
// results in a confusing flow typing error:
// "string literal `styling`. This type is incompatible with..."
// pointing to the definition of `defineFunction` and finishing with
// "some incompatible instantiation of `NODETYPE`"
//
// Having FunctionSpec<NODETYPE> above and FunctionHandler<*> below seems to
// circumvent this error. This is not harmful for catching errors since
// _functions is typed FunctionSpec<*> (it stores all TeX function specs).
// Must be specified unless it's handled directly in the parser.
handler: ?FunctionHandler<*>,
|};
/**
* All registered functions.
* `functions.js` just exports this same dictionary again and makes it public.
* `Parser.js` requires this dictionary.
*/
export const _functions: {[string]: FunctionSpec<*>} = {};
/**
* All HTML builders. Should be only used in the `define*` and the `build*ML`
* functions.
*/
export const _htmlGroupBuilders: {[string]: HtmlBuilder<*>} = {};
/**
* All MathML builders. Should be only used in the `define*` and the `build*ML`
* functions.
*/
export const _mathmlGroupBuilders: {[string]: MathMLBuilder<*>} = {};
export default function defineFunction<NODETYPE: NodeType>({
type,
names,
props,
handler,
htmlBuilder,
mathmlBuilder,
}: FunctionDefSpec<NODETYPE>) {
// Set default values of functions
const data = {
type,
numArgs: props.numArgs,
argTypes: props.argTypes,
allowedInArgument: !!props.allowedInArgument,
allowedInText: !!props.allowedInText,
allowedInMath: (props.allowedInMath === undefined)
? true
: props.allowedInMath,
numOptionalArgs: props.numOptionalArgs || 0,
infix: !!props.infix,
primitive: !!props.primitive,
handler: handler,
};
for (let i = 0; i < names.length; ++i) {
_functions[names[i]] = data;
}
if (type) {
if (htmlBuilder) {
_htmlGroupBuilders[type] = htmlBuilder;
}
if (mathmlBuilder) {
_mathmlGroupBuilders[type] = mathmlBuilder;
}
}
}
/**
* Use this to register only the HTML and MathML builders for a function (e.g.
* if the function's ParseNode is generated in Parser.js rather than via a
* stand-alone handler provided to `defineFunction`).
*/
export function defineFunctionBuilders<NODETYPE: NodeType>({
type, htmlBuilder, mathmlBuilder,
}: {|
type: NODETYPE,
htmlBuilder?: HtmlBuilder<NODETYPE>,
mathmlBuilder: MathMLBuilder<NODETYPE>,
|}) {
defineFunction({
type,
names: [],
props: {numArgs: 0},
handler() { throw new Error('Should never be called.'); },
htmlBuilder,
mathmlBuilder,
});
}
export const normalizeArgument = function(arg: AnyParseNode): AnyParseNode {
return arg.type === "ordgroup" && arg.body.length === 1 ? arg.body[0] : arg;
};
// Since the corresponding buildHTML/buildMathML function expects a
// list of elements, we normalize for different kinds of arguments
export const ordargument = function(arg: AnyParseNode): AnyParseNode[] {
return arg.type === "ordgroup" ? arg.body : [arg];
};

125
node_modules/katex/src/defineMacro.js generated vendored Normal file
View File

@@ -0,0 +1,125 @@
// @flow
import {Token} from "./Token";
import type Namespace from "./Namespace";
import type {Mode} from "./types";
/**
* Provides context to macros defined by functions. Implemented by
* MacroExpander.
*/
export interface MacroContextInterface {
mode: Mode;
/**
* Object mapping macros to their expansions.
*/
macros: Namespace<MacroDefinition>;
/**
* Returns the topmost token on the stack, without expanding it.
* Similar in behavior to TeX's `\futurelet`.
*/
future(): Token;
/**
* Remove and return the next unexpanded token.
*/
popToken(): Token;
/**
* Consume all following space tokens, without expansion.
*/
consumeSpaces(): void;
/**
* Expand the next token only once if possible.
*/
expandOnce(expandableOnly?: boolean): number | boolean;
/**
* Expand the next token only once (if possible), and return the resulting
* top token on the stack (without removing anything from the stack).
* Similar in behavior to TeX's `\expandafter\futurelet`.
*/
expandAfterFuture(): Token;
/**
* Recursively expand first token, then return first non-expandable token.
*/
expandNextToken(): Token;
/**
* Fully expand the given macro name and return the resulting list of
* tokens, or return `undefined` if no such macro is defined.
*/
expandMacro(name: string): Token[] | void;
/**
* Fully expand the given macro name and return the result as a string,
* or return `undefined` if no such macro is defined.
*/
expandMacroAsText(name: string): string | void;
/**
* Fully expand the given token stream and return the resulting list of
* tokens. Note that the input tokens are in reverse order, but the
* output tokens are in forward order.
*/
expandTokens(tokens: Token[]): Token[];
/**
* Consume an argument from the token stream, and return the resulting array
* of tokens and start/end token.
*/
consumeArg(delims?: ?string[]): MacroArg;
/**
* Consume the specified number of arguments from the token stream,
* and return the resulting array of arguments.
*/
consumeArgs(numArgs: number): Token[][];
/**
* Determine whether a command is currently "defined" (has some
* functionality), meaning that it's a macro (in the current group),
* a function, a symbol, or one of the special commands listed in
* `implicitCommands`.
*/
isDefined(name: string): boolean;
/**
* Determine whether a command is expandable.
*/
isExpandable(name: string): boolean;
}
export type MacroArg = {
tokens: Token[],
start: Token,
end: Token
};
/** Macro tokens (in reverse order). */
export type MacroExpansion = {
tokens: Token[],
numArgs: number,
delimiters?: string[][],
unexpandable?: boolean, // used in \let
};
export type MacroDefinition = string | MacroExpansion |
(MacroContextInterface => (string | MacroExpansion));
export type MacroMap = {[string]: MacroDefinition};
/**
* All registered global/built-in macros.
* `macros.js` exports this same dictionary again and makes it public.
* `Parser.js` requires this dictionary via `macros.js`.
*/
export const _macros: MacroMap = {};
// This function might one day accept an additional argument and do more things.
export default function defineMacro(name: string, body: MacroDefinition) {
_macros[name] = body;
}

835
node_modules/katex/src/delimiter.js generated vendored Normal file
View File

@@ -0,0 +1,835 @@
// @flow
/**
* This file deals with creating delimiters of various sizes. The TeXbook
* discusses these routines on page 441-442, in the "Another subroutine sets box
* x to a specified variable delimiter" paragraph.
*
* There are three main routines here. `makeSmallDelim` makes a delimiter in the
* normal font, but in either text, script, or scriptscript style.
* `makeLargeDelim` makes a delimiter in textstyle, but in one of the Size1,
* Size2, Size3, or Size4 fonts. `makeStackedDelim` makes a delimiter out of
* smaller pieces that are stacked on top of one another.
*
* The functions take a parameter `center`, which determines if the delimiter
* should be centered around the axis.
*
* Then, there are three exposed functions. `sizedDelim` makes a delimiter in
* one of the given sizes. This is used for things like `\bigl`.
* `customSizedDelim` makes a delimiter with a given total height+depth. It is
* called in places like `\sqrt`. `leftRightDelim` makes an appropriate
* delimiter which surrounds an expression of a given height an depth. It is
* used in `\left` and `\right`.
*/
import ParseError from "./ParseError";
import Style from "./Style";
import {PathNode, SvgNode, SymbolNode} from "./domTree";
import {sqrtPath, innerPath, tallDelim} from "./svgGeometry";
import buildCommon from "./buildCommon";
import {getCharacterMetrics} from "./fontMetrics";
import symbols from "./symbols";
import utils from "./utils";
import {makeEm} from "./units";
import fontMetricsData from "./fontMetricsData";
import type Options from "./Options";
import type {CharacterMetrics} from "./fontMetrics";
import type {HtmlDomNode, DomSpan, SvgSpan} from "./domTree";
import type {Mode} from "./types";
import type {StyleInterface} from "./Style";
import type {VListElem} from "./buildCommon";
/**
* Get the metrics for a given symbol and font, after transformation (i.e.
* after following replacement from symbols.js)
*/
const getMetrics = function(
symbol: string,
font: string,
mode: Mode,
): CharacterMetrics {
const replace = symbols.math[symbol] && symbols.math[symbol].replace;
const metrics =
getCharacterMetrics(replace || symbol, font, mode);
if (!metrics) {
throw new Error(`Unsupported symbol ${symbol} and font size ${font}.`);
}
return metrics;
};
/**
* Puts a delimiter span in a given style, and adds appropriate height, depth,
* and maxFontSizes.
*/
const styleWrap = function(
delim: HtmlDomNode,
toStyle: StyleInterface,
options: Options,
classes: string[],
): DomSpan {
const newOptions = options.havingBaseStyle(toStyle);
const span = buildCommon.makeSpan(
classes.concat(newOptions.sizingClasses(options)),
[delim], options);
const delimSizeMultiplier =
newOptions.sizeMultiplier / options.sizeMultiplier;
span.height *= delimSizeMultiplier;
span.depth *= delimSizeMultiplier;
span.maxFontSize = newOptions.sizeMultiplier;
return span;
};
const centerSpan = function(
span: DomSpan,
options: Options,
style: StyleInterface,
) {
const newOptions = options.havingBaseStyle(style);
const shift =
(1 - options.sizeMultiplier / newOptions.sizeMultiplier) *
options.fontMetrics().axisHeight;
span.classes.push("delimcenter");
span.style.top = makeEm(shift);
span.height -= shift;
span.depth += shift;
};
/**
* Makes a small delimiter. This is a delimiter that comes in the Main-Regular
* font, but is restyled to either be in textstyle, scriptstyle, or
* scriptscriptstyle.
*/
const makeSmallDelim = function(
delim: string,
style: StyleInterface,
center: boolean,
options: Options,
mode: Mode,
classes: string[],
): DomSpan {
const text = buildCommon.makeSymbol(delim, "Main-Regular", mode, options);
const span = styleWrap(text, style, options, classes);
if (center) {
centerSpan(span, options, style);
}
return span;
};
/**
* Builds a symbol in the given font size (note size is an integer)
*/
const mathrmSize = function(
value: string,
size: number,
mode: Mode,
options: Options,
): SymbolNode {
return buildCommon.makeSymbol(value, "Size" + size + "-Regular",
mode, options);
};
/**
* Makes a large delimiter. This is a delimiter that comes in the Size1, Size2,
* Size3, or Size4 fonts. It is always rendered in textstyle.
*/
const makeLargeDelim = function(delim,
size: number,
center: boolean,
options: Options,
mode: Mode,
classes: string[],
): DomSpan {
const inner = mathrmSize(delim, size, mode, options);
const span = styleWrap(
buildCommon.makeSpan(["delimsizing", "size" + size], [inner], options),
Style.TEXT, options, classes);
if (center) {
centerSpan(span, options, Style.TEXT);
}
return span;
};
/**
* Make a span from a font glyph with the given offset and in the given font.
* This is used in makeStackedDelim to make the stacking pieces for the delimiter.
*/
const makeGlyphSpan = function(
symbol: string,
font: "Size1-Regular" | "Size4-Regular",
mode: Mode,
): VListElem {
let sizeClass;
// Apply the correct CSS class to choose the right font.
if (font === "Size1-Regular") {
sizeClass = "delim-size1";
} else /* if (font === "Size4-Regular") */ {
sizeClass = "delim-size4";
}
const corner = buildCommon.makeSpan(
["delimsizinginner", sizeClass],
[buildCommon.makeSpan([], [buildCommon.makeSymbol(symbol, font, mode)])]);
// Since this will be passed into `makeVList` in the end, wrap the element
// in the appropriate tag that VList uses.
return {type: "elem", elem: corner};
};
const makeInner = function(
ch: string,
height: number,
options: Options
): VListElem {
// Create a span with inline SVG for the inner part of a tall stacked delimiter.
const width = fontMetricsData['Size4-Regular'][ch.charCodeAt(0)]
? fontMetricsData['Size4-Regular'][ch.charCodeAt(0)][4]
: fontMetricsData['Size1-Regular'][ch.charCodeAt(0)][4];
const path = new PathNode("inner", innerPath(ch, Math.round(1000 * height)));
const svgNode = new SvgNode([path], {
"width": makeEm(width),
"height": makeEm(height),
// Override CSS rule `.katex svg { width: 100% }`
"style": "width:" + makeEm(width),
"viewBox": "0 0 " + 1000 * width + " " + Math.round(1000 * height),
"preserveAspectRatio": "xMinYMin",
});
const span = buildCommon.makeSvgSpan([], [svgNode], options);
span.height = height;
span.style.height = makeEm(height);
span.style.width = makeEm(width);
return {type: "elem", elem: span};
};
// Helpers for makeStackedDelim
const lapInEms = 0.008;
const lap = {type: "kern", size: -1 * lapInEms};
const verts = ["|", "\\lvert", "\\rvert", "\\vert"];
const doubleVerts = ["\\|", "\\lVert", "\\rVert", "\\Vert"];
/**
* Make a stacked delimiter out of a given delimiter, with the total height at
* least `heightTotal`. This routine is mentioned on page 442 of the TeXbook.
*/
const makeStackedDelim = function(
delim: string,
heightTotal: number,
center: boolean,
options: Options,
mode: Mode,
classes: string[],
): DomSpan {
// There are four parts, the top, an optional middle, a repeated part, and a
// bottom.
let top;
let middle;
let repeat;
let bottom;
let svgLabel = "";
let viewBoxWidth = 0;
top = repeat = bottom = delim;
middle = null;
// Also keep track of what font the delimiters are in
let font = "Size1-Regular";
// We set the parts and font based on the symbol. Note that we use
// '\u23d0' instead of '|' and '\u2016' instead of '\\|' for the
// repeats of the arrows
if (delim === "\\uparrow") {
repeat = bottom = "\u23d0";
} else if (delim === "\\Uparrow") {
repeat = bottom = "\u2016";
} else if (delim === "\\downarrow") {
top = repeat = "\u23d0";
} else if (delim === "\\Downarrow") {
top = repeat = "\u2016";
} else if (delim === "\\updownarrow") {
top = "\\uparrow";
repeat = "\u23d0";
bottom = "\\downarrow";
} else if (delim === "\\Updownarrow") {
top = "\\Uparrow";
repeat = "\u2016";
bottom = "\\Downarrow";
} else if (utils.contains(verts, delim)) {
repeat = "\u2223";
svgLabel = "vert";
viewBoxWidth = 333;
} else if (utils.contains(doubleVerts, delim)) {
repeat = "\u2225";
svgLabel = "doublevert";
viewBoxWidth = 556;
} else if (delim === "[" || delim === "\\lbrack") {
top = "\u23a1";
repeat = "\u23a2";
bottom = "\u23a3";
font = "Size4-Regular";
svgLabel = "lbrack";
viewBoxWidth = 667;
} else if (delim === "]" || delim === "\\rbrack") {
top = "\u23a4";
repeat = "\u23a5";
bottom = "\u23a6";
font = "Size4-Regular";
svgLabel = "rbrack";
viewBoxWidth = 667;
} else if (delim === "\\lfloor" || delim === "\u230a") {
repeat = top = "\u23a2";
bottom = "\u23a3";
font = "Size4-Regular";
svgLabel = "lfloor";
viewBoxWidth = 667;
} else if (delim === "\\lceil" || delim === "\u2308") {
top = "\u23a1";
repeat = bottom = "\u23a2";
font = "Size4-Regular";
svgLabel = "lceil";
viewBoxWidth = 667;
} else if (delim === "\\rfloor" || delim === "\u230b") {
repeat = top = "\u23a5";
bottom = "\u23a6";
font = "Size4-Regular";
svgLabel = "rfloor";
viewBoxWidth = 667;
} else if (delim === "\\rceil" || delim === "\u2309") {
top = "\u23a4";
repeat = bottom = "\u23a5";
font = "Size4-Regular";
svgLabel = "rceil";
viewBoxWidth = 667;
} else if (delim === "(" || delim === "\\lparen") {
top = "\u239b";
repeat = "\u239c";
bottom = "\u239d";
font = "Size4-Regular";
svgLabel = "lparen";
viewBoxWidth = 875;
} else if (delim === ")" || delim === "\\rparen") {
top = "\u239e";
repeat = "\u239f";
bottom = "\u23a0";
font = "Size4-Regular";
svgLabel = "rparen";
viewBoxWidth = 875;
} else if (delim === "\\{" || delim === "\\lbrace") {
top = "\u23a7";
middle = "\u23a8";
bottom = "\u23a9";
repeat = "\u23aa";
font = "Size4-Regular";
} else if (delim === "\\}" || delim === "\\rbrace") {
top = "\u23ab";
middle = "\u23ac";
bottom = "\u23ad";
repeat = "\u23aa";
font = "Size4-Regular";
} else if (delim === "\\lgroup" || delim === "\u27ee") {
top = "\u23a7";
bottom = "\u23a9";
repeat = "\u23aa";
font = "Size4-Regular";
} else if (delim === "\\rgroup" || delim === "\u27ef") {
top = "\u23ab";
bottom = "\u23ad";
repeat = "\u23aa";
font = "Size4-Regular";
} else if (delim === "\\lmoustache" || delim === "\u23b0") {
top = "\u23a7";
bottom = "\u23ad";
repeat = "\u23aa";
font = "Size4-Regular";
} else if (delim === "\\rmoustache" || delim === "\u23b1") {
top = "\u23ab";
bottom = "\u23a9";
repeat = "\u23aa";
font = "Size4-Regular";
}
// Get the metrics of the four sections
const topMetrics = getMetrics(top, font, mode);
const topHeightTotal = topMetrics.height + topMetrics.depth;
const repeatMetrics = getMetrics(repeat, font, mode);
const repeatHeightTotal = repeatMetrics.height + repeatMetrics.depth;
const bottomMetrics = getMetrics(bottom, font, mode);
const bottomHeightTotal = bottomMetrics.height + bottomMetrics.depth;
let middleHeightTotal = 0;
let middleFactor = 1;
if (middle !== null) {
const middleMetrics = getMetrics(middle, font, mode);
middleHeightTotal = middleMetrics.height + middleMetrics.depth;
middleFactor = 2; // repeat symmetrically above and below middle
}
// Calculate the minimal height that the delimiter can have.
// It is at least the size of the top, bottom, and optional middle combined.
const minHeight = topHeightTotal + bottomHeightTotal + middleHeightTotal;
// Compute the number of copies of the repeat symbol we will need
const repeatCount = Math.max(0, Math.ceil(
(heightTotal - minHeight) / (middleFactor * repeatHeightTotal)));
// Compute the total height of the delimiter including all the symbols
const realHeightTotal =
minHeight + repeatCount * middleFactor * repeatHeightTotal;
// The center of the delimiter is placed at the center of the axis. Note
// that in this context, "center" means that the delimiter should be
// centered around the axis in the current style, while normally it is
// centered around the axis in textstyle.
let axisHeight = options.fontMetrics().axisHeight;
if (center) {
axisHeight *= options.sizeMultiplier;
}
// Calculate the depth
const depth = realHeightTotal / 2 - axisHeight;
// Now, we start building the pieces that will go into the vlist
// Keep a list of the pieces of the stacked delimiter
const stack = [];
if (svgLabel.length > 0) {
// Instead of stacking glyphs, create a single SVG.
// This evades browser problems with imprecise positioning of spans.
const midHeight = realHeightTotal - topHeightTotal - bottomHeightTotal;
const viewBoxHeight = Math.round(realHeightTotal * 1000);
const pathStr = tallDelim(svgLabel, Math.round(midHeight * 1000));
const path = new PathNode(svgLabel, pathStr);
const width = (viewBoxWidth / 1000).toFixed(3) + "em";
const height = (viewBoxHeight / 1000).toFixed(3) + "em";
const svg = new SvgNode([path], {
"width": width,
"height": height,
"viewBox": `0 0 ${viewBoxWidth} ${viewBoxHeight}`,
});
const wrapper = buildCommon.makeSvgSpan([], [svg], options);
wrapper.height = viewBoxHeight / 1000;
wrapper.style.width = width;
wrapper.style.height = height;
stack.push({type: "elem", elem: wrapper});
} else {
// Stack glyphs
// Start by adding the bottom symbol
stack.push(makeGlyphSpan(bottom, font, mode));
stack.push(lap); // overlap
if (middle === null) {
// The middle section will be an SVG. Make it an extra 0.016em tall.
// We'll overlap by 0.008em at top and bottom.
const innerHeight = realHeightTotal - topHeightTotal - bottomHeightTotal
+ 2 * lapInEms;
stack.push(makeInner(repeat, innerHeight, options));
} else {
// When there is a middle bit, we need the middle part and two repeated
// sections
const innerHeight = (realHeightTotal - topHeightTotal -
bottomHeightTotal - middleHeightTotal) / 2 + 2 * lapInEms;
stack.push(makeInner(repeat, innerHeight, options));
// Now insert the middle of the brace.
stack.push(lap);
stack.push(makeGlyphSpan(middle, font, mode));
stack.push(lap);
stack.push(makeInner(repeat, innerHeight, options));
}
// Add the top symbol
stack.push(lap);
stack.push(makeGlyphSpan(top, font, mode));
}
// Finally, build the vlist
const newOptions = options.havingBaseStyle(Style.TEXT);
const inner = buildCommon.makeVList({
positionType: "bottom",
positionData: depth,
children: stack,
}, newOptions);
return styleWrap(
buildCommon.makeSpan(["delimsizing", "mult"], [inner], newOptions),
Style.TEXT, options, classes);
};
// All surds have 0.08em padding above the vinculum inside the SVG.
// That keeps browser span height rounding error from pinching the line.
const vbPad = 80; // padding above the surd, measured inside the viewBox.
const emPad = 0.08; // padding, in ems, measured in the document.
const sqrtSvg = function(
sqrtName: string,
height: number,
viewBoxHeight: number,
extraVinculum: number,
options: Options,
): SvgSpan {
const path = sqrtPath(sqrtName, extraVinculum, viewBoxHeight);
const pathNode = new PathNode(sqrtName, path);
const svg = new SvgNode([pathNode], {
// Note: 1000:1 ratio of viewBox to document em width.
"width": "400em",
"height": makeEm(height),
"viewBox": "0 0 400000 " + viewBoxHeight,
"preserveAspectRatio": "xMinYMin slice",
});
return buildCommon.makeSvgSpan(["hide-tail"], [svg], options);
};
/**
* Make a sqrt image of the given height,
*/
const makeSqrtImage = function(
height: number,
options: Options,
): {
span: SvgSpan,
ruleWidth: number,
advanceWidth: number,
} {
// Define a newOptions that removes the effect of size changes such as \Huge.
// We don't pick different a height surd for \Huge. For it, we scale up.
const newOptions = options.havingBaseSizing();
// Pick the desired surd glyph from a sequence of surds.
const delim = traverseSequence("\\surd", height * newOptions.sizeMultiplier,
stackLargeDelimiterSequence, newOptions);
let sizeMultiplier = newOptions.sizeMultiplier; // default
// The standard sqrt SVGs each have a 0.04em thick vinculum.
// If Settings.minRuleThickness is larger than that, we add extraVinculum.
const extraVinculum = Math.max(0,
options.minRuleThickness - options.fontMetrics().sqrtRuleThickness);
// Create a span containing an SVG image of a sqrt symbol.
let span;
let spanHeight = 0;
let texHeight = 0;
let viewBoxHeight = 0;
let advanceWidth;
// We create viewBoxes with 80 units of "padding" above each surd.
// Then browser rounding error on the parent span height will not
// encroach on the ink of the vinculum. But that padding is not
// included in the TeX-like `height` used for calculation of
// vertical alignment. So texHeight = span.height < span.style.height.
if (delim.type === "small") {
// Get an SVG that is derived from glyph U+221A in font KaTeX-Main.
// 1000 unit normal glyph height.
viewBoxHeight = 1000 + 1000 * extraVinculum + vbPad;
if (height < 1.0) {
sizeMultiplier = 1.0; // mimic a \textfont radical
} else if (height < 1.4) {
sizeMultiplier = 0.7; // mimic a \scriptfont radical
}
spanHeight = (1.0 + extraVinculum + emPad) / sizeMultiplier;
texHeight = (1.00 + extraVinculum) / sizeMultiplier;
span = sqrtSvg("sqrtMain", spanHeight, viewBoxHeight, extraVinculum,
options);
span.style.minWidth = "0.853em";
advanceWidth = 0.833 / sizeMultiplier; // from the font.
} else if (delim.type === "large") {
// These SVGs come from fonts: KaTeX_Size1, _Size2, etc.
viewBoxHeight = (1000 + vbPad) * sizeToMaxHeight[delim.size];
texHeight = (sizeToMaxHeight[delim.size] + extraVinculum) / sizeMultiplier;
spanHeight = (sizeToMaxHeight[delim.size] + extraVinculum + emPad)
/ sizeMultiplier;
span = sqrtSvg("sqrtSize" + delim.size, spanHeight, viewBoxHeight,
extraVinculum, options);
span.style.minWidth = "1.02em";
advanceWidth = 1.0 / sizeMultiplier; // 1.0 from the font.
} else {
// Tall sqrt. In TeX, this would be stacked using multiple glyphs.
// We'll use a single SVG to accomplish the same thing.
spanHeight = height + extraVinculum + emPad;
texHeight = height + extraVinculum;
viewBoxHeight = Math.floor(1000 * height + extraVinculum) + vbPad;
span = sqrtSvg("sqrtTall", spanHeight, viewBoxHeight, extraVinculum,
options);
span.style.minWidth = "0.742em";
advanceWidth = 1.056;
}
span.height = texHeight;
span.style.height = makeEm(spanHeight);
return {
span,
advanceWidth,
// Calculate the actual line width.
// This actually should depend on the chosen font -- e.g. \boldmath
// should use the thicker surd symbols from e.g. KaTeX_Main-Bold, and
// have thicker rules.
ruleWidth: (options.fontMetrics().sqrtRuleThickness + extraVinculum)
* sizeMultiplier,
};
};
// There are three kinds of delimiters, delimiters that stack when they become
// too large
const stackLargeDelimiters = [
"(", "\\lparen", ")", "\\rparen",
"[", "\\lbrack", "]", "\\rbrack",
"\\{", "\\lbrace", "\\}", "\\rbrace",
"\\lfloor", "\\rfloor", "\u230a", "\u230b",
"\\lceil", "\\rceil", "\u2308", "\u2309",
"\\surd",
];
// delimiters that always stack
const stackAlwaysDelimiters = [
"\\uparrow", "\\downarrow", "\\updownarrow",
"\\Uparrow", "\\Downarrow", "\\Updownarrow",
"|", "\\|", "\\vert", "\\Vert",
"\\lvert", "\\rvert", "\\lVert", "\\rVert",
"\\lgroup", "\\rgroup", "\u27ee", "\u27ef",
"\\lmoustache", "\\rmoustache", "\u23b0", "\u23b1",
];
// and delimiters that never stack
const stackNeverDelimiters = [
"<", ">", "\\langle", "\\rangle", "/", "\\backslash", "\\lt", "\\gt",
];
// Metrics of the different sizes. Found by looking at TeX's output of
// $\bigl| // \Bigl| \biggl| \Biggl| \showlists$
// Used to create stacked delimiters of appropriate sizes in makeSizedDelim.
const sizeToMaxHeight = [0, 1.2, 1.8, 2.4, 3.0];
/**
* Used to create a delimiter of a specific size, where `size` is 1, 2, 3, or 4.
*/
const makeSizedDelim = function(
delim: string,
size: number,
options: Options,
mode: Mode,
classes: string[],
): DomSpan {
// < and > turn into \langle and \rangle in delimiters
if (delim === "<" || delim === "\\lt" || delim === "\u27e8") {
delim = "\\langle";
} else if (delim === ">" || delim === "\\gt" || delim === "\u27e9") {
delim = "\\rangle";
}
// Sized delimiters are never centered.
if (utils.contains(stackLargeDelimiters, delim) ||
utils.contains(stackNeverDelimiters, delim)) {
return makeLargeDelim(delim, size, false, options, mode, classes);
} else if (utils.contains(stackAlwaysDelimiters, delim)) {
return makeStackedDelim(
delim, sizeToMaxHeight[size], false, options, mode, classes);
} else {
throw new ParseError("Illegal delimiter: '" + delim + "'");
}
};
/**
* There are three different sequences of delimiter sizes that the delimiters
* follow depending on the kind of delimiter. This is used when creating custom
* sized delimiters to decide whether to create a small, large, or stacked
* delimiter.
*
* In real TeX, these sequences aren't explicitly defined, but are instead
* defined inside the font metrics. Since there are only three sequences that
* are possible for the delimiters that TeX defines, it is easier to just encode
* them explicitly here.
*/
type Delimiter =
{type: "small", style: StyleInterface} |
{type: "large", size: 1 | 2 | 3 | 4} |
{type: "stack"};
// Delimiters that never stack try small delimiters and large delimiters only
const stackNeverDelimiterSequence = [
{type: "small", style: Style.SCRIPTSCRIPT},
{type: "small", style: Style.SCRIPT},
{type: "small", style: Style.TEXT},
{type: "large", size: 1},
{type: "large", size: 2},
{type: "large", size: 3},
{type: "large", size: 4},
];
// Delimiters that always stack try the small delimiters first, then stack
const stackAlwaysDelimiterSequence = [
{type: "small", style: Style.SCRIPTSCRIPT},
{type: "small", style: Style.SCRIPT},
{type: "small", style: Style.TEXT},
{type: "stack"},
];
// Delimiters that stack when large try the small and then large delimiters, and
// stack afterwards
const stackLargeDelimiterSequence = [
{type: "small", style: Style.SCRIPTSCRIPT},
{type: "small", style: Style.SCRIPT},
{type: "small", style: Style.TEXT},
{type: "large", size: 1},
{type: "large", size: 2},
{type: "large", size: 3},
{type: "large", size: 4},
{type: "stack"},
];
/**
* Get the font used in a delimiter based on what kind of delimiter it is.
* TODO(#963) Use more specific font family return type once that is introduced.
*/
const delimTypeToFont = function(type: Delimiter): string {
if (type.type === "small") {
return "Main-Regular";
} else if (type.type === "large") {
return "Size" + type.size + "-Regular";
} else if (type.type === "stack") {
return "Size4-Regular";
} else {
throw new Error(`Add support for delim type '${type.type}' here.`);
}
};
/**
* Traverse a sequence of types of delimiters to decide what kind of delimiter
* should be used to create a delimiter of the given height+depth.
*/
const traverseSequence = function(
delim: string,
height: number,
sequence: Delimiter[],
options: Options,
): Delimiter {
// Here, we choose the index we should start at in the sequences. In smaller
// sizes (which correspond to larger numbers in style.size) we start earlier
// in the sequence. Thus, scriptscript starts at index 3-3=0, script starts
// at index 3-2=1, text starts at 3-1=2, and display starts at min(2,3-0)=2
const start = Math.min(2, 3 - options.style.size);
for (let i = start; i < sequence.length; i++) {
if (sequence[i].type === "stack") {
// This is always the last delimiter, so we just break the loop now.
break;
}
const metrics = getMetrics(delim, delimTypeToFont(sequence[i]), "math");
let heightDepth = metrics.height + metrics.depth;
// Small delimiters are scaled down versions of the same font, so we
// account for the style change size.
if (sequence[i].type === "small") {
const newOptions = options.havingBaseStyle(sequence[i].style);
heightDepth *= newOptions.sizeMultiplier;
}
// Check if the delimiter at this size works for the given height.
if (heightDepth > height) {
return sequence[i];
}
}
// If we reached the end of the sequence, return the last sequence element.
return sequence[sequence.length - 1];
};
/**
* Make a delimiter of a given height+depth, with optional centering. Here, we
* traverse the sequences, and create a delimiter that the sequence tells us to.
*/
const makeCustomSizedDelim = function(
delim: string,
height: number,
center: boolean,
options: Options,
mode: Mode,
classes: string[],
): DomSpan {
if (delim === "<" || delim === "\\lt" || delim === "\u27e8") {
delim = "\\langle";
} else if (delim === ">" || delim === "\\gt" || delim === "\u27e9") {
delim = "\\rangle";
}
// Decide what sequence to use
let sequence;
if (utils.contains(stackNeverDelimiters, delim)) {
sequence = stackNeverDelimiterSequence;
} else if (utils.contains(stackLargeDelimiters, delim)) {
sequence = stackLargeDelimiterSequence;
} else {
sequence = stackAlwaysDelimiterSequence;
}
// Look through the sequence
const delimType = traverseSequence(delim, height, sequence, options);
// Get the delimiter from font glyphs.
// Depending on the sequence element we decided on, call the
// appropriate function.
if (delimType.type === "small") {
return makeSmallDelim(delim, delimType.style, center, options,
mode, classes);
} else if (delimType.type === "large") {
return makeLargeDelim(delim, delimType.size, center, options, mode,
classes);
} else /* if (delimType.type === "stack") */ {
return makeStackedDelim(delim, height, center, options, mode,
classes);
}
};
/**
* Make a delimiter for use with `\left` and `\right`, given a height and depth
* of an expression that the delimiters surround.
*/
const makeLeftRightDelim = function(
delim: string,
height: number,
depth: number,
options: Options,
mode: Mode,
classes: string[],
): DomSpan {
// We always center \left/\right delimiters, so the axis is always shifted
const axisHeight =
options.fontMetrics().axisHeight * options.sizeMultiplier;
// Taken from TeX source, tex.web, function make_left_right
const delimiterFactor = 901;
const delimiterExtend = 5.0 / options.fontMetrics().ptPerEm;
const maxDistFromAxis = Math.max(
height - axisHeight, depth + axisHeight);
const totalHeight = Math.max(
// In real TeX, calculations are done using integral values which are
// 65536 per pt, or 655360 per em. So, the division here truncates in
// TeX but doesn't here, producing different results. If we wanted to
// exactly match TeX's calculation, we could do
// Math.floor(655360 * maxDistFromAxis / 500) *
// delimiterFactor / 655360
// (To see the difference, compare
// x^{x^{\left(\rule{0.1em}{0.68em}\right)}}
// in TeX and KaTeX)
maxDistFromAxis / 500 * delimiterFactor,
2 * maxDistFromAxis - delimiterExtend);
// Finally, we defer to `makeCustomSizedDelim` with our calculated total
// height
return makeCustomSizedDelim(delim, totalHeight, true, options, mode, classes);
};
export default {
sqrtImage: makeSqrtImage,
sizedDelim: makeSizedDelim,
sizeToMaxHeight: sizeToMaxHeight,
customSizedDelim: makeCustomSizedDelim,
leftRightDelim: makeLeftRightDelim,
};

632
node_modules/katex/src/domTree.js generated vendored Normal file
View File

@@ -0,0 +1,632 @@
// @flow
/**
* These objects store the data about the DOM nodes we create, as well as some
* extra data. They can then be transformed into real DOM nodes with the
* `toNode` function or HTML markup using `toMarkup`. They are useful for both
* storing extra properties on the nodes, as well as providing a way to easily
* work with the DOM.
*
* Similar functions for working with MathML nodes exist in mathMLTree.js.
*
* TODO: refactor `span` and `anchor` into common superclass when
* target environments support class inheritance
*/
import {scriptFromCodepoint} from "./unicodeScripts";
import utils from "./utils";
import {path} from "./svgGeometry";
import type Options from "./Options";
import {DocumentFragment} from "./tree";
import {makeEm} from "./units";
import ParseError from "./ParseError";
import type {VirtualNode} from "./tree";
/**
* Create an HTML className based on a list of classes. In addition to joining
* with spaces, we also remove empty classes.
*/
export const createClass = function(classes: string[]): string {
return classes.filter(cls => cls).join(" ");
};
const initNode = function(
classes?: string[],
options?: Options,
style?: CssStyle,
) {
this.classes = classes || [];
this.attributes = {};
this.height = 0;
this.depth = 0;
this.maxFontSize = 0;
this.style = style || {};
if (options) {
if (options.style.isTight()) {
this.classes.push("mtight");
}
const color = options.getColor();
if (color) {
this.style.color = color;
}
}
};
/**
* Convert into an HTML node
*/
const toNode = function(tagName: string): HTMLElement {
const node = document.createElement(tagName);
// Apply the class
node.className = createClass(this.classes);
// Apply inline styles
for (const style in this.style) {
if (this.style.hasOwnProperty(style)) {
// $FlowFixMe Flow doesn't seem to understand span.style's type.
node.style[style] = this.style[style];
}
}
// Apply attributes
for (const attr in this.attributes) {
if (this.attributes.hasOwnProperty(attr)) {
node.setAttribute(attr, this.attributes[attr]);
}
}
// Append the children, also as HTML nodes
for (let i = 0; i < this.children.length; i++) {
node.appendChild(this.children[i].toNode());
}
return node;
};
/**
* https://w3c.github.io/html-reference/syntax.html#syntax-attributes
*
* > Attribute Names must consist of one or more characters
* other than the space characters, U+0000 NULL,
* '"', "'", ">", "/", "=", the control characters,
* and any characters that are not defined by Unicode.
*/
const invalidAttributeNameRegex = /[\s"'>/=\x00-\x1f]/;
/**
* Convert into an HTML markup string
*/
const toMarkup = function(tagName: string): string {
let markup = `<${tagName}`;
// Add the class
if (this.classes.length) {
markup += ` class="${utils.escape(createClass(this.classes))}"`;
}
let styles = "";
// Add the styles, after hyphenation
for (const style in this.style) {
if (this.style.hasOwnProperty(style)) {
styles += `${utils.hyphenate(style)}:${this.style[style]};`;
}
}
if (styles) {
markup += ` style="${utils.escape(styles)}"`;
}
// Add the attributes
for (const attr in this.attributes) {
if (this.attributes.hasOwnProperty(attr)) {
if (invalidAttributeNameRegex.test(attr)) {
throw new ParseError(`Invalid attribute name '${attr}'`);
}
markup += ` ${attr}="${utils.escape(this.attributes[attr])}"`;
}
}
markup += ">";
// Add the markup of the children, also as markup
for (let i = 0; i < this.children.length; i++) {
markup += this.children[i].toMarkup();
}
markup += `</${tagName}>`;
return markup;
};
// Making the type below exact with all optional fields doesn't work due to
// - https://github.com/facebook/flow/issues/4582
// - https://github.com/facebook/flow/issues/5688
// However, since *all* fields are optional, $Shape<> works as suggested in 5688
// above.
// This type does not include all CSS properties. Additional properties should
// be added as needed.
export type CssStyle = $Shape<{
backgroundColor: string,
borderBottomWidth: string,
borderColor: string,
borderRightStyle: string,
borderRightWidth: string,
borderTopWidth: string,
borderStyle: string;
borderWidth: string,
bottom: string,
color: string,
height: string,
left: string,
margin: string,
marginLeft: string,
marginRight: string,
marginTop: string,
minWidth: string,
paddingLeft: string,
position: string,
textShadow: string,
top: string,
width: string,
verticalAlign: string,
}> & {};
export interface HtmlDomNode extends VirtualNode {
classes: string[];
height: number;
depth: number;
maxFontSize: number;
style: CssStyle;
hasClass(className: string): boolean;
}
// Span wrapping other DOM nodes.
export type DomSpan = Span<HtmlDomNode>;
// Span wrapping an SVG node.
export type SvgSpan = Span<SvgNode>;
export type SvgChildNode = PathNode | LineNode;
export type documentFragment = DocumentFragment<HtmlDomNode>;
/**
* This node represents a span node, with a className, a list of children, and
* an inline style. It also contains information about its height, depth, and
* maxFontSize.
*
* Represents two types with different uses: SvgSpan to wrap an SVG and DomSpan
* otherwise. This typesafety is important when HTML builders access a span's
* children.
*/
export class Span<ChildType: VirtualNode> implements HtmlDomNode {
children: ChildType[];
attributes: {[string]: string};
classes: string[];
height: number;
depth: number;
width: ?number;
maxFontSize: number;
style: CssStyle;
constructor(
classes?: string[],
children?: ChildType[],
options?: Options,
style?: CssStyle,
) {
initNode.call(this, classes, options, style);
this.children = children || [];
}
/**
* Sets an arbitrary attribute on the span. Warning: use this wisely. Not
* all browsers support attributes the same, and having too many custom
* attributes is probably bad.
*/
setAttribute(attribute: string, value: string) {
this.attributes[attribute] = value;
}
hasClass(className: string): boolean {
return utils.contains(this.classes, className);
}
toNode(): HTMLElement {
return toNode.call(this, "span");
}
toMarkup(): string {
return toMarkup.call(this, "span");
}
}
/**
* This node represents an anchor (<a>) element with a hyperlink. See `span`
* for further details.
*/
export class Anchor implements HtmlDomNode {
children: HtmlDomNode[];
attributes: {[string]: string};
classes: string[];
height: number;
depth: number;
maxFontSize: number;
style: CssStyle;
constructor(
href: string,
classes: string[],
children: HtmlDomNode[],
options: Options,
) {
initNode.call(this, classes, options);
this.children = children || [];
this.setAttribute('href', href);
}
setAttribute(attribute: string, value: string) {
this.attributes[attribute] = value;
}
hasClass(className: string): boolean {
return utils.contains(this.classes, className);
}
toNode(): HTMLElement {
return toNode.call(this, "a");
}
toMarkup(): string {
return toMarkup.call(this, "a");
}
}
/**
* This node represents an image embed (<img>) element.
*/
export class Img implements VirtualNode {
src: string;
alt: string;
classes: string[];
height: number;
depth: number;
maxFontSize: number;
style: CssStyle;
constructor(
src: string,
alt: string,
style: CssStyle,
) {
this.alt = alt;
this.src = src;
this.classes = ["mord"];
this.style = style;
}
hasClass(className: string): boolean {
return utils.contains(this.classes, className);
}
toNode(): Node {
const node = document.createElement("img");
node.src = this.src;
node.alt = this.alt;
node.className = "mord";
// Apply inline styles
for (const style in this.style) {
if (this.style.hasOwnProperty(style)) {
// $FlowFixMe
node.style[style] = this.style[style];
}
}
return node;
}
toMarkup(): string {
let markup = `<img src="${utils.escape(this.src)}"` +
` alt="${utils.escape(this.alt)}"`;
// Add the styles, after hyphenation
let styles = "";
for (const style in this.style) {
if (this.style.hasOwnProperty(style)) {
styles += `${utils.hyphenate(style)}:${this.style[style]};`;
}
}
if (styles) {
markup += ` style="${utils.escape(styles)}"`;
}
markup += "'/>";
return markup;
}
}
const iCombinations = {
'î': '\u0131\u0302',
'ï': '\u0131\u0308',
'í': '\u0131\u0301',
// 'ī': '\u0131\u0304', // enable when we add Extended Latin
'ì': '\u0131\u0300',
};
/**
* A symbol node contains information about a single symbol. It either renders
* to a single text node, or a span with a single text node in it, depending on
* whether it has CSS classes, styles, or needs italic correction.
*/
export class SymbolNode implements HtmlDomNode {
text: string;
height: number;
depth: number;
italic: number;
skew: number;
width: number;
maxFontSize: number;
classes: string[];
style: CssStyle;
constructor(
text: string,
height?: number,
depth?: number,
italic?: number,
skew?: number,
width?: number,
classes?: string[],
style?: CssStyle,
) {
this.text = text;
this.height = height || 0;
this.depth = depth || 0;
this.italic = italic || 0;
this.skew = skew || 0;
this.width = width || 0;
this.classes = classes || [];
this.style = style || {};
this.maxFontSize = 0;
// Mark text from non-Latin scripts with specific classes so that we
// can specify which fonts to use. This allows us to render these
// characters with a serif font in situations where the browser would
// either default to a sans serif or render a placeholder character.
// We use CSS class names like cjk_fallback, hangul_fallback and
// brahmic_fallback. See ./unicodeScripts.js for the set of possible
// script names
const script = scriptFromCodepoint(this.text.charCodeAt(0));
if (script) {
this.classes.push(script + "_fallback");
}
if (/[îïíì]/.test(this.text)) { // add ī when we add Extended Latin
this.text = iCombinations[this.text];
}
}
hasClass(className: string): boolean {
return utils.contains(this.classes, className);
}
/**
* Creates a text node or span from a symbol node. Note that a span is only
* created if it is needed.
*/
toNode(): Node {
const node = document.createTextNode(this.text);
let span = null;
if (this.italic > 0) {
span = document.createElement("span");
span.style.marginRight = makeEm(this.italic);
}
if (this.classes.length > 0) {
span = span || document.createElement("span");
span.className = createClass(this.classes);
}
for (const style in this.style) {
if (this.style.hasOwnProperty(style)) {
span = span || document.createElement("span");
// $FlowFixMe Flow doesn't seem to understand span.style's type.
span.style[style] = this.style[style];
}
}
if (span) {
span.appendChild(node);
return span;
} else {
return node;
}
}
/**
* Creates markup for a symbol node.
*/
toMarkup(): string {
// TODO(alpert): More duplication than I'd like from
// span.prototype.toMarkup and symbolNode.prototype.toNode...
let needsSpan = false;
let markup = "<span";
if (this.classes.length) {
needsSpan = true;
markup += " class=\"";
markup += utils.escape(createClass(this.classes));
markup += "\"";
}
let styles = "";
if (this.italic > 0) {
styles += "margin-right:" + this.italic + "em;";
}
for (const style in this.style) {
if (this.style.hasOwnProperty(style)) {
styles += utils.hyphenate(style) + ":" + this.style[style] + ";";
}
}
if (styles) {
needsSpan = true;
markup += " style=\"" + utils.escape(styles) + "\"";
}
const escaped = utils.escape(this.text);
if (needsSpan) {
markup += ">";
markup += escaped;
markup += "</span>";
return markup;
} else {
return escaped;
}
}
}
/**
* SVG nodes are used to render stretchy wide elements.
*/
export class SvgNode implements VirtualNode {
children: SvgChildNode[];
attributes: {[string]: string};
constructor(children?: SvgChildNode[], attributes?: {[string]: string}) {
this.children = children || [];
this.attributes = attributes || {};
}
toNode(): Node {
const svgNS = "http://www.w3.org/2000/svg";
const node = document.createElementNS(svgNS, "svg");
// Apply attributes
for (const attr in this.attributes) {
if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
node.setAttribute(attr, this.attributes[attr]);
}
}
for (let i = 0; i < this.children.length; i++) {
node.appendChild(this.children[i].toNode());
}
return node;
}
toMarkup(): string {
let markup = `<svg xmlns="http://www.w3.org/2000/svg"`;
// Apply attributes
for (const attr in this.attributes) {
if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
markup += ` ${attr}="${utils.escape(this.attributes[attr])}"`;
}
}
markup += ">";
for (let i = 0; i < this.children.length; i++) {
markup += this.children[i].toMarkup();
}
markup += "</svg>";
return markup;
}
}
export class PathNode implements VirtualNode {
pathName: string;
alternate: ?string;
constructor(pathName: string, alternate?: string) {
this.pathName = pathName;
this.alternate = alternate; // Used only for \sqrt, \phase, & tall delims
}
toNode(): Node {
const svgNS = "http://www.w3.org/2000/svg";
const node = document.createElementNS(svgNS, "path");
if (this.alternate) {
node.setAttribute("d", this.alternate);
} else {
node.setAttribute("d", path[this.pathName]);
}
return node;
}
toMarkup(): string {
if (this.alternate) {
return `<path d="${utils.escape(this.alternate)}"/>`;
} else {
return `<path d="${utils.escape(path[this.pathName])}"/>`;
}
}
}
export class LineNode implements VirtualNode {
attributes: {[string]: string};
constructor(attributes?: {[string]: string}) {
this.attributes = attributes || {};
}
toNode(): Node {
const svgNS = "http://www.w3.org/2000/svg";
const node = document.createElementNS(svgNS, "line");
// Apply attributes
for (const attr in this.attributes) {
if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
node.setAttribute(attr, this.attributes[attr]);
}
}
return node;
}
toMarkup(): string {
let markup = "<line";
for (const attr in this.attributes) {
if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
markup += ` ${attr}="${utils.escape(this.attributes[attr])}"`;
}
}
markup += "/>";
return markup;
}
}
export function assertSymbolDomNode(
group: HtmlDomNode,
): SymbolNode {
if (group instanceof SymbolNode) {
return group;
} else {
throw new Error(`Expected symbolNode but got ${String(group)}.`);
}
}
export function assertSpan(
group: HtmlDomNode,
): Span<HtmlDomNode> {
if (group instanceof Span) {
return group;
} else {
throw new Error(`Expected span<HtmlDomNode> but got ${String(group)}.`);
}
}

9
node_modules/katex/src/environments.js generated vendored Normal file
View File

@@ -0,0 +1,9 @@
// @flow
import {_environments} from "./defineEnvironment";
const environments = _environments;
export default environments;
// All environment definitions should be imported below
import "./environments/array";

1118
node_modules/katex/src/environments/array.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

313
node_modules/katex/src/environments/cd.js generated vendored Normal file
View File

@@ -0,0 +1,313 @@
// @flow
import buildCommon from "../buildCommon";
import defineFunction from "../defineFunction";
import mathMLTree from "../mathMLTree";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import {assertSymbolNodeType} from "../parseNode";
import ParseError from "../ParseError";
import {makeEm} from "../units";
import type Parser from "../Parser";
import type {ParseNode, AnyParseNode} from "../parseNode";
const cdArrowFunctionName = {
">": "\\\\cdrightarrow",
"<": "\\\\cdleftarrow",
"=": "\\\\cdlongequal",
"A": "\\uparrow",
"V": "\\downarrow",
"|": "\\Vert",
".": "no arrow",
};
const newCell = () => {
// Create an empty cell, to be filled below with parse nodes.
// The parseTree from this module must be constructed like the
// one created by parseArray(), so an empty CD cell must
// be a ParseNode<"styling">. And CD is always displaystyle.
// So these values are fixed and flow can do implicit typing.
return {type: "styling", body: [], mode: "math", style: "display"};
};
const isStartOfArrow = (node: AnyParseNode) => {
return (node.type === "textord" && node.text === "@");
};
const isLabelEnd = (node: AnyParseNode, endChar: string): boolean => {
return ((node.type === "mathord" || node.type === "atom") &&
node.text === endChar);
};
function cdArrow(
arrowChar: string,
labels: ParseNode<"ordgroup">[],
parser: Parser
): AnyParseNode {
// Return a parse tree of an arrow and its labels.
// This acts in a way similar to a macro expansion.
const funcName = cdArrowFunctionName[arrowChar];
switch (funcName) {
case "\\\\cdrightarrow":
case "\\\\cdleftarrow":
return parser.callFunction(
funcName, [labels[0]], [labels[1]]
);
case "\\uparrow":
case "\\downarrow": {
const leftLabel = parser.callFunction(
"\\\\cdleft", [labels[0]], []
);
const bareArrow = {
type: "atom",
text: funcName,
mode: "math",
family: "rel",
};
const sizedArrow = parser.callFunction("\\Big", [bareArrow], []);
const rightLabel = parser.callFunction(
"\\\\cdright", [labels[1]], []
);
const arrowGroup = {
type: "ordgroup",
mode: "math",
body: [leftLabel, sizedArrow, rightLabel],
};
return parser.callFunction("\\\\cdparent", [arrowGroup], []);
}
case "\\\\cdlongequal":
return parser.callFunction("\\\\cdlongequal", [], []);
case "\\Vert": {
const arrow = {type: "textord", text: "\\Vert", mode: "math"};
return parser.callFunction("\\Big", [arrow], []);
}
default:
return {type: "textord", text: " ", mode: "math"};
}
}
export function parseCD(parser: Parser): ParseNode<"array"> {
// Get the array's parse nodes with \\ temporarily mapped to \cr.
const parsedRows: AnyParseNode[][] = [];
parser.gullet.beginGroup();
parser.gullet.macros.set("\\cr", "\\\\\\relax");
parser.gullet.beginGroup();
while (true) { // eslint-disable-line no-constant-condition
// Get the parse nodes for the next row.
parsedRows.push(parser.parseExpression(false, "\\\\"));
parser.gullet.endGroup();
parser.gullet.beginGroup();
const next = parser.fetch().text;
if (next === "&" || next === "\\\\") {
parser.consume();
} else if (next === "\\end") {
if (parsedRows[parsedRows.length - 1].length === 0) {
parsedRows.pop(); // final row ended in \\
}
break;
} else {
throw new ParseError("Expected \\\\ or \\cr or \\end",
parser.nextToken);
}
}
let row = [];
const body = [row];
// Loop thru the parse nodes. Collect them into cells and arrows.
for (let i = 0; i < parsedRows.length; i++) {
// Start a new row.
const rowNodes = parsedRows[i];
// Create the first cell.
let cell = newCell();
for (let j = 0; j < rowNodes.length; j++) {
if (!isStartOfArrow(rowNodes[j])) {
// If a parseNode is not an arrow, it goes into a cell.
cell.body.push(rowNodes[j]);
} else {
// Parse node j is an "@", the start of an arrow.
// Before starting on the arrow, push the cell into `row`.
row.push(cell);
// Now collect parseNodes into an arrow.
// The character after "@" defines the arrow type.
j += 1;
const arrowChar = assertSymbolNodeType(rowNodes[j]).text;
// Create two empty label nodes. We may or may not use them.
const labels: ParseNode<"ordgroup">[] = new Array(2);
labels[0] = {type: "ordgroup", mode: "math", body: []};
labels[1] = {type: "ordgroup", mode: "math", body: []};
// Process the arrow.
if ("=|.".indexOf(arrowChar) > -1) {
// Three "arrows", ``@=`, `@|`, and `@.`, do not take labels.
// Do nothing here.
} else if ("<>AV".indexOf(arrowChar) > -1) {
// Four arrows, `@>>>`, `@<<<`, `@AAA`, and `@VVV`, each take
// two optional labels. E.g. the right-point arrow syntax is
// really: @>{optional label}>{optional label}>
// Collect parseNodes into labels.
for (let labelNum = 0; labelNum < 2; labelNum++) {
let inLabel = true;
for (let k = j + 1; k < rowNodes.length; k++) {
if (isLabelEnd(rowNodes[k], arrowChar)) {
inLabel = false;
j = k;
break;
}
if (isStartOfArrow(rowNodes[k])) {
throw new ParseError("Missing a " + arrowChar +
" character to complete a CD arrow.", rowNodes[k]);
}
labels[labelNum].body.push(rowNodes[k]);
}
if (inLabel) {
// isLabelEnd never returned a true.
throw new ParseError("Missing a " + arrowChar +
" character to complete a CD arrow.", rowNodes[j]);
}
}
} else {
throw new ParseError(`Expected one of "<>AV=|." after @`,
rowNodes[j]);
}
// Now join the arrow to its labels.
const arrow: AnyParseNode = cdArrow(arrowChar, labels, parser);
// Wrap the arrow in ParseNode<"styling">.
// This is done to match parseArray() behavior.
const wrappedArrow = {
type: "styling",
body: [arrow],
mode: "math",
style: "display", // CD is always displaystyle.
};
row.push(wrappedArrow);
// In CD's syntax, cells are implicit. That is, everything that
// is not an arrow gets collected into a cell. So create an empty
// cell now. It will collect upcoming parseNodes.
cell = newCell();
}
}
if (i % 2 === 0) {
// Even-numbered rows consist of: cell, arrow, cell, arrow, ... cell
// The last cell is not yet pushed into `row`, so:
row.push(cell);
} else {
// Odd-numbered rows consist of: vert arrow, empty cell, ... vert arrow
// Remove the empty cell that was placed at the beginning of `row`.
row.shift();
}
row = [];
body.push(row);
}
// End row group
parser.gullet.endGroup();
// End array group defining \\
parser.gullet.endGroup();
// define column separation.
const cols = new Array(body[0].length).fill({
type: "align",
align: "c",
pregap: 0.25, // CD package sets \enskip between columns.
postgap: 0.25, // So pre and post each get half an \enskip, i.e. 0.25em.
});
return {
type: "array",
mode: "math",
body,
arraystretch: 1,
addJot: true,
rowGaps: [null],
cols,
colSeparationType: "CD",
hLinesBeforeRow: new Array(body.length + 1).fill([]),
};
}
// The functions below are not available for general use.
// They are here only for internal use by the {CD} environment in placing labels
// next to vertical arrows.
// We don't need any such functions for horizontal arrows because we can reuse
// the functionality that already exists for extensible arrows.
defineFunction({
type: "cdlabel",
names: ["\\\\cdleft", "\\\\cdright"],
props: {
numArgs: 1,
},
handler({parser, funcName}, args) {
return {
type: "cdlabel",
mode: parser.mode,
side: funcName.slice(4),
label: args[0],
};
},
htmlBuilder(group, options) {
const newOptions = options.havingStyle(options.style.sup());
const label = buildCommon.wrapFragment(
html.buildGroup(group.label, newOptions, options), options);
label.classes.push("cd-label-" + group.side);
label.style.bottom = makeEm(0.8 - label.depth);
// Zero out label height & depth, so vertical align of arrow is set
// by the arrow height, not by the label.
label.height = 0;
label.depth = 0;
return label;
},
mathmlBuilder(group, options) {
let label = new mathMLTree.MathNode("mrow",
[mml.buildGroup(group.label, options)]);
label = new mathMLTree.MathNode("mpadded", [label]);
label.setAttribute("width", "0");
if (group.side === "left") {
label.setAttribute("lspace", "-1width");
}
// We have to guess at vertical alignment. We know the arrow is 1.8em tall,
// But we don't know the height or depth of the label.
label.setAttribute("voffset", "0.7em");
label = new mathMLTree.MathNode("mstyle", [label]);
label.setAttribute("displaystyle", "false");
label.setAttribute("scriptlevel", "1");
return label;
},
});
defineFunction({
type: "cdlabelparent",
names: ["\\\\cdparent"],
props: {
numArgs: 1,
},
handler({parser}, args) {
return {
type: "cdlabelparent",
mode: parser.mode,
fragment: args[0],
};
},
htmlBuilder(group, options) {
// Wrap the vertical arrow and its labels.
// The parent gets position: relative. The child gets position: absolute.
// So CSS can locate the label correctly.
const parent = buildCommon.wrapFragment(
html.buildGroup(group.fragment, options), options
);
parent.classes.push("cd-vert-arrow");
return parent;
},
mathmlBuilder(group, options) {
return new mathMLTree.MathNode("mrow",
[mml.buildGroup(group.fragment, options)]);
},
});

282
node_modules/katex/src/fontMetrics.js generated vendored Normal file
View File

@@ -0,0 +1,282 @@
// @flow
import {supportedCodepoint} from "./unicodeScripts";
import type {Mode} from "./types";
/**
* This file contains metrics regarding fonts and individual symbols. The sigma
* and xi variables, as well as the metricMap map contain data extracted from
* TeX, TeX font metrics, and the TTF files. These data are then exposed via the
* `metrics` variable and the getCharacterMetrics function.
*/
// In TeX, there are actually three sets of dimensions, one for each of
// textstyle (size index 5 and higher: >=9pt), scriptstyle (size index 3 and 4:
// 7-8pt), and scriptscriptstyle (size index 1 and 2: 5-6pt). These are
// provided in the arrays below, in that order.
//
// The font metrics are stored in fonts cmsy10, cmsy7, and cmsy5 respectively.
// This was determined by running the following script:
//
// latex -interaction=nonstopmode \
// '\documentclass{article}\usepackage{amsmath}\begin{document}' \
// '$a$ \expandafter\show\the\textfont2' \
// '\expandafter\show\the\scriptfont2' \
// '\expandafter\show\the\scriptscriptfont2' \
// '\stop'
//
// The metrics themselves were retrieved using the following commands:
//
// tftopl cmsy10
// tftopl cmsy7
// tftopl cmsy5
//
// The output of each of these commands is quite lengthy. The only part we
// care about is the FONTDIMEN section. Each value is measured in EMs.
const sigmasAndXis = {
slant: [0.250, 0.250, 0.250], // sigma1
space: [0.000, 0.000, 0.000], // sigma2
stretch: [0.000, 0.000, 0.000], // sigma3
shrink: [0.000, 0.000, 0.000], // sigma4
xHeight: [0.431, 0.431, 0.431], // sigma5
quad: [1.000, 1.171, 1.472], // sigma6
extraSpace: [0.000, 0.000, 0.000], // sigma7
num1: [0.677, 0.732, 0.925], // sigma8
num2: [0.394, 0.384, 0.387], // sigma9
num3: [0.444, 0.471, 0.504], // sigma10
denom1: [0.686, 0.752, 1.025], // sigma11
denom2: [0.345, 0.344, 0.532], // sigma12
sup1: [0.413, 0.503, 0.504], // sigma13
sup2: [0.363, 0.431, 0.404], // sigma14
sup3: [0.289, 0.286, 0.294], // sigma15
sub1: [0.150, 0.143, 0.200], // sigma16
sub2: [0.247, 0.286, 0.400], // sigma17
supDrop: [0.386, 0.353, 0.494], // sigma18
subDrop: [0.050, 0.071, 0.100], // sigma19
delim1: [2.390, 1.700, 1.980], // sigma20
delim2: [1.010, 1.157, 1.420], // sigma21
axisHeight: [0.250, 0.250, 0.250], // sigma22
// These font metrics are extracted from TeX by using tftopl on cmex10.tfm;
// they correspond to the font parameters of the extension fonts (family 3).
// See the TeXbook, page 441. In AMSTeX, the extension fonts scale; to
// match cmex7, we'd use cmex7.tfm values for script and scriptscript
// values.
defaultRuleThickness: [0.04, 0.049, 0.049], // xi8; cmex7: 0.049
bigOpSpacing1: [0.111, 0.111, 0.111], // xi9
bigOpSpacing2: [0.166, 0.166, 0.166], // xi10
bigOpSpacing3: [0.2, 0.2, 0.2], // xi11
bigOpSpacing4: [0.6, 0.611, 0.611], // xi12; cmex7: 0.611
bigOpSpacing5: [0.1, 0.143, 0.143], // xi13; cmex7: 0.143
// The \sqrt rule width is taken from the height of the surd character.
// Since we use the same font at all sizes, this thickness doesn't scale.
sqrtRuleThickness: [0.04, 0.04, 0.04],
// This value determines how large a pt is, for metrics which are defined
// in terms of pts.
// This value is also used in katex.scss; if you change it make sure the
// values match.
ptPerEm: [10.0, 10.0, 10.0],
// The space between adjacent `|` columns in an array definition. From
// `\showthe\doublerulesep` in LaTeX. Equals 2.0 / ptPerEm.
doubleRuleSep: [0.2, 0.2, 0.2],
// The width of separator lines in {array} environments. From
// `\showthe\arrayrulewidth` in LaTeX. Equals 0.4 / ptPerEm.
arrayRuleWidth: [0.04, 0.04, 0.04],
// Two values from LaTeX source2e:
fboxsep: [0.3, 0.3, 0.3], // 3 pt / ptPerEm
fboxrule: [0.04, 0.04, 0.04], // 0.4 pt / ptPerEm
};
// This map contains a mapping from font name and character code to character
// metrics, including height, depth, italic correction, and skew (kern from the
// character to the corresponding \skewchar)
// This map is generated via `make metrics`. It should not be changed manually.
import metricMap from "./fontMetricsData";
// These are very rough approximations. We default to Times New Roman which
// should have Latin-1 and Cyrillic characters, but may not depending on the
// operating system. The metrics do not account for extra height from the
// accents. In the case of Cyrillic characters which have both ascenders and
// descenders we prefer approximations with ascenders, primarily to prevent
// the fraction bar or root line from intersecting the glyph.
// TODO(kevinb) allow union of multiple glyph metrics for better accuracy.
const extraCharacterMap = {
// Latin-1
'Å': 'A',
'Ð': 'D',
'Þ': 'o',
'å': 'a',
'ð': 'd',
'þ': 'o',
// Cyrillic
'А': 'A',
'Б': 'B',
'В': 'B',
'Г': 'F',
'Д': 'A',
'Е': 'E',
'Ж': 'K',
'З': '3',
'И': 'N',
'Й': 'N',
'К': 'K',
'Л': 'N',
'М': 'M',
'Н': 'H',
'О': 'O',
'П': 'N',
'Р': 'P',
'С': 'C',
'Т': 'T',
'У': 'y',
'Ф': 'O',
'Х': 'X',
'Ц': 'U',
'Ч': 'h',
'Ш': 'W',
'Щ': 'W',
'Ъ': 'B',
'Ы': 'X',
'Ь': 'B',
'Э': '3',
'Ю': 'X',
'Я': 'R',
'а': 'a',
'б': 'b',
'в': 'a',
'г': 'r',
'д': 'y',
'е': 'e',
'ж': 'm',
'з': 'e',
'и': 'n',
'й': 'n',
'к': 'n',
'л': 'n',
'м': 'm',
'н': 'n',
'о': 'o',
'п': 'n',
'р': 'p',
'с': 'c',
'т': 'o',
'у': 'y',
'ф': 'b',
'х': 'x',
'ц': 'n',
'ч': 'n',
'ш': 'w',
'щ': 'w',
'ъ': 'a',
'ы': 'm',
'ь': 'a',
'э': 'e',
'ю': 'm',
'я': 'r',
};
export type CharacterMetrics = {
depth: number;
height: number;
italic: number;
skew: number;
width: number;
};
export type MetricMap = {
[string]: number[]
}
/**
* This function adds new font metrics to default metricMap
* It can also override existing metrics
*/
export function setFontMetrics(fontName: string, metrics: MetricMap) {
metricMap[fontName] = metrics;
}
/**
* This function is a convenience function for looking up information in the
* metricMap table. It takes a character as a string, and a font.
*
* Note: the `width` property may be undefined if fontMetricsData.js wasn't
* built using `Make extended_metrics`.
*/
export function getCharacterMetrics(
character: string,
font: string,
mode: Mode,
): ?CharacterMetrics {
if (!metricMap[font]) {
throw new Error(`Font metrics not found for font: ${font}.`);
}
let ch = character.charCodeAt(0);
let metrics = metricMap[font][ch];
if (!metrics && character[0] in extraCharacterMap) {
ch = extraCharacterMap[character[0]].charCodeAt(0);
metrics = metricMap[font][ch];
}
if (!metrics && mode === 'text') {
// We don't typically have font metrics for Asian scripts.
// But since we support them in text mode, we need to return
// some sort of metrics.
// So if the character is in a script we support but we
// don't have metrics for it, just use the metrics for
// the Latin capital letter M. This is close enough because
// we (currently) only care about the height of the glyph
// not its width.
if (supportedCodepoint(ch)) {
metrics = metricMap[font][77]; // 77 is the charcode for 'M'
}
}
if (metrics) {
return {
depth: metrics[0],
height: metrics[1],
italic: metrics[2],
skew: metrics[3],
width: metrics[4],
};
}
}
type FontSizeIndex = 0 | 1 | 2;
export type FontMetrics = {
cssEmPerMu: number,
[string]: number,
};
const fontMetricsBySizeIndex: {[FontSizeIndex]: FontMetrics} = {};
/**
* Get the font metrics for a given size.
*/
export function getGlobalMetrics(size: number): FontMetrics {
let sizeIndex: FontSizeIndex;
if (size >= 5) {
sizeIndex = 0;
} else if (size >= 3) {
sizeIndex = 1;
} else {
sizeIndex = 2;
}
if (!fontMetricsBySizeIndex[sizeIndex]) {
const metrics = fontMetricsBySizeIndex[sizeIndex] = {
cssEmPerMu: sigmasAndXis.quad[sizeIndex] / 18,
};
for (const key in sigmasAndXis) {
if (sigmasAndXis.hasOwnProperty(key)) {
metrics[key] = sigmasAndXis[key][sizeIndex];
}
}
}
return fontMetricsBySizeIndex[sizeIndex];
}

2077
node_modules/katex/src/fontMetricsData.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

139
node_modules/katex/src/fonts/Makefile generated vendored Normal file
View File

@@ -0,0 +1,139 @@
#!gmake
#
# Version: Apache License 2.0
#
# Copyright (c) 2013 MathJax Project
# Copyright (c) 2013 The MathJax Consortium
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
CUSTOM=custom.cfg
-include $(CUSTOM)
MFTRACE_MODIFIED=lib/mftrace-modified
all: config fonts
$(CUSTOM):
@cp default.cfg $(CUSTOM);
$(CUSTOM).pl: $(CUSTOM)
@echo "Creating Perl config file..."
@cp $(CUSTOM) $(CUSTOM).pl
@echo >> $(CUSTOM).pl # ensure that the config file ends by a new line
@echo "MFTRACE_PATH=`$(WHICH) $(MFTRACE)`" >> $(CUSTOM).pl
@$(SED) -i "s|^\([A-Z_0-9]*\)=\(.*\)|$$\1='\2';|" $(CUSTOM).pl
@echo "1;" >> $(CUSTOM).pl
.PHONY: config
config: $(CUSTOM).pl
blacker: $(MFTRACE_MODIFIED)
$(MFTRACE_MODIFIED):
$(PERL) -I. makeBlacker 15 # values between 10 and 30 seem best
pfa: $(MFTRACE_MODIFIED)
@echo "cmr10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --simplify cmr10
@echo "cmmi10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --encoding $(TETEXENCODING)/aae443f0.enc --simplify cmmi10
@echo "cmsy10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --encoding $(TETEXENCODING)/10037936.enc --simplify cmsy10
@echo "cmex10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --simplify cmex10
@echo "cmbx10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --simplify cmbx10
@echo "cmbxti10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --simplify cmbxti10
@echo "cmti10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --simplify cmti10
@echo "msam10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --simplify --encoding $(TETEXENCODING)/10037936.enc msam10
@echo "msbm10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --simplify --encoding $(TETEXENCODING)/10037936.enc msbm10
@echo "cmmib10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --encoding $(TETEXENCODING)/aae443f0.enc --simplify cmmib10
@echo "cmbsy10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --encoding $(TETEXENCODING)/10037936.enc --simplify cmbsy10
@echo "cmtt10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --simplify cmtt10
@echo "cmss10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --simplify cmss10
@echo "cmssi10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --simplify cmssi10
@echo "cmssbx10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --simplify cmssbx10
@echo "eufm10"
cp "`$(KPSEWHICH) eufm10.pfb`" eufm10.pfb
@echo "eufb10"
cp "`$(KPSEWHICH) eufb10.pfb`" eufb10.pfb
# echo "eusm10"
# $(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --simplify eusm10
# echo "eusb10"
# $(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --simplify eusb10
@echo "rsfs10"
$(PYTHON) $(MFTRACE_MODIFIED) --magnification 1000 --simplify --encoding $(BASEENCODING)/tex256.enc rsfs10
mkdir -p pfa
rm -f pfa/*
mv *.pfa pfa
mv *.pfb pfa
ff: pfa
mkdir -p ff otf
rm -f ff/* otf/*
$(PERL) -I. makeFF
.PHONY: fonts
fonts: ff
mkdir -p ttf woff woff2
rm -f ttf/* woff/* woff2/*
@for file in `ls ff/*.ff | $(SED) 's|ff/\(.*\)\.ff|\1|'`; do \
echo ""; \
echo $$file; \
$(FONTFORGE) -lang=ff -script ff/$$file.ff; \
\
echo "Hinting $$file"; \
if echo "$$file" | $(GREP) -q -e "Size[1-4]" -e "Typewriter"; then \
$(TTFAUTOHINT) -f none -S --windows-compatibility --symbol ttf/$$file.ttf ttf/$$file.ttf.hinted; \
else \
$(TTFAUTOHINT) -f none -S --windows-compatibility ttf/$$file.ttf ttf/$$file.ttf.hinted; \
fi; \
mv ttf/$$file.ttf.hinted ttf/$$file.ttf; \
\
echo "Generating $$file..."; \
$(PYTHON) generate_fonts.py ttf/$$file.ttf; \
done
clean:
rm -f $(CUSTOM).pl
rm -f $(MFTRACE_MODIFIED) lib/blacker.mf
rm -rf pfa ff otf ttf woff woff2

20
node_modules/katex/src/fonts/default.cfg generated vendored Normal file
View File

@@ -0,0 +1,20 @@
# Note: paths should be absolute, unless they point to programs in your $PATH.
##### Standard programs #####
GREP=grep
PERL=perl
PYTHON=python3
SED=sed
WHICH=which
KPSEWHICH=kpsewhich
##### Font tools #####
# Most of the tools below are standard and should be available from your package manager.
FONTFORGE=fontforge
MFTRACE=mftrace
TTX=ttx
TTFAUTOHINT=ttfautohint
##### TeXLive Encoding
TETEXENCODING=/usr/share/texlive/texmf-texlive/fonts/enc/dvips/tetex/
BASEENCODING=/usr/share/texlive/texmf-texlive/fonts/enc/dvips/base/

58
node_modules/katex/src/fonts/generate_fonts.py generated vendored Executable file
View File

@@ -0,0 +1,58 @@
#!/usr/bin/env python3
import sys
import os
import json
from fontTools.ttLib import TTFont, sfnt
from fontTools.misc.timeTools import timestampNow
sfnt.USE_ZOPFLI = True
if len(sys.argv) < 2:
print("Usage: %s <font file>" % sys.argv[0])
sys.exit(1)
font_file = sys.argv[1]
font_name = os.path.splitext(os.path.basename(font_file))[0]
font = TTFont(font_file, recalcBBoxes=False, recalcTimestamp=False)
# fix timestamp to the epoch
font['head'].created = 0
font['head'].modified = 0
# remove fontforge timestamps
if 'FFTM' in font:
del font['FFTM']
# remove redundant GDEF table
if 'GDEF' in font:
del font['GDEF']
# remove Macintosh table
# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6cmap.html
font['name'].names = [record for record in font['name'].names if record.platformID != 1]
font['cmap'].tables = [table for table in font['cmap'].tables if table.platformID != 1]
# fix OS/2 and hhea metrics
glyf = font['glyf']
ascent = int(max(glyf[c].yMax for c in font.getGlyphOrder() if hasattr(glyf[c], "yMax")))
descent = -int(min(glyf[c].yMin for c in font.getGlyphOrder() if hasattr(glyf[c], "yMin")))
font['OS/2'].usWinAscent = ascent
font['OS/2'].usWinDescent = descent
font['hhea'].ascent = ascent
font['hhea'].descent = -descent
# save TTF
font.save(font_file, reorderTables=None)
# save WOFF
font.flavor = 'woff'
font.save(os.path.join('woff', font_name + '.woff'), reorderTables=None)
# save WOFF2
font.flavor = 'woff2'
font.save(os.path.join('woff2', font_name + '.woff2'), reorderTables=None)

BIN
node_modules/katex/src/fonts/lib/Extra.otf generated vendored Normal file

Binary file not shown.

234
node_modules/katex/src/fonts/lib/Space.ttx generated vendored Normal file
View File

@@ -0,0 +1,234 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont sfntVersion="OTTO" ttLibVersion="3.28">
<GlyphOrder>
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
<GlyphID id="0" name=".notdef"/>
<GlyphID id="1" name="space"/>
<GlyphID id="2" name="uni00A0"/>
</GlyphOrder>
<head>
<!-- Most of this table will be recalculated by the compiler -->
<tableVersion value="1.0"/>
<fontRevision value="1.0"/>
<checkSumAdjustment value="0xa98c8795"/>
<magicNumber value="0x5f0f3cf5"/>
<flags value="00000000 00000011"/>
<unitsPerEm value="1000"/>
<created value="Sun Jan 24 23:04:46 2010"/>
<modified value="Sat May 14 12:26:22 2011"/>
<xMin value="50"/>
<yMin value="0"/>
<xMax value="200"/>
<yMax value="533"/>
<macStyle value="00000000 00000000"/>
<lowestRecPPEM value="8"/>
<fontDirectionHint value="2"/>
<indexToLocFormat value="0"/>
<glyphDataFormat value="0"/>
</head>
<hhea>
<tableVersion value="0x00010000"/>
<ascent value="800"/>
<descent value="-200"/>
<lineGap value="90"/>
<advanceWidthMax value="250"/>
<minLeftSideBearing value="50"/>
<minRightSideBearing value="50"/>
<xMaxExtent value="200"/>
<caretSlopeRise value="1"/>
<caretSlopeRun value="0"/>
<caretOffset value="0"/>
<reserved0 value="0"/>
<reserved1 value="0"/>
<reserved2 value="0"/>
<reserved3 value="0"/>
<metricDataFormat value="0"/>
<numberOfHMetrics value="1"/>
</hhea>
<maxp>
<tableVersion value="0x5000"/>
<numGlyphs value="3"/>
</maxp>
<OS_2>
<!-- The fields 'usFirstCharIndex' and 'usLastCharIndex'
will be recalculated by the compiler -->
<version value="2"/>
<xAvgCharWidth value="225"/>
<usWeightClass value="400"/>
<usWidthClass value="5"/>
<fsType value="00000000 00000000"/>
<ySubscriptXSize value="650"/>
<ySubscriptYSize value="700"/>
<ySubscriptXOffset value="0"/>
<ySubscriptYOffset value="140"/>
<ySuperscriptXSize value="650"/>
<ySuperscriptYSize value="700"/>
<ySuperscriptXOffset value="0"/>
<ySuperscriptYOffset value="480"/>
<yStrikeoutSize value="49"/>
<yStrikeoutPosition value="258"/>
<sFamilyClass value="0"/>
<panose>
<bFamilyType value="0"/>
<bSerifStyle value="0"/>
<bWeight value="0"/>
<bProportion value="0"/>
<bContrast value="0"/>
<bStrokeVariation value="0"/>
<bArmStyle value="0"/>
<bLetterForm value="0"/>
<bMidline value="0"/>
<bXHeight value="0"/>
</panose>
<ulUnicodeRange1 value="10000000 00000000 00000000 11101111"/>
<ulUnicodeRange2 value="00010000 00000000 11101100 11101101"/>
<ulUnicodeRange3 value="00000000 00000000 00000000 00000000"/>
<ulUnicodeRange4 value="00000000 00000000 00000000 00000000"/>
<achVendID value="PfEd"/>
<fsSelection value="00000000 01000000"/>
<usFirstCharIndex value="32"/>
<usLastCharIndex value="160"/>
<sTypoAscender value="800"/>
<sTypoDescender value="-200"/>
<sTypoLineGap value="90"/>
<usWinAscent value="533"/>
<usWinDescent value="0"/>
<ulCodePageRange1 value="00100000 00000000 00000000 10001111"/>
<ulCodePageRange2 value="01011110 00000011 00000000 00000000"/>
<sxHeight value="0"/>
<sCapHeight value="0"/>
<usDefaultChar value="32"/>
<usBreakChar value="32"/>
<usMaxContext value="1"/>
</OS_2>
<name>
<namerecord nameID="0" platformID="3" platEncID="1" langID="0x409">
Copyright (c) 2009-2010 Design Science, Inc.
Copyright (c) 2014-2018 Khan Academy
</namerecord>
<namerecord nameID="1" platformID="3" platEncID="1" langID="0x409">
*NAME*
</namerecord>
<namerecord nameID="2" platformID="3" platEncID="1" langID="0x409">
*WEIGHT_S*
</namerecord>
<namerecord nameID="3" platformID="3" platEncID="1" langID="0x409">
FontForge 2.0 : *NAME*-*WEIGHT*
</namerecord>
<namerecord nameID="4" platformID="3" platEncID="1" langID="0x409">
*NAME*-*WEIGHT*
</namerecord>
<namerecord nameID="5" platformID="3" platEncID="1" langID="0x409">
Version 1.1
</namerecord>
<namerecord nameID="6" platformID="3" platEncID="1" langID="0x409">
*NAME*-*WEIGHT*
</namerecord>
<namerecord nameID="13" platformID="3" platEncID="1" langID="0x409">
Copyright (c) 2009-2010, Design Science, Inc. (&lt;www.mathjax.org&gt;)
Copyright (c) 2014-2018 Khan Academy (&lt;www.khanacademy.org&gt;),
with Reserved Font Name *NAME*.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license available with a FAQ at:
http://scripts.sil.org/OFL
</namerecord>
<namerecord nameID="14" platformID="3" platEncID="1" langID="0x409">
http://scripts.sil.org/OFL
</namerecord>
</name>
<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="0" platEncID="3" language="0">
<map code="0x20" name="space"/><!-- SPACE -->
<map code="0xa0" name="uni00A0"/><!-- NO-BREAK SPACE -->
</cmap_format_4>
<cmap_format_4 platformID="3" platEncID="1" language="0">
<map code="0x20" name="space"/><!-- SPACE -->
<map code="0xa0" name="uni00A0"/><!-- NO-BREAK SPACE -->
</cmap_format_4>
</cmap>
<post>
<formatType value="3.0"/>
<italicAngle value="0.0"/>
<underlinePosition value="-125"/>
<underlineThickness value="50"/>
<isFixedPitch value="0"/>
<minMemType42 value="0"/>
<maxMemType42 value="0"/>
<minMemType1 value="0"/>
<maxMemType1 value="0"/>
</post>
<CFF>
<major value="1"/>
<minor value="0"/>
<CFFFont name="*NAME*-*WEIGHT*">
<version value="001.001"/>
<Notice value="Copyright (c) 2009-2010 Design Science, Inc., Copyright (c) 2014-2018 Khan Academy"/>
<FullName value="*NAME*-*WEIGHT*"/>
<FamilyName value="*NAME*"/>
<Weight value="*NORMAL*"/>
<isFixedPitch value="0"/>
<ItalicAngle value="0"/>
<UnderlinePosition value="-150"/>
<UnderlineThickness value="50"/>
<PaintType value="0"/>
<CharstringType value="2"/>
<FontMatrix value="0.001 0 0 0.001 0 0"/>
<FontBBox value="50 0 200 533"/>
<StrokeWidth value="0"/>
<!-- charset is dumped separately as the 'GlyphOrder' element -->
<Encoding name="StandardEncoding"/>
<Private>
<BlueScale value="0.03963"/>
<BlueShift value="0"/>
<BlueFuzz value="1"/>
<StdHW value="50"/>
<StdVW value="50"/>
<ForceBold value="0"/>
<LanguageGroup value="0"/>
<ExpansionFactor value="0.06"/>
<initialRandomSeed value="0"/>
<defaultWidthX value="250"/>
<nominalWidthX value="193"/>
</Private>
<CharStrings>
<CharString name=".notdef">
0 50 433 50 hstem
50 50 50 50 vstem
50 hmoveto
150 533 -150 hlineto
50 -483 rmoveto
433 50 -433 vlineto
endchar
</CharString>
<CharString name="space">
endchar
</CharString>
<CharString name="uni00A0">
endchar
</CharString>
</CharStrings>
</CFFFont>
<GlobalSubrs>
<!-- The 'index' attribute is only for humans; it is ignored when parsed. -->
</GlobalSubrs>
</CFF>
<hmtx>
<mtx name=".notdef" width="250" lsb="50"/>
<mtx name="space" width="250" lsb="0"/>
<mtx name="uni00A0" width="250" lsb="0"/>
</hmtx>
</ttFont>

49
node_modules/katex/src/fonts/makeBlacker generated vendored Executable file
View File

@@ -0,0 +1,49 @@
#! /usr/bin/perl
# Creates the metafont file needed for darker copies of the TeX fonts,
# and modifies mftrace to use it.
#
# Usage: ./makeBlacker blackness
require "custom.cfg.pl";
$blacker = shift;
unless ($blacker) {
print stderr "Usage: ./makeBlacker blackness\n";
exit;
}
sub editMftrace {
my $oldMFTRACE = $MFTRACE_PATH;
$MFTRACE = "./lib/mftrace-modified";
print "Editing mftrace\n";
open(MFT,$oldMFTRACE) || die "Can't read '$oldMFTRACE': $!\n";
my $MFT = join("",<MFT>);
close(MFT);
$MFT =~ s!r"mf '\\mode:=(?:[^;]*)(; [^"]*)"!r"""mf '\\smode:="lib/blacker.mf"$1"""!;
open(MFT,">$MFTRACE") || die "Can't write '$MFTRACE': $!\n";
print MFT $MFT;
close(MFT);
chmod 0755, $MFTRACE;
}
sub makeBlackerMF {
my $blacker = shift;
print "Using blacker = $blacker\n";
open(BLACKER,">lib/blacker.mf") || die "Can't write 'lib/blacker.mf': $!\n";
print BLACKER << " END";
proofing:=0;
fontmaking:=1;
tracingtitles:=0;
pixels_per_inch:=1200;
blacker:=$blacker;
fillin:=0;
o_correction:=1;
END
close(BLACKER);
}
editMftrace();
makeBlackerMF($blacker);
1;

2005
node_modules/katex/src/fonts/makeFF generated vendored Executable file

File diff suppressed because it is too large Load Diff

182
node_modules/katex/src/fonts/xbbold.mf generated vendored Normal file
View File

@@ -0,0 +1,182 @@
%% filename: xbbold.mf
%% version: 2.2
%% date: 1995/01/04
%%
%% (katex-fonts) The line 69 is modified to prevent overflow
%%
%% American Mathematical Society
%% Technical Support
%% Publications Technical Group
%% 201 Charles Street
%% Providence, RI 02904
%% USA
%% tel: (401) 455-4080
%% (800) 321-4267 (USA and Canada only)
%% fax: (401) 331-3842
%% email: tech-support@ams.org
%%
%% Copyright 1995, 2009 American Mathematical Society.
%%
%% This Font Software is licensed under the SIL Open Font License,
%% Version 1.1. This license is in the accompanying file OFL.txt, and
%% is also available with a FAQ at: http://scripts.sil.org/OFL.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Changes of minimal parameters in outlined characters for version 2.1
% done by Stefan Lindner, 18-April-1991
input xbbase;
%%mode_setup; %called by amsyb.mf; two calls confuse Metafont. NGB 15-OCT-1991
%%%%designsize:= font_size; % was 10pt#;
width#:= designsize; % was 10pt#;
unit#:= width#/18;
u#:= width#/54;
smallu#:= width#/162;
ascender#:= 37/3*unit#;
cap#:= 37/3*unit#;
number#:= 36/3*unit#;
xheight#:= 25/3*unit#;
descender#:= 12/4*unit#;
define_whole_vertical_pixels
(width,unit,u,smallu,ascender,cap,number,xheight,descender);
wpix(1.90u) (linethickness);
wpix(0.65u) (Sover_bot);
wpix(1.00u) (Aapex,Napex,Vapex,Wapex,Cover,Gover,Oover,Sover_top,Uover);
wpix(9.00u) (Uthin_bracket);
wpix(8.00u) (Kthin_diag_bracket,Xthin_diag_bracket,Ythin_diag_bracket);
wpix(7.00u) (k_thin_diag);
wpix(6.00u) (c_thin_stem_bracket);
wpix(5.00u) (c_thick_stem_bracket,c_inner_bracket,lc_thick_stem_bracket);
wpix(4.00u) (c_round_bracket);
adjpix(1.35u) (serif_thickness);
adjpix(1.30u) (Emid_tip,inbeak);
adjpix(1.50u) (Atip,Btopthin,Bmidthin,Ebot_tip,Ltip,Mapex,
Ntip,Ttip,Vtip,Wtip,Ztip,outbeak);
adjpix(1.65u) (Bbotthin,Gbotthin,Stopthin);
adjpix(1.75u) (Dtopthin,Ebotarm,Lthin,Tthin);
adjpix(1.80u) (Abar,Ctopthin,Dbotthin,Gtopthin,Jbotthin,Pmidarm,Sbotthin);
adjpix(1.90u) (Emidarm,Etoparm,Othin,Pthin,Rthin,Ydiag,Zthin);
adjpix(2.00u) (kthin,Mthin_diag,Wleftthin);
adjpix(2.10u) (Ctip);
adjpix(2.25u) (Athin,Kthin,Mthin_vert,Nthin,Uthin,Vthin,Wrightthin,Xthin);
adjpix(2.50u) (Hbar);
adjpix(2.60u) (Cbotthin);
%%%% Begin of changes for version 2.1
%(katex-fonts) Originally was pixels_per_inch*designsize < 1500:
if pixels_per_inch < 1500/designsize:
if pixels_per_inch*designsize < 1000:
if pixels_per_inch*designsize < 800:
if pixels_per_inch*designsize < 700:
minadjpix(0)(8.80u) (stem);
minadjpix(0)(6.80u) (kdiag);
minadjpix(0)(7.40u) (kstem);
minadjpix(0)(7.80u) (Jbulb,Mdiag);
minadjpix(0)(8.20u) (Kdiag);
minadjpix(0)(8.30u) (Gstem,Mstem);
minadjpix(0)(8.60u) (Lstem,Ustem,Ythick_diag);
minadjpix(0)(8.50u) (Bstem,Estem,Fstem,Ndiag,Rdiag,Xdiag,Zdiag);
minadjpix(0)(8.90u) (Btopcurve);
minadjpix(1)(9.30u) (Bbotcurve,Pcurve,Rcurve);
minadjpix(1)(9.50u) (Ccurve,Dcurve,Gcurve,Ocurve);
else:
minadjpix(1)(8.80u) (stem);
minadjpix(1)(6.80u) (kdiag);
minadjpix(1)(7.40u) (kstem);
minadjpix(1)(7.80u) (Jbulb,Mdiag);
minadjpix(1)(8.20u) (Kdiag);
minadjpix(1)(8.30u) (Gstem,Mstem);
minadjpix(1)(8.60u) (Lstem,Ustem,Ythick_diag);
minadjpix(1)(8.50u) (Bstem,Estem,Fstem,Ndiag,Rdiag,Xdiag,Zdiag);
minadjpix(1)(8.90u) (Btopcurve);
minadjpix(2)(9.30u) (Bbotcurve,Pcurve,Rcurve);
minadjpix(2)(9.50u) (Ccurve,Dcurve,Gcurve,Ocurve);
fi
else:
adjpix(3.0u) (Mapex);
minadjpix(1)(8.80u) (stem);
minadjpix(2)(6.80u) (kdiag);
minadjpix(2)(7.40u) (kstem);
minadjpix(2)(7.80u) (Jbulb);
minadjpix(1)(6.00u) (Mdiag);
minadjpix(2)(8.20u) (Kdiag);
minadjpix(2)(8.30u) (Gstem)
minadjpix(2)(8.30u) (Mstem);
minadjpix(2)(8.60u) (Lstem,Ustem,Ythick_diag);
minadjpix(2)(8.50u) (Bstem,Ndiag,Rdiag,Xdiag,Zdiag);
minadjpix(1)(8.50u) (Estem, Fstem);
minadjpix(2)(8.90u) (Btopcurve);
minadjpix(3)(9.30u) (Bbotcurve,Pcurve,Rcurve);
minadjpix(3)(9.50u) (Ccurve,Dcurve,Gcurve,Ocurve);
fi
else:
adjpix(3.0u) (Mapex);
minadjpix(2)(8.80u) (stem);
minadjpix(3)(6.80u) (kdiag);
minadjpix(3)(7.40u) (kstem);
minadjpix(3)(7.80u) (Jbulb);
minadjpix(1)(5.00u) (Mdiag);
minadjpix(3)(8.20u) (Kdiag);
minadjpix(3)(8.30u) (Gstem);
minadjpix(2)(8.30u) (Mstem);
minadjpix(3)(8.60u) (Lstem,Ustem,Ythick_diag);
minadjpix(3)(8.50u) (Estem,Fstem,Ndiag,Rdiag,Xdiag,Zdiag);
minadjpix(2)(8.50u) (Bstem);
minadjpix(3)(8.90u) (Btopcurve);
minadjpix(3)(9.30u) (Bbotcurve,Pcurve,Rcurve);
minadjpix(3)(9.50u) (Ccurve,Dcurve,Gcurve,Ocurve)
fi
else:
minadjpix(4)(8.80u) (stem);
minadjpix(4)(6.80u) (kdiag);
minadjpix(4)(7.40u) (kstem);
minadjpix(4)(7.80u) (Jbulb,Mdiag);
minadjpix(4)(8.20u) (Kdiag);
minadjpix(4)(8.30u) (Gstem,Mstem);
minadjpix(4)(8.60u) (Lstem,Ustem,Ythick_diag);
minadjpix(4)(8.50u) (Bstem,Estem,Fstem,Ndiag,Rdiag,Xdiag,Zdiag);
minadjpix(4)(8.90u) (Btopcurve);
minadjpix(5)(9.30u) (Bbotcurve,Pcurve,Rcurve);
minadjpix(5)(9.50u) (Ccurve,Dcurve,Gcurve,Ocurve)
fi;
%%%% end of changes for version 2.1
boolean lowres; lowres:=width<50;
highres_lowres(pullin) (.85)(1); % Emidarm
highres_lowres(pulleven) (1)(1.3); % Etoparm,Tarms,Zarms
highres_lowres(pullout) (1.1)(1); % Ebotarm,Lbotarm
highres_lowres(bracket0) (.0)(0); % Ntopleft
highres_lowres(bracket3) (.3)(0); % Nthinstems
highres_lowres(bracket01) (.0)(.1); % Uthin
highres_lowres(bracket32) (.3)(.2); % Vstems
highres_lowres(bracket4) (.4)(0); % P-all,R-all,I-all,F-all
highres_lowres(bracket42) (.4)(.2); % Xdiag
bool(ctrls):=false;
entasis:=inlimit(0)(0,1);
serif_constant_amt:=0pt;
join_radius:=1;
bool(softpath):=true;
c_thick_stem_bracket:=min(.5cap-eps,c_thick_stem_bracket);
rulepen:=pensquare scaled 1;
extra_beginchar:=extra_beginchar&"save t,p,ref; path p[],p[]',p[]'',ref[];";
extra_beginchar:=extra_beginchar&"pickup pencircle scaled linethickness;";
for x:="R":
wanted[byte x]:=true; endfor % test these characters
let iff=always_iff; % tests all chars in the file
font_normal_space .3width#; % TeX fontdimen 2 normal word space
font_normal_stretch .15width#; % TeX fontdimen 3 interword stretch
font_normal_shrink .1width#; % TeX fontdimen 4 interword shrink
font_x_height xheight#; % Tex fontdinem 5 for accents
font_quad width#; % TeX fontdimen 6 quad width
font_extra_space .1width#; % TeX fontdimen 7 extra space(period)
input xbcaps
bye % changed from "end" 26 Aug 93; bnb

55
node_modules/katex/src/functions.js generated vendored Normal file
View File

@@ -0,0 +1,55 @@
// @flow
/** Include this to ensure that all functions are defined. */
import {_functions} from "./defineFunction";
const functions = _functions;
export default functions;
// TODO(kevinb): have functions return an object and call defineFunction with
// that object in this file instead of relying on side-effects.
import "./functions/accent";
import "./functions/accentunder";
import "./functions/arrow";
import "./functions/pmb";
import "./environments/cd";
import "./functions/char";
import "./functions/color";
import "./functions/cr";
import "./functions/def";
import "./functions/delimsizing";
import "./functions/enclose";
import "./functions/environment";
import "./functions/font";
import "./functions/genfrac";
import "./functions/horizBrace";
import "./functions/href";
import "./functions/hbox";
import "./functions/html";
import "./functions/htmlmathml";
import "./functions/includegraphics";
import "./functions/kern";
import "./functions/lap";
import "./functions/math";
import "./functions/mathchoice";
import "./functions/mclass";
import "./functions/op";
import "./functions/operatorname";
import "./functions/ordgroup";
import "./functions/overline";
import "./functions/phantom";
import "./functions/raisebox";
import "./functions/relax";
import "./functions/rule";
import "./functions/sizing";
import "./functions/smash";
import "./functions/sqrt";
import "./functions/styling";
import "./functions/supsub";
import "./functions/symbolsOp";
import "./functions/symbolsOrd";
import "./functions/symbolsSpacing";
import "./functions/tag";
import "./functions/text";
import "./functions/underline";
import "./functions/vcenter";
import "./functions/verb";

284
node_modules/katex/src/functions/accent.js generated vendored Normal file
View File

@@ -0,0 +1,284 @@
// @flow
import defineFunction, {normalizeArgument} from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import utils from "../utils";
import stretchy from "../stretchy";
import {assertNodeType} from "../parseNode";
import {assertSpan, assertSymbolDomNode} from "../domTree";
import {makeEm} from "../units";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import type {ParseNode, AnyParseNode} from "../parseNode";
import type {HtmlBuilderSupSub, MathMLBuilder} from "../defineFunction";
// NOTE: Unlike most `htmlBuilder`s, this one handles not only "accent", but
// also "supsub" since an accent can affect super/subscripting.
export const htmlBuilder: HtmlBuilderSupSub<"accent"> = (grp, options) => {
// Accents are handled in the TeXbook pg. 443, rule 12.
let base: AnyParseNode;
let group: ParseNode<"accent">;
let supSubGroup;
if (grp && grp.type === "supsub") {
// If our base is a character box, and we have superscripts and
// subscripts, the supsub will defer to us. In particular, we want
// to attach the superscripts and subscripts to the inner body (so
// that the position of the superscripts and subscripts won't be
// affected by the height of the accent). We accomplish this by
// sticking the base of the accent into the base of the supsub, and
// rendering that, while keeping track of where the accent is.
// The real accent group is the base of the supsub group
group = assertNodeType(grp.base, "accent");
// The character box is the base of the accent group
base = group.base;
// Stick the character box into the base of the supsub group
grp.base = base;
// Rerender the supsub group with its new base, and store that
// result.
supSubGroup = assertSpan(html.buildGroup(grp, options));
// reset original base
grp.base = group;
} else {
group = assertNodeType(grp, "accent");
base = group.base;
}
// Build the base group
const body = html.buildGroup(base, options.havingCrampedStyle());
// Does the accent need to shift for the skew of a character?
const mustShift = group.isShifty && utils.isCharacterBox(base);
// Calculate the skew of the accent. This is based on the line "If the
// nucleus is not a single character, let s = 0; otherwise set s to the
// kern amount for the nucleus followed by the \skewchar of its font."
// Note that our skew metrics are just the kern between each character
// and the skewchar.
let skew = 0;
if (mustShift) {
// If the base is a character box, then we want the skew of the
// innermost character. To do that, we find the innermost character:
const baseChar = utils.getBaseElem(base);
// Then, we render its group to get the symbol inside it
const baseGroup = html.buildGroup(baseChar, options.havingCrampedStyle());
// Finally, we pull the skew off of the symbol.
skew = assertSymbolDomNode(baseGroup).skew;
// Note that we now throw away baseGroup, because the layers we
// removed with getBaseElem might contain things like \color which
// we can't get rid of.
// TODO(emily): Find a better way to get the skew
}
const accentBelow = group.label === "\\c";
// calculate the amount of space between the body and the accent
let clearance = accentBelow
? body.height + body.depth
: Math.min(
body.height,
options.fontMetrics().xHeight);
// Build the accent
let accentBody;
if (!group.isStretchy) {
let accent;
let width: number;
if (group.label === "\\vec") {
// Before version 0.9, \vec used the combining font glyph U+20D7.
// But browsers, especially Safari, are not consistent in how they
// render combining characters when not preceded by a character.
// So now we use an SVG.
// If Safari reforms, we should consider reverting to the glyph.
accent = buildCommon.staticSvg("vec", options);
width = buildCommon.svgData.vec[1];
} else {
accent = buildCommon.makeOrd({mode: group.mode, text: group.label},
options, "textord");
accent = assertSymbolDomNode(accent);
// Remove the italic correction of the accent, because it only serves to
// shift the accent over to a place we don't want.
accent.italic = 0;
width = accent.width;
if (accentBelow) {
clearance += accent.depth;
}
}
accentBody = buildCommon.makeSpan(["accent-body"], [accent]);
// "Full" accents expand the width of the resulting symbol to be
// at least the width of the accent, and overlap directly onto the
// character without any vertical offset.
const accentFull = (group.label === "\\textcircled");
if (accentFull) {
accentBody.classes.push('accent-full');
clearance = body.height;
}
// Shift the accent over by the skew.
let left = skew;
// CSS defines `.katex .accent .accent-body:not(.accent-full) { width: 0 }`
// so that the accent doesn't contribute to the bounding box.
// We need to shift the character by its width (effectively half
// its width) to compensate.
if (!accentFull) {
left -= width / 2;
}
accentBody.style.left = makeEm(left);
// \textcircled uses the \bigcirc glyph, so it needs some
// vertical adjustment to match LaTeX.
if (group.label === "\\textcircled") {
accentBody.style.top = ".2em";
}
accentBody = buildCommon.makeVList({
positionType: "firstBaseline",
children: [
{type: "elem", elem: body},
{type: "kern", size: -clearance},
{type: "elem", elem: accentBody},
],
}, options);
} else {
accentBody = stretchy.svgSpan(group, options);
accentBody = buildCommon.makeVList({
positionType: "firstBaseline",
children: [
{type: "elem", elem: body},
{
type: "elem",
elem: accentBody,
wrapperClasses: ["svg-align"],
wrapperStyle: skew > 0
? {
width: `calc(100% - ${makeEm(2 * skew)})`,
marginLeft: makeEm(2 * skew),
}
: undefined,
},
],
}, options);
}
const accentWrap =
buildCommon.makeSpan(["mord", "accent"], [accentBody], options);
if (supSubGroup) {
// Here, we replace the "base" child of the supsub with our newly
// generated accent.
supSubGroup.children[0] = accentWrap;
// Since we don't rerun the height calculation after replacing the
// accent, we manually recalculate height.
supSubGroup.height = Math.max(accentWrap.height, supSubGroup.height);
// Accents should always be ords, even when their innards are not.
supSubGroup.classes[0] = "mord";
return supSubGroup;
} else {
return accentWrap;
}
};
const mathmlBuilder: MathMLBuilder<"accent"> = (group, options) => {
const accentNode =
group.isStretchy ?
stretchy.mathMLnode(group.label) :
new mathMLTree.MathNode("mo", [mml.makeText(group.label, group.mode)]);
const node = new mathMLTree.MathNode(
"mover",
[mml.buildGroup(group.base, options), accentNode]);
node.setAttribute("accent", "true");
return node;
};
const NON_STRETCHY_ACCENT_REGEX = new RegExp([
"\\acute", "\\grave", "\\ddot", "\\tilde", "\\bar", "\\breve",
"\\check", "\\hat", "\\vec", "\\dot", "\\mathring",
].map(accent => `\\${accent}`).join("|"));
// Accents
defineFunction({
type: "accent",
names: [
"\\acute", "\\grave", "\\ddot", "\\tilde", "\\bar", "\\breve",
"\\check", "\\hat", "\\vec", "\\dot", "\\mathring", "\\widecheck",
"\\widehat", "\\widetilde", "\\overrightarrow", "\\overleftarrow",
"\\Overrightarrow", "\\overleftrightarrow", "\\overgroup",
"\\overlinesegment", "\\overleftharpoon", "\\overrightharpoon",
],
props: {
numArgs: 1,
},
handler: (context, args) => {
const base = normalizeArgument(args[0]);
const isStretchy = !NON_STRETCHY_ACCENT_REGEX.test(context.funcName);
const isShifty = !isStretchy ||
context.funcName === "\\widehat" ||
context.funcName === "\\widetilde" ||
context.funcName === "\\widecheck";
return {
type: "accent",
mode: context.parser.mode,
label: context.funcName,
isStretchy: isStretchy,
isShifty: isShifty,
base: base,
};
},
htmlBuilder,
mathmlBuilder,
});
// Text-mode accents
defineFunction({
type: "accent",
names: [
"\\'", "\\`", "\\^", "\\~", "\\=", "\\u", "\\.", '\\"',
"\\c", "\\r", "\\H", "\\v", "\\textcircled",
],
props: {
numArgs: 1,
allowedInText: true,
allowedInMath: true, // unless in strict mode
argTypes: ["primitive"],
},
handler: (context, args) => {
const base = args[0];
let mode = context.parser.mode;
if (mode === "math") {
context.parser.settings.reportNonstrict("mathVsTextAccents",
`LaTeX's accent ${context.funcName} works only in text mode`);
mode = "text";
}
return {
type: "accent",
mode: mode,
label: context.funcName,
isStretchy: false,
isShifty: true,
base: base,
};
},
htmlBuilder,
mathmlBuilder,
});

60
node_modules/katex/src/functions/accentunder.js generated vendored Normal file
View File

@@ -0,0 +1,60 @@
// @flow
// Horizontal overlap functions
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import stretchy from "../stretchy";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import type {ParseNode} from "../parseNode";
defineFunction({
type: "accentUnder",
names: [
"\\underleftarrow", "\\underrightarrow", "\\underleftrightarrow",
"\\undergroup", "\\underlinesegment", "\\utilde",
],
props: {
numArgs: 1,
},
handler: ({parser, funcName}, args) => {
const base = args[0];
return {
type: "accentUnder",
mode: parser.mode,
label: funcName,
base: base,
};
},
htmlBuilder: (group: ParseNode<"accentUnder">, options) => {
// Treat under accents much like underlines.
const innerGroup = html.buildGroup(group.base, options);
const accentBody = stretchy.svgSpan(group, options);
const kern = group.label === "\\utilde" ? 0.12 : 0;
// Generate the vlist, with the appropriate kerns
const vlist = buildCommon.makeVList({
positionType: "top",
positionData: innerGroup.height,
children: [
{type: "elem", elem: accentBody, wrapperClasses: ["svg-align"]},
{type: "kern", size: kern},
{type: "elem", elem: innerGroup},
],
}, options);
return buildCommon.makeSpan(["mord", "accentunder"], [vlist], options);
},
mathmlBuilder: (group, options) => {
const accentNode = stretchy.mathMLnode(group.label);
const node = new mathMLTree.MathNode(
"munder",
[mml.buildGroup(group.base, options), accentNode]
);
node.setAttribute("accentunder", "true");
return node;
},
});

144
node_modules/katex/src/functions/arrow.js generated vendored Normal file
View File

@@ -0,0 +1,144 @@
// @flow
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import stretchy from "../stretchy";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import type {ParseNode} from "../parseNode";
// Helper function
const paddedNode = group => {
const node = new mathMLTree.MathNode("mpadded", group ? [group] : []);
node.setAttribute("width", "+0.6em");
node.setAttribute("lspace", "0.3em");
return node;
};
// Stretchy arrows with an optional argument
defineFunction({
type: "xArrow",
names: [
"\\xleftarrow", "\\xrightarrow", "\\xLeftarrow", "\\xRightarrow",
"\\xleftrightarrow", "\\xLeftrightarrow", "\\xhookleftarrow",
"\\xhookrightarrow", "\\xmapsto", "\\xrightharpoondown",
"\\xrightharpoonup", "\\xleftharpoondown", "\\xleftharpoonup",
"\\xrightleftharpoons", "\\xleftrightharpoons", "\\xlongequal",
"\\xtwoheadrightarrow", "\\xtwoheadleftarrow", "\\xtofrom",
// The next 3 functions are here to support the mhchem extension.
// Direct use of these functions is discouraged and may break someday.
"\\xrightleftarrows", "\\xrightequilibrium", "\\xleftequilibrium",
// The next 3 functions are here only to support the {CD} environment.
"\\\\cdrightarrow", "\\\\cdleftarrow", "\\\\cdlongequal",
],
props: {
numArgs: 1,
numOptionalArgs: 1,
},
handler({parser, funcName}, args, optArgs) {
return {
type: "xArrow",
mode: parser.mode,
label: funcName,
body: args[0],
below: optArgs[0],
};
},
// Flow is unable to correctly infer the type of `group`, even though it's
// unambiguously determined from the passed-in `type` above.
htmlBuilder(group: ParseNode<"xArrow">, options) {
const style = options.style;
// Build the argument groups in the appropriate style.
// Ref: amsmath.dtx: \hbox{$\scriptstyle\mkern#3mu{#6}\mkern#4mu$}%
// Some groups can return document fragments. Handle those by wrapping
// them in a span.
let newOptions = options.havingStyle(style.sup());
const upperGroup = buildCommon.wrapFragment(
html.buildGroup(group.body, newOptions, options), options);
const arrowPrefix = group.label.slice(0, 2) === "\\x" ? "x" : "cd";
upperGroup.classes.push(arrowPrefix + "-arrow-pad");
let lowerGroup;
if (group.below) {
// Build the lower group
newOptions = options.havingStyle(style.sub());
lowerGroup = buildCommon.wrapFragment(
html.buildGroup(group.below, newOptions, options), options);
lowerGroup.classes.push(arrowPrefix + "-arrow-pad");
}
const arrowBody = stretchy.svgSpan(group, options);
// Re shift: Note that stretchy.svgSpan returned arrowBody.depth = 0.
// The point we want on the math axis is at 0.5 * arrowBody.height.
const arrowShift = -options.fontMetrics().axisHeight +
0.5 * arrowBody.height;
// 2 mu kern. Ref: amsmath.dtx: #7\if0#2\else\mkern#2mu\fi
let upperShift = -options.fontMetrics().axisHeight
- 0.5 * arrowBody.height - 0.111; // 0.111 em = 2 mu
if (upperGroup.depth > 0.25 || group.label === "\\xleftequilibrium") {
upperShift -= upperGroup.depth; // shift up if depth encroaches
}
// Generate the vlist
let vlist;
if (lowerGroup) {
const lowerShift = -options.fontMetrics().axisHeight
+ lowerGroup.height + 0.5 * arrowBody.height
+ 0.111;
vlist = buildCommon.makeVList({
positionType: "individualShift",
children: [
{type: "elem", elem: upperGroup, shift: upperShift},
{type: "elem", elem: arrowBody, shift: arrowShift},
{type: "elem", elem: lowerGroup, shift: lowerShift},
],
}, options);
} else {
vlist = buildCommon.makeVList({
positionType: "individualShift",
children: [
{type: "elem", elem: upperGroup, shift: upperShift},
{type: "elem", elem: arrowBody, shift: arrowShift},
],
}, options);
}
// $FlowFixMe: Replace this with passing "svg-align" into makeVList.
vlist.children[0].children[0].children[1].classes.push("svg-align");
return buildCommon.makeSpan(["mrel", "x-arrow"], [vlist], options);
},
mathmlBuilder(group, options) {
const arrowNode = stretchy.mathMLnode(group.label);
arrowNode.setAttribute(
"minsize", group.label.charAt(0) === "x" ? "1.75em" : "3.0em"
);
let node;
if (group.body) {
const upperNode = paddedNode(mml.buildGroup(group.body, options));
if (group.below) {
const lowerNode = paddedNode(mml.buildGroup(group.below, options));
node = new mathMLTree.MathNode(
"munderover", [arrowNode, lowerNode, upperNode]
);
} else {
node = new mathMLTree.MathNode("mover", [arrowNode, upperNode]);
}
} else if (group.below) {
const lowerNode = paddedNode(mml.buildGroup(group.below, options));
node = new mathMLTree.MathNode("munder", [arrowNode, lowerNode]);
} else {
// This should never happen.
// Parser.js throws an error if there is no argument.
node = paddedNode();
node = new mathMLTree.MathNode("mover", [arrowNode, node]);
}
return node;
},
});

45
node_modules/katex/src/functions/char.js generated vendored Normal file
View File

@@ -0,0 +1,45 @@
// @flow
import defineFunction from "../defineFunction";
import ParseError from "../ParseError";
import {assertNodeType} from "../parseNode";
// \@char is an internal function that takes a grouped decimal argument like
// {123} and converts into symbol with code 123. It is used by the *macro*
// \char defined in macros.js.
defineFunction({
type: "textord",
names: ["\\@char"],
props: {
numArgs: 1,
allowedInText: true,
},
handler({parser}, args) {
const arg = assertNodeType(args[0], "ordgroup");
const group = arg.body;
let number = "";
for (let i = 0; i < group.length; i++) {
const node = assertNodeType(group[i], "textord");
number += node.text;
}
let code = parseInt(number);
let text;
if (isNaN(code)) {
throw new ParseError(`\\@char has non-numeric argument ${number}`);
// If we drop IE support, the following code could be replaced with
// text = String.fromCodePoint(code)
} else if (code < 0 || code >= 0x10ffff) {
throw new ParseError(`\\@char with invalid code point ${number}`);
} else if (code <= 0xffff) {
text = String.fromCharCode(code);
} else { // Astral code point; split into surrogate halves
code -= 0x10000;
text = String.fromCharCode((code >> 10) + 0xd800,
(code & 0x3ff) + 0xdc00);
}
return {
type: "textord",
mode: parser.mode,
text: text,
};
},
});

88
node_modules/katex/src/functions/color.js generated vendored Normal file
View File

@@ -0,0 +1,88 @@
// @flow
import defineFunction, {ordargument} from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import {assertNodeType} from "../parseNode";
import type {AnyParseNode} from '../parseNode';
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
const htmlBuilder = (group, options) => {
const elements = html.buildExpression(
group.body,
options.withColor(group.color),
false
);
// \color isn't supposed to affect the type of the elements it contains.
// To accomplish this, we wrap the results in a fragment, so the inner
// elements will be able to directly interact with their neighbors. For
// example, `\color{red}{2 +} 3` has the same spacing as `2 + 3`
return buildCommon.makeFragment(elements);
};
const mathmlBuilder = (group, options) => {
const inner = mml.buildExpression(group.body,
options.withColor(group.color));
const node = new mathMLTree.MathNode("mstyle", inner);
node.setAttribute("mathcolor", group.color);
return node;
};
defineFunction({
type: "color",
names: ["\\textcolor"],
props: {
numArgs: 2,
allowedInText: true,
argTypes: ["color", "original"],
},
handler({parser}, args) {
const color = assertNodeType(args[0], "color-token").color;
const body = args[1];
return {
type: "color",
mode: parser.mode,
color,
body: (ordargument(body): AnyParseNode[]),
};
},
htmlBuilder,
mathmlBuilder,
});
defineFunction({
type: "color",
names: ["\\color"],
props: {
numArgs: 1,
allowedInText: true,
argTypes: ["color"],
},
handler({parser, breakOnTokenText}, args) {
const color = assertNodeType(args[0], "color-token").color;
// Set macro \current@color in current namespace to store the current
// color, mimicking the behavior of color.sty.
// This is currently used just to correctly color a \right
// that follows a \color command.
parser.gullet.macros.set("\\current@color", color);
// Parse out the implicit body that should be colored.
const body: AnyParseNode[] = parser.parseExpression(true, breakOnTokenText);
return {
type: "color",
mode: parser.mode,
color,
body,
};
},
htmlBuilder,
mathmlBuilder,
});

61
node_modules/katex/src/functions/cr.js generated vendored Normal file
View File

@@ -0,0 +1,61 @@
//@flow
// Row breaks within tabular environments, and line breaks at top level
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import {calculateSize, makeEm} from "../units";
import {assertNodeType} from "../parseNode";
// \DeclareRobustCommand\\{...\@xnewline}
defineFunction({
type: "cr",
names: ["\\\\"],
props: {
numArgs: 0,
numOptionalArgs: 0,
allowedInText: true,
},
handler({parser}, args, optArgs) {
const size = parser.gullet.future().text === "[" ?
parser.parseSizeGroup(true) : null;
const newLine = !parser.settings.displayMode ||
!parser.settings.useStrictBehavior(
"newLineInDisplayMode", "In LaTeX, \\\\ or \\newline " +
"does nothing in display mode");
return {
type: "cr",
mode: parser.mode,
newLine,
size: size && assertNodeType(size, "size").value,
};
},
// The following builders are called only at the top level,
// not within tabular/array environments.
htmlBuilder(group, options) {
const span = buildCommon.makeSpan(["mspace"], [], options);
if (group.newLine) {
span.classes.push("newline");
if (group.size) {
span.style.marginTop =
makeEm(calculateSize(group.size, options));
}
}
return span;
},
mathmlBuilder(group, options) {
const node = new mathMLTree.MathNode("mspace");
if (group.newLine) {
node.setAttribute("linebreak", "newline");
if (group.size) {
node.setAttribute("height",
makeEm(calculateSize(group.size, options)));
}
}
return node;
},
});

210
node_modules/katex/src/functions/def.js generated vendored Normal file
View File

@@ -0,0 +1,210 @@
//@flow
import defineFunction from "../defineFunction";
import ParseError from "../ParseError";
import {assertNodeType} from "../parseNode";
const globalMap = {
"\\global": "\\global",
"\\long": "\\\\globallong",
"\\\\globallong": "\\\\globallong",
"\\def": "\\gdef",
"\\gdef": "\\gdef",
"\\edef": "\\xdef",
"\\xdef": "\\xdef",
"\\let": "\\\\globallet",
"\\futurelet": "\\\\globalfuture",
};
const checkControlSequence = (tok) => {
const name = tok.text;
if (/^(?:[\\{}$&#^_]|EOF)$/.test(name)) {
throw new ParseError("Expected a control sequence", tok);
}
return name;
};
const getRHS = (parser) => {
let tok = parser.gullet.popToken();
if (tok.text === "=") { // consume optional equals
tok = parser.gullet.popToken();
if (tok.text === " ") { // consume one optional space
tok = parser.gullet.popToken();
}
}
return tok;
};
const letCommand = (parser, name, tok, global) => {
let macro = parser.gullet.macros.get(tok.text);
if (macro == null) {
// don't expand it later even if a macro with the same name is defined
// e.g., \let\foo=\frac \def\frac{\relax} \frac12
tok.noexpand = true;
macro = {
tokens: [tok],
numArgs: 0,
// reproduce the same behavior in expansion
unexpandable: !parser.gullet.isExpandable(tok.text),
};
}
parser.gullet.macros.set(name, macro, global);
};
// <assignment> -> <non-macro assignment>|<macro assignment>
// <non-macro assignment> -> <simple assignment>|\global<non-macro assignment>
// <macro assignment> -> <definition>|<prefix><macro assignment>
// <prefix> -> \global|\long|\outer
defineFunction({
type: "internal",
names: [
"\\global", "\\long",
"\\\\globallong", // cant be entered directly
],
props: {
numArgs: 0,
allowedInText: true,
},
handler({parser, funcName}) {
parser.consumeSpaces();
const token = parser.fetch();
if (globalMap[token.text]) {
// KaTeX doesn't have \par, so ignore \long
if (funcName === "\\global" || funcName === "\\\\globallong") {
token.text = globalMap[token.text];
}
return assertNodeType(parser.parseFunction(), "internal");
}
throw new ParseError(`Invalid token after macro prefix`, token);
},
});
// Basic support for macro definitions: \def, \gdef, \edef, \xdef
// <definition> -> <def><control sequence><definition text>
// <def> -> \def|\gdef|\edef|\xdef
// <definition text> -> <parameter text><left brace><balanced text><right brace>
defineFunction({
type: "internal",
names: ["\\def", "\\gdef", "\\edef", "\\xdef"],
props: {
numArgs: 0,
allowedInText: true,
primitive: true,
},
handler({parser, funcName}) {
let tok = parser.gullet.popToken();
const name = tok.text;
if (/^(?:[\\{}$&#^_]|EOF)$/.test(name)) {
throw new ParseError("Expected a control sequence", tok);
}
let numArgs = 0;
let insert;
const delimiters = [[]];
// <parameter text> contains no braces
while (parser.gullet.future().text !== "{") {
tok = parser.gullet.popToken();
if (tok.text === "#") {
// If the very last character of the <parameter text> is #, so that
// this # is immediately followed by {, TeX will behave as if the {
// had been inserted at the right end of both the parameter text
// and the replacement text.
if (parser.gullet.future().text === "{") {
insert = parser.gullet.future();
delimiters[numArgs].push("{");
break;
}
// A parameter, the first appearance of # must be followed by 1,
// the next by 2, and so on; up to nine #s are allowed
tok = parser.gullet.popToken();
if (!(/^[1-9]$/.test(tok.text))) {
throw new ParseError(`Invalid argument number "${tok.text}"`);
}
if (parseInt(tok.text) !== numArgs + 1) {
throw new ParseError(
`Argument number "${tok.text}" out of order`);
}
numArgs++;
delimiters.push([]);
} else if (tok.text === "EOF") {
throw new ParseError("Expected a macro definition");
} else {
delimiters[numArgs].push(tok.text);
}
}
// replacement text, enclosed in '{' and '}' and properly nested
let {tokens} = parser.gullet.consumeArg();
if (insert) {
tokens.unshift(insert);
}
if (funcName === "\\edef" || funcName === "\\xdef") {
tokens = parser.gullet.expandTokens(tokens);
tokens.reverse(); // to fit in with stack order
}
// Final arg is the expansion of the macro
parser.gullet.macros.set(name, {
tokens,
numArgs,
delimiters,
}, funcName === globalMap[funcName]);
return {
type: "internal",
mode: parser.mode,
};
},
});
// <simple assignment> -> <let assignment>
// <let assignment> -> \futurelet<control sequence><token><token>
// | \let<control sequence><equals><one optional space><token>
// <equals> -> <optional spaces>|<optional spaces>=
defineFunction({
type: "internal",
names: [
"\\let",
"\\\\globallet", // cant be entered directly
],
props: {
numArgs: 0,
allowedInText: true,
primitive: true,
},
handler({parser, funcName}) {
const name = checkControlSequence(parser.gullet.popToken());
parser.gullet.consumeSpaces();
const tok = getRHS(parser);
letCommand(parser, name, tok, funcName === "\\\\globallet");
return {
type: "internal",
mode: parser.mode,
};
},
});
// ref: https://www.tug.org/TUGboat/tb09-3/tb22bechtolsheim.pdf
defineFunction({
type: "internal",
names: [
"\\futurelet",
"\\\\globalfuture", // cant be entered directly
],
props: {
numArgs: 0,
allowedInText: true,
primitive: true,
},
handler({parser, funcName}) {
const name = checkControlSequence(parser.gullet.popToken());
const middle = parser.gullet.popToken();
const tok = parser.gullet.popToken();
letCommand(parser, name, tok, funcName === "\\\\globalfuture");
parser.gullet.pushToken(tok);
parser.gullet.pushToken(middle);
return {
type: "internal",
mode: parser.mode,
};
},
});

360
node_modules/katex/src/functions/delimsizing.js generated vendored Normal file
View File

@@ -0,0 +1,360 @@
// @flow
import buildCommon from "../buildCommon";
import defineFunction from "../defineFunction";
import delimiter from "../delimiter";
import mathMLTree from "../mathMLTree";
import ParseError from "../ParseError";
import utils from "../utils";
import {assertNodeType, checkSymbolNodeType} from "../parseNode";
import {makeEm} from "../units";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import type Options from "../Options";
import type {AnyParseNode, ParseNode, SymbolParseNode} from "../parseNode";
import type {FunctionContext} from "../defineFunction";
// Extra data needed for the delimiter handler down below
const delimiterSizes = {
"\\bigl" : {mclass: "mopen", size: 1},
"\\Bigl" : {mclass: "mopen", size: 2},
"\\biggl": {mclass: "mopen", size: 3},
"\\Biggl": {mclass: "mopen", size: 4},
"\\bigr" : {mclass: "mclose", size: 1},
"\\Bigr" : {mclass: "mclose", size: 2},
"\\biggr": {mclass: "mclose", size: 3},
"\\Biggr": {mclass: "mclose", size: 4},
"\\bigm" : {mclass: "mrel", size: 1},
"\\Bigm" : {mclass: "mrel", size: 2},
"\\biggm": {mclass: "mrel", size: 3},
"\\Biggm": {mclass: "mrel", size: 4},
"\\big" : {mclass: "mord", size: 1},
"\\Big" : {mclass: "mord", size: 2},
"\\bigg" : {mclass: "mord", size: 3},
"\\Bigg" : {mclass: "mord", size: 4},
};
const delimiters = [
"(", "\\lparen", ")", "\\rparen",
"[", "\\lbrack", "]", "\\rbrack",
"\\{", "\\lbrace", "\\}", "\\rbrace",
"\\lfloor", "\\rfloor", "\u230a", "\u230b",
"\\lceil", "\\rceil", "\u2308", "\u2309",
"<", ">", "\\langle", "\u27e8", "\\rangle", "\u27e9", "\\lt", "\\gt",
"\\lvert", "\\rvert", "\\lVert", "\\rVert",
"\\lgroup", "\\rgroup", "\u27ee", "\u27ef",
"\\lmoustache", "\\rmoustache", "\u23b0", "\u23b1",
"/", "\\backslash",
"|", "\\vert", "\\|", "\\Vert",
"\\uparrow", "\\Uparrow",
"\\downarrow", "\\Downarrow",
"\\updownarrow", "\\Updownarrow",
".",
];
type IsMiddle = {delim: string, options: Options};
// Delimiter functions
function checkDelimiter(
delim: AnyParseNode,
context: FunctionContext,
): SymbolParseNode {
const symDelim = checkSymbolNodeType(delim);
if (symDelim && utils.contains(delimiters, symDelim.text)) {
return symDelim;
} else if (symDelim) {
throw new ParseError(
`Invalid delimiter '${symDelim.text}' after '${context.funcName}'`,
delim);
} else {
throw new ParseError(`Invalid delimiter type '${delim.type}'`, delim);
}
}
defineFunction({
type: "delimsizing",
names: [
"\\bigl", "\\Bigl", "\\biggl", "\\Biggl",
"\\bigr", "\\Bigr", "\\biggr", "\\Biggr",
"\\bigm", "\\Bigm", "\\biggm", "\\Biggm",
"\\big", "\\Big", "\\bigg", "\\Bigg",
],
props: {
numArgs: 1,
argTypes: ["primitive"],
},
handler: (context, args) => {
const delim = checkDelimiter(args[0], context);
return {
type: "delimsizing",
mode: context.parser.mode,
size: delimiterSizes[context.funcName].size,
mclass: delimiterSizes[context.funcName].mclass,
delim: delim.text,
};
},
htmlBuilder: (group, options) => {
if (group.delim === ".") {
// Empty delimiters still count as elements, even though they don't
// show anything.
return buildCommon.makeSpan([group.mclass]);
}
// Use delimiter.sizedDelim to generate the delimiter.
return delimiter.sizedDelim(
group.delim, group.size, options, group.mode, [group.mclass]);
},
mathmlBuilder: (group) => {
const children = [];
if (group.delim !== ".") {
children.push(mml.makeText(group.delim, group.mode));
}
const node = new mathMLTree.MathNode("mo", children);
if (group.mclass === "mopen" ||
group.mclass === "mclose") {
// Only some of the delimsizing functions act as fences, and they
// return "mopen" or "mclose" mclass.
node.setAttribute("fence", "true");
} else {
// Explicitly disable fencing if it's not a fence, to override the
// defaults.
node.setAttribute("fence", "false");
}
node.setAttribute("stretchy", "true");
const size = makeEm(delimiter.sizeToMaxHeight[group.size]);
node.setAttribute("minsize", size);
node.setAttribute("maxsize", size);
return node;
},
});
function assertParsed(group: ParseNode<"leftright">) {
if (!group.body) {
throw new Error("Bug: The leftright ParseNode wasn't fully parsed.");
}
}
defineFunction({
type: "leftright-right",
names: ["\\right"],
props: {
numArgs: 1,
primitive: true,
},
handler: (context, args) => {
// \left case below triggers parsing of \right in
// `const right = parser.parseFunction();`
// uses this return value.
const color = context.parser.gullet.macros.get("\\current@color");
if (color && typeof color !== "string") {
throw new ParseError(
"\\current@color set to non-string in \\right");
}
return {
type: "leftright-right",
mode: context.parser.mode,
delim: checkDelimiter(args[0], context).text,
color, // undefined if not set via \color
};
},
});
defineFunction({
type: "leftright",
names: ["\\left"],
props: {
numArgs: 1,
primitive: true,
},
handler: (context, args) => {
const delim = checkDelimiter(args[0], context);
const parser = context.parser;
// Parse out the implicit body
++parser.leftrightDepth;
// parseExpression stops before '\\right'
const body = parser.parseExpression(false);
--parser.leftrightDepth;
// Check the next token
parser.expect("\\right", false);
const right = assertNodeType(parser.parseFunction(), "leftright-right");
return {
type: "leftright",
mode: parser.mode,
body,
left: delim.text,
right: right.delim,
rightColor: right.color,
};
},
htmlBuilder: (group, options) => {
assertParsed(group);
// Build the inner expression
const inner = html.buildExpression(group.body, options, true,
["mopen", "mclose"]);
let innerHeight = 0;
let innerDepth = 0;
let hadMiddle = false;
// Calculate its height and depth
for (let i = 0; i < inner.length; i++) {
// Property `isMiddle` not defined on `span`. See comment in
// "middle"'s htmlBuilder.
// $FlowFixMe
if (inner[i].isMiddle) {
hadMiddle = true;
} else {
innerHeight = Math.max(inner[i].height, innerHeight);
innerDepth = Math.max(inner[i].depth, innerDepth);
}
}
// The size of delimiters is the same, regardless of what style we are
// in. Thus, to correctly calculate the size of delimiter we need around
// a group, we scale down the inner size based on the size.
innerHeight *= options.sizeMultiplier;
innerDepth *= options.sizeMultiplier;
let leftDelim;
if (group.left === ".") {
// Empty delimiters in \left and \right make null delimiter spaces.
leftDelim = html.makeNullDelimiter(options, ["mopen"]);
} else {
// Otherwise, use leftRightDelim to generate the correct sized
// delimiter.
leftDelim = delimiter.leftRightDelim(
group.left, innerHeight, innerDepth, options,
group.mode, ["mopen"]);
}
// Add it to the beginning of the expression
inner.unshift(leftDelim);
// Handle middle delimiters
if (hadMiddle) {
for (let i = 1; i < inner.length; i++) {
const middleDelim = inner[i];
// Property `isMiddle` not defined on `span`. See comment in
// "middle"'s htmlBuilder.
// $FlowFixMe
const isMiddle: IsMiddle = middleDelim.isMiddle;
if (isMiddle) {
// Apply the options that were active when \middle was called
inner[i] = delimiter.leftRightDelim(
isMiddle.delim, innerHeight, innerDepth,
isMiddle.options, group.mode, []);
}
}
}
let rightDelim;
// Same for the right delimiter, but using color specified by \color
if (group.right === ".") {
rightDelim = html.makeNullDelimiter(options, ["mclose"]);
} else {
const colorOptions = group.rightColor ?
options.withColor(group.rightColor) : options;
rightDelim = delimiter.leftRightDelim(
group.right, innerHeight, innerDepth, colorOptions,
group.mode, ["mclose"]);
}
// Add it to the end of the expression.
inner.push(rightDelim);
return buildCommon.makeSpan(["minner"], inner, options);
},
mathmlBuilder: (group, options) => {
assertParsed(group);
const inner = mml.buildExpression(group.body, options);
if (group.left !== ".") {
const leftNode = new mathMLTree.MathNode(
"mo", [mml.makeText(group.left, group.mode)]);
leftNode.setAttribute("fence", "true");
inner.unshift(leftNode);
}
if (group.right !== ".") {
const rightNode = new mathMLTree.MathNode(
"mo", [mml.makeText(group.right, group.mode)]);
rightNode.setAttribute("fence", "true");
if (group.rightColor) {
rightNode.setAttribute("mathcolor", group.rightColor);
}
inner.push(rightNode);
}
return mml.makeRow(inner);
},
});
defineFunction({
type: "middle",
names: ["\\middle"],
props: {
numArgs: 1,
primitive: true,
},
handler: (context, args) => {
const delim = checkDelimiter(args[0], context);
if (!context.parser.leftrightDepth) {
throw new ParseError("\\middle without preceding \\left", delim);
}
return {
type: "middle",
mode: context.parser.mode,
delim: delim.text,
};
},
htmlBuilder: (group, options) => {
let middleDelim;
if (group.delim === ".") {
middleDelim = html.makeNullDelimiter(options, []);
} else {
middleDelim = delimiter.sizedDelim(
group.delim, 1, options,
group.mode, []);
const isMiddle: IsMiddle = {delim: group.delim, options};
// Property `isMiddle` not defined on `span`. It is only used in
// this file above.
// TODO: Fix this violation of the `span` type and possibly rename
// things since `isMiddle` sounds like a boolean, but is a struct.
// $FlowFixMe
middleDelim.isMiddle = isMiddle;
}
return middleDelim;
},
mathmlBuilder: (group, options) => {
// A Firefox \middle will stretch a character vertically only if it
// is in the fence part of the operator dictionary at:
// https://www.w3.org/TR/MathML3/appendixc.html.
// So we need to avoid U+2223 and use plain "|" instead.
const textNode = (group.delim === "\\vert" || group.delim === "|")
? mml.makeText("|", "text")
: mml.makeText(group.delim, group.mode);
const middleNode = new mathMLTree.MathNode("mo", [textNode]);
middleNode.setAttribute("fence", "true");
// MathML gives 5/18em spacing to each <mo> element.
// \middle should get delimiter spacing instead.
middleNode.setAttribute("lspace", "0.05em");
middleNode.setAttribute("rspace", "0.05em");
return middleNode;
},
});

323
node_modules/katex/src/functions/enclose.js generated vendored Normal file
View File

@@ -0,0 +1,323 @@
// @flow
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import utils from "../utils";
import stretchy from "../stretchy";
import {phasePath} from "../svgGeometry";
import {PathNode, SvgNode} from "../domTree";
import {calculateSize, makeEm} from "../units";
import {assertNodeType} from "../parseNode";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
const htmlBuilder = (group, options) => {
// \cancel, \bcancel, \xcancel, \sout, \fbox, \colorbox, \fcolorbox, \phase
// Some groups can return document fragments. Handle those by wrapping
// them in a span.
const inner = buildCommon.wrapFragment(
html.buildGroup(group.body, options), options);
const label = group.label.slice(1);
let scale = options.sizeMultiplier;
let img;
let imgShift = 0;
// In the LaTeX cancel package, line geometry is slightly different
// depending on whether the subject is wider than it is tall, or vice versa.
// We don't know the width of a group, so as a proxy, we test if
// the subject is a single character. This captures most of the
// subjects that should get the "tall" treatment.
const isSingleChar = utils.isCharacterBox(group.body);
if (label === "sout") {
img = buildCommon.makeSpan(["stretchy", "sout"]);
img.height = options.fontMetrics().defaultRuleThickness / scale;
imgShift = -0.5 * options.fontMetrics().xHeight;
} else if (label === "phase") {
// Set a couple of dimensions from the steinmetz package.
const lineWeight = calculateSize({number: 0.6, unit: "pt"}, options);
const clearance = calculateSize({number: 0.35, unit: "ex"}, options);
// Prevent size changes like \Huge from affecting line thickness
const newOptions = options.havingBaseSizing();
scale = scale / newOptions.sizeMultiplier;
const angleHeight = inner.height + inner.depth + lineWeight + clearance;
// Reserve a left pad for the angle.
inner.style.paddingLeft = makeEm(angleHeight / 2 + lineWeight);
// Create an SVG
const viewBoxHeight = Math.floor(1000 * angleHeight * scale);
const path = phasePath(viewBoxHeight);
const svgNode = new SvgNode([new PathNode("phase", path)], {
"width": "400em",
"height": makeEm(viewBoxHeight / 1000),
"viewBox": `0 0 400000 ${viewBoxHeight}`,
"preserveAspectRatio": "xMinYMin slice",
});
// Wrap it in a span with overflow: hidden.
img = buildCommon.makeSvgSpan(["hide-tail"], [svgNode], options);
img.style.height = makeEm(angleHeight);
imgShift = inner.depth + lineWeight + clearance;
} else {
// Add horizontal padding
if (/cancel/.test(label)) {
if (!isSingleChar) {
inner.classes.push("cancel-pad");
}
} else if (label === "angl") {
inner.classes.push("anglpad");
} else {
inner.classes.push("boxpad");
}
// Add vertical padding
let topPad = 0;
let bottomPad = 0;
let ruleThickness = 0;
// ref: cancel package: \advance\totalheight2\p@ % "+2"
if (/box/.test(label)) {
ruleThickness = Math.max(
options.fontMetrics().fboxrule, // default
options.minRuleThickness, // User override.
);
topPad = options.fontMetrics().fboxsep +
(label === "colorbox" ? 0 : ruleThickness);
bottomPad = topPad;
} else if (label === "angl") {
ruleThickness = Math.max(
options.fontMetrics().defaultRuleThickness,
options.minRuleThickness
);
topPad = 4 * ruleThickness; // gap = 3 × line, plus the line itself.
bottomPad = Math.max(0, 0.25 - inner.depth);
} else {
topPad = isSingleChar ? 0.2 : 0;
bottomPad = topPad;
}
img = stretchy.encloseSpan(inner, label, topPad, bottomPad, options);
if (/fbox|boxed|fcolorbox/.test(label)) {
img.style.borderStyle = "solid";
img.style.borderWidth = makeEm(ruleThickness);
} else if (label === "angl" && ruleThickness !== 0.049) {
img.style.borderTopWidth = makeEm(ruleThickness);
img.style.borderRightWidth = makeEm(ruleThickness);
}
imgShift = inner.depth + bottomPad;
if (group.backgroundColor) {
img.style.backgroundColor = group.backgroundColor;
if (group.borderColor) {
img.style.borderColor = group.borderColor;
}
}
}
let vlist;
if (group.backgroundColor) {
vlist = buildCommon.makeVList({
positionType: "individualShift",
children: [
// Put the color background behind inner;
{type: "elem", elem: img, shift: imgShift},
{type: "elem", elem: inner, shift: 0},
],
}, options);
} else {
const classes = /cancel|phase/.test(label) ? ["svg-align"] : [];
vlist = buildCommon.makeVList({
positionType: "individualShift",
children: [
// Write the \cancel stroke on top of inner.
{
type: "elem",
elem: inner,
shift: 0,
},
{
type: "elem",
elem: img,
shift: imgShift,
wrapperClasses: classes,
},
],
}, options);
}
if (/cancel/.test(label)) {
// The cancel package documentation says that cancel lines add their height
// to the expression, but tests show that isn't how it actually works.
vlist.height = inner.height;
vlist.depth = inner.depth;
}
if (/cancel/.test(label) && !isSingleChar) {
// cancel does not create horiz space for its line extension.
return buildCommon.makeSpan(["mord", "cancel-lap"], [vlist], options);
} else {
return buildCommon.makeSpan(["mord"], [vlist], options);
}
};
const mathmlBuilder = (group, options) => {
let fboxsep = 0;
const node = new mathMLTree.MathNode(
(group.label.indexOf("colorbox") > -1) ? "mpadded" : "menclose",
[mml.buildGroup(group.body, options)]
);
switch (group.label) {
case "\\cancel":
node.setAttribute("notation", "updiagonalstrike");
break;
case "\\bcancel":
node.setAttribute("notation", "downdiagonalstrike");
break;
case "\\phase":
node.setAttribute("notation", "phasorangle");
break;
case "\\sout":
node.setAttribute("notation", "horizontalstrike");
break;
case "\\fbox":
node.setAttribute("notation", "box");
break;
case "\\angl":
node.setAttribute("notation", "actuarial");
break;
case "\\fcolorbox":
case "\\colorbox":
// <menclose> doesn't have a good notation option. So use <mpadded>
// instead. Set some attributes that come included with <menclose>.
fboxsep = options.fontMetrics().fboxsep *
options.fontMetrics().ptPerEm;
node.setAttribute("width", `+${2 * fboxsep}pt`);
node.setAttribute("height", `+${2 * fboxsep}pt`);
node.setAttribute("lspace", `${fboxsep}pt`); //
node.setAttribute("voffset", `${fboxsep}pt`);
if (group.label === "\\fcolorbox") {
const thk = Math.max(
options.fontMetrics().fboxrule, // default
options.minRuleThickness, // user override
);
node.setAttribute("style", "border: " + thk + "em solid " +
String(group.borderColor));
}
break;
case "\\xcancel":
node.setAttribute("notation", "updiagonalstrike downdiagonalstrike");
break;
}
if (group.backgroundColor) {
node.setAttribute("mathbackground", group.backgroundColor);
}
return node;
};
defineFunction({
type: "enclose",
names: ["\\colorbox"],
props: {
numArgs: 2,
allowedInText: true,
argTypes: ["color", "text"],
},
handler({parser, funcName}, args, optArgs) {
const color = assertNodeType(args[0], "color-token").color;
const body = args[1];
return {
type: "enclose",
mode: parser.mode,
label: funcName,
backgroundColor: color,
body,
};
},
htmlBuilder,
mathmlBuilder,
});
defineFunction({
type: "enclose",
names: ["\\fcolorbox"],
props: {
numArgs: 3,
allowedInText: true,
argTypes: ["color", "color", "text"],
},
handler({parser, funcName}, args, optArgs) {
const borderColor = assertNodeType(args[0], "color-token").color;
const backgroundColor = assertNodeType(args[1], "color-token").color;
const body = args[2];
return {
type: "enclose",
mode: parser.mode,
label: funcName,
backgroundColor,
borderColor,
body,
};
},
htmlBuilder,
mathmlBuilder,
});
defineFunction({
type: "enclose",
names: ["\\fbox"],
props: {
numArgs: 1,
argTypes: ["hbox"],
allowedInText: true,
},
handler({parser}, args) {
return {
type: "enclose",
mode: parser.mode,
label: "\\fbox",
body: args[0],
};
},
});
defineFunction({
type: "enclose",
names: ["\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\phase"],
props: {
numArgs: 1,
},
handler({parser, funcName}, args) {
const body = args[0];
return {
type: "enclose",
mode: parser.mode,
label: funcName,
body,
};
},
htmlBuilder,
mathmlBuilder,
});
defineFunction({
type: "enclose",
names: ["\\angl"],
props: {
numArgs: 1,
argTypes: ["hbox"],
allowedInText: false,
},
handler({parser}, args) {
return {
type: "enclose",
mode: parser.mode,
label: "\\angl",
body: args[0],
};
},
});

62
node_modules/katex/src/functions/environment.js generated vendored Normal file
View File

@@ -0,0 +1,62 @@
// @flow
import defineFunction from "../defineFunction";
import ParseError from "../ParseError";
import {assertNodeType} from "../parseNode";
import environments from "../environments";
// Environment delimiters. HTML/MathML rendering is defined in the corresponding
// defineEnvironment definitions.
defineFunction({
type: "environment",
names: ["\\begin", "\\end"],
props: {
numArgs: 1,
argTypes: ["text"],
},
handler({parser, funcName}, args) {
const nameGroup = args[0];
if (nameGroup.type !== "ordgroup") {
throw new ParseError("Invalid environment name", nameGroup);
}
let envName = "";
for (let i = 0; i < nameGroup.body.length; ++i) {
envName += assertNodeType(nameGroup.body[i], "textord").text;
}
if (funcName === "\\begin") {
// begin...end is similar to left...right
if (!environments.hasOwnProperty(envName)) {
throw new ParseError(
"No such environment: " + envName, nameGroup);
}
// Build the environment object. Arguments and other information will
// be made available to the begin and end methods using properties.
const env = environments[envName];
const {args, optArgs} =
parser.parseArguments("\\begin{" + envName + "}", env);
const context = {
mode: parser.mode,
envName,
parser,
};
const result = env.handler(context, args, optArgs);
parser.expect("\\end", false);
const endNameToken = parser.nextToken;
const end = assertNodeType(parser.parseFunction(), "environment");
if (end.name !== envName) {
throw new ParseError(
`Mismatch: \\begin{${envName}} matched by \\end{${end.name}}`,
endNameToken);
}
// $FlowFixMe, "environment" handler returns an environment ParseNode
return result;
}
return {
type: "environment",
mode: parser.mode,
name: envName,
nameGroup,
};
},
});

120
node_modules/katex/src/functions/font.js generated vendored Normal file
View File

@@ -0,0 +1,120 @@
// @flow
// TODO(kevinb): implement \\sl and \\sc
import {binrelClass} from "./mclass";
import defineFunction, {normalizeArgument} from "../defineFunction";
import utils from "../utils";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import type {ParseNode} from "../parseNode";
const htmlBuilder = (group: ParseNode<"font">, options) => {
const font = group.font;
const newOptions = options.withFont(font);
return html.buildGroup(group.body, newOptions);
};
const mathmlBuilder = (group: ParseNode<"font">, options) => {
const font = group.font;
const newOptions = options.withFont(font);
return mml.buildGroup(group.body, newOptions);
};
const fontAliases = {
"\\Bbb": "\\mathbb",
"\\bold": "\\mathbf",
"\\frak": "\\mathfrak",
"\\bm": "\\boldsymbol",
};
defineFunction({
type: "font",
names: [
// styles, except \boldsymbol defined below
"\\mathrm", "\\mathit", "\\mathbf", "\\mathnormal", "\\mathsfit",
// families
"\\mathbb", "\\mathcal", "\\mathfrak", "\\mathscr", "\\mathsf",
"\\mathtt",
// aliases, except \bm defined below
"\\Bbb", "\\bold", "\\frak",
],
props: {
numArgs: 1,
allowedInArgument: true,
},
handler: ({parser, funcName}, args) => {
const body = normalizeArgument(args[0]);
let func = funcName;
if (func in fontAliases) {
func = fontAliases[func];
}
return {
type: "font",
mode: parser.mode,
font: func.slice(1),
body,
};
},
htmlBuilder,
mathmlBuilder,
});
defineFunction({
type: "mclass",
names: ["\\boldsymbol", "\\bm"],
props: {
numArgs: 1,
},
handler: ({parser}, args) => {
const body = args[0];
const isCharacterBox = utils.isCharacterBox(body);
// amsbsy.sty's \boldsymbol uses \binrel spacing to inherit the
// argument's bin|rel|ord status
return {
type: "mclass",
mode: parser.mode,
mclass: binrelClass(body),
body: [
{
type: "font",
mode: parser.mode,
font: "boldsymbol",
body,
},
],
isCharacterBox: isCharacterBox,
};
},
});
// Old font changing functions
defineFunction({
type: "font",
names: ["\\rm", "\\sf", "\\tt", "\\bf", "\\it", "\\cal"],
props: {
numArgs: 0,
allowedInText: true,
},
handler: ({parser, funcName, breakOnTokenText}, args) => {
const {mode} = parser;
const body = parser.parseExpression(true, breakOnTokenText);
const style = `math${funcName.slice(1)}`;
return {
type: "font",
mode: mode,
font: style,
body: {
type: "ordgroup",
mode: parser.mode,
body,
},
};
},
htmlBuilder,
mathmlBuilder,
});

510
node_modules/katex/src/functions/genfrac.js generated vendored Normal file
View File

@@ -0,0 +1,510 @@
// @flow
import defineFunction, {normalizeArgument} from "../defineFunction";
import buildCommon from "../buildCommon";
import delimiter from "../delimiter";
import mathMLTree from "../mathMLTree";
import Style from "../Style";
import {assertNodeType} from "../parseNode";
import {assert} from "../utils";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import {calculateSize, makeEm} from "../units";
const adjustStyle = (size, originalStyle) => {
// Figure out what style this fraction should be in based on the
// function used
let style = originalStyle;
if (size === "display") {
// Get display style as a default.
// If incoming style is sub/sup, use style.text() to get correct size.
style = style.id >= Style.SCRIPT.id ? style.text() : Style.DISPLAY;
} else if (size === "text" &&
style.size === Style.DISPLAY.size) {
// We're in a \tfrac but incoming style is displaystyle, so:
style = Style.TEXT;
} else if (size === "script") {
style = Style.SCRIPT;
} else if (size === "scriptscript") {
style = Style.SCRIPTSCRIPT;
}
return style;
};
const htmlBuilder = (group, options) => {
// Fractions are handled in the TeXbook on pages 444-445, rules 15(a-e).
const style = adjustStyle(group.size, options.style);
const nstyle = style.fracNum();
const dstyle = style.fracDen();
let newOptions;
newOptions = options.havingStyle(nstyle);
const numerm = html.buildGroup(group.numer, newOptions, options);
if (group.continued) {
// \cfrac inserts a \strut into the numerator.
// Get \strut dimensions from TeXbook page 353.
const hStrut = 8.5 / options.fontMetrics().ptPerEm;
const dStrut = 3.5 / options.fontMetrics().ptPerEm;
numerm.height = numerm.height < hStrut ? hStrut : numerm.height;
numerm.depth = numerm.depth < dStrut ? dStrut : numerm.depth;
}
newOptions = options.havingStyle(dstyle);
const denomm = html.buildGroup(group.denom, newOptions, options);
let rule;
let ruleWidth;
let ruleSpacing;
if (group.hasBarLine) {
if (group.barSize) {
ruleWidth = calculateSize(group.barSize, options);
rule = buildCommon.makeLineSpan("frac-line", options, ruleWidth);
} else {
rule = buildCommon.makeLineSpan("frac-line", options);
}
ruleWidth = rule.height;
ruleSpacing = rule.height;
} else {
rule = null;
ruleWidth = 0;
ruleSpacing = options.fontMetrics().defaultRuleThickness;
}
// Rule 15b
let numShift;
let clearance;
let denomShift;
if (style.size === Style.DISPLAY.size || group.size === "display") {
numShift = options.fontMetrics().num1;
if (ruleWidth > 0) {
clearance = 3 * ruleSpacing;
} else {
clearance = 7 * ruleSpacing;
}
denomShift = options.fontMetrics().denom1;
} else {
if (ruleWidth > 0) {
numShift = options.fontMetrics().num2;
clearance = ruleSpacing;
} else {
numShift = options.fontMetrics().num3;
clearance = 3 * ruleSpacing;
}
denomShift = options.fontMetrics().denom2;
}
let frac;
if (!rule) {
// Rule 15c
const candidateClearance =
(numShift - numerm.depth) - (denomm.height - denomShift);
if (candidateClearance < clearance) {
numShift += 0.5 * (clearance - candidateClearance);
denomShift += 0.5 * (clearance - candidateClearance);
}
frac = buildCommon.makeVList({
positionType: "individualShift",
children: [
{type: "elem", elem: denomm, shift: denomShift},
{type: "elem", elem: numerm, shift: -numShift},
],
}, options);
} else {
// Rule 15d
const axisHeight = options.fontMetrics().axisHeight;
if ((numShift - numerm.depth) - (axisHeight + 0.5 * ruleWidth) <
clearance) {
numShift +=
clearance - ((numShift - numerm.depth) -
(axisHeight + 0.5 * ruleWidth));
}
if ((axisHeight - 0.5 * ruleWidth) - (denomm.height - denomShift) <
clearance) {
denomShift +=
clearance - ((axisHeight - 0.5 * ruleWidth) -
(denomm.height - denomShift));
}
const midShift = -(axisHeight - 0.5 * ruleWidth);
frac = buildCommon.makeVList({
positionType: "individualShift",
children: [
{type: "elem", elem: denomm, shift: denomShift},
{type: "elem", elem: rule, shift: midShift},
{type: "elem", elem: numerm, shift: -numShift},
],
}, options);
}
// Since we manually change the style sometimes (with \dfrac or \tfrac),
// account for the possible size change here.
newOptions = options.havingStyle(style);
frac.height *= newOptions.sizeMultiplier / options.sizeMultiplier;
frac.depth *= newOptions.sizeMultiplier / options.sizeMultiplier;
// Rule 15e
let delimSize;
if (style.size === Style.DISPLAY.size) {
delimSize = options.fontMetrics().delim1;
} else if (style.size === Style.SCRIPTSCRIPT.size) {
delimSize = options.havingStyle(Style.SCRIPT).fontMetrics().delim2;
} else {
delimSize = options.fontMetrics().delim2;
}
let leftDelim;
let rightDelim;
if (group.leftDelim == null) {
leftDelim = html.makeNullDelimiter(options, ["mopen"]);
} else {
leftDelim = delimiter.customSizedDelim(
group.leftDelim, delimSize, true,
options.havingStyle(style), group.mode, ["mopen"]);
}
if (group.continued) {
rightDelim = buildCommon.makeSpan([]); // zero width for \cfrac
} else if (group.rightDelim == null) {
rightDelim = html.makeNullDelimiter(options, ["mclose"]);
} else {
rightDelim = delimiter.customSizedDelim(
group.rightDelim, delimSize, true,
options.havingStyle(style), group.mode, ["mclose"]);
}
return buildCommon.makeSpan(
["mord"].concat(newOptions.sizingClasses(options)),
[leftDelim, buildCommon.makeSpan(["mfrac"], [frac]), rightDelim],
options);
};
const mathmlBuilder = (group, options) => {
let node = new mathMLTree.MathNode(
"mfrac",
[
mml.buildGroup(group.numer, options),
mml.buildGroup(group.denom, options),
]);
if (!group.hasBarLine) {
node.setAttribute("linethickness", "0px");
} else if (group.barSize) {
const ruleWidth = calculateSize(group.barSize, options);
node.setAttribute("linethickness", makeEm(ruleWidth));
}
const style = adjustStyle(group.size, options.style);
if (style.size !== options.style.size) {
node = new mathMLTree.MathNode("mstyle", [node]);
const isDisplay = (style.size === Style.DISPLAY.size) ? "true" : "false";
node.setAttribute("displaystyle", isDisplay);
node.setAttribute("scriptlevel", "0");
}
if (group.leftDelim != null || group.rightDelim != null) {
const withDelims = [];
if (group.leftDelim != null) {
const leftOp = new mathMLTree.MathNode(
"mo",
[new mathMLTree.TextNode(group.leftDelim.replace("\\", ""))]
);
leftOp.setAttribute("fence", "true");
withDelims.push(leftOp);
}
withDelims.push(node);
if (group.rightDelim != null) {
const rightOp = new mathMLTree.MathNode(
"mo",
[new mathMLTree.TextNode(group.rightDelim.replace("\\", ""))]
);
rightOp.setAttribute("fence", "true");
withDelims.push(rightOp);
}
return mml.makeRow(withDelims);
}
return node;
};
defineFunction({
type: "genfrac",
names: [
"\\dfrac", "\\frac", "\\tfrac",
"\\dbinom", "\\binom", "\\tbinom",
"\\\\atopfrac", // cant be entered directly
"\\\\bracefrac", "\\\\brackfrac", // ditto
],
props: {
numArgs: 2,
allowedInArgument: true,
},
handler: ({parser, funcName}, args) => {
const numer = args[0];
const denom = args[1];
let hasBarLine;
let leftDelim = null;
let rightDelim = null;
let size = "auto";
switch (funcName) {
case "\\dfrac":
case "\\frac":
case "\\tfrac":
hasBarLine = true;
break;
case "\\\\atopfrac":
hasBarLine = false;
break;
case "\\dbinom":
case "\\binom":
case "\\tbinom":
hasBarLine = false;
leftDelim = "(";
rightDelim = ")";
break;
case "\\\\bracefrac":
hasBarLine = false;
leftDelim = "\\{";
rightDelim = "\\}";
break;
case "\\\\brackfrac":
hasBarLine = false;
leftDelim = "[";
rightDelim = "]";
break;
default:
throw new Error("Unrecognized genfrac command");
}
switch (funcName) {
case "\\dfrac":
case "\\dbinom":
size = "display";
break;
case "\\tfrac":
case "\\tbinom":
size = "text";
break;
}
return {
type: "genfrac",
mode: parser.mode,
continued: false,
numer,
denom,
hasBarLine,
leftDelim,
rightDelim,
size,
barSize: null,
};
},
htmlBuilder,
mathmlBuilder,
});
defineFunction({
type: "genfrac",
names: ["\\cfrac"],
props: {
numArgs: 2,
},
handler: ({parser, funcName}, args) => {
const numer = args[0];
const denom = args[1];
return {
type: "genfrac",
mode: parser.mode,
continued: true,
numer,
denom,
hasBarLine: true,
leftDelim: null,
rightDelim: null,
size: "display",
barSize: null,
};
},
});
// Infix generalized fractions -- these are not rendered directly, but replaced
// immediately by one of the variants above.
defineFunction({
type: "infix",
names: ["\\over", "\\choose", "\\atop", "\\brace", "\\brack"],
props: {
numArgs: 0,
infix: true,
},
handler({parser, funcName, token}) {
let replaceWith;
switch (funcName) {
case "\\over":
replaceWith = "\\frac";
break;
case "\\choose":
replaceWith = "\\binom";
break;
case "\\atop":
replaceWith = "\\\\atopfrac";
break;
case "\\brace":
replaceWith = "\\\\bracefrac";
break;
case "\\brack":
replaceWith = "\\\\brackfrac";
break;
default:
throw new Error("Unrecognized infix genfrac command");
}
return {
type: "infix",
mode: parser.mode,
replaceWith,
token,
};
},
});
const stylArray = ["display", "text", "script", "scriptscript"];
const delimFromValue = function(delimString: string): string | null {
let delim = null;
if (delimString.length > 0) {
delim = delimString;
delim = delim === "." ? null : delim;
}
return delim;
};
defineFunction({
type: "genfrac",
names: ["\\genfrac"],
props: {
numArgs: 6,
allowedInArgument: true,
argTypes: ["math", "math", "size", "text", "math", "math"],
},
handler({parser}, args) {
const numer = args[4];
const denom = args[5];
// Look into the parse nodes to get the desired delimiters.
const leftNode = normalizeArgument(args[0]);
const leftDelim = leftNode.type === "atom" && leftNode.family === "open"
? delimFromValue(leftNode.text) : null;
const rightNode = normalizeArgument(args[1]);
const rightDelim = rightNode.type === "atom" && rightNode.family === "close"
? delimFromValue(rightNode.text) : null;
const barNode = assertNodeType(args[2], "size");
let hasBarLine;
let barSize = null;
if (barNode.isBlank) {
// \genfrac acts differently than \above.
// \genfrac treats an empty size group as a signal to use a
// standard bar size. \above would see size = 0 and omit the bar.
hasBarLine = true;
} else {
barSize = barNode.value;
hasBarLine = barSize.number > 0;
}
// Find out if we want displaystyle, textstyle, etc.
let size = "auto";
let styl = args[3];
if (styl.type === "ordgroup") {
if (styl.body.length > 0) {
const textOrd = assertNodeType(styl.body[0], "textord");
size = stylArray[Number(textOrd.text)];
}
} else {
styl = assertNodeType(styl, "textord");
size = stylArray[Number(styl.text)];
}
return {
type: "genfrac",
mode: parser.mode,
numer,
denom,
continued: false,
hasBarLine,
barSize,
leftDelim,
rightDelim,
size,
};
},
htmlBuilder,
mathmlBuilder,
});
// \above is an infix fraction that also defines a fraction bar size.
defineFunction({
type: "infix",
names: ["\\above"],
props: {
numArgs: 1,
argTypes: ["size"],
infix: true,
},
handler({parser, funcName, token}, args) {
return {
type: "infix",
mode: parser.mode,
replaceWith: "\\\\abovefrac",
size: assertNodeType(args[0], "size").value,
token,
};
},
});
defineFunction({
type: "genfrac",
names: ["\\\\abovefrac"],
props: {
numArgs: 3,
argTypes: ["math", "size", "math"],
},
handler: ({parser, funcName}, args) => {
const numer = args[0];
const barSize = assert(assertNodeType(args[1], "infix").size);
const denom = args[2];
const hasBarLine = barSize.number > 0;
return {
type: "genfrac",
mode: parser.mode,
numer,
denom,
continued: false,
hasBarLine,
barSize,
leftDelim: null,
rightDelim: null,
size: "auto",
};
},
htmlBuilder,
mathmlBuilder,
});

39
node_modules/katex/src/functions/hbox.js generated vendored Normal file
View File

@@ -0,0 +1,39 @@
// @flow
import defineFunction, {ordargument} from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
// \hbox is provided for compatibility with LaTeX \vcenter.
// In LaTeX, \vcenter can act only on a box, as in
// \vcenter{\hbox{$\frac{a+b}{\dfrac{c}{d}}$}}
// This function by itself doesn't do anything but prevent a soft line break.
defineFunction({
type: "hbox",
names: ["\\hbox"],
props: {
numArgs: 1,
argTypes: ["text"],
allowedInText: true,
primitive: true,
},
handler({parser}, args) {
return {
type: "hbox",
mode: parser.mode,
body: ordargument(args[0]),
};
},
htmlBuilder(group, options) {
const elements = html.buildExpression(group.body, options, false);
return buildCommon.makeFragment(elements);
},
mathmlBuilder(group, options) {
return new mathMLTree.MathNode(
"mrow", mml.buildExpression(group.body, options)
);
},
});

137
node_modules/katex/src/functions/horizBrace.js generated vendored Normal file
View File

@@ -0,0 +1,137 @@
// @flow
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import stretchy from "../stretchy";
import Style from "../Style";
import {assertNodeType} from "../parseNode";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import type {HtmlBuilderSupSub, MathMLBuilder} from "../defineFunction";
import type {ParseNode} from "../parseNode";
// NOTE: Unlike most `htmlBuilder`s, this one handles not only "horizBrace", but
// also "supsub" since an over/underbrace can affect super/subscripting.
export const htmlBuilder: HtmlBuilderSupSub<"horizBrace"> = (grp, options) => {
const style = options.style;
// Pull out the `ParseNode<"horizBrace">` if `grp` is a "supsub" node.
let supSubGroup;
let group: ParseNode<"horizBrace">;
if (grp.type === "supsub") {
// Ref: LaTeX source2e: }}}}\limits}
// i.e. LaTeX treats the brace similar to an op and passes it
// with \limits, so we need to assign supsub style.
supSubGroup = grp.sup ?
html.buildGroup(grp.sup, options.havingStyle(style.sup()), options) :
html.buildGroup(grp.sub, options.havingStyle(style.sub()), options);
group = assertNodeType(grp.base, "horizBrace");
} else {
group = assertNodeType(grp, "horizBrace");
}
// Build the base group
const body = html.buildGroup(
group.base, options.havingBaseStyle(Style.DISPLAY));
// Create the stretchy element
const braceBody = stretchy.svgSpan(group, options);
// Generate the vlist, with the appropriate kerns ┏━━━━━━━━┓
// This first vlist contains the content and the brace: equation
let vlist;
if (group.isOver) {
vlist = buildCommon.makeVList({
positionType: "firstBaseline",
children: [
{type: "elem", elem: body},
{type: "kern", size: 0.1},
{type: "elem", elem: braceBody},
],
}, options);
// $FlowFixMe: Replace this with passing "svg-align" into makeVList.
vlist.children[0].children[0].children[1].classes.push("svg-align");
} else {
vlist = buildCommon.makeVList({
positionType: "bottom",
positionData: body.depth + 0.1 + braceBody.height,
children: [
{type: "elem", elem: braceBody},
{type: "kern", size: 0.1},
{type: "elem", elem: body},
],
}, options);
// $FlowFixMe: Replace this with passing "svg-align" into makeVList.
vlist.children[0].children[0].children[0].classes.push("svg-align");
}
if (supSubGroup) {
// To write the supsub, wrap the first vlist in another vlist:
// They can't all go in the same vlist, because the note might be
// wider than the equation. We want the equation to control the
// brace width.
// note long note long note
// ┏━━━━━━━━┓ or ┏━━━┓ not ┏━━━━━━━━━┓
// equation eqn eqn
const vSpan = buildCommon.makeSpan(
["mord", (group.isOver ? "mover" : "munder")],
[vlist], options);
if (group.isOver) {
vlist = buildCommon.makeVList({
positionType: "firstBaseline",
children: [
{type: "elem", elem: vSpan},
{type: "kern", size: 0.2},
{type: "elem", elem: supSubGroup},
],
}, options);
} else {
vlist = buildCommon.makeVList({
positionType: "bottom",
positionData: vSpan.depth + 0.2 + supSubGroup.height +
supSubGroup.depth,
children: [
{type: "elem", elem: supSubGroup},
{type: "kern", size: 0.2},
{type: "elem", elem: vSpan},
],
}, options);
}
}
return buildCommon.makeSpan(
["mord", (group.isOver ? "mover" : "munder")], [vlist], options);
};
const mathmlBuilder: MathMLBuilder<"horizBrace"> = (group, options) => {
const accentNode = stretchy.mathMLnode(group.label);
return new mathMLTree.MathNode(
(group.isOver ? "mover" : "munder"),
[mml.buildGroup(group.base, options), accentNode]
);
};
// Horizontal stretchy braces
defineFunction({
type: "horizBrace",
names: ["\\overbrace", "\\underbrace"],
props: {
numArgs: 1,
},
handler({parser, funcName}, args) {
return {
type: "horizBrace",
mode: parser.mode,
label: funcName,
isOver: /^\\over/.test(funcName),
base: args[0],
};
},
htmlBuilder,
mathmlBuilder,
});

93
node_modules/katex/src/functions/href.js generated vendored Normal file
View File

@@ -0,0 +1,93 @@
// @flow
import defineFunction, {ordargument} from "../defineFunction";
import buildCommon from "../buildCommon";
import {assertNodeType} from "../parseNode";
import {MathNode} from "../mathMLTree";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
defineFunction({
type: "href",
names: ["\\href"],
props: {
numArgs: 2,
argTypes: ["url", "original"],
allowedInText: true,
},
handler: ({parser}, args) => {
const body = args[1];
const href = assertNodeType(args[0], "url").url;
if (!parser.settings.isTrusted({
command: "\\href",
url: href,
})) {
return parser.formatUnsupportedCmd("\\href");
}
return {
type: "href",
mode: parser.mode,
href,
body: ordargument(body),
};
},
htmlBuilder: (group, options) => {
const elements = html.buildExpression(group.body, options, false);
return buildCommon.makeAnchor(group.href, [], elements, options);
},
mathmlBuilder: (group, options) => {
let math = mml.buildExpressionRow(group.body, options);
if (!(math instanceof MathNode)) {
math = new MathNode("mrow", [math]);
}
math.setAttribute("href", group.href);
return math;
},
});
defineFunction({
type: "href",
names: ["\\url"],
props: {
numArgs: 1,
argTypes: ["url"],
allowedInText: true,
},
handler: ({parser}, args) => {
const href = assertNodeType(args[0], "url").url;
if (!parser.settings.isTrusted({
command: "\\url",
url: href,
})) {
return parser.formatUnsupportedCmd("\\url");
}
const chars = [];
for (let i = 0; i < href.length; i++) {
let c = href[i];
if (c === "~") {
c = "\\textasciitilde";
}
chars.push({
type: "textord",
mode: "text",
text: c,
});
}
const body = {
type: "text",
mode: parser.mode,
font: "\\texttt",
body: chars,
};
return {
type: "href",
mode: parser.mode,
href,
body: ordargument(body),
};
},
});

102
node_modules/katex/src/functions/html.js generated vendored Normal file
View File

@@ -0,0 +1,102 @@
// @flow
import defineFunction, {ordargument} from "../defineFunction";
import buildCommon from "../buildCommon";
import {assertNodeType} from "../parseNode";
import ParseError from "../ParseError";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
defineFunction({
type: "html",
names: ["\\htmlClass", "\\htmlId", "\\htmlStyle", "\\htmlData"],
props: {
numArgs: 2,
argTypes: ["raw", "original"],
allowedInText: true,
},
handler: ({parser, funcName, token}, args) => {
const value = assertNodeType(args[0], "raw").string;
const body = args[1];
if (parser.settings.strict) {
parser.settings.reportNonstrict("htmlExtension",
"HTML extension is disabled on strict mode");
}
let trustContext;
const attributes = {};
switch (funcName) {
case "\\htmlClass":
attributes.class = value;
trustContext = {
command: "\\htmlClass",
class: value,
};
break;
case "\\htmlId":
attributes.id = value;
trustContext = {
command: "\\htmlId",
id: value,
};
break;
case "\\htmlStyle":
attributes.style = value;
trustContext = {
command: "\\htmlStyle",
style: value,
};
break;
case "\\htmlData": {
const data = value.split(",");
for (let i = 0; i < data.length; i++) {
const keyVal = data[i].split("=");
if (keyVal.length !== 2) {
throw new ParseError(
"Error parsing key-value for \\htmlData");
}
attributes["data-" + keyVal[0].trim()] = keyVal[1].trim();
}
trustContext = {
command: "\\htmlData",
attributes,
};
break;
}
default:
throw new Error("Unrecognized html command");
}
if (!parser.settings.isTrusted(trustContext)) {
return parser.formatUnsupportedCmd(funcName);
}
return {
type: "html",
mode: parser.mode,
attributes,
body: ordargument(body),
};
},
htmlBuilder: (group, options) => {
const elements = html.buildExpression(group.body, options, false);
const classes = ["enclosing"];
if (group.attributes.class) {
classes.push(...group.attributes.class.trim().split(/\s+/));
}
const span = buildCommon.makeSpan(classes, elements, options);
for (const attr in group.attributes) {
if (attr !== "class" && group.attributes.hasOwnProperty(attr)) {
span.setAttribute(attr, group.attributes[attr]);
}
}
return span;
},
mathmlBuilder: (group, options) => {
return mml.buildExpressionRow(group.body, options);
},
});

34
node_modules/katex/src/functions/htmlmathml.js generated vendored Normal file
View File

@@ -0,0 +1,34 @@
// @flow
import defineFunction, {ordargument} from "../defineFunction";
import buildCommon from "../buildCommon";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
defineFunction({
type: "htmlmathml",
names: ["\\html@mathml"],
props: {
numArgs: 2,
allowedInText: true,
},
handler: ({parser}, args) => {
return {
type: "htmlmathml",
mode: parser.mode,
html: ordargument(args[0]),
mathml: ordargument(args[1]),
};
},
htmlBuilder: (group, options) => {
const elements = html.buildExpression(
group.html,
options,
false
);
return buildCommon.makeFragment(elements);
},
mathmlBuilder: (group, options) => {
return mml.buildExpressionRow(group.mathml, options);
},
});

151
node_modules/katex/src/functions/includegraphics.js generated vendored Normal file
View File

@@ -0,0 +1,151 @@
// @flow
import defineFunction from "../defineFunction";
import type {Measurement} from "../units";
import {calculateSize, validUnit, makeEm} from "../units";
import ParseError from "../ParseError";
import {Img} from "../domTree";
import mathMLTree from "../mathMLTree";
import {assertNodeType} from "../parseNode";
import type {CssStyle} from "../domTree";
const sizeData = function(str: string): Measurement {
if (/^[-+]? *(\d+(\.\d*)?|\.\d+)$/.test(str)) {
// str is a number with no unit specified.
// default unit is bp, per graphix package.
return {number: +str, unit: "bp"};
} else {
const match = (/([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/).exec(str);
if (!match) {
throw new ParseError("Invalid size: '" + str
+ "' in \\includegraphics");
}
const data = {
number: +(match[1] + match[2]), // sign + magnitude, cast to number
unit: match[3],
};
if (!validUnit(data)) {
throw new ParseError("Invalid unit: '" + data.unit
+ "' in \\includegraphics.");
}
return data;
}
};
defineFunction({
type: "includegraphics",
names: ["\\includegraphics"],
props: {
numArgs: 1,
numOptionalArgs: 1,
argTypes: ["raw", "url"],
allowedInText: false,
},
handler: ({parser}, args, optArgs) => {
let width = {number: 0, unit: "em"};
let height = {number: 0.9, unit: "em"}; // sorta character sized.
let totalheight = {number: 0, unit: "em"};
let alt = "";
if (optArgs[0]) {
const attributeStr = assertNodeType(optArgs[0], "raw").string;
// Parser.js does not parse key/value pairs. We get a string.
const attributes = attributeStr.split(",");
for (let i = 0; i < attributes.length; i++) {
const keyVal = attributes[i].split("=");
if (keyVal.length === 2) {
const str = keyVal[1].trim();
switch (keyVal[0].trim()) {
case "alt":
alt = str;
break;
case "width":
width = sizeData(str);
break;
case "height":
height = sizeData(str);
break;
case "totalheight":
totalheight = sizeData(str);
break;
default:
throw new ParseError("Invalid key: '" + keyVal[0] +
"' in \\includegraphics.");
}
}
}
}
const src = assertNodeType(args[0], "url").url;
if (alt === "") {
// No alt given. Use the file name. Strip away the path.
alt = src;
alt = alt.replace(/^.*[\\/]/, '');
alt = alt.substring(0, alt.lastIndexOf('.'));
}
if (!parser.settings.isTrusted({
command: "\\includegraphics",
url: src,
})) {
return parser.formatUnsupportedCmd("\\includegraphics");
}
return {
type: "includegraphics",
mode: parser.mode,
alt: alt,
width: width,
height: height,
totalheight: totalheight,
src: src,
};
},
htmlBuilder: (group, options) => {
const height = calculateSize(group.height, options);
let depth = 0;
if (group.totalheight.number > 0) {
depth = calculateSize(group.totalheight, options) - height;
}
let width = 0;
if (group.width.number > 0) {
width = calculateSize(group.width, options);
}
const style: CssStyle = {height: makeEm(height + depth)};
if (width > 0) {
style.width = makeEm(width);
}
if (depth > 0) {
style.verticalAlign = makeEm(-depth);
}
const node = new Img(group.src, group.alt, style);
node.height = height;
node.depth = depth;
return node;
},
mathmlBuilder: (group, options) => {
const node = new mathMLTree.MathNode("mglyph", []);
node.setAttribute("alt", group.alt);
const height = calculateSize(group.height, options);
let depth = 0;
if (group.totalheight.number > 0) {
depth = calculateSize(group.totalheight, options) - height;
node.setAttribute("valign", makeEm(-depth));
}
node.setAttribute("height", makeEm(height + depth));
if (group.width.number > 0) {
const width = calculateSize(group.width, options);
node.setAttribute("width", makeEm(width));
}
node.setAttribute("src", group.src);
return node;
},
});

56
node_modules/katex/src/functions/kern.js generated vendored Normal file
View File

@@ -0,0 +1,56 @@
//@flow
// Horizontal spacing commands
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import {calculateSize} from "../units";
import {assertNodeType} from "../parseNode";
// TODO: \hskip and \mskip should support plus and minus in lengths
defineFunction({
type: "kern",
names: ["\\kern", "\\mkern", "\\hskip", "\\mskip"],
props: {
numArgs: 1,
argTypes: ["size"],
primitive: true,
allowedInText: true,
},
handler({parser, funcName}, args) {
const size = assertNodeType(args[0], "size");
if (parser.settings.strict) {
const mathFunction = (funcName[1] === 'm'); // \mkern, \mskip
const muUnit = (size.value.unit === 'mu');
if (mathFunction) {
if (!muUnit) {
parser.settings.reportNonstrict("mathVsTextUnits",
`LaTeX's ${funcName} supports only mu units, ` +
`not ${size.value.unit} units`);
}
if (parser.mode !== "math") {
parser.settings.reportNonstrict("mathVsTextUnits",
`LaTeX's ${funcName} works only in math mode`);
}
} else { // !mathFunction
if (muUnit) {
parser.settings.reportNonstrict("mathVsTextUnits",
`LaTeX's ${funcName} doesn't support mu units`);
}
}
}
return {
type: "kern",
mode: parser.mode,
dimension: size.value,
};
},
htmlBuilder(group, options) {
return buildCommon.makeGlue(group.dimension, options);
},
mathmlBuilder(group, options) {
const dimension = calculateSize(group.dimension, options);
return new mathMLTree.SpaceNode(dimension);
},
});

74
node_modules/katex/src/functions/lap.js generated vendored Normal file
View File

@@ -0,0 +1,74 @@
// @flow
// Horizontal overlap functions
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import {makeEm} from "../units";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
defineFunction({
type: "lap",
names: ["\\mathllap", "\\mathrlap", "\\mathclap"],
props: {
numArgs: 1,
allowedInText: true,
},
handler: ({parser, funcName}, args) => {
const body = args[0];
return {
type: "lap",
mode: parser.mode,
alignment: funcName.slice(5),
body,
};
},
htmlBuilder: (group, options) => {
// mathllap, mathrlap, mathclap
let inner;
if (group.alignment === "clap") {
// ref: https://www.math.lsu.edu/~aperlis/publications/mathclap/
inner = buildCommon.makeSpan(
[], [html.buildGroup(group.body, options)]);
// wrap, since CSS will center a .clap > .inner > span
inner = buildCommon.makeSpan(["inner"], [inner], options);
} else {
inner = buildCommon.makeSpan(
["inner"], [html.buildGroup(group.body, options)]);
}
const fix = buildCommon.makeSpan(["fix"], []);
let node = buildCommon.makeSpan(
[group.alignment], [inner, fix], options);
// At this point, we have correctly set horizontal alignment of the
// two items involved in the lap.
// Next, use a strut to set the height of the HTML bounding box.
// Otherwise, a tall argument may be misplaced.
// This code resolved issue #1153
const strut = buildCommon.makeSpan(["strut"]);
strut.style.height = makeEm(node.height + node.depth);
if (node.depth) {
strut.style.verticalAlign = makeEm(-node.depth);
}
node.children.unshift(strut);
// Next, prevent vertical misplacement when next to something tall.
// This code resolves issue #1234
node = buildCommon.makeSpan(["thinbox"], [node], options);
return buildCommon.makeSpan(["mord", "vbox"], [node], options);
},
mathmlBuilder: (group, options) => {
// mathllap, mathrlap, mathclap
const node = new mathMLTree.MathNode(
"mpadded", [mml.buildGroup(group.body, options)]);
if (group.alignment !== "rlap") {
const offset = (group.alignment === "llap" ? "-1" : "-0.5");
node.setAttribute("lspace", offset + "width");
}
node.setAttribute("width", "0px");
return node;
},
});

42
node_modules/katex/src/functions/math.js generated vendored Normal file
View File

@@ -0,0 +1,42 @@
// @flow
import defineFunction from "../defineFunction";
import ParseError from "../ParseError";
// Switching from text mode back to math mode
defineFunction({
type: "styling",
names: ["\\(", "$"],
props: {
numArgs: 0,
allowedInText: true,
allowedInMath: false,
},
handler({funcName, parser}, args) {
const outerMode = parser.mode;
parser.switchMode("math");
const close = (funcName === "\\(" ? "\\)" : "$");
const body = parser.parseExpression(false, close);
parser.expect(close);
parser.switchMode(outerMode);
return {
type: "styling",
mode: parser.mode,
style: "text",
body,
};
},
});
// Check for extra closing math delimiters
defineFunction({
type: "text", // Doesn't matter what this is.
names: ["\\)", "\\]"],
props: {
numArgs: 0,
allowedInText: true,
allowedInMath: false,
},
handler(context, args) {
throw new ParseError(`Mismatched ${context.funcName}`);
},
});

51
node_modules/katex/src/functions/mathchoice.js generated vendored Normal file
View File

@@ -0,0 +1,51 @@
// @flow
import defineFunction, {ordargument} from "../defineFunction";
import buildCommon from "../buildCommon";
import Style from "../Style";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import type {ParseNode} from "../parseNode";
const chooseMathStyle = (group: ParseNode<"mathchoice">, options) => {
switch (options.style.size) {
case Style.DISPLAY.size: return group.display;
case Style.TEXT.size: return group.text;
case Style.SCRIPT.size: return group.script;
case Style.SCRIPTSCRIPT.size: return group.scriptscript;
default: return group.text;
}
};
defineFunction({
type: "mathchoice",
names: ["\\mathchoice"],
props: {
numArgs: 4,
primitive: true,
},
handler: ({parser}, args) => {
return {
type: "mathchoice",
mode: parser.mode,
display: ordargument(args[0]),
text: ordargument(args[1]),
script: ordargument(args[2]),
scriptscript: ordargument(args[3]),
};
},
htmlBuilder: (group, options) => {
const body = chooseMathStyle(group, options);
const elements = html.buildExpression(
body,
options,
false
);
return buildCommon.makeFragment(elements);
},
mathmlBuilder: (group, options) => {
const body = chooseMathStyle(group, options);
return mml.buildExpressionRow(body, options);
},
});

168
node_modules/katex/src/functions/mclass.js generated vendored Normal file
View File

@@ -0,0 +1,168 @@
// @flow
import defineFunction, {ordargument} from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import utils from "../utils";
import type {AnyParseNode} from "../parseNode";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import type {ParseNode} from "../parseNode";
const makeSpan = buildCommon.makeSpan;
function htmlBuilder(group: ParseNode<"mclass">, options) {
const elements = html.buildExpression(group.body, options, true);
return makeSpan([group.mclass], elements, options);
}
function mathmlBuilder(group: ParseNode<"mclass">, options) {
let node: mathMLTree.MathNode;
const inner = mml.buildExpression(group.body, options);
if (group.mclass === "minner") {
node = new mathMLTree.MathNode("mpadded", inner);
} else if (group.mclass === "mord") {
if (group.isCharacterBox) {
node = inner[0];
node.type = "mi";
} else {
node = new mathMLTree.MathNode("mi", inner);
}
} else {
if (group.isCharacterBox) {
node = inner[0];
node.type = "mo";
} else {
node = new mathMLTree.MathNode("mo", inner);
}
// Set spacing based on what is the most likely adjacent atom type.
// See TeXbook p170.
if (group.mclass === "mbin") {
node.attributes.lspace = "0.22em"; // medium space
node.attributes.rspace = "0.22em";
} else if (group.mclass === "mpunct") {
node.attributes.lspace = "0em";
node.attributes.rspace = "0.17em"; // thinspace
} else if (group.mclass === "mopen" || group.mclass === "mclose") {
node.attributes.lspace = "0em";
node.attributes.rspace = "0em";
} else if (group.mclass === "minner") {
node.attributes.lspace = "0.0556em"; // 1 mu is the most likely option
node.attributes.width = "+0.1111em";
}
// MathML <mo> default space is 5/18 em, so <mrel> needs no action.
// Ref: https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mo
}
return node;
}
// Math class commands except \mathop
defineFunction({
type: "mclass",
names: [
"\\mathord", "\\mathbin", "\\mathrel", "\\mathopen",
"\\mathclose", "\\mathpunct", "\\mathinner",
],
props: {
numArgs: 1,
primitive: true,
},
handler({parser, funcName}, args) {
const body = args[0];
return {
type: "mclass",
mode: parser.mode,
mclass: "m" + funcName.slice(5), // TODO(kevinb): don't prefix with 'm'
body: ordargument(body),
isCharacterBox: utils.isCharacterBox(body),
};
},
htmlBuilder,
mathmlBuilder,
});
export const binrelClass = (arg: AnyParseNode): string => {
// \binrel@ spacing varies with (bin|rel|ord) of the atom in the argument.
// (by rendering separately and with {}s before and after, and measuring
// the change in spacing). We'll do roughly the same by detecting the
// atom type directly.
const atom = (arg.type === "ordgroup" && arg.body.length ? arg.body[0] : arg);
if (atom.type === "atom" && (atom.family === "bin" || atom.family === "rel")) {
return "m" + atom.family;
} else {
return "mord";
}
};
// \@binrel{x}{y} renders like y but as mbin/mrel/mord if x is mbin/mrel/mord.
// This is equivalent to \binrel@{x}\binrel@@{y} in AMSTeX.
defineFunction({
type: "mclass",
names: ["\\@binrel"],
props: {
numArgs: 2,
},
handler({parser}, args) {
return {
type: "mclass",
mode: parser.mode,
mclass: binrelClass(args[0]),
body: ordargument(args[1]),
isCharacterBox: utils.isCharacterBox(args[1]),
};
},
});
// Build a relation or stacked op by placing one symbol on top of another
defineFunction({
type: "mclass",
names: ["\\stackrel", "\\overset", "\\underset"],
props: {
numArgs: 2,
},
handler({parser, funcName}, args) {
const baseArg = args[1];
const shiftedArg = args[0];
let mclass;
if (funcName !== "\\stackrel") {
// LaTeX applies \binrel spacing to \overset and \underset.
mclass = binrelClass(baseArg);
} else {
mclass = "mrel"; // for \stackrel
}
const baseOp = {
type: "op",
mode: baseArg.mode,
limits: true,
alwaysHandleSupSub: true,
parentIsSupSub: false,
symbol: false,
suppressBaseShift: funcName !== "\\stackrel",
body: ordargument(baseArg),
};
const supsub = {
type: "supsub",
mode: shiftedArg.mode,
base: baseOp,
sup: funcName === "\\underset" ? null : shiftedArg,
sub: funcName === "\\underset" ? shiftedArg : null,
};
return {
type: "mclass",
mode: parser.mode,
mclass,
body: [supsub],
isCharacterBox: utils.isCharacterBox(supsub),
};
},
htmlBuilder,
mathmlBuilder,
});

334
node_modules/katex/src/functions/op.js generated vendored Normal file
View File

@@ -0,0 +1,334 @@
// @flow
// Limits, symbols
import defineFunction, {ordargument} from "../defineFunction";
import buildCommon from "../buildCommon";
import {SymbolNode} from "../domTree";
import * as mathMLTree from "../mathMLTree";
import utils from "../utils";
import Style from "../Style";
import {assembleSupSub} from "./utils/assembleSupSub";
import {assertNodeType} from "../parseNode";
import {makeEm} from "../units";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import type {HtmlBuilderSupSub, MathMLBuilder} from "../defineFunction";
import type {ParseNode} from "../parseNode";
// Most operators have a large successor symbol, but these don't.
const noSuccessor = [
"\\smallint",
];
// NOTE: Unlike most `htmlBuilder`s, this one handles not only "op", but also
// "supsub" since some of them (like \int) can affect super/subscripting.
export const htmlBuilder: HtmlBuilderSupSub<"op"> = (grp, options) => {
// Operators are handled in the TeXbook pg. 443-444, rule 13(a).
let supGroup;
let subGroup;
let hasLimits = false;
let group: ParseNode<"op">;
if (grp.type === "supsub") {
// If we have limits, supsub will pass us its group to handle. Pull
// out the superscript and subscript and set the group to the op in
// its base.
supGroup = grp.sup;
subGroup = grp.sub;
group = assertNodeType(grp.base, "op");
hasLimits = true;
} else {
group = assertNodeType(grp, "op");
}
const style = options.style;
let large = false;
if (style.size === Style.DISPLAY.size &&
group.symbol &&
!utils.contains(noSuccessor, group.name)) {
// Most symbol operators get larger in displaystyle (rule 13)
large = true;
}
let base;
if (group.symbol) {
// If this is a symbol, create the symbol.
const fontName = large ? "Size2-Regular" : "Size1-Regular";
let stash = "";
if (group.name === "\\oiint" || group.name === "\\oiiint") {
// No font glyphs yet, so use a glyph w/o the oval.
// TODO: When font glyphs are available, delete this code.
stash = group.name.slice(1);
group.name = stash === "oiint" ? "\\iint" : "\\iiint";
}
base = buildCommon.makeSymbol(
group.name, fontName, "math", options,
["mop", "op-symbol", large ? "large-op" : "small-op"]);
if (stash.length > 0) {
// We're in \oiint or \oiiint. Overlay the oval.
// TODO: When font glyphs are available, delete this code.
const italic = base.italic;
const oval = buildCommon.staticSvg(stash + "Size"
+ (large ? "2" : "1"), options);
base = buildCommon.makeVList({
positionType: "individualShift",
children: [
{type: "elem", elem: base, shift: 0},
{type: "elem", elem: oval, shift: large ? 0.08 : 0},
],
}, options);
group.name = "\\" + stash;
base.classes.unshift("mop");
// $FlowFixMe
base.italic = italic;
}
} else if (group.body) {
// If this is a list, compose that list.
const inner = html.buildExpression(group.body, options, true);
if (inner.length === 1 && inner[0] instanceof SymbolNode) {
base = inner[0];
base.classes[0] = "mop"; // replace old mclass
} else {
base = buildCommon.makeSpan(["mop"], inner, options);
}
} else {
// Otherwise, this is a text operator. Build the text from the
// operator's name.
const output = [];
for (let i = 1; i < group.name.length; i++) {
output.push(buildCommon.mathsym(group.name[i], group.mode, options));
}
base = buildCommon.makeSpan(["mop"], output, options);
}
// If content of op is a single symbol, shift it vertically.
let baseShift = 0;
let slant = 0;
if ((base instanceof SymbolNode
|| group.name === "\\oiint" || group.name === "\\oiiint")
&& !group.suppressBaseShift) {
// We suppress the shift of the base of \overset and \underset. Otherwise,
// shift the symbol so its center lies on the axis (rule 13). It
// appears that our fonts have the centers of the symbols already
// almost on the axis, so these numbers are very small. Note we
// don't actually apply this here, but instead it is used either in
// the vlist creation or separately when there are no limits.
baseShift = (base.height - base.depth) / 2 -
options.fontMetrics().axisHeight;
// The slant of the symbol is just its italic correction.
// $FlowFixMe
slant = base.italic;
}
if (hasLimits) {
return assembleSupSub(base, supGroup, subGroup, options,
style, slant, baseShift);
} else {
if (baseShift) {
base.style.position = "relative";
base.style.top = makeEm(baseShift);
}
return base;
}
};
const mathmlBuilder: MathMLBuilder<"op"> = (group, options) => {
let node;
if (group.symbol) {
// This is a symbol. Just add the symbol.
node = new mathMLTree.MathNode(
"mo", [mml.makeText(group.name, group.mode)]);
if (utils.contains(noSuccessor, group.name)) {
node.setAttribute("largeop", "false");
}
} else if (group.body) {
// This is an operator with children. Add them.
node = new mathMLTree.MathNode(
"mo", mml.buildExpression(group.body, options));
} else {
// This is a text operator. Add all of the characters from the
// operator's name.
node = new mathMLTree.MathNode(
"mi", [new mathMLTree.TextNode(group.name.slice(1))]);
// Append an <mo>&ApplyFunction;</mo>.
// ref: https://www.w3.org/TR/REC-MathML/chap3_2.html#sec3.2.4
const operator = new mathMLTree.MathNode("mo",
[mml.makeText("\u2061", "text")]);
if (group.parentIsSupSub) {
node = new mathMLTree.MathNode("mrow", [node, operator]);
} else {
node = mathMLTree.newDocumentFragment([node, operator]);
}
}
return node;
};
const singleCharBigOps: {[string]: string} = {
"\u220F": "\\prod",
"\u2210": "\\coprod",
"\u2211": "\\sum",
"\u22c0": "\\bigwedge",
"\u22c1": "\\bigvee",
"\u22c2": "\\bigcap",
"\u22c3": "\\bigcup",
"\u2a00": "\\bigodot",
"\u2a01": "\\bigoplus",
"\u2a02": "\\bigotimes",
"\u2a04": "\\biguplus",
"\u2a06": "\\bigsqcup",
};
defineFunction({
type: "op",
names: [
"\\coprod", "\\bigvee", "\\bigwedge", "\\biguplus", "\\bigcap",
"\\bigcup", "\\intop", "\\prod", "\\sum", "\\bigotimes",
"\\bigoplus", "\\bigodot", "\\bigsqcup", "\\smallint", "\u220F",
"\u2210", "\u2211", "\u22c0", "\u22c1", "\u22c2", "\u22c3", "\u2a00",
"\u2a01", "\u2a02", "\u2a04", "\u2a06",
],
props: {
numArgs: 0,
},
handler: ({parser, funcName}, args) => {
let fName = funcName;
if (fName.length === 1) {
fName = singleCharBigOps[fName];
}
return {
type: "op",
mode: parser.mode,
limits: true,
parentIsSupSub: false,
symbol: true,
name: fName,
};
},
htmlBuilder,
mathmlBuilder,
});
// Note: calling defineFunction with a type that's already been defined only
// works because the same htmlBuilder and mathmlBuilder are being used.
defineFunction({
type: "op",
names: ["\\mathop"],
props: {
numArgs: 1,
primitive: true,
},
handler: ({parser}, args) => {
const body = args[0];
return {
type: "op",
mode: parser.mode,
limits: false,
parentIsSupSub: false,
symbol: false,
body: ordargument(body),
};
},
htmlBuilder,
mathmlBuilder,
});
// There are 2 flags for operators; whether they produce limits in
// displaystyle, and whether they are symbols and should grow in
// displaystyle. These four groups cover the four possible choices.
const singleCharIntegrals: {[string]: string} = {
"\u222b": "\\int",
"\u222c": "\\iint",
"\u222d": "\\iiint",
"\u222e": "\\oint",
"\u222f": "\\oiint",
"\u2230": "\\oiiint",
};
// No limits, not symbols
defineFunction({
type: "op",
names: [
"\\arcsin", "\\arccos", "\\arctan", "\\arctg", "\\arcctg",
"\\arg", "\\ch", "\\cos", "\\cosec", "\\cosh", "\\cot", "\\cotg",
"\\coth", "\\csc", "\\ctg", "\\cth", "\\deg", "\\dim", "\\exp",
"\\hom", "\\ker", "\\lg", "\\ln", "\\log", "\\sec", "\\sin",
"\\sinh", "\\sh", "\\tan", "\\tanh", "\\tg", "\\th",
],
props: {
numArgs: 0,
},
handler({parser, funcName}) {
return {
type: "op",
mode: parser.mode,
limits: false,
parentIsSupSub: false,
symbol: false,
name: funcName,
};
},
htmlBuilder,
mathmlBuilder,
});
// Limits, not symbols
defineFunction({
type: "op",
names: [
"\\det", "\\gcd", "\\inf", "\\lim", "\\max", "\\min", "\\Pr", "\\sup",
],
props: {
numArgs: 0,
},
handler({parser, funcName}) {
return {
type: "op",
mode: parser.mode,
limits: true,
parentIsSupSub: false,
symbol: false,
name: funcName,
};
},
htmlBuilder,
mathmlBuilder,
});
// No limits, symbols
defineFunction({
type: "op",
names: [
"\\int", "\\iint", "\\iiint", "\\oint", "\\oiint", "\\oiiint",
"\u222b", "\u222c", "\u222d", "\u222e", "\u222f", "\u2230",
],
props: {
numArgs: 0,
},
handler({parser, funcName}) {
let fName = funcName;
if (fName.length === 1) {
fName = singleCharIntegrals[fName];
}
return {
type: "op",
mode: parser.mode,
limits: false,
parentIsSupSub: false,
symbol: true,
name: fName,
};
},
htmlBuilder,
mathmlBuilder,
});

164
node_modules/katex/src/functions/operatorname.js generated vendored Normal file
View File

@@ -0,0 +1,164 @@
// @flow
import defineFunction, {ordargument} from "../defineFunction";
import defineMacro from "../defineMacro";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import {SymbolNode} from "../domTree";
import {assembleSupSub} from "./utils/assembleSupSub";
import {assertNodeType} from "../parseNode";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import type {HtmlBuilderSupSub, MathMLBuilder} from "../defineFunction";
import type {ParseNode} from "../parseNode";
// NOTE: Unlike most `htmlBuilder`s, this one handles not only
// "operatorname", but also "supsub" since \operatorname* can
// affect super/subscripting.
export const htmlBuilder: HtmlBuilderSupSub<"operatorname"> = (grp, options) => {
// Operators are handled in the TeXbook pg. 443-444, rule 13(a).
let supGroup;
let subGroup;
let hasLimits = false;
let group: ParseNode<"operatorname">;
if (grp.type === "supsub") {
// If we have limits, supsub will pass us its group to handle. Pull
// out the superscript and subscript and set the group to the op in
// its base.
supGroup = grp.sup;
subGroup = grp.sub;
group = assertNodeType(grp.base, "operatorname");
hasLimits = true;
} else {
group = assertNodeType(grp, "operatorname");
}
let base;
if (group.body.length > 0) {
const body = group.body.map(child => {
// $FlowFixMe: Check if the node has a string `text` property.
const childText = child.text;
if (typeof childText === "string") {
return {
type: "textord",
mode: child.mode,
text: childText,
};
} else {
return child;
}
});
// Consolidate function names into symbol characters.
const expression = html.buildExpression(
body, options.withFont("mathrm"), true);
for (let i = 0; i < expression.length; i++) {
const child = expression[i];
if (child instanceof SymbolNode) {
// Per amsopn package,
// change minus to hyphen and \ast to asterisk
child.text = child.text.replace(/\u2212/, "-")
.replace(/\u2217/, "*");
}
}
base = buildCommon.makeSpan(["mop"], expression, options);
} else {
base = buildCommon.makeSpan(["mop"], [], options);
}
if (hasLimits) {
return assembleSupSub(base, supGroup, subGroup, options,
options.style, 0, 0);
} else {
return base;
}
};
const mathmlBuilder: MathMLBuilder<"operatorname"> = (group, options) => {
// The steps taken here are similar to the html version.
let expression = mml.buildExpression(
group.body, options.withFont("mathrm"));
// Is expression a string or has it something like a fraction?
let isAllString = true; // default
for (let i = 0; i < expression.length; i++) {
const node = expression[i];
if (node instanceof mathMLTree.SpaceNode) {
// Do nothing
} else if (node instanceof mathMLTree.MathNode) {
switch (node.type) {
case "mi":
case "mn":
case "ms":
case "mspace":
case "mtext":
break; // Do nothing yet.
case "mo": {
const child = node.children[0];
if (node.children.length === 1 &&
child instanceof mathMLTree.TextNode) {
child.text =
child.text.replace(/\u2212/, "-")
.replace(/\u2217/, "*");
} else {
isAllString = false;
}
break;
}
default:
isAllString = false;
}
} else {
isAllString = false;
}
}
if (isAllString) {
// Write a single TextNode instead of multiple nested tags.
const word = expression.map(node => node.toText()).join("");
expression = [new mathMLTree.TextNode(word)];
}
const identifier = new mathMLTree.MathNode("mi", expression);
identifier.setAttribute("mathvariant", "normal");
// \u2061 is the same as &ApplyFunction;
// ref: https://www.w3schools.com/charsets/ref_html_entities_a.asp
const operator = new mathMLTree.MathNode("mo",
[mml.makeText("\u2061", "text")]);
if (group.parentIsSupSub) {
return new mathMLTree.MathNode("mrow", [identifier, operator]);
} else {
return mathMLTree.newDocumentFragment([identifier, operator]);
}
};
// \operatorname
// amsopn.dtx: \mathop{#1\kern\z@\operator@font#3}\newmcodes@
defineFunction({
type: "operatorname",
names: ["\\operatorname@", "\\operatornamewithlimits"],
props: {
numArgs: 1,
},
handler: ({parser, funcName}, args) => {
const body = args[0];
return {
type: "operatorname",
mode: parser.mode,
body: ordargument(body),
alwaysHandleSupSub: (funcName === "\\operatornamewithlimits"),
limits: false,
parentIsSupSub: false,
};
},
htmlBuilder,
mathmlBuilder,
});
defineMacro("\\operatorname",
"\\@ifstar\\operatornamewithlimits\\operatorname@");

22
node_modules/katex/src/functions/ordgroup.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
// @flow
import {defineFunctionBuilders} from "../defineFunction";
import buildCommon from "../buildCommon";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
defineFunctionBuilders({
type: "ordgroup",
htmlBuilder(group, options) {
if (group.semisimple) {
return buildCommon.makeFragment(
html.buildExpression(group.body, options, false));
}
return buildCommon.makeSpan(
["mord"], html.buildExpression(group.body, options, true), options);
},
mathmlBuilder(group, options) {
return mml.buildExpressionRow(group.body, options, true);
},
});

59
node_modules/katex/src/functions/overline.js generated vendored Normal file
View File

@@ -0,0 +1,59 @@
// @flow
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
defineFunction({
type: "overline",
names: ["\\overline"],
props: {
numArgs: 1,
},
handler({parser}, args) {
const body = args[0];
return {
type: "overline",
mode: parser.mode,
body,
};
},
htmlBuilder(group, options) {
// Overlines are handled in the TeXbook pg 443, Rule 9.
// Build the inner group in the cramped style.
const innerGroup = html.buildGroup(group.body,
options.havingCrampedStyle());
// Create the line above the body
const line = buildCommon.makeLineSpan("overline-line", options);
// Generate the vlist, with the appropriate kerns
const defaultRuleThickness = options.fontMetrics().defaultRuleThickness;
const vlist = buildCommon.makeVList({
positionType: "firstBaseline",
children: [
{type: "elem", elem: innerGroup},
{type: "kern", size: 3 * defaultRuleThickness},
{type: "elem", elem: line},
{type: "kern", size: defaultRuleThickness},
],
}, options);
return buildCommon.makeSpan(["mord", "overline"], [vlist], options);
},
mathmlBuilder(group, options) {
const operator = new mathMLTree.MathNode(
"mo", [new mathMLTree.TextNode("\u203e")]);
operator.setAttribute("stretchy", "true");
const node = new mathMLTree.MathNode(
"mover",
[mml.buildGroup(group.body, options), operator]);
node.setAttribute("accent", "true");
return node;
},
});

117
node_modules/katex/src/functions/phantom.js generated vendored Normal file
View File

@@ -0,0 +1,117 @@
// @flow
import defineFunction, {ordargument} from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
defineFunction({
type: "phantom",
names: ["\\phantom"],
props: {
numArgs: 1,
allowedInText: true,
},
handler: ({parser}, args) => {
const body = args[0];
return {
type: "phantom",
mode: parser.mode,
body: ordargument(body),
};
},
htmlBuilder: (group, options) => {
const elements = html.buildExpression(
group.body,
options.withPhantom(),
false
);
// \phantom isn't supposed to affect the elements it contains.
// See "color" for more details.
return buildCommon.makeFragment(elements);
},
mathmlBuilder: (group, options) => {
const inner = mml.buildExpression(group.body, options);
return new mathMLTree.MathNode("mphantom", inner);
},
});
defineFunction({
type: "hphantom",
names: ["\\hphantom"],
props: {
numArgs: 1,
allowedInText: true,
},
handler: ({parser}, args) => {
const body = args[0];
return {
type: "hphantom",
mode: parser.mode,
body,
};
},
htmlBuilder: (group, options) => {
let node = buildCommon.makeSpan(
[], [html.buildGroup(group.body, options.withPhantom())]);
node.height = 0;
node.depth = 0;
if (node.children) {
for (let i = 0; i < node.children.length; i++) {
node.children[i].height = 0;
node.children[i].depth = 0;
}
}
// See smash for comment re: use of makeVList
node = buildCommon.makeVList({
positionType: "firstBaseline",
children: [{type: "elem", elem: node}],
}, options);
// For spacing, TeX treats \smash as a math group (same spacing as ord).
return buildCommon.makeSpan(["mord"], [node], options);
},
mathmlBuilder: (group, options) => {
const inner = mml.buildExpression(ordargument(group.body), options);
const phantom = new mathMLTree.MathNode("mphantom", inner);
const node = new mathMLTree.MathNode("mpadded", [phantom]);
node.setAttribute("height", "0px");
node.setAttribute("depth", "0px");
return node;
},
});
defineFunction({
type: "vphantom",
names: ["\\vphantom"],
props: {
numArgs: 1,
allowedInText: true,
},
handler: ({parser}, args) => {
const body = args[0];
return {
type: "vphantom",
mode: parser.mode,
body,
};
},
htmlBuilder: (group, options) => {
const inner = buildCommon.makeSpan(
["inner"],
[html.buildGroup(group.body, options.withPhantom())]);
const fix = buildCommon.makeSpan(["fix"], []);
return buildCommon.makeSpan(
["mord", "rlap"], [inner, fix], options);
},
mathmlBuilder: (group, options) => {
const inner = mml.buildExpression(ordargument(group.body), options);
const phantom = new mathMLTree.MathNode("mphantom", inner);
const node = new mathMLTree.MathNode("mpadded", [phantom]);
node.setAttribute("width", "0px");
return node;
},
});

44
node_modules/katex/src/functions/pmb.js generated vendored Normal file
View File

@@ -0,0 +1,44 @@
// @flow
import defineFunction, {ordargument} from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import {binrelClass} from "./mclass";
import type {ParseNode} from "../parseNode";
// \pmb is a simulation of bold font.
// The version of \pmb in ambsy.sty works by typesetting three copies
// with small offsets. We use CSS text-shadow.
// It's a hack. Not as good as a real bold font. Better than nothing.
defineFunction({
type: "pmb",
names: ["\\pmb"],
props: {
numArgs: 1,
allowedInText: true,
},
handler({parser}, args) {
return {
type: "pmb",
mode: parser.mode,
mclass: binrelClass(args[0]),
body: ordargument(args[0]),
};
},
htmlBuilder(group: ParseNode<"pmb">, options) {
const elements = html.buildExpression(group.body, options, true);
const node = buildCommon.makeSpan([group.mclass], elements, options);
node.style.textShadow = "0.02em 0.01em 0.04px";
return node;
},
mathmlBuilder(group: ParseNode<"pmb">, style) {
const inner = mml.buildExpression(group.body, style);
// Wrap with an <mstyle> element.
const node = new mathMLTree.MathNode("mstyle", inner);
node.setAttribute("style", "text-shadow: 0.02em 0.01em 0.04px");
return node;
},
});

46
node_modules/katex/src/functions/raisebox.js generated vendored Normal file
View File

@@ -0,0 +1,46 @@
// @flow
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import {assertNodeType} from "../parseNode";
import {calculateSize} from "../units";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
// Box manipulation
defineFunction({
type: "raisebox",
names: ["\\raisebox"],
props: {
numArgs: 2,
argTypes: ["size", "hbox"],
allowedInText: true,
},
handler({parser}, args) {
const amount = assertNodeType(args[0], "size").value;
const body = args[1];
return {
type: "raisebox",
mode: parser.mode,
dy: amount,
body,
};
},
htmlBuilder(group, options) {
const body = html.buildGroup(group.body, options);
const dy = calculateSize(group.dy, options);
return buildCommon.makeVList({
positionType: "shift",
positionData: -dy,
children: [{type: "elem", elem: body}],
}, options);
},
mathmlBuilder(group, options) {
const node = new mathMLTree.MathNode(
"mpadded", [mml.buildGroup(group.body, options)]);
const dy = group.dy.number + group.dy.unit;
node.setAttribute("voffset", dy);
return node;
},
});

18
node_modules/katex/src/functions/relax.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
//@flow
import defineFunction from "../defineFunction";
defineFunction({
type: "internal",
names: ["\\relax"],
props: {
numArgs: 0,
allowedInText: true,
allowedInArgument: true,
},
handler({parser}) {
return {
type: "internal",
mode: parser.mode,
};
},
});

77
node_modules/katex/src/functions/rule.js generated vendored Normal file
View File

@@ -0,0 +1,77 @@
// @flow
import buildCommon from "../buildCommon";
import defineFunction from "../defineFunction";
import mathMLTree from "../mathMLTree";
import {assertNodeType} from "../parseNode";
import {calculateSize, makeEm} from "../units";
defineFunction({
type: "rule",
names: ["\\rule"],
props: {
numArgs: 2,
numOptionalArgs: 1,
allowedInText: true,
allowedInMath: true,
argTypes: ["size", "size", "size"],
},
handler({parser}, args, optArgs) {
const shift = optArgs[0];
const width = assertNodeType(args[0], "size");
const height = assertNodeType(args[1], "size");
return {
type: "rule",
mode: parser.mode,
shift: shift && assertNodeType(shift, "size").value,
width: width.value,
height: height.value,
};
},
htmlBuilder(group, options) {
// Make an empty span for the rule
const rule = buildCommon.makeSpan(["mord", "rule"], [], options);
// Calculate the shift, width, and height of the rule, and account for units
const width = calculateSize(group.width, options);
const height = calculateSize(group.height, options);
const shift = (group.shift) ? calculateSize(group.shift, options) : 0;
// Style the rule to the right size
rule.style.borderRightWidth = makeEm(width);
rule.style.borderTopWidth = makeEm(height);
rule.style.bottom = makeEm(shift);
// Record the height and width
rule.width = width;
rule.height = height + shift;
rule.depth = -shift;
// Font size is the number large enough that the browser will
// reserve at least `absHeight` space above the baseline.
// The 1.125 factor was empirically determined
rule.maxFontSize = height * 1.125 * options.sizeMultiplier;
return rule;
},
mathmlBuilder(group, options) {
const width = calculateSize(group.width, options);
const height = calculateSize(group.height, options);
const shift = (group.shift) ? calculateSize(group.shift, options) : 0;
const color = options.color && options.getColor() || "black";
const rule = new mathMLTree.MathNode("mspace");
rule.setAttribute("mathbackground", color);
rule.setAttribute("width", makeEm(width));
rule.setAttribute("height", makeEm(height));
const wrapper = new mathMLTree.MathNode("mpadded", [rule]);
if (shift >= 0) {
wrapper.setAttribute("height", makeEm(shift));
} else {
wrapper.setAttribute("height", makeEm(shift));
wrapper.setAttribute("depth", makeEm(-shift));
}
wrapper.setAttribute("voffset", makeEm(shift));
return wrapper;
},
});

91
node_modules/katex/src/functions/sizing.js generated vendored Normal file
View File

@@ -0,0 +1,91 @@
// @flow
import buildCommon from "../buildCommon";
import defineFunction from "../defineFunction";
import mathMLTree from "../mathMLTree";
import {makeEm} from "../units";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import type Options from "../Options";
import type {AnyParseNode} from "../parseNode";
import type {HtmlBuilder} from "../defineFunction";
import type {documentFragment as HtmlDocumentFragment} from "../domTree";
export function sizingGroup(
value: AnyParseNode[],
options: Options,
baseOptions: Options,
): HtmlDocumentFragment {
const inner = html.buildExpression(value, options, false);
const multiplier = options.sizeMultiplier / baseOptions.sizeMultiplier;
// Add size-resetting classes to the inner list and set maxFontSize
// manually. Handle nested size changes.
for (let i = 0; i < inner.length; i++) {
const pos = inner[i].classes.indexOf("sizing");
if (pos < 0) {
Array.prototype.push.apply(inner[i].classes,
options.sizingClasses(baseOptions));
} else if (inner[i].classes[pos + 1] === "reset-size" + options.size) {
// This is a nested size change: e.g., inner[i] is the "b" in
// `\Huge a \small b`. Override the old size (the `reset-` class)
// but not the new size.
inner[i].classes[pos + 1] = "reset-size" + baseOptions.size;
}
inner[i].height *= multiplier;
inner[i].depth *= multiplier;
}
return buildCommon.makeFragment(inner);
}
const sizeFuncs = [
"\\tiny", "\\sixptsize", "\\scriptsize", "\\footnotesize", "\\small",
"\\normalsize", "\\large", "\\Large", "\\LARGE", "\\huge", "\\Huge",
];
export const htmlBuilder: HtmlBuilder<"sizing"> = (group, options) => {
// Handle sizing operators like \Huge. Real TeX doesn't actually allow
// these functions inside of math expressions, so we do some special
// handling.
const newOptions = options.havingSize(group.size);
return sizingGroup(group.body, newOptions, options);
};
defineFunction({
type: "sizing",
names: sizeFuncs,
props: {
numArgs: 0,
allowedInText: true,
},
handler: ({breakOnTokenText, funcName, parser}, args) => {
const body = parser.parseExpression(false, breakOnTokenText);
return {
type: "sizing",
mode: parser.mode,
// Figure out what size to use based on the list of functions above
size: sizeFuncs.indexOf(funcName) + 1,
body,
};
},
htmlBuilder,
mathmlBuilder: (group, options) => {
const newOptions = options.havingSize(group.size);
const inner = mml.buildExpression(group.body, newOptions);
const node = new mathMLTree.MathNode("mstyle", inner);
// TODO(emily): This doesn't produce the correct size for nested size
// changes, because we don't keep state of what style we're currently
// in, so we can't reset the size to normal before changing it. Now
// that we're passing an options parameter we should be able to fix
// this.
node.setAttribute("mathsize", makeEm(newOptions.sizeMultiplier));
return node;
},
});

110
node_modules/katex/src/functions/smash.js generated vendored Normal file
View File

@@ -0,0 +1,110 @@
// @flow
// smash, with optional [tb], as in AMS
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import {assertNodeType} from "../parseNode";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
defineFunction({
type: "smash",
names: ["\\smash"],
props: {
numArgs: 1,
numOptionalArgs: 1,
allowedInText: true,
},
handler: ({parser}, args, optArgs) => {
let smashHeight = false;
let smashDepth = false;
const tbArg = optArgs[0] && assertNodeType(optArgs[0], "ordgroup");
if (tbArg) {
// Optional [tb] argument is engaged.
// ref: amsmath: \renewcommand{\smash}[1][tb]{%
// def\mb@t{\ht}\def\mb@b{\dp}\def\mb@tb{\ht\z@\z@\dp}%
let letter = "";
for (let i = 0; i < tbArg.body.length; ++i) {
const node = tbArg.body[i];
// $FlowFixMe: Not every node type has a `text` property.
letter = node.text;
if (letter === "t") {
smashHeight = true;
} else if (letter === "b") {
smashDepth = true;
} else {
smashHeight = false;
smashDepth = false;
break;
}
}
} else {
smashHeight = true;
smashDepth = true;
}
const body = args[0];
return {
type: "smash",
mode: parser.mode,
body,
smashHeight,
smashDepth,
};
},
htmlBuilder: (group, options) => {
const node = buildCommon.makeSpan(
[], [html.buildGroup(group.body, options)]);
if (!group.smashHeight && !group.smashDepth) {
return node;
}
if (group.smashHeight) {
node.height = 0;
// In order to influence makeVList, we have to reset the children.
if (node.children) {
for (let i = 0; i < node.children.length; i++) {
node.children[i].height = 0;
}
}
}
if (group.smashDepth) {
node.depth = 0;
if (node.children) {
for (let i = 0; i < node.children.length; i++) {
node.children[i].depth = 0;
}
}
}
// At this point, we've reset the TeX-like height and depth values.
// But the span still has an HTML line height.
// makeVList applies "display: table-cell", which prevents the browser
// from acting on that line height. So we'll call makeVList now.
const smashedNode = buildCommon.makeVList({
positionType: "firstBaseline",
children: [{type: "elem", elem: node}],
}, options);
// For spacing, TeX treats \hphantom as a math group (same spacing as ord).
return buildCommon.makeSpan(["mord"], [smashedNode], options);
},
mathmlBuilder: (group, options) => {
const node = new mathMLTree.MathNode(
"mpadded", [mml.buildGroup(group.body, options)]);
if (group.smashHeight) {
node.setAttribute("height", "0px");
}
if (group.smashDepth) {
node.setAttribute("depth", "0px");
}
return node;
},
});

125
node_modules/katex/src/functions/sqrt.js generated vendored Normal file
View File

@@ -0,0 +1,125 @@
// @flow
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import delimiter from "../delimiter";
import Style from "../Style";
import {makeEm} from "../units";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
defineFunction({
type: "sqrt",
names: ["\\sqrt"],
props: {
numArgs: 1,
numOptionalArgs: 1,
},
handler({parser}, args, optArgs) {
const index = optArgs[0];
const body = args[0];
return {
type: "sqrt",
mode: parser.mode,
body,
index,
};
},
htmlBuilder(group, options) {
// Square roots are handled in the TeXbook pg. 443, Rule 11.
// First, we do the same steps as in overline to build the inner group
// and line
let inner = html.buildGroup(group.body, options.havingCrampedStyle());
if (inner.height === 0) {
// Render a small surd.
inner.height = options.fontMetrics().xHeight;
}
// Some groups can return document fragments. Handle those by wrapping
// them in a span.
inner = buildCommon.wrapFragment(inner, options);
// Calculate the minimum size for the \surd delimiter
const metrics = options.fontMetrics();
const theta = metrics.defaultRuleThickness;
let phi = theta;
if (options.style.id < Style.TEXT.id) {
phi = options.fontMetrics().xHeight;
}
// Calculate the clearance between the body and line
let lineClearance = theta + phi / 4;
const minDelimiterHeight = (inner.height + inner.depth +
lineClearance + theta);
// Create a sqrt SVG of the required minimum size
const {span: img, ruleWidth, advanceWidth} =
delimiter.sqrtImage(minDelimiterHeight, options);
const delimDepth = img.height - ruleWidth;
// Adjust the clearance based on the delimiter size
if (delimDepth > inner.height + inner.depth + lineClearance) {
lineClearance =
(lineClearance + delimDepth - inner.height - inner.depth) / 2;
}
// Shift the sqrt image
const imgShift = img.height - inner.height - lineClearance - ruleWidth;
inner.style.paddingLeft = makeEm(advanceWidth);
// Overlay the image and the argument.
const body = buildCommon.makeVList({
positionType: "firstBaseline",
children: [
{type: "elem", elem: inner, wrapperClasses: ["svg-align"]},
{type: "kern", size: -(inner.height + imgShift)},
{type: "elem", elem: img},
{type: "kern", size: ruleWidth},
],
}, options);
if (!group.index) {
return buildCommon.makeSpan(["mord", "sqrt"], [body], options);
} else {
// Handle the optional root index
// The index is always in scriptscript style
const newOptions = options.havingStyle(Style.SCRIPTSCRIPT);
const rootm = html.buildGroup(group.index, newOptions, options);
// The amount the index is shifted by. This is taken from the TeX
// source, in the definition of `\r@@t`.
const toShift = 0.6 * (body.height - body.depth);
// Build a VList with the superscript shifted up correctly
const rootVList = buildCommon.makeVList({
positionType: "shift",
positionData: -toShift,
children: [{type: "elem", elem: rootm}],
}, options);
// Add a class surrounding it so we can add on the appropriate
// kerning
const rootVListWrap = buildCommon.makeSpan(["root"], [rootVList]);
return buildCommon.makeSpan(["mord", "sqrt"],
[rootVListWrap, body], options);
}
},
mathmlBuilder(group, options) {
const {body, index} = group;
return index ?
new mathMLTree.MathNode(
"mroot", [
mml.buildGroup(body, options),
mml.buildGroup(index, options),
]) :
new mathMLTree.MathNode(
"msqrt", [mml.buildGroup(body, options)]);
},
});

73
node_modules/katex/src/functions/styling.js generated vendored Normal file
View File

@@ -0,0 +1,73 @@
// @flow
import defineFunction from "../defineFunction";
import mathMLTree from "../mathMLTree";
import Style from "../Style";
import {sizingGroup} from "./sizing";
import * as mml from "../buildMathML";
const styleMap = {
"display": Style.DISPLAY,
"text": Style.TEXT,
"script": Style.SCRIPT,
"scriptscript": Style.SCRIPTSCRIPT,
};
defineFunction({
type: "styling",
names: [
"\\displaystyle", "\\textstyle", "\\scriptstyle",
"\\scriptscriptstyle",
],
props: {
numArgs: 0,
allowedInText: true,
primitive: true,
},
handler({breakOnTokenText, funcName, parser}, args) {
// parse out the implicit body
const body = parser.parseExpression(true, breakOnTokenText);
// TODO: Refactor to avoid duplicating styleMap in multiple places (e.g.
// here and in buildHTML and de-dupe the enumeration of all the styles).
// $FlowFixMe: The names above exactly match the styles.
const style: StyleStr = funcName.slice(1, funcName.length - 5);
return {
type: "styling",
mode: parser.mode,
// Figure out what style to use by pulling out the style from
// the function name
style,
body,
};
},
htmlBuilder(group, options) {
// Style changes are handled in the TeXbook on pg. 442, Rule 3.
const newStyle = styleMap[group.style];
const newOptions = options.havingStyle(newStyle).withFont('');
return sizingGroup(group.body, newOptions, options);
},
mathmlBuilder(group, options) {
// Figure out what style we're changing to.
const newStyle = styleMap[group.style];
const newOptions = options.havingStyle(newStyle);
const inner = mml.buildExpression(group.body, newOptions);
const node = new mathMLTree.MathNode("mstyle", inner);
const styleAttributes = {
"display": ["0", "true"],
"text": ["0", "false"],
"script": ["1", "false"],
"scriptscript": ["2", "false"],
};
const attr = styleAttributes[group.style];
node.setAttribute("scriptlevel", attr[0]);
node.setAttribute("displaystyle", attr[1]);
return node;
},
});

267
node_modules/katex/src/functions/supsub.js generated vendored Normal file
View File

@@ -0,0 +1,267 @@
// @flow
import {defineFunctionBuilders} from "../defineFunction";
import buildCommon from "../buildCommon";
import {SymbolNode} from "../domTree";
import mathMLTree from "../mathMLTree";
import utils from "../utils";
import {makeEm} from "../units";
import Style from "../Style";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import * as accent from "./accent";
import * as horizBrace from "./horizBrace";
import * as op from "./op";
import * as operatorname from "./operatorname";
import type Options from "../Options";
import type {ParseNode} from "../parseNode";
import type {HtmlBuilder} from "../defineFunction";
import type {MathNodeType} from "../mathMLTree";
/**
* Sometimes, groups perform special rules when they have superscripts or
* subscripts attached to them. This function lets the `supsub` group know that
* Sometimes, groups perform special rules when they have superscripts or
* its inner element should handle the superscripts and subscripts instead of
* handling them itself.
*/
const htmlBuilderDelegate = function(
group: ParseNode<"supsub">,
options: Options,
): ?HtmlBuilder<*> {
const base = group.base;
if (!base) {
return null;
} else if (base.type === "op") {
// Operators handle supsubs differently when they have limits
// (e.g. `\displaystyle\sum_2^3`)
const delegate = base.limits &&
(options.style.size === Style.DISPLAY.size ||
base.alwaysHandleSupSub);
return delegate ? op.htmlBuilder : null;
} else if (base.type === "operatorname") {
const delegate = base.alwaysHandleSupSub &&
(options.style.size === Style.DISPLAY.size || base.limits);
return delegate ? operatorname.htmlBuilder : null;
} else if (base.type === "accent") {
return utils.isCharacterBox(base.base) ? accent.htmlBuilder : null;
} else if (base.type === "horizBrace") {
const isSup = !group.sub;
return isSup === base.isOver ? horizBrace.htmlBuilder : null;
} else {
return null;
}
};
// Super scripts and subscripts, whose precise placement can depend on other
// functions that precede them.
defineFunctionBuilders({
type: "supsub",
htmlBuilder(group, options) {
// Superscript and subscripts are handled in the TeXbook on page
// 445-446, rules 18(a-f).
// Here is where we defer to the inner group if it should handle
// superscripts and subscripts itself.
const builderDelegate = htmlBuilderDelegate(group, options);
if (builderDelegate) {
return builderDelegate(group, options);
}
const {base: valueBase, sup: valueSup, sub: valueSub} = group;
const base = html.buildGroup(valueBase, options);
let supm;
let subm;
const metrics = options.fontMetrics();
// Rule 18a
let supShift = 0;
let subShift = 0;
const isCharacterBox = valueBase && utils.isCharacterBox(valueBase);
if (valueSup) {
const newOptions = options.havingStyle(options.style.sup());
supm = html.buildGroup(valueSup, newOptions, options);
if (!isCharacterBox) {
supShift = base.height - newOptions.fontMetrics().supDrop
* newOptions.sizeMultiplier / options.sizeMultiplier;
}
}
if (valueSub) {
const newOptions = options.havingStyle(options.style.sub());
subm = html.buildGroup(valueSub, newOptions, options);
if (!isCharacterBox) {
subShift = base.depth + newOptions.fontMetrics().subDrop
* newOptions.sizeMultiplier / options.sizeMultiplier;
}
}
// Rule 18c
let minSupShift;
if (options.style === Style.DISPLAY) {
minSupShift = metrics.sup1;
} else if (options.style.cramped) {
minSupShift = metrics.sup3;
} else {
minSupShift = metrics.sup2;
}
// scriptspace is a font-size-independent size, so scale it
// appropriately for use as the marginRight.
const multiplier = options.sizeMultiplier;
const marginRight = makeEm((0.5 / metrics.ptPerEm) / multiplier);
let marginLeft = null;
if (subm) {
// Subscripts shouldn't be shifted by the base's italic correction.
// Account for that by shifting the subscript back the appropriate
// amount. Note we only do this when the base is a single symbol.
const isOiint =
group.base && group.base.type === "op" && group.base.name &&
(group.base.name === "\\oiint" || group.base.name === "\\oiiint");
if (base instanceof SymbolNode || isOiint) {
// $FlowFixMe
marginLeft = makeEm(-base.italic);
}
}
let supsub;
if (supm && subm) {
supShift = Math.max(
supShift, minSupShift, supm.depth + 0.25 * metrics.xHeight);
subShift = Math.max(subShift, metrics.sub2);
const ruleWidth = metrics.defaultRuleThickness;
// Rule 18e
const maxWidth = 4 * ruleWidth;
if ((supShift - supm.depth) - (subm.height - subShift) < maxWidth) {
subShift = maxWidth - (supShift - supm.depth) + subm.height;
const psi = 0.8 * metrics.xHeight - (supShift - supm.depth);
if (psi > 0) {
supShift += psi;
subShift -= psi;
}
}
const vlistElem = [
{type: "elem", elem: subm, shift: subShift, marginRight,
marginLeft},
{type: "elem", elem: supm, shift: -supShift, marginRight},
];
supsub = buildCommon.makeVList({
positionType: "individualShift",
children: vlistElem,
}, options);
} else if (subm) {
// Rule 18b
subShift = Math.max(
subShift, metrics.sub1,
subm.height - 0.8 * metrics.xHeight);
const vlistElem =
[{type: "elem", elem: subm, marginLeft, marginRight}];
supsub = buildCommon.makeVList({
positionType: "shift",
positionData: subShift,
children: vlistElem,
}, options);
} else if (supm) {
// Rule 18c, d
supShift = Math.max(supShift, minSupShift,
supm.depth + 0.25 * metrics.xHeight);
supsub = buildCommon.makeVList({
positionType: "shift",
positionData: -supShift,
children: [{type: "elem", elem: supm, marginRight}],
}, options);
} else {
throw new Error("supsub must have either sup or sub.");
}
// Wrap the supsub vlist in a span.msupsub to reset text-align.
const mclass = html.getTypeOfDomTree(base, "right") || "mord";
return buildCommon.makeSpan([mclass],
[base, buildCommon.makeSpan(["msupsub"], [supsub])],
options);
},
mathmlBuilder(group, options) {
// Is the inner group a relevant horizontal brace?
let isBrace = false;
let isOver;
let isSup;
if (group.base && group.base.type === "horizBrace") {
isSup = !!group.sup;
if (isSup === group.base.isOver) {
isBrace = true;
isOver = group.base.isOver;
}
}
if (group.base &&
(group.base.type === "op" || group.base.type === "operatorname")) {
group.base.parentIsSupSub = true;
}
const children = [mml.buildGroup(group.base, options)];
if (group.sub) {
children.push(mml.buildGroup(group.sub, options));
}
if (group.sup) {
children.push(mml.buildGroup(group.sup, options));
}
let nodeType: MathNodeType;
if (isBrace) {
nodeType = (isOver ? "mover" : "munder");
} else if (!group.sub) {
const base = group.base;
if (base && base.type === "op" && base.limits &&
(options.style === Style.DISPLAY || base.alwaysHandleSupSub)) {
nodeType = "mover";
} else if (base && base.type === "operatorname" &&
base.alwaysHandleSupSub &&
(base.limits || options.style === Style.DISPLAY)) {
nodeType = "mover";
} else {
nodeType = "msup";
}
} else if (!group.sup) {
const base = group.base;
if (base && base.type === "op" && base.limits &&
(options.style === Style.DISPLAY || base.alwaysHandleSupSub)) {
nodeType = "munder";
} else if (base && base.type === "operatorname" &&
base.alwaysHandleSupSub &&
(base.limits || options.style === Style.DISPLAY)) {
nodeType = "munder";
} else {
nodeType = "msub";
}
} else {
const base = group.base;
if (base && base.type === "op" && base.limits &&
options.style === Style.DISPLAY) {
nodeType = "munderover";
} else if (base && base.type === "operatorname" &&
base.alwaysHandleSupSub &&
(options.style === Style.DISPLAY || base.limits)) {
nodeType = "munderover";
} else {
nodeType = "msubsup";
}
}
return new mathMLTree.MathNode(nodeType, children);
},
});

34
node_modules/katex/src/functions/symbolsOp.js generated vendored Normal file
View File

@@ -0,0 +1,34 @@
// @flow
import {defineFunctionBuilders} from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import * as mml from "../buildMathML";
// Operator ParseNodes created in Parser.js from symbol Groups in src/symbols.js.
defineFunctionBuilders({
type: "atom",
htmlBuilder(group, options) {
return buildCommon.mathsym(
group.text, group.mode, options, ["m" + group.family]);
},
mathmlBuilder(group, options) {
const node = new mathMLTree.MathNode(
"mo", [mml.makeText(group.text, group.mode)]);
if (group.family === "bin") {
const variant = mml.getVariant(group, options);
if (variant === "bold-italic") {
node.setAttribute("mathvariant", variant);
}
} else if (group.family === "punct") {
node.setAttribute("separator", "true");
} else if (group.family === "open" || group.family === "close") {
// Delims built here should not stretch vertically.
// See delimsizing.js for stretchy delims.
node.setAttribute("stretchy", "false");
}
return node;
},
});

62
node_modules/katex/src/functions/symbolsOrd.js generated vendored Normal file
View File

@@ -0,0 +1,62 @@
// @flow
import {defineFunctionBuilders} from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import * as mml from "../buildMathML";
import type {ParseNode} from "../parseNode";
// "mathord" and "textord" ParseNodes created in Parser.js from symbol Groups in
// src/symbols.js.
const defaultVariant: {[string]: string} = {
"mi": "italic",
"mn": "normal",
"mtext": "normal",
};
defineFunctionBuilders({
type: "mathord",
htmlBuilder(group, options) {
return buildCommon.makeOrd(group, options, "mathord");
},
mathmlBuilder(group: ParseNode<"mathord">, options) {
const node = new mathMLTree.MathNode(
"mi",
[mml.makeText(group.text, group.mode, options)]);
const variant = mml.getVariant(group, options) || "italic";
if (variant !== defaultVariant[node.type]) {
node.setAttribute("mathvariant", variant);
}
return node;
},
});
defineFunctionBuilders({
type: "textord",
htmlBuilder(group, options) {
return buildCommon.makeOrd(group, options, "textord");
},
mathmlBuilder(group: ParseNode<"textord">, options) {
const text = mml.makeText(group.text, group.mode, options);
const variant = mml.getVariant(group, options) || "normal";
let node;
if (group.mode === 'text') {
node = new mathMLTree.MathNode("mtext", [text]);
} else if (/[0-9]/.test(group.text)) {
node = new mathMLTree.MathNode("mn", [text]);
} else if (group.text === "\\prime") {
node = new mathMLTree.MathNode("mo", [text]);
} else {
node = new mathMLTree.MathNode("mi", [text]);
}
if (variant !== defaultVariant[node.type]) {
node.setAttribute("mathvariant", variant);
}
return node;
},
});

73
node_modules/katex/src/functions/symbolsSpacing.js generated vendored Normal file
View File

@@ -0,0 +1,73 @@
// @flow
import {defineFunctionBuilders} from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import ParseError from "../ParseError";
// A map of CSS-based spacing functions to their CSS class.
const cssSpace: {[string]: string} = {
"\\nobreak": "nobreak",
"\\allowbreak": "allowbreak",
};
// A lookup table to determine whether a spacing function/symbol should be
// treated like a regular space character. If a symbol or command is a key
// in this table, then it should be a regular space character. Furthermore,
// the associated value may have a `className` specifying an extra CSS class
// to add to the created `span`.
const regularSpace: {[string]: { className?: string }} = {
" ": {},
"\\ ": {},
"~": {
className: "nobreak",
},
"\\space": {},
"\\nobreakspace": {
className: "nobreak",
},
};
// ParseNode<"spacing"> created in Parser.js from the "spacing" symbol Groups in
// src/symbols.js.
defineFunctionBuilders({
type: "spacing",
htmlBuilder(group, options) {
if (regularSpace.hasOwnProperty(group.text)) {
const className = regularSpace[group.text].className || "";
// Spaces are generated by adding an actual space. Each of these
// things has an entry in the symbols table, so these will be turned
// into appropriate outputs.
if (group.mode === "text") {
const ord = buildCommon.makeOrd(group, options, "textord");
ord.classes.push(className);
return ord;
} else {
return buildCommon.makeSpan(["mspace", className],
[buildCommon.mathsym(group.text, group.mode, options)],
options);
}
} else if (cssSpace.hasOwnProperty(group.text)) {
// Spaces based on just a CSS class.
return buildCommon.makeSpan(
["mspace", cssSpace[group.text]],
[], options);
} else {
throw new ParseError(`Unknown type of space "${group.text}"`);
}
},
mathmlBuilder(group, options) {
let node;
if (regularSpace.hasOwnProperty(group.text)) {
node = new mathMLTree.MathNode(
"mtext", [new mathMLTree.TextNode("\u00a0")]);
} else if (cssSpace.hasOwnProperty(group.text)) {
// CSS-based MathML spaces (\nobreak, \allowbreak) are ignored
return new mathMLTree.MathNode("mspace");
} else {
throw new ParseError(`Unknown type of space "${group.text}"`);
}
return node;
},
});

40
node_modules/katex/src/functions/tag.js generated vendored Normal file
View File

@@ -0,0 +1,40 @@
// @flow
import {defineFunctionBuilders} from "../defineFunction";
import mathMLTree from "../mathMLTree";
import * as mml from "../buildMathML";
const pad = () => {
const padNode = new mathMLTree.MathNode("mtd", []);
padNode.setAttribute("width", "50%");
return padNode;
};
defineFunctionBuilders({
type: "tag",
mathmlBuilder(group, options) {
const table = new mathMLTree.MathNode("mtable", [
new mathMLTree.MathNode("mtr", [
pad(),
new mathMLTree.MathNode("mtd", [
mml.buildExpressionRow(group.body, options),
]),
pad(),
new mathMLTree.MathNode("mtd", [
mml.buildExpressionRow(group.tag, options),
]),
]),
]);
table.setAttribute("width", "100%");
return table;
// TODO: Left-aligned tags.
// Currently, the group and options passed here do not contain
// enough info to set tag alignment. `leqno` is in Settings but it is
// not passed to Options. On the HTML side, leqno is
// set by a CSS class applied in buildTree.js. That would have worked
// in MathML if browsers supported <mlabeledtr>. Since they don't, we
// need to rewrite the way this function is called.
},
});

76
node_modules/katex/src/functions/text.js generated vendored Normal file
View File

@@ -0,0 +1,76 @@
// @flow
import defineFunction, {ordargument} from "../defineFunction";
import buildCommon from "../buildCommon";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
// Non-mathy text, possibly in a font
const textFontFamilies = {
"\\text": undefined, "\\textrm": "textrm", "\\textsf": "textsf",
"\\texttt": "texttt", "\\textnormal": "textrm",
};
const textFontWeights = {
"\\textbf": "textbf",
"\\textmd": "textmd",
};
const textFontShapes = {
"\\textit": "textit",
"\\textup": "textup",
};
const optionsWithFont = (group, options) => {
const font = group.font;
// Checks if the argument is a font family or a font style.
if (!font) {
return options;
} else if (textFontFamilies[font]) {
return options.withTextFontFamily(textFontFamilies[font]);
} else if (textFontWeights[font]) {
return options.withTextFontWeight(textFontWeights[font]);
} else if (font === "\\emph") {
return options.fontShape === "textit" ?
options.withTextFontShape("textup") :
options.withTextFontShape("textit");
}
return options.withTextFontShape(textFontShapes[font]);
};
defineFunction({
type: "text",
names: [
// Font families
"\\text", "\\textrm", "\\textsf", "\\texttt", "\\textnormal",
// Font weights
"\\textbf", "\\textmd",
// Font Shapes
"\\textit", "\\textup", "\\emph",
],
props: {
numArgs: 1,
argTypes: ["text"],
allowedInArgument: true,
allowedInText: true,
},
handler({parser, funcName}, args) {
const body = args[0];
return {
type: "text",
mode: parser.mode,
body: ordargument(body),
font: funcName,
};
},
htmlBuilder(group, options) {
const newOptions = optionsWithFont(group, options);
const inner = html.buildExpression(group.body, newOptions, true);
return buildCommon.makeSpan(["mord", "text"], inner, newOptions);
},
mathmlBuilder(group, options) {
const newOptions = optionsWithFont(group, options);
return mml.buildExpressionRow(group.body, newOptions);
},
});

58
node_modules/katex/src/functions/underline.js generated vendored Normal file
View File

@@ -0,0 +1,58 @@
// @flow
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
defineFunction({
type: "underline",
names: ["\\underline"],
props: {
numArgs: 1,
allowedInText: true,
},
handler({parser}, args) {
return {
type: "underline",
mode: parser.mode,
body: args[0],
};
},
htmlBuilder(group, options) {
// Underlines are handled in the TeXbook pg 443, Rule 10.
// Build the inner group.
const innerGroup = html.buildGroup(group.body, options);
// Create the line to go below the body
const line = buildCommon.makeLineSpan("underline-line", options);
// Generate the vlist, with the appropriate kerns
const defaultRuleThickness = options.fontMetrics().defaultRuleThickness;
const vlist = buildCommon.makeVList({
positionType: "top",
positionData: innerGroup.height,
children: [
{type: "kern", size: defaultRuleThickness},
{type: "elem", elem: line},
{type: "kern", size: 3 * defaultRuleThickness},
{type: "elem", elem: innerGroup},
],
}, options);
return buildCommon.makeSpan(["mord", "underline"], [vlist], options);
},
mathmlBuilder(group, options) {
const operator = new mathMLTree.MathNode(
"mo", [new mathMLTree.TextNode("\u203e")]);
operator.setAttribute("stretchy", "true");
const node = new mathMLTree.MathNode(
"munder",
[mml.buildGroup(group.body, options), operator]);
node.setAttribute("accentunder", "true");
return node;
},
});

View File

@@ -0,0 +1,120 @@
// @flow
import buildCommon from "../../buildCommon";
import * as html from "../../buildHTML";
import utils from "../../utils";
import type {StyleInterface} from "../../Style";
import type Options from "../../Options";
import type {DomSpan, SymbolNode} from "../../domTree";
import type {AnyParseNode} from "../../parseNode";
import {makeEm} from "../../units";
// For an operator with limits, assemble the base, sup, and sub into a span.
export const assembleSupSub = (
base: DomSpan | SymbolNode,
supGroup: ?AnyParseNode,
subGroup: ?AnyParseNode,
options: Options,
style: StyleInterface,
slant: number,
baseShift: number,
): DomSpan => {
base = buildCommon.makeSpan([], [base]);
const subIsSingleCharacter = subGroup && utils.isCharacterBox(subGroup);
let sub;
let sup;
// We manually have to handle the superscripts and subscripts. This,
// aside from the kern calculations, is copied from supsub.
if (supGroup) {
const elem = html.buildGroup(
supGroup, options.havingStyle(style.sup()), options);
sup = {
elem,
kern: Math.max(
options.fontMetrics().bigOpSpacing1,
options.fontMetrics().bigOpSpacing3 - elem.depth),
};
}
if (subGroup) {
const elem = html.buildGroup(
subGroup, options.havingStyle(style.sub()), options);
sub = {
elem,
kern: Math.max(
options.fontMetrics().bigOpSpacing2,
options.fontMetrics().bigOpSpacing4 - elem.height),
};
}
// Build the final group as a vlist of the possible subscript, base,
// and possible superscript.
let finalGroup;
if (sup && sub) {
const bottom = options.fontMetrics().bigOpSpacing5 +
sub.elem.height + sub.elem.depth +
sub.kern +
base.depth + baseShift;
finalGroup = buildCommon.makeVList({
positionType: "bottom",
positionData: bottom,
children: [
{type: "kern", size: options.fontMetrics().bigOpSpacing5},
{type: "elem", elem: sub.elem, marginLeft: makeEm(-slant)},
{type: "kern", size: sub.kern},
{type: "elem", elem: base},
{type: "kern", size: sup.kern},
{type: "elem", elem: sup.elem, marginLeft: makeEm(slant)},
{type: "kern", size: options.fontMetrics().bigOpSpacing5},
],
}, options);
} else if (sub) {
const top = base.height - baseShift;
// Shift the limits by the slant of the symbol. Note
// that we are supposed to shift the limits by 1/2 of the slant,
// but since we are centering the limits adding a full slant of
// margin will shift by 1/2 that.
finalGroup = buildCommon.makeVList({
positionType: "top",
positionData: top,
children: [
{type: "kern", size: options.fontMetrics().bigOpSpacing5},
{type: "elem", elem: sub.elem, marginLeft: makeEm(-slant)},
{type: "kern", size: sub.kern},
{type: "elem", elem: base},
],
}, options);
} else if (sup) {
const bottom = base.depth + baseShift;
finalGroup = buildCommon.makeVList({
positionType: "bottom",
positionData: bottom,
children: [
{type: "elem", elem: base},
{type: "kern", size: sup.kern},
{type: "elem", elem: sup.elem, marginLeft: makeEm(slant)},
{type: "kern", size: options.fontMetrics().bigOpSpacing5},
],
}, options);
} else {
// This case probably shouldn't occur (this would mean the
// supsub was sending us a group with no superscript or
// subscript) but be safe.
return base;
}
const parts = [finalGroup];
if (sub && slant !== 0 && !subIsSingleCharacter) {
// A negative margin-left was applied to the lower limit.
// Avoid an overlap by placing a spacer on the left on the group.
const spacer = buildCommon.makeSpan(["mspace"], [], options);
spacer.style.marginRight = makeEm(slant);
parts.unshift(spacer);
}
return buildCommon.makeSpan(["mop", "op-limits"], parts, options);
};

44
node_modules/katex/src/functions/vcenter.js generated vendored Normal file
View File

@@ -0,0 +1,44 @@
// @flow
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
// \vcenter: Vertically center the argument group on the math axis.
defineFunction({
type: "vcenter",
names: ["\\vcenter"],
props: {
numArgs: 1,
argTypes: ["original"], // In LaTeX, \vcenter can act only on a box.
allowedInText: false,
},
handler({parser}, args) {
return {
type: "vcenter",
mode: parser.mode,
body: args[0],
};
},
htmlBuilder(group, options) {
const body = html.buildGroup(group.body, options);
const axisHeight = options.fontMetrics().axisHeight;
const dy = 0.5 * ((body.height - axisHeight) - (body.depth + axisHeight));
return buildCommon.makeVList({
positionType: "shift",
positionData: dy,
children: [{type: "elem", elem: body}],
}, options);
},
mathmlBuilder(group, options) {
// There is no way to do this in MathML.
// Write a class as a breadcrumb in case some post-processor wants
// to perform a vcenter adjustment.
return new mathMLTree.MathNode(
"mpadded", [mml.buildGroup(group.body, options)], ["vcenter"]);
},
});

58
node_modules/katex/src/functions/verb.js generated vendored Normal file
View File

@@ -0,0 +1,58 @@
// @flow
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import ParseError from "../ParseError";
import type {ParseNode} from "../parseNode";
defineFunction({
type: "verb",
names: ["\\verb"],
props: {
numArgs: 0,
allowedInText: true,
},
handler(context, args, optArgs) {
// \verb and \verb* are dealt with directly in Parser.js.
// If we end up here, it's because of a failure to match the two delimiters
// in the regex in Lexer.js. LaTeX raises the following error when \verb is
// terminated by end of line (or file).
throw new ParseError(
"\\verb ended by end of line instead of matching delimiter");
},
htmlBuilder(group, options) {
const text = makeVerb(group);
const body = [];
// \verb enters text mode and therefore is sized like \textstyle
const newOptions = options.havingStyle(options.style.text());
for (let i = 0; i < text.length; i++) {
let c = text[i];
if (c === '~') {
c = '\\textasciitilde';
}
body.push(buildCommon.makeSymbol(c, "Typewriter-Regular",
group.mode, newOptions, ["mord", "texttt"]));
}
return buildCommon.makeSpan(
["mord", "text"].concat(newOptions.sizingClasses(options)),
buildCommon.tryCombineChars(body),
newOptions,
);
},
mathmlBuilder(group, options) {
const text = new mathMLTree.TextNode(makeVerb(group));
const node = new mathMLTree.MathNode("mtext", [text]);
node.setAttribute("mathvariant", "monospace");
return node;
},
});
/**
* Converts verb group into body string.
*
* \verb* replaces each space with an open box \u2423
* \verb replaces each space with a no-break space \xA0
*/
const makeVerb = (group: ParseNode<"verb">): string =>
group.body.replace(/ /g, group.star ? '\u2423' : '\xA0');

1033
node_modules/katex/src/macros.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

267
node_modules/katex/src/mathMLTree.js generated vendored Normal file
View File

@@ -0,0 +1,267 @@
// @flow
/**
* These objects store data about MathML nodes. This is the MathML equivalent
* of the types in domTree.js. Since MathML handles its own rendering, and
* since we're mainly using MathML to improve accessibility, we don't manage
* any of the styling state that the plain DOM nodes do.
*
* The `toNode` and `toMarkup` functions work similarly to how they do in
* domTree.js, creating namespaced DOM nodes and HTML text markup respectively.
*/
import utils from "./utils";
import {DocumentFragment} from "./tree";
import {createClass} from "./domTree";
import {makeEm} from "./units";
import type {VirtualNode} from "./tree";
/**
* MathML node types used in KaTeX. For a complete list of MathML nodes, see
* https://developer.mozilla.org/en-US/docs/Web/MathML/Element.
*/
export type MathNodeType =
"math" | "annotation" | "semantics" |
"mtext" | "mn" | "mo" | "mi" | "mspace" |
"mover" | "munder" | "munderover" | "msup" | "msub" | "msubsup" |
"mfrac" | "mroot" | "msqrt" |
"mtable" | "mtr" | "mtd" | "mlabeledtr" |
"mrow" | "menclose" |
"mstyle" | "mpadded" | "mphantom" | "mglyph";
export interface MathDomNode extends VirtualNode {
toText(): string;
}
export type documentFragment = DocumentFragment<MathDomNode>;
export function newDocumentFragment(
children: $ReadOnlyArray<MathDomNode>
): documentFragment {
return new DocumentFragment(children);
}
/**
* This node represents a general purpose MathML node of any type. The
* constructor requires the type of node to create (for example, `"mo"` or
* `"mspace"`, corresponding to `<mo>` and `<mspace>` tags).
*/
export class MathNode implements MathDomNode {
type: MathNodeType;
attributes: {[string]: string};
children: $ReadOnlyArray<MathDomNode>;
classes: string[];
constructor(
type: MathNodeType,
children?: $ReadOnlyArray<MathDomNode>,
classes?: string[]
) {
this.type = type;
this.attributes = {};
this.children = children || [];
this.classes = classes || [];
}
/**
* Sets an attribute on a MathML node. MathML depends on attributes to convey a
* semantic content, so this is used heavily.
*/
setAttribute(name: string, value: string) {
this.attributes[name] = value;
}
/**
* Gets an attribute on a MathML node.
*/
getAttribute(name: string): string {
return this.attributes[name];
}
/**
* Converts the math node into a MathML-namespaced DOM element.
*/
toNode(): Node {
const node = document.createElementNS(
"http://www.w3.org/1998/Math/MathML", this.type);
for (const attr in this.attributes) {
if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
node.setAttribute(attr, this.attributes[attr]);
}
}
if (this.classes.length > 0) {
node.className = createClass(this.classes);
}
for (let i = 0; i < this.children.length; i++) {
// Combine multiple TextNodes into one TextNode, to prevent
// screen readers from reading each as a separate word [#3995]
if (this.children[i] instanceof TextNode &&
this.children[i + 1] instanceof TextNode) {
let text = this.children[i].toText() + this.children[++i].toText();
while (this.children[i + 1] instanceof TextNode) {
text += this.children[++i].toText();
}
node.appendChild(new TextNode(text).toNode());
} else {
node.appendChild(this.children[i].toNode());
}
}
return node;
}
/**
* Converts the math node into an HTML markup string.
*/
toMarkup(): string {
let markup = "<" + this.type;
// Add the attributes
for (const attr in this.attributes) {
if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
markup += " " + attr + "=\"";
markup += utils.escape(this.attributes[attr]);
markup += "\"";
}
}
if (this.classes.length > 0) {
markup += ` class ="${utils.escape(createClass(this.classes))}"`;
}
markup += ">";
for (let i = 0; i < this.children.length; i++) {
markup += this.children[i].toMarkup();
}
markup += "</" + this.type + ">";
return markup;
}
/**
* Converts the math node into a string, similar to innerText, but escaped.
*/
toText(): string {
return this.children.map(child => child.toText()).join("");
}
}
/**
* This node represents a piece of text.
*/
export class TextNode implements MathDomNode {
text: string;
constructor(text: string) {
this.text = text;
}
/**
* Converts the text node into a DOM text node.
*/
toNode(): Node {
return document.createTextNode(this.text);
}
/**
* Converts the text node into escaped HTML markup
* (representing the text itself).
*/
toMarkup(): string {
return utils.escape(this.toText());
}
/**
* Converts the text node into a string
* (representing the text itself).
*/
toText(): string {
return this.text;
}
}
/**
* This node represents a space, but may render as <mspace.../> or as text,
* depending on the width.
*/
class SpaceNode implements MathDomNode {
width: number;
character: ?string;
/**
* Create a Space node with width given in CSS ems.
*/
constructor(width: number) {
this.width = width;
// See https://www.w3.org/TR/2000/WD-MathML2-20000328/chapter6.html
// for a table of space-like characters. We use Unicode
// representations instead of &LongNames; as it's not clear how to
// make the latter via document.createTextNode.
if (width >= 0.05555 && width <= 0.05556) {
this.character = "\u200a"; // &VeryThinSpace;
} else if (width >= 0.1666 && width <= 0.1667) {
this.character = "\u2009"; // &ThinSpace;
} else if (width >= 0.2222 && width <= 0.2223) {
this.character = "\u2005"; // &MediumSpace;
} else if (width >= 0.2777 && width <= 0.2778) {
this.character = "\u2005\u200a"; // &ThickSpace;
} else if (width >= -0.05556 && width <= -0.05555) {
this.character = "\u200a\u2063"; // &NegativeVeryThinSpace;
} else if (width >= -0.1667 && width <= -0.1666) {
this.character = "\u2009\u2063"; // &NegativeThinSpace;
} else if (width >= -0.2223 && width <= -0.2222) {
this.character = "\u205f\u2063"; // &NegativeMediumSpace;
} else if (width >= -0.2778 && width <= -0.2777) {
this.character = "\u2005\u2063"; // &NegativeThickSpace;
} else {
this.character = null;
}
}
/**
* Converts the math node into a MathML-namespaced DOM element.
*/
toNode(): Node {
if (this.character) {
return document.createTextNode(this.character);
} else {
const node = document.createElementNS(
"http://www.w3.org/1998/Math/MathML", "mspace");
node.setAttribute("width", makeEm(this.width));
return node;
}
}
/**
* Converts the math node into an HTML markup string.
*/
toMarkup(): string {
if (this.character) {
return `<mtext>${this.character}</mtext>`;
} else {
return `<mspace width="${makeEm(this.width)}"/>`;
}
}
/**
* Converts the math node into a string, similar to innerText.
*/
toText(): string {
if (this.character) {
return this.character;
} else {
return " ";
}
}
}
export default {
MathNode,
TextNode,
SpaceNode,
newDocumentFragment,
};

23
node_modules/katex/src/metrics/README.md generated vendored Normal file
View File

@@ -0,0 +1,23 @@
### How to generate new metrics
-------------------------------
There are several requirements for generating the metrics used by KaTeX.
- You need to have an installation of TeX which supports kpathsea. You can check
this by running `tex --version`, and seeing if it has a line that looks like
> kpathsea version 6.2.0
- You need the Perl module `JSON`. You can install this either from CPAN
(e.g. using the `cpan` command line tool: `cpan install JSON`)
or with your package manager.
- You need the Python module `fonttools`. You can install this either from PyPI
(using `easy_install` or `pip`: `pip install fonttools`)
or with your package manager.
Once you have these things, run the following command from the root directory:
sh ./dockers/fonts/buildMetrics.sh
which should generate new metrics and place them into `fontMetricsData.json`.
You're done!

114
node_modules/katex/src/metrics/extract_tfms.py generated vendored Executable file
View File

@@ -0,0 +1,114 @@
#!/usr/bin/env python3
import collections
import json
import parse_tfm
import subprocess
import sys
def find_font_path(font_name):
try:
font_path = subprocess.check_output(['kpsewhich', font_name])
except OSError:
raise RuntimeError("Couldn't find kpsewhich program, make sure you" +
" have TeX installed")
except subprocess.CalledProcessError:
raise RuntimeError("Couldn't find font metrics: '%s'" % font_name)
return font_path.strip()
def main():
mapping = json.load(sys.stdin)
fonts = [
'cmbsy10.tfm',
'cmbx10.tfm',
'cmbxti10.tfm',
'cmex10.tfm',
'cmmi10.tfm',
'cmmib10.tfm',
'cmr10.tfm',
'cmsy10.tfm',
'cmti10.tfm',
'msam10.tfm',
'msbm10.tfm',
'eufm10.tfm',
'cmtt10.tfm',
'rsfs10.tfm',
'cmss10.tfm',
'cmssbx10.tfm',
'cmssi10.tfm',
]
# Extracted by running `\font\a=<font>` and then `\showthe\skewchar\a` in
# TeX, where `<font>` is the name of the font listed here. The skewchar
# will be printed out in the output. If it outputs `-1`, that means there
# is no skewchar, so we use `None` here.
font_skewchar = {
'cmbsy10': None,
'cmbx10': None,
'cmbxti10': None,
'cmex10': None,
'cmmi10': 127,
'cmmib10': None,
'cmr10': None,
'cmsy10': 48,
'cmti10': None,
'msam10': None,
'msbm10': None,
'eufm10': None,
'cmtt10': None,
'rsfs10': None,
'cmss10': None,
'cmssbx10': None,
'cmssi10': None,
}
font_name_to_tfm = {}
for font_name in fonts:
font_basename = font_name.split('.')[0]
font_path = find_font_path(font_name)
font_name_to_tfm[font_basename] = parse_tfm.read_tfm_file(font_path)
families = collections.defaultdict(dict)
for family, chars in mapping.items():
for char, char_data in chars.items():
char_num = int(char)
font = char_data['font']
tex_char_num = int(char_data['char'])
yshift = float(char_data['yshift'])
if family == "Script-Regular":
tfm_char = font_name_to_tfm[font].get_char_metrics(tex_char_num,
fix_rsfs=True)
else:
tfm_char = font_name_to_tfm[font].get_char_metrics(tex_char_num)
height = round(tfm_char.height + yshift / 1000.0, 5)
depth = round(tfm_char.depth - yshift / 1000.0, 5)
italic = round(tfm_char.italic_correction, 5)
width = round(tfm_char.width, 5)
skewkern = 0.0
if (font_skewchar[font] and
font_skewchar[font] in tfm_char.kern_table):
skewkern = round(
tfm_char.kern_table[font_skewchar[font]], 5)
families[family][char_num] = {
'height': height,
'depth': depth,
'italic': italic,
'skew': skewkern,
'width': width
}
sys.stdout.write(
json.dumps(families, separators=(',', ':'), sort_keys=True))
if __name__ == '__main__':
main()

122
node_modules/katex/src/metrics/extract_ttfs.py generated vendored Executable file
View File

@@ -0,0 +1,122 @@
#!/usr/bin/env python3
from fontTools.ttLib import TTFont
import sys
import json
# map of characters to extract
metrics_to_extract = {
# Font name
"AMS-Regular": {
u"\u21e2": None, # \dashrightarrow
u"\u21e0": None, # \dashleftarrow
},
"Main-Regular": {
# Skew and italic metrics can't be easily parsed from the TTF. Instead,
# we map each character to a "base character", which is a character
# from the same font with correct italic and skew metrics. A character
# maps to None if it doesn't have a base.
#u"\u2209": None, # \notin
#u"\u2260": None, # \neq
u"\u2245": None, # \cong
u"\u2026": None, # \ldots
u"\u22ef": None, # \cdots
u"\u22f1": None, # \ddots
u"\u22ee": None, # \vdots
u"\u22ee": None, # \vdots
u"\u22a8": None, # \models
u"\u22c8": None, # \bowtie
u"\u2250": None, # \doteq
u"\u23b0": None, # \lmoustache
u"\u23b1": None, # \rmoustache
u"\u27ee": None, # \lgroup
u"\u27ef": None, # \rgroup
u"\u27f5": None, # \longleftarrow
u"\u27f8": None, # \Longleftarrow
u"\u27f6": None, # \longrightarrow
u"\u27f9": None, # \Longrightarrow
u"\u27f7": None, # \longleftrightarrow
u"\u27fa": None, # \Longleftrightarrow
u"\u21a6": None, # \mapsto
u"\u27fc": None, # \longmapsto
u"\u21a9": None, # \hookleftarrow
u"\u21aa": None, # \hookrightarrow
u"\u21cc": None, # \rightleftharpoons
},
"Main-Bold": {
u"\u2245": None, # \cong
},
"Size1-Regular": {
u"\u222c": u"\u222b", # \iint, based on \int
u"\u222d": u"\u222b", # \iiint, based on \int
},
"Size2-Regular": {
u"\u222c": u"\u222b", # \iint, based on \int
u"\u222d": u"\u222b", # \iiint, based on \int
},
}
def main():
start_json = json.load(sys.stdin)
for font in start_json:
fontInfo = TTFont("../../fonts/KaTeX_" + font + ".ttf")
glyf = fontInfo["glyf"]
widths = fontInfo.getGlyphSet()
unitsPerEm = float(fontInfo["head"].unitsPerEm)
# We keep ALL Unicode cmaps, not just fontInfo["cmap"].getcmap(3, 1).
# This is playing it extra safe, since it reports inconsistencies.
# Platform 0 is Unicode, platform 3 is Windows. For platform 3,
# encoding 1 is UCS-2 and encoding 10 is UCS-4.
cmap = [t.cmap for t in fontInfo["cmap"].tables
if (t.platformID == 0)
or (t.platformID == 3 and t.platEncID in (1, 10))]
chars = metrics_to_extract.get(font, {})
chars[u"\u0020"] = None # space
chars[u"\u00a0"] = None # nbsp
for char, base_char in chars.items():
code = ord(char)
names = set(t.get(code) for t in cmap)
if not names:
sys.stderr.write(
"Codepoint {} of font {} maps to no name\n"
.format(code, font))
continue
if len(names) != 1:
sys.stderr.write(
"Codepoint {} of font {} maps to multiple names: {}\n"
.format(code, font, ", ".join(sorted(names))))
continue
name = names.pop()
height = depth = italic = skew = width = 0
glyph = glyf[name]
if glyph.numberOfContours:
height = glyph.yMax / unitsPerEm
depth = -glyph.yMin / unitsPerEm
width = widths[name].width / unitsPerEm
if base_char:
base_char_str = str(ord(base_char))
base_metrics = start_json[font][base_char_str]
italic = base_metrics["italic"]
skew = base_metrics["skew"]
width = base_metrics["width"]
start_json[font][str(code)] = {
"height": height,
"depth": depth,
"italic": italic,
"skew": skew,
"width": width
}
sys.stdout.write(
json.dumps(start_json, separators=(',', ':'), sort_keys=True))
if __name__ == "__main__":
main()

28
node_modules/katex/src/metrics/format_json.py generated vendored Executable file
View File

@@ -0,0 +1,28 @@
#!/usr/bin/env python3
import sys
import json
props = ['depth', 'height', 'italic', 'skew']
if len(sys.argv) > 1:
if sys.argv[1] == '--width':
props.append('width')
data = json.load(sys.stdin)
sys.stdout.write(
"// This file is GENERATED by buildMetrics.sh. DO NOT MODIFY.\n")
sep = "export default {\n "
for font in sorted(data):
sys.stdout.write(sep + json.dumps(font))
sep = ": {\n "
for glyph in sorted(data[font], key=int):
sys.stdout.write(sep + json.dumps(glyph) + ": ")
values = [value if value != 0.0 else 0 for value in
[data[font][glyph][key] for key in props]]
sys.stdout.write(json.dumps(values))
sep = ",\n "
sep = ",\n },\n "
sys.stdout.write(",\n },\n};\n")

1224
node_modules/katex/src/metrics/mapping.pl generated vendored Executable file

File diff suppressed because it is too large Load Diff

211
node_modules/katex/src/metrics/parse_tfm.py generated vendored Normal file
View File

@@ -0,0 +1,211 @@
class CharInfoWord(object):
def __init__(self, word):
b1, b2, b3, b4 = (word >> 24,
(word & 0xff0000) >> 16,
(word & 0xff00) >> 8,
word & 0xff)
self.width_index = b1
self.height_index = b2 >> 4
self.depth_index = b2 & 0x0f
self.italic_index = (b3 & 0b11111100) >> 2
self.tag = b3 & 0b11
self.remainder = b4
def has_ligkern(self):
return self.tag == 1
def ligkern_start(self):
return self.remainder
class LigKernProgram(object):
def __init__(self, program):
self.program = program
def execute(self, start, next_char):
curr_instruction = start
while True:
instruction = self.program[curr_instruction]
(skip, inst_next_char, op, remainder) = instruction
if inst_next_char == next_char:
if op < 128:
# Don't worry about ligatures for now, we only need kerns
return None
else:
return 256 * (op - 128) + remainder
elif skip >= 128:
return None
else:
curr_instruction += 1 + skip
class TfmCharMetrics(object):
def __init__(self, width, height, depth, italic, kern_table):
self.width = width
self.height = height
self.depth = depth
self.italic_correction = italic
self.kern_table = kern_table
class TfmFile(object):
def __init__(self, start_char, end_char, char_info, width_table,
height_table, depth_table, italic_table, ligkern_table,
kern_table):
self.start_char = start_char
self.end_char = end_char
self.char_info = char_info
self.width_table = width_table
self.height_table = height_table
self.depth_table = depth_table
self.italic_table = italic_table
self.ligkern_program = LigKernProgram(ligkern_table)
self.kern_table = kern_table
def get_char_metrics(self, char_num, fix_rsfs=False):
"""Return glyph metrics for a unicode code point.
Arguments:
char_num: a unicode code point
fix_rsfs: adjust for rsfs10.tfm's different indexing system
"""
if char_num < self.start_char or char_num > self.end_char:
raise RuntimeError("Invalid character number")
if fix_rsfs:
# all of the char_nums contained start from zero in rsfs10.tfm
info = self.char_info[char_num - self.start_char]
else:
info = self.char_info[char_num + self.start_char]
char_kern_table = {}
if info.has_ligkern():
for char in range(self.start_char, self.end_char + 1):
kern = self.ligkern_program.execute(info.ligkern_start(), char)
if kern:
char_kern_table[char] = self.kern_table[kern]
return TfmCharMetrics(
self.width_table[info.width_index],
self.height_table[info.height_index],
self.depth_table[info.depth_index],
self.italic_table[info.italic_index],
char_kern_table)
class TfmReader(object):
def __init__(self, f):
self.f = f
def read_byte(self):
return ord(self.f.read(1))
def read_halfword(self):
b1 = self.read_byte()
b2 = self.read_byte()
return (b1 << 8) | b2
def read_word(self):
b1 = self.read_byte()
b2 = self.read_byte()
b3 = self.read_byte()
b4 = self.read_byte()
return (b1 << 24) | (b2 << 16) | (b3 << 8) | b4
def read_fixword(self):
word = self.read_word()
neg = False
if word & 0x80000000:
neg = True
word = (-word & 0xffffffff)
return (-1 if neg else 1) * word / float(1 << 20)
def read_bcpl(self, length):
str_length = self.read_byte()
data = self.f.read(length - 1)
return data[:str_length]
def read_tfm_file(file_name):
with open(file_name, 'rb') as f:
reader = TfmReader(f)
# file_size
reader.read_halfword()
header_size = reader.read_halfword()
start_char = reader.read_halfword()
end_char = reader.read_halfword()
width_table_size = reader.read_halfword()
height_table_size = reader.read_halfword()
depth_table_size = reader.read_halfword()
italic_table_size = reader.read_halfword()
ligkern_table_size = reader.read_halfword()
kern_table_size = reader.read_halfword()
# extensible_table_size
reader.read_halfword()
# parameter_table_size
reader.read_halfword()
# checksum
reader.read_word()
# design_size
reader.read_fixword()
if header_size > 2:
# coding_scheme
reader.read_bcpl(40)
if header_size > 12:
# font_family
reader.read_bcpl(20)
for i in range(header_size - 17):
reader.read_word()
char_info = []
for i in range(start_char, end_char + 1):
char_info.append(CharInfoWord(reader.read_word()))
width_table = []
for i in range(width_table_size):
width_table.append(reader.read_fixword())
height_table = []
for i in range(height_table_size):
height_table.append(reader.read_fixword())
depth_table = []
for i in range(depth_table_size):
depth_table.append(reader.read_fixword())
italic_table = []
for i in range(italic_table_size):
italic_table.append(reader.read_fixword())
ligkern_table = []
for i in range(ligkern_table_size):
skip = reader.read_byte()
next_char = reader.read_byte()
op = reader.read_byte()
remainder = reader.read_byte()
ligkern_table.append((skip, next_char, op, remainder))
kern_table = []
for i in range(kern_table_size):
kern_table.append(reader.read_fixword())
# There is more information, like the ligkern, kern, extensible, and
# param table, but we don't need these for now
return TfmFile(start_char, end_char, char_info, width_table,
height_table, depth_table, italic_table,
ligkern_table, kern_table)

524
node_modules/katex/src/parseNode.js generated vendored Normal file
View File

@@ -0,0 +1,524 @@
// @flow
import {NON_ATOMS} from "./symbols";
import type SourceLocation from "./SourceLocation";
import type {AlignSpec, ColSeparationType} from "./environments/array";
import type {Atom} from "./symbols";
import type {Mode, StyleStr} from "./types";
import type {Token} from "./Token";
import type {Measurement} from "./units";
export type NodeType = $Keys<ParseNodeTypes>;
export type ParseNode<TYPE: NodeType> = $ElementType<ParseNodeTypes, TYPE>;
// ParseNode's corresponding to Symbol `Group`s in symbols.js.
export type SymbolParseNode =
ParseNode<"atom"> |
ParseNode<"accent-token"> |
ParseNode<"mathord"> |
ParseNode<"op-token"> |
ParseNode<"spacing"> |
ParseNode<"textord">;
// ParseNode from `Parser.formatUnsupportedCmd`
export type UnsupportedCmdParseNode = ParseNode<"color">;
// Union of all possible `ParseNode<>` types.
export type AnyParseNode = $Values<ParseNodeTypes>;
// Map from `NodeType` to the corresponding `ParseNode`.
type ParseNodeTypes = {
"array": {|
type: "array",
mode: Mode,
loc?: ?SourceLocation,
colSeparationType?: ColSeparationType,
hskipBeforeAndAfter?: boolean,
addJot?: boolean,
cols?: AlignSpec[],
arraystretch: number,
body: AnyParseNode[][], // List of rows in the (2D) array.
rowGaps: (?Measurement)[],
hLinesBeforeRow: Array<boolean[]>,
// Whether each row should be automatically numbered, or an explicit tag
tags?: (boolean | AnyParseNode[])[],
leqno?: boolean,
isCD?: boolean,
|},
"cdlabel": {|
type: "cdlabel",
mode: Mode,
loc?: ?SourceLocation,
side: string,
label: AnyParseNode,
|},
"cdlabelparent": {|
type: "cdlabelparent",
mode: Mode,
loc?: ?SourceLocation,
fragment: AnyParseNode,
|},
"color": {|
type: "color",
mode: Mode,
loc?: ?SourceLocation,
color: string,
body: AnyParseNode[],
|},
"color-token": {|
type: "color-token",
mode: Mode,
loc?: ?SourceLocation,
color: string,
|},
// To avoid requiring run-time type assertions, this more carefully captures
// the requirements on the fields per the op.js htmlBuilder logic:
// - `body` and `value` are NEVER set simultaneously.
// - When `symbol` is true, `body` is set.
"op": {|
type: "op",
mode: Mode,
loc?: ?SourceLocation,
limits: boolean,
alwaysHandleSupSub?: boolean,
suppressBaseShift?: boolean,
parentIsSupSub: boolean,
symbol: boolean,
name: string,
body?: void,
|} | {|
type: "op",
mode: Mode,
loc?: ?SourceLocation,
limits: boolean,
alwaysHandleSupSub?: boolean,
suppressBaseShift?: boolean,
parentIsSupSub: boolean,
symbol: false, // If 'symbol' is true, `body` *must* be set.
name?: void,
body: AnyParseNode[],
|},
"ordgroup": {|
type: "ordgroup",
mode: Mode,
loc?: ?SourceLocation,
body: AnyParseNode[],
semisimple?: boolean,
|},
"raw": {|
type: "raw",
mode: Mode,
loc?: ?SourceLocation,
string: string,
|},
"size": {|
type: "size",
mode: Mode,
loc?: ?SourceLocation,
value: Measurement,
isBlank: boolean,
|},
"styling": {|
type: "styling",
mode: Mode,
loc?: ?SourceLocation,
style: StyleStr,
body: AnyParseNode[],
|},
"supsub": {|
type: "supsub",
mode: Mode,
loc?: ?SourceLocation,
base: ?AnyParseNode,
sup?: ?AnyParseNode,
sub?: ?AnyParseNode,
|},
"tag": {|
type: "tag",
mode: Mode,
loc?: ?SourceLocation,
body: AnyParseNode[],
tag: AnyParseNode[],
|},
"text": {|
type: "text",
mode: Mode,
loc?: ?SourceLocation,
body: AnyParseNode[],
font?: string,
|},
"url": {|
type: "url",
mode: Mode,
loc?: ?SourceLocation,
url: string,
|},
"verb": {|
type: "verb",
mode: Mode,
loc?: ?SourceLocation,
body: string,
star: boolean,
|},
// From symbol groups, constructed in Parser.js via `symbols` lookup.
// (Some of these have "-token" suffix to distinguish them from existing
// `ParseNode` types.)
"atom": {|
type: "atom",
family: Atom,
mode: Mode,
loc?: ?SourceLocation,
text: string,
|},
"mathord": {|
type: "mathord",
mode: Mode,
loc?: ?SourceLocation,
text: string,
|},
"spacing": {|
type: "spacing",
mode: Mode,
loc?: ?SourceLocation,
text: string,
|},
"textord": {|
type: "textord",
mode: Mode,
loc?: ?SourceLocation,
text: string,
|},
// These "-token" types don't have corresponding HTML/MathML builders.
"accent-token": {|
type: "accent-token",
mode: Mode,
loc?: ?SourceLocation,
text: string,
|},
"op-token": {|
type: "op-token",
mode: Mode,
loc?: ?SourceLocation,
text: string,
|},
// From functions.js and functions/*.js. See also "color", "op", "styling",
// and "text" above.
"accent": {|
type: "accent",
mode: Mode,
loc?: ?SourceLocation,
label: string,
isStretchy?: boolean,
isShifty?: boolean,
base: AnyParseNode,
|},
"accentUnder": {|
type: "accentUnder",
mode: Mode,
loc?: ?SourceLocation,
label: string,
isStretchy?: boolean,
isShifty?: boolean,
base: AnyParseNode,
|},
"cr": {|
type: "cr",
mode: Mode,
loc?: ?SourceLocation,
newLine: boolean,
size: ?Measurement,
|},
"delimsizing": {|
type: "delimsizing",
mode: Mode,
loc?: ?SourceLocation,
size: 1 | 2 | 3 | 4,
mclass: "mopen" | "mclose" | "mrel" | "mord",
delim: string,
|},
"enclose": {|
type: "enclose",
mode: Mode,
loc?: ?SourceLocation,
label: string,
backgroundColor?: string,
borderColor?: string,
body: AnyParseNode,
|},
"environment": {|
type: "environment",
mode: Mode,
loc?: ?SourceLocation,
name: string,
nameGroup: AnyParseNode,
|},
"font": {|
type: "font",
mode: Mode,
loc?: ?SourceLocation,
font: string,
body: AnyParseNode,
|},
"genfrac": {|
type: "genfrac",
mode: Mode,
loc?: ?SourceLocation,
continued: boolean,
numer: AnyParseNode,
denom: AnyParseNode,
hasBarLine: boolean,
leftDelim: ?string,
rightDelim: ?string,
size: StyleStr | "auto",
barSize: Measurement | null,
|},
"hbox": {|
type: "hbox",
mode: Mode,
loc?: ?SourceLocation,
body: AnyParseNode[],
|},
"horizBrace": {|
type: "horizBrace",
mode: Mode,
loc?: ?SourceLocation,
label: string,
isOver: boolean,
base: AnyParseNode,
|},
"href": {|
type: "href",
mode: Mode,
loc?: ?SourceLocation,
href: string,
body: AnyParseNode[],
|},
"html": {|
type: "html",
mode: Mode,
loc?: ?SourceLocation,
attributes: {[string]: string},
body: AnyParseNode[],
|},
"htmlmathml": {|
type: "htmlmathml",
mode: Mode,
loc?: ?SourceLocation,
html: AnyParseNode[],
mathml: AnyParseNode[],
|},
"includegraphics": {|
type: "includegraphics",
mode: Mode,
loc?: ?SourceLocation,
alt: string,
width: Measurement,
height: Measurement,
totalheight: Measurement,
src: string,
|},
"infix": {|
type: "infix",
mode: Mode,
loc?: ?SourceLocation,
replaceWith: string,
size?: Measurement,
token: ?Token,
|},
"internal": {|
type: "internal",
mode: Mode,
loc?: ?SourceLocation,
|},
"kern": {|
type: "kern",
mode: Mode,
loc?: ?SourceLocation,
dimension: Measurement,
|},
"lap": {|
type: "lap",
mode: Mode,
loc?: ?SourceLocation,
alignment: string,
body: AnyParseNode,
|},
"leftright": {|
type: "leftright",
mode: Mode,
loc?: ?SourceLocation,
body: AnyParseNode[],
left: string,
right: string,
rightColor: ?string, // undefined means "inherit"
|},
"leftright-right": {|
type: "leftright-right",
mode: Mode,
loc?: ?SourceLocation,
delim: string,
color: ?string, // undefined means "inherit"
|},
"mathchoice": {|
type: "mathchoice",
mode: Mode,
loc?: ?SourceLocation,
display: AnyParseNode[],
text: AnyParseNode[],
script: AnyParseNode[],
scriptscript: AnyParseNode[],
|},
"middle": {|
type: "middle",
mode: Mode,
loc?: ?SourceLocation,
delim: string,
|},
"mclass": {|
type: "mclass",
mode: Mode,
loc?: ?SourceLocation,
mclass: string,
body: AnyParseNode[],
isCharacterBox: boolean,
|},
"operatorname": {|
type: "operatorname",
mode: Mode,
loc?: ?SourceLocation,
body: AnyParseNode[],
alwaysHandleSupSub: boolean,
limits: boolean,
parentIsSupSub: boolean,
|},
"overline": {|
type: "overline",
mode: Mode,
loc?: ?SourceLocation,
body: AnyParseNode,
|},
"phantom": {|
type: "phantom",
mode: Mode,
loc?: ?SourceLocation,
body: AnyParseNode[],
|},
"hphantom": {|
type: "hphantom",
mode: Mode,
loc?: ?SourceLocation,
body: AnyParseNode,
|},
"vphantom": {|
type: "vphantom",
mode: Mode,
loc?: ?SourceLocation,
body: AnyParseNode,
|},
"pmb": {|
type: "pmb",
mode: Mode,
loc?: ?SourceLocation,
mclass: string,
body: AnyParseNode[],
|},
"raisebox": {|
type: "raisebox",
mode: Mode,
loc?: ?SourceLocation,
dy: Measurement,
body: AnyParseNode,
|},
"rule": {|
type: "rule",
mode: Mode,
loc?: ?SourceLocation,
shift: ?Measurement,
width: Measurement,
height: Measurement,
|},
"sizing": {|
type: "sizing",
mode: Mode,
loc?: ?SourceLocation,
size: number,
body: AnyParseNode[],
|},
"smash": {|
type: "smash",
mode: Mode,
loc?: ?SourceLocation,
body: AnyParseNode,
smashHeight: boolean,
smashDepth: boolean,
|},
"sqrt": {|
type: "sqrt",
mode: Mode,
loc?: ?SourceLocation,
body: AnyParseNode,
index: ?AnyParseNode,
|},
"underline": {|
type: "underline",
mode: Mode,
loc?: ?SourceLocation,
body: AnyParseNode,
|},
"vcenter": {|
type: "vcenter",
mode: Mode,
loc?: ?SourceLocation,
body: AnyParseNode,
|},
"xArrow": {|
type: "xArrow",
mode: Mode,
loc?: ?SourceLocation,
label: string,
body: AnyParseNode,
below: ?AnyParseNode,
|},
};
/**
* Asserts that the node is of the given type and returns it with stricter
* typing. Throws if the node's type does not match.
*/
export function assertNodeType<NODETYPE: NodeType>(
node: ?AnyParseNode,
type: NODETYPE,
): ParseNode<NODETYPE> {
if (!node || node.type !== type) {
throw new Error(
`Expected node of type ${type}, but got ` +
(node ? `node of type ${node.type}` : String(node)));
}
// $FlowFixMe, >=0.125
return node;
}
/**
* Returns the node more strictly typed iff it is of the given type. Otherwise,
* returns null.
*/
export function assertSymbolNodeType(node: ?AnyParseNode): SymbolParseNode {
const typedNode = checkSymbolNodeType(node);
if (!typedNode) {
throw new Error(
`Expected node of symbol group type, but got ` +
(node ? `node of type ${node.type}` : String(node)));
}
return typedNode;
}
/**
* Returns the node more strictly typed iff it is of the given type. Otherwise,
* returns null.
*/
export function checkSymbolNodeType(node: ?AnyParseNode): ?SymbolParseNode {
if (node && (node.type === "atom" || NON_ATOMS.hasOwnProperty(node.type))) {
// $FlowFixMe
return node;
}
return null;
}

49
node_modules/katex/src/parseTree.js generated vendored Normal file
View File

@@ -0,0 +1,49 @@
// @flow
/**
* Provides a single function for parsing an expression using a Parser
* TODO(emily): Remove this
*/
import Parser from "./Parser";
import ParseError from "./ParseError";
import {Token} from "./Token";
import type Settings from "./Settings";
import type {AnyParseNode} from "./parseNode";
/**
* Parses an expression using a Parser, then returns the parsed result.
*/
const parseTree = function(toParse: string, settings: Settings): AnyParseNode[] {
if (!(typeof toParse === 'string' || toParse instanceof String)) {
throw new TypeError('KaTeX can only parse string typed expression');
}
const parser = new Parser(toParse, settings);
// Blank out any \df@tag to avoid spurious "Duplicate \tag" errors
delete parser.gullet.macros.current["\\df@tag"];
let tree = parser.parse();
// Prevent a color definition from persisting between calls to katex.render().
delete parser.gullet.macros.current["\\current@color"];
delete parser.gullet.macros.current["\\color"];
// If the input used \tag, it will set the \df@tag macro to the tag.
// In this case, we separately parse the tag and wrap the tree.
if (parser.gullet.macros.get("\\df@tag")) {
if (!settings.displayMode) {
throw new ParseError("\\tag works only in display equations");
}
tree = [{
type: "tag",
mode: "text",
body: tree,
tag: parser.subparse([new Token("\\df@tag")]),
}];
}
return tree;
};
export default parseTree;

108
node_modules/katex/src/spacingData.js generated vendored Normal file
View File

@@ -0,0 +1,108 @@
// @flow
/**
* Describes spaces between different classes of atoms.
*/
import type {Measurement} from "./units";
const thinspace: Measurement = {
number: 3,
unit: "mu",
};
const mediumspace: Measurement = {
number: 4,
unit: "mu",
};
const thickspace: Measurement = {
number: 5,
unit: "mu",
};
// Making the type below exact with all optional fields doesn't work due to
// - https://github.com/facebook/flow/issues/4582
// - https://github.com/facebook/flow/issues/5688
// However, since *all* fields are optional, $Shape<> works as suggested in 5688
// above.
export type Spacings = $Shape<{
mord: Measurement,
mop: Measurement,
mbin: Measurement,
mrel: Measurement,
mopen: Measurement,
mclose: Measurement,
mpunct: Measurement,
minner: Measurement,
}> & {};
// Spacing relationships for display and text styles
export const spacings: {[$Keys<Spacings>]: Spacings} = {
mord: {
mop: thinspace,
mbin: mediumspace,
mrel: thickspace,
minner: thinspace,
},
mop: {
mord: thinspace,
mop: thinspace,
mrel: thickspace,
minner: thinspace,
},
mbin: {
mord: mediumspace,
mop: mediumspace,
mopen: mediumspace,
minner: mediumspace,
},
mrel: {
mord: thickspace,
mop: thickspace,
mopen: thickspace,
minner: thickspace,
},
mopen: {},
mclose: {
mop: thinspace,
mbin: mediumspace,
mrel: thickspace,
minner: thinspace,
},
mpunct: {
mord: thinspace,
mop: thinspace,
mrel: thickspace,
mopen: thinspace,
mclose: thinspace,
mpunct: thinspace,
minner: thinspace,
},
minner: {
mord: thinspace,
mop: thinspace,
mbin: mediumspace,
mrel: thickspace,
mopen: thinspace,
mpunct: thinspace,
minner: thinspace,
},
};
// Spacing relationships for script and scriptscript styles
export const tightSpacings: {[$Keys<Spacings>]: Spacings} = {
mord: {
mop: thinspace,
},
mop: {
mord: thinspace,
mop: thinspace,
},
mbin: {},
mrel: {},
mopen: {},
mclose: {
mop: thinspace,
},
mpunct: {},
minner: {
mop: thinspace,
},
};

378
node_modules/katex/src/stretchy.js generated vendored Normal file
View File

@@ -0,0 +1,378 @@
// @flow
/**
* This file provides support to buildMathML.js and buildHTML.js
* for stretchy wide elements rendered from SVG files
* and other CSS trickery.
*/
import {LineNode, PathNode, SvgNode} from "./domTree";
import buildCommon from "./buildCommon";
import mathMLTree from "./mathMLTree";
import utils from "./utils";
import {makeEm} from "./units";
import type Options from "./Options";
import type {ParseNode, AnyParseNode} from "./parseNode";
import type {DomSpan, HtmlDomNode, SvgSpan} from "./domTree";
const stretchyCodePoint: {[string]: string} = {
widehat: "^",
widecheck: "ˇ",
widetilde: "~",
utilde: "~",
overleftarrow: "\u2190",
underleftarrow: "\u2190",
xleftarrow: "\u2190",
overrightarrow: "\u2192",
underrightarrow: "\u2192",
xrightarrow: "\u2192",
underbrace: "\u23df",
overbrace: "\u23de",
overgroup: "\u23e0",
undergroup: "\u23e1",
overleftrightarrow: "\u2194",
underleftrightarrow: "\u2194",
xleftrightarrow: "\u2194",
Overrightarrow: "\u21d2",
xRightarrow: "\u21d2",
overleftharpoon: "\u21bc",
xleftharpoonup: "\u21bc",
overrightharpoon: "\u21c0",
xrightharpoonup: "\u21c0",
xLeftarrow: "\u21d0",
xLeftrightarrow: "\u21d4",
xhookleftarrow: "\u21a9",
xhookrightarrow: "\u21aa",
xmapsto: "\u21a6",
xrightharpoondown: "\u21c1",
xleftharpoondown: "\u21bd",
xrightleftharpoons: "\u21cc",
xleftrightharpoons: "\u21cb",
xtwoheadleftarrow: "\u219e",
xtwoheadrightarrow: "\u21a0",
xlongequal: "=",
xtofrom: "\u21c4",
xrightleftarrows: "\u21c4",
xrightequilibrium: "\u21cc", // Not a perfect match.
xleftequilibrium: "\u21cb", // None better available.
"\\cdrightarrow": "\u2192",
"\\cdleftarrow": "\u2190",
"\\cdlongequal": "=",
};
const mathMLnode = function(label: string): mathMLTree.MathNode {
const node = new mathMLTree.MathNode(
"mo",
[new mathMLTree.TextNode(stretchyCodePoint[label.replace(/^\\/, '')])],
);
node.setAttribute("stretchy", "true");
return node;
};
// Many of the KaTeX SVG images have been adapted from glyphs in KaTeX fonts.
// Copyright (c) 2009-2010, Design Science, Inc. (<www.mathjax.org>)
// Copyright (c) 2014-2017 Khan Academy (<www.khanacademy.org>)
// Licensed under the SIL Open Font License, Version 1.1.
// See \nhttp://scripts.sil.org/OFL
// Very Long SVGs
// Many of the KaTeX stretchy wide elements use a long SVG image and an
// overflow: hidden tactic to achieve a stretchy image while avoiding
// distortion of arrowheads or brace corners.
// The SVG typically contains a very long (400 em) arrow.
// The SVG is in a container span that has overflow: hidden, so the span
// acts like a window that exposes only part of the SVG.
// The SVG always has a longer, thinner aspect ratio than the container span.
// After the SVG fills 100% of the height of the container span,
// there is a long arrow shaft left over. That left-over shaft is not shown.
// Instead, it is sliced off because the span's CSS has overflow: hidden.
// Thus, the reader sees an arrow that matches the subject matter width
// without distortion.
// Some functions, such as \cancel, need to vary their aspect ratio. These
// functions do not get the overflow SVG treatment.
// Second Brush Stroke
// Low resolution monitors struggle to display images in fine detail.
// So browsers apply anti-aliasing. A long straight arrow shaft therefore
// will sometimes appear as if it has a blurred edge.
// To mitigate this, these SVG files contain a second "brush-stroke" on the
// arrow shafts. That is, a second long thin rectangular SVG path has been
// written directly on top of each arrow shaft. This reinforcement causes
// some of the screen pixels to display as black instead of the anti-aliased
// gray pixel that a single path would generate. So we get arrow shafts
// whose edges appear to be sharper.
// In the katexImagesData object just below, the dimensions all
// correspond to path geometry inside the relevant SVG.
// For example, \overrightarrow uses the same arrowhead as glyph U+2192
// from the KaTeX Main font. The scaling factor is 1000.
// That is, inside the font, that arrowhead is 522 units tall, which
// corresponds to 0.522 em inside the document.
const katexImagesData: {
[string]: ([string[], number, number] | [[string], number, number, string])
} = {
// path(s), minWidth, height, align
overrightarrow: [["rightarrow"], 0.888, 522, "xMaxYMin"],
overleftarrow: [["leftarrow"], 0.888, 522, "xMinYMin"],
underrightarrow: [["rightarrow"], 0.888, 522, "xMaxYMin"],
underleftarrow: [["leftarrow"], 0.888, 522, "xMinYMin"],
xrightarrow: [["rightarrow"], 1.469, 522, "xMaxYMin"],
"\\cdrightarrow": [["rightarrow"], 3.0, 522, "xMaxYMin"], // CD minwwidth2.5pc
xleftarrow: [["leftarrow"], 1.469, 522, "xMinYMin"],
"\\cdleftarrow": [["leftarrow"], 3.0, 522, "xMinYMin"],
Overrightarrow: [["doublerightarrow"], 0.888, 560, "xMaxYMin"],
xRightarrow: [["doublerightarrow"], 1.526, 560, "xMaxYMin"],
xLeftarrow: [["doubleleftarrow"], 1.526, 560, "xMinYMin"],
overleftharpoon: [["leftharpoon"], 0.888, 522, "xMinYMin"],
xleftharpoonup: [["leftharpoon"], 0.888, 522, "xMinYMin"],
xleftharpoondown: [["leftharpoondown"], 0.888, 522, "xMinYMin"],
overrightharpoon: [["rightharpoon"], 0.888, 522, "xMaxYMin"],
xrightharpoonup: [["rightharpoon"], 0.888, 522, "xMaxYMin"],
xrightharpoondown: [["rightharpoondown"], 0.888, 522, "xMaxYMin"],
xlongequal: [["longequal"], 0.888, 334, "xMinYMin"],
"\\cdlongequal": [["longequal"], 3.0, 334, "xMinYMin"],
xtwoheadleftarrow: [["twoheadleftarrow"], 0.888, 334, "xMinYMin"],
xtwoheadrightarrow: [["twoheadrightarrow"], 0.888, 334, "xMaxYMin"],
overleftrightarrow: [["leftarrow", "rightarrow"], 0.888, 522],
overbrace: [["leftbrace", "midbrace", "rightbrace"], 1.6, 548],
underbrace: [["leftbraceunder", "midbraceunder", "rightbraceunder"],
1.6, 548],
underleftrightarrow: [["leftarrow", "rightarrow"], 0.888, 522],
xleftrightarrow: [["leftarrow", "rightarrow"], 1.75, 522],
xLeftrightarrow: [["doubleleftarrow", "doublerightarrow"], 1.75, 560],
xrightleftharpoons: [["leftharpoondownplus", "rightharpoonplus"], 1.75, 716],
xleftrightharpoons: [["leftharpoonplus", "rightharpoondownplus"],
1.75, 716],
xhookleftarrow: [["leftarrow", "righthook"], 1.08, 522],
xhookrightarrow: [["lefthook", "rightarrow"], 1.08, 522],
overlinesegment: [["leftlinesegment", "rightlinesegment"], 0.888, 522],
underlinesegment: [["leftlinesegment", "rightlinesegment"], 0.888, 522],
overgroup: [["leftgroup", "rightgroup"], 0.888, 342],
undergroup: [["leftgroupunder", "rightgroupunder"], 0.888, 342],
xmapsto: [["leftmapsto", "rightarrow"], 1.5, 522],
xtofrom: [["leftToFrom", "rightToFrom"], 1.75, 528],
// The next three arrows are from the mhchem package.
// In mhchem.sty, min-length is 2.0em. But these arrows might appear in the
// document as \xrightarrow or \xrightleftharpoons. Those have
// min-length = 1.75em, so we set min-length on these next three to match.
xrightleftarrows: [["baraboveleftarrow", "rightarrowabovebar"], 1.75, 901],
xrightequilibrium: [["baraboveshortleftharpoon",
"rightharpoonaboveshortbar"], 1.75, 716],
xleftequilibrium: [["shortbaraboveleftharpoon",
"shortrightharpoonabovebar"], 1.75, 716],
};
const groupLength = function(arg: AnyParseNode): number {
if (arg.type === "ordgroup") {
return arg.body.length;
} else {
return 1;
}
};
const svgSpan = function(
group: ParseNode<"accent"> | ParseNode<"accentUnder"> | ParseNode<"xArrow">
| ParseNode<"horizBrace">,
options: Options,
): DomSpan | SvgSpan {
// Create a span with inline SVG for the element.
function buildSvgSpan_(): {
span: DomSpan | SvgSpan,
minWidth: number,
height: number,
} {
let viewBoxWidth = 400000; // default
const label = group.label.slice(1);
if (utils.contains(["widehat", "widecheck", "widetilde", "utilde"],
label)) {
// Each type in the `if` statement corresponds to one of the ParseNode
// types below. This narrowing is required to access `grp.base`.
// $FlowFixMe
const grp: ParseNode<"accent"> | ParseNode<"accentUnder"> = group;
// There are four SVG images available for each function.
// Choose a taller image when there are more characters.
const numChars = groupLength(grp.base);
let viewBoxHeight;
let pathName;
let height;
if (numChars > 5) {
if (label === "widehat" || label === "widecheck") {
viewBoxHeight = 420;
viewBoxWidth = 2364;
height = 0.42;
pathName = label + "4";
} else {
viewBoxHeight = 312;
viewBoxWidth = 2340;
height = 0.34;
pathName = "tilde4";
}
} else {
const imgIndex = [1, 1, 2, 2, 3, 3][numChars];
if (label === "widehat" || label === "widecheck") {
viewBoxWidth = [0, 1062, 2364, 2364, 2364][imgIndex];
viewBoxHeight = [0, 239, 300, 360, 420][imgIndex];
height = [0, 0.24, 0.3, 0.3, 0.36, 0.42][imgIndex];
pathName = label + imgIndex;
} else {
viewBoxWidth = [0, 600, 1033, 2339, 2340][imgIndex];
viewBoxHeight = [0, 260, 286, 306, 312][imgIndex];
height = [0, 0.26, 0.286, 0.3, 0.306, 0.34][imgIndex];
pathName = "tilde" + imgIndex;
}
}
const path = new PathNode(pathName);
const svgNode = new SvgNode([path], {
"width": "100%",
"height": makeEm(height),
"viewBox": `0 0 ${viewBoxWidth} ${viewBoxHeight}`,
"preserveAspectRatio": "none",
});
return {
span: buildCommon.makeSvgSpan([], [svgNode], options),
minWidth: 0,
height,
};
} else {
const spans = [];
const data = katexImagesData[label];
const [paths, minWidth, viewBoxHeight] = data;
const height = viewBoxHeight / 1000;
const numSvgChildren = paths.length;
let widthClasses;
let aligns;
if (numSvgChildren === 1) {
// $FlowFixMe: All these cases must be of the 4-tuple type.
const align1: string = data[3];
widthClasses = ["hide-tail"];
aligns = [align1];
} else if (numSvgChildren === 2) {
widthClasses = ["halfarrow-left", "halfarrow-right"];
aligns = ["xMinYMin", "xMaxYMin"];
} else if (numSvgChildren === 3) {
widthClasses = ["brace-left", "brace-center", "brace-right"];
aligns = ["xMinYMin", "xMidYMin", "xMaxYMin"];
} else {
throw new Error(
`Correct katexImagesData or update code here to support
${numSvgChildren} children.`);
}
for (let i = 0; i < numSvgChildren; i++) {
const path = new PathNode(paths[i]);
const svgNode = new SvgNode([path], {
"width": "400em",
"height": makeEm(height),
"viewBox": `0 0 ${viewBoxWidth} ${viewBoxHeight}`,
"preserveAspectRatio": aligns[i] + " slice",
});
const span = buildCommon.makeSvgSpan(
[widthClasses[i]], [svgNode], options);
if (numSvgChildren === 1) {
return {span, minWidth, height};
} else {
span.style.height = makeEm(height);
spans.push(span);
}
}
return {
span: buildCommon.makeSpan(["stretchy"], spans, options),
minWidth,
height,
};
}
} // buildSvgSpan_()
const {span, minWidth, height} = buildSvgSpan_();
// Note that we are returning span.depth = 0.
// Any adjustments relative to the baseline must be done in buildHTML.
span.height = height;
span.style.height = makeEm(height);
if (minWidth > 0) {
span.style.minWidth = makeEm(minWidth);
}
return span;
};
const encloseSpan = function(
inner: HtmlDomNode,
label: string,
topPad: number,
bottomPad: number,
options: Options,
): DomSpan | SvgSpan {
// Return an image span for \cancel, \bcancel, \xcancel, \fbox, or \angl
let img;
const totalHeight = inner.height + inner.depth + topPad + bottomPad;
if (/fbox|color|angl/.test(label)) {
img = buildCommon.makeSpan(["stretchy", label], [], options);
if (label === "fbox") {
const color = options.color && options.getColor();
if (color) {
img.style.borderColor = color;
}
}
} else {
// \cancel, \bcancel, or \xcancel
// Since \cancel's SVG is inline and it omits the viewBox attribute,
// its stroke-width will not vary with span area.
const lines = [];
if (/^[bx]cancel$/.test(label)) {
lines.push(new LineNode({
"x1": "0",
"y1": "0",
"x2": "100%",
"y2": "100%",
"stroke-width": "0.046em",
}));
}
if (/^x?cancel$/.test(label)) {
lines.push(new LineNode({
"x1": "0",
"y1": "100%",
"x2": "100%",
"y2": "0",
"stroke-width": "0.046em",
}));
}
const svgNode = new SvgNode(lines, {
"width": "100%",
"height": makeEm(totalHeight),
});
img = buildCommon.makeSvgSpan([], [svgNode], options);
}
img.height = totalHeight;
img.style.height = makeEm(totalHeight);
return img;
};
export default {
encloseSpan,
mathMLnode,
svgSpan,
};

71
node_modules/katex/src/styles/fonts.scss generated vendored Normal file
View File

@@ -0,0 +1,71 @@
$font-folder: "../../fonts" !default;
$use-woff2: true !default;
$use-woff: true !default;
$use-ttf: true !default;
@function generate-src($family, $family-suffix) {
$src: null;
@if $use-woff2 {
$src: append($src, url('#{$font-folder}/KaTeX_#{$family}-#{$family-suffix}.woff2') format('woff2'), comma);
}
@if $use-woff {
$src: append($src, url('#{$font-folder}/KaTeX_#{$family}-#{$family-suffix}.woff') format('woff'), comma);
}
@if $use-ttf {
$src: append($src, url('#{$font-folder}/KaTeX_#{$family}-#{$family-suffix}.ttf') format('truetype'), comma);
}
@return $src;
}
@function generate-suffix($weight, $style) {
$suffix: null;
@if $weight == normal and $style == normal {
$suffix: 'Regular';
}
@if $weight == normal and $style == italic {
$suffix: 'Italic';
}
@if $weight == bold and $style == normal {
$suffix: 'Bold';
}
@if $weight == bold and $style == italic {
$suffix: 'BoldItalic';
}
@return $suffix;
}
@mixin font-face($family, $weight, $style) {
$suffix: generate-suffix($weight, $style);
$src: generate-src($family, $suffix);
@font-face {
font-family: 'KaTeX_#{$family}';
src: $src;
font-weight: $weight;
font-style: $style;
}
}
@include font-face('AMS', normal, normal);
@include font-face('Caligraphic', bold, normal);
@include font-face('Caligraphic', normal, normal);
@include font-face('Fraktur', bold, normal);
@include font-face('Fraktur', normal, normal);
@include font-face('Main', bold, normal);
@include font-face('Main', bold, italic);
@include font-face('Main', normal, italic);
@include font-face('Main', normal, normal);
@include font-face('Math', bold, italic);
@include font-face('Math', normal, italic);
@include font-face('SansSerif', bold, normal);
@include font-face('SansSerif', normal, italic);
@include font-face('SansSerif', normal, normal);
@include font-face('Script', normal, normal);
@include font-face('Size1', normal, normal);
@include font-face('Size2', normal, normal);
@include font-face('Size3', normal, normal);
@include font-face('Size4', normal, normal);
@include font-face('Typewriter', normal, normal);

664
node_modules/katex/src/styles/katex.scss generated vendored Normal file
View File

@@ -0,0 +1,664 @@
/* stylelint-disable font-family-no-missing-generic-family-keyword */
@import "./fonts.scss";
// The mu unit is defined as 1/18 em
$mu: calc(1em / 18);
// The version is dynamically set from package.json via webpack.common.js
$version: "" !default;
// CSS margin property for math in display mode
$display-margin: 1em 0 !default;
.katex {
font: normal 1.21em KaTeX_Main, Times New Roman, serif;
line-height: 1.2;
// Protect elements inside .katex from inheriting text-indent.
text-indent: 0;
// Prevent a rendering bug that misplaces \vec in Chrome.
text-rendering: auto;
* {
// Prevent background resetting on elements in Windows's high-contrast
// mode, while still allowing background/foreground setting on root .katex
-ms-high-contrast-adjust: none !important;
// Insulate fraction bars and rules from CSS that sets border-color.
border-color: currentColor;
}
.katex-version::after {
content: $version;
}
.katex-mathml {
/* Accessibility hack to only show to screen readers
Found at: http://a11yproject.com/posts/how-to-hide-content/ */
position: absolute;
clip: rect(1px, 1px, 1px, 1px);
padding: 0;
border: 0;
height: 1px;
width: 1px;
overflow: hidden;
}
.katex-html {
/* \newline is an empty block at top level, between .base elements */
> .newline {
display: block;
}
}
.base {
position: relative;
display: inline-block;
white-space: nowrap;
// Fix width of containers of negative spaces, working around Chrome bug.
width: min-content;
}
.strut {
display: inline-block;
}
// Text font weights
.textbf {
font-weight: bold;
}
// Text font shapes.
.textit {
font-style: italic;
}
// Text font families.
.textrm {
font-family: KaTeX_Main;
}
.textsf {
font-family: KaTeX_SansSerif;
}
.texttt {
font-family: KaTeX_Typewriter;
}
// Math fonts.
.mathnormal {
font-family: KaTeX_Math;
font-style: italic;
}
.mathit {
font-family: KaTeX_Main;
font-style: italic;
}
.mathrm {
font-style: normal;
}
.mathbf {
font-family: KaTeX_Main;
font-weight: bold;
}
.boldsymbol {
font-family: KaTeX_Math;
font-weight: bold;
font-style: italic;
}
.amsrm {
font-family: KaTeX_AMS;
}
.mathbb,
.textbb {
font-family: KaTeX_AMS;
}
.mathcal {
font-family: KaTeX_Caligraphic;
}
.mathfrak,
.textfrak {
font-family: KaTeX_Fraktur;
}
.mathboldfrak,
.textboldfrak {
font-family: KaTeX_Fraktur;
font-weight: bold;
}
.mathtt {
font-family: KaTeX_Typewriter;
}
.mathscr,
.textscr {
font-family: KaTeX_Script;
}
.mathsf,
.textsf {
font-family: KaTeX_SansSerif;
}
.mathboldsf,
.textboldsf {
font-family: KaTeX_SansSerif;
font-weight: bold;
}
.mathsfit,
.mathitsf,
.textitsf {
font-family: KaTeX_SansSerif;
font-style: italic;
}
.mainrm {
font-family: KaTeX_Main;
font-style: normal;
}
// This value is also used in fontMetrics.js, if you change it make sure the
// values match.
$ptperem: 10;
$nulldelimiterspace: calc(1.2em / $ptperem);
$muspace: 0.055556em; // 1mu
$thinspace: 0.16667em; // 3mu
$mediumspace: 0.22222em; // 4mu
$thickspace: 0.27778em; // 5mu
.vlist-t {
display: inline-table;
table-layout: fixed;
border-collapse: collapse;
}
.vlist-r {
display: table-row;
}
.vlist {
display: table-cell;
vertical-align: bottom;
position: relative;
> span {
display: block;
height: 0;
position: relative;
> span {
display: inline-block;
}
> .pstrut {
overflow: hidden;
width: 0;
}
}
}
.vlist-t2 {
margin-right: -2px;
}
.vlist-s {
// This cell solves Safari rendering problems. It has text content, so
// its baseline is used for the table. A very small font avoids line-box
// issues; absolute units prevent user font-size overrides from breaking
// rendering. Safari refuses to make the box zero-width, so we give it
// a known width and compensate with negative right margin on the
// inline-table. To prevent the "width: min-content" Chrome workaround
// from shrinking this box, we also set min-width.
display: table-cell;
vertical-align: bottom;
font-size: 1px;
width: 2px;
min-width: 2px;
}
.vbox {
display: inline-flex;
flex-direction: column;
align-items: baseline;
}
.hbox {
display: inline-flex;
flex-direction: row;
width: 100%;
}
.thinbox {
display: inline-flex;
flex-direction: row;
width: 0;
max-width: 0; // necessary for Safari
}
.msupsub {
text-align: left;
}
.mfrac {
> span > span {
text-align: center;
}
.frac-line {
display: inline-block;
width: 100%;
border-bottom-style: solid;
}
}
// Prevent Chrome from disappearing frac-lines, rules, etc.
.mfrac .frac-line,
.overline .overline-line,
.underline .underline-line,
.hline,
.hdashline,
.rule {
min-height: 1px;
}
.mspace {
display: inline-block;
}
.llap,
.rlap,
.clap {
width: 0;
position: relative;
> .inner {
position: absolute;
}
> .fix {
display: inline-block;
}
}
.llap > .inner {
right: 0;
}
.rlap > .inner,
.clap > .inner {
left: 0;
}
.clap > .inner > span {
margin-left: -50%;
margin-right: 50%;
}
.rule {
display: inline-block;
border: solid 0;
position: relative;
}
.overline .overline-line,
.underline .underline-line,
.hline {
display: inline-block;
width: 100%;
border-bottom-style: solid;
}
.hdashline {
display: inline-block;
width: 100%;
border-bottom-style: dashed;
}
.sqrt {
> .root {
/* These values are taken from the definition of `\r@@t`,
`\mkern 5mu` and `\mkern -10mu`. */
margin-left: calc(5*$mu);
margin-right: calc(-10*$mu);
}
}
.sizing,
.fontsize-ensurer {
$sizes: 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.2, 1.44, 1.728, 2.074, 2.488;
@for $from from 1 through length($sizes) {
@for $to from 1 through length($sizes) {
&.reset-size#{$from}.size#{$to} {
/* stylelint-disable-next-line */
font-size: calc((nth($sizes, $to) / nth($sizes, $from)) * 1em);
}
}
}
}
.delimsizing {
&.size1 { font-family: KaTeX_Size1; }
&.size2 { font-family: KaTeX_Size2; }
&.size3 { font-family: KaTeX_Size3; }
&.size4 { font-family: KaTeX_Size4; }
&.mult {
.delim-size1 > span {
font-family: KaTeX_Size1;
}
.delim-size4 > span {
font-family: KaTeX_Size4;
}
}
}
.nulldelimiter {
display: inline-block;
width: $nulldelimiterspace;
}
.delimcenter {
position: relative;
}
.op-symbol {
position: relative;
&.small-op {
font-family: KaTeX_Size1;
}
&.large-op {
font-family: KaTeX_Size2;
}
}
.op-limits {
> .vlist-t {
text-align: center;
}
}
.accent {
> .vlist-t {
text-align: center;
}
.accent-body {
position: relative; // so that 'left' can shift the accent
}
// Accents that are not of the accent-full class have zero width
// (do not contribute to the width of the final symbol).
.accent-body:not(.accent-full) {
width: 0;
}
}
.overlay {
display: block;
}
.mtable {
.vertical-separator {
display: inline-block;
// margin and border-right are set in JavaScript
min-width: 1px; // Prevent Chrome from omitting a line.
}
.arraycolsep {
display: inline-block;
}
.col-align-c > .vlist-t {
text-align: center;
}
.col-align-l > .vlist-t {
text-align: left;
}
.col-align-r > .vlist-t {
text-align: right;
}
}
.svg-align {
text-align: left;
}
svg {
display: block;
position: absolute; // absolute relative to parent
width: 100%;
height: inherit;
// We want to inherit colors from our environment
fill: currentColor;
stroke: currentColor;
// But path elements should not have an outline by default
// that would make them bigger than we expect.
path {
stroke: none;
}
// And we don't want to inherit any other style properties
// that could affect SVG rendering without affecting font
// rendering. So we reset these properties to their default
// values for every <svg> element.
// See https://www.w3.org/TR/SVG/painting.html
fill-rule: nonzero;
fill-opacity: 1;
stroke-width: 1;
stroke-linecap: butt;
stroke-linejoin: miter;
stroke-miterlimit: 4;
stroke-dasharray: none;
stroke-dashoffset: 0;
stroke-opacity: 1;
}
img {
border-style: none;
min-width: 0;
min-height: 0;
max-width: none;
max-height: none;
}
// Define CSS for image whose width will match its span width.
.stretchy {
width: 100%;
display: block;
position: relative;
overflow: hidden;
&::before,
&::after {
content: "";
}
}
// Hide the long tail of a stretchy SVG.
.hide-tail {
width: 100%; // necessary only to get IE to work properly
position: relative; // ditto
overflow: hidden; // This line applies to all browsers.
}
.halfarrow-left {
position: absolute;
left: 0;
width: 50.2%;
overflow: hidden;
}
.halfarrow-right {
position: absolute;
right: 0;
width: 50.2%;
overflow: hidden;
}
.brace-left {
position: absolute;
left: 0;
width: 25.1%;
overflow: hidden;
}
.brace-center {
position: absolute;
left: 25%;
width: 50%;
overflow: hidden;
}
.brace-right {
position: absolute;
right: 0;
width: 25.1%;
overflow: hidden;
}
// Lengthen the extensible arrows via padding.
.x-arrow-pad {
padding: 0 0.5em;
}
.cd-arrow-pad {
padding: 0 0.55556em 0 0.27778em; // \;{#1}\;\;
}
.x-arrow,
.mover,
.munder {
text-align: center;
}
.boxpad {
padding: 0 0.3em; // \fboxsep = 3pt
}
.fbox,
.fcolorbox {
box-sizing: border-box;
border: 0.04em solid; // \fboxrule = 0.4pt
}
.cancel-pad {
padding: 0 0.2em; // ref: cancel package \advance\dimen@ 2\p@ % "+2"
}
.cancel-lap {
margin-left: -0.2em; // \cancel does not affect horizontal spacing.
margin-right: -0.2em; // Apply negative margin to correct for 0.2em padding
} // inside the \cancel group.
.sout {
border-bottom-style: solid;
border-bottom-width: 0.08em;
}
.angl {
// from package actuarialangle, which is always used in a subscript.
box-sizing: border-box;
border-top: 0.049em solid; // defaultRuleThickness in scriptstyle
border-right: 0.049em solid; // ditto
margin-right: 0.03889em; // 1 mu
}
.anglpad {
padding: 0 0.03889em; // pad 1mu left and right (in scriptstyle)
}
.eqn-num::before {
counter-increment: katexEqnNo;
content: "(" counter(katexEqnNo) ")";
}
.mml-eqn-num::before {
counter-increment: mmlEqnNo;
content: "(" counter(mmlEqnNo) ")";
}
.mtr-glue {
width: 50%;
}
.cd-vert-arrow {
display: inline-block;
position: relative;
}
.cd-label-left {
display: inline-block;
position: absolute;
right: calc(50% + 0.3em);
text-align: left;
}
.cd-label-right {
display: inline-block;
position: absolute;
left: calc(50% + 0.3em);
text-align: right;
}
}
.katex-display {
display: block;
margin: $display-margin;
text-align: center;
> .katex {
display: block;
text-align: center;
white-space: nowrap;
> .katex-html {
display: block;
position: relative;
> .tag {
position: absolute;
right: 0;
}
}
}
}
// Left-justified tags (default is right-justified)
.katex-display.leqno > .katex > .katex-html > .tag {
left: 0;
right: auto;
}
// Flush-left display math
.katex-display.fleqn > .katex {
text-align: left;
padding-left: 2em;
}
// Automatic equation numbers for some environments.
// Use parallel counters for HTML and MathML.
body {
counter-reset: katexEqnNo mmlEqnNo;
}

545
node_modules/katex/src/svgGeometry.js generated vendored Normal file
View File

@@ -0,0 +1,545 @@
// @flow
/**
* This file provides support to domTree.js and delimiter.js.
* It's a storehouse of path geometry for SVG images.
*/
// In all paths below, the viewBox-to-em scale is 1000:1.
const hLinePad = 80; // padding above a sqrt vinculum. Prevents image cropping.
// The vinculum of a \sqrt can be made thicker by a KaTeX rendering option.
// Think of variable extraVinculum as two detours in the SVG path.
// The detour begins at the lower left of the area labeled extraVinculum below.
// The detour proceeds one extraVinculum distance up and slightly to the right,
// displacing the radiused corner between surd and vinculum. The radius is
// traversed as usual, then the detour resumes. It goes right, to the end of
// the very long vinculum, then down one extraVinculum distance,
// after which it resumes regular path geometry for the radical.
/* vinculum
/
/▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒←extraVinculum
/ █████████████████████←0.04em (40 unit) std vinculum thickness
/ /
/ /
/ /\
/ / surd
*/
const sqrtMain = function(extraVinculum: number, hLinePad: number): string {
// sqrtMain path geometry is from glyph U221A in the font KaTeX Main
return `M95,${622 + extraVinculum + hLinePad}
c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14
c0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54
c44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10
s173,378,173,378c0.7,0,35.3,-71,104,-213c68.7,-142,137.5,-285,206.5,-429
c69,-144,104.5,-217.7,106.5,-221
l${extraVinculum / 2.075} -${extraVinculum}
c5.3,-9.3,12,-14,20,-14
H400000v${40 + extraVinculum}H845.2724
s-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7
c-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z
M${834 + extraVinculum} ${hLinePad}h400000v${40 + extraVinculum}h-400000z`;
};
const sqrtSize1 = function(extraVinculum: number, hLinePad: number): string {
// size1 is from glyph U221A in the font KaTeX_Size1-Regular
return `M263,${601 + extraVinculum + hLinePad}c0.7,0,18,39.7,52,119
c34,79.3,68.167,158.7,102.5,238c34.3,79.3,51.8,119.3,52.5,120
c340,-704.7,510.7,-1060.3,512,-1067
l${extraVinculum / 2.084} -${extraVinculum}
c4.7,-7.3,11,-11,19,-11
H40000v${40 + extraVinculum}H1012.3
s-271.3,567,-271.3,567c-38.7,80.7,-84,175,-136,283c-52,108,-89.167,185.3,-111.5,232
c-22.3,46.7,-33.8,70.3,-34.5,71c-4.7,4.7,-12.3,7,-23,7s-12,-1,-12,-1
s-109,-253,-109,-253c-72.7,-168,-109.3,-252,-110,-252c-10.7,8,-22,16.7,-34,26
c-22,17.3,-33.3,26,-34,26s-26,-26,-26,-26s76,-59,76,-59s76,-60,76,-60z
M${1001 + extraVinculum} ${hLinePad}h400000v${40 + extraVinculum}h-400000z`;
};
const sqrtSize2 = function(extraVinculum: number, hLinePad: number): string {
// size2 is from glyph U221A in the font KaTeX_Size2-Regular
return `M983 ${10 + extraVinculum + hLinePad}
l${extraVinculum / 3.13} -${extraVinculum}
c4,-6.7,10,-10,18,-10 H400000v${40 + extraVinculum}
H1013.1s-83.4,268,-264.1,840c-180.7,572,-277,876.3,-289,913c-4.7,4.7,-12.7,7,-24,7
s-12,0,-12,0c-1.3,-3.3,-3.7,-11.7,-7,-25c-35.3,-125.3,-106.7,-373.3,-214,-744
c-10,12,-21,25,-33,39s-32,39,-32,39c-6,-5.3,-15,-14,-27,-26s25,-30,25,-30
c26.7,-32.7,52,-63,76,-91s52,-60,52,-60s208,722,208,722
c56,-175.3,126.3,-397.3,211,-666c84.7,-268.7,153.8,-488.2,207.5,-658.5
c53.7,-170.3,84.5,-266.8,92.5,-289.5z
M${1001 + extraVinculum} ${hLinePad}h400000v${40 + extraVinculum}h-400000z`;
};
const sqrtSize3 = function(extraVinculum: number, hLinePad: number): string {
// size3 is from glyph U221A in the font KaTeX_Size3-Regular
return `M424,${2398 + extraVinculum + hLinePad}
c-1.3,-0.7,-38.5,-172,-111.5,-514c-73,-342,-109.8,-513.3,-110.5,-514
c0,-2,-10.7,14.3,-32,49c-4.7,7.3,-9.8,15.7,-15.5,25c-5.7,9.3,-9.8,16,-12.5,20
s-5,7,-5,7c-4,-3.3,-8.3,-7.7,-13,-13s-13,-13,-13,-13s76,-122,76,-122s77,-121,77,-121
s209,968,209,968c0,-2,84.7,-361.7,254,-1079c169.3,-717.3,254.7,-1077.7,256,-1081
l${extraVinculum / 4.223} -${extraVinculum}c4,-6.7,10,-10,18,-10 H400000
v${40 + extraVinculum}H1014.6
s-87.3,378.7,-272.6,1166c-185.3,787.3,-279.3,1182.3,-282,1185
c-2,6,-10,9,-24,9
c-8,0,-12,-0.7,-12,-2z M${1001 + extraVinculum} ${hLinePad}
h400000v${40 + extraVinculum}h-400000z`;
};
const sqrtSize4 = function(extraVinculum: number, hLinePad: number): string {
// size4 is from glyph U221A in the font KaTeX_Size4-Regular
return `M473,${2713 + extraVinculum + hLinePad}
c339.3,-1799.3,509.3,-2700,510,-2702 l${extraVinculum / 5.298} -${extraVinculum}
c3.3,-7.3,9.3,-11,18,-11 H400000v${40 + extraVinculum}H1017.7
s-90.5,478,-276.2,1466c-185.7,988,-279.5,1483,-281.5,1485c-2,6,-10,9,-24,9
c-8,0,-12,-0.7,-12,-2c0,-1.3,-5.3,-32,-16,-92c-50.7,-293.3,-119.7,-693.3,-207,-1200
c0,-1.3,-5.3,8.7,-16,30c-10.7,21.3,-21.3,42.7,-32,64s-16,33,-16,33s-26,-26,-26,-26
s76,-153,76,-153s77,-151,77,-151c0.7,0.7,35.7,202,105,604c67.3,400.7,102,602.7,104,
606zM${1001 + extraVinculum} ${hLinePad}h400000v${40 + extraVinculum}H1017.7z`;
};
export const phasePath = function(y: number): string {
const x = y / 2; // x coordinate at top of angle
return `M400000 ${y} H0 L${x} 0 l65 45 L145 ${y - 80} H400000z`;
};
const sqrtTall = function(
extraVinculum: number,
hLinePad: number,
viewBoxHeight: number
): string {
// sqrtTall is from glyph U23B7 in the font KaTeX_Size4-Regular
// One path edge has a variable length. It runs vertically from the vinculum
// to a point near (14 units) the bottom of the surd. The vinculum
// is normally 40 units thick. So the length of the line in question is:
const vertSegment = viewBoxHeight - 54 - hLinePad - extraVinculum;
return `M702 ${extraVinculum + hLinePad}H400000${40 + extraVinculum}
H742v${vertSegment}l-4 4-4 4c-.667.7 -2 1.5-4 2.5s-4.167 1.833-6.5 2.5-5.5 1-9.5 1
h-12l-28-84c-16.667-52-96.667 -294.333-240-727l-212 -643 -85 170
c-4-3.333-8.333-7.667-13 -13l-13-13l77-155 77-156c66 199.333 139 419.667
219 661 l218 661zM702 ${hLinePad}H400000v${40 + extraVinculum}H742z`;
};
export const sqrtPath = function(
size: string,
extraVinculum: number,
viewBoxHeight: number
): string {
extraVinculum = 1000 * extraVinculum; // Convert from document ems to viewBox.
let path = "";
switch (size) {
case "sqrtMain":
path = sqrtMain(extraVinculum, hLinePad);
break;
case "sqrtSize1":
path = sqrtSize1(extraVinculum, hLinePad);
break;
case "sqrtSize2":
path = sqrtSize2(extraVinculum, hLinePad);
break;
case "sqrtSize3":
path = sqrtSize3(extraVinculum, hLinePad);
break;
case "sqrtSize4":
path = sqrtSize4(extraVinculum, hLinePad);
break;
case "sqrtTall":
path = sqrtTall(extraVinculum, hLinePad, viewBoxHeight);
}
return path;
};
export const innerPath = function(name: string, height: number): string {
// The inner part of stretchy tall delimiters
switch (name) {
case "\u239c":
return `M291 0 H417 V${height} H291z M291 0 H417 V${height} H291z`;
case "\u2223":
return `M145 0 H188 V${height} H145z M145 0 H188 V${height} H145z`;
case "\u2225":
return `M145 0 H188 V${height} H145z M145 0 H188 V${height} H145z` +
`M367 0 H410 V${height} H367z M367 0 H410 V${height} H367z`;
case "\u239f":
return `M457 0 H583 V${height} H457z M457 0 H583 V${height} H457z`;
case "\u23a2":
return `M319 0 H403 V${height} H319z M319 0 H403 V${height} H319z`;
case "\u23a5":
return `M263 0 H347 V${height} H263z M263 0 H347 V${height} H263z`;
case "\u23aa":
return `M384 0 H504 V${height} H384z M384 0 H504 V${height} H384z`;
case "\u23d0":
return `M312 0 H355 V${height} H312z M312 0 H355 V${height} H312z`;
case "\u2016":
return `M257 0 H300 V${height} H257z M257 0 H300 V${height} H257z` +
`M478 0 H521 V${height} H478z M478 0 H521 V${height} H478z`;
default:
return "";
}
};
export const path: {[string]: string} = {
// The doubleleftarrow geometry is from glyph U+21D0 in the font KaTeX Main
doubleleftarrow: `M262 157
l10-10c34-36 62.7-77 86-123 3.3-8 5-13.3 5-16 0-5.3-6.7-8-20-8-7.3
0-12.2.5-14.5 1.5-2.3 1-4.8 4.5-7.5 10.5-49.3 97.3-121.7 169.3-217 216-28
14-57.3 25-88 33-6.7 2-11 3.8-13 5.5-2 1.7-3 4.2-3 7.5s1 5.8 3 7.5
c2 1.7 6.3 3.5 13 5.5 68 17.3 128.2 47.8 180.5 91.5 52.3 43.7 93.8 96.2 124.5
157.5 9.3 8 15.3 12.3 18 13h6c12-.7 18-4 18-10 0-2-1.7-7-5-15-23.3-46-52-87
-86-123l-10-10h399738v-40H218c328 0 0 0 0 0l-10-8c-26.7-20-65.7-43-117-69 2.7
-2 6-3.7 10-5 36.7-16 72.3-37.3 107-64l10-8h399782v-40z
m8 0v40h399730v-40zm0 194v40h399730v-40z`,
// doublerightarrow is from glyph U+21D2 in font KaTeX Main
doublerightarrow: `M399738 392l
-10 10c-34 36-62.7 77-86 123-3.3 8-5 13.3-5 16 0 5.3 6.7 8 20 8 7.3 0 12.2-.5
14.5-1.5 2.3-1 4.8-4.5 7.5-10.5 49.3-97.3 121.7-169.3 217-216 28-14 57.3-25 88
-33 6.7-2 11-3.8 13-5.5 2-1.7 3-4.2 3-7.5s-1-5.8-3-7.5c-2-1.7-6.3-3.5-13-5.5-68
-17.3-128.2-47.8-180.5-91.5-52.3-43.7-93.8-96.2-124.5-157.5-9.3-8-15.3-12.3-18
-13h-6c-12 .7-18 4-18 10 0 2 1.7 7 5 15 23.3 46 52 87 86 123l10 10H0v40h399782
c-328 0 0 0 0 0l10 8c26.7 20 65.7 43 117 69-2.7 2-6 3.7-10 5-36.7 16-72.3 37.3
-107 64l-10 8H0v40zM0 157v40h399730v-40zm0 194v40h399730v-40z`,
// leftarrow is from glyph U+2190 in font KaTeX Main
leftarrow: `M400000 241H110l3-3c68.7-52.7 113.7-120
135-202 4-14.7 6-23 6-25 0-7.3-7-11-21-11-8 0-13.2.8-15.5 2.5-2.3 1.7-4.2 5.8
-5.5 12.5-1.3 4.7-2.7 10.3-4 17-12 48.7-34.8 92-68.5 130S65.3 228.3 18 247
c-10 4-16 7.7-18 11 0 8.7 6 14.3 18 17 47.3 18.7 87.8 47 121.5 85S196 441.3 208
490c.7 2 1.3 5 2 9s1.2 6.7 1.5 8c.3 1.3 1 3.3 2 6s2.2 4.5 3.5 5.5c1.3 1 3.3
1.8 6 2.5s6 1 10 1c14 0 21-3.7 21-11 0-2-2-10.3-6-25-20-79.3-65-146.7-135-202
l-3-3h399890zM100 241v40h399900v-40z`,
// overbrace is from glyphs U+23A9/23A8/23A7 in font KaTeX_Size4-Regular
leftbrace: `M6 548l-6-6v-35l6-11c56-104 135.3-181.3 238-232 57.3-28.7 117
-45 179-50h399577v120H403c-43.3 7-81 15-113 26-100.7 33-179.7 91-237 174-2.7
5-6 9-10 13-.7 1-7.3 1-20 1H6z`,
leftbraceunder: `M0 6l6-6h17c12.688 0 19.313.3 20 1 4 4 7.313 8.3 10 13
35.313 51.3 80.813 93.8 136.5 127.5 55.688 33.7 117.188 55.8 184.5 66.5.688
0 2 .3 4 1 18.688 2.7 76 4.3 172 5h399450v120H429l-6-1c-124.688-8-235-61.7
-331-161C60.687 138.7 32.312 99.3 7 54L0 41V6z`,
// overgroup is from the MnSymbol package (public domain)
leftgroup: `M400000 80
H435C64 80 168.3 229.4 21 260c-5.9 1.2-18 0-18 0-2 0-3-1-3-3v-38C76 61 257 0
435 0h399565z`,
leftgroupunder: `M400000 262
H435C64 262 168.3 112.6 21 82c-5.9-1.2-18 0-18 0-2 0-3 1-3 3v38c76 158 257 219
435 219h399565z`,
// Harpoons are from glyph U+21BD in font KaTeX Main
leftharpoon: `M0 267c.7 5.3 3 10 7 14h399993v-40H93c3.3
-3.3 10.2-9.5 20.5-18.5s17.8-15.8 22.5-20.5c50.7-52 88-110.3 112-175 4-11.3 5
-18.3 3-21-1.3-4-7.3-6-18-6-8 0-13 .7-15 2s-4.7 6.7-8 16c-42 98.7-107.3 174.7
-196 228-6.7 4.7-10.7 8-12 10-1.3 2-2 5.7-2 11zm100-26v40h399900v-40z`,
leftharpoonplus: `M0 267c.7 5.3 3 10 7 14h399993v-40H93c3.3-3.3 10.2-9.5
20.5-18.5s17.8-15.8 22.5-20.5c50.7-52 88-110.3 112-175 4-11.3 5-18.3 3-21-1.3
-4-7.3-6-18-6-8 0-13 .7-15 2s-4.7 6.7-8 16c-42 98.7-107.3 174.7-196 228-6.7 4.7
-10.7 8-12 10-1.3 2-2 5.7-2 11zm100-26v40h399900v-40zM0 435v40h400000v-40z
m0 0v40h400000v-40z`,
leftharpoondown: `M7 241c-4 4-6.333 8.667-7 14 0 5.333.667 9 2 11s5.333
5.333 12 10c90.667 54 156 130 196 228 3.333 10.667 6.333 16.333 9 17 2 .667 5
1 9 1h5c10.667 0 16.667-2 18-6 2-2.667 1-9.667-3-21-32-87.333-82.667-157.667
-152-211l-3-3h399907v-40zM93 281 H400000 v-40L7 241z`,
leftharpoondownplus: `M7 435c-4 4-6.3 8.7-7 14 0 5.3.7 9 2 11s5.3 5.3 12
10c90.7 54 156 130 196 228 3.3 10.7 6.3 16.3 9 17 2 .7 5 1 9 1h5c10.7 0 16.7
-2 18-6 2-2.7 1-9.7-3-21-32-87.3-82.7-157.7-152-211l-3-3h399907v-40H7zm93 0
v40h399900v-40zM0 241v40h399900v-40zm0 0v40h399900v-40z`,
// hook is from glyph U+21A9 in font KaTeX Main
lefthook: `M400000 281 H103s-33-11.2-61-33.5S0 197.3 0 164s14.2-61.2 42.5
-83.5C70.8 58.2 104 47 142 47 c16.7 0 25 6.7 25 20 0 12-8.7 18.7-26 20-40 3.3
-68.7 15.7-86 37-10 12-15 25.3-15 40 0 22.7 9.8 40.7 29.5 54 19.7 13.3 43.5 21
71.5 23h399859zM103 281v-40h399897v40z`,
leftlinesegment: `M40 281 V428 H0 V94 H40 V241 H400000 v40z
M40 281 V428 H0 V94 H40 V241 H400000 v40z`,
leftmapsto: `M40 281 V448H0V74H40V241H400000v40z
M40 281 V448H0V74H40V241H400000v40z`,
// tofrom is from glyph U+21C4 in font KaTeX AMS Regular
leftToFrom: `M0 147h400000v40H0zm0 214c68 40 115.7 95.7 143 167h22c15.3 0 23
-.3 23-1 0-1.3-5.3-13.7-16-37-18-35.3-41.3-69-70-101l-7-8h399905v-40H95l7-8
c28.7-32 52-65.7 70-101 10.7-23.3 16-35.7 16-37 0-.7-7.7-1-23-1h-22C115.7 265.3
68 321 0 361zm0-174v-40h399900v40zm100 154v40h399900v-40z`,
longequal: `M0 50 h400000 v40H0z m0 194h40000v40H0z
M0 50 h400000 v40H0z m0 194h40000v40H0z`,
midbrace: `M200428 334
c-100.7-8.3-195.3-44-280-108-55.3-42-101.7-93-139-153l-9-14c-2.7 4-5.7 8.7-9 14
-53.3 86.7-123.7 153-211 199-66.7 36-137.3 56.3-212 62H0V214h199568c178.3-11.7
311.7-78.3 403-201 6-8 9.7-12 11-12 .7-.7 6.7-1 18-1s17.3.3 18 1c1.3 0 5 4 11
12 44.7 59.3 101.3 106.3 170 141s145.3 54.3 229 60h199572v120z`,
midbraceunder: `M199572 214
c100.7 8.3 195.3 44 280 108 55.3 42 101.7 93 139 153l9 14c2.7-4 5.7-8.7 9-14
53.3-86.7 123.7-153 211-199 66.7-36 137.3-56.3 212-62h199568v120H200432c-178.3
11.7-311.7 78.3-403 201-6 8-9.7 12-11 12-.7.7-6.7 1-18 1s-17.3-.3-18-1c-1.3 0
-5-4-11-12-44.7-59.3-101.3-106.3-170-141s-145.3-54.3-229-60H0V214z`,
oiintSize1: `M512.6 71.6c272.6 0 320.3 106.8 320.3 178.2 0 70.8-47.7 177.6
-320.3 177.6S193.1 320.6 193.1 249.8c0-71.4 46.9-178.2 319.5-178.2z
m368.1 178.2c0-86.4-60.9-215.4-368.1-215.4-306.4 0-367.3 129-367.3 215.4 0 85.8
60.9 214.8 367.3 214.8 307.2 0 368.1-129 368.1-214.8z`,
oiintSize2: `M757.8 100.1c384.7 0 451.1 137.6 451.1 230 0 91.3-66.4 228.8
-451.1 228.8-386.3 0-452.7-137.5-452.7-228.8 0-92.4 66.4-230 452.7-230z
m502.4 230c0-111.2-82.4-277.2-502.4-277.2s-504 166-504 277.2
c0 110 84 276 504 276s502.4-166 502.4-276z`,
oiiintSize1: `M681.4 71.6c408.9 0 480.5 106.8 480.5 178.2 0 70.8-71.6 177.6
-480.5 177.6S202.1 320.6 202.1 249.8c0-71.4 70.5-178.2 479.3-178.2z
m525.8 178.2c0-86.4-86.8-215.4-525.7-215.4-437.9 0-524.7 129-524.7 215.4 0
85.8 86.8 214.8 524.7 214.8 438.9 0 525.7-129 525.7-214.8z`,
oiiintSize2: `M1021.2 53c603.6 0 707.8 165.8 707.8 277.2 0 110-104.2 275.8
-707.8 275.8-606 0-710.2-165.8-710.2-275.8C311 218.8 415.2 53 1021.2 53z
m770.4 277.1c0-131.2-126.4-327.6-770.5-327.6S248.4 198.9 248.4 330.1
c0 130 128.8 326.4 772.7 326.4s770.5-196.4 770.5-326.4z`,
rightarrow: `M0 241v40h399891c-47.3 35.3-84 78-110 128
-16.7 32-27.7 63.7-33 95 0 1.3-.2 2.7-.5 4-.3 1.3-.5 2.3-.5 3 0 7.3 6.7 11 20
11 8 0 13.2-.8 15.5-2.5 2.3-1.7 4.2-5.5 5.5-11.5 2-13.3 5.7-27 11-41 14.7-44.7
39-84.5 73-119.5s73.7-60.2 119-75.5c6-2 9-5.7 9-11s-3-9-9-11c-45.3-15.3-85
-40.5-119-75.5s-58.3-74.8-73-119.5c-4.7-14-8.3-27.3-11-40-1.3-6.7-3.2-10.8-5.5
-12.5-2.3-1.7-7.5-2.5-15.5-2.5-14 0-21 3.7-21 11 0 2 2 10.3 6 25 20.7 83.3 67
151.7 139 205zm0 0v40h399900v-40z`,
rightbrace: `M400000 542l
-6 6h-17c-12.7 0-19.3-.3-20-1-4-4-7.3-8.3-10-13-35.3-51.3-80.8-93.8-136.5-127.5
s-117.2-55.8-184.5-66.5c-.7 0-2-.3-4-1-18.7-2.7-76-4.3-172-5H0V214h399571l6 1
c124.7 8 235 61.7 331 161 31.3 33.3 59.7 72.7 85 118l7 13v35z`,
rightbraceunder: `M399994 0l6 6v35l-6 11c-56 104-135.3 181.3-238 232-57.3
28.7-117 45-179 50H-300V214h399897c43.3-7 81-15 113-26 100.7-33 179.7-91 237
-174 2.7-5 6-9 10-13 .7-1 7.3-1 20-1h17z`,
rightgroup: `M0 80h399565c371 0 266.7 149.4 414 180 5.9 1.2 18 0 18 0 2 0
3-1 3-3v-38c-76-158-257-219-435-219H0z`,
rightgroupunder: `M0 262h399565c371 0 266.7-149.4 414-180 5.9-1.2 18 0 18
0 2 0 3 1 3 3v38c-76 158-257 219-435 219H0z`,
rightharpoon: `M0 241v40h399993c4.7-4.7 7-9.3 7-14 0-9.3
-3.7-15.3-11-18-92.7-56.7-159-133.7-199-231-3.3-9.3-6-14.7-8-16-2-1.3-7-2-15-2
-10.7 0-16.7 2-18 6-2 2.7-1 9.7 3 21 15.3 42 36.7 81.8 64 119.5 27.3 37.7 58
69.2 92 94.5zm0 0v40h399900v-40z`,
rightharpoonplus: `M0 241v40h399993c4.7-4.7 7-9.3 7-14 0-9.3-3.7-15.3-11
-18-92.7-56.7-159-133.7-199-231-3.3-9.3-6-14.7-8-16-2-1.3-7-2-15-2-10.7 0-16.7
2-18 6-2 2.7-1 9.7 3 21 15.3 42 36.7 81.8 64 119.5 27.3 37.7 58 69.2 92 94.5z
m0 0v40h399900v-40z m100 194v40h399900v-40zm0 0v40h399900v-40z`,
rightharpoondown: `M399747 511c0 7.3 6.7 11 20 11 8 0 13-.8 15-2.5s4.7-6.8
8-15.5c40-94 99.3-166.3 178-217 13.3-8 20.3-12.3 21-13 5.3-3.3 8.5-5.8 9.5
-7.5 1-1.7 1.5-5.2 1.5-10.5s-2.3-10.3-7-15H0v40h399908c-34 25.3-64.7 57-92 95
-27.3 38-48.7 77.7-64 119-3.3 8.7-5 14-5 16zM0 241v40h399900v-40z`,
rightharpoondownplus: `M399747 705c0 7.3 6.7 11 20 11 8 0 13-.8
15-2.5s4.7-6.8 8-15.5c40-94 99.3-166.3 178-217 13.3-8 20.3-12.3 21-13 5.3-3.3
8.5-5.8 9.5-7.5 1-1.7 1.5-5.2 1.5-10.5s-2.3-10.3-7-15H0v40h399908c-34 25.3
-64.7 57-92 95-27.3 38-48.7 77.7-64 119-3.3 8.7-5 14-5 16zM0 435v40h399900v-40z
m0-194v40h400000v-40zm0 0v40h400000v-40z`,
righthook: `M399859 241c-764 0 0 0 0 0 40-3.3 68.7-15.7 86-37 10-12 15-25.3
15-40 0-22.7-9.8-40.7-29.5-54-19.7-13.3-43.5-21-71.5-23-17.3-1.3-26-8-26-20 0
-13.3 8.7-20 26-20 38 0 71 11.2 99 33.5 0 0 7 5.6 21 16.7 14 11.2 21 33.5 21
66.8s-14 61.2-42 83.5c-28 22.3-61 33.5-99 33.5L0 241z M0 281v-40h399859v40z`,
rightlinesegment: `M399960 241 V94 h40 V428 h-40 V281 H0 v-40z
M399960 241 V94 h40 V428 h-40 V281 H0 v-40z`,
rightToFrom: `M400000 167c-70.7-42-118-97.7-142-167h-23c-15.3 0-23 .3-23
1 0 1.3 5.3 13.7 16 37 18 35.3 41.3 69 70 101l7 8H0v40h399905l-7 8c-28.7 32
-52 65.7-70 101-10.7 23.3-16 35.7-16 37 0 .7 7.7 1 23 1h23c24-69.3 71.3-125 142
-167z M100 147v40h399900v-40zM0 341v40h399900v-40z`,
// twoheadleftarrow is from glyph U+219E in font KaTeX AMS Regular
twoheadleftarrow: `M0 167c68 40
115.7 95.7 143 167h22c15.3 0 23-.3 23-1 0-1.3-5.3-13.7-16-37-18-35.3-41.3-69
-70-101l-7-8h125l9 7c50.7 39.3 85 86 103 140h46c0-4.7-6.3-18.7-19-42-18-35.3
-40-67.3-66-96l-9-9h399716v-40H284l9-9c26-28.7 48-60.7 66-96 12.7-23.333 19
-37.333 19-42h-46c-18 54-52.3 100.7-103 140l-9 7H95l7-8c28.7-32 52-65.7 70-101
10.7-23.333 16-35.7 16-37 0-.7-7.7-1-23-1h-22C115.7 71.3 68 127 0 167z`,
twoheadrightarrow: `M400000 167
c-68-40-115.7-95.7-143-167h-22c-15.3 0-23 .3-23 1 0 1.3 5.3 13.7 16 37 18 35.3
41.3 69 70 101l7 8h-125l-9-7c-50.7-39.3-85-86-103-140h-46c0 4.7 6.3 18.7 19 42
18 35.3 40 67.3 66 96l9 9H0v40h399716l-9 9c-26 28.7-48 60.7-66 96-12.7 23.333
-19 37.333-19 42h46c18-54 52.3-100.7 103-140l9-7h125l-7 8c-28.7 32-52 65.7-70
101-10.7 23.333-16 35.7-16 37 0 .7 7.7 1 23 1h22c27.3-71.3 75-127 143-167z`,
// tilde1 is a modified version of a glyph from the MnSymbol package
tilde1: `M200 55.538c-77 0-168 73.953-177 73.953-3 0-7
-2.175-9-5.437L2 97c-1-2-2-4-2-6 0-4 2-7 5-9l20-12C116 12 171 0 207 0c86 0
114 68 191 68 78 0 168-68 177-68 4 0 7 2 9 5l12 19c1 2.175 2 4.35 2 6.525 0
4.35-2 7.613-5 9.788l-19 13.05c-92 63.077-116.937 75.308-183 76.128
-68.267.847-113-73.952-191-73.952z`,
// ditto tilde2, tilde3, & tilde4
tilde2: `M344 55.266c-142 0-300.638 81.316-311.5 86.418
-8.01 3.762-22.5 10.91-23.5 5.562L1 120c-1-2-1-3-1-4 0-5 3-9 8-10l18.4-9C160.9
31.9 283 0 358 0c148 0 188 122 331 122s314-97 326-97c4 0 8 2 10 7l7 21.114
c1 2.14 1 3.21 1 4.28 0 5.347-3 9.626-7 10.696l-22.3 12.622C852.6 158.372 751
181.476 676 181.476c-149 0-189-126.21-332-126.21z`,
tilde3: `M786 59C457 59 32 175.242 13 175.242c-6 0-10-3.457
-11-10.37L.15 138c-1-7 3-12 10-13l19.2-6.4C378.4 40.7 634.3 0 804.3 0c337 0
411.8 157 746.8 157 328 0 754-112 773-112 5 0 10 3 11 9l1 14.075c1 8.066-.697
16.595-6.697 17.492l-21.052 7.31c-367.9 98.146-609.15 122.696-778.15 122.696
-338 0-409-156.573-744-156.573z`,
tilde4: `M786 58C457 58 32 177.487 13 177.487c-6 0-10-3.345
-11-10.035L.15 143c-1-7 3-12 10-13l22-6.7C381.2 35 637.15 0 807.15 0c337 0 409
177 744 177 328 0 754-127 773-127 5 0 10 3 11 9l1 14.794c1 7.805-3 13.38-9
14.495l-20.7 5.574c-366.85 99.79-607.3 139.372-776.3 139.372-338 0-409
-175.236-744-175.236z`,
// vec is from glyph U+20D7 in font KaTeX Main
vec: `M377 20c0-5.333 1.833-10 5.5-14S391 0 397 0c4.667 0 8.667 1.667 12 5
3.333 2.667 6.667 9 10 19 6.667 24.667 20.333 43.667 41 57 7.333 4.667 11
10.667 11 18 0 6-1 10-3 12s-6.667 5-14 9c-28.667 14.667-53.667 35.667-75 63
-1.333 1.333-3.167 3.5-5.5 6.5s-4 4.833-5 5.5c-1 .667-2.5 1.333-4.5 2s-4.333 1
-7 1c-4.667 0-9.167-1.833-13.5-5.5S337 184 337 178c0-12.667 15.667-32.333 47-59
H213l-171-1c-8.667-6-13-12.333-13-19 0-4.667 4.333-11.333 13-20h359
c-16-25.333-24-45-24-59z`,
// widehat1 is a modified version of a glyph from the MnSymbol package
widehat1: `M529 0h5l519 115c5 1 9 5 9 10 0 1-1 2-1 3l-4 22
c-1 5-5 9-11 9h-2L532 67 19 159h-2c-5 0-9-4-11-9l-5-22c-1-6 2-12 8-13z`,
// ditto widehat2, widehat3, & widehat4
widehat2: `M1181 0h2l1171 176c6 0 10 5 10 11l-2 23c-1 6-5 10
-11 10h-1L1182 67 15 220h-1c-6 0-10-4-11-10l-2-23c-1-6 4-11 10-11z`,
widehat3: `M1181 0h2l1171 236c6 0 10 5 10 11l-2 23c-1 6-5 10
-11 10h-1L1182 67 15 280h-1c-6 0-10-4-11-10l-2-23c-1-6 4-11 10-11z`,
widehat4: `M1181 0h2l1171 296c6 0 10 5 10 11l-2 23c-1 6-5 10
-11 10h-1L1182 67 15 340h-1c-6 0-10-4-11-10l-2-23c-1-6 4-11 10-11z`,
// widecheck paths are all inverted versions of widehat
widecheck1: `M529,159h5l519,-115c5,-1,9,-5,9,-10c0,-1,-1,-2,-1,-3l-4,-22c-1,
-5,-5,-9,-11,-9h-2l-512,92l-513,-92h-2c-5,0,-9,4,-11,9l-5,22c-1,6,2,12,8,13z`,
widecheck2: `M1181,220h2l1171,-176c6,0,10,-5,10,-11l-2,-23c-1,-6,-5,-10,
-11,-10h-1l-1168,153l-1167,-153h-1c-6,0,-10,4,-11,10l-2,23c-1,6,4,11,10,11z`,
widecheck3: `M1181,280h2l1171,-236c6,0,10,-5,10,-11l-2,-23c-1,-6,-5,-10,
-11,-10h-1l-1168,213l-1167,-213h-1c-6,0,-10,4,-11,10l-2,23c-1,6,4,11,10,11z`,
widecheck4: `M1181,340h2l1171,-296c6,0,10,-5,10,-11l-2,-23c-1,-6,-5,-10,
-11,-10h-1l-1168,273l-1167,-273h-1c-6,0,-10,4,-11,10l-2,23c-1,6,4,11,10,11z`,
// The next ten paths support reaction arrows from the mhchem package.
// Arrows for \ce{<-->} are offset from xAxis by 0.22ex, per mhchem in LaTeX
// baraboveleftarrow is mostly from glyph U+2190 in font KaTeX Main
baraboveleftarrow: `M400000 620h-399890l3 -3c68.7 -52.7 113.7 -120 135 -202
c4 -14.7 6 -23 6 -25c0 -7.3 -7 -11 -21 -11c-8 0 -13.2 0.8 -15.5 2.5
c-2.3 1.7 -4.2 5.8 -5.5 12.5c-1.3 4.7 -2.7 10.3 -4 17c-12 48.7 -34.8 92 -68.5 130
s-74.2 66.3 -121.5 85c-10 4 -16 7.7 -18 11c0 8.7 6 14.3 18 17c47.3 18.7 87.8 47
121.5 85s56.5 81.3 68.5 130c0.7 2 1.3 5 2 9s1.2 6.7 1.5 8c0.3 1.3 1 3.3 2 6
s2.2 4.5 3.5 5.5c1.3 1 3.3 1.8 6 2.5s6 1 10 1c14 0 21 -3.7 21 -11
c0 -2 -2 -10.3 -6 -25c-20 -79.3 -65 -146.7 -135 -202l-3 -3h399890z
M100 620v40h399900v-40z M0 241v40h399900v-40zM0 241v40h399900v-40z`,
// rightarrowabovebar is mostly from glyph U+2192, KaTeX Main
rightarrowabovebar: `M0 241v40h399891c-47.3 35.3-84 78-110 128-16.7 32
-27.7 63.7-33 95 0 1.3-.2 2.7-.5 4-.3 1.3-.5 2.3-.5 3 0 7.3 6.7 11 20 11 8 0
13.2-.8 15.5-2.5 2.3-1.7 4.2-5.5 5.5-11.5 2-13.3 5.7-27 11-41 14.7-44.7 39
-84.5 73-119.5s73.7-60.2 119-75.5c6-2 9-5.7 9-11s-3-9-9-11c-45.3-15.3-85-40.5
-119-75.5s-58.3-74.8-73-119.5c-4.7-14-8.3-27.3-11-40-1.3-6.7-3.2-10.8-5.5
-12.5-2.3-1.7-7.5-2.5-15.5-2.5-14 0-21 3.7-21 11 0 2 2 10.3 6 25 20.7 83.3 67
151.7 139 205zm96 379h399894v40H0zm0 0h399904v40H0z`,
// The short left harpoon has 0.5em (i.e. 500 units) kern on the left end.
// Ref from mhchem.sty: \rlap{\raisebox{-.22ex}{$\kern0.5em
baraboveshortleftharpoon: `M507,435c-4,4,-6.3,8.7,-7,14c0,5.3,0.7,9,2,11
c1.3,2,5.3,5.3,12,10c90.7,54,156,130,196,228c3.3,10.7,6.3,16.3,9,17
c2,0.7,5,1,9,1c0,0,5,0,5,0c10.7,0,16.7,-2,18,-6c2,-2.7,1,-9.7,-3,-21
c-32,-87.3,-82.7,-157.7,-152,-211c0,0,-3,-3,-3,-3l399351,0l0,-40
c-398570,0,-399437,0,-399437,0z M593 435 v40 H399500 v-40z
M0 281 v-40 H399908 v40z M0 281 v-40 H399908 v40z`,
rightharpoonaboveshortbar: `M0,241 l0,40c399126,0,399993,0,399993,0
c4.7,-4.7,7,-9.3,7,-14c0,-9.3,-3.7,-15.3,-11,-18c-92.7,-56.7,-159,-133.7,-199,
-231c-3.3,-9.3,-6,-14.7,-8,-16c-2,-1.3,-7,-2,-15,-2c-10.7,0,-16.7,2,-18,6
c-2,2.7,-1,9.7,3,21c15.3,42,36.7,81.8,64,119.5c27.3,37.7,58,69.2,92,94.5z
M0 241 v40 H399908 v-40z M0 475 v-40 H399500 v40z M0 475 v-40 H399500 v40z`,
shortbaraboveleftharpoon: `M7,435c-4,4,-6.3,8.7,-7,14c0,5.3,0.7,9,2,11
c1.3,2,5.3,5.3,12,10c90.7,54,156,130,196,228c3.3,10.7,6.3,16.3,9,17c2,0.7,5,1,9,
1c0,0,5,0,5,0c10.7,0,16.7,-2,18,-6c2,-2.7,1,-9.7,-3,-21c-32,-87.3,-82.7,-157.7,
-152,-211c0,0,-3,-3,-3,-3l399907,0l0,-40c-399126,0,-399993,0,-399993,0z
M93 435 v40 H400000 v-40z M500 241 v40 H400000 v-40z M500 241 v40 H400000 v-40z`,
shortrightharpoonabovebar: `M53,241l0,40c398570,0,399437,0,399437,0
c4.7,-4.7,7,-9.3,7,-14c0,-9.3,-3.7,-15.3,-11,-18c-92.7,-56.7,-159,-133.7,-199,
-231c-3.3,-9.3,-6,-14.7,-8,-16c-2,-1.3,-7,-2,-15,-2c-10.7,0,-16.7,2,-18,6
c-2,2.7,-1,9.7,3,21c15.3,42,36.7,81.8,64,119.5c27.3,37.7,58,69.2,92,94.5z
M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`,
};
export const tallDelim = function(label: string, midHeight: number): string {
switch (label) {
case "lbrack":
return `M403 1759 V84 H666 V0 H319 V1759 v${midHeight} v1759 h347 v-84
H403z M403 1759 V0 H319 V1759 v${midHeight} v1759 h84z`;
case "rbrack":
return `M347 1759 V0 H0 V84 H263 V1759 v${midHeight} v1759 H0 v84 H347z
M347 1759 V0 H263 V1759 v${midHeight} v1759 h84z`;
case "vert":
return `M145 15 v585 v${midHeight} v585 c2.667,10,9.667,15,21,15
c10,0,16.667,-5,20,-15 v-585 v${-midHeight} v-585 c-2.667,-10,-9.667,-15,-21,-15
c-10,0,-16.667,5,-20,15z M188 15 H145 v585 v${midHeight} v585 h43z`;
case "doublevert":
return `M145 15 v585 v${midHeight} v585 c2.667,10,9.667,15,21,15
c10,0,16.667,-5,20,-15 v-585 v${-midHeight} v-585 c-2.667,-10,-9.667,-15,-21,-15
c-10,0,-16.667,5,-20,15z M188 15 H145 v585 v${midHeight} v585 h43z
M367 15 v585 v${midHeight} v585 c2.667,10,9.667,15,21,15
c10,0,16.667,-5,20,-15 v-585 v${-midHeight} v-585 c-2.667,-10,-9.667,-15,-21,-15
c-10,0,-16.667,5,-20,15z M410 15 H367 v585 v${midHeight} v585 h43z`;
case "lfloor":
return `M319 602 V0 H403 V602 v${midHeight} v1715 h263 v84 H319z
MM319 602 V0 H403 V602 v${midHeight} v1715 H319z`;
case "rfloor":
return `M319 602 V0 H403 V602 v${midHeight} v1799 H0 v-84 H319z
MM319 602 V0 H403 V602 v${midHeight} v1715 H319z`;
case "lceil":
return `M403 1759 V84 H666 V0 H319 V1759 v${midHeight} v602 h84z
M403 1759 V0 H319 V1759 v${midHeight} v602 h84z`;
case "rceil":
return `M347 1759 V0 H0 V84 H263 V1759 v${midHeight} v602 h84z
M347 1759 V0 h-84 V1759 v${midHeight} v602 h84z`;
case "lparen":
return `M863,9c0,-2,-2,-5,-6,-9c0,0,-17,0,-17,0c-12.7,0,-19.3,0.3,-20,1
c-5.3,5.3,-10.3,11,-15,17c-242.7,294.7,-395.3,682,-458,1162c-21.3,163.3,-33.3,349,
-36,557 l0,${midHeight + 84}c0.2,6,0,26,0,60c2,159.3,10,310.7,24,454c53.3,528,210,
949.7,470,1265c4.7,6,9.7,11.7,15,17c0.7,0.7,7,1,19,1c0,0,18,0,18,0c4,-4,6,-7,6,-9
c0,-2.7,-3.3,-8.7,-10,-18c-135.3,-192.7,-235.5,-414.3,-300.5,-665c-65,-250.7,-102.5,
-544.7,-112.5,-882c-2,-104,-3,-167,-3,-189
l0,-${midHeight + 92}c0,-162.7,5.7,-314,17,-454c20.7,-272,63.7,-513,129,-723c65.3,
-210,155.3,-396.3,270,-559c6.7,-9.3,10,-15.3,10,-18z`;
case "rparen":
return `M76,0c-16.7,0,-25,3,-25,9c0,2,2,6.3,6,13c21.3,28.7,42.3,60.3,
63,95c96.7,156.7,172.8,332.5,228.5,527.5c55.7,195,92.8,416.5,111.5,664.5
c11.3,139.3,17,290.7,17,454c0,28,1.7,43,3.3,45l0,${midHeight + 9}
c-3,4,-3.3,16.7,-3.3,38c0,162,-5.7,313.7,-17,455c-18.7,248,-55.8,469.3,-111.5,664
c-55.7,194.7,-131.8,370.3,-228.5,527c-20.7,34.7,-41.7,66.3,-63,95c-2,3.3,-4,7,-6,11
c0,7.3,5.7,11,17,11c0,0,11,0,11,0c9.3,0,14.3,-0.3,15,-1c5.3,-5.3,10.3,-11,15,-17
c242.7,-294.7,395.3,-681.7,458,-1161c21.3,-164.7,33.3,-350.7,36,-558
l0,-${midHeight + 144}c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
-470,-1265c-4.7,-6,-9.7,-11.7,-15,-17c-0.7,-0.7,-6.7,-1,-18,-1z`;
default:
// We should not ever get here.
throw new Error("Unknown stretchy delimiter.");
}
};

890
node_modules/katex/src/symbols.js generated vendored Normal file
View File

@@ -0,0 +1,890 @@
// @flow
/**
* This file holds a list of all no-argument functions and single-character
* symbols (like 'a' or ';').
*
* For each of the symbols, there are three properties they can have:
* - font (required): the font to be used for this symbol. Either "main" (the
normal font), or "ams" (the ams fonts).
* - group (required): the ParseNode group type the symbol should have (i.e.
"textord", "mathord", etc).
See https://github.com/KaTeX/KaTeX/wiki/Examining-TeX#group-types
* - replace: the character that this symbol or function should be
* replaced with (i.e. "\phi" has a replace value of "\u03d5", the phi
* character in the main font).
*
* The outermost map in the table indicates what mode the symbols should be
* accepted in (e.g. "math" or "text").
*/
import type {Mode} from "./types";
type Font = "main" | "ams";
// Some of these have a "-token" suffix since these are also used as `ParseNode`
// types for raw text tokens, and we want to avoid conflicts with higher-level
// `ParseNode` types. These `ParseNode`s are constructed within `Parser` by
// looking up the `symbols` map.
export const ATOMS = {
"bin": 1,
"close": 1,
"inner": 1,
"open": 1,
"punct": 1,
"rel": 1,
};
export const NON_ATOMS = {
"accent-token": 1,
"mathord": 1,
"op-token": 1,
"spacing": 1,
"textord": 1,
};
export type Atom = $Keys<typeof ATOMS>;
export type NonAtom = $Keys<typeof NON_ATOMS>
export type Group = Atom | NonAtom;
type CharInfoMap = {[string]: {font: Font, group: Group, replace: ?string}};
const symbols: {[Mode]: CharInfoMap} = {
"math": {},
"text": {},
};
export default symbols;
/** `acceptUnicodeChar = true` is only applicable if `replace` is set. */
export function defineSymbol(
mode: Mode,
font: Font,
group: Group,
replace: ?string,
name: string,
acceptUnicodeChar?: boolean,
) {
symbols[mode][name] = {font, group, replace};
if (acceptUnicodeChar && replace) {
symbols[mode][replace] = symbols[mode][name];
}
}
// Some abbreviations for commonly used strings.
// This helps minify the code, and also spotting typos using jshint.
// modes:
const math = "math";
const text = "text";
// fonts:
const main = "main";
const ams = "ams";
// groups:
const accent = "accent-token";
const bin = "bin";
const close = "close";
const inner = "inner";
const mathord = "mathord";
const op = "op-token";
const open = "open";
const punct = "punct";
const rel = "rel";
const spacing = "spacing";
const textord = "textord";
// Now comes the symbol table
// Relation Symbols
defineSymbol(math, main, rel, "\u2261", "\\equiv", true);
defineSymbol(math, main, rel, "\u227a", "\\prec", true);
defineSymbol(math, main, rel, "\u227b", "\\succ", true);
defineSymbol(math, main, rel, "\u223c", "\\sim", true);
defineSymbol(math, main, rel, "\u22a5", "\\perp");
defineSymbol(math, main, rel, "\u2aaf", "\\preceq", true);
defineSymbol(math, main, rel, "\u2ab0", "\\succeq", true);
defineSymbol(math, main, rel, "\u2243", "\\simeq", true);
defineSymbol(math, main, rel, "\u2223", "\\mid", true);
defineSymbol(math, main, rel, "\u226a", "\\ll", true);
defineSymbol(math, main, rel, "\u226b", "\\gg", true);
defineSymbol(math, main, rel, "\u224d", "\\asymp", true);
defineSymbol(math, main, rel, "\u2225", "\\parallel");
defineSymbol(math, main, rel, "\u22c8", "\\bowtie", true);
defineSymbol(math, main, rel, "\u2323", "\\smile", true);
defineSymbol(math, main, rel, "\u2291", "\\sqsubseteq", true);
defineSymbol(math, main, rel, "\u2292", "\\sqsupseteq", true);
defineSymbol(math, main, rel, "\u2250", "\\doteq", true);
defineSymbol(math, main, rel, "\u2322", "\\frown", true);
defineSymbol(math, main, rel, "\u220b", "\\ni", true);
defineSymbol(math, main, rel, "\u221d", "\\propto", true);
defineSymbol(math, main, rel, "\u22a2", "\\vdash", true);
defineSymbol(math, main, rel, "\u22a3", "\\dashv", true);
defineSymbol(math, main, rel, "\u220b", "\\owns");
// Punctuation
defineSymbol(math, main, punct, "\u002e", "\\ldotp");
defineSymbol(math, main, punct, "\u22c5", "\\cdotp");
// Misc Symbols
defineSymbol(math, main, textord, "\u0023", "\\#");
defineSymbol(text, main, textord, "\u0023", "\\#");
defineSymbol(math, main, textord, "\u0026", "\\&");
defineSymbol(text, main, textord, "\u0026", "\\&");
defineSymbol(math, main, textord, "\u2135", "\\aleph", true);
defineSymbol(math, main, textord, "\u2200", "\\forall", true);
defineSymbol(math, main, textord, "\u210f", "\\hbar", true);
defineSymbol(math, main, textord, "\u2203", "\\exists", true);
defineSymbol(math, main, textord, "\u2207", "\\nabla", true);
defineSymbol(math, main, textord, "\u266d", "\\flat", true);
defineSymbol(math, main, textord, "\u2113", "\\ell", true);
defineSymbol(math, main, textord, "\u266e", "\\natural", true);
defineSymbol(math, main, textord, "\u2663", "\\clubsuit", true);
defineSymbol(math, main, textord, "\u2118", "\\wp", true);
defineSymbol(math, main, textord, "\u266f", "\\sharp", true);
defineSymbol(math, main, textord, "\u2662", "\\diamondsuit", true);
defineSymbol(math, main, textord, "\u211c", "\\Re", true);
defineSymbol(math, main, textord, "\u2661", "\\heartsuit", true);
defineSymbol(math, main, textord, "\u2111", "\\Im", true);
defineSymbol(math, main, textord, "\u2660", "\\spadesuit", true);
defineSymbol(math, main, textord, "\u00a7", "\\S", true);
defineSymbol(text, main, textord, "\u00a7", "\\S");
defineSymbol(math, main, textord, "\u00b6", "\\P", true);
defineSymbol(text, main, textord, "\u00b6", "\\P");
// Math and Text
defineSymbol(math, main, textord, "\u2020", "\\dag");
defineSymbol(text, main, textord, "\u2020", "\\dag");
defineSymbol(text, main, textord, "\u2020", "\\textdagger");
defineSymbol(math, main, textord, "\u2021", "\\ddag");
defineSymbol(text, main, textord, "\u2021", "\\ddag");
defineSymbol(text, main, textord, "\u2021", "\\textdaggerdbl");
// Large Delimiters
defineSymbol(math, main, close, "\u23b1", "\\rmoustache", true);
defineSymbol(math, main, open, "\u23b0", "\\lmoustache", true);
defineSymbol(math, main, close, "\u27ef", "\\rgroup", true);
defineSymbol(math, main, open, "\u27ee", "\\lgroup", true);
// Binary Operators
defineSymbol(math, main, bin, "\u2213", "\\mp", true);
defineSymbol(math, main, bin, "\u2296", "\\ominus", true);
defineSymbol(math, main, bin, "\u228e", "\\uplus", true);
defineSymbol(math, main, bin, "\u2293", "\\sqcap", true);
defineSymbol(math, main, bin, "\u2217", "\\ast");
defineSymbol(math, main, bin, "\u2294", "\\sqcup", true);
defineSymbol(math, main, bin, "\u25ef", "\\bigcirc", true);
defineSymbol(math, main, bin, "\u2219", "\\bullet", true);
defineSymbol(math, main, bin, "\u2021", "\\ddagger");
defineSymbol(math, main, bin, "\u2240", "\\wr", true);
defineSymbol(math, main, bin, "\u2a3f", "\\amalg");
defineSymbol(math, main, bin, "\u0026", "\\And"); // from amsmath
// Arrow Symbols
defineSymbol(math, main, rel, "\u27f5", "\\longleftarrow", true);
defineSymbol(math, main, rel, "\u21d0", "\\Leftarrow", true);
defineSymbol(math, main, rel, "\u27f8", "\\Longleftarrow", true);
defineSymbol(math, main, rel, "\u27f6", "\\longrightarrow", true);
defineSymbol(math, main, rel, "\u21d2", "\\Rightarrow", true);
defineSymbol(math, main, rel, "\u27f9", "\\Longrightarrow", true);
defineSymbol(math, main, rel, "\u2194", "\\leftrightarrow", true);
defineSymbol(math, main, rel, "\u27f7", "\\longleftrightarrow", true);
defineSymbol(math, main, rel, "\u21d4", "\\Leftrightarrow", true);
defineSymbol(math, main, rel, "\u27fa", "\\Longleftrightarrow", true);
defineSymbol(math, main, rel, "\u21a6", "\\mapsto", true);
defineSymbol(math, main, rel, "\u27fc", "\\longmapsto", true);
defineSymbol(math, main, rel, "\u2197", "\\nearrow", true);
defineSymbol(math, main, rel, "\u21a9", "\\hookleftarrow", true);
defineSymbol(math, main, rel, "\u21aa", "\\hookrightarrow", true);
defineSymbol(math, main, rel, "\u2198", "\\searrow", true);
defineSymbol(math, main, rel, "\u21bc", "\\leftharpoonup", true);
defineSymbol(math, main, rel, "\u21c0", "\\rightharpoonup", true);
defineSymbol(math, main, rel, "\u2199", "\\swarrow", true);
defineSymbol(math, main, rel, "\u21bd", "\\leftharpoondown", true);
defineSymbol(math, main, rel, "\u21c1", "\\rightharpoondown", true);
defineSymbol(math, main, rel, "\u2196", "\\nwarrow", true);
defineSymbol(math, main, rel, "\u21cc", "\\rightleftharpoons", true);
// AMS Negated Binary Relations
defineSymbol(math, ams, rel, "\u226e", "\\nless", true);
// Symbol names preceded by "@" each have a corresponding macro.
defineSymbol(math, ams, rel, "\ue010", "\\@nleqslant");
defineSymbol(math, ams, rel, "\ue011", "\\@nleqq");
defineSymbol(math, ams, rel, "\u2a87", "\\lneq", true);
defineSymbol(math, ams, rel, "\u2268", "\\lneqq", true);
defineSymbol(math, ams, rel, "\ue00c", "\\@lvertneqq");
defineSymbol(math, ams, rel, "\u22e6", "\\lnsim", true);
defineSymbol(math, ams, rel, "\u2a89", "\\lnapprox", true);
defineSymbol(math, ams, rel, "\u2280", "\\nprec", true);
// unicode-math maps \u22e0 to \npreccurlyeq. We'll use the AMS synonym.
defineSymbol(math, ams, rel, "\u22e0", "\\npreceq", true);
defineSymbol(math, ams, rel, "\u22e8", "\\precnsim", true);
defineSymbol(math, ams, rel, "\u2ab9", "\\precnapprox", true);
defineSymbol(math, ams, rel, "\u2241", "\\nsim", true);
defineSymbol(math, ams, rel, "\ue006", "\\@nshortmid");
defineSymbol(math, ams, rel, "\u2224", "\\nmid", true);
defineSymbol(math, ams, rel, "\u22ac", "\\nvdash", true);
defineSymbol(math, ams, rel, "\u22ad", "\\nvDash", true);
defineSymbol(math, ams, rel, "\u22ea", "\\ntriangleleft");
defineSymbol(math, ams, rel, "\u22ec", "\\ntrianglelefteq", true);
defineSymbol(math, ams, rel, "\u228a", "\\subsetneq", true);
defineSymbol(math, ams, rel, "\ue01a", "\\@varsubsetneq");
defineSymbol(math, ams, rel, "\u2acb", "\\subsetneqq", true);
defineSymbol(math, ams, rel, "\ue017", "\\@varsubsetneqq");
defineSymbol(math, ams, rel, "\u226f", "\\ngtr", true);
defineSymbol(math, ams, rel, "\ue00f", "\\@ngeqslant");
defineSymbol(math, ams, rel, "\ue00e", "\\@ngeqq");
defineSymbol(math, ams, rel, "\u2a88", "\\gneq", true);
defineSymbol(math, ams, rel, "\u2269", "\\gneqq", true);
defineSymbol(math, ams, rel, "\ue00d", "\\@gvertneqq");
defineSymbol(math, ams, rel, "\u22e7", "\\gnsim", true);
defineSymbol(math, ams, rel, "\u2a8a", "\\gnapprox", true);
defineSymbol(math, ams, rel, "\u2281", "\\nsucc", true);
// unicode-math maps \u22e1 to \nsucccurlyeq. We'll use the AMS synonym.
defineSymbol(math, ams, rel, "\u22e1", "\\nsucceq", true);
defineSymbol(math, ams, rel, "\u22e9", "\\succnsim", true);
defineSymbol(math, ams, rel, "\u2aba", "\\succnapprox", true);
// unicode-math maps \u2246 to \simneqq. We'll use the AMS synonym.
defineSymbol(math, ams, rel, "\u2246", "\\ncong", true);
defineSymbol(math, ams, rel, "\ue007", "\\@nshortparallel");
defineSymbol(math, ams, rel, "\u2226", "\\nparallel", true);
defineSymbol(math, ams, rel, "\u22af", "\\nVDash", true);
defineSymbol(math, ams, rel, "\u22eb", "\\ntriangleright");
defineSymbol(math, ams, rel, "\u22ed", "\\ntrianglerighteq", true);
defineSymbol(math, ams, rel, "\ue018", "\\@nsupseteqq");
defineSymbol(math, ams, rel, "\u228b", "\\supsetneq", true);
defineSymbol(math, ams, rel, "\ue01b", "\\@varsupsetneq");
defineSymbol(math, ams, rel, "\u2acc", "\\supsetneqq", true);
defineSymbol(math, ams, rel, "\ue019", "\\@varsupsetneqq");
defineSymbol(math, ams, rel, "\u22ae", "\\nVdash", true);
defineSymbol(math, ams, rel, "\u2ab5", "\\precneqq", true);
defineSymbol(math, ams, rel, "\u2ab6", "\\succneqq", true);
defineSymbol(math, ams, rel, "\ue016", "\\@nsubseteqq");
defineSymbol(math, ams, bin, "\u22b4", "\\unlhd");
defineSymbol(math, ams, bin, "\u22b5", "\\unrhd");
// AMS Negated Arrows
defineSymbol(math, ams, rel, "\u219a", "\\nleftarrow", true);
defineSymbol(math, ams, rel, "\u219b", "\\nrightarrow", true);
defineSymbol(math, ams, rel, "\u21cd", "\\nLeftarrow", true);
defineSymbol(math, ams, rel, "\u21cf", "\\nRightarrow", true);
defineSymbol(math, ams, rel, "\u21ae", "\\nleftrightarrow", true);
defineSymbol(math, ams, rel, "\u21ce", "\\nLeftrightarrow", true);
// AMS Misc
defineSymbol(math, ams, rel, "\u25b3", "\\vartriangle");
defineSymbol(math, ams, textord, "\u210f", "\\hslash");
defineSymbol(math, ams, textord, "\u25bd", "\\triangledown");
defineSymbol(math, ams, textord, "\u25ca", "\\lozenge");
defineSymbol(math, ams, textord, "\u24c8", "\\circledS");
defineSymbol(math, ams, textord, "\u00ae", "\\circledR");
defineSymbol(text, ams, textord, "\u00ae", "\\circledR");
defineSymbol(math, ams, textord, "\u2221", "\\measuredangle", true);
defineSymbol(math, ams, textord, "\u2204", "\\nexists");
defineSymbol(math, ams, textord, "\u2127", "\\mho");
defineSymbol(math, ams, textord, "\u2132", "\\Finv", true);
defineSymbol(math, ams, textord, "\u2141", "\\Game", true);
defineSymbol(math, ams, textord, "\u2035", "\\backprime");
defineSymbol(math, ams, textord, "\u25b2", "\\blacktriangle");
defineSymbol(math, ams, textord, "\u25bc", "\\blacktriangledown");
defineSymbol(math, ams, textord, "\u25a0", "\\blacksquare");
defineSymbol(math, ams, textord, "\u29eb", "\\blacklozenge");
defineSymbol(math, ams, textord, "\u2605", "\\bigstar");
defineSymbol(math, ams, textord, "\u2222", "\\sphericalangle", true);
defineSymbol(math, ams, textord, "\u2201", "\\complement", true);
// unicode-math maps U+F0 to \matheth. We map to AMS function \eth
defineSymbol(math, ams, textord, "\u00f0", "\\eth", true);
defineSymbol(text, main, textord, "\u00f0", "\u00f0");
defineSymbol(math, ams, textord, "\u2571", "\\diagup");
defineSymbol(math, ams, textord, "\u2572", "\\diagdown");
defineSymbol(math, ams, textord, "\u25a1", "\\square");
defineSymbol(math, ams, textord, "\u25a1", "\\Box");
defineSymbol(math, ams, textord, "\u25ca", "\\Diamond");
// unicode-math maps U+A5 to \mathyen. We map to AMS function \yen
defineSymbol(math, ams, textord, "\u00a5", "\\yen", true);
defineSymbol(text, ams, textord, "\u00a5", "\\yen", true);
defineSymbol(math, ams, textord, "\u2713", "\\checkmark", true);
defineSymbol(text, ams, textord, "\u2713", "\\checkmark");
// AMS Hebrew
defineSymbol(math, ams, textord, "\u2136", "\\beth", true);
defineSymbol(math, ams, textord, "\u2138", "\\daleth", true);
defineSymbol(math, ams, textord, "\u2137", "\\gimel", true);
// AMS Greek
defineSymbol(math, ams, textord, "\u03dd", "\\digamma", true);
defineSymbol(math, ams, textord, "\u03f0", "\\varkappa");
// AMS Delimiters
defineSymbol(math, ams, open, "\u250c", "\\@ulcorner", true);
defineSymbol(math, ams, close, "\u2510", "\\@urcorner", true);
defineSymbol(math, ams, open, "\u2514", "\\@llcorner", true);
defineSymbol(math, ams, close, "\u2518", "\\@lrcorner", true);
// AMS Binary Relations
defineSymbol(math, ams, rel, "\u2266", "\\leqq", true);
defineSymbol(math, ams, rel, "\u2a7d", "\\leqslant", true);
defineSymbol(math, ams, rel, "\u2a95", "\\eqslantless", true);
defineSymbol(math, ams, rel, "\u2272", "\\lesssim", true);
defineSymbol(math, ams, rel, "\u2a85", "\\lessapprox", true);
defineSymbol(math, ams, rel, "\u224a", "\\approxeq", true);
defineSymbol(math, ams, bin, "\u22d6", "\\lessdot");
defineSymbol(math, ams, rel, "\u22d8", "\\lll", true);
defineSymbol(math, ams, rel, "\u2276", "\\lessgtr", true);
defineSymbol(math, ams, rel, "\u22da", "\\lesseqgtr", true);
defineSymbol(math, ams, rel, "\u2a8b", "\\lesseqqgtr", true);
defineSymbol(math, ams, rel, "\u2251", "\\doteqdot");
defineSymbol(math, ams, rel, "\u2253", "\\risingdotseq", true);
defineSymbol(math, ams, rel, "\u2252", "\\fallingdotseq", true);
defineSymbol(math, ams, rel, "\u223d", "\\backsim", true);
defineSymbol(math, ams, rel, "\u22cd", "\\backsimeq", true);
defineSymbol(math, ams, rel, "\u2ac5", "\\subseteqq", true);
defineSymbol(math, ams, rel, "\u22d0", "\\Subset", true);
defineSymbol(math, ams, rel, "\u228f", "\\sqsubset", true);
defineSymbol(math, ams, rel, "\u227c", "\\preccurlyeq", true);
defineSymbol(math, ams, rel, "\u22de", "\\curlyeqprec", true);
defineSymbol(math, ams, rel, "\u227e", "\\precsim", true);
defineSymbol(math, ams, rel, "\u2ab7", "\\precapprox", true);
defineSymbol(math, ams, rel, "\u22b2", "\\vartriangleleft");
defineSymbol(math, ams, rel, "\u22b4", "\\trianglelefteq");
defineSymbol(math, ams, rel, "\u22a8", "\\vDash", true);
defineSymbol(math, ams, rel, "\u22aa", "\\Vvdash", true);
defineSymbol(math, ams, rel, "\u2323", "\\smallsmile");
defineSymbol(math, ams, rel, "\u2322", "\\smallfrown");
defineSymbol(math, ams, rel, "\u224f", "\\bumpeq", true);
defineSymbol(math, ams, rel, "\u224e", "\\Bumpeq", true);
defineSymbol(math, ams, rel, "\u2267", "\\geqq", true);
defineSymbol(math, ams, rel, "\u2a7e", "\\geqslant", true);
defineSymbol(math, ams, rel, "\u2a96", "\\eqslantgtr", true);
defineSymbol(math, ams, rel, "\u2273", "\\gtrsim", true);
defineSymbol(math, ams, rel, "\u2a86", "\\gtrapprox", true);
defineSymbol(math, ams, bin, "\u22d7", "\\gtrdot");
defineSymbol(math, ams, rel, "\u22d9", "\\ggg", true);
defineSymbol(math, ams, rel, "\u2277", "\\gtrless", true);
defineSymbol(math, ams, rel, "\u22db", "\\gtreqless", true);
defineSymbol(math, ams, rel, "\u2a8c", "\\gtreqqless", true);
defineSymbol(math, ams, rel, "\u2256", "\\eqcirc", true);
defineSymbol(math, ams, rel, "\u2257", "\\circeq", true);
defineSymbol(math, ams, rel, "\u225c", "\\triangleq", true);
defineSymbol(math, ams, rel, "\u223c", "\\thicksim");
defineSymbol(math, ams, rel, "\u2248", "\\thickapprox");
defineSymbol(math, ams, rel, "\u2ac6", "\\supseteqq", true);
defineSymbol(math, ams, rel, "\u22d1", "\\Supset", true);
defineSymbol(math, ams, rel, "\u2290", "\\sqsupset", true);
defineSymbol(math, ams, rel, "\u227d", "\\succcurlyeq", true);
defineSymbol(math, ams, rel, "\u22df", "\\curlyeqsucc", true);
defineSymbol(math, ams, rel, "\u227f", "\\succsim", true);
defineSymbol(math, ams, rel, "\u2ab8", "\\succapprox", true);
defineSymbol(math, ams, rel, "\u22b3", "\\vartriangleright");
defineSymbol(math, ams, rel, "\u22b5", "\\trianglerighteq");
defineSymbol(math, ams, rel, "\u22a9", "\\Vdash", true);
defineSymbol(math, ams, rel, "\u2223", "\\shortmid");
defineSymbol(math, ams, rel, "\u2225", "\\shortparallel");
defineSymbol(math, ams, rel, "\u226c", "\\between", true);
defineSymbol(math, ams, rel, "\u22d4", "\\pitchfork", true);
defineSymbol(math, ams, rel, "\u221d", "\\varpropto");
defineSymbol(math, ams, rel, "\u25c0", "\\blacktriangleleft");
// unicode-math says that \therefore is a mathord atom.
// We kept the amssymb atom type, which is rel.
defineSymbol(math, ams, rel, "\u2234", "\\therefore", true);
defineSymbol(math, ams, rel, "\u220d", "\\backepsilon");
defineSymbol(math, ams, rel, "\u25b6", "\\blacktriangleright");
// unicode-math says that \because is a mathord atom.
// We kept the amssymb atom type, which is rel.
defineSymbol(math, ams, rel, "\u2235", "\\because", true);
defineSymbol(math, ams, rel, "\u22d8", "\\llless");
defineSymbol(math, ams, rel, "\u22d9", "\\gggtr");
defineSymbol(math, ams, bin, "\u22b2", "\\lhd");
defineSymbol(math, ams, bin, "\u22b3", "\\rhd");
defineSymbol(math, ams, rel, "\u2242", "\\eqsim", true);
defineSymbol(math, main, rel, "\u22c8", "\\Join");
defineSymbol(math, ams, rel, "\u2251", "\\Doteq", true);
// AMS Binary Operators
defineSymbol(math, ams, bin, "\u2214", "\\dotplus", true);
defineSymbol(math, ams, bin, "\u2216", "\\smallsetminus");
defineSymbol(math, ams, bin, "\u22d2", "\\Cap", true);
defineSymbol(math, ams, bin, "\u22d3", "\\Cup", true);
defineSymbol(math, ams, bin, "\u2a5e", "\\doublebarwedge", true);
defineSymbol(math, ams, bin, "\u229f", "\\boxminus", true);
defineSymbol(math, ams, bin, "\u229e", "\\boxplus", true);
defineSymbol(math, ams, bin, "\u22c7", "\\divideontimes", true);
defineSymbol(math, ams, bin, "\u22c9", "\\ltimes", true);
defineSymbol(math, ams, bin, "\u22ca", "\\rtimes", true);
defineSymbol(math, ams, bin, "\u22cb", "\\leftthreetimes", true);
defineSymbol(math, ams, bin, "\u22cc", "\\rightthreetimes", true);
defineSymbol(math, ams, bin, "\u22cf", "\\curlywedge", true);
defineSymbol(math, ams, bin, "\u22ce", "\\curlyvee", true);
defineSymbol(math, ams, bin, "\u229d", "\\circleddash", true);
defineSymbol(math, ams, bin, "\u229b", "\\circledast", true);
defineSymbol(math, ams, bin, "\u22c5", "\\centerdot");
defineSymbol(math, ams, bin, "\u22ba", "\\intercal", true);
defineSymbol(math, ams, bin, "\u22d2", "\\doublecap");
defineSymbol(math, ams, bin, "\u22d3", "\\doublecup");
defineSymbol(math, ams, bin, "\u22a0", "\\boxtimes", true);
// AMS Arrows
// Note: unicode-math maps \u21e2 to their own function \rightdasharrow.
// We'll map it to AMS function \dashrightarrow. It produces the same atom.
defineSymbol(math, ams, rel, "\u21e2", "\\dashrightarrow", true);
// unicode-math maps \u21e0 to \leftdasharrow. We'll use the AMS synonym.
defineSymbol(math, ams, rel, "\u21e0", "\\dashleftarrow", true);
defineSymbol(math, ams, rel, "\u21c7", "\\leftleftarrows", true);
defineSymbol(math, ams, rel, "\u21c6", "\\leftrightarrows", true);
defineSymbol(math, ams, rel, "\u21da", "\\Lleftarrow", true);
defineSymbol(math, ams, rel, "\u219e", "\\twoheadleftarrow", true);
defineSymbol(math, ams, rel, "\u21a2", "\\leftarrowtail", true);
defineSymbol(math, ams, rel, "\u21ab", "\\looparrowleft", true);
defineSymbol(math, ams, rel, "\u21cb", "\\leftrightharpoons", true);
defineSymbol(math, ams, rel, "\u21b6", "\\curvearrowleft", true);
// unicode-math maps \u21ba to \acwopencirclearrow. We'll use the AMS synonym.
defineSymbol(math, ams, rel, "\u21ba", "\\circlearrowleft", true);
defineSymbol(math, ams, rel, "\u21b0", "\\Lsh", true);
defineSymbol(math, ams, rel, "\u21c8", "\\upuparrows", true);
defineSymbol(math, ams, rel, "\u21bf", "\\upharpoonleft", true);
defineSymbol(math, ams, rel, "\u21c3", "\\downharpoonleft", true);
defineSymbol(math, main, rel, "\u22b6", "\\origof", true); // not in font
defineSymbol(math, main, rel, "\u22b7", "\\imageof", true); // not in font
defineSymbol(math, ams, rel, "\u22b8", "\\multimap", true);
defineSymbol(math, ams, rel, "\u21ad", "\\leftrightsquigarrow", true);
defineSymbol(math, ams, rel, "\u21c9", "\\rightrightarrows", true);
defineSymbol(math, ams, rel, "\u21c4", "\\rightleftarrows", true);
defineSymbol(math, ams, rel, "\u21a0", "\\twoheadrightarrow", true);
defineSymbol(math, ams, rel, "\u21a3", "\\rightarrowtail", true);
defineSymbol(math, ams, rel, "\u21ac", "\\looparrowright", true);
defineSymbol(math, ams, rel, "\u21b7", "\\curvearrowright", true);
// unicode-math maps \u21bb to \cwopencirclearrow. We'll use the AMS synonym.
defineSymbol(math, ams, rel, "\u21bb", "\\circlearrowright", true);
defineSymbol(math, ams, rel, "\u21b1", "\\Rsh", true);
defineSymbol(math, ams, rel, "\u21ca", "\\downdownarrows", true);
defineSymbol(math, ams, rel, "\u21be", "\\upharpoonright", true);
defineSymbol(math, ams, rel, "\u21c2", "\\downharpoonright", true);
defineSymbol(math, ams, rel, "\u21dd", "\\rightsquigarrow", true);
defineSymbol(math, ams, rel, "\u21dd", "\\leadsto");
defineSymbol(math, ams, rel, "\u21db", "\\Rrightarrow", true);
defineSymbol(math, ams, rel, "\u21be", "\\restriction");
defineSymbol(math, main, textord, "\u2018", "`");
defineSymbol(math, main, textord, "$", "\\$");
defineSymbol(text, main, textord, "$", "\\$");
defineSymbol(text, main, textord, "$", "\\textdollar");
defineSymbol(math, main, textord, "%", "\\%");
defineSymbol(text, main, textord, "%", "\\%");
defineSymbol(math, main, textord, "_", "\\_");
defineSymbol(text, main, textord, "_", "\\_");
defineSymbol(text, main, textord, "_", "\\textunderscore");
defineSymbol(math, main, textord, "\u2220", "\\angle", true);
defineSymbol(math, main, textord, "\u221e", "\\infty", true);
defineSymbol(math, main, textord, "\u2032", "\\prime");
defineSymbol(math, main, textord, "\u25b3", "\\triangle");
defineSymbol(math, main, textord, "\u0393", "\\Gamma", true);
defineSymbol(math, main, textord, "\u0394", "\\Delta", true);
defineSymbol(math, main, textord, "\u0398", "\\Theta", true);
defineSymbol(math, main, textord, "\u039b", "\\Lambda", true);
defineSymbol(math, main, textord, "\u039e", "\\Xi", true);
defineSymbol(math, main, textord, "\u03a0", "\\Pi", true);
defineSymbol(math, main, textord, "\u03a3", "\\Sigma", true);
defineSymbol(math, main, textord, "\u03a5", "\\Upsilon", true);
defineSymbol(math, main, textord, "\u03a6", "\\Phi", true);
defineSymbol(math, main, textord, "\u03a8", "\\Psi", true);
defineSymbol(math, main, textord, "\u03a9", "\\Omega", true);
defineSymbol(math, main, textord, "A", "\u0391");
defineSymbol(math, main, textord, "B", "\u0392");
defineSymbol(math, main, textord, "E", "\u0395");
defineSymbol(math, main, textord, "Z", "\u0396");
defineSymbol(math, main, textord, "H", "\u0397");
defineSymbol(math, main, textord, "I", "\u0399");
defineSymbol(math, main, textord, "K", "\u039A");
defineSymbol(math, main, textord, "M", "\u039C");
defineSymbol(math, main, textord, "N", "\u039D");
defineSymbol(math, main, textord, "O", "\u039F");
defineSymbol(math, main, textord, "P", "\u03A1");
defineSymbol(math, main, textord, "T", "\u03A4");
defineSymbol(math, main, textord, "X", "\u03A7");
defineSymbol(math, main, textord, "\u00ac", "\\neg", true);
defineSymbol(math, main, textord, "\u00ac", "\\lnot");
defineSymbol(math, main, textord, "\u22a4", "\\top");
defineSymbol(math, main, textord, "\u22a5", "\\bot");
defineSymbol(math, main, textord, "\u2205", "\\emptyset");
defineSymbol(math, ams, textord, "\u2205", "\\varnothing");
defineSymbol(math, main, mathord, "\u03b1", "\\alpha", true);
defineSymbol(math, main, mathord, "\u03b2", "\\beta", true);
defineSymbol(math, main, mathord, "\u03b3", "\\gamma", true);
defineSymbol(math, main, mathord, "\u03b4", "\\delta", true);
defineSymbol(math, main, mathord, "\u03f5", "\\epsilon", true);
defineSymbol(math, main, mathord, "\u03b6", "\\zeta", true);
defineSymbol(math, main, mathord, "\u03b7", "\\eta", true);
defineSymbol(math, main, mathord, "\u03b8", "\\theta", true);
defineSymbol(math, main, mathord, "\u03b9", "\\iota", true);
defineSymbol(math, main, mathord, "\u03ba", "\\kappa", true);
defineSymbol(math, main, mathord, "\u03bb", "\\lambda", true);
defineSymbol(math, main, mathord, "\u03bc", "\\mu", true);
defineSymbol(math, main, mathord, "\u03bd", "\\nu", true);
defineSymbol(math, main, mathord, "\u03be", "\\xi", true);
defineSymbol(math, main, mathord, "\u03bf", "\\omicron", true);
defineSymbol(math, main, mathord, "\u03c0", "\\pi", true);
defineSymbol(math, main, mathord, "\u03c1", "\\rho", true);
defineSymbol(math, main, mathord, "\u03c3", "\\sigma", true);
defineSymbol(math, main, mathord, "\u03c4", "\\tau", true);
defineSymbol(math, main, mathord, "\u03c5", "\\upsilon", true);
defineSymbol(math, main, mathord, "\u03d5", "\\phi", true);
defineSymbol(math, main, mathord, "\u03c7", "\\chi", true);
defineSymbol(math, main, mathord, "\u03c8", "\\psi", true);
defineSymbol(math, main, mathord, "\u03c9", "\\omega", true);
defineSymbol(math, main, mathord, "\u03b5", "\\varepsilon", true);
defineSymbol(math, main, mathord, "\u03d1", "\\vartheta", true);
defineSymbol(math, main, mathord, "\u03d6", "\\varpi", true);
defineSymbol(math, main, mathord, "\u03f1", "\\varrho", true);
defineSymbol(math, main, mathord, "\u03c2", "\\varsigma", true);
defineSymbol(math, main, mathord, "\u03c6", "\\varphi", true);
defineSymbol(math, main, bin, "\u2217", "*", true);
defineSymbol(math, main, bin, "+", "+");
defineSymbol(math, main, bin, "\u2212", "-", true);
defineSymbol(math, main, bin, "\u22c5", "\\cdot", true);
defineSymbol(math, main, bin, "\u2218", "\\circ", true);
defineSymbol(math, main, bin, "\u00f7", "\\div", true);
defineSymbol(math, main, bin, "\u00b1", "\\pm", true);
defineSymbol(math, main, bin, "\u00d7", "\\times", true);
defineSymbol(math, main, bin, "\u2229", "\\cap", true);
defineSymbol(math, main, bin, "\u222a", "\\cup", true);
defineSymbol(math, main, bin, "\u2216", "\\setminus", true);
defineSymbol(math, main, bin, "\u2227", "\\land");
defineSymbol(math, main, bin, "\u2228", "\\lor");
defineSymbol(math, main, bin, "\u2227", "\\wedge", true);
defineSymbol(math, main, bin, "\u2228", "\\vee", true);
defineSymbol(math, main, textord, "\u221a", "\\surd");
defineSymbol(math, main, open, "\u27e8", "\\langle", true);
defineSymbol(math, main, open, "\u2223", "\\lvert");
defineSymbol(math, main, open, "\u2225", "\\lVert");
defineSymbol(math, main, close, "?", "?");
defineSymbol(math, main, close, "!", "!");
defineSymbol(math, main, close, "\u27e9", "\\rangle", true);
defineSymbol(math, main, close, "\u2223", "\\rvert");
defineSymbol(math, main, close, "\u2225", "\\rVert");
defineSymbol(math, main, rel, "=", "=");
defineSymbol(math, main, rel, ":", ":");
defineSymbol(math, main, rel, "\u2248", "\\approx", true);
defineSymbol(math, main, rel, "\u2245", "\\cong", true);
defineSymbol(math, main, rel, "\u2265", "\\ge");
defineSymbol(math, main, rel, "\u2265", "\\geq", true);
defineSymbol(math, main, rel, "\u2190", "\\gets");
defineSymbol(math, main, rel, ">", "\\gt", true);
defineSymbol(math, main, rel, "\u2208", "\\in", true);
defineSymbol(math, main, rel, "\ue020", "\\@not");
defineSymbol(math, main, rel, "\u2282", "\\subset", true);
defineSymbol(math, main, rel, "\u2283", "\\supset", true);
defineSymbol(math, main, rel, "\u2286", "\\subseteq", true);
defineSymbol(math, main, rel, "\u2287", "\\supseteq", true);
defineSymbol(math, ams, rel, "\u2288", "\\nsubseteq", true);
defineSymbol(math, ams, rel, "\u2289", "\\nsupseteq", true);
defineSymbol(math, main, rel, "\u22a8", "\\models");
defineSymbol(math, main, rel, "\u2190", "\\leftarrow", true);
defineSymbol(math, main, rel, "\u2264", "\\le");
defineSymbol(math, main, rel, "\u2264", "\\leq", true);
defineSymbol(math, main, rel, "<", "\\lt", true);
defineSymbol(math, main, rel, "\u2192", "\\rightarrow", true);
defineSymbol(math, main, rel, "\u2192", "\\to");
defineSymbol(math, ams, rel, "\u2271", "\\ngeq", true);
defineSymbol(math, ams, rel, "\u2270", "\\nleq", true);
defineSymbol(math, main, spacing, "\u00a0", "\\ ");
defineSymbol(math, main, spacing, "\u00a0", "\\space");
// Ref: LaTeX Source 2e: \DeclareRobustCommand{\nobreakspace}{%
defineSymbol(math, main, spacing, "\u00a0", "\\nobreakspace");
defineSymbol(text, main, spacing, "\u00a0", "\\ ");
defineSymbol(text, main, spacing, "\u00a0", " ");
defineSymbol(text, main, spacing, "\u00a0", "\\space");
defineSymbol(text, main, spacing, "\u00a0", "\\nobreakspace");
defineSymbol(math, main, spacing, null, "\\nobreak");
defineSymbol(math, main, spacing, null, "\\allowbreak");
defineSymbol(math, main, punct, ",", ",");
defineSymbol(math, main, punct, ";", ";");
defineSymbol(math, ams, bin, "\u22bc", "\\barwedge", true);
defineSymbol(math, ams, bin, "\u22bb", "\\veebar", true);
defineSymbol(math, main, bin, "\u2299", "\\odot", true);
defineSymbol(math, main, bin, "\u2295", "\\oplus", true);
defineSymbol(math, main, bin, "\u2297", "\\otimes", true);
defineSymbol(math, main, textord, "\u2202", "\\partial", true);
defineSymbol(math, main, bin, "\u2298", "\\oslash", true);
defineSymbol(math, ams, bin, "\u229a", "\\circledcirc", true);
defineSymbol(math, ams, bin, "\u22a1", "\\boxdot", true);
defineSymbol(math, main, bin, "\u25b3", "\\bigtriangleup");
defineSymbol(math, main, bin, "\u25bd", "\\bigtriangledown");
defineSymbol(math, main, bin, "\u2020", "\\dagger");
defineSymbol(math, main, bin, "\u22c4", "\\diamond");
defineSymbol(math, main, bin, "\u22c6", "\\star");
defineSymbol(math, main, bin, "\u25c3", "\\triangleleft");
defineSymbol(math, main, bin, "\u25b9", "\\triangleright");
defineSymbol(math, main, open, "{", "\\{");
defineSymbol(text, main, textord, "{", "\\{");
defineSymbol(text, main, textord, "{", "\\textbraceleft");
defineSymbol(math, main, close, "}", "\\}");
defineSymbol(text, main, textord, "}", "\\}");
defineSymbol(text, main, textord, "}", "\\textbraceright");
defineSymbol(math, main, open, "{", "\\lbrace");
defineSymbol(math, main, close, "}", "\\rbrace");
defineSymbol(math, main, open, "[", "\\lbrack", true);
defineSymbol(text, main, textord, "[", "\\lbrack", true);
defineSymbol(math, main, close, "]", "\\rbrack", true);
defineSymbol(text, main, textord, "]", "\\rbrack", true);
defineSymbol(math, main, open, "(", "\\lparen", true);
defineSymbol(math, main, close, ")", "\\rparen", true);
defineSymbol(text, main, textord, "<", "\\textless", true); // in T1 fontenc
defineSymbol(text, main, textord, ">", "\\textgreater", true); // in T1 fontenc
defineSymbol(math, main, open, "\u230a", "\\lfloor", true);
defineSymbol(math, main, close, "\u230b", "\\rfloor", true);
defineSymbol(math, main, open, "\u2308", "\\lceil", true);
defineSymbol(math, main, close, "\u2309", "\\rceil", true);
defineSymbol(math, main, textord, "\\", "\\backslash");
defineSymbol(math, main, textord, "\u2223", "|");
defineSymbol(math, main, textord, "\u2223", "\\vert");
defineSymbol(text, main, textord, "|", "\\textbar", true); // in T1 fontenc
defineSymbol(math, main, textord, "\u2225", "\\|");
defineSymbol(math, main, textord, "\u2225", "\\Vert");
defineSymbol(text, main, textord, "\u2225", "\\textbardbl");
defineSymbol(text, main, textord, "~", "\\textasciitilde");
defineSymbol(text, main, textord, "\\", "\\textbackslash");
defineSymbol(text, main, textord, "^", "\\textasciicircum");
defineSymbol(math, main, rel, "\u2191", "\\uparrow", true);
defineSymbol(math, main, rel, "\u21d1", "\\Uparrow", true);
defineSymbol(math, main, rel, "\u2193", "\\downarrow", true);
defineSymbol(math, main, rel, "\u21d3", "\\Downarrow", true);
defineSymbol(math, main, rel, "\u2195", "\\updownarrow", true);
defineSymbol(math, main, rel, "\u21d5", "\\Updownarrow", true);
defineSymbol(math, main, op, "\u2210", "\\coprod");
defineSymbol(math, main, op, "\u22c1", "\\bigvee");
defineSymbol(math, main, op, "\u22c0", "\\bigwedge");
defineSymbol(math, main, op, "\u2a04", "\\biguplus");
defineSymbol(math, main, op, "\u22c2", "\\bigcap");
defineSymbol(math, main, op, "\u22c3", "\\bigcup");
defineSymbol(math, main, op, "\u222b", "\\int");
defineSymbol(math, main, op, "\u222b", "\\intop");
defineSymbol(math, main, op, "\u222c", "\\iint");
defineSymbol(math, main, op, "\u222d", "\\iiint");
defineSymbol(math, main, op, "\u220f", "\\prod");
defineSymbol(math, main, op, "\u2211", "\\sum");
defineSymbol(math, main, op, "\u2a02", "\\bigotimes");
defineSymbol(math, main, op, "\u2a01", "\\bigoplus");
defineSymbol(math, main, op, "\u2a00", "\\bigodot");
defineSymbol(math, main, op, "\u222e", "\\oint");
defineSymbol(math, main, op, "\u222f", "\\oiint");
defineSymbol(math, main, op, "\u2230", "\\oiiint");
defineSymbol(math, main, op, "\u2a06", "\\bigsqcup");
defineSymbol(math, main, op, "\u222b", "\\smallint");
defineSymbol(text, main, inner, "\u2026", "\\textellipsis");
defineSymbol(math, main, inner, "\u2026", "\\mathellipsis");
defineSymbol(text, main, inner, "\u2026", "\\ldots", true);
defineSymbol(math, main, inner, "\u2026", "\\ldots", true);
defineSymbol(math, main, inner, "\u22ef", "\\@cdots", true);
defineSymbol(math, main, inner, "\u22f1", "\\ddots", true);
// \vdots is a macro that uses one of these two symbols (with made-up names):
defineSymbol(math, main, textord, "\u22ee", "\\varvdots");
defineSymbol(text, main, textord, "\u22ee", "\\varvdots");
defineSymbol(math, main, accent, "\u02ca", "\\acute");
defineSymbol(math, main, accent, "\u02cb", "\\grave");
defineSymbol(math, main, accent, "\u00a8", "\\ddot");
defineSymbol(math, main, accent, "\u007e", "\\tilde");
defineSymbol(math, main, accent, "\u02c9", "\\bar");
defineSymbol(math, main, accent, "\u02d8", "\\breve");
defineSymbol(math, main, accent, "\u02c7", "\\check");
defineSymbol(math, main, accent, "\u005e", "\\hat");
defineSymbol(math, main, accent, "\u20d7", "\\vec");
defineSymbol(math, main, accent, "\u02d9", "\\dot");
defineSymbol(math, main, accent, "\u02da", "\\mathring");
// \imath and \jmath should be invariant to \mathrm, \mathbf, etc., so use PUA
defineSymbol(math, main, mathord, "\ue131", "\\@imath");
defineSymbol(math, main, mathord, "\ue237", "\\@jmath");
defineSymbol(math, main, textord, "\u0131", "\u0131");
defineSymbol(math, main, textord, "\u0237", "\u0237");
defineSymbol(text, main, textord, "\u0131", "\\i", true);
defineSymbol(text, main, textord, "\u0237", "\\j", true);
defineSymbol(text, main, textord, "\u00df", "\\ss", true);
defineSymbol(text, main, textord, "\u00e6", "\\ae", true);
defineSymbol(text, main, textord, "\u0153", "\\oe", true);
defineSymbol(text, main, textord, "\u00f8", "\\o", true);
defineSymbol(text, main, textord, "\u00c6", "\\AE", true);
defineSymbol(text, main, textord, "\u0152", "\\OE", true);
defineSymbol(text, main, textord, "\u00d8", "\\O", true);
defineSymbol(text, main, accent, "\u02ca", "\\'"); // acute
defineSymbol(text, main, accent, "\u02cb", "\\`"); // grave
defineSymbol(text, main, accent, "\u02c6", "\\^"); // circumflex
defineSymbol(text, main, accent, "\u02dc", "\\~"); // tilde
defineSymbol(text, main, accent, "\u02c9", "\\="); // macron
defineSymbol(text, main, accent, "\u02d8", "\\u"); // breve
defineSymbol(text, main, accent, "\u02d9", "\\."); // dot above
defineSymbol(text, main, accent, "\u00b8", "\\c"); // cedilla
defineSymbol(text, main, accent, "\u02da", "\\r"); // ring above
defineSymbol(text, main, accent, "\u02c7", "\\v"); // caron
defineSymbol(text, main, accent, "\u00a8", '\\"'); // diaeresis
defineSymbol(text, main, accent, "\u02dd", "\\H"); // double acute
defineSymbol(text, main, accent, "\u25ef", "\\textcircled"); // \bigcirc glyph
// These ligatures are detected and created in Parser.js's `formLigatures`.
export const ligatures = {
"--": true,
"---": true,
"``": true,
"''": true,
};
defineSymbol(text, main, textord, "\u2013", "--", true);
defineSymbol(text, main, textord, "\u2013", "\\textendash");
defineSymbol(text, main, textord, "\u2014", "---", true);
defineSymbol(text, main, textord, "\u2014", "\\textemdash");
defineSymbol(text, main, textord, "\u2018", "`", true);
defineSymbol(text, main, textord, "\u2018", "\\textquoteleft");
defineSymbol(text, main, textord, "\u2019", "'", true);
defineSymbol(text, main, textord, "\u2019", "\\textquoteright");
defineSymbol(text, main, textord, "\u201c", "``", true);
defineSymbol(text, main, textord, "\u201c", "\\textquotedblleft");
defineSymbol(text, main, textord, "\u201d", "''", true);
defineSymbol(text, main, textord, "\u201d", "\\textquotedblright");
// \degree from gensymb package
defineSymbol(math, main, textord, "\u00b0", "\\degree", true);
defineSymbol(text, main, textord, "\u00b0", "\\degree");
// \textdegree from inputenc package
defineSymbol(text, main, textord, "\u00b0", "\\textdegree", true);
// TODO: In LaTeX, \pounds can generate a different character in text and math
// mode, but among our fonts, only Main-Regular defines this character "163".
defineSymbol(math, main, textord, "\u00a3", "\\pounds");
defineSymbol(math, main, textord, "\u00a3", "\\mathsterling", true);
defineSymbol(text, main, textord, "\u00a3", "\\pounds");
defineSymbol(text, main, textord, "\u00a3", "\\textsterling", true);
defineSymbol(math, ams, textord, "\u2720", "\\maltese");
defineSymbol(text, ams, textord, "\u2720", "\\maltese");
// There are lots of symbols which are the same, so we add them in afterwards.
// All of these are textords in math mode
const mathTextSymbols = "0123456789/@.\"";
for (let i = 0; i < mathTextSymbols.length; i++) {
const ch = mathTextSymbols.charAt(i);
defineSymbol(math, main, textord, ch, ch);
}
// All of these are textords in text mode
const textSymbols = "0123456789!@*()-=+\";:?/.,";
for (let i = 0; i < textSymbols.length; i++) {
const ch = textSymbols.charAt(i);
defineSymbol(text, main, textord, ch, ch);
}
// All of these are textords in text mode, and mathords in math mode
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for (let i = 0; i < letters.length; i++) {
const ch = letters.charAt(i);
defineSymbol(math, main, mathord, ch, ch);
defineSymbol(text, main, textord, ch, ch);
}
// Blackboard bold and script letters in Unicode range
defineSymbol(math, ams, textord, "C", "\u2102"); // blackboard bold
defineSymbol(text, ams, textord, "C", "\u2102");
defineSymbol(math, ams, textord, "H", "\u210D");
defineSymbol(text, ams, textord, "H", "\u210D");
defineSymbol(math, ams, textord, "N", "\u2115");
defineSymbol(text, ams, textord, "N", "\u2115");
defineSymbol(math, ams, textord, "P", "\u2119");
defineSymbol(text, ams, textord, "P", "\u2119");
defineSymbol(math, ams, textord, "Q", "\u211A");
defineSymbol(text, ams, textord, "Q", "\u211A");
defineSymbol(math, ams, textord, "R", "\u211D");
defineSymbol(text, ams, textord, "R", "\u211D");
defineSymbol(math, ams, textord, "Z", "\u2124");
defineSymbol(text, ams, textord, "Z", "\u2124");
defineSymbol(math, main, mathord, "h", "\u210E"); // italic h, Planck constant
defineSymbol(text, main, mathord, "h", "\u210E");
// The next loop loads wide (surrogate pair) characters.
// We support some letters in the Unicode range U+1D400 to U+1D7FF,
// Mathematical Alphanumeric Symbols.
// Some editors do not deal well with wide characters. So don't write the
// string into this file. Instead, create the string from the surrogate pair.
let wideChar = "";
for (let i = 0; i < letters.length; i++) {
const ch = letters.charAt(i);
// The hex numbers in the next line are a surrogate pair.
// 0xD835 is the high surrogate for all letters in the range we support.
// 0xDC00 is the low surrogate for bold A.
wideChar = String.fromCharCode(0xD835, 0xDC00 + i); // A-Z a-z bold
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDC34 + i); // A-Z a-z italic
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDC68 + i); // A-Z a-z bold italic
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDD04 + i); // A-Z a-z Fraktur
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDD6C + i); // A-Z a-z bold Fraktur
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDDA0 + i); // A-Z a-z sans-serif
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDDD4 + i); // A-Z a-z sans bold
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDE08 + i); // A-Z a-z sans italic
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDE70 + i); // A-Z a-z monospace
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
if (i < 26) {
// KaTeX fonts have only capital letters for blackboard bold and script.
// See exception for k below.
wideChar = String.fromCharCode(0xD835, 0xDD38 + i); // A-Z double struck
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDC9C + i); // A-Z script
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
}
// TODO: Add bold script when it is supported by a KaTeX font.
}
// "k" is the only double struck lower case letter in the KaTeX fonts.
wideChar = String.fromCharCode(0xD835, 0xDD5C); // k double struck
defineSymbol(math, main, mathord, "k", wideChar);
defineSymbol(text, main, textord, "k", wideChar);
// Next, some wide character numerals
for (let i = 0; i < 10; i++) {
const ch = i.toString();
wideChar = String.fromCharCode(0xD835, 0xDFCE + i); // 0-9 bold
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDFE2 + i); // 0-9 sans serif
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDFEC + i); // 0-9 bold sans
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDFF6 + i); // 0-9 monospace
defineSymbol(math, main, mathord, ch, wideChar);
defineSymbol(text, main, textord, ch, wideChar);
}
// We add these Latin-1 letters as symbols for backwards-compatibility,
// but they are not actually in the font, nor are they supported by the
// Unicode accent mechanism, so they fall back to Times font and look ugly.
// TODO(edemaine): Fix this.
export const extraLatin = "\u00d0\u00de\u00fe";
for (let i = 0; i < extraLatin.length; i++) {
const ch = extraLatin.charAt(i);
defineSymbol(math, main, mathord, ch, ch);
defineSymbol(text, main, textord, ch, ch);
}

78
node_modules/katex/src/tree.js generated vendored Normal file
View File

@@ -0,0 +1,78 @@
// @flow
import utils from "./utils";
import type {CssStyle, HtmlDomNode} from "./domTree";
import type {MathDomNode} from "./mathMLTree";
// To ensure that all nodes have compatible signatures for these methods.
export interface VirtualNode {
toNode(): Node;
toMarkup(): string;
}
/**
* This node represents a document fragment, which contains elements, but when
* placed into the DOM doesn't have any representation itself. It only contains
* children and doesn't have any DOM node properties.
*/
export class DocumentFragment<ChildType: VirtualNode>
implements HtmlDomNode, MathDomNode {
children: $ReadOnlyArray<ChildType>;
// HtmlDomNode
classes: string[];
height: number;
depth: number;
maxFontSize: number;
style: CssStyle; // Never used; needed for satisfying interface.
constructor(children: $ReadOnlyArray<ChildType>) {
this.children = children;
this.classes = [];
this.height = 0;
this.depth = 0;
this.maxFontSize = 0;
this.style = {};
}
hasClass(className: string): boolean {
return utils.contains(this.classes, className);
}
/** Convert the fragment into a node. */
toNode(): Node {
const frag = document.createDocumentFragment();
for (let i = 0; i < this.children.length; i++) {
frag.appendChild(this.children[i].toNode());
}
return frag;
}
/** Convert the fragment into HTML markup. */
toMarkup(): string {
let markup = "";
// Simply concatenate the markup for the children together.
for (let i = 0; i < this.children.length; i++) {
markup += this.children[i].toMarkup();
}
return markup;
}
/**
* Converts the math node into a string, similar to innerText. Applies to
* MathDomNode's only.
*/
toText(): string {
// To avoid this, we would subclass documentFragment separately for
// MathML, but polyfills for subclassing is expensive per PR 1469.
// $FlowFixMe: Only works for ChildType = MathDomNode.
const toText = (child: ChildType): string => child.toText();
return this.children.map(toText).join("");
}
}

36
node_modules/katex/src/types.js generated vendored Normal file
View File

@@ -0,0 +1,36 @@
// @flow
/**
* This file consists only of basic flow types used in multiple places.
* For types with javascript, create separate files by themselves.
*/
export type Mode = "math" | "text";
// LaTeX argument type.
// - "size": A size-like thing, such as "1em" or "5ex"
// - "color": An html color, like "#abc" or "blue"
// - "url": An url string, in which "\" will be ignored
// - if it precedes [#$%&~_^\{}]
// - "raw": A string, allowing single character, percent sign,
// and nested braces
// - "original": The same type as the environment that the
// function being parsed is in (e.g. used for the
// bodies of functions like \textcolor where the
// first argument is special and the second
// argument is parsed normally)
// - Mode: Node group parsed in given mode.
export type ArgType = "color" | "size" | "url" | "raw" | "original" | "hbox" |
"primitive" | Mode;
// LaTeX display style.
export type StyleStr = "text" | "display" | "script" | "scriptscript";
// Allowable token text for "break" arguments in parser.
export type BreakToken = "]" | "}" | "\\endgroup" | "$" | "\\)" | "\\\\" | "\\end" |
"EOF";
// Math font variants.
export type FontVariant = "bold" | "bold-italic" | "bold-sans-serif" |
"double-struck" | "fraktur" | "italic" | "monospace" | "normal" | "sans-serif" |
"sans-serif-bold-italic" | "sans-serif-italic" | "script";

18
node_modules/katex/src/unicodeAccents.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
// Mapping of Unicode accent characters to their LaTeX equivalent in text and
// math mode (when they exist).
// This exports a CommonJS module, allowing to be required in unicodeSymbols
// without transpiling.
module.exports = {
'\u0301': {text: "\\'", math: '\\acute'},
'\u0300': {text: '\\`', math: '\\grave'},
'\u0308': {text: '\\"', math: '\\ddot'},
'\u0303': {text: '\\~', math: '\\tilde'},
'\u0304': {text: '\\=', math: '\\bar'},
'\u0306': {text: '\\u', math: '\\breve'},
'\u030c': {text: '\\v', math: '\\check'},
'\u0302': {text: '\\^', math: '\\hat'},
'\u0307': {text: '\\.', math: '\\dot'},
'\u030a': {text: '\\r', math: '\\mathring'},
'\u030b': {text: '\\H'},
'\u0327': {text: '\\c'},
};

126
node_modules/katex/src/unicodeScripts.js generated vendored Normal file
View File

@@ -0,0 +1,126 @@
// @flow
/*
* This file defines the Unicode scripts and script families that we
* support. To add new scripts or families, just add a new entry to the
* scriptData array below. Adding scripts to the scriptData array allows
* characters from that script to appear in \text{} environments.
*/
/**
* Each script or script family has a name and an array of blocks.
* Each block is an array of two numbers which specify the start and
* end points (inclusive) of a block of Unicode codepoints.
*/
type Script = {
name: string;
blocks: Array<Array<number>>;
};
/**
* Unicode block data for the families of scripts we support in \text{}.
* Scripts only need to appear here if they do not have font metrics.
*/
const scriptData: Array<Script> = [
{
// Latin characters beyond the Latin-1 characters we have metrics for.
// Needed for Czech, Hungarian and Turkish text, for example.
name: 'latin',
blocks: [
[0x0100, 0x024f], // Latin Extended-A and Latin Extended-B
[0x0300, 0x036f], // Combining Diacritical marks
],
},
{
// The Cyrillic script used by Russian and related languages.
// A Cyrillic subset used to be supported as explicitly defined
// symbols in symbols.js
name: 'cyrillic',
blocks: [[0x0400, 0x04ff]],
},
{
// Armenian
name: 'armenian',
blocks: [[0x0530, 0x058F]],
},
{
// The Brahmic scripts of South and Southeast Asia
// Devanagari (0900097F)
// Bengali (098009FF)
// Gurmukhi (0A000A7F)
// Gujarati (0A800AFF)
// Oriya (0B000B7F)
// Tamil (0B800BFF)
// Telugu (0C000C7F)
// Kannada (0C800CFF)
// Malayalam (0D000D7F)
// Sinhala (0D800DFF)
// Thai (0E000E7F)
// Lao (0E800EFF)
// Tibetan (0F000FFF)
// Myanmar (1000109F)
name: 'brahmic',
blocks: [[0x0900, 0x109F]],
},
{
name: 'georgian',
blocks: [[0x10A0, 0x10ff]],
},
{
// Chinese and Japanese.
// The "k" in cjk is for Korean, but we've separated Korean out
name: "cjk",
blocks: [
[0x3000, 0x30FF], // CJK symbols and punctuation, Hiragana, Katakana
[0x4E00, 0x9FAF], // CJK ideograms
[0xFF00, 0xFF60], // Fullwidth punctuation
// TODO: add halfwidth Katakana and Romanji glyphs
],
},
{
// Korean
name: 'hangul',
blocks: [[0xAC00, 0xD7AF]],
},
];
/**
* Given a codepoint, return the name of the script or script family
* it is from, or null if it is not part of a known block
*/
export function scriptFromCodepoint(codepoint: number): ?string {
for (let i = 0; i < scriptData.length; i++) {
const script = scriptData[i];
for (let i = 0; i < script.blocks.length; i++) {
const block = script.blocks[i];
if (codepoint >= block[0] && codepoint <= block[1]) {
return script.name;
}
}
}
return null;
}
/**
* A flattened version of all the supported blocks in a single array.
* This is an optimization to make supportedCodepoint() fast.
*/
const allBlocks: Array<number> = [];
scriptData.forEach(s => s.blocks.forEach(b => allBlocks.push(...b)));
/**
* Given a codepoint, return true if it falls within one of the
* scripts or script families defined above and false otherwise.
*
* Micro benchmarks shows that this is faster than
* /[\u3000-\u30FF\u4E00-\u9FAF\uFF00-\uFF60\uAC00-\uD7AF\u0900-\u109F]/.test()
* in Firefox, Chrome and Node.
*/
export function supportedCodepoint(codepoint: number): boolean {
for (let i = 0; i < allBlocks.length; i += 2) {
if (codepoint >= allBlocks[i] && codepoint <= allBlocks[i + 1]) {
return true;
}
}
return false;
}

108
node_modules/katex/src/unicodeSupOrSub.js generated vendored Normal file
View File

@@ -0,0 +1,108 @@
// Helpers for Parser.js handling of Unicode (sub|super)script characters.
export const unicodeSubRegEx = /^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/;
export const uSubsAndSups = Object.freeze({
'₊': '+',
'₋': '-',
'₌': '=',
'₍': '(',
'₎': ')',
'₀': '0',
'₁': '1',
'₂': '2',
'₃': '3',
'₄': '4',
'₅': '5',
'₆': '6',
'₇': '7',
'₈': '8',
'₉': '9',
'\u2090': 'a',
'\u2091': 'e',
'\u2095': 'h',
'\u1D62': 'i',
'\u2C7C': 'j',
'\u2096': 'k',
'\u2097': 'l',
'\u2098': 'm',
'\u2099': 'n',
'\u2092': 'o',
'\u209A': 'p',
'\u1D63': 'r',
'\u209B': 's',
'\u209C': 't',
'\u1D64': 'u',
'\u1D65': 'v',
'\u2093': 'x',
'\u1D66': 'β',
'\u1D67': 'γ',
'\u1D68': 'ρ',
'\u1D69': '\u03d5',
'\u1D6A': 'χ',
'⁺': '+',
'⁻': '-',
'⁼': '=',
'⁽': '(',
'⁾': ')',
'⁰': '0',
'¹': '1',
'²': '2',
'³': '3',
'⁴': '4',
'⁵': '5',
'⁶': '6',
'⁷': '7',
'⁸': '8',
'⁹': '9',
'\u1D2C': 'A',
'\u1D2E': 'B',
'\u1D30': 'D',
'\u1D31': 'E',
'\u1D33': 'G',
'\u1D34': 'H',
'\u1D35': 'I',
'\u1D36': 'J',
'\u1D37': 'K',
'\u1D38': 'L',
'\u1D39': 'M',
'\u1D3A': 'N',
'\u1D3C': 'O',
'\u1D3E': 'P',
'\u1D3F': 'R',
'\u1D40': 'T',
'\u1D41': 'U',
'\u2C7D': 'V',
'\u1D42': 'W',
'\u1D43': 'a',
'\u1D47': 'b',
'\u1D9C': 'c',
'\u1D48': 'd',
'\u1D49': 'e',
'\u1DA0': 'f',
'\u1D4D': 'g',
'\u02B0': 'h',
'\u2071': 'i',
'\u02B2': 'j',
'\u1D4F': 'k',
'\u02E1': 'l',
'\u1D50': 'm',
'\u207F': 'n',
'\u1D52': 'o',
'\u1D56': 'p',
'\u02B3': 'r',
'\u02E2': 's',
'\u1D57': 't',
'\u1D58': 'u',
'\u1D5B': 'v',
'\u02B7': 'w',
'\u02E3': 'x',
'\u02B8': 'y',
'\u1DBB': 'z',
'\u1D5D': 'β',
'\u1D5E': 'γ',
'\u1D5F': 'δ',
'\u1D60': '\u03d5',
'\u1D61': 'χ',
'\u1DBF': 'θ',
});

Some files were not shown because too many files have changed in this diff Show More