file_path
stringlengths 3
280
| file_language
stringclasses 66
values | content
stringlengths 1
1.04M
| repo_name
stringlengths 5
92
| repo_stars
int64 0
154k
| repo_description
stringlengths 0
402
| repo_primary_language
stringclasses 108
values | developer_username
stringlengths 1
25
| developer_name
stringlengths 0
30
| developer_company
stringlengths 0
82
|
|---|---|---|---|---|---|---|---|---|---|
.vitepress/config.mts
|
TypeScript
|
import { defineConfig } from 'vitepress'
const fileAndStyles: Record<string, string> = {}
// https://vitepress.dev/reference/site-config
export default defineConfig({
title: 'naive-ui-vitepress-demo',
description: 'naive-ui vitepress demo',
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
nav: [{ text: 'Home', link: '/' }],
sidebar: [
{
text: 'Examples',
items: [
{ text: 'Button Demo 1', link: '/button-demo-1' },
{ text: 'Button Demo 2', link: '/button-demo-2' }
]
}
]
},
vite: {
ssr: {
noExternal: ['naive-ui', 'date-fns', 'vueuc']
}
},
postRender(context) {
const styleRegex = /<css-render-style>((.|\s)+)<\/css-render-style>/
const vitepressPathRegex = /<vitepress-path>(.+)<\/vitepress-path>/
const style = styleRegex.exec(context.content)?.[1]
const vitepressPath = vitepressPathRegex.exec(context.content)?.[1]
if (vitepressPath && style) {
fileAndStyles[vitepressPath] = style
}
context.content = context.content.replace(styleRegex, '')
context.content = context.content.replace(vitepressPathRegex, '')
},
transformHtml(code, id) {
const html = id.split('/').pop()
if (!html) return
const style = fileAndStyles[`/${html}`]
if (style) {
return code.replace(/<\/head>/, style + '</head>')
}
}
})
|
07akioni/naive-ui-vitepress-demo
| 8
|
This is a demo for using `naive-ui` in `vitepress` with SSR enabled.
|
TypeScript
|
07akioni
|
07akioni
|
DeepSeek
|
.vitepress/theme/index.js
|
JavaScript
|
// .vitepress/theme/index.js
import { defineComponent, h, inject } from 'vue'
import DefaultTheme from 'vitepress/theme'
import { NConfigProvider } from 'naive-ui'
import { setup } from '@css-render/vue3-ssr'
import { useRoute } from 'vitepress'
const { Layout } = DefaultTheme
const CssRenderStyle = defineComponent({
setup() {
const collect = inject('css-render-collect')
return {
style: collect()
}
},
render() {
return h('css-render-style', {
innerHTML: this.style
})
}
})
const VitepressPath = defineComponent({
setup() {
const route = useRoute()
return () => {
return h('vitepress-path', null, [route.path])
}
}
})
const NaiveUIProvider = defineComponent({
render() {
return h(
NConfigProvider,
{ abstract: true, inlineThemeDisabled: true },
{
default: () => [
h(Layout, null, { default: this.$slots.default?.() }),
import.meta.env.SSR ? [h(CssRenderStyle), h(VitepressPath)] : null
]
}
)
}
})
export default {
extends: DefaultTheme,
Layout: NaiveUIProvider,
enhanceApp: ({ app }) => {
if (import.meta.env.SSR) {
const { collect } = setup(app)
app.provide('css-render-collect', collect)
}
}
}
|
07akioni/naive-ui-vitepress-demo
| 8
|
This is a demo for using `naive-ui` in `vitepress` with SSR enabled.
|
TypeScript
|
07akioni
|
07akioni
|
DeepSeek
|
eslint.config.mjs
|
JavaScript
|
// @ts-check
import { createConfigForNuxt } from '@nuxt/eslint-config/flat'
// Run `npx @eslint/config-inspector` to inspect the resolved config interactively
export default createConfigForNuxt({
features: {
// Rules for module authors
tooling: true,
// Rules for formatting
stylistic: true,
},
dirs: {
src: [
'./playground',
],
},
})
.append(
// your custom flat config here...
)
|
07akioni/nuxtjs-naive-ui
| 27
|
The official nuxt module for naive-ui that supports Nuxt.js SSR.
|
TypeScript
|
07akioni
|
07akioni
|
DeepSeek
|
playground/app.vue
|
Vue
|
<template>
<NConfigProvider inline-theme-disabled>
<NButton>Hello World</NButton>
</NConfigProvider>
</template>
<script setup lang="ts">
import { NButton, NConfigProvider } from 'naive-ui'
</script>
|
07akioni/nuxtjs-naive-ui
| 27
|
The official nuxt module for naive-ui that supports Nuxt.js SSR.
|
TypeScript
|
07akioni
|
07akioni
|
DeepSeek
|
playground/nuxt.config.ts
|
TypeScript
|
export default defineNuxtConfig({
modules: ['../src/module'],
devtools: { enabled: true },
})
|
07akioni/nuxtjs-naive-ui
| 27
|
The official nuxt module for naive-ui that supports Nuxt.js SSR.
|
TypeScript
|
07akioni
|
07akioni
|
DeepSeek
|
src/module.ts
|
TypeScript
|
import { defineNuxtModule, createResolver, addPlugin } from '@nuxt/kit'
// Module options TypeScript interface definition
export interface ModuleOptions {}
export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'nuxtjs-naive-ui',
configKey: 'naive-ui',
},
// Default configuration options of the Nuxt module
defaults: {},
setup(_options, _nuxt) {
_nuxt.options.nitro.plugins = _nuxt.options.nitro.plugins || []
// Setup transpile
const transpile = process.env.NODE_ENV === 'production' ? ['naive-ui'] : []
if (!_nuxt.options.build.transpile) {
_nuxt.options.build.transpile = transpile
}
else {
_nuxt.options.build.transpile
= _nuxt.options.build.transpile.concat(transpile)
}
const resolver = createResolver(import.meta.url)
// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
addPlugin(resolver.resolve('./runtime/plugin'))
},
})
|
07akioni/nuxtjs-naive-ui
| 27
|
The official nuxt module for naive-ui that supports Nuxt.js SSR.
|
TypeScript
|
07akioni
|
07akioni
|
DeepSeek
|
src/runtime/plugin.ts
|
TypeScript
|
import { setup } from '@css-render/vue3-ssr'
import { defineNuxtPlugin } from '#app'
export default defineNuxtPlugin((_nuxtApp) => {
if (import.meta.server) {
const { collect } = setup(_nuxtApp.vueApp)
_nuxtApp.hooks.hook('app:rendered', () => {
if (_nuxtApp.ssrContext) {
if (typeof _nuxtApp.ssrContext.styles === 'string') {
_nuxtApp.ssrContext.styles += collect()
}
else if (!_nuxtApp.ssrContext.styles) {
_nuxtApp.ssrContext.styles = collect()
}
}
})
}
})
|
07akioni/nuxtjs-naive-ui
| 27
|
The official nuxt module for naive-ui that supports Nuxt.js SSR.
|
TypeScript
|
07akioni
|
07akioni
|
DeepSeek
|
test/basic.test.ts
|
TypeScript
|
import { fileURLToPath } from 'node:url'
import { describe, it, expect } from 'vitest'
import { setup, $fetch } from '@nuxt/test-utils/e2e'
describe('ssr', async () => {
await setup({
rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)),
})
it('renders the index page', async () => {
// Get response to a server-rendered page with `$fetch`.
const html = await $fetch('/')
expect(html).toContain('<div>basic</div>')
})
})
|
07akioni/nuxtjs-naive-ui
| 27
|
The official nuxt module for naive-ui that supports Nuxt.js SSR.
|
TypeScript
|
07akioni
|
07akioni
|
DeepSeek
|
test/fixtures/basic/app.vue
|
Vue
|
<template>
<div>basic</div>
</template>
<script setup>
</script>
|
07akioni/nuxtjs-naive-ui
| 27
|
The official nuxt module for naive-ui that supports Nuxt.js SSR.
|
TypeScript
|
07akioni
|
07akioni
|
DeepSeek
|
test/fixtures/basic/nuxt.config.ts
|
TypeScript
|
import MyModule from '../../../src/module'
export default defineNuxtConfig({
modules: [
MyModule,
],
})
|
07akioni/nuxtjs-naive-ui
| 27
|
The official nuxt module for naive-ui that supports Nuxt.js SSR.
|
TypeScript
|
07akioni
|
07akioni
|
DeepSeek
|
config.mjs
|
JavaScript
|
import path from "path";
import { fileURLToPath } from "url";
import HtmlWebpackPlugin from "html-webpack-plugin";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const isRunningWebpack = !!process.env.WEBPACK;
const isRunningRspack = !!process.env.RSPACK;
if (!isRunningRspack && !isRunningWebpack) {
throw new Error("Unknown bundler");
}
/**
* @type {import('webpack').Configuration | import('@rspack/cli').Configuration}
*/
const config = {
mode: "development",
devtool: false,
entry: {
main: "./src/index",
},
plugins: [new HtmlWebpackPlugin()],
output: {
clean: true,
path: isRunningWebpack
? path.resolve(__dirname, "webpack-dist")
: path.resolve(__dirname, "rspack-dist"),
filename: "[name].js",
},
experiments: {
css: true,
},
};
export default config;
|
07akioni/rspack-treeshaking-issue-reprod
| 0
|
JavaScript
|
07akioni
|
07akioni
|
DeepSeek
|
|
rspack-dist/index.html
|
HTML
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Webpack App</title>
<meta name="viewport" content="width=device-width, initial-scale=1"><script defer src="main.js"></script></head>
<body>
</body>
</html>
|
07akioni/rspack-treeshaking-issue-reprod
| 0
|
JavaScript
|
07akioni
|
07akioni
|
DeepSeek
|
|
rspack-dist/main.js
|
JavaScript
|
(function() {
var __webpack_modules__ = {
"./src/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */var micromark_extension_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! micromark-extension-math */"./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/index.js");
console.log(micromark_extension_math__WEBPACK_IMPORTED_MODULE_0__.math);
__webpack_require__.el("./src/index.js@68:83").then(__webpack_require__.bind(__webpack_require__, /*! katex */"./node_modules/.pnpm/katex@0.16.9/node_modules/katex/dist/katex.mjs")).then((katex)=>{
console.log(katex);
});
}),
"./node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/dist/index.mjs": (function (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
dequal: function() { return dequal; }
});
var has = Object.prototype.hasOwnProperty;
function find(iter, tar, key) {
for (key of iter.keys()){
if (dequal(key, tar)) return key;
}
}
function dequal(foo, bar) {
var ctor, len, tmp;
if (foo === bar) return true;
if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
if (ctor === Date) return foo.getTime() === bar.getTime();
if (ctor === RegExp) return foo.toString() === bar.toString();
if (ctor === Array) {
if ((len = foo.length) === bar.length) {
while(len-- && dequal(foo[len], bar[len]));
}
return len === -1;
}
if (ctor === Set) {
if (foo.size !== bar.size) return false;
for (len of foo){
tmp = len;
if (tmp && typeof tmp === 'object') {
tmp = find(bar, tmp);
if (!tmp) return false;
}
if (!bar.has(tmp)) return false;
}
return true;
}
if (ctor === Map) {
if (foo.size !== bar.size) return false;
for (len of foo){
tmp = len[0];
if (tmp && typeof tmp === 'object') {
tmp = find(bar, tmp);
if (!tmp) return false;
}
if (!dequal(len[1], bar.get(tmp))) return false;
}
return true;
}
if (ctor === ArrayBuffer) {
foo = new Uint8Array(foo);
bar = new Uint8Array(bar);
} else if (ctor === DataView) {
if ((len = foo.byteLength) === bar.byteLength) {
while(len-- && foo.getInt8(len) === bar.getInt8(len));
}
return len === -1;
}
if (ArrayBuffer.isView(foo)) {
if ((len = foo.byteLength) === bar.byteLength) {
while(len-- && foo[len] === bar[len]);
}
return len === -1;
}
if (!ctor || typeof foo === 'object') {
len = 0;
for(ctor in foo){
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
}
return Object.keys(bar).length === len;
}
}
return foo !== foo && bar !== bar;
}
}),
"./node_modules/.pnpm/devlop@1.1.0/node_modules/devlop/lib/development.js": (function (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
deprecate: function() { return deprecate; },
equal: function() { return equal; },
ok: function() { return ok; },
unreachable: function() { return unreachable; }
});
/* harmony import */var dequal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! dequal */"./node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/dist/index.mjs");
/**
* @type {Set<string>}
*/ const codesWarned = new Set();
class AssertionError extends Error {
name = 'Assertion';
code = 'ERR_ASSERTION';
/**
* Create an assertion error.
*
* @param {string} message
* Message explaining error.
* @param {unknown} actual
* Value.
* @param {unknown} expected
* Baseline.
* @param {string} operator
* Name of equality operation.
* @param {boolean} generated
* Whether `message` is a custom message or not
* @returns
* Instance.
*/ // eslint-disable-next-line max-params
constructor(message, actual, expected, operator, generated){
super(message);
if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
/**
* @type {unknown}
*/ this.actual = actual;
/**
* @type {unknown}
*/ this.expected = expected;
/**
* @type {boolean}
*/ this.generated = generated;
/**
* @type {string}
*/ this.operator = operator;
}
}
class DeprecationError extends Error {
name = 'DeprecationWarning';
/**
* Create a deprecation message.
*
* @param {string} message
* Message explaining deprecation.
* @param {string | undefined} code
* Deprecation identifier; deprecation messages will be generated only once per code.
* @returns
* Instance.
*/ constructor(message, code){
super(message);
/**
* @type {string | undefined}
*/ this.code = code;
}
}
/**
* Wrap a function or class to show a deprecation message when first called.
*
* > 👉 **Important**: only shows a message when the `development` condition is
* > used, does nothing in production.
*
* When the resulting wrapped `fn` is called, emits a warning once to
* `console.error` (`stderr`).
* If a code is given, one warning message will be emitted in total per code.
*
* @template {Function} T
* Function or class kind.
* @param {T} fn
* Function or class.
* @param {string} message
* Message explaining deprecation.
* @param {string | null | undefined} [code]
* Deprecation identifier (optional); deprecation messages will be generated
* only once per code.
* @returns {T}
* Wrapped `fn`.
*/ function deprecate(fn, message, code) {
let warned = false;
// The wrapper will keep the same prototype as fn to maintain prototype chain
Object.setPrototypeOf(deprecated, fn);
// @ts-expect-error: it’s perfect, typescript…
return deprecated;
/**
* @this {unknown}
* @param {...Array<unknown>} args
* @returns {unknown}
*/ function deprecated(...args) {
if (!warned) {
warned = true;
if (typeof code === 'string' && codesWarned.has(code)) ;
else {
console.error(new DeprecationError(message, code || undefined));
if (typeof code === 'string') codesWarned.add(code);
}
}
return new.target ? Reflect.construct(fn, args, new.target) : Reflect.apply(fn, this, args);
}
}
/**
* Assert deep strict equivalence.
*
* > 👉 **Important**: only asserts when the `development` condition is used,
* > does nothing in production.
*
* @template {unknown} T
* Expected kind.
* @param {unknown} actual
* Value.
* @param {T} expected
* Baseline.
* @param {Error | string | null | undefined} [message]
* Message for assertion error (default: `'Expected values to be deeply equal'`).
* @returns {asserts actual is T}
* Nothing; throws when `actual` is not deep strict equal to `expected`.
* @throws {AssertionError}
* Throws when `actual` is not deep strict equal to `expected`.
*/ function equal(actual, expected, message) {
assert((0, dequal__WEBPACK_IMPORTED_MODULE_0__.dequal)(actual, expected), actual, expected, 'equal', 'Expected values to be deeply equal', message);
}
/**
* Assert if `value` is truthy.
*
* > 👉 **Important**: only asserts when the `development` condition is used,
* > does nothing in production.
*
* @param {unknown} value
* Value to assert.
* @param {Error | string | null | undefined} [message]
* Message for assertion error (default: `'Expected value to be truthy'`).
* @returns {asserts value}
* Nothing; throws when `value` is falsey.
* @throws {AssertionError}
* Throws when `value` is falsey.
*/ function ok(value, message) {
assert(Boolean(value), false, true, 'ok', 'Expected value to be truthy', message);
}
/**
* Assert that a code path never happens.
*
* > 👉 **Important**: only asserts when the `development` condition is used,
* > does nothing in production.
*
* @param {Error | string | null | undefined} [message]
* Message for assertion error (default: `'Unreachable'`).
* @returns {never}
* Nothing; always throws.
* @throws {AssertionError}
* Throws when `value` is falsey.
*/ function unreachable(message) {
assert(false, false, true, 'ok', 'Unreachable', message);
}
/**
* @param {boolean} bool
* Whether to skip this operation.
* @param {unknown} actual
* Actual value.
* @param {unknown} expected
* Expected value.
* @param {string} operator
* Operator.
* @param {string} defaultMessage
* Default message for operation.
* @param {Error | string | null | undefined} userMessage
* User-provided message.
* @returns {asserts bool}
* Nothing; throws when falsey.
*/ // eslint-disable-next-line max-params
function assert(bool, actual, expected, operator, defaultMessage, userMessage) {
if (!bool) throw userMessage instanceof Error ? userMessage : new AssertionError(userMessage || defaultMessage, actual, expected, operator, !userMessage);
}
}),
"./node_modules/.pnpm/katex@0.16.9/node_modules/katex/dist/katex.mjs": (function (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
"default": function() { return katex; }
});
/**
* Lexing or parsing positional information for error reporting.
* This object is immutable.
*/ class SourceLocation {
// The + prefix indicates that these fields aren't writeable
// Lexer holding the input string.
// Start offset, zero-based inclusive.
// End offset, zero-based exclusive.
constructor(lexer, start, end){
this.lexer = void 0;
this.start = void 0;
this.end = void 0;
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, second) {
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);
}
}
/**
* Interface required to break circular dependency between Token, Lexer, and
* ParseError.
*/ /**
* 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.
*/ class Token {
// don't expand the token
// used in \noexpand
constructor(text, loc){
this.text = void 0;
this.loc = void 0;
this.noexpand = void 0;
this.treatAsRelax = void 0;
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, text // the text of the newly constructed token
) {
return new Token(text, SourceLocation.range(this, endToken));
}
}
/**
* 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 {
// Error start position based on passed-in Token or ParseNode.
// Length of affected text based on passed-in Token or ParseNode.
// The underlying error message without any context added.
constructor(message, token // An object providing position information
){
this.name = void 0;
this.position = void 0;
this.length = void 0;
this.rawMessage = void 0;
var error = "KaTeX parse error: " + message;
var start;
var end;
var 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
var 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
var underlined = input.slice(start, end).replace(/[^]/g, "$&\u0332"); // Extract some context from the input and add it to the error
var left;
if (start > 15) left = "…" + input.slice(start - 15, start);
else left = input.slice(0, start);
var 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
var self = 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;
/**
* This file contains a list of utility functions which are useful in other
* files.
*/ /**
* Return whether an element is contained in a list
*/ var contains = function contains(list, elem) {
return list.indexOf(elem) !== -1;
};
/**
* Provide a default value if a setting is undefined
* NOTE: Couldn't use `T` as the output type due to facebook/flow#5022.
*/ var deflt = function deflt(setting, defaultIfUndefined) {
return setting === undefined ? defaultIfUndefined : setting;
}; // hyphenate and escape adapted from Facebook's React under Apache 2 license
var uppercase = /([A-Z])/g;
var hyphenate = function hyphenate(str) {
return str.replace(uppercase, "-$1").toLowerCase();
};
var ESCAPE_LOOKUP = {
"&": "&",
">": ">",
"<": "<",
"\"": """,
"'": "'"
};
var ESCAPE_REGEX = /[&><"']/g;
/**
* Escapes text to prevent scripting attacks.
*/ function escape(text) {
return String(text).replace(ESCAPE_REGEX, (match)=>ESCAPE_LOOKUP[match]);
}
/**
* Sometimes we want to pull out the innermost element of a group. In most
* cases, this will just be the group itself, but when ordgroups and colors have
* a single element, we want to pull that out.
*/ var getBaseElem = function getBaseElem(group) {
if (group.type === "ordgroup") {
if (group.body.length === 1) return getBaseElem(group.body[0]);
else return group;
} else if (group.type === "color") {
if (group.body.length === 1) return getBaseElem(group.body[0]);
else return group;
} else if (group.type === "font") return getBaseElem(group.body);
else return group;
};
/**
* TeXbook algorithms often reference "character boxes", which are simply groups
* with a single character in them. To decide if something is a character box,
* we find its innermost group, and see if it is a single character.
*/ var isCharacterBox = function isCharacterBox(group) {
var baseElem = getBaseElem(group); // These are all they types of groups which hold single characters
return baseElem.type === "mathord" || baseElem.type === "textord" || baseElem.type === "atom";
};
var assert = function assert(value) {
if (!value) throw new Error('Expected non-null, but got ' + String(value));
return value;
};
/**
* Return the protocol of a URL, or "_relative" if the URL does not specify a
* protocol (and thus is relative).
*/ var protocolFromUrl = function protocolFromUrl(url) {
var protocol = /^\s*([^\\/#]*?)(?::|�*58|�*3a)/i.exec(url);
return protocol != null ? protocol[1] : "_relative";
};
var utils = {
contains,
deflt,
escape,
hyphenate,
getBaseElem,
isCharacterBox,
protocolFromUrl
};
/* eslint no-console:0 */ // TODO: automatically generate documentation
// TODO: check all properties on Settings exist
// TODO: check the type of a property on Settings matches
var SETTINGS_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) instead 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) {
if (schema.default) return schema.default;
var type = schema.type;
var 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.
*/ class Settings {
constructor(options){
this.displayMode = void 0;
this.output = void 0;
this.leqno = void 0;
this.fleqn = void 0;
this.throwOnError = void 0;
this.errorColor = void 0;
this.macros = void 0;
this.minRuleThickness = void 0;
this.colorIsTextColor = void 0;
this.strict = void 0;
this.trust = void 0;
this.maxSize = void 0;
this.maxExpand = void 0;
this.globalGroup = void 0;
// allow null options
options = options || {};
for(var prop in SETTINGS_SCHEMA)if (SETTINGS_SCHEMA.hasOwnProperty(prop)) {
// $FlowFixMe
var 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, errorMsg, token) {
var 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, errorMsg, token) {
var 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) {
if (context.url && !context.protocol) context.protocol = utils.protocolFromUrl(context.url);
var trust = typeof this.trust === "function" ? this.trust(context) : this.trust;
return Boolean(trust);
}
}
/**
* 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 {
constructor(id, size, cramped){
this.id = void 0;
this.size = void 0;
this.cramped = void 0;
this.id = id;
this.size = size;
this.cramped = cramped;
}
/**
* Get the style of a superscript given a base in the current style.
*/ sup() {
return styles[sup[this.id]];
}
/**
* Get the style of a subscript given a base in the current style.
*/ sub() {
return styles[sub[this.id]];
}
/**
* Get the style of a fraction numerator given the fraction in the current
* style.
*/ fracNum() {
return styles[fracNum[this.id]];
}
/**
* Get the style of a fraction denominator given the fraction in the current
* style.
*/ fracDen() {
return styles[fracDen[this.id]];
}
/**
* Get the cramped version of a style (in particular, cramping a cramped style
* doesn't change the style).
*/ cramp() {
return styles[cramp[this.id]];
}
/**
* Get a text or display version of this style.
*/ text() {
return styles[text$1[this.id]];
}
/**
* Return true if this style is tightly spaced (scriptstyle/scriptscriptstyle)
*/ isTight() {
return this.size >= 2;
}
} // Export an interface for type checking, but don't expose the implementation.
// This way, no more styles can be generated.
// IDs of the different styles
var D = 0;
var Dc = 1;
var T = 2;
var Tc = 3;
var S = 4;
var Sc = 5;
var SS = 6;
var SSc = 7; // Instances of the different styles
var 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
var sup = [
S,
Sc,
S,
Sc,
SS,
SSc,
SS,
SSc
];
var sub = [
Sc,
Sc,
Sc,
Sc,
SSc,
SSc,
SSc,
SSc
];
var fracNum = [
T,
Tc,
S,
Sc,
SS,
SSc,
SS,
SSc
];
var fracDen = [
Tc,
Tc,
Sc,
Sc,
SSc,
SSc,
SSc,
SSc
];
var cramp = [
Dc,
Dc,
Tc,
Tc,
Sc,
Sc,
SSc,
SSc
];
var text$1 = [
D,
Dc,
T,
Tc,
T,
Tc,
T,
Tc
]; // We only export some of the styles.
var Style$1 = {
DISPLAY: styles[D],
TEXT: styles[T],
SCRIPT: styles[S],
SCRIPTSCRIPT: styles[SS]
};
/*
* 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.
*/ /**
* 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.
*/ var scriptData = [
{
// 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
],
[
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 (0900–097F)
// Bengali (0980–09FF)
// Gurmukhi (0A00–0A7F)
// Gujarati (0A80–0AFF)
// Oriya (0B00–0B7F)
// Tamil (0B80–0BFF)
// Telugu (0C00–0C7F)
// Kannada (0C80–0CFF)
// Malayalam (0D00–0D7F)
// Sinhala (0D80–0DFF)
// Thai (0E00–0E7F)
// Lao (0E80–0EFF)
// Tibetan (0F00–0FFF)
// Myanmar (1000–109F)
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
],
[
0x4E00,
0x9FAF
],
[
0xFF00,
0xFF60
] // Fullwidth punctuation
]
},
{
// 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
*/ function scriptFromCodepoint(codepoint) {
for(var i = 0; i < scriptData.length; i++){
var script = scriptData[i];
for(var _i = 0; _i < script.blocks.length; _i++){
var 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.
*/ var allBlocks = [];
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.
*/ function supportedCodepoint(codepoint) {
for(var i = 0; i < allBlocks.length; i += 2){
if (codepoint >= allBlocks[i] && codepoint <= allBlocks[i + 1]) return true;
}
return false;
}
/**
* 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.
var 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
*/ var sqrtMain = function sqrtMain(extraVinculum, hLinePad) {
// sqrtMain path geometry is from glyph U221A in the font KaTeX Main
return "M95," + (622 + extraVinculum + hLinePad) + "\nc-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14\nc0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54\nc44.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\ns173,378,173,378c0.7,0,35.3,-71,104,-213c68.7,-142,137.5,-285,206.5,-429\nc69,-144,104.5,-217.7,106.5,-221\nl" + extraVinculum / 2.075 + " -" + extraVinculum + "\nc5.3,-9.3,12,-14,20,-14\nH400000v" + (40 + extraVinculum) + "H845.2724\ns-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7\nc-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z\nM" + (834 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "h-400000z";
};
var sqrtSize1 = function sqrtSize1(extraVinculum, hLinePad) {
// size1 is from glyph U221A in the font KaTeX_Size1-Regular
return "M263," + (601 + extraVinculum + hLinePad) + "c0.7,0,18,39.7,52,119\nc34,79.3,68.167,158.7,102.5,238c34.3,79.3,51.8,119.3,52.5,120\nc340,-704.7,510.7,-1060.3,512,-1067\nl" + extraVinculum / 2.084 + " -" + extraVinculum + "\nc4.7,-7.3,11,-11,19,-11\nH40000v" + (40 + extraVinculum) + "H1012.3\ns-271.3,567,-271.3,567c-38.7,80.7,-84,175,-136,283c-52,108,-89.167,185.3,-111.5,232\nc-22.3,46.7,-33.8,70.3,-34.5,71c-4.7,4.7,-12.3,7,-23,7s-12,-1,-12,-1\ns-109,-253,-109,-253c-72.7,-168,-109.3,-252,-110,-252c-10.7,8,-22,16.7,-34,26\nc-22,17.3,-33.3,26,-34,26s-26,-26,-26,-26s76,-59,76,-59s76,-60,76,-60z\nM" + (1001 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "h-400000z";
};
var sqrtSize2 = function sqrtSize2(extraVinculum, hLinePad) {
// size2 is from glyph U221A in the font KaTeX_Size2-Regular
return "M983 " + (10 + extraVinculum + hLinePad) + "\nl" + extraVinculum / 3.13 + " -" + extraVinculum + "\nc4,-6.7,10,-10,18,-10 H400000v" + (40 + extraVinculum) + "\nH1013.1s-83.4,268,-264.1,840c-180.7,572,-277,876.3,-289,913c-4.7,4.7,-12.7,7,-24,7\ns-12,0,-12,0c-1.3,-3.3,-3.7,-11.7,-7,-25c-35.3,-125.3,-106.7,-373.3,-214,-744\nc-10,12,-21,25,-33,39s-32,39,-32,39c-6,-5.3,-15,-14,-27,-26s25,-30,25,-30\nc26.7,-32.7,52,-63,76,-91s52,-60,52,-60s208,722,208,722\nc56,-175.3,126.3,-397.3,211,-666c84.7,-268.7,153.8,-488.2,207.5,-658.5\nc53.7,-170.3,84.5,-266.8,92.5,-289.5z\nM" + (1001 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "h-400000z";
};
var sqrtSize3 = function sqrtSize3(extraVinculum, hLinePad) {
// size3 is from glyph U221A in the font KaTeX_Size3-Regular
return "M424," + (2398 + extraVinculum + hLinePad) + "\nc-1.3,-0.7,-38.5,-172,-111.5,-514c-73,-342,-109.8,-513.3,-110.5,-514\nc0,-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\ns-5,7,-5,7c-4,-3.3,-8.3,-7.7,-13,-13s-13,-13,-13,-13s76,-122,76,-122s77,-121,77,-121\ns209,968,209,968c0,-2,84.7,-361.7,254,-1079c169.3,-717.3,254.7,-1077.7,256,-1081\nl" + extraVinculum / 4.223 + " -" + extraVinculum + "c4,-6.7,10,-10,18,-10 H400000\nv" + (40 + extraVinculum) + "H1014.6\ns-87.3,378.7,-272.6,1166c-185.3,787.3,-279.3,1182.3,-282,1185\nc-2,6,-10,9,-24,9\nc-8,0,-12,-0.7,-12,-2z M" + (1001 + extraVinculum) + " " + hLinePad + "\nh400000v" + (40 + extraVinculum) + "h-400000z";
};
var sqrtSize4 = function sqrtSize4(extraVinculum, hLinePad) {
// size4 is from glyph U221A in the font KaTeX_Size4-Regular
return "M473," + (2713 + extraVinculum + hLinePad) + "\nc339.3,-1799.3,509.3,-2700,510,-2702 l" + extraVinculum / 5.298 + " -" + extraVinculum + "\nc3.3,-7.3,9.3,-11,18,-11 H400000v" + (40 + extraVinculum) + "H1017.7\ns-90.5,478,-276.2,1466c-185.7,988,-279.5,1483,-281.5,1485c-2,6,-10,9,-24,9\nc-8,0,-12,-0.7,-12,-2c0,-1.3,-5.3,-32,-16,-92c-50.7,-293.3,-119.7,-693.3,-207,-1200\nc0,-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\ns76,-153,76,-153s77,-151,77,-151c0.7,0.7,35.7,202,105,604c67.3,400.7,102,602.7,104,\n606zM" + (1001 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "H1017.7z";
};
var phasePath = function phasePath(y) {
var x = y / 2; // x coordinate at top of angle
return "M400000 " + y + " H0 L" + x + " 0 l65 45 L145 " + (y - 80) + " H400000z";
};
var sqrtTall = function sqrtTall(extraVinculum, hLinePad, viewBoxHeight) {
// 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:
var vertSegment = viewBoxHeight - 54 - hLinePad - extraVinculum;
return "M702 " + (extraVinculum + hLinePad) + "H400000" + (40 + extraVinculum) + "\nH742v" + 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\nh-12l-28-84c-16.667-52-96.667 -294.333-240-727l-212 -643 -85 170\nc-4-3.333-8.333-7.667-13 -13l-13-13l77-155 77-156c66 199.333 139 419.667\n219 661 l218 661zM702 " + hLinePad + "H400000v" + (40 + extraVinculum) + "H742z";
};
var sqrtPath = function sqrtPath(size, extraVinculum, viewBoxHeight) {
extraVinculum = 1000 * extraVinculum; // Convert from document ems to viewBox.
var 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;
};
var innerPath = function innerPath(name, height) {
// 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 "";
}
};
var path = {
// The doubleleftarrow geometry is from glyph U+21D0 in the font KaTeX Main
doubleleftarrow: "M262 157\nl10-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\n 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\n 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\nc2 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\n 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\n-86-123l-10-10h399738v-40H218c328 0 0 0 0 0l-10-8c-26.7-20-65.7-43-117-69 2.7\n-2 6-3.7 10-5 36.7-16 72.3-37.3 107-64l10-8h399782v-40z\nm8 0v40h399730v-40zm0 194v40h399730v-40z",
// doublerightarrow is from glyph U+21D2 in font KaTeX Main
doublerightarrow: "M399738 392l\n-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\n 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\n-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\n-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\n-13h-6c-12 .7-18 4-18 10 0 2 1.7 7 5 15 23.3 46 52 87 86 123l10 10H0v40h399782\nc-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\n-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\n 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\n-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\nc-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\n 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\n 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\n 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\n-45 179-50h399577v120H403c-43.3 7-81 15-113 26-100.7 33-179.7 91-237 174-2.7\n 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\n 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\n 0 2 .3 4 1 18.688 2.7 76 4.3 172 5h399450v120H429l-6-1c-124.688-8-235-61.7\n-331-161C60.687 138.7 32.312 99.3 7 54L0 41V6z",
// overgroup is from the MnSymbol package (public domain)
leftgroup: "M400000 80\nH435C64 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\n 435 0h399565z",
leftgroupunder: "M400000 262\nH435C64 262 168.3 112.6 21 82c-5.9-1.2-18 0-18 0-2 0-3 1-3 3v38c76 158 257 219\n 435 219h399565z",
// Harpoons are from glyph U+21BD in font KaTeX Main
leftharpoon: "M0 267c.7 5.3 3 10 7 14h399993v-40H93c3.3\n-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\n-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\n-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\n 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\n-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\n-10.7 8-12 10-1.3 2-2 5.7-2 11zm100-26v40h399900v-40zM0 435v40h400000v-40z\nm0 0v40h400000v-40z",
leftharpoondown: "M7 241c-4 4-6.333 8.667-7 14 0 5.333.667 9 2 11s5.333\n 5.333 12 10c90.667 54 156 130 196 228 3.333 10.667 6.333 16.333 9 17 2 .667 5\n 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\n-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\n 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\n-2 18-6 2-2.7 1-9.7-3-21-32-87.3-82.7-157.7-152-211l-3-3h399907v-40H7zm93 0\nv40h399900v-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\n-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\n-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\n 71.5 23h399859zM103 281v-40h399897v40z",
leftlinesegment: "M40 281 V428 H0 V94 H40 V241 H400000 v40z\nM40 281 V428 H0 V94 H40 V241 H400000 v40z",
leftmapsto: "M40 281 V448H0V74H40V241H400000v40z\nM40 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\n-.3 23-1 0-1.3-5.3-13.7-16-37-18-35.3-41.3-69-70-101l-7-8h399905v-40H95l7-8\nc28.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\n 68 321 0 361zm0-174v-40h399900v40zm100 154v40h399900v-40z",
longequal: "M0 50 h400000 v40H0z m0 194h40000v40H0z\nM0 50 h400000 v40H0z m0 194h40000v40H0z",
midbrace: "M200428 334\nc-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\n-53.3 86.7-123.7 153-211 199-66.7 36-137.3 56.3-212 62H0V214h199568c178.3-11.7\n 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\n 12 44.7 59.3 101.3 106.3 170 141s145.3 54.3 229 60h199572v120z",
midbraceunder: "M199572 214\nc100.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\n 53.3-86.7 123.7-153 211-199 66.7-36 137.3-56.3 212-62h199568v120H200432c-178.3\n 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\n-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\n-320.3 177.6S193.1 320.6 193.1 249.8c0-71.4 46.9-178.2 319.5-178.2z\nm368.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\n60.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\n-451.1 228.8-386.3 0-452.7-137.5-452.7-228.8 0-92.4 66.4-230 452.7-230z\nm502.4 230c0-111.2-82.4-277.2-502.4-277.2s-504 166-504 277.2\nc0 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\n-480.5 177.6S202.1 320.6 202.1 249.8c0-71.4 70.5-178.2 479.3-178.2z\nm525.8 178.2c0-86.4-86.8-215.4-525.7-215.4-437.9 0-524.7 129-524.7 215.4 0\n85.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\n-707.8 275.8-606 0-710.2-165.8-710.2-275.8C311 218.8 415.2 53 1021.2 53z\nm770.4 277.1c0-131.2-126.4-327.6-770.5-327.6S248.4 198.9 248.4 330.1\nc0 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\n-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\n 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\n 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\n-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\n-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\n 151.7 139 205zm0 0v40h399900v-40z",
rightbrace: "M400000 542l\n-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\ns-117.2-55.8-184.5-66.5c-.7 0-2-.3-4-1-18.7-2.7-76-4.3-172-5H0V214h399571l6 1\nc124.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\n 28.7-117 45-179 50H-300V214h399897c43.3-7 81-15 113-26 100.7-33 179.7-91 237\n-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\n 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\n 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\n-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\n-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\n 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\n-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\n 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\nm0 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\n 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\n-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\n-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\n 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\n 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\n-64.7 57-92 95-27.3 38-48.7 77.7-64 119-3.3 8.7-5 14-5 16zM0 435v40h399900v-40z\nm0-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\n 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\n-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\n 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\nM399960 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\n 1 0 1.3 5.3 13.7 16 37 18 35.3 41.3 69 70 101l7 8H0v40h399905l-7 8c-28.7 32\n-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\n-167z M100 147v40h399900v-40zM0 341v40h399900v-40z",
// twoheadleftarrow is from glyph U+219E in font KaTeX AMS Regular
twoheadleftarrow: "M0 167c68 40\n 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\n-70-101l-7-8h125l9 7c50.7 39.3 85 86 103 140h46c0-4.7-6.3-18.7-19-42-18-35.3\n-40-67.3-66-96l-9-9h399716v-40H284l9-9c26-28.7 48-60.7 66-96 12.7-23.333 19\n-37.333 19-42h-46c-18 54-52.3 100.7-103 140l-9 7H95l7-8c28.7-32 52-65.7 70-101\n 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\nc-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\n 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\n 18 35.3 40 67.3 66 96l9 9H0v40h399716l-9 9c-26 28.7-48 60.7-66 96-12.7 23.333\n-19 37.333-19 42h46c18-54 52.3-100.7 103-140l9-7h125l-7 8c-28.7 32-52 65.7-70\n 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\n-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\n 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\n 4.35-2 7.613-5 9.788l-19 13.05c-92 63.077-116.937 75.308-183 76.128\n-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\n-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\n 31.9 283 0 358 0c148 0 188 122 331 122s314-97 326-97c4 0 8 2 10 7l7 21.114\nc1 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\n 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\n-11-10.37L.15 138c-1-7 3-12 10-13l19.2-6.4C378.4 40.7 634.3 0 804.3 0c337 0\n 411.8 157 746.8 157 328 0 754-112 773-112 5 0 10 3 11 9l1 14.075c1 8.066-.697\n 16.595-6.697 17.492l-21.052 7.31c-367.9 98.146-609.15 122.696-778.15 122.696\n -338 0-409-156.573-744-156.573z",
tilde4: "M786 58C457 58 32 177.487 13 177.487c-6 0-10-3.345\n-11-10.035L.15 143c-1-7 3-12 10-13l22-6.7C381.2 35 637.15 0 807.15 0c337 0 409\n 177 744 177 328 0 754-127 773-127 5 0 10 3 11 9l1 14.794c1 7.805-3 13.38-9\n 14.495l-20.7 5.574c-366.85 99.79-607.3 139.372-776.3 139.372-338 0-409\n -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\n3.333 2.667 6.667 9 10 19 6.667 24.667 20.333 43.667 41 57 7.333 4.667 11\n10.667 11 18 0 6-1 10-3 12s-6.667 5-14 9c-28.667 14.667-53.667 35.667-75 63\n-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\n-7 1c-4.667 0-9.167-1.833-13.5-5.5S337 184 337 178c0-12.667 15.667-32.333 47-59\nH213l-171-1c-8.667-6-13-12.333-13-19 0-4.667 4.333-11.333 13-20h359\nc-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\nc-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\n-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\n-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\n-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,\n-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,\n-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,\n-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,\n-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\nc4 -14.7 6 -23 6 -25c0 -7.3 -7 -11 -21 -11c-8 0 -13.2 0.8 -15.5 2.5\nc-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\ns-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\n121.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\ns2.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\nc0 -2 -2 -10.3 -6 -25c-20 -79.3 -65 -146.7 -135 -202l-3 -3h399890z\nM100 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\n-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\n13.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\n-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\n-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\n-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\n151.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\nc1.3,2,5.3,5.3,12,10c90.7,54,156,130,196,228c3.3,10.7,6.3,16.3,9,17\nc2,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\nc-32,-87.3,-82.7,-157.7,-152,-211c0,0,-3,-3,-3,-3l399351,0l0,-40\nc-398570,0,-399437,0,-399437,0z M593 435 v40 H399500 v-40z\nM0 281 v-40 H399908 v40z M0 281 v-40 H399908 v40z",
rightharpoonaboveshortbar: "M0,241 l0,40c399126,0,399993,0,399993,0\nc4.7,-4.7,7,-9.3,7,-14c0,-9.3,-3.7,-15.3,-11,-18c-92.7,-56.7,-159,-133.7,-199,\n-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\nc-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\nM0 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\nc1.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,\n1c0,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,\n-152,-211c0,0,-3,-3,-3,-3l399907,0l0,-40c-399126,0,-399993,0,-399993,0z\nM93 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\nc4.7,-4.7,7,-9.3,7,-14c0,-9.3,-3.7,-15.3,-11,-18c-92.7,-56.7,-159,-133.7,-199,\n-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\nc-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\nM500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z"
};
var tallDelim = function tallDelim(label, midHeight) {
switch(label){
case "lbrack":
return "M403 1759 V84 H666 V0 H319 V1759 v" + midHeight + " v1759 h347 v-84\nH403z 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\nM347 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\nc10,0,16.667,-5,20,-15 v-585 v" + -midHeight + " v-585 c-2.667,-10,-9.667,-15,-21,-15\nc-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\nc10,0,16.667,-5,20,-15 v-585 v" + -midHeight + " v-585 c-2.667,-10,-9.667,-15,-21,-15\nc-10,0,-16.667,5,-20,15z M188 15 H145 v585 v" + midHeight + " v585 h43z\nM367 15 v585 v" + midHeight + " v585 c2.667,10,9.667,15,21,15\nc10,0,16.667,-5,20,-15 v-585 v" + -midHeight + " v-585 c-2.667,-10,-9.667,-15,-21,-15\nc-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\nMM319 602 V0 H403 V602 v" + midHeight + " v1715 H319z";
case "rfloor":
return "M319 602 V0 H403 V602 v" + midHeight + " v1799 H0 v-84 H319z\nMM319 602 V0 H403 V602 v" + midHeight + " v1715 H319z";
case "lceil":
return "M403 1759 V84 H666 V0 H319 V1759 v" + midHeight + " v602 h84z\nM403 1759 V0 H319 V1759 v" + midHeight + " v602 h84z";
case "rceil":
return "M347 1759 V0 H0 V84 H263 V1759 v" + midHeight + " v602 h84z\nM347 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\nc-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,\n-36,557 l0," + (midHeight + 84) + "c0.2,6,0,26,0,60c2,159.3,10,310.7,24,454c53.3,528,210,\n949.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\nc0,-2.7,-3.3,-8.7,-10,-18c-135.3,-192.7,-235.5,-414.3,-300.5,-665c-65,-250.7,-102.5,\n-544.7,-112.5,-882c-2,-104,-3,-167,-3,-189\nl0,-" + (midHeight + 92) + "c0,-162.7,5.7,-314,17,-454c20.7,-272,63.7,-513,129,-723c65.3,\n-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,\n63,95c96.7,156.7,172.8,332.5,228.5,527.5c55.7,195,92.8,416.5,111.5,664.5\nc11.3,139.3,17,290.7,17,454c0,28,1.7,43,3.3,45l0," + (midHeight + 9) + "\nc-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\nc-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\nc0,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\nc242.7,-294.7,395.3,-681.7,458,-1161c21.3,-164.7,33.3,-350.7,36,-558\nl0,-" + (midHeight + 144) + "c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,\n-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.");
}
};
/**
* 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.
*/ class DocumentFragment {
// HtmlDomNode
// Never used; needed for satisfying interface.
constructor(children){
this.children = void 0;
this.classes = void 0;
this.height = void 0;
this.depth = void 0;
this.maxFontSize = void 0;
this.style = void 0;
this.children = children;
this.classes = [];
this.height = 0;
this.depth = 0;
this.maxFontSize = 0;
this.style = {};
}
hasClass(className) {
return utils.contains(this.classes, className);
}
/** Convert the fragment into a node. */ toNode() {
var frag = document.createDocumentFragment();
for(var i = 0; i < this.children.length; i++)frag.appendChild(this.children[i].toNode());
return frag;
}
/** Convert the fragment into HTML markup. */ toMarkup() {
var markup = ""; // Simply concatenate the markup for the children together.
for(var 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() {
// 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.
var toText = (child)=>child.toText();
return this.children.map(toText).join("");
}
}
// This file is GENERATED by buildMetrics.sh. DO NOT MODIFY.
var fontMetricsData = {
"AMS-Regular": {
"32": [
0,
0,
0,
0,
0.25
],
"65": [
0,
0.68889,
0,
0,
0.72222
],
"66": [
0,
0.68889,
0,
0,
0.66667
],
"67": [
0,
0.68889,
0,
0,
0.72222
],
"68": [
0,
0.68889,
0,
0,
0.72222
],
"69": [
0,
0.68889,
0,
0,
0.66667
],
"70": [
0,
0.68889,
0,
0,
0.61111
],
"71": [
0,
0.68889,
0,
0,
0.77778
],
"72": [
0,
0.68889,
0,
0,
0.77778
],
"73": [
0,
0.68889,
0,
0,
0.38889
],
"74": [
0.16667,
0.68889,
0,
0,
0.5
],
"75": [
0,
0.68889,
0,
0,
0.77778
],
"76": [
0,
0.68889,
0,
0,
0.66667
],
"77": [
0,
0.68889,
0,
0,
0.94445
],
"78": [
0,
0.68889,
0,
0,
0.72222
],
"79": [
0.16667,
0.68889,
0,
0,
0.77778
],
"80": [
0,
0.68889,
0,
0,
0.61111
],
"81": [
0.16667,
0.68889,
0,
0,
0.77778
],
"82": [
0,
0.68889,
0,
0,
0.72222
],
"83": [
0,
0.68889,
0,
0,
0.55556
],
"84": [
0,
0.68889,
0,
0,
0.66667
],
"85": [
0,
0.68889,
0,
0,
0.72222
],
"86": [
0,
0.68889,
0,
0,
0.72222
],
"87": [
0,
0.68889,
0,
0,
1.0
],
"88": [
0,
0.68889,
0,
0,
0.72222
],
"89": [
0,
0.68889,
0,
0,
0.72222
],
"90": [
0,
0.68889,
0,
0,
0.66667
],
"107": [
0,
0.68889,
0,
0,
0.55556
],
"160": [
0,
0,
0,
0,
0.25
],
"165": [
0,
0.675,
0.025,
0,
0.75
],
"174": [
0.15559,
0.69224,
0,
0,
0.94666
],
"240": [
0,
0.68889,
0,
0,
0.55556
],
"295": [
0,
0.68889,
0,
0,
0.54028
],
"710": [
0,
0.825,
0,
0,
2.33334
],
"732": [
0,
0.9,
0,
0,
2.33334
],
"770": [
0,
0.825,
0,
0,
2.33334
],
"771": [
0,
0.9,
0,
0,
2.33334
],
"989": [
0.08167,
0.58167,
0,
0,
0.77778
],
"1008": [
0,
0.43056,
0.04028,
0,
0.66667
],
"8245": [
0,
0.54986,
0,
0,
0.275
],
"8463": [
0,
0.68889,
0,
0,
0.54028
],
"8487": [
0,
0.68889,
0,
0,
0.72222
],
"8498": [
0,
0.68889,
0,
0,
0.55556
],
"8502": [
0,
0.68889,
0,
0,
0.66667
],
"8503": [
0,
0.68889,
0,
0,
0.44445
],
"8504": [
0,
0.68889,
0,
0,
0.66667
],
"8513": [
0,
0.68889,
0,
0,
0.63889
],
"8592": [
-0.03598,
0.46402,
0,
0,
0.5
],
"8594": [
-0.03598,
0.46402,
0,
0,
0.5
],
"8602": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8603": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8606": [
0.01354,
0.52239,
0,
0,
1.0
],
"8608": [
0.01354,
0.52239,
0,
0,
1.0
],
"8610": [
0.01354,
0.52239,
0,
0,
1.11111
],
"8611": [
0.01354,
0.52239,
0,
0,
1.11111
],
"8619": [
0,
0.54986,
0,
0,
1.0
],
"8620": [
0,
0.54986,
0,
0,
1.0
],
"8621": [
-0.13313,
0.37788,
0,
0,
1.38889
],
"8622": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8624": [
0,
0.69224,
0,
0,
0.5
],
"8625": [
0,
0.69224,
0,
0,
0.5
],
"8630": [
0,
0.43056,
0,
0,
1.0
],
"8631": [
0,
0.43056,
0,
0,
1.0
],
"8634": [
0.08198,
0.58198,
0,
0,
0.77778
],
"8635": [
0.08198,
0.58198,
0,
0,
0.77778
],
"8638": [
0.19444,
0.69224,
0,
0,
0.41667
],
"8639": [
0.19444,
0.69224,
0,
0,
0.41667
],
"8642": [
0.19444,
0.69224,
0,
0,
0.41667
],
"8643": [
0.19444,
0.69224,
0,
0,
0.41667
],
"8644": [
0.1808,
0.675,
0,
0,
1.0
],
"8646": [
0.1808,
0.675,
0,
0,
1.0
],
"8647": [
0.1808,
0.675,
0,
0,
1.0
],
"8648": [
0.19444,
0.69224,
0,
0,
0.83334
],
"8649": [
0.1808,
0.675,
0,
0,
1.0
],
"8650": [
0.19444,
0.69224,
0,
0,
0.83334
],
"8651": [
0.01354,
0.52239,
0,
0,
1.0
],
"8652": [
0.01354,
0.52239,
0,
0,
1.0
],
"8653": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8654": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8655": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8666": [
0.13667,
0.63667,
0,
0,
1.0
],
"8667": [
0.13667,
0.63667,
0,
0,
1.0
],
"8669": [
-0.13313,
0.37788,
0,
0,
1.0
],
"8672": [
-0.064,
0.437,
0,
0,
1.334
],
"8674": [
-0.064,
0.437,
0,
0,
1.334
],
"8705": [
0,
0.825,
0,
0,
0.5
],
"8708": [
0,
0.68889,
0,
0,
0.55556
],
"8709": [
0.08167,
0.58167,
0,
0,
0.77778
],
"8717": [
0,
0.43056,
0,
0,
0.42917
],
"8722": [
-0.03598,
0.46402,
0,
0,
0.5
],
"8724": [
0.08198,
0.69224,
0,
0,
0.77778
],
"8726": [
0.08167,
0.58167,
0,
0,
0.77778
],
"8733": [
0,
0.69224,
0,
0,
0.77778
],
"8736": [
0,
0.69224,
0,
0,
0.72222
],
"8737": [
0,
0.69224,
0,
0,
0.72222
],
"8738": [
0.03517,
0.52239,
0,
0,
0.72222
],
"8739": [
0.08167,
0.58167,
0,
0,
0.22222
],
"8740": [
0.25142,
0.74111,
0,
0,
0.27778
],
"8741": [
0.08167,
0.58167,
0,
0,
0.38889
],
"8742": [
0.25142,
0.74111,
0,
0,
0.5
],
"8756": [
0,
0.69224,
0,
0,
0.66667
],
"8757": [
0,
0.69224,
0,
0,
0.66667
],
"8764": [
-0.13313,
0.36687,
0,
0,
0.77778
],
"8765": [
-0.13313,
0.37788,
0,
0,
0.77778
],
"8769": [
-0.13313,
0.36687,
0,
0,
0.77778
],
"8770": [
-0.03625,
0.46375,
0,
0,
0.77778
],
"8774": [
0.30274,
0.79383,
0,
0,
0.77778
],
"8776": [
-0.01688,
0.48312,
0,
0,
0.77778
],
"8778": [
0.08167,
0.58167,
0,
0,
0.77778
],
"8782": [
0.06062,
0.54986,
0,
0,
0.77778
],
"8783": [
0.06062,
0.54986,
0,
0,
0.77778
],
"8785": [
0.08198,
0.58198,
0,
0,
0.77778
],
"8786": [
0.08198,
0.58198,
0,
0,
0.77778
],
"8787": [
0.08198,
0.58198,
0,
0,
0.77778
],
"8790": [
0,
0.69224,
0,
0,
0.77778
],
"8791": [
0.22958,
0.72958,
0,
0,
0.77778
],
"8796": [
0.08198,
0.91667,
0,
0,
0.77778
],
"8806": [
0.25583,
0.75583,
0,
0,
0.77778
],
"8807": [
0.25583,
0.75583,
0,
0,
0.77778
],
"8808": [
0.25142,
0.75726,
0,
0,
0.77778
],
"8809": [
0.25142,
0.75726,
0,
0,
0.77778
],
"8812": [
0.25583,
0.75583,
0,
0,
0.5
],
"8814": [
0.20576,
0.70576,
0,
0,
0.77778
],
"8815": [
0.20576,
0.70576,
0,
0,
0.77778
],
"8816": [
0.30274,
0.79383,
0,
0,
0.77778
],
"8817": [
0.30274,
0.79383,
0,
0,
0.77778
],
"8818": [
0.22958,
0.72958,
0,
0,
0.77778
],
"8819": [
0.22958,
0.72958,
0,
0,
0.77778
],
"8822": [
0.1808,
0.675,
0,
0,
0.77778
],
"8823": [
0.1808,
0.675,
0,
0,
0.77778
],
"8828": [
0.13667,
0.63667,
0,
0,
0.77778
],
"8829": [
0.13667,
0.63667,
0,
0,
0.77778
],
"8830": [
0.22958,
0.72958,
0,
0,
0.77778
],
"8831": [
0.22958,
0.72958,
0,
0,
0.77778
],
"8832": [
0.20576,
0.70576,
0,
0,
0.77778
],
"8833": [
0.20576,
0.70576,
0,
0,
0.77778
],
"8840": [
0.30274,
0.79383,
0,
0,
0.77778
],
"8841": [
0.30274,
0.79383,
0,
0,
0.77778
],
"8842": [
0.13597,
0.63597,
0,
0,
0.77778
],
"8843": [
0.13597,
0.63597,
0,
0,
0.77778
],
"8847": [
0.03517,
0.54986,
0,
0,
0.77778
],
"8848": [
0.03517,
0.54986,
0,
0,
0.77778
],
"8858": [
0.08198,
0.58198,
0,
0,
0.77778
],
"8859": [
0.08198,
0.58198,
0,
0,
0.77778
],
"8861": [
0.08198,
0.58198,
0,
0,
0.77778
],
"8862": [
0,
0.675,
0,
0,
0.77778
],
"8863": [
0,
0.675,
0,
0,
0.77778
],
"8864": [
0,
0.675,
0,
0,
0.77778
],
"8865": [
0,
0.675,
0,
0,
0.77778
],
"8872": [
0,
0.69224,
0,
0,
0.61111
],
"8873": [
0,
0.69224,
0,
0,
0.72222
],
"8874": [
0,
0.69224,
0,
0,
0.88889
],
"8876": [
0,
0.68889,
0,
0,
0.61111
],
"8877": [
0,
0.68889,
0,
0,
0.61111
],
"8878": [
0,
0.68889,
0,
0,
0.72222
],
"8879": [
0,
0.68889,
0,
0,
0.72222
],
"8882": [
0.03517,
0.54986,
0,
0,
0.77778
],
"8883": [
0.03517,
0.54986,
0,
0,
0.77778
],
"8884": [
0.13667,
0.63667,
0,
0,
0.77778
],
"8885": [
0.13667,
0.63667,
0,
0,
0.77778
],
"8888": [
0,
0.54986,
0,
0,
1.11111
],
"8890": [
0.19444,
0.43056,
0,
0,
0.55556
],
"8891": [
0.19444,
0.69224,
0,
0,
0.61111
],
"8892": [
0.19444,
0.69224,
0,
0,
0.61111
],
"8901": [
0,
0.54986,
0,
0,
0.27778
],
"8903": [
0.08167,
0.58167,
0,
0,
0.77778
],
"8905": [
0.08167,
0.58167,
0,
0,
0.77778
],
"8906": [
0.08167,
0.58167,
0,
0,
0.77778
],
"8907": [
0,
0.69224,
0,
0,
0.77778
],
"8908": [
0,
0.69224,
0,
0,
0.77778
],
"8909": [
-0.03598,
0.46402,
0,
0,
0.77778
],
"8910": [
0,
0.54986,
0,
0,
0.76042
],
"8911": [
0,
0.54986,
0,
0,
0.76042
],
"8912": [
0.03517,
0.54986,
0,
0,
0.77778
],
"8913": [
0.03517,
0.54986,
0,
0,
0.77778
],
"8914": [
0,
0.54986,
0,
0,
0.66667
],
"8915": [
0,
0.54986,
0,
0,
0.66667
],
"8916": [
0,
0.69224,
0,
0,
0.66667
],
"8918": [
0.0391,
0.5391,
0,
0,
0.77778
],
"8919": [
0.0391,
0.5391,
0,
0,
0.77778
],
"8920": [
0.03517,
0.54986,
0,
0,
1.33334
],
"8921": [
0.03517,
0.54986,
0,
0,
1.33334
],
"8922": [
0.38569,
0.88569,
0,
0,
0.77778
],
"8923": [
0.38569,
0.88569,
0,
0,
0.77778
],
"8926": [
0.13667,
0.63667,
0,
0,
0.77778
],
"8927": [
0.13667,
0.63667,
0,
0,
0.77778
],
"8928": [
0.30274,
0.79383,
0,
0,
0.77778
],
"8929": [
0.30274,
0.79383,
0,
0,
0.77778
],
"8934": [
0.23222,
0.74111,
0,
0,
0.77778
],
"8935": [
0.23222,
0.74111,
0,
0,
0.77778
],
"8936": [
0.23222,
0.74111,
0,
0,
0.77778
],
"8937": [
0.23222,
0.74111,
0,
0,
0.77778
],
"8938": [
0.20576,
0.70576,
0,
0,
0.77778
],
"8939": [
0.20576,
0.70576,
0,
0,
0.77778
],
"8940": [
0.30274,
0.79383,
0,
0,
0.77778
],
"8941": [
0.30274,
0.79383,
0,
0,
0.77778
],
"8994": [
0.19444,
0.69224,
0,
0,
0.77778
],
"8995": [
0.19444,
0.69224,
0,
0,
0.77778
],
"9416": [
0.15559,
0.69224,
0,
0,
0.90222
],
"9484": [
0,
0.69224,
0,
0,
0.5
],
"9488": [
0,
0.69224,
0,
0,
0.5
],
"9492": [
0,
0.37788,
0,
0,
0.5
],
"9496": [
0,
0.37788,
0,
0,
0.5
],
"9585": [
0.19444,
0.68889,
0,
0,
0.88889
],
"9586": [
0.19444,
0.74111,
0,
0,
0.88889
],
"9632": [
0,
0.675,
0,
0,
0.77778
],
"9633": [
0,
0.675,
0,
0,
0.77778
],
"9650": [
0,
0.54986,
0,
0,
0.72222
],
"9651": [
0,
0.54986,
0,
0,
0.72222
],
"9654": [
0.03517,
0.54986,
0,
0,
0.77778
],
"9660": [
0,
0.54986,
0,
0,
0.72222
],
"9661": [
0,
0.54986,
0,
0,
0.72222
],
"9664": [
0.03517,
0.54986,
0,
0,
0.77778
],
"9674": [
0.11111,
0.69224,
0,
0,
0.66667
],
"9733": [
0.19444,
0.69224,
0,
0,
0.94445
],
"10003": [
0,
0.69224,
0,
0,
0.83334
],
"10016": [
0,
0.69224,
0,
0,
0.83334
],
"10731": [
0.11111,
0.69224,
0,
0,
0.66667
],
"10846": [
0.19444,
0.75583,
0,
0,
0.61111
],
"10877": [
0.13667,
0.63667,
0,
0,
0.77778
],
"10878": [
0.13667,
0.63667,
0,
0,
0.77778
],
"10885": [
0.25583,
0.75583,
0,
0,
0.77778
],
"10886": [
0.25583,
0.75583,
0,
0,
0.77778
],
"10887": [
0.13597,
0.63597,
0,
0,
0.77778
],
"10888": [
0.13597,
0.63597,
0,
0,
0.77778
],
"10889": [
0.26167,
0.75726,
0,
0,
0.77778
],
"10890": [
0.26167,
0.75726,
0,
0,
0.77778
],
"10891": [
0.48256,
0.98256,
0,
0,
0.77778
],
"10892": [
0.48256,
0.98256,
0,
0,
0.77778
],
"10901": [
0.13667,
0.63667,
0,
0,
0.77778
],
"10902": [
0.13667,
0.63667,
0,
0,
0.77778
],
"10933": [
0.25142,
0.75726,
0,
0,
0.77778
],
"10934": [
0.25142,
0.75726,
0,
0,
0.77778
],
"10935": [
0.26167,
0.75726,
0,
0,
0.77778
],
"10936": [
0.26167,
0.75726,
0,
0,
0.77778
],
"10937": [
0.26167,
0.75726,
0,
0,
0.77778
],
"10938": [
0.26167,
0.75726,
0,
0,
0.77778
],
"10949": [
0.25583,
0.75583,
0,
0,
0.77778
],
"10950": [
0.25583,
0.75583,
0,
0,
0.77778
],
"10955": [
0.28481,
0.79383,
0,
0,
0.77778
],
"10956": [
0.28481,
0.79383,
0,
0,
0.77778
],
"57350": [
0.08167,
0.58167,
0,
0,
0.22222
],
"57351": [
0.08167,
0.58167,
0,
0,
0.38889
],
"57352": [
0.08167,
0.58167,
0,
0,
0.77778
],
"57353": [
0,
0.43056,
0.04028,
0,
0.66667
],
"57356": [
0.25142,
0.75726,
0,
0,
0.77778
],
"57357": [
0.25142,
0.75726,
0,
0,
0.77778
],
"57358": [
0.41951,
0.91951,
0,
0,
0.77778
],
"57359": [
0.30274,
0.79383,
0,
0,
0.77778
],
"57360": [
0.30274,
0.79383,
0,
0,
0.77778
],
"57361": [
0.41951,
0.91951,
0,
0,
0.77778
],
"57366": [
0.25142,
0.75726,
0,
0,
0.77778
],
"57367": [
0.25142,
0.75726,
0,
0,
0.77778
],
"57368": [
0.25142,
0.75726,
0,
0,
0.77778
],
"57369": [
0.25142,
0.75726,
0,
0,
0.77778
],
"57370": [
0.13597,
0.63597,
0,
0,
0.77778
],
"57371": [
0.13597,
0.63597,
0,
0,
0.77778
]
},
"Caligraphic-Regular": {
"32": [
0,
0,
0,
0,
0.25
],
"65": [
0,
0.68333,
0,
0.19445,
0.79847
],
"66": [
0,
0.68333,
0.03041,
0.13889,
0.65681
],
"67": [
0,
0.68333,
0.05834,
0.13889,
0.52653
],
"68": [
0,
0.68333,
0.02778,
0.08334,
0.77139
],
"69": [
0,
0.68333,
0.08944,
0.11111,
0.52778
],
"70": [
0,
0.68333,
0.09931,
0.11111,
0.71875
],
"71": [
0.09722,
0.68333,
0.0593,
0.11111,
0.59487
],
"72": [
0,
0.68333,
0.00965,
0.11111,
0.84452
],
"73": [
0,
0.68333,
0.07382,
0,
0.54452
],
"74": [
0.09722,
0.68333,
0.18472,
0.16667,
0.67778
],
"75": [
0,
0.68333,
0.01445,
0.05556,
0.76195
],
"76": [
0,
0.68333,
0,
0.13889,
0.68972
],
"77": [
0,
0.68333,
0,
0.13889,
1.2009
],
"78": [
0,
0.68333,
0.14736,
0.08334,
0.82049
],
"79": [
0,
0.68333,
0.02778,
0.11111,
0.79611
],
"80": [
0,
0.68333,
0.08222,
0.08334,
0.69556
],
"81": [
0.09722,
0.68333,
0,
0.11111,
0.81667
],
"82": [
0,
0.68333,
0,
0.08334,
0.8475
],
"83": [
0,
0.68333,
0.075,
0.13889,
0.60556
],
"84": [
0,
0.68333,
0.25417,
0,
0.54464
],
"85": [
0,
0.68333,
0.09931,
0.08334,
0.62583
],
"86": [
0,
0.68333,
0.08222,
0,
0.61278
],
"87": [
0,
0.68333,
0.08222,
0.08334,
0.98778
],
"88": [
0,
0.68333,
0.14643,
0.13889,
0.7133
],
"89": [
0.09722,
0.68333,
0.08222,
0.08334,
0.66834
],
"90": [
0,
0.68333,
0.07944,
0.13889,
0.72473
],
"160": [
0,
0,
0,
0,
0.25
]
},
"Fraktur-Regular": {
"32": [
0,
0,
0,
0,
0.25
],
"33": [
0,
0.69141,
0,
0,
0.29574
],
"34": [
0,
0.69141,
0,
0,
0.21471
],
"38": [
0,
0.69141,
0,
0,
0.73786
],
"39": [
0,
0.69141,
0,
0,
0.21201
],
"40": [
0.24982,
0.74947,
0,
0,
0.38865
],
"41": [
0.24982,
0.74947,
0,
0,
0.38865
],
"42": [
0,
0.62119,
0,
0,
0.27764
],
"43": [
0.08319,
0.58283,
0,
0,
0.75623
],
"44": [
0,
0.10803,
0,
0,
0.27764
],
"45": [
0.08319,
0.58283,
0,
0,
0.75623
],
"46": [
0,
0.10803,
0,
0,
0.27764
],
"47": [
0.24982,
0.74947,
0,
0,
0.50181
],
"48": [
0,
0.47534,
0,
0,
0.50181
],
"49": [
0,
0.47534,
0,
0,
0.50181
],
"50": [
0,
0.47534,
0,
0,
0.50181
],
"51": [
0.18906,
0.47534,
0,
0,
0.50181
],
"52": [
0.18906,
0.47534,
0,
0,
0.50181
],
"53": [
0.18906,
0.47534,
0,
0,
0.50181
],
"54": [
0,
0.69141,
0,
0,
0.50181
],
"55": [
0.18906,
0.47534,
0,
0,
0.50181
],
"56": [
0,
0.69141,
0,
0,
0.50181
],
"57": [
0.18906,
0.47534,
0,
0,
0.50181
],
"58": [
0,
0.47534,
0,
0,
0.21606
],
"59": [
0.12604,
0.47534,
0,
0,
0.21606
],
"61": [
-0.13099,
0.36866,
0,
0,
0.75623
],
"63": [
0,
0.69141,
0,
0,
0.36245
],
"65": [
0,
0.69141,
0,
0,
0.7176
],
"66": [
0,
0.69141,
0,
0,
0.88397
],
"67": [
0,
0.69141,
0,
0,
0.61254
],
"68": [
0,
0.69141,
0,
0,
0.83158
],
"69": [
0,
0.69141,
0,
0,
0.66278
],
"70": [
0.12604,
0.69141,
0,
0,
0.61119
],
"71": [
0,
0.69141,
0,
0,
0.78539
],
"72": [
0.06302,
0.69141,
0,
0,
0.7203
],
"73": [
0,
0.69141,
0,
0,
0.55448
],
"74": [
0.12604,
0.69141,
0,
0,
0.55231
],
"75": [
0,
0.69141,
0,
0,
0.66845
],
"76": [
0,
0.69141,
0,
0,
0.66602
],
"77": [
0,
0.69141,
0,
0,
1.04953
],
"78": [
0,
0.69141,
0,
0,
0.83212
],
"79": [
0,
0.69141,
0,
0,
0.82699
],
"80": [
0.18906,
0.69141,
0,
0,
0.82753
],
"81": [
0.03781,
0.69141,
0,
0,
0.82699
],
"82": [
0,
0.69141,
0,
0,
0.82807
],
"83": [
0,
0.69141,
0,
0,
0.82861
],
"84": [
0,
0.69141,
0,
0,
0.66899
],
"85": [
0,
0.69141,
0,
0,
0.64576
],
"86": [
0,
0.69141,
0,
0,
0.83131
],
"87": [
0,
0.69141,
0,
0,
1.04602
],
"88": [
0,
0.69141,
0,
0,
0.71922
],
"89": [
0.18906,
0.69141,
0,
0,
0.83293
],
"90": [
0.12604,
0.69141,
0,
0,
0.60201
],
"91": [
0.24982,
0.74947,
0,
0,
0.27764
],
"93": [
0.24982,
0.74947,
0,
0,
0.27764
],
"94": [
0,
0.69141,
0,
0,
0.49965
],
"97": [
0,
0.47534,
0,
0,
0.50046
],
"98": [
0,
0.69141,
0,
0,
0.51315
],
"99": [
0,
0.47534,
0,
0,
0.38946
],
"100": [
0,
0.62119,
0,
0,
0.49857
],
"101": [
0,
0.47534,
0,
0,
0.40053
],
"102": [
0.18906,
0.69141,
0,
0,
0.32626
],
"103": [
0.18906,
0.47534,
0,
0,
0.5037
],
"104": [
0.18906,
0.69141,
0,
0,
0.52126
],
"105": [
0,
0.69141,
0,
0,
0.27899
],
"106": [
0,
0.69141,
0,
0,
0.28088
],
"107": [
0,
0.69141,
0,
0,
0.38946
],
"108": [
0,
0.69141,
0,
0,
0.27953
],
"109": [
0,
0.47534,
0,
0,
0.76676
],
"110": [
0,
0.47534,
0,
0,
0.52666
],
"111": [
0,
0.47534,
0,
0,
0.48885
],
"112": [
0.18906,
0.52396,
0,
0,
0.50046
],
"113": [
0.18906,
0.47534,
0,
0,
0.48912
],
"114": [
0,
0.47534,
0,
0,
0.38919
],
"115": [
0,
0.47534,
0,
0,
0.44266
],
"116": [
0,
0.62119,
0,
0,
0.33301
],
"117": [
0,
0.47534,
0,
0,
0.5172
],
"118": [
0,
0.52396,
0,
0,
0.5118
],
"119": [
0,
0.52396,
0,
0,
0.77351
],
"120": [
0.18906,
0.47534,
0,
0,
0.38865
],
"121": [
0.18906,
0.47534,
0,
0,
0.49884
],
"122": [
0.18906,
0.47534,
0,
0,
0.39054
],
"160": [
0,
0,
0,
0,
0.25
],
"8216": [
0,
0.69141,
0,
0,
0.21471
],
"8217": [
0,
0.69141,
0,
0,
0.21471
],
"58112": [
0,
0.62119,
0,
0,
0.49749
],
"58113": [
0,
0.62119,
0,
0,
0.4983
],
"58114": [
0.18906,
0.69141,
0,
0,
0.33328
],
"58115": [
0.18906,
0.69141,
0,
0,
0.32923
],
"58116": [
0.18906,
0.47534,
0,
0,
0.50343
],
"58117": [
0,
0.69141,
0,
0,
0.33301
],
"58118": [
0,
0.62119,
0,
0,
0.33409
],
"58119": [
0,
0.47534,
0,
0,
0.50073
]
},
"Main-Bold": {
"32": [
0,
0,
0,
0,
0.25
],
"33": [
0,
0.69444,
0,
0,
0.35
],
"34": [
0,
0.69444,
0,
0,
0.60278
],
"35": [
0.19444,
0.69444,
0,
0,
0.95833
],
"36": [
0.05556,
0.75,
0,
0,
0.575
],
"37": [
0.05556,
0.75,
0,
0,
0.95833
],
"38": [
0,
0.69444,
0,
0,
0.89444
],
"39": [
0,
0.69444,
0,
0,
0.31944
],
"40": [
0.25,
0.75,
0,
0,
0.44722
],
"41": [
0.25,
0.75,
0,
0,
0.44722
],
"42": [
0,
0.75,
0,
0,
0.575
],
"43": [
0.13333,
0.63333,
0,
0,
0.89444
],
"44": [
0.19444,
0.15556,
0,
0,
0.31944
],
"45": [
0,
0.44444,
0,
0,
0.38333
],
"46": [
0,
0.15556,
0,
0,
0.31944
],
"47": [
0.25,
0.75,
0,
0,
0.575
],
"48": [
0,
0.64444,
0,
0,
0.575
],
"49": [
0,
0.64444,
0,
0,
0.575
],
"50": [
0,
0.64444,
0,
0,
0.575
],
"51": [
0,
0.64444,
0,
0,
0.575
],
"52": [
0,
0.64444,
0,
0,
0.575
],
"53": [
0,
0.64444,
0,
0,
0.575
],
"54": [
0,
0.64444,
0,
0,
0.575
],
"55": [
0,
0.64444,
0,
0,
0.575
],
"56": [
0,
0.64444,
0,
0,
0.575
],
"57": [
0,
0.64444,
0,
0,
0.575
],
"58": [
0,
0.44444,
0,
0,
0.31944
],
"59": [
0.19444,
0.44444,
0,
0,
0.31944
],
"60": [
0.08556,
0.58556,
0,
0,
0.89444
],
"61": [
-0.10889,
0.39111,
0,
0,
0.89444
],
"62": [
0.08556,
0.58556,
0,
0,
0.89444
],
"63": [
0,
0.69444,
0,
0,
0.54305
],
"64": [
0,
0.69444,
0,
0,
0.89444
],
"65": [
0,
0.68611,
0,
0,
0.86944
],
"66": [
0,
0.68611,
0,
0,
0.81805
],
"67": [
0,
0.68611,
0,
0,
0.83055
],
"68": [
0,
0.68611,
0,
0,
0.88194
],
"69": [
0,
0.68611,
0,
0,
0.75555
],
"70": [
0,
0.68611,
0,
0,
0.72361
],
"71": [
0,
0.68611,
0,
0,
0.90416
],
"72": [
0,
0.68611,
0,
0,
0.9
],
"73": [
0,
0.68611,
0,
0,
0.43611
],
"74": [
0,
0.68611,
0,
0,
0.59444
],
"75": [
0,
0.68611,
0,
0,
0.90138
],
"76": [
0,
0.68611,
0,
0,
0.69166
],
"77": [
0,
0.68611,
0,
0,
1.09166
],
"78": [
0,
0.68611,
0,
0,
0.9
],
"79": [
0,
0.68611,
0,
0,
0.86388
],
"80": [
0,
0.68611,
0,
0,
0.78611
],
"81": [
0.19444,
0.68611,
0,
0,
0.86388
],
"82": [
0,
0.68611,
0,
0,
0.8625
],
"83": [
0,
0.68611,
0,
0,
0.63889
],
"84": [
0,
0.68611,
0,
0,
0.8
],
"85": [
0,
0.68611,
0,
0,
0.88472
],
"86": [
0,
0.68611,
0.01597,
0,
0.86944
],
"87": [
0,
0.68611,
0.01597,
0,
1.18888
],
"88": [
0,
0.68611,
0,
0,
0.86944
],
"89": [
0,
0.68611,
0.02875,
0,
0.86944
],
"90": [
0,
0.68611,
0,
0,
0.70277
],
"91": [
0.25,
0.75,
0,
0,
0.31944
],
"92": [
0.25,
0.75,
0,
0,
0.575
],
"93": [
0.25,
0.75,
0,
0,
0.31944
],
"94": [
0,
0.69444,
0,
0,
0.575
],
"95": [
0.31,
0.13444,
0.03194,
0,
0.575
],
"97": [
0,
0.44444,
0,
0,
0.55902
],
"98": [
0,
0.69444,
0,
0,
0.63889
],
"99": [
0,
0.44444,
0,
0,
0.51111
],
"100": [
0,
0.69444,
0,
0,
0.63889
],
"101": [
0,
0.44444,
0,
0,
0.52708
],
"102": [
0,
0.69444,
0.10903,
0,
0.35139
],
"103": [
0.19444,
0.44444,
0.01597,
0,
0.575
],
"104": [
0,
0.69444,
0,
0,
0.63889
],
"105": [
0,
0.69444,
0,
0,
0.31944
],
"106": [
0.19444,
0.69444,
0,
0,
0.35139
],
"107": [
0,
0.69444,
0,
0,
0.60694
],
"108": [
0,
0.69444,
0,
0,
0.31944
],
"109": [
0,
0.44444,
0,
0,
0.95833
],
"110": [
0,
0.44444,
0,
0,
0.63889
],
"111": [
0,
0.44444,
0,
0,
0.575
],
"112": [
0.19444,
0.44444,
0,
0,
0.63889
],
"113": [
0.19444,
0.44444,
0,
0,
0.60694
],
"114": [
0,
0.44444,
0,
0,
0.47361
],
"115": [
0,
0.44444,
0,
0,
0.45361
],
"116": [
0,
0.63492,
0,
0,
0.44722
],
"117": [
0,
0.44444,
0,
0,
0.63889
],
"118": [
0,
0.44444,
0.01597,
0,
0.60694
],
"119": [
0,
0.44444,
0.01597,
0,
0.83055
],
"120": [
0,
0.44444,
0,
0,
0.60694
],
"121": [
0.19444,
0.44444,
0.01597,
0,
0.60694
],
"122": [
0,
0.44444,
0,
0,
0.51111
],
"123": [
0.25,
0.75,
0,
0,
0.575
],
"124": [
0.25,
0.75,
0,
0,
0.31944
],
"125": [
0.25,
0.75,
0,
0,
0.575
],
"126": [
0.35,
0.34444,
0,
0,
0.575
],
"160": [
0,
0,
0,
0,
0.25
],
"163": [
0,
0.69444,
0,
0,
0.86853
],
"168": [
0,
0.69444,
0,
0,
0.575
],
"172": [
0,
0.44444,
0,
0,
0.76666
],
"176": [
0,
0.69444,
0,
0,
0.86944
],
"177": [
0.13333,
0.63333,
0,
0,
0.89444
],
"184": [
0.17014,
0,
0,
0,
0.51111
],
"198": [
0,
0.68611,
0,
0,
1.04166
],
"215": [
0.13333,
0.63333,
0,
0,
0.89444
],
"216": [
0.04861,
0.73472,
0,
0,
0.89444
],
"223": [
0,
0.69444,
0,
0,
0.59722
],
"230": [
0,
0.44444,
0,
0,
0.83055
],
"247": [
0.13333,
0.63333,
0,
0,
0.89444
],
"248": [
0.09722,
0.54167,
0,
0,
0.575
],
"305": [
0,
0.44444,
0,
0,
0.31944
],
"338": [
0,
0.68611,
0,
0,
1.16944
],
"339": [
0,
0.44444,
0,
0,
0.89444
],
"567": [
0.19444,
0.44444,
0,
0,
0.35139
],
"710": [
0,
0.69444,
0,
0,
0.575
],
"711": [
0,
0.63194,
0,
0,
0.575
],
"713": [
0,
0.59611,
0,
0,
0.575
],
"714": [
0,
0.69444,
0,
0,
0.575
],
"715": [
0,
0.69444,
0,
0,
0.575
],
"728": [
0,
0.69444,
0,
0,
0.575
],
"729": [
0,
0.69444,
0,
0,
0.31944
],
"730": [
0,
0.69444,
0,
0,
0.86944
],
"732": [
0,
0.69444,
0,
0,
0.575
],
"733": [
0,
0.69444,
0,
0,
0.575
],
"915": [
0,
0.68611,
0,
0,
0.69166
],
"916": [
0,
0.68611,
0,
0,
0.95833
],
"920": [
0,
0.68611,
0,
0,
0.89444
],
"923": [
0,
0.68611,
0,
0,
0.80555
],
"926": [
0,
0.68611,
0,
0,
0.76666
],
"928": [
0,
0.68611,
0,
0,
0.9
],
"931": [
0,
0.68611,
0,
0,
0.83055
],
"933": [
0,
0.68611,
0,
0,
0.89444
],
"934": [
0,
0.68611,
0,
0,
0.83055
],
"936": [
0,
0.68611,
0,
0,
0.89444
],
"937": [
0,
0.68611,
0,
0,
0.83055
],
"8211": [
0,
0.44444,
0.03194,
0,
0.575
],
"8212": [
0,
0.44444,
0.03194,
0,
1.14999
],
"8216": [
0,
0.69444,
0,
0,
0.31944
],
"8217": [
0,
0.69444,
0,
0,
0.31944
],
"8220": [
0,
0.69444,
0,
0,
0.60278
],
"8221": [
0,
0.69444,
0,
0,
0.60278
],
"8224": [
0.19444,
0.69444,
0,
0,
0.51111
],
"8225": [
0.19444,
0.69444,
0,
0,
0.51111
],
"8242": [
0,
0.55556,
0,
0,
0.34444
],
"8407": [
0,
0.72444,
0.15486,
0,
0.575
],
"8463": [
0,
0.69444,
0,
0,
0.66759
],
"8465": [
0,
0.69444,
0,
0,
0.83055
],
"8467": [
0,
0.69444,
0,
0,
0.47361
],
"8472": [
0.19444,
0.44444,
0,
0,
0.74027
],
"8476": [
0,
0.69444,
0,
0,
0.83055
],
"8501": [
0,
0.69444,
0,
0,
0.70277
],
"8592": [
-0.10889,
0.39111,
0,
0,
1.14999
],
"8593": [
0.19444,
0.69444,
0,
0,
0.575
],
"8594": [
-0.10889,
0.39111,
0,
0,
1.14999
],
"8595": [
0.19444,
0.69444,
0,
0,
0.575
],
"8596": [
-0.10889,
0.39111,
0,
0,
1.14999
],
"8597": [
0.25,
0.75,
0,
0,
0.575
],
"8598": [
0.19444,
0.69444,
0,
0,
1.14999
],
"8599": [
0.19444,
0.69444,
0,
0,
1.14999
],
"8600": [
0.19444,
0.69444,
0,
0,
1.14999
],
"8601": [
0.19444,
0.69444,
0,
0,
1.14999
],
"8636": [
-0.10889,
0.39111,
0,
0,
1.14999
],
"8637": [
-0.10889,
0.39111,
0,
0,
1.14999
],
"8640": [
-0.10889,
0.39111,
0,
0,
1.14999
],
"8641": [
-0.10889,
0.39111,
0,
0,
1.14999
],
"8656": [
-0.10889,
0.39111,
0,
0,
1.14999
],
"8657": [
0.19444,
0.69444,
0,
0,
0.70277
],
"8658": [
-0.10889,
0.39111,
0,
0,
1.14999
],
"8659": [
0.19444,
0.69444,
0,
0,
0.70277
],
"8660": [
-0.10889,
0.39111,
0,
0,
1.14999
],
"8661": [
0.25,
0.75,
0,
0,
0.70277
],
"8704": [
0,
0.69444,
0,
0,
0.63889
],
"8706": [
0,
0.69444,
0.06389,
0,
0.62847
],
"8707": [
0,
0.69444,
0,
0,
0.63889
],
"8709": [
0.05556,
0.75,
0,
0,
0.575
],
"8711": [
0,
0.68611,
0,
0,
0.95833
],
"8712": [
0.08556,
0.58556,
0,
0,
0.76666
],
"8715": [
0.08556,
0.58556,
0,
0,
0.76666
],
"8722": [
0.13333,
0.63333,
0,
0,
0.89444
],
"8723": [
0.13333,
0.63333,
0,
0,
0.89444
],
"8725": [
0.25,
0.75,
0,
0,
0.575
],
"8726": [
0.25,
0.75,
0,
0,
0.575
],
"8727": [
-0.02778,
0.47222,
0,
0,
0.575
],
"8728": [
-0.02639,
0.47361,
0,
0,
0.575
],
"8729": [
-0.02639,
0.47361,
0,
0,
0.575
],
"8730": [
0.18,
0.82,
0,
0,
0.95833
],
"8733": [
0,
0.44444,
0,
0,
0.89444
],
"8734": [
0,
0.44444,
0,
0,
1.14999
],
"8736": [
0,
0.69224,
0,
0,
0.72222
],
"8739": [
0.25,
0.75,
0,
0,
0.31944
],
"8741": [
0.25,
0.75,
0,
0,
0.575
],
"8743": [
0,
0.55556,
0,
0,
0.76666
],
"8744": [
0,
0.55556,
0,
0,
0.76666
],
"8745": [
0,
0.55556,
0,
0,
0.76666
],
"8746": [
0,
0.55556,
0,
0,
0.76666
],
"8747": [
0.19444,
0.69444,
0.12778,
0,
0.56875
],
"8764": [
-0.10889,
0.39111,
0,
0,
0.89444
],
"8768": [
0.19444,
0.69444,
0,
0,
0.31944
],
"8771": [
0.00222,
0.50222,
0,
0,
0.89444
],
"8773": [
0.027,
0.638,
0,
0,
0.894
],
"8776": [
0.02444,
0.52444,
0,
0,
0.89444
],
"8781": [
0.00222,
0.50222,
0,
0,
0.89444
],
"8801": [
0.00222,
0.50222,
0,
0,
0.89444
],
"8804": [
0.19667,
0.69667,
0,
0,
0.89444
],
"8805": [
0.19667,
0.69667,
0,
0,
0.89444
],
"8810": [
0.08556,
0.58556,
0,
0,
1.14999
],
"8811": [
0.08556,
0.58556,
0,
0,
1.14999
],
"8826": [
0.08556,
0.58556,
0,
0,
0.89444
],
"8827": [
0.08556,
0.58556,
0,
0,
0.89444
],
"8834": [
0.08556,
0.58556,
0,
0,
0.89444
],
"8835": [
0.08556,
0.58556,
0,
0,
0.89444
],
"8838": [
0.19667,
0.69667,
0,
0,
0.89444
],
"8839": [
0.19667,
0.69667,
0,
0,
0.89444
],
"8846": [
0,
0.55556,
0,
0,
0.76666
],
"8849": [
0.19667,
0.69667,
0,
0,
0.89444
],
"8850": [
0.19667,
0.69667,
0,
0,
0.89444
],
"8851": [
0,
0.55556,
0,
0,
0.76666
],
"8852": [
0,
0.55556,
0,
0,
0.76666
],
"8853": [
0.13333,
0.63333,
0,
0,
0.89444
],
"8854": [
0.13333,
0.63333,
0,
0,
0.89444
],
"8855": [
0.13333,
0.63333,
0,
0,
0.89444
],
"8856": [
0.13333,
0.63333,
0,
0,
0.89444
],
"8857": [
0.13333,
0.63333,
0,
0,
0.89444
],
"8866": [
0,
0.69444,
0,
0,
0.70277
],
"8867": [
0,
0.69444,
0,
0,
0.70277
],
"8868": [
0,
0.69444,
0,
0,
0.89444
],
"8869": [
0,
0.69444,
0,
0,
0.89444
],
"8900": [
-0.02639,
0.47361,
0,
0,
0.575
],
"8901": [
-0.02639,
0.47361,
0,
0,
0.31944
],
"8902": [
-0.02778,
0.47222,
0,
0,
0.575
],
"8968": [
0.25,
0.75,
0,
0,
0.51111
],
"8969": [
0.25,
0.75,
0,
0,
0.51111
],
"8970": [
0.25,
0.75,
0,
0,
0.51111
],
"8971": [
0.25,
0.75,
0,
0,
0.51111
],
"8994": [
-0.13889,
0.36111,
0,
0,
1.14999
],
"8995": [
-0.13889,
0.36111,
0,
0,
1.14999
],
"9651": [
0.19444,
0.69444,
0,
0,
1.02222
],
"9657": [
-0.02778,
0.47222,
0,
0,
0.575
],
"9661": [
0.19444,
0.69444,
0,
0,
1.02222
],
"9667": [
-0.02778,
0.47222,
0,
0,
0.575
],
"9711": [
0.19444,
0.69444,
0,
0,
1.14999
],
"9824": [
0.12963,
0.69444,
0,
0,
0.89444
],
"9825": [
0.12963,
0.69444,
0,
0,
0.89444
],
"9826": [
0.12963,
0.69444,
0,
0,
0.89444
],
"9827": [
0.12963,
0.69444,
0,
0,
0.89444
],
"9837": [
0,
0.75,
0,
0,
0.44722
],
"9838": [
0.19444,
0.69444,
0,
0,
0.44722
],
"9839": [
0.19444,
0.69444,
0,
0,
0.44722
],
"10216": [
0.25,
0.75,
0,
0,
0.44722
],
"10217": [
0.25,
0.75,
0,
0,
0.44722
],
"10815": [
0,
0.68611,
0,
0,
0.9
],
"10927": [
0.19667,
0.69667,
0,
0,
0.89444
],
"10928": [
0.19667,
0.69667,
0,
0,
0.89444
],
"57376": [
0.19444,
0.69444,
0,
0,
0
]
},
"Main-BoldItalic": {
"32": [
0,
0,
0,
0,
0.25
],
"33": [
0,
0.69444,
0.11417,
0,
0.38611
],
"34": [
0,
0.69444,
0.07939,
0,
0.62055
],
"35": [
0.19444,
0.69444,
0.06833,
0,
0.94444
],
"37": [
0.05556,
0.75,
0.12861,
0,
0.94444
],
"38": [
0,
0.69444,
0.08528,
0,
0.88555
],
"39": [
0,
0.69444,
0.12945,
0,
0.35555
],
"40": [
0.25,
0.75,
0.15806,
0,
0.47333
],
"41": [
0.25,
0.75,
0.03306,
0,
0.47333
],
"42": [
0,
0.75,
0.14333,
0,
0.59111
],
"43": [
0.10333,
0.60333,
0.03306,
0,
0.88555
],
"44": [
0.19444,
0.14722,
0,
0,
0.35555
],
"45": [
0,
0.44444,
0.02611,
0,
0.41444
],
"46": [
0,
0.14722,
0,
0,
0.35555
],
"47": [
0.25,
0.75,
0.15806,
0,
0.59111
],
"48": [
0,
0.64444,
0.13167,
0,
0.59111
],
"49": [
0,
0.64444,
0.13167,
0,
0.59111
],
"50": [
0,
0.64444,
0.13167,
0,
0.59111
],
"51": [
0,
0.64444,
0.13167,
0,
0.59111
],
"52": [
0.19444,
0.64444,
0.13167,
0,
0.59111
],
"53": [
0,
0.64444,
0.13167,
0,
0.59111
],
"54": [
0,
0.64444,
0.13167,
0,
0.59111
],
"55": [
0.19444,
0.64444,
0.13167,
0,
0.59111
],
"56": [
0,
0.64444,
0.13167,
0,
0.59111
],
"57": [
0,
0.64444,
0.13167,
0,
0.59111
],
"58": [
0,
0.44444,
0.06695,
0,
0.35555
],
"59": [
0.19444,
0.44444,
0.06695,
0,
0.35555
],
"61": [
-0.10889,
0.39111,
0.06833,
0,
0.88555
],
"63": [
0,
0.69444,
0.11472,
0,
0.59111
],
"64": [
0,
0.69444,
0.09208,
0,
0.88555
],
"65": [
0,
0.68611,
0,
0,
0.86555
],
"66": [
0,
0.68611,
0.0992,
0,
0.81666
],
"67": [
0,
0.68611,
0.14208,
0,
0.82666
],
"68": [
0,
0.68611,
0.09062,
0,
0.87555
],
"69": [
0,
0.68611,
0.11431,
0,
0.75666
],
"70": [
0,
0.68611,
0.12903,
0,
0.72722
],
"71": [
0,
0.68611,
0.07347,
0,
0.89527
],
"72": [
0,
0.68611,
0.17208,
0,
0.8961
],
"73": [
0,
0.68611,
0.15681,
0,
0.47166
],
"74": [
0,
0.68611,
0.145,
0,
0.61055
],
"75": [
0,
0.68611,
0.14208,
0,
0.89499
],
"76": [
0,
0.68611,
0,
0,
0.69777
],
"77": [
0,
0.68611,
0.17208,
0,
1.07277
],
"78": [
0,
0.68611,
0.17208,
0,
0.8961
],
"79": [
0,
0.68611,
0.09062,
0,
0.85499
],
"80": [
0,
0.68611,
0.0992,
0,
0.78721
],
"81": [
0.19444,
0.68611,
0.09062,
0,
0.85499
],
"82": [
0,
0.68611,
0.02559,
0,
0.85944
],
"83": [
0,
0.68611,
0.11264,
0,
0.64999
],
"84": [
0,
0.68611,
0.12903,
0,
0.7961
],
"85": [
0,
0.68611,
0.17208,
0,
0.88083
],
"86": [
0,
0.68611,
0.18625,
0,
0.86555
],
"87": [
0,
0.68611,
0.18625,
0,
1.15999
],
"88": [
0,
0.68611,
0.15681,
0,
0.86555
],
"89": [
0,
0.68611,
0.19803,
0,
0.86555
],
"90": [
0,
0.68611,
0.14208,
0,
0.70888
],
"91": [
0.25,
0.75,
0.1875,
0,
0.35611
],
"93": [
0.25,
0.75,
0.09972,
0,
0.35611
],
"94": [
0,
0.69444,
0.06709,
0,
0.59111
],
"95": [
0.31,
0.13444,
0.09811,
0,
0.59111
],
"97": [
0,
0.44444,
0.09426,
0,
0.59111
],
"98": [
0,
0.69444,
0.07861,
0,
0.53222
],
"99": [
0,
0.44444,
0.05222,
0,
0.53222
],
"100": [
0,
0.69444,
0.10861,
0,
0.59111
],
"101": [
0,
0.44444,
0.085,
0,
0.53222
],
"102": [
0.19444,
0.69444,
0.21778,
0,
0.4
],
"103": [
0.19444,
0.44444,
0.105,
0,
0.53222
],
"104": [
0,
0.69444,
0.09426,
0,
0.59111
],
"105": [
0,
0.69326,
0.11387,
0,
0.35555
],
"106": [
0.19444,
0.69326,
0.1672,
0,
0.35555
],
"107": [
0,
0.69444,
0.11111,
0,
0.53222
],
"108": [
0,
0.69444,
0.10861,
0,
0.29666
],
"109": [
0,
0.44444,
0.09426,
0,
0.94444
],
"110": [
0,
0.44444,
0.09426,
0,
0.64999
],
"111": [
0,
0.44444,
0.07861,
0,
0.59111
],
"112": [
0.19444,
0.44444,
0.07861,
0,
0.59111
],
"113": [
0.19444,
0.44444,
0.105,
0,
0.53222
],
"114": [
0,
0.44444,
0.11111,
0,
0.50167
],
"115": [
0,
0.44444,
0.08167,
0,
0.48694
],
"116": [
0,
0.63492,
0.09639,
0,
0.385
],
"117": [
0,
0.44444,
0.09426,
0,
0.62055
],
"118": [
0,
0.44444,
0.11111,
0,
0.53222
],
"119": [
0,
0.44444,
0.11111,
0,
0.76777
],
"120": [
0,
0.44444,
0.12583,
0,
0.56055
],
"121": [
0.19444,
0.44444,
0.105,
0,
0.56166
],
"122": [
0,
0.44444,
0.13889,
0,
0.49055
],
"126": [
0.35,
0.34444,
0.11472,
0,
0.59111
],
"160": [
0,
0,
0,
0,
0.25
],
"168": [
0,
0.69444,
0.11473,
0,
0.59111
],
"176": [
0,
0.69444,
0,
0,
0.94888
],
"184": [
0.17014,
0,
0,
0,
0.53222
],
"198": [
0,
0.68611,
0.11431,
0,
1.02277
],
"216": [
0.04861,
0.73472,
0.09062,
0,
0.88555
],
"223": [
0.19444,
0.69444,
0.09736,
0,
0.665
],
"230": [
0,
0.44444,
0.085,
0,
0.82666
],
"248": [
0.09722,
0.54167,
0.09458,
0,
0.59111
],
"305": [
0,
0.44444,
0.09426,
0,
0.35555
],
"338": [
0,
0.68611,
0.11431,
0,
1.14054
],
"339": [
0,
0.44444,
0.085,
0,
0.82666
],
"567": [
0.19444,
0.44444,
0.04611,
0,
0.385
],
"710": [
0,
0.69444,
0.06709,
0,
0.59111
],
"711": [
0,
0.63194,
0.08271,
0,
0.59111
],
"713": [
0,
0.59444,
0.10444,
0,
0.59111
],
"714": [
0,
0.69444,
0.08528,
0,
0.59111
],
"715": [
0,
0.69444,
0,
0,
0.59111
],
"728": [
0,
0.69444,
0.10333,
0,
0.59111
],
"729": [
0,
0.69444,
0.12945,
0,
0.35555
],
"730": [
0,
0.69444,
0,
0,
0.94888
],
"732": [
0,
0.69444,
0.11472,
0,
0.59111
],
"733": [
0,
0.69444,
0.11472,
0,
0.59111
],
"915": [
0,
0.68611,
0.12903,
0,
0.69777
],
"916": [
0,
0.68611,
0,
0,
0.94444
],
"920": [
0,
0.68611,
0.09062,
0,
0.88555
],
"923": [
0,
0.68611,
0,
0,
0.80666
],
"926": [
0,
0.68611,
0.15092,
0,
0.76777
],
"928": [
0,
0.68611,
0.17208,
0,
0.8961
],
"931": [
0,
0.68611,
0.11431,
0,
0.82666
],
"933": [
0,
0.68611,
0.10778,
0,
0.88555
],
"934": [
0,
0.68611,
0.05632,
0,
0.82666
],
"936": [
0,
0.68611,
0.10778,
0,
0.88555
],
"937": [
0,
0.68611,
0.0992,
0,
0.82666
],
"8211": [
0,
0.44444,
0.09811,
0,
0.59111
],
"8212": [
0,
0.44444,
0.09811,
0,
1.18221
],
"8216": [
0,
0.69444,
0.12945,
0,
0.35555
],
"8217": [
0,
0.69444,
0.12945,
0,
0.35555
],
"8220": [
0,
0.69444,
0.16772,
0,
0.62055
],
"8221": [
0,
0.69444,
0.07939,
0,
0.62055
]
},
"Main-Italic": {
"32": [
0,
0,
0,
0,
0.25
],
"33": [
0,
0.69444,
0.12417,
0,
0.30667
],
"34": [
0,
0.69444,
0.06961,
0,
0.51444
],
"35": [
0.19444,
0.69444,
0.06616,
0,
0.81777
],
"37": [
0.05556,
0.75,
0.13639,
0,
0.81777
],
"38": [
0,
0.69444,
0.09694,
0,
0.76666
],
"39": [
0,
0.69444,
0.12417,
0,
0.30667
],
"40": [
0.25,
0.75,
0.16194,
0,
0.40889
],
"41": [
0.25,
0.75,
0.03694,
0,
0.40889
],
"42": [
0,
0.75,
0.14917,
0,
0.51111
],
"43": [
0.05667,
0.56167,
0.03694,
0,
0.76666
],
"44": [
0.19444,
0.10556,
0,
0,
0.30667
],
"45": [
0,
0.43056,
0.02826,
0,
0.35778
],
"46": [
0,
0.10556,
0,
0,
0.30667
],
"47": [
0.25,
0.75,
0.16194,
0,
0.51111
],
"48": [
0,
0.64444,
0.13556,
0,
0.51111
],
"49": [
0,
0.64444,
0.13556,
0,
0.51111
],
"50": [
0,
0.64444,
0.13556,
0,
0.51111
],
"51": [
0,
0.64444,
0.13556,
0,
0.51111
],
"52": [
0.19444,
0.64444,
0.13556,
0,
0.51111
],
"53": [
0,
0.64444,
0.13556,
0,
0.51111
],
"54": [
0,
0.64444,
0.13556,
0,
0.51111
],
"55": [
0.19444,
0.64444,
0.13556,
0,
0.51111
],
"56": [
0,
0.64444,
0.13556,
0,
0.51111
],
"57": [
0,
0.64444,
0.13556,
0,
0.51111
],
"58": [
0,
0.43056,
0.0582,
0,
0.30667
],
"59": [
0.19444,
0.43056,
0.0582,
0,
0.30667
],
"61": [
-0.13313,
0.36687,
0.06616,
0,
0.76666
],
"63": [
0,
0.69444,
0.1225,
0,
0.51111
],
"64": [
0,
0.69444,
0.09597,
0,
0.76666
],
"65": [
0,
0.68333,
0,
0,
0.74333
],
"66": [
0,
0.68333,
0.10257,
0,
0.70389
],
"67": [
0,
0.68333,
0.14528,
0,
0.71555
],
"68": [
0,
0.68333,
0.09403,
0,
0.755
],
"69": [
0,
0.68333,
0.12028,
0,
0.67833
],
"70": [
0,
0.68333,
0.13305,
0,
0.65277
],
"71": [
0,
0.68333,
0.08722,
0,
0.77361
],
"72": [
0,
0.68333,
0.16389,
0,
0.74333
],
"73": [
0,
0.68333,
0.15806,
0,
0.38555
],
"74": [
0,
0.68333,
0.14028,
0,
0.525
],
"75": [
0,
0.68333,
0.14528,
0,
0.76888
],
"76": [
0,
0.68333,
0,
0,
0.62722
],
"77": [
0,
0.68333,
0.16389,
0,
0.89666
],
"78": [
0,
0.68333,
0.16389,
0,
0.74333
],
"79": [
0,
0.68333,
0.09403,
0,
0.76666
],
"80": [
0,
0.68333,
0.10257,
0,
0.67833
],
"81": [
0.19444,
0.68333,
0.09403,
0,
0.76666
],
"82": [
0,
0.68333,
0.03868,
0,
0.72944
],
"83": [
0,
0.68333,
0.11972,
0,
0.56222
],
"84": [
0,
0.68333,
0.13305,
0,
0.71555
],
"85": [
0,
0.68333,
0.16389,
0,
0.74333
],
"86": [
0,
0.68333,
0.18361,
0,
0.74333
],
"87": [
0,
0.68333,
0.18361,
0,
0.99888
],
"88": [
0,
0.68333,
0.15806,
0,
0.74333
],
"89": [
0,
0.68333,
0.19383,
0,
0.74333
],
"90": [
0,
0.68333,
0.14528,
0,
0.61333
],
"91": [
0.25,
0.75,
0.1875,
0,
0.30667
],
"93": [
0.25,
0.75,
0.10528,
0,
0.30667
],
"94": [
0,
0.69444,
0.06646,
0,
0.51111
],
"95": [
0.31,
0.12056,
0.09208,
0,
0.51111
],
"97": [
0,
0.43056,
0.07671,
0,
0.51111
],
"98": [
0,
0.69444,
0.06312,
0,
0.46
],
"99": [
0,
0.43056,
0.05653,
0,
0.46
],
"100": [
0,
0.69444,
0.10333,
0,
0.51111
],
"101": [
0,
0.43056,
0.07514,
0,
0.46
],
"102": [
0.19444,
0.69444,
0.21194,
0,
0.30667
],
"103": [
0.19444,
0.43056,
0.08847,
0,
0.46
],
"104": [
0,
0.69444,
0.07671,
0,
0.51111
],
"105": [
0,
0.65536,
0.1019,
0,
0.30667
],
"106": [
0.19444,
0.65536,
0.14467,
0,
0.30667
],
"107": [
0,
0.69444,
0.10764,
0,
0.46
],
"108": [
0,
0.69444,
0.10333,
0,
0.25555
],
"109": [
0,
0.43056,
0.07671,
0,
0.81777
],
"110": [
0,
0.43056,
0.07671,
0,
0.56222
],
"111": [
0,
0.43056,
0.06312,
0,
0.51111
],
"112": [
0.19444,
0.43056,
0.06312,
0,
0.51111
],
"113": [
0.19444,
0.43056,
0.08847,
0,
0.46
],
"114": [
0,
0.43056,
0.10764,
0,
0.42166
],
"115": [
0,
0.43056,
0.08208,
0,
0.40889
],
"116": [
0,
0.61508,
0.09486,
0,
0.33222
],
"117": [
0,
0.43056,
0.07671,
0,
0.53666
],
"118": [
0,
0.43056,
0.10764,
0,
0.46
],
"119": [
0,
0.43056,
0.10764,
0,
0.66444
],
"120": [
0,
0.43056,
0.12042,
0,
0.46389
],
"121": [
0.19444,
0.43056,
0.08847,
0,
0.48555
],
"122": [
0,
0.43056,
0.12292,
0,
0.40889
],
"126": [
0.35,
0.31786,
0.11585,
0,
0.51111
],
"160": [
0,
0,
0,
0,
0.25
],
"168": [
0,
0.66786,
0.10474,
0,
0.51111
],
"176": [
0,
0.69444,
0,
0,
0.83129
],
"184": [
0.17014,
0,
0,
0,
0.46
],
"198": [
0,
0.68333,
0.12028,
0,
0.88277
],
"216": [
0.04861,
0.73194,
0.09403,
0,
0.76666
],
"223": [
0.19444,
0.69444,
0.10514,
0,
0.53666
],
"230": [
0,
0.43056,
0.07514,
0,
0.71555
],
"248": [
0.09722,
0.52778,
0.09194,
0,
0.51111
],
"338": [
0,
0.68333,
0.12028,
0,
0.98499
],
"339": [
0,
0.43056,
0.07514,
0,
0.71555
],
"710": [
0,
0.69444,
0.06646,
0,
0.51111
],
"711": [
0,
0.62847,
0.08295,
0,
0.51111
],
"713": [
0,
0.56167,
0.10333,
0,
0.51111
],
"714": [
0,
0.69444,
0.09694,
0,
0.51111
],
"715": [
0,
0.69444,
0,
0,
0.51111
],
"728": [
0,
0.69444,
0.10806,
0,
0.51111
],
"729": [
0,
0.66786,
0.11752,
0,
0.30667
],
"730": [
0,
0.69444,
0,
0,
0.83129
],
"732": [
0,
0.66786,
0.11585,
0,
0.51111
],
"733": [
0,
0.69444,
0.1225,
0,
0.51111
],
"915": [
0,
0.68333,
0.13305,
0,
0.62722
],
"916": [
0,
0.68333,
0,
0,
0.81777
],
"920": [
0,
0.68333,
0.09403,
0,
0.76666
],
"923": [
0,
0.68333,
0,
0,
0.69222
],
"926": [
0,
0.68333,
0.15294,
0,
0.66444
],
"928": [
0,
0.68333,
0.16389,
0,
0.74333
],
"931": [
0,
0.68333,
0.12028,
0,
0.71555
],
"933": [
0,
0.68333,
0.11111,
0,
0.76666
],
"934": [
0,
0.68333,
0.05986,
0,
0.71555
],
"936": [
0,
0.68333,
0.11111,
0,
0.76666
],
"937": [
0,
0.68333,
0.10257,
0,
0.71555
],
"8211": [
0,
0.43056,
0.09208,
0,
0.51111
],
"8212": [
0,
0.43056,
0.09208,
0,
1.02222
],
"8216": [
0,
0.69444,
0.12417,
0,
0.30667
],
"8217": [
0,
0.69444,
0.12417,
0,
0.30667
],
"8220": [
0,
0.69444,
0.1685,
0,
0.51444
],
"8221": [
0,
0.69444,
0.06961,
0,
0.51444
],
"8463": [
0,
0.68889,
0,
0,
0.54028
]
},
"Main-Regular": {
"32": [
0,
0,
0,
0,
0.25
],
"33": [
0,
0.69444,
0,
0,
0.27778
],
"34": [
0,
0.69444,
0,
0,
0.5
],
"35": [
0.19444,
0.69444,
0,
0,
0.83334
],
"36": [
0.05556,
0.75,
0,
0,
0.5
],
"37": [
0.05556,
0.75,
0,
0,
0.83334
],
"38": [
0,
0.69444,
0,
0,
0.77778
],
"39": [
0,
0.69444,
0,
0,
0.27778
],
"40": [
0.25,
0.75,
0,
0,
0.38889
],
"41": [
0.25,
0.75,
0,
0,
0.38889
],
"42": [
0,
0.75,
0,
0,
0.5
],
"43": [
0.08333,
0.58333,
0,
0,
0.77778
],
"44": [
0.19444,
0.10556,
0,
0,
0.27778
],
"45": [
0,
0.43056,
0,
0,
0.33333
],
"46": [
0,
0.10556,
0,
0,
0.27778
],
"47": [
0.25,
0.75,
0,
0,
0.5
],
"48": [
0,
0.64444,
0,
0,
0.5
],
"49": [
0,
0.64444,
0,
0,
0.5
],
"50": [
0,
0.64444,
0,
0,
0.5
],
"51": [
0,
0.64444,
0,
0,
0.5
],
"52": [
0,
0.64444,
0,
0,
0.5
],
"53": [
0,
0.64444,
0,
0,
0.5
],
"54": [
0,
0.64444,
0,
0,
0.5
],
"55": [
0,
0.64444,
0,
0,
0.5
],
"56": [
0,
0.64444,
0,
0,
0.5
],
"57": [
0,
0.64444,
0,
0,
0.5
],
"58": [
0,
0.43056,
0,
0,
0.27778
],
"59": [
0.19444,
0.43056,
0,
0,
0.27778
],
"60": [
0.0391,
0.5391,
0,
0,
0.77778
],
"61": [
-0.13313,
0.36687,
0,
0,
0.77778
],
"62": [
0.0391,
0.5391,
0,
0,
0.77778
],
"63": [
0,
0.69444,
0,
0,
0.47222
],
"64": [
0,
0.69444,
0,
0,
0.77778
],
"65": [
0,
0.68333,
0,
0,
0.75
],
"66": [
0,
0.68333,
0,
0,
0.70834
],
"67": [
0,
0.68333,
0,
0,
0.72222
],
"68": [
0,
0.68333,
0,
0,
0.76389
],
"69": [
0,
0.68333,
0,
0,
0.68056
],
"70": [
0,
0.68333,
0,
0,
0.65278
],
"71": [
0,
0.68333,
0,
0,
0.78472
],
"72": [
0,
0.68333,
0,
0,
0.75
],
"73": [
0,
0.68333,
0,
0,
0.36111
],
"74": [
0,
0.68333,
0,
0,
0.51389
],
"75": [
0,
0.68333,
0,
0,
0.77778
],
"76": [
0,
0.68333,
0,
0,
0.625
],
"77": [
0,
0.68333,
0,
0,
0.91667
],
"78": [
0,
0.68333,
0,
0,
0.75
],
"79": [
0,
0.68333,
0,
0,
0.77778
],
"80": [
0,
0.68333,
0,
0,
0.68056
],
"81": [
0.19444,
0.68333,
0,
0,
0.77778
],
"82": [
0,
0.68333,
0,
0,
0.73611
],
"83": [
0,
0.68333,
0,
0,
0.55556
],
"84": [
0,
0.68333,
0,
0,
0.72222
],
"85": [
0,
0.68333,
0,
0,
0.75
],
"86": [
0,
0.68333,
0.01389,
0,
0.75
],
"87": [
0,
0.68333,
0.01389,
0,
1.02778
],
"88": [
0,
0.68333,
0,
0,
0.75
],
"89": [
0,
0.68333,
0.025,
0,
0.75
],
"90": [
0,
0.68333,
0,
0,
0.61111
],
"91": [
0.25,
0.75,
0,
0,
0.27778
],
"92": [
0.25,
0.75,
0,
0,
0.5
],
"93": [
0.25,
0.75,
0,
0,
0.27778
],
"94": [
0,
0.69444,
0,
0,
0.5
],
"95": [
0.31,
0.12056,
0.02778,
0,
0.5
],
"97": [
0,
0.43056,
0,
0,
0.5
],
"98": [
0,
0.69444,
0,
0,
0.55556
],
"99": [
0,
0.43056,
0,
0,
0.44445
],
"100": [
0,
0.69444,
0,
0,
0.55556
],
"101": [
0,
0.43056,
0,
0,
0.44445
],
"102": [
0,
0.69444,
0.07778,
0,
0.30556
],
"103": [
0.19444,
0.43056,
0.01389,
0,
0.5
],
"104": [
0,
0.69444,
0,
0,
0.55556
],
"105": [
0,
0.66786,
0,
0,
0.27778
],
"106": [
0.19444,
0.66786,
0,
0,
0.30556
],
"107": [
0,
0.69444,
0,
0,
0.52778
],
"108": [
0,
0.69444,
0,
0,
0.27778
],
"109": [
0,
0.43056,
0,
0,
0.83334
],
"110": [
0,
0.43056,
0,
0,
0.55556
],
"111": [
0,
0.43056,
0,
0,
0.5
],
"112": [
0.19444,
0.43056,
0,
0,
0.55556
],
"113": [
0.19444,
0.43056,
0,
0,
0.52778
],
"114": [
0,
0.43056,
0,
0,
0.39167
],
"115": [
0,
0.43056,
0,
0,
0.39445
],
"116": [
0,
0.61508,
0,
0,
0.38889
],
"117": [
0,
0.43056,
0,
0,
0.55556
],
"118": [
0,
0.43056,
0.01389,
0,
0.52778
],
"119": [
0,
0.43056,
0.01389,
0,
0.72222
],
"120": [
0,
0.43056,
0,
0,
0.52778
],
"121": [
0.19444,
0.43056,
0.01389,
0,
0.52778
],
"122": [
0,
0.43056,
0,
0,
0.44445
],
"123": [
0.25,
0.75,
0,
0,
0.5
],
"124": [
0.25,
0.75,
0,
0,
0.27778
],
"125": [
0.25,
0.75,
0,
0,
0.5
],
"126": [
0.35,
0.31786,
0,
0,
0.5
],
"160": [
0,
0,
0,
0,
0.25
],
"163": [
0,
0.69444,
0,
0,
0.76909
],
"167": [
0.19444,
0.69444,
0,
0,
0.44445
],
"168": [
0,
0.66786,
0,
0,
0.5
],
"172": [
0,
0.43056,
0,
0,
0.66667
],
"176": [
0,
0.69444,
0,
0,
0.75
],
"177": [
0.08333,
0.58333,
0,
0,
0.77778
],
"182": [
0.19444,
0.69444,
0,
0,
0.61111
],
"184": [
0.17014,
0,
0,
0,
0.44445
],
"198": [
0,
0.68333,
0,
0,
0.90278
],
"215": [
0.08333,
0.58333,
0,
0,
0.77778
],
"216": [
0.04861,
0.73194,
0,
0,
0.77778
],
"223": [
0,
0.69444,
0,
0,
0.5
],
"230": [
0,
0.43056,
0,
0,
0.72222
],
"247": [
0.08333,
0.58333,
0,
0,
0.77778
],
"248": [
0.09722,
0.52778,
0,
0,
0.5
],
"305": [
0,
0.43056,
0,
0,
0.27778
],
"338": [
0,
0.68333,
0,
0,
1.01389
],
"339": [
0,
0.43056,
0,
0,
0.77778
],
"567": [
0.19444,
0.43056,
0,
0,
0.30556
],
"710": [
0,
0.69444,
0,
0,
0.5
],
"711": [
0,
0.62847,
0,
0,
0.5
],
"713": [
0,
0.56778,
0,
0,
0.5
],
"714": [
0,
0.69444,
0,
0,
0.5
],
"715": [
0,
0.69444,
0,
0,
0.5
],
"728": [
0,
0.69444,
0,
0,
0.5
],
"729": [
0,
0.66786,
0,
0,
0.27778
],
"730": [
0,
0.69444,
0,
0,
0.75
],
"732": [
0,
0.66786,
0,
0,
0.5
],
"733": [
0,
0.69444,
0,
0,
0.5
],
"915": [
0,
0.68333,
0,
0,
0.625
],
"916": [
0,
0.68333,
0,
0,
0.83334
],
"920": [
0,
0.68333,
0,
0,
0.77778
],
"923": [
0,
0.68333,
0,
0,
0.69445
],
"926": [
0,
0.68333,
0,
0,
0.66667
],
"928": [
0,
0.68333,
0,
0,
0.75
],
"931": [
0,
0.68333,
0,
0,
0.72222
],
"933": [
0,
0.68333,
0,
0,
0.77778
],
"934": [
0,
0.68333,
0,
0,
0.72222
],
"936": [
0,
0.68333,
0,
0,
0.77778
],
"937": [
0,
0.68333,
0,
0,
0.72222
],
"8211": [
0,
0.43056,
0.02778,
0,
0.5
],
"8212": [
0,
0.43056,
0.02778,
0,
1.0
],
"8216": [
0,
0.69444,
0,
0,
0.27778
],
"8217": [
0,
0.69444,
0,
0,
0.27778
],
"8220": [
0,
0.69444,
0,
0,
0.5
],
"8221": [
0,
0.69444,
0,
0,
0.5
],
"8224": [
0.19444,
0.69444,
0,
0,
0.44445
],
"8225": [
0.19444,
0.69444,
0,
0,
0.44445
],
"8230": [
0,
0.123,
0,
0,
1.172
],
"8242": [
0,
0.55556,
0,
0,
0.275
],
"8407": [
0,
0.71444,
0.15382,
0,
0.5
],
"8463": [
0,
0.68889,
0,
0,
0.54028
],
"8465": [
0,
0.69444,
0,
0,
0.72222
],
"8467": [
0,
0.69444,
0,
0.11111,
0.41667
],
"8472": [
0.19444,
0.43056,
0,
0.11111,
0.63646
],
"8476": [
0,
0.69444,
0,
0,
0.72222
],
"8501": [
0,
0.69444,
0,
0,
0.61111
],
"8592": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8593": [
0.19444,
0.69444,
0,
0,
0.5
],
"8594": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8595": [
0.19444,
0.69444,
0,
0,
0.5
],
"8596": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8597": [
0.25,
0.75,
0,
0,
0.5
],
"8598": [
0.19444,
0.69444,
0,
0,
1.0
],
"8599": [
0.19444,
0.69444,
0,
0,
1.0
],
"8600": [
0.19444,
0.69444,
0,
0,
1.0
],
"8601": [
0.19444,
0.69444,
0,
0,
1.0
],
"8614": [
0.011,
0.511,
0,
0,
1.0
],
"8617": [
0.011,
0.511,
0,
0,
1.126
],
"8618": [
0.011,
0.511,
0,
0,
1.126
],
"8636": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8637": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8640": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8641": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8652": [
0.011,
0.671,
0,
0,
1.0
],
"8656": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8657": [
0.19444,
0.69444,
0,
0,
0.61111
],
"8658": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8659": [
0.19444,
0.69444,
0,
0,
0.61111
],
"8660": [
-0.13313,
0.36687,
0,
0,
1.0
],
"8661": [
0.25,
0.75,
0,
0,
0.61111
],
"8704": [
0,
0.69444,
0,
0,
0.55556
],
"8706": [
0,
0.69444,
0.05556,
0.08334,
0.5309
],
"8707": [
0,
0.69444,
0,
0,
0.55556
],
"8709": [
0.05556,
0.75,
0,
0,
0.5
],
"8711": [
0,
0.68333,
0,
0,
0.83334
],
"8712": [
0.0391,
0.5391,
0,
0,
0.66667
],
"8715": [
0.0391,
0.5391,
0,
0,
0.66667
],
"8722": [
0.08333,
0.58333,
0,
0,
0.77778
],
"8723": [
0.08333,
0.58333,
0,
0,
0.77778
],
"8725": [
0.25,
0.75,
0,
0,
0.5
],
"8726": [
0.25,
0.75,
0,
0,
0.5
],
"8727": [
-0.03472,
0.46528,
0,
0,
0.5
],
"8728": [
-0.05555,
0.44445,
0,
0,
0.5
],
"8729": [
-0.05555,
0.44445,
0,
0,
0.5
],
"8730": [
0.2,
0.8,
0,
0,
0.83334
],
"8733": [
0,
0.43056,
0,
0,
0.77778
],
"8734": [
0,
0.43056,
0,
0,
1.0
],
"8736": [
0,
0.69224,
0,
0,
0.72222
],
"8739": [
0.25,
0.75,
0,
0,
0.27778
],
"8741": [
0.25,
0.75,
0,
0,
0.5
],
"8743": [
0,
0.55556,
0,
0,
0.66667
],
"8744": [
0,
0.55556,
0,
0,
0.66667
],
"8745": [
0,
0.55556,
0,
0,
0.66667
],
"8746": [
0,
0.55556,
0,
0,
0.66667
],
"8747": [
0.19444,
0.69444,
0.11111,
0,
0.41667
],
"8764": [
-0.13313,
0.36687,
0,
0,
0.77778
],
"8768": [
0.19444,
0.69444,
0,
0,
0.27778
],
"8771": [
-0.03625,
0.46375,
0,
0,
0.77778
],
"8773": [
-0.022,
0.589,
0,
0,
0.778
],
"8776": [
-0.01688,
0.48312,
0,
0,
0.77778
],
"8781": [
-0.03625,
0.46375,
0,
0,
0.77778
],
"8784": [
-0.133,
0.673,
0,
0,
0.778
],
"8801": [
-0.03625,
0.46375,
0,
0,
0.77778
],
"8804": [
0.13597,
0.63597,
0,
0,
0.77778
],
"8805": [
0.13597,
0.63597,
0,
0,
0.77778
],
"8810": [
0.0391,
0.5391,
0,
0,
1.0
],
"8811": [
0.0391,
0.5391,
0,
0,
1.0
],
"8826": [
0.0391,
0.5391,
0,
0,
0.77778
],
"8827": [
0.0391,
0.5391,
0,
0,
0.77778
],
"8834": [
0.0391,
0.5391,
0,
0,
0.77778
],
"8835": [
0.0391,
0.5391,
0,
0,
0.77778
],
"8838": [
0.13597,
0.63597,
0,
0,
0.77778
],
"8839": [
0.13597,
0.63597,
0,
0,
0.77778
],
"8846": [
0,
0.55556,
0,
0,
0.66667
],
"8849": [
0.13597,
0.63597,
0,
0,
0.77778
],
"8850": [
0.13597,
0.63597,
0,
0,
0.77778
],
"8851": [
0,
0.55556,
0,
0,
0.66667
],
"8852": [
0,
0.55556,
0,
0,
0.66667
],
"8853": [
0.08333,
0.58333,
0,
0,
0.77778
],
"8854": [
0.08333,
0.58333,
0,
0,
0.77778
],
"8855": [
0.08333,
0.58333,
0,
0,
0.77778
],
"8856": [
0.08333,
0.58333,
0,
0,
0.77778
],
"8857": [
0.08333,
0.58333,
0,
0,
0.77778
],
"8866": [
0,
0.69444,
0,
0,
0.61111
],
"8867": [
0,
0.69444,
0,
0,
0.61111
],
"8868": [
0,
0.69444,
0,
0,
0.77778
],
"8869": [
0,
0.69444,
0,
0,
0.77778
],
"8872": [
0.249,
0.75,
0,
0,
0.867
],
"8900": [
-0.05555,
0.44445,
0,
0,
0.5
],
"8901": [
-0.05555,
0.44445,
0,
0,
0.27778
],
"8902": [
-0.03472,
0.46528,
0,
0,
0.5
],
"8904": [
0.005,
0.505,
0,
0,
0.9
],
"8942": [
0.03,
0.903,
0,
0,
0.278
],
"8943": [
-0.19,
0.313,
0,
0,
1.172
],
"8945": [
-0.1,
0.823,
0,
0,
1.282
],
"8968": [
0.25,
0.75,
0,
0,
0.44445
],
"8969": [
0.25,
0.75,
0,
0,
0.44445
],
"8970": [
0.25,
0.75,
0,
0,
0.44445
],
"8971": [
0.25,
0.75,
0,
0,
0.44445
],
"8994": [
-0.14236,
0.35764,
0,
0,
1.0
],
"8995": [
-0.14236,
0.35764,
0,
0,
1.0
],
"9136": [
0.244,
0.744,
0,
0,
0.412
],
"9137": [
0.244,
0.745,
0,
0,
0.412
],
"9651": [
0.19444,
0.69444,
0,
0,
0.88889
],
"9657": [
-0.03472,
0.46528,
0,
0,
0.5
],
"9661": [
0.19444,
0.69444,
0,
0,
0.88889
],
"9667": [
-0.03472,
0.46528,
0,
0,
0.5
],
"9711": [
0.19444,
0.69444,
0,
0,
1.0
],
"9824": [
0.12963,
0.69444,
0,
0,
0.77778
],
"9825": [
0.12963,
0.69444,
0,
0,
0.77778
],
"9826": [
0.12963,
0.69444,
0,
0,
0.77778
],
"9827": [
0.12963,
0.69444,
0,
0,
0.77778
],
"9837": [
0,
0.75,
0,
0,
0.38889
],
"9838": [
0.19444,
0.69444,
0,
0,
0.38889
],
"9839": [
0.19444,
0.69444,
0,
0,
0.38889
],
"10216": [
0.25,
0.75,
0,
0,
0.38889
],
"10217": [
0.25,
0.75,
0,
0,
0.38889
],
"10222": [
0.244,
0.744,
0,
0,
0.412
],
"10223": [
0.244,
0.745,
0,
0,
0.412
],
"10229": [
0.011,
0.511,
0,
0,
1.609
],
"10230": [
0.011,
0.511,
0,
0,
1.638
],
"10231": [
0.011,
0.511,
0,
0,
1.859
],
"10232": [
0.024,
0.525,
0,
0,
1.609
],
"10233": [
0.024,
0.525,
0,
0,
1.638
],
"10234": [
0.024,
0.525,
0,
0,
1.858
],
"10236": [
0.011,
0.511,
0,
0,
1.638
],
"10815": [
0,
0.68333,
0,
0,
0.75
],
"10927": [
0.13597,
0.63597,
0,
0,
0.77778
],
"10928": [
0.13597,
0.63597,
0,
0,
0.77778
],
"57376": [
0.19444,
0.69444,
0,
0,
0
]
},
"Math-BoldItalic": {
"32": [
0,
0,
0,
0,
0.25
],
"48": [
0,
0.44444,
0,
0,
0.575
],
"49": [
0,
0.44444,
0,
0,
0.575
],
"50": [
0,
0.44444,
0,
0,
0.575
],
"51": [
0.19444,
0.44444,
0,
0,
0.575
],
"52": [
0.19444,
0.44444,
0,
0,
0.575
],
"53": [
0.19444,
0.44444,
0,
0,
0.575
],
"54": [
0,
0.64444,
0,
0,
0.575
],
"55": [
0.19444,
0.44444,
0,
0,
0.575
],
"56": [
0,
0.64444,
0,
0,
0.575
],
"57": [
0.19444,
0.44444,
0,
0,
0.575
],
"65": [
0,
0.68611,
0,
0,
0.86944
],
"66": [
0,
0.68611,
0.04835,
0,
0.8664
],
"67": [
0,
0.68611,
0.06979,
0,
0.81694
],
"68": [
0,
0.68611,
0.03194,
0,
0.93812
],
"69": [
0,
0.68611,
0.05451,
0,
0.81007
],
"70": [
0,
0.68611,
0.15972,
0,
0.68889
],
"71": [
0,
0.68611,
0,
0,
0.88673
],
"72": [
0,
0.68611,
0.08229,
0,
0.98229
],
"73": [
0,
0.68611,
0.07778,
0,
0.51111
],
"74": [
0,
0.68611,
0.10069,
0,
0.63125
],
"75": [
0,
0.68611,
0.06979,
0,
0.97118
],
"76": [
0,
0.68611,
0,
0,
0.75555
],
"77": [
0,
0.68611,
0.11424,
0,
1.14201
],
"78": [
0,
0.68611,
0.11424,
0,
0.95034
],
"79": [
0,
0.68611,
0.03194,
0,
0.83666
],
"80": [
0,
0.68611,
0.15972,
0,
0.72309
],
"81": [
0.19444,
0.68611,
0,
0,
0.86861
],
"82": [
0,
0.68611,
0.00421,
0,
0.87235
],
"83": [
0,
0.68611,
0.05382,
0,
0.69271
],
"84": [
0,
0.68611,
0.15972,
0,
0.63663
],
"85": [
0,
0.68611,
0.11424,
0,
0.80027
],
"86": [
0,
0.68611,
0.25555,
0,
0.67778
],
"87": [
0,
0.68611,
0.15972,
0,
1.09305
],
"88": [
0,
0.68611,
0.07778,
0,
0.94722
],
"89": [
0,
0.68611,
0.25555,
0,
0.67458
],
"90": [
0,
0.68611,
0.06979,
0,
0.77257
],
"97": [
0,
0.44444,
0,
0,
0.63287
],
"98": [
0,
0.69444,
0,
0,
0.52083
],
"99": [
0,
0.44444,
0,
0,
0.51342
],
"100": [
0,
0.69444,
0,
0,
0.60972
],
"101": [
0,
0.44444,
0,
0,
0.55361
],
"102": [
0.19444,
0.69444,
0.11042,
0,
0.56806
],
"103": [
0.19444,
0.44444,
0.03704,
0,
0.5449
],
"104": [
0,
0.69444,
0,
0,
0.66759
],
"105": [
0,
0.69326,
0,
0,
0.4048
],
"106": [
0.19444,
0.69326,
0.0622,
0,
0.47083
],
"107": [
0,
0.69444,
0.01852,
0,
0.6037
],
"108": [
0,
0.69444,
0.0088,
0,
0.34815
],
"109": [
0,
0.44444,
0,
0,
1.0324
],
"110": [
0,
0.44444,
0,
0,
0.71296
],
"111": [
0,
0.44444,
0,
0,
0.58472
],
"112": [
0.19444,
0.44444,
0,
0,
0.60092
],
"113": [
0.19444,
0.44444,
0.03704,
0,
0.54213
],
"114": [
0,
0.44444,
0.03194,
0,
0.5287
],
"115": [
0,
0.44444,
0,
0,
0.53125
],
"116": [
0,
0.63492,
0,
0,
0.41528
],
"117": [
0,
0.44444,
0,
0,
0.68102
],
"118": [
0,
0.44444,
0.03704,
0,
0.56666
],
"119": [
0,
0.44444,
0.02778,
0,
0.83148
],
"120": [
0,
0.44444,
0,
0,
0.65903
],
"121": [
0.19444,
0.44444,
0.03704,
0,
0.59028
],
"122": [
0,
0.44444,
0.04213,
0,
0.55509
],
"160": [
0,
0,
0,
0,
0.25
],
"915": [
0,
0.68611,
0.15972,
0,
0.65694
],
"916": [
0,
0.68611,
0,
0,
0.95833
],
"920": [
0,
0.68611,
0.03194,
0,
0.86722
],
"923": [
0,
0.68611,
0,
0,
0.80555
],
"926": [
0,
0.68611,
0.07458,
0,
0.84125
],
"928": [
0,
0.68611,
0.08229,
0,
0.98229
],
"931": [
0,
0.68611,
0.05451,
0,
0.88507
],
"933": [
0,
0.68611,
0.15972,
0,
0.67083
],
"934": [
0,
0.68611,
0,
0,
0.76666
],
"936": [
0,
0.68611,
0.11653,
0,
0.71402
],
"937": [
0,
0.68611,
0.04835,
0,
0.8789
],
"945": [
0,
0.44444,
0,
0,
0.76064
],
"946": [
0.19444,
0.69444,
0.03403,
0,
0.65972
],
"947": [
0.19444,
0.44444,
0.06389,
0,
0.59003
],
"948": [
0,
0.69444,
0.03819,
0,
0.52222
],
"949": [
0,
0.44444,
0,
0,
0.52882
],
"950": [
0.19444,
0.69444,
0.06215,
0,
0.50833
],
"951": [
0.19444,
0.44444,
0.03704,
0,
0.6
],
"952": [
0,
0.69444,
0.03194,
0,
0.5618
],
"953": [
0,
0.44444,
0,
0,
0.41204
],
"954": [
0,
0.44444,
0,
0,
0.66759
],
"955": [
0,
0.69444,
0,
0,
0.67083
],
"956": [
0.19444,
0.44444,
0,
0,
0.70787
],
"957": [
0,
0.44444,
0.06898,
0,
0.57685
],
"958": [
0.19444,
0.69444,
0.03021,
0,
0.50833
],
"959": [
0,
0.44444,
0,
0,
0.58472
],
"960": [
0,
0.44444,
0.03704,
0,
0.68241
],
"961": [
0.19444,
0.44444,
0,
0,
0.6118
],
"962": [
0.09722,
0.44444,
0.07917,
0,
0.42361
],
"963": [
0,
0.44444,
0.03704,
0,
0.68588
],
"964": [
0,
0.44444,
0.13472,
0,
0.52083
],
"965": [
0,
0.44444,
0.03704,
0,
0.63055
],
"966": [
0.19444,
0.44444,
0,
0,
0.74722
],
"967": [
0.19444,
0.44444,
0,
0,
0.71805
],
"968": [
0.19444,
0.69444,
0.03704,
0,
0.75833
],
"969": [
0,
0.44444,
0.03704,
0,
0.71782
],
"977": [
0,
0.69444,
0,
0,
0.69155
],
"981": [
0.19444,
0.69444,
0,
0,
0.7125
],
"982": [
0,
0.44444,
0.03194,
0,
0.975
],
"1009": [
0.19444,
0.44444,
0,
0,
0.6118
],
"1013": [
0,
0.44444,
0,
0,
0.48333
],
"57649": [
0,
0.44444,
0,
0,
0.39352
],
"57911": [
0.19444,
0.44444,
0,
0,
0.43889
]
},
"Math-Italic": {
"32": [
0,
0,
0,
0,
0.25
],
"48": [
0,
0.43056,
0,
0,
0.5
],
"49": [
0,
0.43056,
0,
0,
0.5
],
"50": [
0,
0.43056,
0,
0,
0.5
],
"51": [
0.19444,
0.43056,
0,
0,
0.5
],
"52": [
0.19444,
0.43056,
0,
0,
0.5
],
"53": [
0.19444,
0.43056,
0,
0,
0.5
],
"54": [
0,
0.64444,
0,
0,
0.5
],
"55": [
0.19444,
0.43056,
0,
0,
0.5
],
"56": [
0,
0.64444,
0,
0,
0.5
],
"57": [
0.19444,
0.43056,
0,
0,
0.5
],
"65": [
0,
0.68333,
0,
0.13889,
0.75
],
"66": [
0,
0.68333,
0.05017,
0.08334,
0.75851
],
"67": [
0,
0.68333,
0.07153,
0.08334,
0.71472
],
"68": [
0,
0.68333,
0.02778,
0.05556,
0.82792
],
"69": [
0,
0.68333,
0.05764,
0.08334,
0.7382
],
"70": [
0,
0.68333,
0.13889,
0.08334,
0.64306
],
"71": [
0,
0.68333,
0,
0.08334,
0.78625
],
"72": [
0,
0.68333,
0.08125,
0.05556,
0.83125
],
"73": [
0,
0.68333,
0.07847,
0.11111,
0.43958
],
"74": [
0,
0.68333,
0.09618,
0.16667,
0.55451
],
"75": [
0,
0.68333,
0.07153,
0.05556,
0.84931
],
"76": [
0,
0.68333,
0,
0.02778,
0.68056
],
"77": [
0,
0.68333,
0.10903,
0.08334,
0.97014
],
"78": [
0,
0.68333,
0.10903,
0.08334,
0.80347
],
"79": [
0,
0.68333,
0.02778,
0.08334,
0.76278
],
"80": [
0,
0.68333,
0.13889,
0.08334,
0.64201
],
"81": [
0.19444,
0.68333,
0,
0.08334,
0.79056
],
"82": [
0,
0.68333,
0.00773,
0.08334,
0.75929
],
"83": [
0,
0.68333,
0.05764,
0.08334,
0.6132
],
"84": [
0,
0.68333,
0.13889,
0.08334,
0.58438
],
"85": [
0,
0.68333,
0.10903,
0.02778,
0.68278
],
"86": [
0,
0.68333,
0.22222,
0,
0.58333
],
"87": [
0,
0.68333,
0.13889,
0,
0.94445
],
"88": [
0,
0.68333,
0.07847,
0.08334,
0.82847
],
"89": [
0,
0.68333,
0.22222,
0,
0.58056
],
"90": [
0,
0.68333,
0.07153,
0.08334,
0.68264
],
"97": [
0,
0.43056,
0,
0,
0.52859
],
"98": [
0,
0.69444,
0,
0,
0.42917
],
"99": [
0,
0.43056,
0,
0.05556,
0.43276
],
"100": [
0,
0.69444,
0,
0.16667,
0.52049
],
"101": [
0,
0.43056,
0,
0.05556,
0.46563
],
"102": [
0.19444,
0.69444,
0.10764,
0.16667,
0.48959
],
"103": [
0.19444,
0.43056,
0.03588,
0.02778,
0.47697
],
"104": [
0,
0.69444,
0,
0,
0.57616
],
"105": [
0,
0.65952,
0,
0,
0.34451
],
"106": [
0.19444,
0.65952,
0.05724,
0,
0.41181
],
"107": [
0,
0.69444,
0.03148,
0,
0.5206
],
"108": [
0,
0.69444,
0.01968,
0.08334,
0.29838
],
"109": [
0,
0.43056,
0,
0,
0.87801
],
"110": [
0,
0.43056,
0,
0,
0.60023
],
"111": [
0,
0.43056,
0,
0.05556,
0.48472
],
"112": [
0.19444,
0.43056,
0,
0.08334,
0.50313
],
"113": [
0.19444,
0.43056,
0.03588,
0.08334,
0.44641
],
"114": [
0,
0.43056,
0.02778,
0.05556,
0.45116
],
"115": [
0,
0.43056,
0,
0.05556,
0.46875
],
"116": [
0,
0.61508,
0,
0.08334,
0.36111
],
"117": [
0,
0.43056,
0,
0.02778,
0.57246
],
"118": [
0,
0.43056,
0.03588,
0.02778,
0.48472
],
"119": [
0,
0.43056,
0.02691,
0.08334,
0.71592
],
"120": [
0,
0.43056,
0,
0.02778,
0.57153
],
"121": [
0.19444,
0.43056,
0.03588,
0.05556,
0.49028
],
"122": [
0,
0.43056,
0.04398,
0.05556,
0.46505
],
"160": [
0,
0,
0,
0,
0.25
],
"915": [
0,
0.68333,
0.13889,
0.08334,
0.61528
],
"916": [
0,
0.68333,
0,
0.16667,
0.83334
],
"920": [
0,
0.68333,
0.02778,
0.08334,
0.76278
],
"923": [
0,
0.68333,
0,
0.16667,
0.69445
],
"926": [
0,
0.68333,
0.07569,
0.08334,
0.74236
],
"928": [
0,
0.68333,
0.08125,
0.05556,
0.83125
],
"931": [
0,
0.68333,
0.05764,
0.08334,
0.77986
],
"933": [
0,
0.68333,
0.13889,
0.05556,
0.58333
],
"934": [
0,
0.68333,
0,
0.08334,
0.66667
],
"936": [
0,
0.68333,
0.11,
0.05556,
0.61222
],
"937": [
0,
0.68333,
0.05017,
0.08334,
0.7724
],
"945": [
0,
0.43056,
0.0037,
0.02778,
0.6397
],
"946": [
0.19444,
0.69444,
0.05278,
0.08334,
0.56563
],
"947": [
0.19444,
0.43056,
0.05556,
0,
0.51773
],
"948": [
0,
0.69444,
0.03785,
0.05556,
0.44444
],
"949": [
0,
0.43056,
0,
0.08334,
0.46632
],
"950": [
0.19444,
0.69444,
0.07378,
0.08334,
0.4375
],
"951": [
0.19444,
0.43056,
0.03588,
0.05556,
0.49653
],
"952": [
0,
0.69444,
0.02778,
0.08334,
0.46944
],
"953": [
0,
0.43056,
0,
0.05556,
0.35394
],
"954": [
0,
0.43056,
0,
0,
0.57616
],
"955": [
0,
0.69444,
0,
0,
0.58334
],
"956": [
0.19444,
0.43056,
0,
0.02778,
0.60255
],
"957": [
0,
0.43056,
0.06366,
0.02778,
0.49398
],
"958": [
0.19444,
0.69444,
0.04601,
0.11111,
0.4375
],
"959": [
0,
0.43056,
0,
0.05556,
0.48472
],
"960": [
0,
0.43056,
0.03588,
0,
0.57003
],
"961": [
0.19444,
0.43056,
0,
0.08334,
0.51702
],
"962": [
0.09722,
0.43056,
0.07986,
0.08334,
0.36285
],
"963": [
0,
0.43056,
0.03588,
0,
0.57141
],
"964": [
0,
0.43056,
0.1132,
0.02778,
0.43715
],
"965": [
0,
0.43056,
0.03588,
0.02778,
0.54028
],
"966": [
0.19444,
0.43056,
0,
0.08334,
0.65417
],
"967": [
0.19444,
0.43056,
0,
0.05556,
0.62569
],
"968": [
0.19444,
0.69444,
0.03588,
0.11111,
0.65139
],
"969": [
0,
0.43056,
0.03588,
0,
0.62245
],
"977": [
0,
0.69444,
0,
0.08334,
0.59144
],
"981": [
0.19444,
0.69444,
0,
0.08334,
0.59583
],
"982": [
0,
0.43056,
0.02778,
0,
0.82813
],
"1009": [
0.19444,
0.43056,
0,
0.08334,
0.51702
],
"1013": [
0,
0.43056,
0,
0.05556,
0.4059
],
"57649": [
0,
0.43056,
0,
0.02778,
0.32246
],
"57911": [
0.19444,
0.43056,
0,
0.08334,
0.38403
]
},
"SansSerif-Bold": {
"32": [
0,
0,
0,
0,
0.25
],
"33": [
0,
0.69444,
0,
0,
0.36667
],
"34": [
0,
0.69444,
0,
0,
0.55834
],
"35": [
0.19444,
0.69444,
0,
0,
0.91667
],
"36": [
0.05556,
0.75,
0,
0,
0.55
],
"37": [
0.05556,
0.75,
0,
0,
1.02912
],
"38": [
0,
0.69444,
0,
0,
0.83056
],
"39": [
0,
0.69444,
0,
0,
0.30556
],
"40": [
0.25,
0.75,
0,
0,
0.42778
],
"41": [
0.25,
0.75,
0,
0,
0.42778
],
"42": [
0,
0.75,
0,
0,
0.55
],
"43": [
0.11667,
0.61667,
0,
0,
0.85556
],
"44": [
0.10556,
0.13056,
0,
0,
0.30556
],
"45": [
0,
0.45833,
0,
0,
0.36667
],
"46": [
0,
0.13056,
0,
0,
0.30556
],
"47": [
0.25,
0.75,
0,
0,
0.55
],
"48": [
0,
0.69444,
0,
0,
0.55
],
"49": [
0,
0.69444,
0,
0,
0.55
],
"50": [
0,
0.69444,
0,
0,
0.55
],
"51": [
0,
0.69444,
0,
0,
0.55
],
"52": [
0,
0.69444,
0,
0,
0.55
],
"53": [
0,
0.69444,
0,
0,
0.55
],
"54": [
0,
0.69444,
0,
0,
0.55
],
"55": [
0,
0.69444,
0,
0,
0.55
],
"56": [
0,
0.69444,
0,
0,
0.55
],
"57": [
0,
0.69444,
0,
0,
0.55
],
"58": [
0,
0.45833,
0,
0,
0.30556
],
"59": [
0.10556,
0.45833,
0,
0,
0.30556
],
"61": [
-0.09375,
0.40625,
0,
0,
0.85556
],
"63": [
0,
0.69444,
0,
0,
0.51945
],
"64": [
0,
0.69444,
0,
0,
0.73334
],
"65": [
0,
0.69444,
0,
0,
0.73334
],
"66": [
0,
0.69444,
0,
0,
0.73334
],
"67": [
0,
0.69444,
0,
0,
0.70278
],
"68": [
0,
0.69444,
0,
0,
0.79445
],
"69": [
0,
0.69444,
0,
0,
0.64167
],
"70": [
0,
0.69444,
0,
0,
0.61111
],
"71": [
0,
0.69444,
0,
0,
0.73334
],
"72": [
0,
0.69444,
0,
0,
0.79445
],
"73": [
0,
0.69444,
0,
0,
0.33056
],
"74": [
0,
0.69444,
0,
0,
0.51945
],
"75": [
0,
0.69444,
0,
0,
0.76389
],
"76": [
0,
0.69444,
0,
0,
0.58056
],
"77": [
0,
0.69444,
0,
0,
0.97778
],
"78": [
0,
0.69444,
0,
0,
0.79445
],
"79": [
0,
0.69444,
0,
0,
0.79445
],
"80": [
0,
0.69444,
0,
0,
0.70278
],
"81": [
0.10556,
0.69444,
0,
0,
0.79445
],
"82": [
0,
0.69444,
0,
0,
0.70278
],
"83": [
0,
0.69444,
0,
0,
0.61111
],
"84": [
0,
0.69444,
0,
0,
0.73334
],
"85": [
0,
0.69444,
0,
0,
0.76389
],
"86": [
0,
0.69444,
0.01528,
0,
0.73334
],
"87": [
0,
0.69444,
0.01528,
0,
1.03889
],
"88": [
0,
0.69444,
0,
0,
0.73334
],
"89": [
0,
0.69444,
0.0275,
0,
0.73334
],
"90": [
0,
0.69444,
0,
0,
0.67223
],
"91": [
0.25,
0.75,
0,
0,
0.34306
],
"93": [
0.25,
0.75,
0,
0,
0.34306
],
"94": [
0,
0.69444,
0,
0,
0.55
],
"95": [
0.35,
0.10833,
0.03056,
0,
0.55
],
"97": [
0,
0.45833,
0,
0,
0.525
],
"98": [
0,
0.69444,
0,
0,
0.56111
],
"99": [
0,
0.45833,
0,
0,
0.48889
],
"100": [
0,
0.69444,
0,
0,
0.56111
],
"101": [
0,
0.45833,
0,
0,
0.51111
],
"102": [
0,
0.69444,
0.07639,
0,
0.33611
],
"103": [
0.19444,
0.45833,
0.01528,
0,
0.55
],
"104": [
0,
0.69444,
0,
0,
0.56111
],
"105": [
0,
0.69444,
0,
0,
0.25556
],
"106": [
0.19444,
0.69444,
0,
0,
0.28611
],
"107": [
0,
0.69444,
0,
0,
0.53056
],
"108": [
0,
0.69444,
0,
0,
0.25556
],
"109": [
0,
0.45833,
0,
0,
0.86667
],
"110": [
0,
0.45833,
0,
0,
0.56111
],
"111": [
0,
0.45833,
0,
0,
0.55
],
"112": [
0.19444,
0.45833,
0,
0,
0.56111
],
"113": [
0.19444,
0.45833,
0,
0,
0.56111
],
"114": [
0,
0.45833,
0.01528,
0,
0.37222
],
"115": [
0,
0.45833,
0,
0,
0.42167
],
"116": [
0,
0.58929,
0,
0,
0.40417
],
"117": [
0,
0.45833,
0,
0,
0.56111
],
"118": [
0,
0.45833,
0.01528,
0,
0.5
],
"119": [
0,
0.45833,
0.01528,
0,
0.74445
],
"120": [
0,
0.45833,
0,
0,
0.5
],
"121": [
0.19444,
0.45833,
0.01528,
0,
0.5
],
"122": [
0,
0.45833,
0,
0,
0.47639
],
"126": [
0.35,
0.34444,
0,
0,
0.55
],
"160": [
0,
0,
0,
0,
0.25
],
"168": [
0,
0.69444,
0,
0,
0.55
],
"176": [
0,
0.69444,
0,
0,
0.73334
],
"180": [
0,
0.69444,
0,
0,
0.55
],
"184": [
0.17014,
0,
0,
0,
0.48889
],
"305": [
0,
0.45833,
0,
0,
0.25556
],
"567": [
0.19444,
0.45833,
0,
0,
0.28611
],
"710": [
0,
0.69444,
0,
0,
0.55
],
"711": [
0,
0.63542,
0,
0,
0.55
],
"713": [
0,
0.63778,
0,
0,
0.55
],
"728": [
0,
0.69444,
0,
0,
0.55
],
"729": [
0,
0.69444,
0,
0,
0.30556
],
"730": [
0,
0.69444,
0,
0,
0.73334
],
"732": [
0,
0.69444,
0,
0,
0.55
],
"733": [
0,
0.69444,
0,
0,
0.55
],
"915": [
0,
0.69444,
0,
0,
0.58056
],
"916": [
0,
0.69444,
0,
0,
0.91667
],
"920": [
0,
0.69444,
0,
0,
0.85556
],
"923": [
0,
0.69444,
0,
0,
0.67223
],
"926": [
0,
0.69444,
0,
0,
0.73334
],
"928": [
0,
0.69444,
0,
0,
0.79445
],
"931": [
0,
0.69444,
0,
0,
0.79445
],
"933": [
0,
0.69444,
0,
0,
0.85556
],
"934": [
0,
0.69444,
0,
0,
0.79445
],
"936": [
0,
0.69444,
0,
0,
0.85556
],
"937": [
0,
0.69444,
0,
0,
0.79445
],
"8211": [
0,
0.45833,
0.03056,
0,
0.55
],
"8212": [
0,
0.45833,
0.03056,
0,
1.10001
],
"8216": [
0,
0.69444,
0,
0,
0.30556
],
"8217": [
0,
0.69444,
0,
0,
0.30556
],
"8220": [
0,
0.69444,
0,
0,
0.55834
],
"8221": [
0,
0.69444,
0,
0,
0.55834
]
},
"SansSerif-Italic": {
"32": [
0,
0,
0,
0,
0.25
],
"33": [
0,
0.69444,
0.05733,
0,
0.31945
],
"34": [
0,
0.69444,
0.00316,
0,
0.5
],
"35": [
0.19444,
0.69444,
0.05087,
0,
0.83334
],
"36": [
0.05556,
0.75,
0.11156,
0,
0.5
],
"37": [
0.05556,
0.75,
0.03126,
0,
0.83334
],
"38": [
0,
0.69444,
0.03058,
0,
0.75834
],
"39": [
0,
0.69444,
0.07816,
0,
0.27778
],
"40": [
0.25,
0.75,
0.13164,
0,
0.38889
],
"41": [
0.25,
0.75,
0.02536,
0,
0.38889
],
"42": [
0,
0.75,
0.11775,
0,
0.5
],
"43": [
0.08333,
0.58333,
0.02536,
0,
0.77778
],
"44": [
0.125,
0.08333,
0,
0,
0.27778
],
"45": [
0,
0.44444,
0.01946,
0,
0.33333
],
"46": [
0,
0.08333,
0,
0,
0.27778
],
"47": [
0.25,
0.75,
0.13164,
0,
0.5
],
"48": [
0,
0.65556,
0.11156,
0,
0.5
],
"49": [
0,
0.65556,
0.11156,
0,
0.5
],
"50": [
0,
0.65556,
0.11156,
0,
0.5
],
"51": [
0,
0.65556,
0.11156,
0,
0.5
],
"52": [
0,
0.65556,
0.11156,
0,
0.5
],
"53": [
0,
0.65556,
0.11156,
0,
0.5
],
"54": [
0,
0.65556,
0.11156,
0,
0.5
],
"55": [
0,
0.65556,
0.11156,
0,
0.5
],
"56": [
0,
0.65556,
0.11156,
0,
0.5
],
"57": [
0,
0.65556,
0.11156,
0,
0.5
],
"58": [
0,
0.44444,
0.02502,
0,
0.27778
],
"59": [
0.125,
0.44444,
0.02502,
0,
0.27778
],
"61": [
-0.13,
0.37,
0.05087,
0,
0.77778
],
"63": [
0,
0.69444,
0.11809,
0,
0.47222
],
"64": [
0,
0.69444,
0.07555,
0,
0.66667
],
"65": [
0,
0.69444,
0,
0,
0.66667
],
"66": [
0,
0.69444,
0.08293,
0,
0.66667
],
"67": [
0,
0.69444,
0.11983,
0,
0.63889
],
"68": [
0,
0.69444,
0.07555,
0,
0.72223
],
"69": [
0,
0.69444,
0.11983,
0,
0.59722
],
"70": [
0,
0.69444,
0.13372,
0,
0.56945
],
"71": [
0,
0.69444,
0.11983,
0,
0.66667
],
"72": [
0,
0.69444,
0.08094,
0,
0.70834
],
"73": [
0,
0.69444,
0.13372,
0,
0.27778
],
"74": [
0,
0.69444,
0.08094,
0,
0.47222
],
"75": [
0,
0.69444,
0.11983,
0,
0.69445
],
"76": [
0,
0.69444,
0,
0,
0.54167
],
"77": [
0,
0.69444,
0.08094,
0,
0.875
],
"78": [
0,
0.69444,
0.08094,
0,
0.70834
],
"79": [
0,
0.69444,
0.07555,
0,
0.73611
],
"80": [
0,
0.69444,
0.08293,
0,
0.63889
],
"81": [
0.125,
0.69444,
0.07555,
0,
0.73611
],
"82": [
0,
0.69444,
0.08293,
0,
0.64584
],
"83": [
0,
0.69444,
0.09205,
0,
0.55556
],
"84": [
0,
0.69444,
0.13372,
0,
0.68056
],
"85": [
0,
0.69444,
0.08094,
0,
0.6875
],
"86": [
0,
0.69444,
0.1615,
0,
0.66667
],
"87": [
0,
0.69444,
0.1615,
0,
0.94445
],
"88": [
0,
0.69444,
0.13372,
0,
0.66667
],
"89": [
0,
0.69444,
0.17261,
0,
0.66667
],
"90": [
0,
0.69444,
0.11983,
0,
0.61111
],
"91": [
0.25,
0.75,
0.15942,
0,
0.28889
],
"93": [
0.25,
0.75,
0.08719,
0,
0.28889
],
"94": [
0,
0.69444,
0.0799,
0,
0.5
],
"95": [
0.35,
0.09444,
0.08616,
0,
0.5
],
"97": [
0,
0.44444,
0.00981,
0,
0.48056
],
"98": [
0,
0.69444,
0.03057,
0,
0.51667
],
"99": [
0,
0.44444,
0.08336,
0,
0.44445
],
"100": [
0,
0.69444,
0.09483,
0,
0.51667
],
"101": [
0,
0.44444,
0.06778,
0,
0.44445
],
"102": [
0,
0.69444,
0.21705,
0,
0.30556
],
"103": [
0.19444,
0.44444,
0.10836,
0,
0.5
],
"104": [
0,
0.69444,
0.01778,
0,
0.51667
],
"105": [
0,
0.67937,
0.09718,
0,
0.23889
],
"106": [
0.19444,
0.67937,
0.09162,
0,
0.26667
],
"107": [
0,
0.69444,
0.08336,
0,
0.48889
],
"108": [
0,
0.69444,
0.09483,
0,
0.23889
],
"109": [
0,
0.44444,
0.01778,
0,
0.79445
],
"110": [
0,
0.44444,
0.01778,
0,
0.51667
],
"111": [
0,
0.44444,
0.06613,
0,
0.5
],
"112": [
0.19444,
0.44444,
0.0389,
0,
0.51667
],
"113": [
0.19444,
0.44444,
0.04169,
0,
0.51667
],
"114": [
0,
0.44444,
0.10836,
0,
0.34167
],
"115": [
0,
0.44444,
0.0778,
0,
0.38333
],
"116": [
0,
0.57143,
0.07225,
0,
0.36111
],
"117": [
0,
0.44444,
0.04169,
0,
0.51667
],
"118": [
0,
0.44444,
0.10836,
0,
0.46111
],
"119": [
0,
0.44444,
0.10836,
0,
0.68334
],
"120": [
0,
0.44444,
0.09169,
0,
0.46111
],
"121": [
0.19444,
0.44444,
0.10836,
0,
0.46111
],
"122": [
0,
0.44444,
0.08752,
0,
0.43472
],
"126": [
0.35,
0.32659,
0.08826,
0,
0.5
],
"160": [
0,
0,
0,
0,
0.25
],
"168": [
0,
0.67937,
0.06385,
0,
0.5
],
"176": [
0,
0.69444,
0,
0,
0.73752
],
"184": [
0.17014,
0,
0,
0,
0.44445
],
"305": [
0,
0.44444,
0.04169,
0,
0.23889
],
"567": [
0.19444,
0.44444,
0.04169,
0,
0.26667
],
"710": [
0,
0.69444,
0.0799,
0,
0.5
],
"711": [
0,
0.63194,
0.08432,
0,
0.5
],
"713": [
0,
0.60889,
0.08776,
0,
0.5
],
"714": [
0,
0.69444,
0.09205,
0,
0.5
],
"715": [
0,
0.69444,
0,
0,
0.5
],
"728": [
0,
0.69444,
0.09483,
0,
0.5
],
"729": [
0,
0.67937,
0.07774,
0,
0.27778
],
"730": [
0,
0.69444,
0,
0,
0.73752
],
"732": [
0,
0.67659,
0.08826,
0,
0.5
],
"733": [
0,
0.69444,
0.09205,
0,
0.5
],
"915": [
0,
0.69444,
0.13372,
0,
0.54167
],
"916": [
0,
0.69444,
0,
0,
0.83334
],
"920": [
0,
0.69444,
0.07555,
0,
0.77778
],
"923": [
0,
0.69444,
0,
0,
0.61111
],
"926": [
0,
0.69444,
0.12816,
0,
0.66667
],
"928": [
0,
0.69444,
0.08094,
0,
0.70834
],
"931": [
0,
0.69444,
0.11983,
0,
0.72222
],
"933": [
0,
0.69444,
0.09031,
0,
0.77778
],
"934": [
0,
0.69444,
0.04603,
0,
0.72222
],
"936": [
0,
0.69444,
0.09031,
0,
0.77778
],
"937": [
0,
0.69444,
0.08293,
0,
0.72222
],
"8211": [
0,
0.44444,
0.08616,
0,
0.5
],
"8212": [
0,
0.44444,
0.08616,
0,
1.0
],
"8216": [
0,
0.69444,
0.07816,
0,
0.27778
],
"8217": [
0,
0.69444,
0.07816,
0,
0.27778
],
"8220": [
0,
0.69444,
0.14205,
0,
0.5
],
"8221": [
0,
0.69444,
0.00316,
0,
0.5
]
},
"SansSerif-Regular": {
"32": [
0,
0,
0,
0,
0.25
],
"33": [
0,
0.69444,
0,
0,
0.31945
],
"34": [
0,
0.69444,
0,
0,
0.5
],
"35": [
0.19444,
0.69444,
0,
0,
0.83334
],
"36": [
0.05556,
0.75,
0,
0,
0.5
],
"37": [
0.05556,
0.75,
0,
0,
0.83334
],
"38": [
0,
0.69444,
0,
0,
0.75834
],
"39": [
0,
0.69444,
0,
0,
0.27778
],
"40": [
0.25,
0.75,
0,
0,
0.38889
],
"41": [
0.25,
0.75,
0,
0,
0.38889
],
"42": [
0,
0.75,
0,
0,
0.5
],
"43": [
0.08333,
0.58333,
0,
0,
0.77778
],
"44": [
0.125,
0.08333,
0,
0,
0.27778
],
"45": [
0,
0.44444,
0,
0,
0.33333
],
"46": [
0,
0.08333,
0,
0,
0.27778
],
"47": [
0.25,
0.75,
0,
0,
0.5
],
"48": [
0,
0.65556,
0,
0,
0.5
],
"49": [
0,
0.65556,
0,
0,
0.5
],
"50": [
0,
0.65556,
0,
0,
0.5
],
"51": [
0,
0.65556,
0,
0,
0.5
],
"52": [
0,
0.65556,
0,
0,
0.5
],
"53": [
0,
0.65556,
0,
0,
0.5
],
"54": [
0,
0.65556,
0,
0,
0.5
],
"55": [
0,
0.65556,
0,
0,
0.5
],
"56": [
0,
0.65556,
0,
0,
0.5
],
"57": [
0,
0.65556,
0,
0,
0.5
],
"58": [
0,
0.44444,
0,
0,
0.27778
],
"59": [
0.125,
0.44444,
0,
0,
0.27778
],
"61": [
-0.13,
0.37,
0,
0,
0.77778
],
"63": [
0,
0.69444,
0,
0,
0.47222
],
"64": [
0,
0.69444,
0,
0,
0.66667
],
"65": [
0,
0.69444,
0,
0,
0.66667
],
"66": [
0,
0.69444,
0,
0,
0.66667
],
"67": [
0,
0.69444,
0,
0,
0.63889
],
"68": [
0,
0.69444,
0,
0,
0.72223
],
"69": [
0,
0.69444,
0,
0,
0.59722
],
"70": [
0,
0.69444,
0,
0,
0.56945
],
"71": [
0,
0.69444,
0,
0,
0.66667
],
"72": [
0,
0.69444,
0,
0,
0.70834
],
"73": [
0,
0.69444,
0,
0,
0.27778
],
"74": [
0,
0.69444,
0,
0,
0.47222
],
"75": [
0,
0.69444,
0,
0,
0.69445
],
"76": [
0,
0.69444,
0,
0,
0.54167
],
"77": [
0,
0.69444,
0,
0,
0.875
],
"78": [
0,
0.69444,
0,
0,
0.70834
],
"79": [
0,
0.69444,
0,
0,
0.73611
],
"80": [
0,
0.69444,
0,
0,
0.63889
],
"81": [
0.125,
0.69444,
0,
0,
0.73611
],
"82": [
0,
0.69444,
0,
0,
0.64584
],
"83": [
0,
0.69444,
0,
0,
0.55556
],
"84": [
0,
0.69444,
0,
0,
0.68056
],
"85": [
0,
0.69444,
0,
0,
0.6875
],
"86": [
0,
0.69444,
0.01389,
0,
0.66667
],
"87": [
0,
0.69444,
0.01389,
0,
0.94445
],
"88": [
0,
0.69444,
0,
0,
0.66667
],
"89": [
0,
0.69444,
0.025,
0,
0.66667
],
"90": [
0,
0.69444,
0,
0,
0.61111
],
"91": [
0.25,
0.75,
0,
0,
0.28889
],
"93": [
0.25,
0.75,
0,
0,
0.28889
],
"94": [
0,
0.69444,
0,
0,
0.5
],
"95": [
0.35,
0.09444,
0.02778,
0,
0.5
],
"97": [
0,
0.44444,
0,
0,
0.48056
],
"98": [
0,
0.69444,
0,
0,
0.51667
],
"99": [
0,
0.44444,
0,
0,
0.44445
],
"100": [
0,
0.69444,
0,
0,
0.51667
],
"101": [
0,
0.44444,
0,
0,
0.44445
],
"102": [
0,
0.69444,
0.06944,
0,
0.30556
],
"103": [
0.19444,
0.44444,
0.01389,
0,
0.5
],
"104": [
0,
0.69444,
0,
0,
0.51667
],
"105": [
0,
0.67937,
0,
0,
0.23889
],
"106": [
0.19444,
0.67937,
0,
0,
0.26667
],
"107": [
0,
0.69444,
0,
0,
0.48889
],
"108": [
0,
0.69444,
0,
0,
0.23889
],
"109": [
0,
0.44444,
0,
0,
0.79445
],
"110": [
0,
0.44444,
0,
0,
0.51667
],
"111": [
0,
0.44444,
0,
0,
0.5
],
"112": [
0.19444,
0.44444,
0,
0,
0.51667
],
"113": [
0.19444,
0.44444,
0,
0,
0.51667
],
"114": [
0,
0.44444,
0.01389,
0,
0.34167
],
"115": [
0,
0.44444,
0,
0,
0.38333
],
"116": [
0,
0.57143,
0,
0,
0.36111
],
"117": [
0,
0.44444,
0,
0,
0.51667
],
"118": [
0,
0.44444,
0.01389,
0,
0.46111
],
"119": [
0,
0.44444,
0.01389,
0,
0.68334
],
"120": [
0,
0.44444,
0,
0,
0.46111
],
"121": [
0.19444,
0.44444,
0.01389,
0,
0.46111
],
"122": [
0,
0.44444,
0,
0,
0.43472
],
"126": [
0.35,
0.32659,
0,
0,
0.5
],
"160": [
0,
0,
0,
0,
0.25
],
"168": [
0,
0.67937,
0,
0,
0.5
],
"176": [
0,
0.69444,
0,
0,
0.66667
],
"184": [
0.17014,
0,
0,
0,
0.44445
],
"305": [
0,
0.44444,
0,
0,
0.23889
],
"567": [
0.19444,
0.44444,
0,
0,
0.26667
],
"710": [
0,
0.69444,
0,
0,
0.5
],
"711": [
0,
0.63194,
0,
0,
0.5
],
"713": [
0,
0.60889,
0,
0,
0.5
],
"714": [
0,
0.69444,
0,
0,
0.5
],
"715": [
0,
0.69444,
0,
0,
0.5
],
"728": [
0,
0.69444,
0,
0,
0.5
],
"729": [
0,
0.67937,
0,
0,
0.27778
],
"730": [
0,
0.69444,
0,
0,
0.66667
],
"732": [
0,
0.67659,
0,
0,
0.5
],
"733": [
0,
0.69444,
0,
0,
0.5
],
"915": [
0,
0.69444,
0,
0,
0.54167
],
"916": [
0,
0.69444,
0,
0,
0.83334
],
"920": [
0,
0.69444,
0,
0,
0.77778
],
"923": [
0,
0.69444,
0,
0,
0.61111
],
"926": [
0,
0.69444,
0,
0,
0.66667
],
"928": [
0,
0.69444,
0,
0,
0.70834
],
"931": [
0,
0.69444,
0,
0,
0.72222
],
"933": [
0,
0.69444,
0,
0,
0.77778
],
"934": [
0,
0.69444,
0,
0,
0.72222
],
"936": [
0,
0.69444,
0,
0,
0.77778
],
"937": [
0,
0.69444,
0,
0,
0.72222
],
"8211": [
0,
0.44444,
0.02778,
0,
0.5
],
"8212": [
0,
0.44444,
0.02778,
0,
1.0
],
"8216": [
0,
0.69444,
0,
0,
0.27778
],
"8217": [
0,
0.69444,
0,
0,
0.27778
],
"8220": [
0,
0.69444,
0,
0,
0.5
],
"8221": [
0,
0.69444,
0,
0,
0.5
]
},
"Script-Regular": {
"32": [
0,
0,
0,
0,
0.25
],
"65": [
0,
0.7,
0.22925,
0,
0.80253
],
"66": [
0,
0.7,
0.04087,
0,
0.90757
],
"67": [
0,
0.7,
0.1689,
0,
0.66619
],
"68": [
0,
0.7,
0.09371,
0,
0.77443
],
"69": [
0,
0.7,
0.18583,
0,
0.56162
],
"70": [
0,
0.7,
0.13634,
0,
0.89544
],
"71": [
0,
0.7,
0.17322,
0,
0.60961
],
"72": [
0,
0.7,
0.29694,
0,
0.96919
],
"73": [
0,
0.7,
0.19189,
0,
0.80907
],
"74": [
0.27778,
0.7,
0.19189,
0,
1.05159
],
"75": [
0,
0.7,
0.31259,
0,
0.91364
],
"76": [
0,
0.7,
0.19189,
0,
0.87373
],
"77": [
0,
0.7,
0.15981,
0,
1.08031
],
"78": [
0,
0.7,
0.3525,
0,
0.9015
],
"79": [
0,
0.7,
0.08078,
0,
0.73787
],
"80": [
0,
0.7,
0.08078,
0,
1.01262
],
"81": [
0,
0.7,
0.03305,
0,
0.88282
],
"82": [
0,
0.7,
0.06259,
0,
0.85
],
"83": [
0,
0.7,
0.19189,
0,
0.86767
],
"84": [
0,
0.7,
0.29087,
0,
0.74697
],
"85": [
0,
0.7,
0.25815,
0,
0.79996
],
"86": [
0,
0.7,
0.27523,
0,
0.62204
],
"87": [
0,
0.7,
0.27523,
0,
0.80532
],
"88": [
0,
0.7,
0.26006,
0,
0.94445
],
"89": [
0,
0.7,
0.2939,
0,
0.70961
],
"90": [
0,
0.7,
0.24037,
0,
0.8212
],
"160": [
0,
0,
0,
0,
0.25
]
},
"Size1-Regular": {
"32": [
0,
0,
0,
0,
0.25
],
"40": [
0.35001,
0.85,
0,
0,
0.45834
],
"41": [
0.35001,
0.85,
0,
0,
0.45834
],
"47": [
0.35001,
0.85,
0,
0,
0.57778
],
"91": [
0.35001,
0.85,
0,
0,
0.41667
],
"92": [
0.35001,
0.85,
0,
0,
0.57778
],
"93": [
0.35001,
0.85,
0,
0,
0.41667
],
"123": [
0.35001,
0.85,
0,
0,
0.58334
],
"125": [
0.35001,
0.85,
0,
0,
0.58334
],
"160": [
0,
0,
0,
0,
0.25
],
"710": [
0,
0.72222,
0,
0,
0.55556
],
"732": [
0,
0.72222,
0,
0,
0.55556
],
"770": [
0,
0.72222,
0,
0,
0.55556
],
"771": [
0,
0.72222,
0,
0,
0.55556
],
"8214": [
-0.00099,
0.601,
0,
0,
0.77778
],
"8593": [
1e-05,
0.6,
0,
0,
0.66667
],
"8595": [
1e-05,
0.6,
0,
0,
0.66667
],
"8657": [
1e-05,
0.6,
0,
0,
0.77778
],
"8659": [
1e-05,
0.6,
0,
0,
0.77778
],
"8719": [
0.25001,
0.75,
0,
0,
0.94445
],
"8720": [
0.25001,
0.75,
0,
0,
0.94445
],
"8721": [
0.25001,
0.75,
0,
0,
1.05556
],
"8730": [
0.35001,
0.85,
0,
0,
1.0
],
"8739": [
-0.00599,
0.606,
0,
0,
0.33333
],
"8741": [
-0.00599,
0.606,
0,
0,
0.55556
],
"8747": [
0.30612,
0.805,
0.19445,
0,
0.47222
],
"8748": [
0.306,
0.805,
0.19445,
0,
0.47222
],
"8749": [
0.306,
0.805,
0.19445,
0,
0.47222
],
"8750": [
0.30612,
0.805,
0.19445,
0,
0.47222
],
"8896": [
0.25001,
0.75,
0,
0,
0.83334
],
"8897": [
0.25001,
0.75,
0,
0,
0.83334
],
"8898": [
0.25001,
0.75,
0,
0,
0.83334
],
"8899": [
0.25001,
0.75,
0,
0,
0.83334
],
"8968": [
0.35001,
0.85,
0,
0,
0.47222
],
"8969": [
0.35001,
0.85,
0,
0,
0.47222
],
"8970": [
0.35001,
0.85,
0,
0,
0.47222
],
"8971": [
0.35001,
0.85,
0,
0,
0.47222
],
"9168": [
-0.00099,
0.601,
0,
0,
0.66667
],
"10216": [
0.35001,
0.85,
0,
0,
0.47222
],
"10217": [
0.35001,
0.85,
0,
0,
0.47222
],
"10752": [
0.25001,
0.75,
0,
0,
1.11111
],
"10753": [
0.25001,
0.75,
0,
0,
1.11111
],
"10754": [
0.25001,
0.75,
0,
0,
1.11111
],
"10756": [
0.25001,
0.75,
0,
0,
0.83334
],
"10758": [
0.25001,
0.75,
0,
0,
0.83334
]
},
"Size2-Regular": {
"32": [
0,
0,
0,
0,
0.25
],
"40": [
0.65002,
1.15,
0,
0,
0.59722
],
"41": [
0.65002,
1.15,
0,
0,
0.59722
],
"47": [
0.65002,
1.15,
0,
0,
0.81111
],
"91": [
0.65002,
1.15,
0,
0,
0.47222
],
"92": [
0.65002,
1.15,
0,
0,
0.81111
],
"93": [
0.65002,
1.15,
0,
0,
0.47222
],
"123": [
0.65002,
1.15,
0,
0,
0.66667
],
"125": [
0.65002,
1.15,
0,
0,
0.66667
],
"160": [
0,
0,
0,
0,
0.25
],
"710": [
0,
0.75,
0,
0,
1.0
],
"732": [
0,
0.75,
0,
0,
1.0
],
"770": [
0,
0.75,
0,
0,
1.0
],
"771": [
0,
0.75,
0,
0,
1.0
],
"8719": [
0.55001,
1.05,
0,
0,
1.27778
],
"8720": [
0.55001,
1.05,
0,
0,
1.27778
],
"8721": [
0.55001,
1.05,
0,
0,
1.44445
],
"8730": [
0.65002,
1.15,
0,
0,
1.0
],
"8747": [
0.86225,
1.36,
0.44445,
0,
0.55556
],
"8748": [
0.862,
1.36,
0.44445,
0,
0.55556
],
"8749": [
0.862,
1.36,
0.44445,
0,
0.55556
],
"8750": [
0.86225,
1.36,
0.44445,
0,
0.55556
],
"8896": [
0.55001,
1.05,
0,
0,
1.11111
],
"8897": [
0.55001,
1.05,
0,
0,
1.11111
],
"8898": [
0.55001,
1.05,
0,
0,
1.11111
],
"8899": [
0.55001,
1.05,
0,
0,
1.11111
],
"8968": [
0.65002,
1.15,
0,
0,
0.52778
],
"8969": [
0.65002,
1.15,
0,
0,
0.52778
],
"8970": [
0.65002,
1.15,
0,
0,
0.52778
],
"8971": [
0.65002,
1.15,
0,
0,
0.52778
],
"10216": [
0.65002,
1.15,
0,
0,
0.61111
],
"10217": [
0.65002,
1.15,
0,
0,
0.61111
],
"10752": [
0.55001,
1.05,
0,
0,
1.51112
],
"10753": [
0.55001,
1.05,
0,
0,
1.51112
],
"10754": [
0.55001,
1.05,
0,
0,
1.51112
],
"10756": [
0.55001,
1.05,
0,
0,
1.11111
],
"10758": [
0.55001,
1.05,
0,
0,
1.11111
]
},
"Size3-Regular": {
"32": [
0,
0,
0,
0,
0.25
],
"40": [
0.95003,
1.45,
0,
0,
0.73611
],
"41": [
0.95003,
1.45,
0,
0,
0.73611
],
"47": [
0.95003,
1.45,
0,
0,
1.04445
],
"91": [
0.95003,
1.45,
0,
0,
0.52778
],
"92": [
0.95003,
1.45,
0,
0,
1.04445
],
"93": [
0.95003,
1.45,
0,
0,
0.52778
],
"123": [
0.95003,
1.45,
0,
0,
0.75
],
"125": [
0.95003,
1.45,
0,
0,
0.75
],
"160": [
0,
0,
0,
0,
0.25
],
"710": [
0,
0.75,
0,
0,
1.44445
],
"732": [
0,
0.75,
0,
0,
1.44445
],
"770": [
0,
0.75,
0,
0,
1.44445
],
"771": [
0,
0.75,
0,
0,
1.44445
],
"8730": [
0.95003,
1.45,
0,
0,
1.0
],
"8968": [
0.95003,
1.45,
0,
0,
0.58334
],
"8969": [
0.95003,
1.45,
0,
0,
0.58334
],
"8970": [
0.95003,
1.45,
0,
0,
0.58334
],
"8971": [
0.95003,
1.45,
0,
0,
0.58334
],
"10216": [
0.95003,
1.45,
0,
0,
0.75
],
"10217": [
0.95003,
1.45,
0,
0,
0.75
]
},
"Size4-Regular": {
"32": [
0,
0,
0,
0,
0.25
],
"40": [
1.25003,
1.75,
0,
0,
0.79167
],
"41": [
1.25003,
1.75,
0,
0,
0.79167
],
"47": [
1.25003,
1.75,
0,
0,
1.27778
],
"91": [
1.25003,
1.75,
0,
0,
0.58334
],
"92": [
1.25003,
1.75,
0,
0,
1.27778
],
"93": [
1.25003,
1.75,
0,
0,
0.58334
],
"123": [
1.25003,
1.75,
0,
0,
0.80556
],
"125": [
1.25003,
1.75,
0,
0,
0.80556
],
"160": [
0,
0,
0,
0,
0.25
],
"710": [
0,
0.825,
0,
0,
1.8889
],
"732": [
0,
0.825,
0,
0,
1.8889
],
"770": [
0,
0.825,
0,
0,
1.8889
],
"771": [
0,
0.825,
0,
0,
1.8889
],
"8730": [
1.25003,
1.75,
0,
0,
1.0
],
"8968": [
1.25003,
1.75,
0,
0,
0.63889
],
"8969": [
1.25003,
1.75,
0,
0,
0.63889
],
"8970": [
1.25003,
1.75,
0,
0,
0.63889
],
"8971": [
1.25003,
1.75,
0,
0,
0.63889
],
"9115": [
0.64502,
1.155,
0,
0,
0.875
],
"9116": [
1e-05,
0.6,
0,
0,
0.875
],
"9117": [
0.64502,
1.155,
0,
0,
0.875
],
"9118": [
0.64502,
1.155,
0,
0,
0.875
],
"9119": [
1e-05,
0.6,
0,
0,
0.875
],
"9120": [
0.64502,
1.155,
0,
0,
0.875
],
"9121": [
0.64502,
1.155,
0,
0,
0.66667
],
"9122": [
-0.00099,
0.601,
0,
0,
0.66667
],
"9123": [
0.64502,
1.155,
0,
0,
0.66667
],
"9124": [
0.64502,
1.155,
0,
0,
0.66667
],
"9125": [
-0.00099,
0.601,
0,
0,
0.66667
],
"9126": [
0.64502,
1.155,
0,
0,
0.66667
],
"9127": [
1e-05,
0.9,
0,
0,
0.88889
],
"9128": [
0.65002,
1.15,
0,
0,
0.88889
],
"9129": [
0.90001,
0,
0,
0,
0.88889
],
"9130": [
0,
0.3,
0,
0,
0.88889
],
"9131": [
1e-05,
0.9,
0,
0,
0.88889
],
"9132": [
0.65002,
1.15,
0,
0,
0.88889
],
"9133": [
0.90001,
0,
0,
0,
0.88889
],
"9143": [
0.88502,
0.915,
0,
0,
1.05556
],
"10216": [
1.25003,
1.75,
0,
0,
0.80556
],
"10217": [
1.25003,
1.75,
0,
0,
0.80556
],
"57344": [
-0.00499,
0.605,
0,
0,
1.05556
],
"57345": [
-0.00499,
0.605,
0,
0,
1.05556
],
"57680": [
0,
0.12,
0,
0,
0.45
],
"57681": [
0,
0.12,
0,
0,
0.45
],
"57682": [
0,
0.12,
0,
0,
0.45
],
"57683": [
0,
0.12,
0,
0,
0.45
]
},
"Typewriter-Regular": {
"32": [
0,
0,
0,
0,
0.525
],
"33": [
0,
0.61111,
0,
0,
0.525
],
"34": [
0,
0.61111,
0,
0,
0.525
],
"35": [
0,
0.61111,
0,
0,
0.525
],
"36": [
0.08333,
0.69444,
0,
0,
0.525
],
"37": [
0.08333,
0.69444,
0,
0,
0.525
],
"38": [
0,
0.61111,
0,
0,
0.525
],
"39": [
0,
0.61111,
0,
0,
0.525
],
"40": [
0.08333,
0.69444,
0,
0,
0.525
],
"41": [
0.08333,
0.69444,
0,
0,
0.525
],
"42": [
0,
0.52083,
0,
0,
0.525
],
"43": [
-0.08056,
0.53055,
0,
0,
0.525
],
"44": [
0.13889,
0.125,
0,
0,
0.525
],
"45": [
-0.08056,
0.53055,
0,
0,
0.525
],
"46": [
0,
0.125,
0,
0,
0.525
],
"47": [
0.08333,
0.69444,
0,
0,
0.525
],
"48": [
0,
0.61111,
0,
0,
0.525
],
"49": [
0,
0.61111,
0,
0,
0.525
],
"50": [
0,
0.61111,
0,
0,
0.525
],
"51": [
0,
0.61111,
0,
0,
0.525
],
"52": [
0,
0.61111,
0,
0,
0.525
],
"53": [
0,
0.61111,
0,
0,
0.525
],
"54": [
0,
0.61111,
0,
0,
0.525
],
"55": [
0,
0.61111,
0,
0,
0.525
],
"56": [
0,
0.61111,
0,
0,
0.525
],
"57": [
0,
0.61111,
0,
0,
0.525
],
"58": [
0,
0.43056,
0,
0,
0.525
],
"59": [
0.13889,
0.43056,
0,
0,
0.525
],
"60": [
-0.05556,
0.55556,
0,
0,
0.525
],
"61": [
-0.19549,
0.41562,
0,
0,
0.525
],
"62": [
-0.05556,
0.55556,
0,
0,
0.525
],
"63": [
0,
0.61111,
0,
0,
0.525
],
"64": [
0,
0.61111,
0,
0,
0.525
],
"65": [
0,
0.61111,
0,
0,
0.525
],
"66": [
0,
0.61111,
0,
0,
0.525
],
"67": [
0,
0.61111,
0,
0,
0.525
],
"68": [
0,
0.61111,
0,
0,
0.525
],
"69": [
0,
0.61111,
0,
0,
0.525
],
"70": [
0,
0.61111,
0,
0,
0.525
],
"71": [
0,
0.61111,
0,
0,
0.525
],
"72": [
0,
0.61111,
0,
0,
0.525
],
"73": [
0,
0.61111,
0,
0,
0.525
],
"74": [
0,
0.61111,
0,
0,
0.525
],
"75": [
0,
0.61111,
0,
0,
0.525
],
"76": [
0,
0.61111,
0,
0,
0.525
],
"77": [
0,
0.61111,
0,
0,
0.525
],
"78": [
0,
0.61111,
0,
0,
0.525
],
"79": [
0,
0.61111,
0,
0,
0.525
],
"80": [
0,
0.61111,
0,
0,
0.525
],
"81": [
0.13889,
0.61111,
0,
0,
0.525
],
"82": [
0,
0.61111,
0,
0,
0.525
],
"83": [
0,
0.61111,
0,
0,
0.525
],
"84": [
0,
0.61111,
0,
0,
0.525
],
"85": [
0,
0.61111,
0,
0,
0.525
],
"86": [
0,
0.61111,
0,
0,
0.525
],
"87": [
0,
0.61111,
0,
0,
0.525
],
"88": [
0,
0.61111,
0,
0,
0.525
],
"89": [
0,
0.61111,
0,
0,
0.525
],
"90": [
0,
0.61111,
0,
0,
0.525
],
"91": [
0.08333,
0.69444,
0,
0,
0.525
],
"92": [
0.08333,
0.69444,
0,
0,
0.525
],
"93": [
0.08333,
0.69444,
0,
0,
0.525
],
"94": [
0,
0.61111,
0,
0,
0.525
],
"95": [
0.09514,
0,
0,
0,
0.525
],
"96": [
0,
0.61111,
0,
0,
0.525
],
"97": [
0,
0.43056,
0,
0,
0.525
],
"98": [
0,
0.61111,
0,
0,
0.525
],
"99": [
0,
0.43056,
0,
0,
0.525
],
"100": [
0,
0.61111,
0,
0,
0.525
],
"101": [
0,
0.43056,
0,
0,
0.525
],
"102": [
0,
0.61111,
0,
0,
0.525
],
"103": [
0.22222,
0.43056,
0,
0,
0.525
],
"104": [
0,
0.61111,
0,
0,
0.525
],
"105": [
0,
0.61111,
0,
0,
0.525
],
"106": [
0.22222,
0.61111,
0,
0,
0.525
],
"107": [
0,
0.61111,
0,
0,
0.525
],
"108": [
0,
0.61111,
0,
0,
0.525
],
"109": [
0,
0.43056,
0,
0,
0.525
],
"110": [
0,
0.43056,
0,
0,
0.525
],
"111": [
0,
0.43056,
0,
0,
0.525
],
"112": [
0.22222,
0.43056,
0,
0,
0.525
],
"113": [
0.22222,
0.43056,
0,
0,
0.525
],
"114": [
0,
0.43056,
0,
0,
0.525
],
"115": [
0,
0.43056,
0,
0,
0.525
],
"116": [
0,
0.55358,
0,
0,
0.525
],
"117": [
0,
0.43056,
0,
0,
0.525
],
"118": [
0,
0.43056,
0,
0,
0.525
],
"119": [
0,
0.43056,
0,
0,
0.525
],
"120": [
0,
0.43056,
0,
0,
0.525
],
"121": [
0.22222,
0.43056,
0,
0,
0.525
],
"122": [
0,
0.43056,
0,
0,
0.525
],
"123": [
0.08333,
0.69444,
0,
0,
0.525
],
"124": [
0.08333,
0.69444,
0,
0,
0.525
],
"125": [
0.08333,
0.69444,
0,
0,
0.525
],
"126": [
0,
0.61111,
0,
0,
0.525
],
"127": [
0,
0.61111,
0,
0,
0.525
],
"160": [
0,
0,
0,
0,
0.525
],
"176": [
0,
0.61111,
0,
0,
0.525
],
"184": [
0.19445,
0,
0,
0,
0.525
],
"305": [
0,
0.43056,
0,
0,
0.525
],
"567": [
0.22222,
0.43056,
0,
0,
0.525
],
"711": [
0,
0.56597,
0,
0,
0.525
],
"713": [
0,
0.56555,
0,
0,
0.525
],
"714": [
0,
0.61111,
0,
0,
0.525
],
"715": [
0,
0.61111,
0,
0,
0.525
],
"728": [
0,
0.61111,
0,
0,
0.525
],
"730": [
0,
0.61111,
0,
0,
0.525
],
"770": [
0,
0.61111,
0,
0,
0.525
],
"771": [
0,
0.61111,
0,
0,
0.525
],
"776": [
0,
0.61111,
0,
0,
0.525
],
"915": [
0,
0.61111,
0,
0,
0.525
],
"916": [
0,
0.61111,
0,
0,
0.525
],
"920": [
0,
0.61111,
0,
0,
0.525
],
"923": [
0,
0.61111,
0,
0,
0.525
],
"926": [
0,
0.61111,
0,
0,
0.525
],
"928": [
0,
0.61111,
0,
0,
0.525
],
"931": [
0,
0.61111,
0,
0,
0.525
],
"933": [
0,
0.61111,
0,
0,
0.525
],
"934": [
0,
0.61111,
0,
0,
0.525
],
"936": [
0,
0.61111,
0,
0,
0.525
],
"937": [
0,
0.61111,
0,
0,
0.525
],
"8216": [
0,
0.61111,
0,
0,
0.525
],
"8217": [
0,
0.61111,
0,
0,
0.525
],
"8242": [
0,
0.61111,
0,
0,
0.525
],
"9251": [
0.11111,
0.21944,
0,
0,
0.525
]
}
};
/**
* 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.
var 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.less; 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
// 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.
var 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'
};
/**
* This function adds new font metrics to default metricMap
* It can also override existing metrics
*/ function setFontMetrics(fontName, metrics) {
fontMetricsData[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`.
*/ function getCharacterMetrics(character, font, mode) {
if (!fontMetricsData[font]) throw new Error("Font metrics not found for font: " + font + ".");
var ch = character.charCodeAt(0);
var metrics = fontMetricsData[font][ch];
if (!metrics && character[0] in extraCharacterMap) {
ch = extraCharacterMap[character[0]].charCodeAt(0);
metrics = fontMetricsData[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 = fontMetricsData[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]
};
}
var fontMetricsBySizeIndex = {};
/**
* Get the font metrics for a given size.
*/ function getGlobalMetrics(size) {
var sizeIndex;
if (size >= 5) sizeIndex = 0;
else if (size >= 3) sizeIndex = 1;
else sizeIndex = 2;
if (!fontMetricsBySizeIndex[sizeIndex]) {
var metrics = fontMetricsBySizeIndex[sizeIndex] = {
cssEmPerMu: sigmasAndXis.quad[sizeIndex] / 18
};
for(var key in sigmasAndXis)if (sigmasAndXis.hasOwnProperty(key)) metrics[key] = sigmasAndXis[key][sizeIndex];
}
return fontMetricsBySizeIndex[sizeIndex];
}
/**
* 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.
*/ var sizeStyleMap = [
// The size mappings are taken from TeX with \normalsize=10pt.
[
1,
1,
1
],
[
2,
1,
1
],
[
3,
1,
1
],
[
4,
2,
1
],
[
5,
2,
1
],
[
6,
3,
1
],
[
7,
4,
2
],
[
8,
6,
3
],
[
9,
7,
6
],
[
10,
8,
7
],
[
11,
10,
9
] // size11: [24.88, 20.74, 17.28] \HUGE
];
var sizeMultipliers = [
// 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
];
var sizeAtStyle = function sizeAtStyle(size, style) {
return style.size < 2 ? size : sizeStyleMap[size - 1][style.size - 1];
}; // In these types, "" (empty string) means "no change".
/**
* 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 {
// 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
/**
* The base size index.
*/ constructor(data){
this.style = void 0;
this.color = void 0;
this.size = void 0;
this.textSize = void 0;
this.phantom = void 0;
this.font = void 0;
this.fontFamily = void 0;
this.fontWeight = void 0;
this.fontShape = void 0;
this.sizeMultiplier = void 0;
this.maxSize = void 0;
this.minRuleThickness = void 0;
this._fontMetrics = void 0;
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) {
var 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(var 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) {
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() {
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) {
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) {
style = style || this.style.text();
var 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() {
var 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;
}
return this.extend({
style: this.style.text(),
size: size
});
}
/**
* Create a new options object with the given color.
*/ withColor(color) {
return this.extend({
color: color
});
}
/**
* Create a new options object with "phantom" set to true.
*/ withPhantom() {
return this.extend({
phantom: true
});
}
/**
* Creates a new options object with the given math font or old text font.
* @type {[type]}
*/ withFont(font) {
return this.extend({
font
});
}
/**
* Create a new options objects with the given fontFamily.
*/ withTextFontFamily(fontFamily) {
return this.extend({
fontFamily,
font: ""
});
}
/**
* Creates a new options object with the given font weight
*/ withTextFontWeight(fontWeight) {
return this.extend({
fontWeight,
font: ""
});
}
/**
* Creates a new options object with the given font weight
*/ withTextFontShape(fontShape) {
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) {
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() {
if (this.size !== Options.BASESIZE) return [
"sizing",
"reset-size" + this.size,
"size" + Options.BASESIZE
];
else return [];
}
/**
* Return the font metrics for this size.
*/ fontMetrics() {
if (!this._fontMetrics) this._fontMetrics = getGlobalMetrics(this.size);
return this._fontMetrics;
}
/**
* Gets the CSS color of the current options object
*/ getColor() {
if (this.phantom) return "transparent";
else return this.color;
}
}
Options.BASESIZE = 6;
/**
* This file does conversion between units. In particular, it provides
* calculateSize to convert other units into ems.
*/ // Thus, multiplying a length by this number converts the length from units
// into pts. Dividing the result by ptPerEm gives the number of ems
// *assuming* a font size of ptPerEm (normal size, normal style).
var ptPerUnit = {
// https://en.wikibooks.org/wiki/LaTeX/Lengths and
// https://tex.stackexchange.com/a/8263
"pt": 1,
// TeX point
"mm": 7227 / 2540,
// millimeter
"cm": 7227 / 254,
// centimeter
"in": 72.27,
// inch
"bp": 1.00375,
// big (PostScript) points
"pc": 12,
// pica
"dd": 1238 / 1157,
// didot
"cc": 14856 / 1157,
// cicero (12 didot)
"nd": 685 / 642,
// new didot
"nc": 1370 / 107,
// new cicero (12 new didot)
"sp": 1 / 65536,
// scaled point (TeX's internal smallest unit)
// https://tex.stackexchange.com/a/41371
"px": 1.00375 // \pdfpxdimen defaults to 1 bp in pdfTeX and LuaTeX
}; // Dictionary of relative units, for fast validity testing.
var relativeUnit = {
"ex": true,
"em": true,
"mu": true
};
/**
* Determine whether the specified unit (either a string defining the unit
* or a "size" parse node containing a unit field) is valid.
*/ var validUnit = function validUnit(unit) {
if (typeof unit !== "string") unit = unit.unit;
return unit in ptPerUnit || unit in relativeUnit || unit === "ex";
};
/*
* Convert a "size" parse node (with numeric "number" and string "unit" fields,
* as parsed by functions.js argType "size") into a CSS em value for the
* current style/scale. `options` gives the current options.
*/ var calculateSize = function calculateSize(sizeValue, options) {
var scale;
if (sizeValue.unit in ptPerUnit) // Absolute units
scale = ptPerUnit[sizeValue.unit] // Convert unit to pt
/ options.fontMetrics().ptPerEm // Convert pt to CSS em
/ options.sizeMultiplier; // Unscale to make absolute units
else if (sizeValue.unit === "mu") // `mu` units scale with scriptstyle/scriptscriptstyle.
scale = options.fontMetrics().cssEmPerMu;
else {
// Other relative units always refer to the *textstyle* font
// in the current size.
var unitOptions;
if (options.style.isTight()) // isTight() means current style is script/scriptscript.
unitOptions = options.havingStyle(options.style.text());
else unitOptions = options;
// TODO: In TeX these units are relative to the quad of the current
// *text* font, e.g. cmr10. KaTeX instead uses values from the
// comparably-sized *Computer Modern symbol* font. At 10pt, these
// match. At 7pt and 5pt, they differ: cmr7=1.138894, cmsy7=1.170641;
// cmr5=1.361133, cmsy5=1.472241. Consider $\scriptsize a\kern1emb$.
// TeX \showlists shows a kern of 1.13889 * fontsize;
// KaTeX shows a kern of 1.171 * fontsize.
if (sizeValue.unit === "ex") scale = unitOptions.fontMetrics().xHeight;
else if (sizeValue.unit === "em") scale = unitOptions.fontMetrics().quad;
else throw new ParseError("Invalid unit: '" + sizeValue.unit + "'");
if (unitOptions !== options) scale *= unitOptions.sizeMultiplier / options.sizeMultiplier;
}
return Math.min(sizeValue.number * scale, options.maxSize);
};
/**
* Round `n` to 4 decimal places, or to the nearest 1/10,000th em. See
* https://github.com/KaTeX/KaTeX/pull/2460.
*/ var makeEm = function makeEm(n) {
return +n.toFixed(4) + "em";
};
/**
* 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
*/ /**
* Create an HTML className based on a list of classes. In addition to joining
* with spaces, we also remove empty classes.
*/ var createClass = function createClass(classes) {
return classes.filter((cls)=>cls).join(" ");
};
var initNode = function initNode(classes, options, style) {
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");
var color = options.getColor();
if (color) this.style.color = color;
}
};
/**
* Convert into an HTML node
*/ var toNode = function toNode(tagName) {
var node = document.createElement(tagName); // Apply the class
node.className = createClass(this.classes); // Apply inline styles
for(var 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(var attr in this.attributes)if (this.attributes.hasOwnProperty(attr)) node.setAttribute(attr, this.attributes[attr]);
// Append the children, also as HTML nodes
for(var i = 0; i < this.children.length; i++)node.appendChild(this.children[i].toNode());
return node;
};
/**
* Convert into an HTML markup string
*/ var toMarkup = function toMarkup(tagName) {
var markup = "<" + tagName; // Add the class
if (this.classes.length) markup += " class=\"" + utils.escape(createClass(this.classes)) + "\"";
var styles = ""; // Add the styles, after hyphenation
for(var 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(var attr in this.attributes)if (this.attributes.hasOwnProperty(attr)) markup += " " + attr + "=\"" + utils.escape(this.attributes[attr]) + "\"";
markup += ">"; // Add the markup of the children, also as markup
for(var 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.
/**
* 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.
*/ class Span {
constructor(classes, children, options, style){
this.children = void 0;
this.attributes = void 0;
this.classes = void 0;
this.height = void 0;
this.depth = void 0;
this.width = void 0;
this.maxFontSize = void 0;
this.style = void 0;
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, value) {
this.attributes[attribute] = value;
}
hasClass(className) {
return utils.contains(this.classes, className);
}
toNode() {
return toNode.call(this, "span");
}
toMarkup() {
return toMarkup.call(this, "span");
}
}
/**
* This node represents an anchor (<a>) element with a hyperlink. See `span`
* for further details.
*/ class Anchor {
constructor(href, classes, children, options){
this.children = void 0;
this.attributes = void 0;
this.classes = void 0;
this.height = void 0;
this.depth = void 0;
this.maxFontSize = void 0;
this.style = void 0;
initNode.call(this, classes, options);
this.children = children || [];
this.setAttribute('href', href);
}
setAttribute(attribute, value) {
this.attributes[attribute] = value;
}
hasClass(className) {
return utils.contains(this.classes, className);
}
toNode() {
return toNode.call(this, "a");
}
toMarkup() {
return toMarkup.call(this, "a");
}
}
/**
* This node represents an image embed (<img>) element.
*/ class Img {
constructor(src, alt, style){
this.src = void 0;
this.alt = void 0;
this.classes = void 0;
this.height = void 0;
this.depth = void 0;
this.maxFontSize = void 0;
this.style = void 0;
this.alt = alt;
this.src = src;
this.classes = [
"mord"
];
this.style = style;
}
hasClass(className) {
return utils.contains(this.classes, className);
}
toNode() {
var node = document.createElement("img");
node.src = this.src;
node.alt = this.alt;
node.className = "mord"; // Apply inline styles
for(var style in this.style)if (this.style.hasOwnProperty(style)) // $FlowFixMe
node.style[style] = this.style[style];
return node;
}
toMarkup() {
var markup = "<img src='" + this.src + " 'alt='" + this.alt + "' "; // Add the styles, after hyphenation
var styles = "";
for(var 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;
}
}
var 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.
*/ class SymbolNode {
constructor(text, height, depth, italic, skew, width, classes, style){
this.text = void 0;
this.height = void 0;
this.depth = void 0;
this.italic = void 0;
this.skew = void 0;
this.width = void 0;
this.maxFontSize = void 0;
this.classes = void 0;
this.style = void 0;
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
var 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) {
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() {
var node = document.createTextNode(this.text);
var 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(var 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() {
// TODO(alpert): More duplication than I'd like from
// span.prototype.toMarkup and symbolNode.prototype.toNode...
var needsSpan = false;
var markup = "<span";
if (this.classes.length) {
needsSpan = true;
markup += " class=\"";
markup += utils.escape(createClass(this.classes));
markup += "\"";
}
var styles = "";
if (this.italic > 0) styles += "margin-right:" + this.italic + "em;";
for(var 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) + "\"";
}
var 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.
*/ class SvgNode {
constructor(children, attributes){
this.children = void 0;
this.attributes = void 0;
this.children = children || [];
this.attributes = attributes || {};
}
toNode() {
var svgNS = "http://www.w3.org/2000/svg";
var node = document.createElementNS(svgNS, "svg"); // Apply attributes
for(var attr in this.attributes)if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) node.setAttribute(attr, this.attributes[attr]);
for(var i = 0; i < this.children.length; i++)node.appendChild(this.children[i].toNode());
return node;
}
toMarkup() {
var markup = "<svg xmlns=\"http://www.w3.org/2000/svg\""; // Apply attributes
for(var attr in this.attributes)if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) markup += " " + attr + "='" + this.attributes[attr] + "'";
markup += ">";
for(var i = 0; i < this.children.length; i++)markup += this.children[i].toMarkup();
markup += "</svg>";
return markup;
}
}
class PathNode {
constructor(pathName, alternate){
this.pathName = void 0;
this.alternate = void 0;
this.pathName = pathName;
this.alternate = alternate; // Used only for \sqrt, \phase, & tall delims
}
toNode() {
var svgNS = "http://www.w3.org/2000/svg";
var node = document.createElementNS(svgNS, "path");
if (this.alternate) node.setAttribute("d", this.alternate);
else node.setAttribute("d", path[this.pathName]);
return node;
}
toMarkup() {
if (this.alternate) return "<path d='" + this.alternate + "'/>";
else return "<path d='" + path[this.pathName] + "'/>";
}
}
class LineNode {
constructor(attributes){
this.attributes = void 0;
this.attributes = attributes || {};
}
toNode() {
var svgNS = "http://www.w3.org/2000/svg";
var node = document.createElementNS(svgNS, "line"); // Apply attributes
for(var attr in this.attributes)if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) node.setAttribute(attr, this.attributes[attr]);
return node;
}
toMarkup() {
var markup = "<line";
for(var attr in this.attributes)if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) markup += " " + attr + "='" + this.attributes[attr] + "'";
markup += "/>";
return markup;
}
}
function assertSymbolDomNode(group) {
if (group instanceof SymbolNode) return group;
else throw new Error("Expected symbolNode but got " + String(group) + ".");
}
function assertSpan(group) {
if (group instanceof Span) return group;
else throw new Error("Expected span<HtmlDomNode> but got " + String(group) + ".");
}
/**
* 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").
*/ // 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.
var ATOMS = {
"bin": 1,
"close": 1,
"inner": 1,
"open": 1,
"punct": 1,
"rel": 1
};
var NON_ATOMS = {
"accent-token": 1,
"mathord": 1,
"op-token": 1,
"spacing": 1,
"textord": 1
};
var symbols = {
"math": {},
"text": {}
};
/** `acceptUnicodeChar = true` is only applicable if `replace` is set. */ function defineSymbol(mode, font, group, replace, name, acceptUnicodeChar) {
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:
var math = "math";
var text = "text"; // fonts:
var main = "main";
var ams = "ams"; // groups:
var accent = "accent-token";
var bin = "bin";
var close = "close";
var inner = "inner";
var mathord = "mathord";
var op = "op-token";
var open = "open";
var punct = "punct";
var rel = "rel";
var spacing = "spacing";
var 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 preceeded 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);
defineSymbol(math, main, textord, "\u22ee", "\\varvdots"); // \vdots is a macro
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", '\\"'); // diaresis
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`.
var 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
var mathTextSymbols = "0123456789/@.\"";
for(var i = 0; i < mathTextSymbols.length; i++){
var ch = mathTextSymbols.charAt(i);
defineSymbol(math, main, textord, ch, ch);
} // All of these are textords in text mode
var textSymbols = "0123456789!@*()-=+\";:?/.,";
for(var _i = 0; _i < textSymbols.length; _i++){
var _ch = textSymbols.charAt(_i);
defineSymbol(text, main, textord, _ch, _ch);
} // All of these are textords in text mode, and mathords in math mode
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for(var _i2 = 0; _i2 < letters.length; _i2++){
var _ch2 = letters.charAt(_i2);
defineSymbol(math, main, mathord, _ch2, _ch2);
defineSymbol(text, main, textord, _ch2, _ch2);
} // 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.
var wideChar = "";
for(var _i3 = 0; _i3 < letters.length; _i3++){
var _ch3 = letters.charAt(_i3); // 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 + _i3); // A-Z a-z bold
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDC34 + _i3); // A-Z a-z italic
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDC68 + _i3); // A-Z a-z bold italic
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDD04 + _i3); // A-Z a-z Fractur
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDD6C + _i3); // A-Z a-z bold Fractur
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDDA0 + _i3); // A-Z a-z sans-serif
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDDD4 + _i3); // A-Z a-z sans bold
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDE08 + _i3); // A-Z a-z sans italic
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDE70 + _i3); // A-Z a-z monospace
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
if (_i3 < 26) {
// KaTeX fonts have only capital letters for blackboard bold and script.
// See exception for k below.
wideChar = String.fromCharCode(0xD835, 0xDD38 + _i3); // A-Z double struck
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDC9C + _i3); // A-Z script
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, 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(var _i4 = 0; _i4 < 10; _i4++){
var _ch4 = _i4.toString();
wideChar = String.fromCharCode(0xD835, 0xDFCE + _i4); // 0-9 bold
defineSymbol(math, main, mathord, _ch4, wideChar);
defineSymbol(text, main, textord, _ch4, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDFE2 + _i4); // 0-9 sans serif
defineSymbol(math, main, mathord, _ch4, wideChar);
defineSymbol(text, main, textord, _ch4, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDFEC + _i4); // 0-9 bold sans
defineSymbol(math, main, mathord, _ch4, wideChar);
defineSymbol(text, main, textord, _ch4, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDFF6 + _i4); // 0-9 monospace
defineSymbol(math, main, mathord, _ch4, wideChar);
defineSymbol(text, main, textord, _ch4, 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.
var extraLatin = "\u00d0\u00de\u00fe";
for(var _i5 = 0; _i5 < extraLatin.length; _i5++){
var _ch5 = extraLatin.charAt(_i5);
defineSymbol(math, main, mathord, _ch5, _ch5);
defineSymbol(text, main, textord, _ch5, _ch5);
}
/**
* This file provides support for Unicode range U+1D400 to U+1D7FF,
* Mathematical Alphanumeric Symbols.
*
* Function wideCharacterFont takes a wide character as input and returns
* the font information necessary to render it properly.
*/ /**
* Data below is from https://www.unicode.org/charts/PDF/U1D400.pdf
* That document sorts characters into groups by font type, say bold or italic.
*
* In the arrays below, each subarray consists three elements:
* * The CSS class of that group when in math mode.
* * The CSS class of that group when in text mode.
* * The font name, so that KaTeX can get font metrics.
*/ var wideLatinLetterData = [
[
"mathbf",
"textbf",
"Main-Bold"
],
[
"mathbf",
"textbf",
"Main-Bold"
],
[
"mathnormal",
"textit",
"Math-Italic"
],
[
"mathnormal",
"textit",
"Math-Italic"
],
[
"boldsymbol",
"boldsymbol",
"Main-BoldItalic"
],
[
"boldsymbol",
"boldsymbol",
"Main-BoldItalic"
],
// Map fancy A-Z letters to script, not calligraphic.
// This aligns with unicode-math and math fonts (except Cambria Math).
[
"mathscr",
"textscr",
"Script-Regular"
],
[
"",
"",
""
],
[
"",
"",
""
],
[
"",
"",
""
],
[
"mathfrak",
"textfrak",
"Fraktur-Regular"
],
[
"mathfrak",
"textfrak",
"Fraktur-Regular"
],
[
"mathbb",
"textbb",
"AMS-Regular"
],
[
"mathbb",
"textbb",
"AMS-Regular"
],
// Note that we are using a bold font, but font metrics for regular Fraktur.
[
"mathboldfrak",
"textboldfrak",
"Fraktur-Regular"
],
[
"mathboldfrak",
"textboldfrak",
"Fraktur-Regular"
],
[
"mathsf",
"textsf",
"SansSerif-Regular"
],
[
"mathsf",
"textsf",
"SansSerif-Regular"
],
[
"mathboldsf",
"textboldsf",
"SansSerif-Bold"
],
[
"mathboldsf",
"textboldsf",
"SansSerif-Bold"
],
[
"mathitsf",
"textitsf",
"SansSerif-Italic"
],
[
"mathitsf",
"textitsf",
"SansSerif-Italic"
],
[
"",
"",
""
],
[
"",
"",
""
],
[
"mathtt",
"texttt",
"Typewriter-Regular"
],
[
"mathtt",
"texttt",
"Typewriter-Regular"
] // a-z monospace
];
var wideNumeralData = [
[
"mathbf",
"textbf",
"Main-Bold"
],
[
"",
"",
""
],
[
"mathsf",
"textsf",
"SansSerif-Regular"
],
[
"mathboldsf",
"textboldsf",
"SansSerif-Bold"
],
[
"mathtt",
"texttt",
"Typewriter-Regular"
] // 0-9 monospace
];
var wideCharacterFont = function wideCharacterFont(wideChar, mode) {
// IE doesn't support codePointAt(). So work with the surrogate pair.
var H = wideChar.charCodeAt(0); // high surrogate
var L = wideChar.charCodeAt(1); // low surrogate
var codePoint = (H - 0xD800) * 0x400 + (L - 0xDC00) + 0x10000;
var j = mode === "math" ? 0 : 1; // column index for CSS class.
if (0x1D400 <= codePoint && codePoint < 0x1D6A4) {
// wideLatinLetterData contains exactly 26 chars on each row.
// So we can calculate the relevant row. No traverse necessary.
var i = Math.floor((codePoint - 0x1D400) / 26);
return [
wideLatinLetterData[i][2],
wideLatinLetterData[i][j]
];
} else if (0x1D7CE <= codePoint && codePoint <= 0x1D7FF) {
// Numerals, ten per row.
var _i = Math.floor((codePoint - 0x1D7CE) / 10);
return [
wideNumeralData[_i][2],
wideNumeralData[_i][j]
];
} else if (codePoint === 0x1D6A5 || codePoint === 0x1D6A6) // dotless i or j
return [
wideLatinLetterData[0][2],
wideLatinLetterData[0][j]
];
else if (0x1D6A6 < codePoint && codePoint < 0x1D7CE) // Greek letters. Not supported, yet.
return [
"",
""
];
else // We don't support any wide characters outside 1D400–1D7FF.
throw new ParseError("Unsupported character: " + wideChar);
};
/* eslint no-console:0 */ /**
* Looks up the given symbol in fontMetrics, after applying any symbol
* replacements defined in symbol.js
*/ var lookupSymbol = function lookupSymbol(value, fontName, mode) {
// 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.
*/ var makeSymbol = function makeSymbol(value, fontName, mode, options, classes) {
var lookup = lookupSymbol(value, fontName, mode);
var metrics = lookup.metrics;
value = lookup.value;
var symbolNode;
if (metrics) {
var 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");
var 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.
*/ var mathsym = function mathsym(value, mode, options, classes) {
if (classes === void 0) classes = [];
// 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".
*/ var boldsymbol = function boldsymbol(value, mode, options, classes, type) {
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.
*/ var makeOrd = function makeOrd(group, options, type) {
var mode = group.mode;
var text = group.text;
var classes = [
"mord"
]; // Math mode or Old font (i.e. \rm)
var isFont = mode === "math" || mode === "text" && options.font;
var fontOrFamily = isFont ? options.font : options.fontFamily;
var wideFontName = "";
var 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) {
var fontName;
var fontClasses;
if (fontOrFamily === "boldsymbol") {
var 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).
var parts = [];
for(var 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") {
var font = symbols[mode][text] && symbols[mode][text].font;
if (font === "ams") {
var _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) {
var _fontName2 = retrieveTextFontName("textrm", options.fontWeight, options.fontShape);
return makeSymbol(text, _fontName2, mode, options, classes.concat(options.fontWeight, options.fontShape));
} else {
// fonts added by plugins
var _fontName3 = retrieveTextFontName(font, options.fontWeight, options.fontShape); // We add font name as a css class
return makeSymbol(text, _fontName3, mode, options, classes.concat(_fontName3, 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.
*/ var canCombine = (prev, next)=>{
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) {
var cls = prev.classes[0];
if (cls === "mbin" || cls === "mord") return false;
}
for(var style in prev.style){
if (prev.style.hasOwnProperty(style) && prev.style[style] !== next.style[style]) return false;
}
for(var _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.
*/ var tryCombineChars = (chars)=>{
for(var i = 0; i < chars.length - 1; i++){
var prev = chars[i];
var 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.
*/ var sizeElementFromChildren = function sizeElementFromChildren(elem) {
var height = 0;
var depth = 0;
var maxFontSize = 0;
for(var i = 0; i < elem.children.length; i++){
var 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`.
*/ var makeSpan$2 = function makeSpan(classes, children, options, style) {
var 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.
var makeSvgSpan = (classes, children, options, style)=>new Span(classes, children, options, style);
var makeLineSpan = function makeLineSpan(className, options, thickness) {
var line = makeSpan$2([
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.
*/ var makeAnchor = function makeAnchor(href, classes, children, options) {
var anchor = new Anchor(href, classes, children, options);
sizeElementFromChildren(anchor);
return anchor;
};
/**
* Makes a document fragment with the given list of children.
*/ var makeFragment = function makeFragment(children) {
var 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
*/ var wrapFragment = function wrapFragment(group, options) {
if (group instanceof DocumentFragment) return makeSpan$2([], [
group
], options);
return group;
}; // These are exact object types to catch typos in the names of the optional fields.
// 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.
var getVListChildrenAndDepth = function getVListChildrenAndDepth(params) {
if (params.positionType === "individualShift") {
var oldChildren = params.children;
var children = [
oldChildren[0]
]; // Add in kerns to the list of params.children to get each element to be
// shifted to the correct specified shift
var _depth = -oldChildren[0].shift - oldChildren[0].elem.depth;
var currPos = _depth;
for(var i = 1; i < oldChildren.length; i++){
var diff = -oldChildren[i].shift - currPos - oldChildren[i].elem.depth;
var 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: _depth
};
}
var depth;
if (params.positionType === "top") {
// We always start at the bottom, so calculate the bottom by adding up
// all the sizes
var bottom = params.positionData;
for(var _i = 0; _i < params.children.length; _i++){
var 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 {
var 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.
*/ var makeVList = function makeVList(params, options) {
var { 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.
var pstrutSize = 0;
for(var i = 0; i < children.length; i++){
var child = children[i];
if (child.type === "elem") {
var elem = child.elem;
pstrutSize = Math.max(pstrutSize, elem.maxFontSize, elem.height);
}
}
pstrutSize += 2;
var pstrut = makeSpan$2([
"pstrut"
], []);
pstrut.style.height = makeEm(pstrutSize); // Create a new list of actual children at the correct offsets
var realChildren = [];
var minPos = depth;
var maxPos = depth;
var currPos = depth;
for(var _i2 = 0; _i2 < children.length; _i2++){
var _child = children[_i2];
if (_child.type === "kern") currPos += _child.size;
else {
var _elem = _child.elem;
var classes = _child.wrapperClasses || [];
var style = _child.wrapperStyle || {};
var childWrap = makeSpan$2(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.
var vlist = makeSpan$2([
"vlist"
], realChildren);
vlist.style.height = makeEm(maxPos); // A second row is used if necessary to represent the vlist's depth.
var 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.
var emptySpan = makeSpan$2([], []);
var depthStrut = makeSpan$2([
"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.
var topStrut = makeSpan$2([
"vlist-s"
], [
new SymbolNode("\u200b")
]);
rows = [
makeSpan$2([
"vlist-r"
], [
vlist,
topStrut
]),
makeSpan$2([
"vlist-r"
], [
depthStrut
])
];
} else rows = [
makeSpan$2([
"vlist-r"
], [
vlist
])
];
var vtable = makeSpan$2([
"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.
var makeGlue = (measurement, options)=>{
// Make an empty span for the space
var rule = makeSpan$2([
"mspace"
], [], options);
var size = calculateSize(measurement, options);
rule.style.marginRight = makeEm(size);
return rule;
}; // Takes font options, and returns the appropriate fontLookup name
var retrieveTextFontName = function retrieveTextFontName(fontFamily, fontWeight, fontShape) {
var 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;
}
var 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
var fontMap = {
// 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"
},
// "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"
}
};
var svgData = {
// 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
]
};
var staticSvg = function staticSvg(value, options) {
// Create a span with inline SVG for the element.
var [pathName, width, height] = svgData[value];
var path = new PathNode(pathName);
var 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"
});
var span = makeSvgSpan([
"overlay"
], [
svgNode
], options);
span.height = height;
span.style.height = makeEm(height);
span.style.width = makeEm(width);
return span;
};
var buildCommon = {
fontMap,
makeSymbol,
mathsym,
makeSpan: makeSpan$2,
makeSvgSpan,
makeLineSpan,
makeAnchor,
makeFragment,
wrapFragment,
makeVList,
makeOrd,
makeGlue,
staticSvg,
svgData,
tryCombineChars
};
/**
* Describes spaces between different classes of atoms.
*/ var thinspace = {
number: 3,
unit: "mu"
};
var mediumspace = {
number: 4,
unit: "mu"
};
var thickspace = {
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.
// Spacing relationships for display and text styles
var 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
var tightSpacings = {
mord: {
mop: thinspace
},
mop: {
mord: thinspace,
mop: thinspace
},
mbin: {},
mrel: {},
mopen: {},
mclose: {
mop: thinspace
},
mpunct: {},
minner: {
mop: thinspace
}
};
/** Context provided to function handlers for error messages. */ // Note: reverse the order of the return type union will cause a flow error.
// See https://github.com/facebook/flow/issues/3663.
// 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.
/**
* 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.
*/ /**
* All registered functions.
* `functions.js` just exports this same dictionary again and makes it public.
* `Parser.js` requires this dictionary.
*/ var _functions = {};
/**
* All HTML builders. Should be only used in the `define*` and the `build*ML`
* functions.
*/ var _htmlGroupBuilders = {};
/**
* All MathML builders. Should be only used in the `define*` and the `build*ML`
* functions.
*/ var _mathmlGroupBuilders = {};
function defineFunction(_ref) {
var { type, names, props, handler, htmlBuilder, mathmlBuilder } = _ref;
// Set default values of functions
var 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(var 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`).
*/ function defineFunctionBuilders(_ref2) {
var { type, htmlBuilder, mathmlBuilder } = _ref2;
defineFunction({
type,
names: [],
props: {
numArgs: 0
},
handler () {
throw new Error('Should never be called.');
},
htmlBuilder,
mathmlBuilder
});
}
var normalizeArgument = function normalizeArgument(arg) {
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
var ordargument = function ordargument(arg) {
return arg.type === "ordgroup" ? arg.body : [
arg
];
};
/**
* 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.
*/ var makeSpan$1 = 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.
var binLeftCanceller = [
"leftmost",
"mbin",
"mopen",
"mrel",
"mop",
"mpunct"
];
var binRightCanceller = [
"rightmost",
"mrel",
"mclose",
"mpunct"
];
var styleMap$1 = {
"display": Style$1.DISPLAY,
"text": Style$1.TEXT,
"script": Style$1.SCRIPT,
"scriptscript": Style$1.SCRIPTSCRIPT
};
var DomEnum = {
mord: "mord",
mop: "mop",
mbin: "mbin",
mrel: "mrel",
mopen: "mopen",
mclose: "mclose",
mpunct: "mpunct",
minner: "minner"
};
/**
* 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.
*/ var buildExpression$1 = function buildExpression(expression, options, isRealGroup, surrounding) {
if (surrounding === void 0) surrounding = [
null,
null
];
// Parse expressions into `groups`.
var groups = [];
for(var i = 0; i < expression.length; i++){
var output = buildGroup$1(expression[i], options);
if (output instanceof DocumentFragment) {
var children = 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;
var glueOptions = options;
if (expression.length === 1) {
var node = expression[0];
if (node.type === "sizing") glueOptions = options.havingSize(node.size);
else if (node.type === "styling") glueOptions = options.havingStyle(styleMap$1[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.
var dummyPrev = makeSpan$1([
surrounding[0] || "leftmost"
], [], options);
var dummyNext = makeSpan$1([
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.
var isRoot = isRealGroup === "root";
traverseNonSpaceNodes(groups, (node, prev)=>{
var prevType = prev.classes[0];
var 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)=>{
var prevType = getTypeOfDomTree(prev);
var type = getTypeOfDomTree(node); // 'mtight' indicates that the node is script or scriptscript style.
var 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.
var traverseNonSpaceNodes = function traverseNonSpaceNodes(nodes, callback, prev, next, isRoot) {
if (next) // temporarily append the right node, if exists
nodes.push(next);
var i = 0;
for(; i < nodes.length; i++){
var node = nodes[i];
var 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
var nonspace = !node.hasClass("mspace");
if (nonspace) {
var 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$1([
"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.
var checkPartialGroup = function checkPartialGroup(node) {
if (node instanceof DocumentFragment || node instanceof Anchor || node instanceof Span && node.hasClass("enclosing")) return node;
return null;
}; // Return the outermost node of a domTree.
var getOutermostNode = function getOutermostNode(node, side) {
var partialGroup = checkPartialGroup(node);
if (partialGroup) {
var 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.
var getTypeOfDomTree = function getTypeOfDomTree(node, side) {
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;
};
var makeNullDelimiter = function makeNullDelimiter(options, classes) {
var moreClasses = [
"nulldelimiter"
].concat(options.baseSizingClasses());
return makeSpan$1(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.
*/ var buildGroup$1 = function buildGroup(group, options, baseOptions) {
if (!group) return makeSpan$1();
if (_htmlGroupBuilders[group.type]) {
// Call the groupBuilders function
// $FlowFixMe
var groupNode = _htmlGroupBuilders[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$1(options.sizingClasses(baseOptions), [
groupNode
], options);
var 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.
var body = makeSpan$1([
"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.
var strut = makeSpan$1([
"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.
*/ function buildHTML(tree, options) {
// Strip off outer tag wrapper for processing below.
var 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
var expression = buildExpression$1(tree, options, "root");
var eqnNum;
if (expression.length === 2 && expression[1].hasClass("tag")) // An environment with automatic equation numbers, e.g. {gather}.
eqnNum = expression.pop();
var 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)."
var parts = [];
for(var 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.
var 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.
var tagChild;
if (tag) {
tagChild = buildHTMLUnbreakable(buildExpression$1(tag, options, true));
tagChild.classes = [
"tag"
];
children.push(tagChild);
} else if (eqnNum) children.push(eqnNum);
var htmlNode = makeSpan$1([
"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) {
var strut = tagChild.children[0];
strut.style.height = makeEm(htmlNode.height + htmlNode.depth);
if (htmlNode.depth) strut.style.verticalAlign = makeEm(-htmlNode.depth);
}
return htmlNode;
}
/**
* 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.
*/ function newDocumentFragment(children) {
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).
*/ class MathNode {
constructor(type, children, classes){
this.type = void 0;
this.attributes = void 0;
this.children = void 0;
this.classes = void 0;
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, value) {
this.attributes[name] = value;
}
/**
* Gets an attribute on a MathML node.
*/ getAttribute(name) {
return this.attributes[name];
}
/**
* Converts the math node into a MathML-namespaced DOM element.
*/ toNode() {
var node = document.createElementNS("http://www.w3.org/1998/Math/MathML", this.type);
for(var 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(var i = 0; i < this.children.length; i++)node.appendChild(this.children[i].toNode());
return node;
}
/**
* Converts the math node into an HTML markup string.
*/ toMarkup() {
var markup = "<" + this.type; // Add the attributes
for(var 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(var 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() {
return this.children.map((child)=>child.toText()).join("");
}
}
/**
* This node represents a piece of text.
*/ class TextNode {
constructor(text){
this.text = void 0;
this.text = text;
}
/**
* Converts the text node into a DOM text node.
*/ toNode() {
return document.createTextNode(this.text);
}
/**
* Converts the text node into escaped HTML markup
* (representing the text itself).
*/ toMarkup() {
return utils.escape(this.toText());
}
/**
* Converts the text node into a string
* (representing the text itself).
*/ toText() {
return this.text;
}
}
/**
* This node represents a space, but may render as <mspace.../> or as text,
* depending on the width.
*/ class SpaceNode {
/**
* Create a Space node with width given in CSS ems.
*/ constructor(width){
this.width = void 0;
this.character = void 0;
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"; //  
else if (width >= 0.1666 && width <= 0.1667) this.character = "\u2009"; //  
else if (width >= 0.2222 && width <= 0.2223) this.character = "\u2005"; //  
else if (width >= 0.2777 && width <= 0.2778) this.character = "\u2005\u200a"; //   
else if (width >= -0.05556 && width <= -0.05555) this.character = "\u200a\u2063"; // ​
else if (width >= -0.1667 && width <= -0.1666) this.character = "\u2009\u2063"; // ​
else if (width >= -0.2223 && width <= -0.2222) this.character = "\u205f\u2063"; // ​
else if (width >= -0.2778 && width <= -0.2777) this.character = "\u2005\u2063"; // ​
else this.character = null;
}
/**
* Converts the math node into a MathML-namespaced DOM element.
*/ toNode() {
if (this.character) return document.createTextNode(this.character);
else {
var 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() {
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() {
if (this.character) return this.character;
else return " ";
}
}
var mathMLTree = {
MathNode,
TextNode,
SpaceNode,
newDocumentFragment
};
/**
* 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.
*/ /**
* Takes a symbol and converts it into a MathML text node after performing
* optional replacement from symbols.js.
*/ var makeText = function makeText(text, mode, options) {
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.
*/ var makeRow = function makeRow(body) {
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.
*/ var getVariant = function getVariant(group, options) {
// 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";
var font = options.font;
if (!font || font === "mathnormal") return null;
var 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 === "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";
var text = group.text;
if (utils.contains([
"\\imath",
"\\jmath"
], text)) return null;
if (symbols[mode][text] && symbols[mode][text].replace) text = symbols[mode][text].replace;
var fontName = buildCommon.fontMap[font].fontName;
if (getCharacterMetrics(text, fontName, mode)) return buildCommon.fontMap[font].variant;
return null;
};
/**
* 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.
*/ var buildExpression = function buildExpression(expression, options, isOrdgroup) {
if (expression.length === 1) {
var 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
];
}
var groups = [];
var lastGroup;
for(var i = 0; i < expression.length; i++){
var _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 (_group.type === 'mi' && _group.children.length === 1 && lastGroup.type === 'mn') {
var child = _group.children[0];
if (child instanceof TextNode && child.text === '.') {
lastGroup.children.push(..._group.children);
continue;
}
} else if (lastGroup.type === 'mi' && lastGroup.children.length === 1) {
var lastChild = lastGroup.children[0];
if (lastChild instanceof TextNode && lastChild.text === '\u0338' && (_group.type === 'mo' || _group.type === 'mi' || _group.type === 'mn')) {
var _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.
*/ var buildExpressionRow = function buildExpressionRow(expression, options, isOrdgroup) {
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.
*/ var buildGroup = function buildGroup(group, options) {
if (!group) return new mathMLTree.MathNode("mrow");
if (_mathmlGroupBuilders[group.type]) {
// Call the groupBuilders function
// $FlowFixMe
var result = _mathmlGroupBuilders[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.
*/ function buildMathML(tree, texExpression, options, isDisplayMode, forMathmlOnly) {
var 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>.
var 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
var annotation = new mathMLTree.MathNode("annotation", [
new mathMLTree.TextNode(texExpression)
]);
annotation.setAttribute("encoding", "application/x-tex");
var semantics = new mathMLTree.MathNode("semantics", [
wrapper,
annotation
]);
var 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.
var wrapperClass = forMathmlOnly ? "katex" : "katex-mathml"; // $FlowFixMe
return buildCommon.makeSpan([
wrapperClass
], [
math
]);
}
var optionsFromSettings = function optionsFromSettings(settings) {
return new Options({
style: settings.displayMode ? Style$1.DISPLAY : Style$1.TEXT,
maxSize: settings.maxSize,
minRuleThickness: settings.minRuleThickness
});
};
var displayWrap = function displayWrap(node, settings) {
if (settings.displayMode) {
var classes = [
"katex-display"
];
if (settings.leqno) classes.push("leqno");
if (settings.fleqn) classes.push("fleqn");
node = buildCommon.makeSpan(classes, [
node
]);
}
return node;
};
var buildTree = function buildTree(tree, expression, settings) {
var options = optionsFromSettings(settings);
var katexNode;
if (settings.output === "mathml") return buildMathML(tree, expression, options, settings.displayMode, true);
else if (settings.output === "html") {
var htmlNode = buildHTML(tree, options);
katexNode = buildCommon.makeSpan([
"katex"
], [
htmlNode
]);
} else {
var mathMLNode = buildMathML(tree, expression, options, settings.displayMode, false);
var _htmlNode = buildHTML(tree, options);
katexNode = buildCommon.makeSpan([
"katex"
], [
mathMLNode,
_htmlNode
]);
}
return displayWrap(katexNode, settings);
};
var buildHTMLTree = function buildHTMLTree(tree, expression, settings) {
var options = optionsFromSettings(settings);
var htmlNode = buildHTML(tree, options);
var katexNode = buildCommon.makeSpan([
"katex"
], [
htmlNode
]);
return displayWrap(katexNode, settings);
};
/**
* This file provides support to buildMathML.js and buildHTML.js
* for stretchy wide elements rendered from SVG files
* and other CSS trickery.
*/ var stretchyCodePoint = {
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": "="
};
var mathMLnode = function mathMLnode(label) {
var 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.
var katexImagesData = {
// 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
]
};
var groupLength = function groupLength(arg) {
if (arg.type === "ordgroup") return arg.body.length;
else return 1;
};
var svgSpan = function svgSpan(group, options) {
// Create a span with inline SVG for the element.
function buildSvgSpan_() {
var viewBoxWidth = 400000; // default
var 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
var grp = group; // There are four SVG images available for each function.
// Choose a taller image when there are more characters.
var numChars = groupLength(grp.base);
var viewBoxHeight;
var pathName;
var _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 {
var 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;
}
}
var path = new PathNode(pathName);
var 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: _height
};
} else {
var spans = [];
var data = katexImagesData[label];
var [paths, _minWidth, _viewBoxHeight] = data;
var _height2 = _viewBoxHeight / 1000;
var numSvgChildren = paths.length;
var widthClasses;
var aligns;
if (numSvgChildren === 1) {
// $FlowFixMe: All these cases must be of the 4-tuple type.
var align1 = 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\n " + numSvgChildren + " children.");
for(var i = 0; i < numSvgChildren; i++){
var _path = new PathNode(paths[i]);
var _svgNode = new SvgNode([
_path
], {
"width": "400em",
"height": makeEm(_height2),
"viewBox": "0 0 " + viewBoxWidth + " " + _viewBoxHeight,
"preserveAspectRatio": aligns[i] + " slice"
});
var _span = buildCommon.makeSvgSpan([
widthClasses[i]
], [
_svgNode
], options);
if (numSvgChildren === 1) return {
span: _span,
minWidth: _minWidth,
height: _height2
};
else {
_span.style.height = makeEm(_height2);
spans.push(_span);
}
}
return {
span: buildCommon.makeSpan([
"stretchy"
], spans, options),
minWidth: _minWidth,
height: _height2
};
}
} // buildSvgSpan_()
var { 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;
};
var encloseSpan = function encloseSpan(inner, label, topPad, bottomPad, options) {
// Return an image span for \cancel, \bcancel, \xcancel, \fbox, or \angl
var img;
var totalHeight = inner.height + inner.depth + topPad + bottomPad;
if (/fbox|color|angl/.test(label)) {
img = buildCommon.makeSpan([
"stretchy",
label
], [], options);
if (label === "fbox") {
var 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.
var 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"
}));
var svgNode = new SvgNode(lines, {
"width": "100%",
"height": makeEm(totalHeight)
});
img = buildCommon.makeSvgSpan([], [
svgNode
], options);
}
img.height = totalHeight;
img.style.height = makeEm(totalHeight);
return img;
};
var stretchy = {
encloseSpan,
mathMLnode,
svgSpan
};
/**
* Asserts that the node is of the given type and returns it with stricter
* typing. Throws if the node's type does not match.
*/ function assertNodeType(node, type) {
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.
*/ function assertSymbolNodeType(node) {
var 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.
*/ function checkSymbolNodeType(node) {
if (node && (node.type === "atom" || NON_ATOMS.hasOwnProperty(node.type))) // $FlowFixMe
return node;
return null;
}
// NOTE: Unlike most `htmlBuilder`s, this one handles not only "accent", but
// also "supsub" since an accent can affect super/subscripting.
var htmlBuilder$a = (grp, options)=>{
// Accents are handled in the TeXbook pg. 443, rule 12.
var base;
var group;
var 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(buildGroup$1(grp, options)); // reset original base
grp.base = group;
} else {
group = assertNodeType(grp, "accent");
base = group.base;
} // Build the base group
var body = buildGroup$1(base, options.havingCrampedStyle()); // Does the accent need to shift for the skew of a character?
var 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.
var 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:
var baseChar = utils.getBaseElem(base); // Then, we render its group to get the symbol inside it
var baseGroup = buildGroup$1(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
}
var accentBelow = group.label === "\\c"; // calculate the amount of space between the body and the accent
var clearance = accentBelow ? body.height + body.depth : Math.min(body.height, options.fontMetrics().xHeight); // Build the accent
var accentBody;
if (!group.isStretchy) {
var accent;
var width;
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.
var accentFull = group.label === "\\textcircled";
if (accentFull) {
accentBody.classes.push('accent-full');
clearance = body.height;
} // Shift the accent over by the skew.
var 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);
}
var 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;
};
var mathmlBuilder$9 = (group, options)=>{
var accentNode = group.isStretchy ? stretchy.mathMLnode(group.label) : new mathMLTree.MathNode("mo", [
makeText(group.label, group.mode)
]);
var node = new mathMLTree.MathNode("mover", [
buildGroup(group.base, options),
accentNode
]);
node.setAttribute("accent", "true");
return node;
};
var 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)=>{
var base = normalizeArgument(args[0]);
var isStretchy = !NON_STRETCHY_ACCENT_REGEX.test(context.funcName);
var 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: htmlBuilder$a,
mathmlBuilder: mathmlBuilder$9
}); // 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)=>{
var base = args[0];
var 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: htmlBuilder$a,
mathmlBuilder: mathmlBuilder$9
});
// Horizontal overlap functions
defineFunction({
type: "accentUnder",
names: [
"\\underleftarrow",
"\\underrightarrow",
"\\underleftrightarrow",
"\\undergroup",
"\\underlinesegment",
"\\utilde"
],
props: {
numArgs: 1
},
handler: (_ref, args)=>{
var { parser, funcName } = _ref;
var base = args[0];
return {
type: "accentUnder",
mode: parser.mode,
label: funcName,
base: base
};
},
htmlBuilder: (group, options)=>{
// Treat under accents much like underlines.
var innerGroup = buildGroup$1(group.base, options);
var accentBody = stretchy.svgSpan(group, options);
var kern = group.label === "\\utilde" ? 0.12 : 0; // Generate the vlist, with the appropriate kerns
var 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)=>{
var accentNode = stretchy.mathMLnode(group.label);
var node = new mathMLTree.MathNode("munder", [
buildGroup(group.base, options),
accentNode
]);
node.setAttribute("accentunder", "true");
return node;
}
});
// Helper function
var paddedNode = (group)=>{
var 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",
// Direct use of these functions is discouraged and may break someday.
"\\xrightleftarrows",
"\\xrightequilibrium",
"\\xleftequilibrium",
"\\\\cdrightarrow",
"\\\\cdleftarrow",
"\\\\cdlongequal"
],
props: {
numArgs: 1,
numOptionalArgs: 1
},
handler (_ref, args, optArgs) {
var { parser, funcName } = _ref;
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, options) {
var 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.
var newOptions = options.havingStyle(style.sup());
var upperGroup = buildCommon.wrapFragment(buildGroup$1(group.body, newOptions, options), options);
var arrowPrefix = group.label.slice(0, 2) === "\\x" ? "x" : "cd";
upperGroup.classes.push(arrowPrefix + "-arrow-pad");
var lowerGroup;
if (group.below) {
// Build the lower group
newOptions = options.havingStyle(style.sub());
lowerGroup = buildCommon.wrapFragment(buildGroup$1(group.below, newOptions, options), options);
lowerGroup.classes.push(arrowPrefix + "-arrow-pad");
}
var 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.
var arrowShift = -options.fontMetrics().axisHeight + 0.5 * arrowBody.height; // 2 mu kern. Ref: amsmath.dtx: #7\if0#2\else\mkern#2mu\fi
var 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
var vlist;
if (lowerGroup) {
var 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) {
var arrowNode = stretchy.mathMLnode(group.label);
arrowNode.setAttribute("minsize", group.label.charAt(0) === "x" ? "1.75em" : "3.0em");
var node;
if (group.body) {
var upperNode = paddedNode(buildGroup(group.body, options));
if (group.below) {
var lowerNode = paddedNode(buildGroup(group.below, options));
node = new mathMLTree.MathNode("munderover", [
arrowNode,
lowerNode,
upperNode
]);
} else node = new mathMLTree.MathNode("mover", [
arrowNode,
upperNode
]);
} else if (group.below) {
var _lowerNode = paddedNode(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;
}
});
var makeSpan = buildCommon.makeSpan;
function htmlBuilder$9(group, options) {
var elements = buildExpression$1(group.body, options, true);
return makeSpan([
group.mclass
], elements, options);
}
function mathmlBuilder$8(group, options) {
var node;
var inner = 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 (_ref, args) {
var { parser, funcName } = _ref;
var 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: htmlBuilder$9,
mathmlBuilder: mathmlBuilder$8
});
var binrelClass = (arg)=>{
// \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.
var 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 (_ref2, args) {
var { parser } = _ref2;
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 (_ref3, args) {
var { parser, funcName } = _ref3;
var baseArg = args[1];
var shiftedArg = args[0];
var mclass;
if (funcName !== "\\stackrel") // LaTeX applies \binrel spacing to \overset and \underset.
mclass = binrelClass(baseArg);
else mclass = "mrel"; // for \stackrel
var baseOp = {
type: "op",
mode: baseArg.mode,
limits: true,
alwaysHandleSupSub: true,
parentIsSupSub: false,
symbol: false,
suppressBaseShift: funcName !== "\\stackrel",
body: ordargument(baseArg)
};
var 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: htmlBuilder$9,
mathmlBuilder: mathmlBuilder$8
});
// \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 (_ref, args) {
var { parser } = _ref;
return {
type: "pmb",
mode: parser.mode,
mclass: binrelClass(args[0]),
body: ordargument(args[0])
};
},
htmlBuilder (group, options) {
var elements = buildExpression$1(group.body, options, true);
var node = buildCommon.makeSpan([
group.mclass
], elements, options);
node.style.textShadow = "0.02em 0.01em 0.04px";
return node;
},
mathmlBuilder (group, style) {
var inner = buildExpression(group.body, style); // Wrap with an <mstyle> element.
var node = new mathMLTree.MathNode("mstyle", inner);
node.setAttribute("style", "text-shadow: 0.02em 0.01em 0.04px");
return node;
}
});
var cdArrowFunctionName = {
">": "\\\\cdrightarrow",
"<": "\\\\cdleftarrow",
"=": "\\\\cdlongequal",
"A": "\\uparrow",
"V": "\\downarrow",
"|": "\\Vert",
".": "no arrow"
};
var 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"
};
};
var isStartOfArrow = (node)=>{
return node.type === "textord" && node.text === "@";
};
var isLabelEnd = (node, endChar)=>{
return (node.type === "mathord" || node.type === "atom") && node.text === endChar;
};
function cdArrow(arrowChar, labels, parser) {
// Return a parse tree of an arrow and its labels.
// This acts in a way similar to a macro expansion.
var funcName = cdArrowFunctionName[arrowChar];
switch(funcName){
case "\\\\cdrightarrow":
case "\\\\cdleftarrow":
return parser.callFunction(funcName, [
labels[0]
], [
labels[1]
]);
case "\\uparrow":
case "\\downarrow":
var leftLabel = parser.callFunction("\\\\cdleft", [
labels[0]
], []);
var bareArrow = {
type: "atom",
text: funcName,
mode: "math",
family: "rel"
};
var sizedArrow = parser.callFunction("\\Big", [
bareArrow
], []);
var rightLabel = parser.callFunction("\\\\cdright", [
labels[1]
], []);
var arrowGroup = {
type: "ordgroup",
mode: "math",
body: [
leftLabel,
sizedArrow,
rightLabel
]
};
return parser.callFunction("\\\\cdparent", [
arrowGroup
], []);
case "\\\\cdlongequal":
return parser.callFunction("\\\\cdlongequal", [], []);
case "\\Vert":
var arrow = {
type: "textord",
text: "\\Vert",
mode: "math"
};
return parser.callFunction("\\Big", [
arrow
], []);
default:
return {
type: "textord",
text: " ",
mode: "math"
};
}
}
function parseCD(parser) {
// Get the array's parse nodes with \\ temporarily mapped to \cr.
var parsedRows = [];
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();
var 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);
}
var row = [];
var body = [
row
]; // Loop thru the parse nodes. Collect them into cells and arrows.
for(var i = 0; i < parsedRows.length; i++){
// Start a new row.
var rowNodes = parsedRows[i]; // Create the first cell.
var cell = newCell();
for(var 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;
var arrowChar = assertSymbolNodeType(rowNodes[j]).text; // Create two empty label nodes. We may or may not use them.
var labels = new Array(2);
labels[0] = {
type: "ordgroup",
mode: "math",
body: []
};
labels[1] = {
type: "ordgroup",
mode: "math",
body: []
}; // Process the arrow.
if ("=|.".indexOf(arrowChar) > -1) ;
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(var labelNum = 0; labelNum < 2; labelNum++){
var inLabel = true;
for(var 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.
var arrow = cdArrow(arrowChar, labels, parser); // Wrap the arrow in ParseNode<"styling">.
// This is done to match parseArray() behavior.
var 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.
var 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 (_ref, args) {
var { parser, funcName } = _ref;
return {
type: "cdlabel",
mode: parser.mode,
side: funcName.slice(4),
label: args[0]
};
},
htmlBuilder (group, options) {
var newOptions = options.havingStyle(options.style.sup());
var label = buildCommon.wrapFragment(buildGroup$1(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) {
var label = new mathMLTree.MathNode("mrow", [
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 (_ref2, args) {
var { parser } = _ref2;
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.
var parent = buildCommon.wrapFragment(buildGroup$1(group.fragment, options), options);
parent.classes.push("cd-vert-arrow");
return parent;
},
mathmlBuilder (group, options) {
return new mathMLTree.MathNode("mrow", [
buildGroup(group.fragment, options)
]);
}
});
// {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 (_ref, args) {
var { parser } = _ref;
var arg = assertNodeType(args[0], "ordgroup");
var group = arg.body;
var number = "";
for(var i = 0; i < group.length; i++){
var node = assertNodeType(group[i], "textord");
number += node.text;
}
var code = parseInt(number);
var 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
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
};
}
});
var htmlBuilder$8 = (group, options)=>{
var elements = buildExpression$1(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);
};
var mathmlBuilder$7 = (group, options)=>{
var inner = buildExpression(group.body, options.withColor(group.color));
var 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 (_ref, args) {
var { parser } = _ref;
var color = assertNodeType(args[0], "color-token").color;
var body = args[1];
return {
type: "color",
mode: parser.mode,
color,
body: ordargument(body)
};
},
htmlBuilder: htmlBuilder$8,
mathmlBuilder: mathmlBuilder$7
});
defineFunction({
type: "color",
names: [
"\\color"
],
props: {
numArgs: 1,
allowedInText: true,
argTypes: [
"color"
]
},
handler (_ref2, args) {
var { parser, breakOnTokenText } = _ref2;
var 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.
var body = parser.parseExpression(true, breakOnTokenText);
return {
type: "color",
mode: parser.mode,
color,
body
};
},
htmlBuilder: htmlBuilder$8,
mathmlBuilder: mathmlBuilder$7
});
// Row breaks within tabular environments, and line breaks at top level
defineFunction({
type: "cr",
names: [
"\\\\"
],
props: {
numArgs: 0,
numOptionalArgs: 0,
allowedInText: true
},
handler (_ref, args, optArgs) {
var { parser } = _ref;
var size = parser.gullet.future().text === "[" ? parser.parseSizeGroup(true) : null;
var 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) {
var 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) {
var 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;
}
});
var globalMap = {
"\\global": "\\global",
"\\long": "\\\\globallong",
"\\\\globallong": "\\\\globallong",
"\\def": "\\gdef",
"\\gdef": "\\gdef",
"\\edef": "\\xdef",
"\\xdef": "\\xdef",
"\\let": "\\\\globallet",
"\\futurelet": "\\\\globalfuture"
};
var checkControlSequence = (tok)=>{
var name = tok.text;
if (/^(?:[\\{}$&#^_]|EOF)$/.test(name)) throw new ParseError("Expected a control sequence", tok);
return name;
};
var getRHS = (parser)=>{
var 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;
};
var letCommand = (parser, name, tok, global)=>{
var 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" // can’t be entered directly
],
props: {
numArgs: 0,
allowedInText: true
},
handler (_ref) {
var { parser, funcName } = _ref;
parser.consumeSpaces();
var 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 (_ref2) {
var { parser, funcName } = _ref2;
var tok = parser.gullet.popToken();
var name = tok.text;
if (/^(?:[\\{}$&#^_]|EOF)$/.test(name)) throw new ParseError("Expected a control sequence", tok);
var numArgs = 0;
var insert;
var 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
var { 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" // can’t be entered directly
],
props: {
numArgs: 0,
allowedInText: true,
primitive: true
},
handler (_ref3) {
var { parser, funcName } = _ref3;
var name = checkControlSequence(parser.gullet.popToken());
parser.gullet.consumeSpaces();
var 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" // can’t be entered directly
],
props: {
numArgs: 0,
allowedInText: true,
primitive: true
},
handler (_ref4) {
var { parser, funcName } = _ref4;
var name = checkControlSequence(parser.gullet.popToken());
var middle = parser.gullet.popToken();
var tok = parser.gullet.popToken();
letCommand(parser, name, tok, funcName === "\\\\globalfuture");
parser.gullet.pushToken(tok);
parser.gullet.pushToken(middle);
return {
type: "internal",
mode: parser.mode
};
}
});
/**
* 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`.
*/ /**
* Get the metrics for a given symbol and font, after transformation (i.e.
* after following replacement from symbols.js)
*/ var getMetrics = function getMetrics(symbol, font, mode) {
var replace = symbols.math[symbol] && symbols.math[symbol].replace;
var 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.
*/ var styleWrap = function styleWrap(delim, toStyle, options, classes) {
var newOptions = options.havingBaseStyle(toStyle);
var span = buildCommon.makeSpan(classes.concat(newOptions.sizingClasses(options)), [
delim
], options);
var delimSizeMultiplier = newOptions.sizeMultiplier / options.sizeMultiplier;
span.height *= delimSizeMultiplier;
span.depth *= delimSizeMultiplier;
span.maxFontSize = newOptions.sizeMultiplier;
return span;
};
var centerSpan = function centerSpan(span, options, style) {
var newOptions = options.havingBaseStyle(style);
var 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.
*/ var makeSmallDelim = function makeSmallDelim(delim, style, center, options, mode, classes) {
var text = buildCommon.makeSymbol(delim, "Main-Regular", mode, options);
var 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)
*/ var mathrmSize = function mathrmSize(value, size, mode, options) {
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.
*/ var makeLargeDelim = function makeLargeDelim(delim, size, center, options, mode, classes) {
var inner = mathrmSize(delim, size, mode, options);
var span = styleWrap(buildCommon.makeSpan([
"delimsizing",
"size" + size
], [
inner
], options), Style$1.TEXT, options, classes);
if (center) centerSpan(span, options, Style$1.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.
*/ var makeGlyphSpan = function makeGlyphSpan(symbol, font, mode) {
var sizeClass; // Apply the correct CSS class to choose the right font.
if (font === "Size1-Regular") sizeClass = "delim-size1";
else sizeClass = "delim-size4";
var 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
};
};
var makeInner = function makeInner(ch, height, options) {
// Create a span with inline SVG for the inner part of a tall stacked delimiter.
var width = fontMetricsData['Size4-Regular'][ch.charCodeAt(0)] ? fontMetricsData['Size4-Regular'][ch.charCodeAt(0)][4] : fontMetricsData['Size1-Regular'][ch.charCodeAt(0)][4];
var path = new PathNode("inner", innerPath(ch, Math.round(1000 * height)));
var 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"
});
var 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
var lapInEms = 0.008;
var lap = {
type: "kern",
size: -1 * lapInEms
};
var verts = [
"|",
"\\lvert",
"\\rvert",
"\\vert"
];
var 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.
*/ var makeStackedDelim = function makeStackedDelim(delim, heightTotal, center, options, mode, classes) {
// There are four parts, the top, an optional middle, a repeated part, and a
// bottom.
var top;
var middle;
var repeat;
var bottom;
var svgLabel = "";
var viewBoxWidth = 0;
top = repeat = bottom = delim;
middle = null; // Also keep track of what font the delimiters are in
var 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
var topMetrics = getMetrics(top, font, mode);
var topHeightTotal = topMetrics.height + topMetrics.depth;
var repeatMetrics = getMetrics(repeat, font, mode);
var repeatHeightTotal = repeatMetrics.height + repeatMetrics.depth;
var bottomMetrics = getMetrics(bottom, font, mode);
var bottomHeightTotal = bottomMetrics.height + bottomMetrics.depth;
var middleHeightTotal = 0;
var middleFactor = 1;
if (middle !== null) {
var 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.
var minHeight = topHeightTotal + bottomHeightTotal + middleHeightTotal; // Compute the number of copies of the repeat symbol we will need
var repeatCount = Math.max(0, Math.ceil((heightTotal - minHeight) / (middleFactor * repeatHeightTotal))); // Compute the total height of the delimiter including all the symbols
var 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.
var axisHeight = options.fontMetrics().axisHeight;
if (center) axisHeight *= options.sizeMultiplier;
// Calculate the depth
var 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
var stack = [];
if (svgLabel.length > 0) {
// Instead of stacking glyphs, create a single SVG.
// This evades browser problems with imprecise positioning of spans.
var midHeight = realHeightTotal - topHeightTotal - bottomHeightTotal;
var viewBoxHeight = Math.round(realHeightTotal * 1000);
var pathStr = tallDelim(svgLabel, Math.round(midHeight * 1000));
var path = new PathNode(svgLabel, pathStr);
var width = (viewBoxWidth / 1000).toFixed(3) + "em";
var height = (viewBoxHeight / 1000).toFixed(3) + "em";
var svg = new SvgNode([
path
], {
"width": width,
"height": height,
"viewBox": "0 0 " + viewBoxWidth + " " + viewBoxHeight
});
var 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.
var 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
var _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
var newOptions = options.havingBaseStyle(Style$1.TEXT);
var inner = buildCommon.makeVList({
positionType: "bottom",
positionData: depth,
children: stack
}, newOptions);
return styleWrap(buildCommon.makeSpan([
"delimsizing",
"mult"
], [
inner
], newOptions), Style$1.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.
var vbPad = 80; // padding above the surd, measured inside the viewBox.
var emPad = 0.08; // padding, in ems, measured in the document.
var sqrtSvg = function sqrtSvg(sqrtName, height, viewBoxHeight, extraVinculum, options) {
var path = sqrtPath(sqrtName, extraVinculum, viewBoxHeight);
var pathNode = new PathNode(sqrtName, path);
var 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,
*/ var makeSqrtImage = function makeSqrtImage(height, options) {
// 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.
var newOptions = options.havingBaseSizing(); // Pick the desired surd glyph from a sequence of surds.
var delim = traverseSequence("\\surd", height * newOptions.sizeMultiplier, stackLargeDelimiterSequence, newOptions);
var 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.
var extraVinculum = Math.max(0, options.minRuleThickness - options.fontMetrics().sqrtRuleThickness); // Create a span containing an SVG image of a sqrt symbol.
var span;
var spanHeight = 0;
var texHeight = 0;
var viewBoxHeight = 0;
var 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
var stackLargeDelimiters = [
"(",
"\\lparen",
")",
"\\rparen",
"[",
"\\lbrack",
"]",
"\\rbrack",
"\\{",
"\\lbrace",
"\\}",
"\\rbrace",
"\\lfloor",
"\\rfloor",
"\u230a",
"\u230b",
"\\lceil",
"\\rceil",
"\u2308",
"\u2309",
"\\surd"
]; // delimiters that always stack
var 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
var 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.
var 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.
*/ var makeSizedDelim = function makeSizedDelim(delim, size, options, mode, classes) {
// < 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.
*/ // Delimiters that never stack try small delimiters and large delimiters only
var stackNeverDelimiterSequence = [
{
type: "small",
style: Style$1.SCRIPTSCRIPT
},
{
type: "small",
style: Style$1.SCRIPT
},
{
type: "small",
style: Style$1.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
var stackAlwaysDelimiterSequence = [
{
type: "small",
style: Style$1.SCRIPTSCRIPT
},
{
type: "small",
style: Style$1.SCRIPT
},
{
type: "small",
style: Style$1.TEXT
},
{
type: "stack"
}
]; // Delimiters that stack when large try the small and then large delimiters, and
// stack afterwards
var stackLargeDelimiterSequence = [
{
type: "small",
style: Style$1.SCRIPTSCRIPT
},
{
type: "small",
style: Style$1.SCRIPT
},
{
type: "small",
style: Style$1.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.
*/ var delimTypeToFont = function delimTypeToFont(type) {
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.
*/ var traverseSequence = function traverseSequence(delim, height, sequence, options) {
// 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
var start = Math.min(2, 3 - options.style.size);
for(var i = start; i < sequence.length; i++){
if (sequence[i].type === "stack") break;
var metrics = getMetrics(delim, delimTypeToFont(sequence[i]), "math");
var 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") {
var 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.
*/ var makeCustomSizedDelim = function makeCustomSizedDelim(delim, height, center, options, mode, classes) {
if (delim === "<" || delim === "\\lt" || delim === "\u27e8") delim = "\\langle";
else if (delim === ">" || delim === "\\gt" || delim === "\u27e9") delim = "\\rangle";
// Decide what sequence to use
var sequence;
if (utils.contains(stackNeverDelimiters, delim)) sequence = stackNeverDelimiterSequence;
else if (utils.contains(stackLargeDelimiters, delim)) sequence = stackLargeDelimiterSequence;
else sequence = stackAlwaysDelimiterSequence;
// Look through the sequence
var 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 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.
*/ var makeLeftRightDelim = function makeLeftRightDelim(delim, height, depth, options, mode, classes) {
// We always center \left/\right delimiters, so the axis is always shifted
var axisHeight = options.fontMetrics().axisHeight * options.sizeMultiplier; // Taken from TeX source, tex.web, function make_left_right
var delimiterFactor = 901;
var delimiterExtend = 5.0 / options.fontMetrics().ptPerEm;
var maxDistFromAxis = Math.max(height - axisHeight, depth + axisHeight);
var totalHeight = Math.max(// 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);
};
var delimiter = {
sqrtImage: makeSqrtImage,
sizedDelim: makeSizedDelim,
sizeToMaxHeight: sizeToMaxHeight,
customSizedDelim: makeCustomSizedDelim,
leftRightDelim: makeLeftRightDelim
};
// Extra data needed for the delimiter handler down below
var 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
}
};
var 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",
"."
];
// Delimiter functions
function checkDelimiter(delim, context) {
var 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)=>{
var 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)=>{
var children = [];
if (group.delim !== ".") children.push(makeText(group.delim, group.mode));
var 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");
var size = makeEm(delimiter.sizeToMaxHeight[group.size]);
node.setAttribute("minsize", size);
node.setAttribute("maxsize", size);
return node;
}
});
function assertParsed(group) {
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.
var 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
};
}
});
defineFunction({
type: "leftright",
names: [
"\\left"
],
props: {
numArgs: 1,
primitive: true
},
handler: (context, args)=>{
var delim = checkDelimiter(args[0], context);
var parser = context.parser; // Parse out the implicit body
++parser.leftrightDepth; // parseExpression stops before '\\right'
var body = parser.parseExpression(false);
--parser.leftrightDepth; // Check the next token
parser.expect("\\right", false);
var 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
var inner = buildExpression$1(group.body, options, true, [
"mopen",
"mclose"
]);
var innerHeight = 0;
var innerDepth = 0;
var hadMiddle = false; // Calculate its height and depth
for(var 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;
var leftDelim;
if (group.left === ".") // Empty delimiters in \left and \right make null delimiter spaces.
leftDelim = 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(var _i = 1; _i < inner.length; _i++){
var middleDelim = inner[_i]; // Property `isMiddle` not defined on `span`. See comment in
// "middle"'s htmlBuilder.
// $FlowFixMe
var 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, []);
}
var rightDelim; // Same for the right delimiter, but using color specified by \color
if (group.right === ".") rightDelim = makeNullDelimiter(options, [
"mclose"
]);
else {
var 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);
var inner = buildExpression(group.body, options);
if (group.left !== ".") {
var leftNode = new mathMLTree.MathNode("mo", [
makeText(group.left, group.mode)
]);
leftNode.setAttribute("fence", "true");
inner.unshift(leftNode);
}
if (group.right !== ".") {
var rightNode = new mathMLTree.MathNode("mo", [
makeText(group.right, group.mode)
]);
rightNode.setAttribute("fence", "true");
if (group.rightColor) rightNode.setAttribute("mathcolor", group.rightColor);
inner.push(rightNode);
}
return makeRow(inner);
}
});
defineFunction({
type: "middle",
names: [
"\\middle"
],
props: {
numArgs: 1,
primitive: true
},
handler: (context, args)=>{
var 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)=>{
var middleDelim;
if (group.delim === ".") middleDelim = makeNullDelimiter(options, []);
else {
middleDelim = delimiter.sizedDelim(group.delim, 1, options, group.mode, []);
var 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.
var textNode = group.delim === "\\vert" || group.delim === "|" ? makeText("|", "text") : makeText(group.delim, group.mode);
var 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;
}
});
var htmlBuilder$7 = (group, options)=>{
// \cancel, \bcancel, \xcancel, \sout, \fbox, \colorbox, \fcolorbox, \phase
// Some groups can return document fragments. Handle those by wrapping
// them in a span.
var inner = buildCommon.wrapFragment(buildGroup$1(group.body, options), options);
var label = group.label.slice(1);
var scale = options.sizeMultiplier;
var img;
var 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.
var 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.
var lineWeight = calculateSize({
number: 0.6,
unit: "pt"
}, options);
var clearance = calculateSize({
number: 0.35,
unit: "ex"
}, options); // Prevent size changes like \Huge from affecting line thickness
var newOptions = options.havingBaseSizing();
scale = scale / newOptions.sizeMultiplier;
var angleHeight = inner.height + inner.depth + lineWeight + clearance; // Reserve a left pad for the angle.
inner.style.paddingLeft = makeEm(angleHeight / 2 + lineWeight); // Create an SVG
var viewBoxHeight = Math.floor(1000 * angleHeight * scale);
var path = phasePath(viewBoxHeight);
var 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
var topPad = 0;
var bottomPad = 0;
var ruleThickness = 0; // ref: cancel package: \advance\totalheight2\p@ % "+2"
if (/box/.test(label)) {
ruleThickness = Math.max(options.fontMetrics().fboxrule, 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;
}
}
var vlist;
if (group.backgroundColor) vlist = buildCommon.makeVList({
positionType: "individualShift",
children: [
{
type: "elem",
elem: img,
shift: imgShift
},
{
type: "elem",
elem: inner,
shift: 0
}
]
}, options);
else {
var classes = /cancel|phase/.test(label) ? [
"svg-align"
] : [];
vlist = buildCommon.makeVList({
positionType: "individualShift",
children: [
{
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);
};
var mathmlBuilder$6 = (group, options)=>{
var fboxsep = 0;
var node = new mathMLTree.MathNode(group.label.indexOf("colorbox") > -1 ? "mpadded" : "menclose", [
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") {
var thk = Math.max(options.fontMetrics().fboxrule, 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 (_ref, args, optArgs) {
var { parser, funcName } = _ref;
var color = assertNodeType(args[0], "color-token").color;
var body = args[1];
return {
type: "enclose",
mode: parser.mode,
label: funcName,
backgroundColor: color,
body
};
},
htmlBuilder: htmlBuilder$7,
mathmlBuilder: mathmlBuilder$6
});
defineFunction({
type: "enclose",
names: [
"\\fcolorbox"
],
props: {
numArgs: 3,
allowedInText: true,
argTypes: [
"color",
"color",
"text"
]
},
handler (_ref2, args, optArgs) {
var { parser, funcName } = _ref2;
var borderColor = assertNodeType(args[0], "color-token").color;
var backgroundColor = assertNodeType(args[1], "color-token").color;
var body = args[2];
return {
type: "enclose",
mode: parser.mode,
label: funcName,
backgroundColor,
borderColor,
body
};
},
htmlBuilder: htmlBuilder$7,
mathmlBuilder: mathmlBuilder$6
});
defineFunction({
type: "enclose",
names: [
"\\fbox"
],
props: {
numArgs: 1,
argTypes: [
"hbox"
],
allowedInText: true
},
handler (_ref3, args) {
var { parser } = _ref3;
return {
type: "enclose",
mode: parser.mode,
label: "\\fbox",
body: args[0]
};
}
});
defineFunction({
type: "enclose",
names: [
"\\cancel",
"\\bcancel",
"\\xcancel",
"\\sout",
"\\phase"
],
props: {
numArgs: 1
},
handler (_ref4, args) {
var { parser, funcName } = _ref4;
var body = args[0];
return {
type: "enclose",
mode: parser.mode,
label: funcName,
body
};
},
htmlBuilder: htmlBuilder$7,
mathmlBuilder: mathmlBuilder$6
});
defineFunction({
type: "enclose",
names: [
"\\angl"
],
props: {
numArgs: 1,
argTypes: [
"hbox"
],
allowedInText: false
},
handler (_ref5, args) {
var { parser } = _ref5;
return {
type: "enclose",
mode: parser.mode,
label: "\\angl",
body: args[0]
};
}
});
/**
* All registered environments.
* `environments.js` exports this same dictionary again and makes it public.
* `Parser.js` requires this dictionary via `environments.js`.
*/ var _environments = {};
function defineEnvironment(_ref) {
var { type, names, props, handler, htmlBuilder, mathmlBuilder } = _ref;
// Set default values of environments.
var data = {
type,
numArgs: props.numArgs || 0,
allowedInText: false,
numOptionalArgs: 0,
handler
};
for(var 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;
}
/**
* 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`.
*/ var _macros = {}; // This function might one day accept an additional argument and do more things.
function defineMacro(name, body) {
_macros[name] = body;
}
// Helper functions
function getHLines(parser) {
// Return an array. The array length = number of hlines.
// Each element in the array tells if the line is dashed.
var hlineInfo = [];
parser.consumeSpaces();
var nxt = parser.fetch().text;
if (nxt === "\\relax") {
// \relax is an artifact of the \cr macro below
parser.consume();
parser.consumeSpaces();
nxt = parser.fetch().text;
}
while(nxt === "\\hline" || nxt === "\\hdashline"){
parser.consume();
hlineInfo.push(nxt === "\\hdashline");
parser.consumeSpaces();
nxt = parser.fetch().text;
}
return hlineInfo;
}
var validateAmsEnvironmentContext = (context)=>{
var settings = context.parser.settings;
if (!settings.displayMode) throw new ParseError("{" + context.envName + "} can be used only in" + " display mode.");
}; // autoTag (an argument to parseArray) can be one of three values:
// * undefined: Regular (not-top-level) array; no tags on each row
// * true: Automatic equation numbering, overridable by \tag
// * false: Tags allowed on each row, but no automatic numbering
// This function *doesn't* work with the "split" environment name.
function getAutoTag(name) {
if (name.indexOf("ed") === -1) return name.indexOf("*") === -1;
// return undefined;
}
/**
* Parse the body of the environment, with rows delimited by \\ and
* columns delimited by &, and create a nested list in row-major order
* with one group per cell. If given an optional argument style
* ("text", "display", etc.), then each cell is cast into that style.
*/ function parseArray(parser, _ref, style) {
var { hskipBeforeAndAfter, addJot, cols, arraystretch, colSeparationType, autoTag, singleRow, emptySingleRow, maxNumCols, leqno } = _ref;
parser.gullet.beginGroup();
if (!singleRow) // \cr is equivalent to \\ without the optional size argument (see below)
// TODO: provide helpful error when \cr is used outside array environment
parser.gullet.macros.set("\\cr", "\\\\\\relax");
// Get current arraystretch if it's not set by the environment
if (!arraystretch) {
var stretch = parser.gullet.expandMacroAsText("\\arraystretch");
if (stretch == null) // Default \arraystretch from lttab.dtx
arraystretch = 1;
else {
arraystretch = parseFloat(stretch);
if (!arraystretch || arraystretch < 0) throw new ParseError("Invalid \\arraystretch: " + stretch);
}
} // Start group for first cell
parser.gullet.beginGroup();
var row = [];
var body = [
row
];
var rowGaps = [];
var hLinesBeforeRow = [];
var tags = autoTag != null ? [] : undefined; // amsmath uses \global\@eqnswtrue and \global\@eqnswfalse to represent
// whether this row should have an equation number. Simulate this with
// a \@eqnsw macro set to 1 or 0.
function beginRow() {
if (autoTag) parser.gullet.macros.set("\\@eqnsw", "1", true);
}
function endRow() {
if (tags) {
if (parser.gullet.macros.get("\\df@tag")) {
tags.push(parser.subparse([
new Token("\\df@tag")
]));
parser.gullet.macros.set("\\df@tag", undefined, true);
} else tags.push(Boolean(autoTag) && parser.gullet.macros.get("\\@eqnsw") === "1");
}
}
beginRow(); // Test for \hline at the top of the array.
hLinesBeforeRow.push(getHLines(parser));
while(true){
// eslint-disable-line no-constant-condition
// Parse each cell in its own group (namespace)
var cell = parser.parseExpression(false, singleRow ? "\\end" : "\\\\");
parser.gullet.endGroup();
parser.gullet.beginGroup();
cell = {
type: "ordgroup",
mode: parser.mode,
body: cell
};
if (style) cell = {
type: "styling",
mode: parser.mode,
style,
body: [
cell
]
};
row.push(cell);
var next = parser.fetch().text;
if (next === "&") {
if (maxNumCols && row.length === maxNumCols) {
if (singleRow || colSeparationType) // {equation} or {split}
throw new ParseError("Too many tab characters: &", parser.nextToken);
else // {array} environment
parser.settings.reportNonstrict("textEnv", "Too few columns specified in the {array} column argument.");
}
parser.consume();
} else if (next === "\\end") {
endRow(); // Arrays terminate newlines with `\crcr` which consumes a `\cr` if
// the last line is empty. However, AMS environments keep the
// empty row if it's the only one.
// NOTE: Currently, `cell` is the last item added into `row`.
if (row.length === 1 && cell.type === "styling" && cell.body[0].body.length === 0 && (body.length > 1 || !emptySingleRow)) body.pop();
if (hLinesBeforeRow.length < body.length + 1) hLinesBeforeRow.push([]);
break;
} else if (next === "\\\\") {
parser.consume();
var size = void 0; // \def\Let@{\let\\\math@cr}
// \def\math@cr{...\math@cr@}
// \def\math@cr@{\new@ifnextchar[\math@cr@@{\math@cr@@[\z@]}}
// \def\math@cr@@[#1]{...\math@cr@@@...}
// \def\math@cr@@@{\cr}
if (parser.gullet.future().text !== " ") size = parser.parseSizeGroup(true);
rowGaps.push(size ? size.value : null);
endRow(); // check for \hline(s) following the row separator
hLinesBeforeRow.push(getHLines(parser));
row = [];
body.push(row);
beginRow();
} else throw new ParseError("Expected & or \\\\ or \\cr or \\end", parser.nextToken);
} // End cell group
parser.gullet.endGroup(); // End array group defining \cr
parser.gullet.endGroup();
return {
type: "array",
mode: parser.mode,
addJot,
arraystretch,
body,
cols,
rowGaps,
hskipBeforeAndAfter,
hLinesBeforeRow,
colSeparationType,
tags,
leqno
};
} // Decides on a style for cells in an array according to whether the given
// environment name starts with the letter 'd'.
function dCellStyle(envName) {
if (envName.slice(0, 1) === "d") return "display";
else return "text";
}
var htmlBuilder$6 = function htmlBuilder(group, options) {
var r;
var c;
var nr = group.body.length;
var hLinesBeforeRow = group.hLinesBeforeRow;
var nc = 0;
var body = new Array(nr);
var hlines = [];
var ruleThickness = Math.max(options.fontMetrics().arrayRuleWidth, options.minRuleThickness // User override.
); // Horizontal spacing
var pt = 1 / options.fontMetrics().ptPerEm;
var arraycolsep = 5 * pt; // default value, i.e. \arraycolsep in article.cls
if (group.colSeparationType && group.colSeparationType === "small") {
// We're in a {smallmatrix}. Default column space is \thickspace,
// i.e. 5/18em = 0.2778em, per amsmath.dtx for {smallmatrix}.
// But that needs adjustment because LaTeX applies \scriptstyle to the
// entire array, including the colspace, but this function applies
// \scriptstyle only inside each element.
var localMultiplier = options.havingStyle(Style$1.SCRIPT).sizeMultiplier;
arraycolsep = 0.2778 * (localMultiplier / options.sizeMultiplier);
} // Vertical spacing
var baselineskip = group.colSeparationType === "CD" ? calculateSize({
number: 3,
unit: "ex"
}, options) : 12 * pt; // see size10.clo
// Default \jot from ltmath.dtx
// TODO(edemaine): allow overriding \jot via \setlength (#687)
var jot = 3 * pt;
var arrayskip = group.arraystretch * baselineskip;
var arstrutHeight = 0.7 * arrayskip; // \strutbox in ltfsstrc.dtx and
var arstrutDepth = 0.3 * arrayskip; // \@arstrutbox in lttab.dtx
var totalHeight = 0; // Set a position for \hline(s) at the top of the array, if any.
function setHLinePos(hlinesInGap) {
for(var i = 0; i < hlinesInGap.length; ++i){
if (i > 0) totalHeight += 0.25;
hlines.push({
pos: totalHeight,
isDashed: hlinesInGap[i]
});
}
}
setHLinePos(hLinesBeforeRow[0]);
for(r = 0; r < group.body.length; ++r){
var inrow = group.body[r];
var height = arstrutHeight; // \@array adds an \@arstrut
var depth = arstrutDepth; // to each tow (via the template)
if (nc < inrow.length) nc = inrow.length;
var outrow = new Array(inrow.length);
for(c = 0; c < inrow.length; ++c){
var elt = buildGroup$1(inrow[c], options);
if (depth < elt.depth) depth = elt.depth;
if (height < elt.height) height = elt.height;
outrow[c] = elt;
}
var rowGap = group.rowGaps[r];
var gap = 0;
if (rowGap) {
gap = calculateSize(rowGap, options);
if (gap > 0) {
// \@argarraycr
gap += arstrutDepth;
if (depth < gap) depth = gap; // \@xargarraycr
gap = 0;
}
} // In AMS multiline environments such as aligned and gathered, rows
// correspond to lines that have additional \jot added to the
// \baselineskip via \openup.
if (group.addJot) depth += jot;
outrow.height = height;
outrow.depth = depth;
totalHeight += height;
outrow.pos = totalHeight;
totalHeight += depth + gap; // \@yargarraycr
body[r] = outrow; // Set a position for \hline(s), if any.
setHLinePos(hLinesBeforeRow[r + 1]);
}
var offset = totalHeight / 2 + options.fontMetrics().axisHeight;
var colDescriptions = group.cols || [];
var cols = [];
var colSep;
var colDescrNum;
var tagSpans = [];
if (group.tags && group.tags.some((tag)=>tag)) // An environment with manual tags and/or automatic equation numbers.
// Create node(s), the latter of which trigger CSS counter increment.
for(r = 0; r < nr; ++r){
var rw = body[r];
var shift = rw.pos - offset;
var tag = group.tags[r];
var tagSpan = void 0;
if (tag === true) // automatic numbering
tagSpan = buildCommon.makeSpan([
"eqn-num"
], [], options);
else if (tag === false) // \nonumber/\notag or starred environment
tagSpan = buildCommon.makeSpan([], [], options);
else // manual \tag
tagSpan = buildCommon.makeSpan([], buildExpression$1(tag, options, true), options);
tagSpan.depth = rw.depth;
tagSpan.height = rw.height;
tagSpans.push({
type: "elem",
elem: tagSpan,
shift
});
}
for(c = 0, colDescrNum = 0; // descriptions, so trailing separators don't get lost.
c < nc || colDescrNum < colDescriptions.length; ++c, ++colDescrNum){
var colDescr = colDescriptions[colDescrNum] || {};
var firstSeparator = true;
while(colDescr.type === "separator"){
// If there is more than one separator in a row, add a space
// between them.
if (!firstSeparator) {
colSep = buildCommon.makeSpan([
"arraycolsep"
], []);
colSep.style.width = makeEm(options.fontMetrics().doubleRuleSep);
cols.push(colSep);
}
if (colDescr.separator === "|" || colDescr.separator === ":") {
var lineType = colDescr.separator === "|" ? "solid" : "dashed";
var separator = buildCommon.makeSpan([
"vertical-separator"
], [], options);
separator.style.height = makeEm(totalHeight);
separator.style.borderRightWidth = makeEm(ruleThickness);
separator.style.borderRightStyle = lineType;
separator.style.margin = "0 " + makeEm(-ruleThickness / 2);
var _shift = totalHeight - offset;
if (_shift) separator.style.verticalAlign = makeEm(-_shift);
cols.push(separator);
} else throw new ParseError("Invalid separator type: " + colDescr.separator);
colDescrNum++;
colDescr = colDescriptions[colDescrNum] || {};
firstSeparator = false;
}
if (c >= nc) continue;
var sepwidth = void 0;
if (c > 0 || group.hskipBeforeAndAfter) {
sepwidth = utils.deflt(colDescr.pregap, arraycolsep);
if (sepwidth !== 0) {
colSep = buildCommon.makeSpan([
"arraycolsep"
], []);
colSep.style.width = makeEm(sepwidth);
cols.push(colSep);
}
}
var col = [];
for(r = 0; r < nr; ++r){
var row = body[r];
var elem = row[c];
if (!elem) continue;
var _shift2 = row.pos - offset;
elem.depth = row.depth;
elem.height = row.height;
col.push({
type: "elem",
elem: elem,
shift: _shift2
});
}
col = buildCommon.makeVList({
positionType: "individualShift",
children: col
}, options);
col = buildCommon.makeSpan([
"col-align-" + (colDescr.align || "c")
], [
col
]);
cols.push(col);
if (c < nc - 1 || group.hskipBeforeAndAfter) {
sepwidth = utils.deflt(colDescr.postgap, arraycolsep);
if (sepwidth !== 0) {
colSep = buildCommon.makeSpan([
"arraycolsep"
], []);
colSep.style.width = makeEm(sepwidth);
cols.push(colSep);
}
}
}
body = buildCommon.makeSpan([
"mtable"
], cols); // Add \hline(s), if any.
if (hlines.length > 0) {
var line = buildCommon.makeLineSpan("hline", options, ruleThickness);
var dashes = buildCommon.makeLineSpan("hdashline", options, ruleThickness);
var vListElems = [
{
type: "elem",
elem: body,
shift: 0
}
];
while(hlines.length > 0){
var hline = hlines.pop();
var lineShift = hline.pos - offset;
if (hline.isDashed) vListElems.push({
type: "elem",
elem: dashes,
shift: lineShift
});
else vListElems.push({
type: "elem",
elem: line,
shift: lineShift
});
}
body = buildCommon.makeVList({
positionType: "individualShift",
children: vListElems
}, options);
}
if (tagSpans.length === 0) return buildCommon.makeSpan([
"mord"
], [
body
], options);
else {
var eqnNumCol = buildCommon.makeVList({
positionType: "individualShift",
children: tagSpans
}, options);
eqnNumCol = buildCommon.makeSpan([
"tag"
], [
eqnNumCol
], options);
return buildCommon.makeFragment([
body,
eqnNumCol
]);
}
};
var alignMap = {
c: "center ",
l: "left ",
r: "right "
};
var mathmlBuilder$5 = function mathmlBuilder(group, options) {
var tbl = [];
var glue = new mathMLTree.MathNode("mtd", [], [
"mtr-glue"
]);
var tag = new mathMLTree.MathNode("mtd", [], [
"mml-eqn-num"
]);
for(var i = 0; i < group.body.length; i++){
var rw = group.body[i];
var row = [];
for(var j = 0; j < rw.length; j++)row.push(new mathMLTree.MathNode("mtd", [
buildGroup(rw[j], options)
]));
if (group.tags && group.tags[i]) {
row.unshift(glue);
row.push(glue);
if (group.leqno) row.unshift(tag);
else row.push(tag);
}
tbl.push(new mathMLTree.MathNode("mtr", row));
}
var table = new mathMLTree.MathNode("mtable", tbl); // Set column alignment, row spacing, column spacing, and
// array lines by setting attributes on the table element.
// Set the row spacing. In MathML, we specify a gap distance.
// We do not use rowGap[] because MathML automatically increases
// cell height with the height/depth of the element content.
// LaTeX \arraystretch multiplies the row baseline-to-baseline distance.
// We simulate this by adding (arraystretch - 1)em to the gap. This
// does a reasonable job of adjusting arrays containing 1 em tall content.
// The 0.16 and 0.09 values are found empirically. They produce an array
// similar to LaTeX and in which content does not interfere with \hlines.
var gap = group.arraystretch === 0.5 ? 0.1 // {smallmatrix}, {subarray}
: 0.16 + group.arraystretch - 1 + (group.addJot ? 0.09 : 0);
table.setAttribute("rowspacing", makeEm(gap)); // MathML table lines go only between cells.
// To place a line on an edge we'll use <menclose>, if necessary.
var menclose = "";
var align = "";
if (group.cols && group.cols.length > 0) {
// Find column alignment, column spacing, and vertical lines.
var cols = group.cols;
var columnLines = "";
var prevTypeWasAlign = false;
var iStart = 0;
var iEnd = cols.length;
if (cols[0].type === "separator") {
menclose += "top ";
iStart = 1;
}
if (cols[cols.length - 1].type === "separator") {
menclose += "bottom ";
iEnd -= 1;
}
for(var _i = iStart; _i < iEnd; _i++){
if (cols[_i].type === "align") {
align += alignMap[cols[_i].align];
if (prevTypeWasAlign) columnLines += "none ";
prevTypeWasAlign = true;
} else if (cols[_i].type === "separator") // MathML accepts only single lines between cells.
// So we read only the first of consecutive separators.
{
if (prevTypeWasAlign) {
columnLines += cols[_i].separator === "|" ? "solid " : "dashed ";
prevTypeWasAlign = false;
}
}
}
table.setAttribute("columnalign", align.trim());
if (/[sd]/.test(columnLines)) table.setAttribute("columnlines", columnLines.trim());
} // Set column spacing.
if (group.colSeparationType === "align") {
var _cols = group.cols || [];
var spacing = "";
for(var _i2 = 1; _i2 < _cols.length; _i2++)spacing += _i2 % 2 ? "0em " : "1em ";
table.setAttribute("columnspacing", spacing.trim());
} else if (group.colSeparationType === "alignat" || group.colSeparationType === "gather") table.setAttribute("columnspacing", "0em");
else if (group.colSeparationType === "small") table.setAttribute("columnspacing", "0.2778em");
else if (group.colSeparationType === "CD") table.setAttribute("columnspacing", "0.5em");
else table.setAttribute("columnspacing", "1em");
// Address \hline and \hdashline
var rowLines = "";
var hlines = group.hLinesBeforeRow;
menclose += hlines[0].length > 0 ? "left " : "";
menclose += hlines[hlines.length - 1].length > 0 ? "right " : "";
for(var _i3 = 1; _i3 < hlines.length - 1; _i3++)rowLines += hlines[_i3].length === 0 ? "none " // MathML accepts only a single line between rows. Read one element.
: hlines[_i3][0] ? "dashed " : "solid ";
if (/[sd]/.test(rowLines)) table.setAttribute("rowlines", rowLines.trim());
if (menclose !== "") {
table = new mathMLTree.MathNode("menclose", [
table
]);
table.setAttribute("notation", menclose.trim());
}
if (group.arraystretch && group.arraystretch < 1) {
// A small array. Wrap in scriptstyle so row gap is not too large.
table = new mathMLTree.MathNode("mstyle", [
table
]);
table.setAttribute("scriptlevel", "1");
}
return table;
}; // Convenience function for align, align*, aligned, alignat, alignat*, alignedat.
var alignedHandler = function alignedHandler(context, args) {
if (context.envName.indexOf("ed") === -1) validateAmsEnvironmentContext(context);
var cols = [];
var separationType = context.envName.indexOf("at") > -1 ? "alignat" : "align";
var isSplit = context.envName === "split";
var res = parseArray(context.parser, {
cols,
addJot: true,
autoTag: isSplit ? undefined : getAutoTag(context.envName),
emptySingleRow: true,
colSeparationType: separationType,
maxNumCols: isSplit ? 2 : undefined,
leqno: context.parser.settings.leqno
}, "display"); // Determining number of columns.
// 1. If the first argument is given, we use it as a number of columns,
// and makes sure that each row doesn't exceed that number.
// 2. Otherwise, just count number of columns = maximum number
// of cells in each row ("aligned" mode -- isAligned will be true).
//
// At the same time, prepend empty group {} at beginning of every second
// cell in each row (starting with second cell) so that operators become
// binary. This behavior is implemented in amsmath's \start@aligned.
var numMaths;
var numCols = 0;
var emptyGroup = {
type: "ordgroup",
mode: context.mode,
body: []
};
if (args[0] && args[0].type === "ordgroup") {
var arg0 = "";
for(var i = 0; i < args[0].body.length; i++){
var textord = assertNodeType(args[0].body[i], "textord");
arg0 += textord.text;
}
numMaths = Number(arg0);
numCols = numMaths * 2;
}
var isAligned = !numCols;
res.body.forEach(function(row) {
for(var _i4 = 1; _i4 < row.length; _i4 += 2){
// Modify ordgroup node within styling node
var styling = assertNodeType(row[_i4], "styling");
var ordgroup = assertNodeType(styling.body[0], "ordgroup");
ordgroup.body.unshift(emptyGroup);
}
if (!isAligned) {
// Case 1
var curMaths = row.length / 2;
if (numMaths < curMaths) throw new ParseError("Too many math in a row: " + ("expected " + numMaths + ", but got " + curMaths), row[0]);
} else if (numCols < row.length) // Case 2
numCols = row.length;
}); // Adjusting alignment.
// In aligned mode, we add one \qquad between columns;
// otherwise we add nothing.
for(var _i5 = 0; _i5 < numCols; ++_i5){
var align = "r";
var pregap = 0;
if (_i5 % 2 === 1) align = "l";
else if (_i5 > 0 && isAligned) // "aligned" mode.
pregap = 1; // add one \quad
cols[_i5] = {
type: "align",
align: align,
pregap: pregap,
postgap: 0
};
}
res.colSeparationType = isAligned ? "align" : "alignat";
return res;
}; // Arrays are part of LaTeX, defined in lttab.dtx so its documentation
// is part of the source2e.pdf file of LaTeX2e source documentation.
// {darray} is an {array} environment where cells are set in \displaystyle,
// as defined in nccmath.sty.
defineEnvironment({
type: "array",
names: [
"array",
"darray"
],
props: {
numArgs: 1
},
handler (context, args) {
// Since no types are specified above, the two possibilities are
// - The argument is wrapped in {} or [], in which case Parser's
// parseGroup() returns an "ordgroup" wrapping some symbol node.
// - The argument is a bare symbol node.
var symNode = checkSymbolNodeType(args[0]);
var colalign = symNode ? [
args[0]
] : assertNodeType(args[0], "ordgroup").body;
var cols = colalign.map(function(nde) {
var node = assertSymbolNodeType(nde);
var ca = node.text;
if ("lcr".indexOf(ca) !== -1) return {
type: "align",
align: ca
};
else if (ca === "|") return {
type: "separator",
separator: "|"
};
else if (ca === ":") return {
type: "separator",
separator: ":"
};
throw new ParseError("Unknown column alignment: " + ca, nde);
});
var res = {
cols,
hskipBeforeAndAfter: true,
// \@preamble in lttab.dtx
maxNumCols: cols.length
};
return parseArray(context.parser, res, dCellStyle(context.envName));
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
}); // The matrix environments of amsmath builds on the array environment
// of LaTeX, which is discussed above.
// The mathtools package adds starred versions of the same environments.
// These have an optional argument to choose left|center|right justification.
defineEnvironment({
type: "array",
names: [
"matrix",
"pmatrix",
"bmatrix",
"Bmatrix",
"vmatrix",
"Vmatrix",
"matrix*",
"pmatrix*",
"bmatrix*",
"Bmatrix*",
"vmatrix*",
"Vmatrix*"
],
props: {
numArgs: 0
},
handler (context) {
var delimiters = {
"matrix": null,
"pmatrix": [
"(",
")"
],
"bmatrix": [
"[",
"]"
],
"Bmatrix": [
"\\{",
"\\}"
],
"vmatrix": [
"|",
"|"
],
"Vmatrix": [
"\\Vert",
"\\Vert"
]
}[context.envName.replace("*", "")]; // \hskip -\arraycolsep in amsmath
var colAlign = "c";
var payload = {
hskipBeforeAndAfter: false,
cols: [
{
type: "align",
align: colAlign
}
]
};
if (context.envName.charAt(context.envName.length - 1) === "*") {
// It's one of the mathtools starred functions.
// Parse the optional alignment argument.
var parser = context.parser;
parser.consumeSpaces();
if (parser.fetch().text === "[") {
parser.consume();
parser.consumeSpaces();
colAlign = parser.fetch().text;
if ("lcr".indexOf(colAlign) === -1) throw new ParseError("Expected l or c or r", parser.nextToken);
parser.consume();
parser.consumeSpaces();
parser.expect("]");
parser.consume();
payload.cols = [
{
type: "align",
align: colAlign
}
];
}
}
var res = parseArray(context.parser, payload, dCellStyle(context.envName)); // Populate cols with the correct number of column alignment specs.
var numCols = Math.max(0, ...res.body.map((row)=>row.length));
res.cols = new Array(numCols).fill({
type: "align",
align: colAlign
});
return delimiters ? {
type: "leftright",
mode: context.mode,
body: [
res
],
left: delimiters[0],
right: delimiters[1],
rightColor: undefined // \right uninfluenced by \color in array
} : res;
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
});
defineEnvironment({
type: "array",
names: [
"smallmatrix"
],
props: {
numArgs: 0
},
handler (context) {
var payload = {
arraystretch: 0.5
};
var res = parseArray(context.parser, payload, "script");
res.colSeparationType = "small";
return res;
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
});
defineEnvironment({
type: "array",
names: [
"subarray"
],
props: {
numArgs: 1
},
handler (context, args) {
// Parsing of {subarray} is similar to {array}
var symNode = checkSymbolNodeType(args[0]);
var colalign = symNode ? [
args[0]
] : assertNodeType(args[0], "ordgroup").body;
var cols = colalign.map(function(nde) {
var node = assertSymbolNodeType(nde);
var ca = node.text; // {subarray} only recognizes "l" & "c"
if ("lc".indexOf(ca) !== -1) return {
type: "align",
align: ca
};
throw new ParseError("Unknown column alignment: " + ca, nde);
});
if (cols.length > 1) throw new ParseError("{subarray} can contain only one column");
var res = {
cols,
hskipBeforeAndAfter: false,
arraystretch: 0.5
};
res = parseArray(context.parser, res, "script");
if (res.body.length > 0 && res.body[0].length > 1) throw new ParseError("{subarray} can contain only one column");
return res;
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
}); // A cases environment (in amsmath.sty) is almost equivalent to
// \def\arraystretch{1.2}%
// \left\{\begin{array}{@{}l@{\quad}l@{}} … \end{array}\right.
// {dcases} is a {cases} environment where cells are set in \displaystyle,
// as defined in mathtools.sty.
// {rcases} is another mathtools environment. It's brace is on the right side.
defineEnvironment({
type: "array",
names: [
"cases",
"dcases",
"rcases",
"drcases"
],
props: {
numArgs: 0
},
handler (context) {
var payload = {
arraystretch: 1.2,
cols: [
{
type: "align",
align: "l",
pregap: 0,
// TODO(kevinb) get the current style.
// For now we use the metrics for TEXT style which is what we were
// doing before. Before attempting to get the current style we
// should look at TeX's behavior especially for \over and matrices.
postgap: 1.0
},
{
type: "align",
align: "l",
pregap: 0,
postgap: 0
}
]
};
var res = parseArray(context.parser, payload, dCellStyle(context.envName));
return {
type: "leftright",
mode: context.mode,
body: [
res
],
left: context.envName.indexOf("r") > -1 ? "." : "\\{",
right: context.envName.indexOf("r") > -1 ? "\\}" : ".",
rightColor: undefined
};
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
}); // In the align environment, one uses ampersands, &, to specify number of
// columns in each row, and to locate spacing between each column.
// align gets automatic numbering. align* and aligned do not.
// The alignedat environment can be used in math mode.
// Note that we assume \nomallineskiplimit to be zero,
// so that \strut@ is the same as \strut.
defineEnvironment({
type: "array",
names: [
"align",
"align*",
"aligned",
"split"
],
props: {
numArgs: 0
},
handler: alignedHandler,
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
}); // A gathered environment is like an array environment with one centered
// column, but where rows are considered lines so get \jot line spacing
// and contents are set in \displaystyle.
defineEnvironment({
type: "array",
names: [
"gathered",
"gather",
"gather*"
],
props: {
numArgs: 0
},
handler (context) {
if (utils.contains([
"gather",
"gather*"
], context.envName)) validateAmsEnvironmentContext(context);
var res = {
cols: [
{
type: "align",
align: "c"
}
],
addJot: true,
colSeparationType: "gather",
autoTag: getAutoTag(context.envName),
emptySingleRow: true,
leqno: context.parser.settings.leqno
};
return parseArray(context.parser, res, "display");
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
}); // alignat environment is like an align environment, but one must explicitly
// specify maximum number of columns in each row, and can adjust spacing between
// each columns.
defineEnvironment({
type: "array",
names: [
"alignat",
"alignat*",
"alignedat"
],
props: {
numArgs: 1
},
handler: alignedHandler,
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
});
defineEnvironment({
type: "array",
names: [
"equation",
"equation*"
],
props: {
numArgs: 0
},
handler (context) {
validateAmsEnvironmentContext(context);
var res = {
autoTag: getAutoTag(context.envName),
emptySingleRow: true,
singleRow: true,
maxNumCols: 1,
leqno: context.parser.settings.leqno
};
return parseArray(context.parser, res, "display");
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
});
defineEnvironment({
type: "array",
names: [
"CD"
],
props: {
numArgs: 0
},
handler (context) {
validateAmsEnvironmentContext(context);
return parseCD(context.parser);
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
});
defineMacro("\\nonumber", "\\gdef\\@eqnsw{0}");
defineMacro("\\notag", "\\nonumber"); // Catch \hline outside array environment
defineFunction({
type: "text",
// Doesn't matter what this is.
names: [
"\\hline",
"\\hdashline"
],
props: {
numArgs: 0,
allowedInText: true,
allowedInMath: true
},
handler (context, args) {
throw new ParseError(context.funcName + " valid only within array environment");
}
});
var environments = _environments;
// defineEnvironment definitions.
defineFunction({
type: "environment",
names: [
"\\begin",
"\\end"
],
props: {
numArgs: 1,
argTypes: [
"text"
]
},
handler (_ref, args) {
var { parser, funcName } = _ref;
var nameGroup = args[0];
if (nameGroup.type !== "ordgroup") throw new ParseError("Invalid environment name", nameGroup);
var envName = "";
for(var 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.
var env = environments[envName];
var { args: _args, optArgs } = parser.parseArguments("\\begin{" + envName + "}", env);
var context = {
mode: parser.mode,
envName,
parser
};
var result = env.handler(context, _args, optArgs);
parser.expect("\\end", false);
var endNameToken = parser.nextToken;
var 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
};
}
});
// TODO(kevinb): implement \\sl and \\sc
var htmlBuilder$5 = (group, options)=>{
var font = group.font;
var newOptions = options.withFont(font);
return buildGroup$1(group.body, newOptions);
};
var mathmlBuilder$4 = (group, options)=>{
var font = group.font;
var newOptions = options.withFont(font);
return buildGroup(group.body, newOptions);
};
var fontAliases = {
"\\Bbb": "\\mathbb",
"\\bold": "\\mathbf",
"\\frak": "\\mathfrak",
"\\bm": "\\boldsymbol"
};
defineFunction({
type: "font",
names: [
"\\mathrm",
"\\mathit",
"\\mathbf",
"\\mathnormal",
"\\mathbb",
"\\mathcal",
"\\mathfrak",
"\\mathscr",
"\\mathsf",
"\\mathtt",
"\\Bbb",
"\\bold",
"\\frak"
],
props: {
numArgs: 1,
allowedInArgument: true
},
handler: (_ref, args)=>{
var { parser, funcName } = _ref;
var body = normalizeArgument(args[0]);
var func = funcName;
if (func in fontAliases) func = fontAliases[func];
return {
type: "font",
mode: parser.mode,
font: func.slice(1),
body
};
},
htmlBuilder: htmlBuilder$5,
mathmlBuilder: mathmlBuilder$4
});
defineFunction({
type: "mclass",
names: [
"\\boldsymbol",
"\\bm"
],
props: {
numArgs: 1
},
handler: (_ref2, args)=>{
var { parser } = _ref2;
var body = args[0];
var 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: (_ref3, args)=>{
var { parser, funcName, breakOnTokenText } = _ref3;
var { mode } = parser;
var body = parser.parseExpression(true, breakOnTokenText);
var style = "math" + funcName.slice(1);
return {
type: "font",
mode: mode,
font: style,
body: {
type: "ordgroup",
mode: parser.mode,
body
}
};
},
htmlBuilder: htmlBuilder$5,
mathmlBuilder: mathmlBuilder$4
});
var adjustStyle = (size, originalStyle)=>{
// Figure out what style this fraction should be in based on the
// function used
var 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$1.SCRIPT.id ? style.text() : Style$1.DISPLAY;
else if (size === "text" && style.size === Style$1.DISPLAY.size) // We're in a \tfrac but incoming style is displaystyle, so:
style = Style$1.TEXT;
else if (size === "script") style = Style$1.SCRIPT;
else if (size === "scriptscript") style = Style$1.SCRIPTSCRIPT;
return style;
};
var htmlBuilder$4 = (group, options)=>{
// Fractions are handled in the TeXbook on pages 444-445, rules 15(a-e).
var style = adjustStyle(group.size, options.style);
var nstyle = style.fracNum();
var dstyle = style.fracDen();
var newOptions;
newOptions = options.havingStyle(nstyle);
var numerm = buildGroup$1(group.numer, newOptions, options);
if (group.continued) {
// \cfrac inserts a \strut into the numerator.
// Get \strut dimensions from TeXbook page 353.
var hStrut = 8.5 / options.fontMetrics().ptPerEm;
var 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);
var denomm = buildGroup$1(group.denom, newOptions, options);
var rule;
var ruleWidth;
var 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
var numShift;
var clearance;
var denomShift;
if (style.size === Style$1.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;
}
var frac;
if (!rule) {
// Rule 15c
var 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
var 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));
var 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
var delimSize;
if (style.size === Style$1.DISPLAY.size) delimSize = options.fontMetrics().delim1;
else if (style.size === Style$1.SCRIPTSCRIPT.size) delimSize = options.havingStyle(Style$1.SCRIPT).fontMetrics().delim2;
else delimSize = options.fontMetrics().delim2;
var leftDelim;
var rightDelim;
if (group.leftDelim == null) leftDelim = 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 = 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);
};
var mathmlBuilder$3 = (group, options)=>{
var node = new mathMLTree.MathNode("mfrac", [
buildGroup(group.numer, options),
buildGroup(group.denom, options)
]);
if (!group.hasBarLine) node.setAttribute("linethickness", "0px");
else if (group.barSize) {
var ruleWidth = calculateSize(group.barSize, options);
node.setAttribute("linethickness", makeEm(ruleWidth));
}
var style = adjustStyle(group.size, options.style);
if (style.size !== options.style.size) {
node = new mathMLTree.MathNode("mstyle", [
node
]);
var isDisplay = style.size === Style$1.DISPLAY.size ? "true" : "false";
node.setAttribute("displaystyle", isDisplay);
node.setAttribute("scriptlevel", "0");
}
if (group.leftDelim != null || group.rightDelim != null) {
var withDelims = [];
if (group.leftDelim != null) {
var 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) {
var rightOp = new mathMLTree.MathNode("mo", [
new mathMLTree.TextNode(group.rightDelim.replace("\\", ""))
]);
rightOp.setAttribute("fence", "true");
withDelims.push(rightOp);
}
return makeRow(withDelims);
}
return node;
};
defineFunction({
type: "genfrac",
names: [
"\\dfrac",
"\\frac",
"\\tfrac",
"\\dbinom",
"\\binom",
"\\tbinom",
"\\\\atopfrac",
"\\\\bracefrac",
"\\\\brackfrac" // ditto
],
props: {
numArgs: 2,
allowedInArgument: true
},
handler: (_ref, args)=>{
var { parser, funcName } = _ref;
var numer = args[0];
var denom = args[1];
var hasBarLine;
var leftDelim = null;
var rightDelim = null;
var 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: htmlBuilder$4,
mathmlBuilder: mathmlBuilder$3
});
defineFunction({
type: "genfrac",
names: [
"\\cfrac"
],
props: {
numArgs: 2
},
handler: (_ref2, args)=>{
var { parser, funcName } = _ref2;
var numer = args[0];
var 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 (_ref3) {
var { parser, funcName, token } = _ref3;
var 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
};
}
});
var stylArray = [
"display",
"text",
"script",
"scriptscript"
];
var delimFromValue = function delimFromValue(delimString) {
var 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 (_ref4, args) {
var { parser } = _ref4;
var numer = args[4];
var denom = args[5]; // Look into the parse nodes to get the desired delimiters.
var leftNode = normalizeArgument(args[0]);
var leftDelim = leftNode.type === "atom" && leftNode.family === "open" ? delimFromValue(leftNode.text) : null;
var rightNode = normalizeArgument(args[1]);
var rightDelim = rightNode.type === "atom" && rightNode.family === "close" ? delimFromValue(rightNode.text) : null;
var barNode = assertNodeType(args[2], "size");
var hasBarLine;
var 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.
var size = "auto";
var styl = args[3];
if (styl.type === "ordgroup") {
if (styl.body.length > 0) {
var 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: htmlBuilder$4,
mathmlBuilder: mathmlBuilder$3
}); // \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 (_ref5, args) {
var { parser, funcName, token } = _ref5;
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: (_ref6, args)=>{
var { parser, funcName } = _ref6;
var numer = args[0];
var barSize = assert(assertNodeType(args[1], "infix").size);
var denom = args[2];
var hasBarLine = barSize.number > 0;
return {
type: "genfrac",
mode: parser.mode,
numer,
denom,
continued: false,
hasBarLine,
barSize,
leftDelim: null,
rightDelim: null,
size: "auto"
};
},
htmlBuilder: htmlBuilder$4,
mathmlBuilder: mathmlBuilder$3
});
// NOTE: Unlike most `htmlBuilder`s, this one handles not only "horizBrace", but
// also "supsub" since an over/underbrace can affect super/subscripting.
var htmlBuilder$3 = (grp, options)=>{
var style = options.style; // Pull out the `ParseNode<"horizBrace">` if `grp` is a "supsub" node.
var supSubGroup;
var group;
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 ? buildGroup$1(grp.sup, options.havingStyle(style.sup()), options) : buildGroup$1(grp.sub, options.havingStyle(style.sub()), options);
group = assertNodeType(grp.base, "horizBrace");
} else group = assertNodeType(grp, "horizBrace");
// Build the base group
var body = buildGroup$1(group.base, options.havingBaseStyle(Style$1.DISPLAY)); // Create the stretchy element
var braceBody = stretchy.svgSpan(group, options); // Generate the vlist, with the appropriate kerns ┏━━━━━━━━┓
// This first vlist contains the content and the brace: equation
var 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
var 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);
};
var mathmlBuilder$2 = (group, options)=>{
var accentNode = stretchy.mathMLnode(group.label);
return new mathMLTree.MathNode(group.isOver ? "mover" : "munder", [
buildGroup(group.base, options),
accentNode
]);
}; // Horizontal stretchy braces
defineFunction({
type: "horizBrace",
names: [
"\\overbrace",
"\\underbrace"
],
props: {
numArgs: 1
},
handler (_ref, args) {
var { parser, funcName } = _ref;
return {
type: "horizBrace",
mode: parser.mode,
label: funcName,
isOver: /^\\over/.test(funcName),
base: args[0]
};
},
htmlBuilder: htmlBuilder$3,
mathmlBuilder: mathmlBuilder$2
});
defineFunction({
type: "href",
names: [
"\\href"
],
props: {
numArgs: 2,
argTypes: [
"url",
"original"
],
allowedInText: true
},
handler: (_ref, args)=>{
var { parser } = _ref;
var body = args[1];
var 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)=>{
var elements = buildExpression$1(group.body, options, false);
return buildCommon.makeAnchor(group.href, [], elements, options);
},
mathmlBuilder: (group, options)=>{
var math = 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: (_ref2, args)=>{
var { parser } = _ref2;
var href = assertNodeType(args[0], "url").url;
if (!parser.settings.isTrusted({
command: "\\url",
url: href
})) return parser.formatUnsupportedCmd("\\url");
var chars = [];
for(var i = 0; i < href.length; i++){
var c = href[i];
if (c === "~") c = "\\textasciitilde";
chars.push({
type: "textord",
mode: "text",
text: c
});
}
var body = {
type: "text",
mode: parser.mode,
font: "\\texttt",
body: chars
};
return {
type: "href",
mode: parser.mode,
href,
body: ordargument(body)
};
}
});
// 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 (_ref, args) {
var { parser } = _ref;
return {
type: "hbox",
mode: parser.mode,
body: ordargument(args[0])
};
},
htmlBuilder (group, options) {
var elements = buildExpression$1(group.body, options, false);
return buildCommon.makeFragment(elements);
},
mathmlBuilder (group, options) {
return new mathMLTree.MathNode("mrow", buildExpression(group.body, options));
}
});
defineFunction({
type: "html",
names: [
"\\htmlClass",
"\\htmlId",
"\\htmlStyle",
"\\htmlData"
],
props: {
numArgs: 2,
argTypes: [
"raw",
"original"
],
allowedInText: true
},
handler: (_ref, args)=>{
var { parser, funcName, token } = _ref;
var value = assertNodeType(args[0], "raw").string;
var body = args[1];
if (parser.settings.strict) parser.settings.reportNonstrict("htmlExtension", "HTML extension is disabled on strict mode");
var trustContext;
var 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":
var data = value.split(",");
for(var i = 0; i < data.length; i++){
var 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)=>{
var elements = buildExpression$1(group.body, options, false);
var classes = [
"enclosing"
];
if (group.attributes.class) classes.push(...group.attributes.class.trim().split(/\s+/));
var span = buildCommon.makeSpan(classes, elements, options);
for(var attr in group.attributes)if (attr !== "class" && group.attributes.hasOwnProperty(attr)) span.setAttribute(attr, group.attributes[attr]);
return span;
},
mathmlBuilder: (group, options)=>{
return buildExpressionRow(group.body, options);
}
});
defineFunction({
type: "htmlmathml",
names: [
"\\html@mathml"
],
props: {
numArgs: 2,
allowedInText: true
},
handler: (_ref, args)=>{
var { parser } = _ref;
return {
type: "htmlmathml",
mode: parser.mode,
html: ordargument(args[0]),
mathml: ordargument(args[1])
};
},
htmlBuilder: (group, options)=>{
var elements = buildExpression$1(group.html, options, false);
return buildCommon.makeFragment(elements);
},
mathmlBuilder: (group, options)=>{
return buildExpressionRow(group.mathml, options);
}
});
var sizeData = function sizeData(str) {
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 {
var match = /([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(str);
if (!match) throw new ParseError("Invalid size: '" + str + "' in \\includegraphics");
var 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: (_ref, args, optArgs)=>{
var { parser } = _ref;
var width = {
number: 0,
unit: "em"
};
var height = {
number: 0.9,
unit: "em"
}; // sorta character sized.
var totalheight = {
number: 0,
unit: "em"
};
var alt = "";
if (optArgs[0]) {
var attributeStr = assertNodeType(optArgs[0], "raw").string; // Parser.js does not parse key/value pairs. We get a string.
var attributes = attributeStr.split(",");
for(var i = 0; i < attributes.length; i++){
var keyVal = attributes[i].split("=");
if (keyVal.length === 2) {
var 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.");
}
}
}
}
var 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)=>{
var height = calculateSize(group.height, options);
var depth = 0;
if (group.totalheight.number > 0) depth = calculateSize(group.totalheight, options) - height;
var width = 0;
if (group.width.number > 0) width = calculateSize(group.width, options);
var style = {
height: makeEm(height + depth)
};
if (width > 0) style.width = makeEm(width);
if (depth > 0) style.verticalAlign = makeEm(-depth);
var node = new Img(group.src, group.alt, style);
node.height = height;
node.depth = depth;
return node;
},
mathmlBuilder: (group, options)=>{
var node = new mathMLTree.MathNode("mglyph", []);
node.setAttribute("alt", group.alt);
var height = calculateSize(group.height, options);
var 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) {
var width = calculateSize(group.width, options);
node.setAttribute("width", makeEm(width));
}
node.setAttribute("src", group.src);
return node;
}
});
// Horizontal spacing commands
defineFunction({
type: "kern",
names: [
"\\kern",
"\\mkern",
"\\hskip",
"\\mskip"
],
props: {
numArgs: 1,
argTypes: [
"size"
],
primitive: true,
allowedInText: true
},
handler (_ref, args) {
var { parser, funcName } = _ref;
var size = assertNodeType(args[0], "size");
if (parser.settings.strict) {
var mathFunction = funcName[1] === 'm'; // \mkern, \mskip
var 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) {
var dimension = calculateSize(group.dimension, options);
return new mathMLTree.SpaceNode(dimension);
}
});
// Horizontal overlap functions
defineFunction({
type: "lap",
names: [
"\\mathllap",
"\\mathrlap",
"\\mathclap"
],
props: {
numArgs: 1,
allowedInText: true
},
handler: (_ref, args)=>{
var { parser, funcName } = _ref;
var body = args[0];
return {
type: "lap",
mode: parser.mode,
alignment: funcName.slice(5),
body
};
},
htmlBuilder: (group, options)=>{
// mathllap, mathrlap, mathclap
var inner;
if (group.alignment === "clap") {
// ref: https://www.math.lsu.edu/~aperlis/publications/mathclap/
inner = buildCommon.makeSpan([], [
buildGroup$1(group.body, options)
]); // wrap, since CSS will center a .clap > .inner > span
inner = buildCommon.makeSpan([
"inner"
], [
inner
], options);
} else inner = buildCommon.makeSpan([
"inner"
], [
buildGroup$1(group.body, options)
]);
var fix = buildCommon.makeSpan([
"fix"
], []);
var 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
var 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
var node = new mathMLTree.MathNode("mpadded", [
buildGroup(group.body, options)
]);
if (group.alignment !== "rlap") {
var offset = group.alignment === "llap" ? "-1" : "-0.5";
node.setAttribute("lspace", offset + "width");
}
node.setAttribute("width", "0px");
return node;
}
});
defineFunction({
type: "styling",
names: [
"\\(",
"$"
],
props: {
numArgs: 0,
allowedInText: true,
allowedInMath: false
},
handler (_ref, args) {
var { funcName, parser } = _ref;
var outerMode = parser.mode;
parser.switchMode("math");
var close = funcName === "\\(" ? "\\)" : "$";
var 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);
}
});
var chooseMathStyle = (group, options)=>{
switch(options.style.size){
case Style$1.DISPLAY.size:
return group.display;
case Style$1.TEXT.size:
return group.text;
case Style$1.SCRIPT.size:
return group.script;
case Style$1.SCRIPTSCRIPT.size:
return group.scriptscript;
default:
return group.text;
}
};
defineFunction({
type: "mathchoice",
names: [
"\\mathchoice"
],
props: {
numArgs: 4,
primitive: true
},
handler: (_ref, args)=>{
var { parser } = _ref;
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)=>{
var body = chooseMathStyle(group, options);
var elements = buildExpression$1(body, options, false);
return buildCommon.makeFragment(elements);
},
mathmlBuilder: (group, options)=>{
var body = chooseMathStyle(group, options);
return buildExpressionRow(body, options);
}
});
var assembleSupSub = (base, supGroup, subGroup, options, style, slant, baseShift)=>{
base = buildCommon.makeSpan([], [
base
]);
var subIsSingleCharacter = subGroup && utils.isCharacterBox(subGroup);
var sub;
var sup; // We manually have to handle the superscripts and subscripts. This,
// aside from the kern calculations, is copied from supsub.
if (supGroup) {
var elem = buildGroup$1(supGroup, options.havingStyle(style.sup()), options);
sup = {
elem,
kern: Math.max(options.fontMetrics().bigOpSpacing1, options.fontMetrics().bigOpSpacing3 - elem.depth)
};
}
if (subGroup) {
var _elem = buildGroup$1(subGroup, options.havingStyle(style.sub()), options);
sub = {
elem: _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.
var finalGroup;
if (sup && sub) {
var 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) {
var 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) {
var _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;
var 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.
var spacer = buildCommon.makeSpan([
"mspace"
], [], options);
spacer.style.marginRight = makeEm(slant);
parts.unshift(spacer);
}
return buildCommon.makeSpan([
"mop",
"op-limits"
], parts, options);
};
// Limits, symbols
// Most operators have a large successor symbol, but these don't.
var 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.
var htmlBuilder$2 = (grp, options)=>{
// Operators are handled in the TeXbook pg. 443-444, rule 13(a).
var supGroup;
var subGroup;
var hasLimits = false;
var group;
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");
var style = options.style;
var large = false;
if (style.size === Style$1.DISPLAY.size && group.symbol && !utils.contains(noSuccessor, group.name)) // Most symbol operators get larger in displaystyle (rule 13)
large = true;
var base;
if (group.symbol) {
// If this is a symbol, create the symbol.
var fontName = large ? "Size2-Regular" : "Size1-Regular";
var 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.
var italic = base.italic;
var 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.
var inner = buildExpression$1(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.
var output = [];
for(var 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.
var baseShift = 0;
var 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;
}
};
var mathmlBuilder$1 = (group, options)=>{
var node;
if (group.symbol) {
// This is a symbol. Just add the symbol.
node = new MathNode("mo", [
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 MathNode("mo", buildExpression(group.body, options));
else {
// This is a text operator. Add all of the characters from the
// operator's name.
node = new MathNode("mi", [
new TextNode(group.name.slice(1))
]); // Append an <mo>⁡</mo>.
// ref: https://www.w3.org/TR/REC-MathML/chap3_2.html#sec3.2.4
var operator = new MathNode("mo", [
makeText("\u2061", "text")
]);
if (group.parentIsSupSub) node = new MathNode("mrow", [
node,
operator
]);
else node = newDocumentFragment([
node,
operator
]);
}
return node;
};
var singleCharBigOps = {
"\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: (_ref, args)=>{
var { parser, funcName } = _ref;
var fName = funcName;
if (fName.length === 1) fName = singleCharBigOps[fName];
return {
type: "op",
mode: parser.mode,
limits: true,
parentIsSupSub: false,
symbol: true,
name: fName
};
},
htmlBuilder: htmlBuilder$2,
mathmlBuilder: mathmlBuilder$1
}); // 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: (_ref2, args)=>{
var { parser } = _ref2;
var body = args[0];
return {
type: "op",
mode: parser.mode,
limits: false,
parentIsSupSub: false,
symbol: false,
body: ordargument(body)
};
},
htmlBuilder: htmlBuilder$2,
mathmlBuilder: mathmlBuilder$1
}); // 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.
var singleCharIntegrals = {
"\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 (_ref3) {
var { parser, funcName } = _ref3;
return {
type: "op",
mode: parser.mode,
limits: false,
parentIsSupSub: false,
symbol: false,
name: funcName
};
},
htmlBuilder: htmlBuilder$2,
mathmlBuilder: mathmlBuilder$1
}); // Limits, not symbols
defineFunction({
type: "op",
names: [
"\\det",
"\\gcd",
"\\inf",
"\\lim",
"\\max",
"\\min",
"\\Pr",
"\\sup"
],
props: {
numArgs: 0
},
handler (_ref4) {
var { parser, funcName } = _ref4;
return {
type: "op",
mode: parser.mode,
limits: true,
parentIsSupSub: false,
symbol: false,
name: funcName
};
},
htmlBuilder: htmlBuilder$2,
mathmlBuilder: mathmlBuilder$1
}); // No limits, symbols
defineFunction({
type: "op",
names: [
"\\int",
"\\iint",
"\\iiint",
"\\oint",
"\\oiint",
"\\oiiint",
"\u222b",
"\u222c",
"\u222d",
"\u222e",
"\u222f",
"\u2230"
],
props: {
numArgs: 0
},
handler (_ref5) {
var { parser, funcName } = _ref5;
var fName = funcName;
if (fName.length === 1) fName = singleCharIntegrals[fName];
return {
type: "op",
mode: parser.mode,
limits: false,
parentIsSupSub: false,
symbol: true,
name: fName
};
},
htmlBuilder: htmlBuilder$2,
mathmlBuilder: mathmlBuilder$1
});
// NOTE: Unlike most `htmlBuilder`s, this one handles not only
// "operatorname", but also "supsub" since \operatorname* can
// affect super/subscripting.
var htmlBuilder$1 = (grp, options)=>{
// Operators are handled in the TeXbook pg. 443-444, rule 13(a).
var supGroup;
var subGroup;
var hasLimits = false;
var group;
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");
var base;
if (group.body.length > 0) {
var body = group.body.map((child)=>{
// $FlowFixMe: Check if the node has a string `text` property.
var childText = child.text;
if (typeof childText === "string") return {
type: "textord",
mode: child.mode,
text: childText
};
else return child;
}); // Consolidate function names into symbol characters.
var expression = buildExpression$1(body, options.withFont("mathrm"), true);
for(var i = 0; i < expression.length; i++){
var 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;
};
var mathmlBuilder = (group, options)=>{
// The steps taken here are similar to the html version.
var expression = buildExpression(group.body, options.withFont("mathrm")); // Is expression a string or has it something like a fraction?
var isAllString = true; // default
for(var i = 0; i < expression.length; i++){
var node = expression[i];
if (node instanceof mathMLTree.SpaceNode) ;
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":
var 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.
var word = expression.map((node)=>node.toText()).join("");
expression = [
new mathMLTree.TextNode(word)
];
}
var identifier = new mathMLTree.MathNode("mi", expression);
identifier.setAttribute("mathvariant", "normal"); // \u2061 is the same as ⁡
// ref: https://www.w3schools.com/charsets/ref_html_entities_a.asp
var operator = new mathMLTree.MathNode("mo", [
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: (_ref, args)=>{
var { parser, funcName } = _ref;
var body = args[0];
return {
type: "operatorname",
mode: parser.mode,
body: ordargument(body),
alwaysHandleSupSub: funcName === "\\operatornamewithlimits",
limits: false,
parentIsSupSub: false
};
},
htmlBuilder: htmlBuilder$1,
mathmlBuilder
});
defineMacro("\\operatorname", "\\@ifstar\\operatornamewithlimits\\operatorname@");
defineFunctionBuilders({
type: "ordgroup",
htmlBuilder (group, options) {
if (group.semisimple) return buildCommon.makeFragment(buildExpression$1(group.body, options, false));
return buildCommon.makeSpan([
"mord"
], buildExpression$1(group.body, options, true), options);
},
mathmlBuilder (group, options) {
return buildExpressionRow(group.body, options, true);
}
});
defineFunction({
type: "overline",
names: [
"\\overline"
],
props: {
numArgs: 1
},
handler (_ref, args) {
var { parser } = _ref;
var 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.
var innerGroup = buildGroup$1(group.body, options.havingCrampedStyle()); // Create the line above the body
var line = buildCommon.makeLineSpan("overline-line", options); // Generate the vlist, with the appropriate kerns
var defaultRuleThickness = options.fontMetrics().defaultRuleThickness;
var 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) {
var operator = new mathMLTree.MathNode("mo", [
new mathMLTree.TextNode("\u203e")
]);
operator.setAttribute("stretchy", "true");
var node = new mathMLTree.MathNode("mover", [
buildGroup(group.body, options),
operator
]);
node.setAttribute("accent", "true");
return node;
}
});
defineFunction({
type: "phantom",
names: [
"\\phantom"
],
props: {
numArgs: 1,
allowedInText: true
},
handler: (_ref, args)=>{
var { parser } = _ref;
var body = args[0];
return {
type: "phantom",
mode: parser.mode,
body: ordargument(body)
};
},
htmlBuilder: (group, options)=>{
var elements = buildExpression$1(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)=>{
var inner = buildExpression(group.body, options);
return new mathMLTree.MathNode("mphantom", inner);
}
});
defineFunction({
type: "hphantom",
names: [
"\\hphantom"
],
props: {
numArgs: 1,
allowedInText: true
},
handler: (_ref2, args)=>{
var { parser } = _ref2;
var body = args[0];
return {
type: "hphantom",
mode: parser.mode,
body
};
},
htmlBuilder: (group, options)=>{
var node = buildCommon.makeSpan([], [
buildGroup$1(group.body, options.withPhantom())
]);
node.height = 0;
node.depth = 0;
if (node.children) for(var 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)=>{
var inner = buildExpression(ordargument(group.body), options);
var phantom = new mathMLTree.MathNode("mphantom", inner);
var 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: (_ref3, args)=>{
var { parser } = _ref3;
var body = args[0];
return {
type: "vphantom",
mode: parser.mode,
body
};
},
htmlBuilder: (group, options)=>{
var inner = buildCommon.makeSpan([
"inner"
], [
buildGroup$1(group.body, options.withPhantom())
]);
var fix = buildCommon.makeSpan([
"fix"
], []);
return buildCommon.makeSpan([
"mord",
"rlap"
], [
inner,
fix
], options);
},
mathmlBuilder: (group, options)=>{
var inner = buildExpression(ordargument(group.body), options);
var phantom = new mathMLTree.MathNode("mphantom", inner);
var node = new mathMLTree.MathNode("mpadded", [
phantom
]);
node.setAttribute("width", "0px");
return node;
}
});
defineFunction({
type: "raisebox",
names: [
"\\raisebox"
],
props: {
numArgs: 2,
argTypes: [
"size",
"hbox"
],
allowedInText: true
},
handler (_ref, args) {
var { parser } = _ref;
var amount = assertNodeType(args[0], "size").value;
var body = args[1];
return {
type: "raisebox",
mode: parser.mode,
dy: amount,
body
};
},
htmlBuilder (group, options) {
var body = buildGroup$1(group.body, options);
var dy = calculateSize(group.dy, options);
return buildCommon.makeVList({
positionType: "shift",
positionData: -dy,
children: [
{
type: "elem",
elem: body
}
]
}, options);
},
mathmlBuilder (group, options) {
var node = new mathMLTree.MathNode("mpadded", [
buildGroup(group.body, options)
]);
var dy = group.dy.number + group.dy.unit;
node.setAttribute("voffset", dy);
return node;
}
});
defineFunction({
type: "internal",
names: [
"\\relax"
],
props: {
numArgs: 0,
allowedInText: true
},
handler (_ref) {
var { parser } = _ref;
return {
type: "internal",
mode: parser.mode
};
}
});
defineFunction({
type: "rule",
names: [
"\\rule"
],
props: {
numArgs: 2,
numOptionalArgs: 1,
argTypes: [
"size",
"size",
"size"
]
},
handler (_ref, args, optArgs) {
var { parser } = _ref;
var shift = optArgs[0];
var width = assertNodeType(args[0], "size");
var 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
var rule = buildCommon.makeSpan([
"mord",
"rule"
], [], options); // Calculate the shift, width, and height of the rule, and account for units
var width = calculateSize(group.width, options);
var height = calculateSize(group.height, options);
var 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) {
var width = calculateSize(group.width, options);
var height = calculateSize(group.height, options);
var shift = group.shift ? calculateSize(group.shift, options) : 0;
var color = options.color && options.getColor() || "black";
var rule = new mathMLTree.MathNode("mspace");
rule.setAttribute("mathbackground", color);
rule.setAttribute("width", makeEm(width));
rule.setAttribute("height", makeEm(height));
var 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;
}
});
function sizingGroup(value, options, baseOptions) {
var inner = buildExpression$1(value, options, false);
var multiplier = options.sizeMultiplier / baseOptions.sizeMultiplier; // Add size-resetting classes to the inner list and set maxFontSize
// manually. Handle nested size changes.
for(var i = 0; i < inner.length; i++){
var 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);
}
var sizeFuncs = [
"\\tiny",
"\\sixptsize",
"\\scriptsize",
"\\footnotesize",
"\\small",
"\\normalsize",
"\\large",
"\\Large",
"\\LARGE",
"\\huge",
"\\Huge"
];
var htmlBuilder = (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.
var newOptions = options.havingSize(group.size);
return sizingGroup(group.body, newOptions, options);
};
defineFunction({
type: "sizing",
names: sizeFuncs,
props: {
numArgs: 0,
allowedInText: true
},
handler: (_ref, args)=>{
var { breakOnTokenText, funcName, parser } = _ref;
var 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)=>{
var newOptions = options.havingSize(group.size);
var inner = buildExpression(group.body, newOptions);
var 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;
}
});
// smash, with optional [tb], as in AMS
defineFunction({
type: "smash",
names: [
"\\smash"
],
props: {
numArgs: 1,
numOptionalArgs: 1,
allowedInText: true
},
handler: (_ref, args, optArgs)=>{
var { parser } = _ref;
var smashHeight = false;
var smashDepth = false;
var 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}%
var letter = "";
for(var i = 0; i < tbArg.body.length; ++i){
var 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;
}
var body = args[0];
return {
type: "smash",
mode: parser.mode,
body,
smashHeight,
smashDepth
};
},
htmlBuilder: (group, options)=>{
var node = buildCommon.makeSpan([], [
buildGroup$1(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(var i = 0; i < node.children.length; i++)node.children[i].height = 0;
}
if (group.smashDepth) {
node.depth = 0;
if (node.children) for(var _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.
var 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)=>{
var node = new mathMLTree.MathNode("mpadded", [
buildGroup(group.body, options)
]);
if (group.smashHeight) node.setAttribute("height", "0px");
if (group.smashDepth) node.setAttribute("depth", "0px");
return node;
}
});
defineFunction({
type: "sqrt",
names: [
"\\sqrt"
],
props: {
numArgs: 1,
numOptionalArgs: 1
},
handler (_ref, args, optArgs) {
var { parser } = _ref;
var index = optArgs[0];
var 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
var inner = buildGroup$1(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
var metrics = options.fontMetrics();
var theta = metrics.defaultRuleThickness;
var phi = theta;
if (options.style.id < Style$1.TEXT.id) phi = options.fontMetrics().xHeight;
// Calculate the clearance between the body and line
var lineClearance = theta + phi / 4;
var minDelimiterHeight = inner.height + inner.depth + lineClearance + theta; // Create a sqrt SVG of the required minimum size
var { span: img, ruleWidth, advanceWidth } = delimiter.sqrtImage(minDelimiterHeight, options);
var 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
var imgShift = img.height - inner.height - lineClearance - ruleWidth;
inner.style.paddingLeft = makeEm(advanceWidth); // Overlay the image and the argument.
var 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
var newOptions = options.havingStyle(Style$1.SCRIPTSCRIPT);
var rootm = buildGroup$1(group.index, newOptions, options); // The amount the index is shifted by. This is taken from the TeX
// source, in the definition of `\r@@t`.
var toShift = 0.6 * (body.height - body.depth); // Build a VList with the superscript shifted up correctly
var 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
var rootVListWrap = buildCommon.makeSpan([
"root"
], [
rootVList
]);
return buildCommon.makeSpan([
"mord",
"sqrt"
], [
rootVListWrap,
body
], options);
}
},
mathmlBuilder (group, options) {
var { body, index } = group;
return index ? new mathMLTree.MathNode("mroot", [
buildGroup(body, options),
buildGroup(index, options)
]) : new mathMLTree.MathNode("msqrt", [
buildGroup(body, options)
]);
}
});
var styleMap = {
"display": Style$1.DISPLAY,
"text": Style$1.TEXT,
"script": Style$1.SCRIPT,
"scriptscript": Style$1.SCRIPTSCRIPT
};
defineFunction({
type: "styling",
names: [
"\\displaystyle",
"\\textstyle",
"\\scriptstyle",
"\\scriptscriptstyle"
],
props: {
numArgs: 0,
allowedInText: true,
primitive: true
},
handler (_ref, args) {
var { breakOnTokenText, funcName, parser } = _ref;
// parse out the implicit body
var 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.
var style = 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.
var newStyle = styleMap[group.style];
var newOptions = options.havingStyle(newStyle).withFont('');
return sizingGroup(group.body, newOptions, options);
},
mathmlBuilder (group, options) {
// Figure out what style we're changing to.
var newStyle = styleMap[group.style];
var newOptions = options.havingStyle(newStyle);
var inner = buildExpression(group.body, newOptions);
var node = new mathMLTree.MathNode("mstyle", inner);
var styleAttributes = {
"display": [
"0",
"true"
],
"text": [
"0",
"false"
],
"script": [
"1",
"false"
],
"scriptscript": [
"2",
"false"
]
};
var attr = styleAttributes[group.style];
node.setAttribute("scriptlevel", attr[0]);
node.setAttribute("displaystyle", attr[1]);
return node;
}
});
/**
* 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.
*/ var htmlBuilderDelegate = function htmlBuilderDelegate(group, options) {
var 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`)
var delegate = base.limits && (options.style.size === Style$1.DISPLAY.size || base.alwaysHandleSupSub);
return delegate ? htmlBuilder$2 : null;
} else if (base.type === "operatorname") {
var _delegate = base.alwaysHandleSupSub && (options.style.size === Style$1.DISPLAY.size || base.limits);
return _delegate ? htmlBuilder$1 : null;
} else if (base.type === "accent") return utils.isCharacterBox(base.base) ? htmlBuilder$a : null;
else if (base.type === "horizBrace") {
var isSup = !group.sub;
return isSup === base.isOver ? htmlBuilder$3 : 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.
var builderDelegate = htmlBuilderDelegate(group, options);
if (builderDelegate) return builderDelegate(group, options);
var { base: valueBase, sup: valueSup, sub: valueSub } = group;
var base = buildGroup$1(valueBase, options);
var supm;
var subm;
var metrics = options.fontMetrics(); // Rule 18a
var supShift = 0;
var subShift = 0;
var isCharacterBox = valueBase && utils.isCharacterBox(valueBase);
if (valueSup) {
var newOptions = options.havingStyle(options.style.sup());
supm = buildGroup$1(valueSup, newOptions, options);
if (!isCharacterBox) supShift = base.height - newOptions.fontMetrics().supDrop * newOptions.sizeMultiplier / options.sizeMultiplier;
}
if (valueSub) {
var _newOptions = options.havingStyle(options.style.sub());
subm = buildGroup$1(valueSub, _newOptions, options);
if (!isCharacterBox) subShift = base.depth + _newOptions.fontMetrics().subDrop * _newOptions.sizeMultiplier / options.sizeMultiplier;
} // Rule 18c
var minSupShift;
if (options.style === Style$1.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.
var multiplier = options.sizeMultiplier;
var marginRight = makeEm(0.5 / metrics.ptPerEm / multiplier);
var 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.
var 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);
}
var supsub;
if (supm && subm) {
supShift = Math.max(supShift, minSupShift, supm.depth + 0.25 * metrics.xHeight);
subShift = Math.max(subShift, metrics.sub2);
var ruleWidth = metrics.defaultRuleThickness; // Rule 18e
var maxWidth = 4 * ruleWidth;
if (supShift - supm.depth - (subm.height - subShift) < maxWidth) {
subShift = maxWidth - (supShift - supm.depth) + subm.height;
var psi = 0.8 * metrics.xHeight - (supShift - supm.depth);
if (psi > 0) {
supShift += psi;
subShift -= psi;
}
}
var 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);
var _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.
var mclass = getTypeOfDomTree(base, "right") || "mord";
return buildCommon.makeSpan([
mclass
], [
base,
buildCommon.makeSpan([
"msupsub"
], [
supsub
])
], options);
},
mathmlBuilder (group, options) {
// Is the inner group a relevant horizonal brace?
var isBrace = false;
var isOver;
var 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;
var children = [
buildGroup(group.base, options)
];
if (group.sub) children.push(buildGroup(group.sub, options));
if (group.sup) children.push(buildGroup(group.sup, options));
var nodeType;
if (isBrace) nodeType = isOver ? "mover" : "munder";
else if (!group.sub) {
var base = group.base;
if (base && base.type === "op" && base.limits && (options.style === Style$1.DISPLAY || base.alwaysHandleSupSub)) nodeType = "mover";
else if (base && base.type === "operatorname" && base.alwaysHandleSupSub && (base.limits || options.style === Style$1.DISPLAY)) nodeType = "mover";
else nodeType = "msup";
} else if (!group.sup) {
var _base = group.base;
if (_base && _base.type === "op" && _base.limits && (options.style === Style$1.DISPLAY || _base.alwaysHandleSupSub)) nodeType = "munder";
else if (_base && _base.type === "operatorname" && _base.alwaysHandleSupSub && (_base.limits || options.style === Style$1.DISPLAY)) nodeType = "munder";
else nodeType = "msub";
} else {
var _base2 = group.base;
if (_base2 && _base2.type === "op" && _base2.limits && options.style === Style$1.DISPLAY) nodeType = "munderover";
else if (_base2 && _base2.type === "operatorname" && _base2.alwaysHandleSupSub && (options.style === Style$1.DISPLAY || _base2.limits)) nodeType = "munderover";
else nodeType = "msubsup";
}
return new mathMLTree.MathNode(nodeType, children);
}
});
defineFunctionBuilders({
type: "atom",
htmlBuilder (group, options) {
return buildCommon.mathsym(group.text, group.mode, options, [
"m" + group.family
]);
},
mathmlBuilder (group, options) {
var node = new mathMLTree.MathNode("mo", [
makeText(group.text, group.mode)
]);
if (group.family === "bin") {
var variant = 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;
}
});
// "mathord" and "textord" ParseNodes created in Parser.js from symbol Groups in
// src/symbols.js.
var defaultVariant = {
"mi": "italic",
"mn": "normal",
"mtext": "normal"
};
defineFunctionBuilders({
type: "mathord",
htmlBuilder (group, options) {
return buildCommon.makeOrd(group, options, "mathord");
},
mathmlBuilder (group, options) {
var node = new mathMLTree.MathNode("mi", [
makeText(group.text, group.mode, options)
]);
var variant = 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, options) {
var text = makeText(group.text, group.mode, options);
var variant = getVariant(group, options) || "normal";
var 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;
}
});
var cssSpace = {
"\\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`.
var regularSpace = {
" ": {},
"\\ ": {},
"~": {
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)) {
var 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") {
var 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) {
var 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;
}
});
var pad = ()=>{
var padNode = new mathMLTree.MathNode("mtd", []);
padNode.setAttribute("width", "50%");
return padNode;
};
defineFunctionBuilders({
type: "tag",
mathmlBuilder (group, options) {
var table = new mathMLTree.MathNode("mtable", [
new mathMLTree.MathNode("mtr", [
pad(),
new mathMLTree.MathNode("mtd", [
buildExpressionRow(group.body, options)
]),
pad(),
new mathMLTree.MathNode("mtd", [
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.
}
});
var textFontFamilies = {
"\\text": undefined,
"\\textrm": "textrm",
"\\textsf": "textsf",
"\\texttt": "texttt",
"\\textnormal": "textrm"
};
var textFontWeights = {
"\\textbf": "textbf",
"\\textmd": "textmd"
};
var textFontShapes = {
"\\textit": "textit",
"\\textup": "textup"
};
var optionsWithFont = (group, options)=>{
var 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 return options.withTextFontShape(textFontShapes[font]);
};
defineFunction({
type: "text",
names: [
"\\text",
"\\textrm",
"\\textsf",
"\\texttt",
"\\textnormal",
"\\textbf",
"\\textmd",
"\\textit",
"\\textup"
],
props: {
numArgs: 1,
argTypes: [
"text"
],
allowedInArgument: true,
allowedInText: true
},
handler (_ref, args) {
var { parser, funcName } = _ref;
var body = args[0];
return {
type: "text",
mode: parser.mode,
body: ordargument(body),
font: funcName
};
},
htmlBuilder (group, options) {
var newOptions = optionsWithFont(group, options);
var inner = buildExpression$1(group.body, newOptions, true);
return buildCommon.makeSpan([
"mord",
"text"
], inner, newOptions);
},
mathmlBuilder (group, options) {
var newOptions = optionsWithFont(group, options);
return buildExpressionRow(group.body, newOptions);
}
});
defineFunction({
type: "underline",
names: [
"\\underline"
],
props: {
numArgs: 1,
allowedInText: true
},
handler (_ref, args) {
var { parser } = _ref;
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.
var innerGroup = buildGroup$1(group.body, options); // Create the line to go below the body
var line = buildCommon.makeLineSpan("underline-line", options); // Generate the vlist, with the appropriate kerns
var defaultRuleThickness = options.fontMetrics().defaultRuleThickness;
var 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) {
var operator = new mathMLTree.MathNode("mo", [
new mathMLTree.TextNode("\u203e")
]);
operator.setAttribute("stretchy", "true");
var node = new mathMLTree.MathNode("munder", [
buildGroup(group.body, options),
operator
]);
node.setAttribute("accentunder", "true");
return node;
}
});
defineFunction({
type: "vcenter",
names: [
"\\vcenter"
],
props: {
numArgs: 1,
argTypes: [
"original"
],
// In LaTeX, \vcenter can act only on a box.
allowedInText: false
},
handler (_ref, args) {
var { parser } = _ref;
return {
type: "vcenter",
mode: parser.mode,
body: args[0]
};
},
htmlBuilder (group, options) {
var body = buildGroup$1(group.body, options);
var axisHeight = options.fontMetrics().axisHeight;
var 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", [
buildGroup(group.body, options)
], [
"vcenter"
]);
}
});
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) {
var text = makeVerb(group);
var body = []; // \verb enters text mode and therefore is sized like \textstyle
var newOptions = options.havingStyle(options.style.text());
for(var i = 0; i < text.length; i++){
var 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) {
var text = new mathMLTree.TextNode(makeVerb(group));
var 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
*/ var makeVerb = (group)=>group.body.replace(/ /g, group.star ? '\u2423' : '\xA0');
/** Include this to ensure that all functions are defined. */ var functions = _functions;
/**
* 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.
*/ /* 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.
*/ var spaceRegexString = "[ \r\n\t]";
var controlWordRegexString = "\\\\[a-zA-Z@]+";
var controlSymbolRegexString = "\\\\[^\uD800-\uDFFF]";
var controlWordWhitespaceRegexString = "(" + controlWordRegexString + ")" + spaceRegexString + "*";
var controlSpaceRegexString = "\\\\(\n|[ \r\t]+\n?)[ \r\t]*";
var combiningDiacriticalMarkString = "[\u0300-\u036f]";
var combiningDiacriticalMarksEndRegex = new RegExp(combiningDiacriticalMarkString + "+$");
var tokenRegexString = "(" + spaceRegexString + "+)|" + (controlSpaceRegexString + "|") + // \whitespace
"([!-\\[\\]-\u2027\u202A-\uD7FF\uF900-\uFFFF]" + (combiningDiacriticalMarkString + "*") + // ...plus accents
"|[\uD800-\uDBFF][\uDC00-\uDFFF]" + (combiningDiacriticalMarkString + "*") + // ...plus accents
"|\\\\verb\\*([^]).*?\\4" + // \verb*
"|\\\\verb([^*a-zA-Z]).*?\\5" + ("|" + controlWordWhitespaceRegexString) + ("|" + controlSymbolRegexString + ")"); // \\, \', etc.
/** Main Lexer class */ class Lexer {
// Category codes. The lexer only supports comment characters (14) for now.
// MacroExpander additionally distinguishes active (13).
constructor(input, settings){
this.input = void 0;
this.settings = void 0;
this.tokenRegex = void 0;
this.catcodes = void 0;
// 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, code) {
this.catcodes[char] = code;
}
/**
* This function lexes a single token.
*/ lex() {
var input = this.input;
var pos = this.tokenRegex.lastIndex;
if (pos === input.length) return new Token("EOF", new SourceLocation(this, pos, pos));
var 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)));
var text = match[6] || match[3] || (match[2] ? "\\ " : " ");
if (this.catcodes[text] === 14) {
// comment character
var 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));
}
}
/**
* 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.
*/ class Namespace {
/**
* 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, globalMacros){
if (builtins === void 0) builtins = {};
if (globalMacros === void 0) globalMacros = {};
this.current = void 0;
this.builtins = void 0;
this.undefStack = void 0;
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");
var undefs = this.undefStack.pop();
for(var 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) {
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) {
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, value, global) {
if (global === void 0) global = 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(var 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.
var 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;
}
}
/**
* Predefined macros for KaTeX.
* This can be used to define some commands in terms of others.
*/ var macros = _macros;
// macro tools
defineMacro("\\noexpand", function(context) {
// The expansion is the token itself; but that token is interpreted
// as if its meaning were ‘\relax’ if it is a control sequence that
// would ordinarily be expanded by TeX’s expansion rules.
var t = context.popToken();
if (context.isExpandable(t.text)) {
t.noexpand = true;
t.treatAsRelax = true;
}
return {
tokens: [
t
],
numArgs: 0
};
});
defineMacro("\\expandafter", function(context) {
// TeX first reads the token that comes immediately after \expandafter,
// without expanding it; let’s call this token t. Then TeX reads the
// token that comes after t (and possibly more tokens, if that token
// has an argument), replacing it by its expansion. Finally TeX puts
// t back in front of that expansion.
var t = context.popToken();
context.expandOnce(true); // expand only an expandable token
return {
tokens: [
t
],
numArgs: 0
};
}); // LaTeX's \@firstoftwo{#1}{#2} expands to #1, skipping #2
// TeX source: \long\def\@firstoftwo#1#2{#1}
defineMacro("\\@firstoftwo", function(context) {
var args = context.consumeArgs(2);
return {
tokens: args[0],
numArgs: 0
};
}); // LaTeX's \@secondoftwo{#1}{#2} expands to #2, skipping #1
// TeX source: \long\def\@secondoftwo#1#2{#2}
defineMacro("\\@secondoftwo", function(context) {
var args = context.consumeArgs(2);
return {
tokens: args[1],
numArgs: 0
};
}); // LaTeX's \@ifnextchar{#1}{#2}{#3} looks ahead to the next (unexpanded)
// symbol that isn't a space, consuming any spaces but not consuming the
// first nonspace character. If that nonspace character matches #1, then
// the macro expands to #2; otherwise, it expands to #3.
defineMacro("\\@ifnextchar", function(context) {
var args = context.consumeArgs(3); // symbol, if, else
context.consumeSpaces();
var nextToken = context.future();
if (args[0].length === 1 && args[0][0].text === nextToken.text) return {
tokens: args[1],
numArgs: 0
};
else return {
tokens: args[2],
numArgs: 0
};
}); // LaTeX's \@ifstar{#1}{#2} looks ahead to the next (unexpanded) symbol.
// If it is `*`, then it consumes the symbol, and the macro expands to #1;
// otherwise, the macro expands to #2 (without consuming the symbol).
// TeX source: \def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}}
defineMacro("\\@ifstar", "\\@ifnextchar *{\\@firstoftwo{#1}}"); // LaTeX's \TextOrMath{#1}{#2} expands to #1 in text mode, #2 in math mode
defineMacro("\\TextOrMath", function(context) {
var args = context.consumeArgs(2);
if (context.mode === 'text') return {
tokens: args[0],
numArgs: 0
};
else return {
tokens: args[1],
numArgs: 0
};
}); // Lookup table for parsing numbers in base 8 through 16
var digitToNumber = {
"0": 0,
"1": 1,
"2": 2,
"3": 3,
"4": 4,
"5": 5,
"6": 6,
"7": 7,
"8": 8,
"9": 9,
"a": 10,
"A": 10,
"b": 11,
"B": 11,
"c": 12,
"C": 12,
"d": 13,
"D": 13,
"e": 14,
"E": 14,
"f": 15,
"F": 15
}; // TeX \char makes a literal character (catcode 12) using the following forms:
// (see The TeXBook, p. 43)
// \char123 -- decimal
// \char'123 -- octal
// \char"123 -- hex
// \char`x -- character that can be written (i.e. isn't active)
// \char`\x -- character that cannot be written (e.g. %)
// These all refer to characters from the font, so we turn them into special
// calls to a function \@char dealt with in the Parser.
defineMacro("\\char", function(context) {
var token = context.popToken();
var base;
var number = '';
if (token.text === "'") {
base = 8;
token = context.popToken();
} else if (token.text === '"') {
base = 16;
token = context.popToken();
} else if (token.text === "`") {
token = context.popToken();
if (token.text[0] === "\\") number = token.text.charCodeAt(1);
else if (token.text === "EOF") throw new ParseError("\\char` missing argument");
else number = token.text.charCodeAt(0);
} else base = 10;
if (base) {
// Parse a number in the given base, starting with first `token`.
number = digitToNumber[token.text];
if (number == null || number >= base) throw new ParseError("Invalid base-" + base + " digit " + token.text);
var digit;
while((digit = digitToNumber[context.future().text]) != null && digit < base){
number *= base;
number += digit;
context.popToken();
}
}
return "\\@char{" + number + "}";
}); // \newcommand{\macro}[args]{definition}
// \renewcommand{\macro}[args]{definition}
// TODO: Optional arguments: \newcommand{\macro}[args][default]{definition}
var newcommand = (context, existsOK, nonexistsOK)=>{
var arg = context.consumeArg().tokens;
if (arg.length !== 1) throw new ParseError("\\newcommand's first argument must be a macro name");
var name = arg[0].text;
var exists = context.isDefined(name);
if (exists && !existsOK) throw new ParseError("\\newcommand{" + name + "} attempting to redefine " + (name + "; use \\renewcommand"));
if (!exists && !nonexistsOK) throw new ParseError("\\renewcommand{" + name + "} when command " + name + " " + "does not yet exist; use \\newcommand");
var numArgs = 0;
arg = context.consumeArg().tokens;
if (arg.length === 1 && arg[0].text === "[") {
var argText = '';
var token = context.expandNextToken();
while(token.text !== "]" && token.text !== "EOF"){
// TODO: Should properly expand arg, e.g., ignore {}s
argText += token.text;
token = context.expandNextToken();
}
if (!argText.match(/^\s*[0-9]+\s*$/)) throw new ParseError("Invalid number of arguments: " + argText);
numArgs = parseInt(argText);
arg = context.consumeArg().tokens;
} // Final arg is the expansion of the macro
context.macros.set(name, {
tokens: arg,
numArgs
});
return '';
};
defineMacro("\\newcommand", (context)=>newcommand(context, false, true));
defineMacro("\\renewcommand", (context)=>newcommand(context, true, false));
defineMacro("\\providecommand", (context)=>newcommand(context, true, true)); // terminal (console) tools
defineMacro("\\message", (context)=>{
var arg = context.consumeArgs(1)[0]; // eslint-disable-next-line no-console
console.log(arg.reverse().map((token)=>token.text).join(""));
return '';
});
defineMacro("\\errmessage", (context)=>{
var arg = context.consumeArgs(1)[0]; // eslint-disable-next-line no-console
console.error(arg.reverse().map((token)=>token.text).join(""));
return '';
});
defineMacro("\\show", (context)=>{
var tok = context.popToken();
var name = tok.text; // eslint-disable-next-line no-console
console.log(tok, context.macros.get(name), functions[name], symbols.math[name], symbols.text[name]);
return '';
}); //////////////////////////////////////////////////////////////////////
// Grouping
// \let\bgroup={ \let\egroup=}
defineMacro("\\bgroup", "{");
defineMacro("\\egroup", "}"); // Symbols from latex.ltx:
// \def~{\nobreakspace{}}
// \def\lq{`}
// \def\rq{'}
// \def \aa {\r a}
// \def \AA {\r A}
defineMacro("~", "\\nobreakspace");
defineMacro("\\lq", "`");
defineMacro("\\rq", "'");
defineMacro("\\aa", "\\r a");
defineMacro("\\AA", "\\r A"); // Copyright (C) and registered (R) symbols. Use raw symbol in MathML.
// \DeclareTextCommandDefault{\textcopyright}{\textcircled{c}}
// \DeclareTextCommandDefault{\textregistered}{\textcircled{%
// \check@mathfonts\fontsize\sf@size\z@\math@fontsfalse\selectfont R}}
// \DeclareRobustCommand{\copyright}{%
// \ifmmode{\nfss@text{\textcopyright}}\else\textcopyright\fi}
defineMacro("\\textcopyright", "\\html@mathml{\\textcircled{c}}{\\char`©}");
defineMacro("\\copyright", "\\TextOrMath{\\textcopyright}{\\text{\\textcopyright}}");
defineMacro("\\textregistered", "\\html@mathml{\\textcircled{\\scriptsize R}}{\\char`®}"); // Characters omitted from Unicode range 1D400–1D7FF
defineMacro("\u212C", "\\mathscr{B}"); // script
defineMacro("\u2130", "\\mathscr{E}");
defineMacro("\u2131", "\\mathscr{F}");
defineMacro("\u210B", "\\mathscr{H}");
defineMacro("\u2110", "\\mathscr{I}");
defineMacro("\u2112", "\\mathscr{L}");
defineMacro("\u2133", "\\mathscr{M}");
defineMacro("\u211B", "\\mathscr{R}");
defineMacro("\u212D", "\\mathfrak{C}"); // Fraktur
defineMacro("\u210C", "\\mathfrak{H}");
defineMacro("\u2128", "\\mathfrak{Z}"); // Define \Bbbk with a macro that works in both HTML and MathML.
defineMacro("\\Bbbk", "\\Bbb{k}"); // Unicode middle dot
// The KaTeX fonts do not contain U+00B7. Instead, \cdotp displays
// the dot at U+22C5 and gives it punct spacing.
defineMacro("\u00b7", "\\cdotp"); // \llap and \rlap render their contents in text mode
defineMacro("\\llap", "\\mathllap{\\textrm{#1}}");
defineMacro("\\rlap", "\\mathrlap{\\textrm{#1}}");
defineMacro("\\clap", "\\mathclap{\\textrm{#1}}"); // \mathstrut from the TeXbook, p 360
defineMacro("\\mathstrut", "\\vphantom{(}"); // \underbar from TeXbook p 353
defineMacro("\\underbar", "\\underline{\\text{#1}}"); // \not is defined by base/fontmath.ltx via
// \DeclareMathSymbol{\not}{\mathrel}{symbols}{"36}
// It's thus treated like a \mathrel, but defined by a symbol that has zero
// width but extends to the right. We use \rlap to get that spacing.
// For MathML we write U+0338 here. buildMathML.js will then do the overlay.
defineMacro("\\not", '\\html@mathml{\\mathrel{\\mathrlap\\@not}}{\\char"338}'); // Negated symbols from base/fontmath.ltx:
// \def\neq{\not=} \let\ne=\neq
// \DeclareRobustCommand
// \notin{\mathrel{\m@th\mathpalette\c@ncel\in}}
// \def\c@ncel#1#2{\m@th\ooalign{$\hfil#1\mkern1mu/\hfil$\crcr$#1#2$}}
defineMacro("\\neq", "\\html@mathml{\\mathrel{\\not=}}{\\mathrel{\\char`≠}}");
defineMacro("\\ne", "\\neq");
defineMacro("\u2260", "\\neq");
defineMacro("\\notin", "\\html@mathml{\\mathrel{{\\in}\\mathllap{/\\mskip1mu}}}{\\mathrel{\\char`∉}}");
defineMacro("\u2209", "\\notin"); // Unicode stacked relations
defineMacro("\u2258", "\\html@mathml{\\mathrel{=\\kern{-1em}\\raisebox{0.4em}{$\\scriptsize\\frown$}}}{\\mathrel{\\char`≘}}");
defineMacro("\u2259", "\\html@mathml{\\stackrel{\\tiny\\wedge}{=}}{\\mathrel{\\char`\u2258}}");
defineMacro("\u225A", "\\html@mathml{\\stackrel{\\tiny\\vee}{=}}{\\mathrel{\\char`\u225A}}");
defineMacro("\u225B", "\\html@mathml{\\stackrel{\\scriptsize\\star}{=}}{\\mathrel{\\char`≛}}");
defineMacro("\u225D", "\\html@mathml{\\stackrel{\\tiny\\mathrm{def}}{=}}{\\mathrel{\\char`≝}}");
defineMacro("\u225E", "\\html@mathml{\\stackrel{\\tiny\\mathrm{m}}{=}}{\\mathrel{\\char`≞}}");
defineMacro("\u225F", "\\html@mathml{\\stackrel{\\tiny?}{=}}{\\mathrel{\\char`\u225F}}"); // Misc Unicode
defineMacro("\u27C2", "\\perp");
defineMacro("\u203C", "\\mathclose{!\\mkern-0.8mu!}");
defineMacro("\u220C", "\\notni");
defineMacro("\u231C", "\\ulcorner");
defineMacro("\u231D", "\\urcorner");
defineMacro("\u231E", "\\llcorner");
defineMacro("\u231F", "\\lrcorner");
defineMacro("\u00A9", "\\copyright");
defineMacro("\u00AE", "\\textregistered");
defineMacro("\uFE0F", "\\textregistered"); // The KaTeX fonts have corners at codepoints that don't match Unicode.
// For MathML purposes, use the Unicode code point.
defineMacro("\\ulcorner", "\\html@mathml{\\@ulcorner}{\\mathop{\\char\"231c}}");
defineMacro("\\urcorner", "\\html@mathml{\\@urcorner}{\\mathop{\\char\"231d}}");
defineMacro("\\llcorner", "\\html@mathml{\\@llcorner}{\\mathop{\\char\"231e}}");
defineMacro("\\lrcorner", "\\html@mathml{\\@lrcorner}{\\mathop{\\char\"231f}}"); //////////////////////////////////////////////////////////////////////
// LaTeX_2ε
// \vdots{\vbox{\baselineskip4\p@ \lineskiplimit\z@
// \kern6\p@\hbox{.}\hbox{.}\hbox{.}}}
// We'll call \varvdots, which gets a glyph from symbols.js.
// The zero-width rule gets us an equivalent to the vertical 6pt kern.
defineMacro("\\vdots", "\\mathord{\\varvdots\\rule{0pt}{15pt}}");
defineMacro("\u22ee", "\\vdots"); //////////////////////////////////////////////////////////////////////
// amsmath.sty
// http://mirrors.concertpass.com/tex-archive/macros/latex/required/amsmath/amsmath.pdf
// Italic Greek capital letters. AMS defines these with \DeclareMathSymbol,
// but they are equivalent to \mathit{\Letter}.
defineMacro("\\varGamma", "\\mathit{\\Gamma}");
defineMacro("\\varDelta", "\\mathit{\\Delta}");
defineMacro("\\varTheta", "\\mathit{\\Theta}");
defineMacro("\\varLambda", "\\mathit{\\Lambda}");
defineMacro("\\varXi", "\\mathit{\\Xi}");
defineMacro("\\varPi", "\\mathit{\\Pi}");
defineMacro("\\varSigma", "\\mathit{\\Sigma}");
defineMacro("\\varUpsilon", "\\mathit{\\Upsilon}");
defineMacro("\\varPhi", "\\mathit{\\Phi}");
defineMacro("\\varPsi", "\\mathit{\\Psi}");
defineMacro("\\varOmega", "\\mathit{\\Omega}"); //\newcommand{\substack}[1]{\subarray{c}#1\endsubarray}
defineMacro("\\substack", "\\begin{subarray}{c}#1\\end{subarray}"); // \renewcommand{\colon}{\nobreak\mskip2mu\mathpunct{}\nonscript
// \mkern-\thinmuskip{:}\mskip6muplus1mu\relax}
defineMacro("\\colon", "\\nobreak\\mskip2mu\\mathpunct{}\\mathchoice{\\mkern-3mu}{\\mkern-3mu}{}{}{:}\\mskip6mu\\relax"); // \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}
defineMacro("\\boxed", "\\fbox{$\\displaystyle{#1}$}"); // \def\iff{\DOTSB\;\Longleftrightarrow\;}
// \def\implies{\DOTSB\;\Longrightarrow\;}
// \def\impliedby{\DOTSB\;\Longleftarrow\;}
defineMacro("\\iff", "\\DOTSB\\;\\Longleftrightarrow\\;");
defineMacro("\\implies", "\\DOTSB\\;\\Longrightarrow\\;");
defineMacro("\\impliedby", "\\DOTSB\\;\\Longleftarrow\\;"); // AMSMath's automatic \dots, based on \mdots@@ macro.
var dotsByToken = {
',': '\\dotsc',
'\\not': '\\dotsb',
// \keybin@ checks for the following:
'+': '\\dotsb',
'=': '\\dotsb',
'<': '\\dotsb',
'>': '\\dotsb',
'-': '\\dotsb',
'*': '\\dotsb',
':': '\\dotsb',
// Symbols whose definition starts with \DOTSB:
'\\DOTSB': '\\dotsb',
'\\coprod': '\\dotsb',
'\\bigvee': '\\dotsb',
'\\bigwedge': '\\dotsb',
'\\biguplus': '\\dotsb',
'\\bigcap': '\\dotsb',
'\\bigcup': '\\dotsb',
'\\prod': '\\dotsb',
'\\sum': '\\dotsb',
'\\bigotimes': '\\dotsb',
'\\bigoplus': '\\dotsb',
'\\bigodot': '\\dotsb',
'\\bigsqcup': '\\dotsb',
'\\And': '\\dotsb',
'\\longrightarrow': '\\dotsb',
'\\Longrightarrow': '\\dotsb',
'\\longleftarrow': '\\dotsb',
'\\Longleftarrow': '\\dotsb',
'\\longleftrightarrow': '\\dotsb',
'\\Longleftrightarrow': '\\dotsb',
'\\mapsto': '\\dotsb',
'\\longmapsto': '\\dotsb',
'\\hookrightarrow': '\\dotsb',
'\\doteq': '\\dotsb',
// Symbols whose definition starts with \mathbin:
'\\mathbin': '\\dotsb',
// Symbols whose definition starts with \mathrel:
'\\mathrel': '\\dotsb',
'\\relbar': '\\dotsb',
'\\Relbar': '\\dotsb',
'\\xrightarrow': '\\dotsb',
'\\xleftarrow': '\\dotsb',
// Symbols whose definition starts with \DOTSI:
'\\DOTSI': '\\dotsi',
'\\int': '\\dotsi',
'\\oint': '\\dotsi',
'\\iint': '\\dotsi',
'\\iiint': '\\dotsi',
'\\iiiint': '\\dotsi',
'\\idotsint': '\\dotsi',
// Symbols whose definition starts with \DOTSX:
'\\DOTSX': '\\dotsx'
};
defineMacro("\\dots", function(context) {
// TODO: If used in text mode, should expand to \textellipsis.
// However, in KaTeX, \textellipsis and \ldots behave the same
// (in text mode), and it's unlikely we'd see any of the math commands
// that affect the behavior of \dots when in text mode. So fine for now
// (until we support \ifmmode ... \else ... \fi).
var thedots = '\\dotso';
var next = context.expandAfterFuture().text;
if (next in dotsByToken) thedots = dotsByToken[next];
else if (next.slice(0, 4) === '\\not') thedots = '\\dotsb';
else if (next in symbols.math) {
if (utils.contains([
'bin',
'rel'
], symbols.math[next].group)) thedots = '\\dotsb';
}
return thedots;
});
var spaceAfterDots = {
// \rightdelim@ checks for the following:
')': true,
']': true,
'\\rbrack': true,
'\\}': true,
'\\rbrace': true,
'\\rangle': true,
'\\rceil': true,
'\\rfloor': true,
'\\rgroup': true,
'\\rmoustache': true,
'\\right': true,
'\\bigr': true,
'\\biggr': true,
'\\Bigr': true,
'\\Biggr': true,
// \extra@ also tests for the following:
'$': true,
// \extrap@ checks for the following:
';': true,
'.': true,
',': true
};
defineMacro("\\dotso", function(context) {
var next = context.future().text;
if (next in spaceAfterDots) return "\\ldots\\,";
else return "\\ldots";
});
defineMacro("\\dotsc", function(context) {
var next = context.future().text; // \dotsc uses \extra@ but not \extrap@, instead specially checking for
// ';' and '.', but doesn't check for ','.
if (next in spaceAfterDots && next !== ',') return "\\ldots\\,";
else return "\\ldots";
});
defineMacro("\\cdots", function(context) {
var next = context.future().text;
if (next in spaceAfterDots) return "\\@cdots\\,";
else return "\\@cdots";
});
defineMacro("\\dotsb", "\\cdots");
defineMacro("\\dotsm", "\\cdots");
defineMacro("\\dotsi", "\\!\\cdots"); // amsmath doesn't actually define \dotsx, but \dots followed by a macro
// starting with \DOTSX implies \dotso, and then \extra@ detects this case
// and forces the added `\,`.
defineMacro("\\dotsx", "\\ldots\\,"); // \let\DOTSI\relax
// \let\DOTSB\relax
// \let\DOTSX\relax
defineMacro("\\DOTSI", "\\relax");
defineMacro("\\DOTSB", "\\relax");
defineMacro("\\DOTSX", "\\relax"); // Spacing, based on amsmath.sty's override of LaTeX defaults
// \DeclareRobustCommand{\tmspace}[3]{%
// \ifmmode\mskip#1#2\else\kern#1#3\fi\relax}
defineMacro("\\tmspace", "\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax"); // \renewcommand{\,}{\tmspace+\thinmuskip{.1667em}}
// TODO: math mode should use \thinmuskip
defineMacro("\\,", "\\tmspace+{3mu}{.1667em}"); // \let\thinspace\,
defineMacro("\\thinspace", "\\,"); // \def\>{\mskip\medmuskip}
// \renewcommand{\:}{\tmspace+\medmuskip{.2222em}}
// TODO: \> and math mode of \: should use \medmuskip = 4mu plus 2mu minus 4mu
defineMacro("\\>", "\\mskip{4mu}");
defineMacro("\\:", "\\tmspace+{4mu}{.2222em}"); // \let\medspace\:
defineMacro("\\medspace", "\\:"); // \renewcommand{\;}{\tmspace+\thickmuskip{.2777em}}
// TODO: math mode should use \thickmuskip = 5mu plus 5mu
defineMacro("\\;", "\\tmspace+{5mu}{.2777em}"); // \let\thickspace\;
defineMacro("\\thickspace", "\\;"); // \renewcommand{\!}{\tmspace-\thinmuskip{.1667em}}
// TODO: math mode should use \thinmuskip
defineMacro("\\!", "\\tmspace-{3mu}{.1667em}"); // \let\negthinspace\!
defineMacro("\\negthinspace", "\\!"); // \newcommand{\negmedspace}{\tmspace-\medmuskip{.2222em}}
// TODO: math mode should use \medmuskip
defineMacro("\\negmedspace", "\\tmspace-{4mu}{.2222em}"); // \newcommand{\negthickspace}{\tmspace-\thickmuskip{.2777em}}
// TODO: math mode should use \thickmuskip
defineMacro("\\negthickspace", "\\tmspace-{5mu}{.277em}"); // \def\enspace{\kern.5em }
defineMacro("\\enspace", "\\kern.5em "); // \def\enskip{\hskip.5em\relax}
defineMacro("\\enskip", "\\hskip.5em\\relax"); // \def\quad{\hskip1em\relax}
defineMacro("\\quad", "\\hskip1em\\relax"); // \def\qquad{\hskip2em\relax}
defineMacro("\\qquad", "\\hskip2em\\relax"); // \tag@in@display form of \tag
defineMacro("\\tag", "\\@ifstar\\tag@literal\\tag@paren");
defineMacro("\\tag@paren", "\\tag@literal{({#1})}");
defineMacro("\\tag@literal", (context)=>{
if (context.macros.get("\\df@tag")) throw new ParseError("Multiple \\tag");
return "\\gdef\\df@tag{\\text{#1}}";
}); // \renewcommand{\bmod}{\nonscript\mskip-\medmuskip\mkern5mu\mathbin
// {\operator@font mod}\penalty900
// \mkern5mu\nonscript\mskip-\medmuskip}
// \newcommand{\pod}[1]{\allowbreak
// \if@display\mkern18mu\else\mkern8mu\fi(#1)}
// \renewcommand{\pmod}[1]{\pod{{\operator@font mod}\mkern6mu#1}}
// \newcommand{\mod}[1]{\allowbreak\if@display\mkern18mu
// \else\mkern12mu\fi{\operator@font mod}\,\,#1}
// TODO: math mode should use \medmuskip = 4mu plus 2mu minus 4mu
defineMacro("\\bmod", "\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}\\mathbin{\\rm mod}\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}");
defineMacro("\\pod", "\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern8mu}{\\mkern8mu}{\\mkern8mu}(#1)");
defineMacro("\\pmod", "\\pod{{\\rm mod}\\mkern6mu#1}");
defineMacro("\\mod", "\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}{\\rm mod}\\,\\,#1"); //////////////////////////////////////////////////////////////////////
// LaTeX source2e
// \expandafter\let\expandafter\@normalcr
// \csname\expandafter\@gobble\string\\ \endcsname
// \DeclareRobustCommand\newline{\@normalcr\relax}
defineMacro("\\newline", "\\\\\\relax"); // \def\TeX{T\kern-.1667em\lower.5ex\hbox{E}\kern-.125emX\@}
// TODO: Doesn't normally work in math mode because \@ fails. KaTeX doesn't
// support \@ yet, so that's omitted, and we add \text so that the result
// doesn't look funny in math mode.
defineMacro("\\TeX", "\\textrm{\\html@mathml{T\\kern-.1667em\\raisebox{-.5ex}{E}\\kern-.125emX}{TeX}}"); // \DeclareRobustCommand{\LaTeX}{L\kern-.36em%
// {\sbox\z@ T%
// \vbox to\ht\z@{\hbox{\check@mathfonts
// \fontsize\sf@size\z@
// \math@fontsfalse\selectfont
// A}%
// \vss}%
// }%
// \kern-.15em%
// \TeX}
// This code aligns the top of the A with the T (from the perspective of TeX's
// boxes, though visually the A appears to extend above slightly).
// We compute the corresponding \raisebox when A is rendered in \normalsize
// \scriptstyle, which has a scale factor of 0.7 (see Options.js).
var latexRaiseA = makeEm(fontMetricsData['Main-Regular']["T".charCodeAt(0)][1] - 0.7 * fontMetricsData['Main-Regular']["A".charCodeAt(0)][1]);
defineMacro("\\LaTeX", "\\textrm{\\html@mathml{" + ("L\\kern-.36em\\raisebox{" + latexRaiseA + "}{\\scriptstyle A}") + "\\kern-.15em\\TeX}{LaTeX}}"); // New KaTeX logo based on tweaking LaTeX logo
defineMacro("\\KaTeX", "\\textrm{\\html@mathml{" + ("K\\kern-.17em\\raisebox{" + latexRaiseA + "}{\\scriptstyle A}") + "\\kern-.15em\\TeX}{KaTeX}}"); // \DeclareRobustCommand\hspace{\@ifstar\@hspacer\@hspace}
// \def\@hspace#1{\hskip #1\relax}
// \def\@hspacer#1{\vrule \@width\z@\nobreak
// \hskip #1\hskip \z@skip}
defineMacro("\\hspace", "\\@ifstar\\@hspacer\\@hspace");
defineMacro("\\@hspace", "\\hskip #1\\relax");
defineMacro("\\@hspacer", "\\rule{0pt}{0pt}\\hskip #1\\relax"); //////////////////////////////////////////////////////////////////////
// mathtools.sty
//\providecommand\ordinarycolon{:}
defineMacro("\\ordinarycolon", ":"); //\def\vcentcolon{\mathrel{\mathop\ordinarycolon}}
//TODO(edemaine): Not yet centered. Fix via \raisebox or #726
defineMacro("\\vcentcolon", "\\mathrel{\\mathop\\ordinarycolon}"); // \providecommand*\dblcolon{\vcentcolon\mathrel{\mkern-.9mu}\vcentcolon}
defineMacro("\\dblcolon", '\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-.9mu}\\vcentcolon}}{\\mathop{\\char"2237}}'); // \providecommand*\coloneqq{\vcentcolon\mathrel{\mkern-1.2mu}=}
defineMacro("\\coloneqq", '\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}=}}{\\mathop{\\char"2254}}'); // ≔
// \providecommand*\Coloneqq{\dblcolon\mathrel{\mkern-1.2mu}=}
defineMacro("\\Coloneqq", '\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}=}}{\\mathop{\\char"2237\\char"3d}}'); // \providecommand*\coloneq{\vcentcolon\mathrel{\mkern-1.2mu}\mathrel{-}}
defineMacro("\\coloneq", '\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}{\\mathop{\\char"3a\\char"2212}}'); // \providecommand*\Coloneq{\dblcolon\mathrel{\mkern-1.2mu}\mathrel{-}}
defineMacro("\\Coloneq", '\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}{\\mathop{\\char"2237\\char"2212}}'); // \providecommand*\eqqcolon{=\mathrel{\mkern-1.2mu}\vcentcolon}
defineMacro("\\eqqcolon", '\\html@mathml{\\mathrel{=\\mathrel{\\mkern-1.2mu}\\vcentcolon}}{\\mathop{\\char"2255}}'); // ≕
// \providecommand*\Eqqcolon{=\mathrel{\mkern-1.2mu}\dblcolon}
defineMacro("\\Eqqcolon", '\\html@mathml{\\mathrel{=\\mathrel{\\mkern-1.2mu}\\dblcolon}}{\\mathop{\\char"3d\\char"2237}}'); // \providecommand*\eqcolon{\mathrel{-}\mathrel{\mkern-1.2mu}\vcentcolon}
defineMacro("\\eqcolon", '\\html@mathml{\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\vcentcolon}}{\\mathop{\\char"2239}}'); // \providecommand*\Eqcolon{\mathrel{-}\mathrel{\mkern-1.2mu}\dblcolon}
defineMacro("\\Eqcolon", '\\html@mathml{\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\dblcolon}}{\\mathop{\\char"2212\\char"2237}}'); // \providecommand*\colonapprox{\vcentcolon\mathrel{\mkern-1.2mu}\approx}
defineMacro("\\colonapprox", '\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\approx}}{\\mathop{\\char"3a\\char"2248}}'); // \providecommand*\Colonapprox{\dblcolon\mathrel{\mkern-1.2mu}\approx}
defineMacro("\\Colonapprox", '\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\approx}}{\\mathop{\\char"2237\\char"2248}}'); // \providecommand*\colonsim{\vcentcolon\mathrel{\mkern-1.2mu}\sim}
defineMacro("\\colonsim", '\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\sim}}{\\mathop{\\char"3a\\char"223c}}'); // \providecommand*\Colonsim{\dblcolon\mathrel{\mkern-1.2mu}\sim}
defineMacro("\\Colonsim", '\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\sim}}{\\mathop{\\char"2237\\char"223c}}'); // Some Unicode characters are implemented with macros to mathtools functions.
defineMacro("\u2237", "\\dblcolon"); // ::
defineMacro("\u2239", "\\eqcolon"); // -:
defineMacro("\u2254", "\\coloneqq"); // :=
defineMacro("\u2255", "\\eqqcolon"); // =:
defineMacro("\u2A74", "\\Coloneqq"); // ::=
//////////////////////////////////////////////////////////////////////
// colonequals.sty
// Alternate names for mathtools's macros:
defineMacro("\\ratio", "\\vcentcolon");
defineMacro("\\coloncolon", "\\dblcolon");
defineMacro("\\colonequals", "\\coloneqq");
defineMacro("\\coloncolonequals", "\\Coloneqq");
defineMacro("\\equalscolon", "\\eqqcolon");
defineMacro("\\equalscoloncolon", "\\Eqqcolon");
defineMacro("\\colonminus", "\\coloneq");
defineMacro("\\coloncolonminus", "\\Coloneq");
defineMacro("\\minuscolon", "\\eqcolon");
defineMacro("\\minuscoloncolon", "\\Eqcolon"); // \colonapprox name is same in mathtools and colonequals.
defineMacro("\\coloncolonapprox", "\\Colonapprox"); // \colonsim name is same in mathtools and colonequals.
defineMacro("\\coloncolonsim", "\\Colonsim"); // Additional macros, implemented by analogy with mathtools definitions:
defineMacro("\\simcolon", "\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\vcentcolon}");
defineMacro("\\simcoloncolon", "\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\dblcolon}");
defineMacro("\\approxcolon", "\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\vcentcolon}");
defineMacro("\\approxcoloncolon", "\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\dblcolon}"); // Present in newtxmath, pxfonts and txfonts
defineMacro("\\notni", "\\html@mathml{\\not\\ni}{\\mathrel{\\char`\u220C}}");
defineMacro("\\limsup", "\\DOTSB\\operatorname*{lim\\,sup}");
defineMacro("\\liminf", "\\DOTSB\\operatorname*{lim\\,inf}"); //////////////////////////////////////////////////////////////////////
// From amsopn.sty
defineMacro("\\injlim", "\\DOTSB\\operatorname*{inj\\,lim}");
defineMacro("\\projlim", "\\DOTSB\\operatorname*{proj\\,lim}");
defineMacro("\\varlimsup", "\\DOTSB\\operatorname*{\\overline{lim}}");
defineMacro("\\varliminf", "\\DOTSB\\operatorname*{\\underline{lim}}");
defineMacro("\\varinjlim", "\\DOTSB\\operatorname*{\\underrightarrow{lim}}");
defineMacro("\\varprojlim", "\\DOTSB\\operatorname*{\\underleftarrow{lim}}"); //////////////////////////////////////////////////////////////////////
// MathML alternates for KaTeX glyphs in the Unicode private area
defineMacro("\\gvertneqq", "\\html@mathml{\\@gvertneqq}{\u2269}");
defineMacro("\\lvertneqq", "\\html@mathml{\\@lvertneqq}{\u2268}");
defineMacro("\\ngeqq", "\\html@mathml{\\@ngeqq}{\u2271}");
defineMacro("\\ngeqslant", "\\html@mathml{\\@ngeqslant}{\u2271}");
defineMacro("\\nleqq", "\\html@mathml{\\@nleqq}{\u2270}");
defineMacro("\\nleqslant", "\\html@mathml{\\@nleqslant}{\u2270}");
defineMacro("\\nshortmid", "\\html@mathml{\\@nshortmid}{∤}");
defineMacro("\\nshortparallel", "\\html@mathml{\\@nshortparallel}{∦}");
defineMacro("\\nsubseteqq", "\\html@mathml{\\@nsubseteqq}{\u2288}");
defineMacro("\\nsupseteqq", "\\html@mathml{\\@nsupseteqq}{\u2289}");
defineMacro("\\varsubsetneq", "\\html@mathml{\\@varsubsetneq}{⊊}");
defineMacro("\\varsubsetneqq", "\\html@mathml{\\@varsubsetneqq}{⫋}");
defineMacro("\\varsupsetneq", "\\html@mathml{\\@varsupsetneq}{⊋}");
defineMacro("\\varsupsetneqq", "\\html@mathml{\\@varsupsetneqq}{⫌}");
defineMacro("\\imath", "\\html@mathml{\\@imath}{\u0131}");
defineMacro("\\jmath", "\\html@mathml{\\@jmath}{\u0237}"); //////////////////////////////////////////////////////////////////////
// stmaryrd and semantic
// The stmaryrd and semantic packages render the next four items by calling a
// glyph. Those glyphs do not exist in the KaTeX fonts. Hence the macros.
defineMacro("\\llbracket", "\\html@mathml{\\mathopen{[\\mkern-3.2mu[}}{\\mathopen{\\char`⟦}}");
defineMacro("\\rrbracket", "\\html@mathml{\\mathclose{]\\mkern-3.2mu]}}{\\mathclose{\\char`⟧}}");
defineMacro("\u27e6", "\\llbracket"); // blackboard bold [
defineMacro("\u27e7", "\\rrbracket"); // blackboard bold ]
defineMacro("\\lBrace", "\\html@mathml{\\mathopen{\\{\\mkern-3.2mu[}}{\\mathopen{\\char`⦃}}");
defineMacro("\\rBrace", "\\html@mathml{\\mathclose{]\\mkern-3.2mu\\}}}{\\mathclose{\\char`⦄}}");
defineMacro("\u2983", "\\lBrace"); // blackboard bold {
defineMacro("\u2984", "\\rBrace"); // blackboard bold }
// TODO: Create variable sized versions of the last two items. I believe that
// will require new font glyphs.
// The stmaryrd function `\minuso` provides a "Plimsoll" symbol that
// superimposes the characters \circ and \mathminus. Used in chemistry.
defineMacro("\\minuso", "\\mathbin{\\html@mathml{{\\mathrlap{\\mathchoice{\\kern{0.145em}}{\\kern{0.145em}}{\\kern{0.1015em}}{\\kern{0.0725em}}\\circ}{-}}}{\\char`⦵}}");
defineMacro("⦵", "\\minuso"); //////////////////////////////////////////////////////////////////////
// texvc.sty
// The texvc package contains macros available in mediawiki pages.
// We omit the functions deprecated at
// https://en.wikipedia.org/wiki/Help:Displaying_a_formula#Deprecated_syntax
// We also omit texvc's \O, which conflicts with \text{\O}
defineMacro("\\darr", "\\downarrow");
defineMacro("\\dArr", "\\Downarrow");
defineMacro("\\Darr", "\\Downarrow");
defineMacro("\\lang", "\\langle");
defineMacro("\\rang", "\\rangle");
defineMacro("\\uarr", "\\uparrow");
defineMacro("\\uArr", "\\Uparrow");
defineMacro("\\Uarr", "\\Uparrow");
defineMacro("\\N", "\\mathbb{N}");
defineMacro("\\R", "\\mathbb{R}");
defineMacro("\\Z", "\\mathbb{Z}");
defineMacro("\\alef", "\\aleph");
defineMacro("\\alefsym", "\\aleph");
defineMacro("\\Alpha", "\\mathrm{A}");
defineMacro("\\Beta", "\\mathrm{B}");
defineMacro("\\bull", "\\bullet");
defineMacro("\\Chi", "\\mathrm{X}");
defineMacro("\\clubs", "\\clubsuit");
defineMacro("\\cnums", "\\mathbb{C}");
defineMacro("\\Complex", "\\mathbb{C}");
defineMacro("\\Dagger", "\\ddagger");
defineMacro("\\diamonds", "\\diamondsuit");
defineMacro("\\empty", "\\emptyset");
defineMacro("\\Epsilon", "\\mathrm{E}");
defineMacro("\\Eta", "\\mathrm{H}");
defineMacro("\\exist", "\\exists");
defineMacro("\\harr", "\\leftrightarrow");
defineMacro("\\hArr", "\\Leftrightarrow");
defineMacro("\\Harr", "\\Leftrightarrow");
defineMacro("\\hearts", "\\heartsuit");
defineMacro("\\image", "\\Im");
defineMacro("\\infin", "\\infty");
defineMacro("\\Iota", "\\mathrm{I}");
defineMacro("\\isin", "\\in");
defineMacro("\\Kappa", "\\mathrm{K}");
defineMacro("\\larr", "\\leftarrow");
defineMacro("\\lArr", "\\Leftarrow");
defineMacro("\\Larr", "\\Leftarrow");
defineMacro("\\lrarr", "\\leftrightarrow");
defineMacro("\\lrArr", "\\Leftrightarrow");
defineMacro("\\Lrarr", "\\Leftrightarrow");
defineMacro("\\Mu", "\\mathrm{M}");
defineMacro("\\natnums", "\\mathbb{N}");
defineMacro("\\Nu", "\\mathrm{N}");
defineMacro("\\Omicron", "\\mathrm{O}");
defineMacro("\\plusmn", "\\pm");
defineMacro("\\rarr", "\\rightarrow");
defineMacro("\\rArr", "\\Rightarrow");
defineMacro("\\Rarr", "\\Rightarrow");
defineMacro("\\real", "\\Re");
defineMacro("\\reals", "\\mathbb{R}");
defineMacro("\\Reals", "\\mathbb{R}");
defineMacro("\\Rho", "\\mathrm{P}");
defineMacro("\\sdot", "\\cdot");
defineMacro("\\sect", "\\S");
defineMacro("\\spades", "\\spadesuit");
defineMacro("\\sub", "\\subset");
defineMacro("\\sube", "\\subseteq");
defineMacro("\\supe", "\\supseteq");
defineMacro("\\Tau", "\\mathrm{T}");
defineMacro("\\thetasym", "\\vartheta"); // TODO: defineMacro("\\varcoppa", "\\\mbox{\\coppa}");
defineMacro("\\weierp", "\\wp");
defineMacro("\\Zeta", "\\mathrm{Z}"); //////////////////////////////////////////////////////////////////////
// statmath.sty
// https://ctan.math.illinois.edu/macros/latex/contrib/statmath/statmath.pdf
defineMacro("\\argmin", "\\DOTSB\\operatorname*{arg\\,min}");
defineMacro("\\argmax", "\\DOTSB\\operatorname*{arg\\,max}");
defineMacro("\\plim", "\\DOTSB\\mathop{\\operatorname{plim}}\\limits"); //////////////////////////////////////////////////////////////////////
// braket.sty
// http://ctan.math.washington.edu/tex-archive/macros/latex/contrib/braket/braket.pdf
defineMacro("\\bra", "\\mathinner{\\langle{#1}|}");
defineMacro("\\ket", "\\mathinner{|{#1}\\rangle}");
defineMacro("\\braket", "\\mathinner{\\langle{#1}\\rangle}");
defineMacro("\\Bra", "\\left\\langle#1\\right|");
defineMacro("\\Ket", "\\left|#1\\right\\rangle");
var braketHelper = (one)=>(context)=>{
var left = context.consumeArg().tokens;
var middle = context.consumeArg().tokens;
var middleDouble = context.consumeArg().tokens;
var right = context.consumeArg().tokens;
var oldMiddle = context.macros.get("|");
var oldMiddleDouble = context.macros.get("\\|");
context.macros.beginGroup();
var midMacro = (double)=>(context)=>{
if (one) {
// Only modify the first instance of | or \|
context.macros.set("|", oldMiddle);
if (middleDouble.length) context.macros.set("\\|", oldMiddleDouble);
}
var doubled = double;
if (!double && middleDouble.length) {
// Mimic \@ifnextchar
var nextToken = context.future();
if (nextToken.text === "|") {
context.popToken();
doubled = true;
}
}
return {
tokens: doubled ? middleDouble : middle,
numArgs: 0
};
};
context.macros.set("|", midMacro(false));
if (middleDouble.length) context.macros.set("\\|", midMacro(true));
var arg = context.consumeArg().tokens;
var expanded = context.expandTokens([
...right,
...arg,
...left // reversed
]);
context.macros.endGroup();
return {
tokens: expanded.reverse(),
numArgs: 0
};
};
defineMacro("\\bra@ket", braketHelper(false));
defineMacro("\\bra@set", braketHelper(true));
defineMacro("\\Braket", "\\bra@ket{\\left\\langle}{\\,\\middle\\vert\\,}{\\,\\middle\\vert\\,}{\\right\\rangle}");
defineMacro("\\Set", "\\bra@set{\\left\\{\\:}{\\;\\middle\\vert\\;}{\\;\\middle\\Vert\\;}{\\:\\right\\}}");
defineMacro("\\set", "\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}"); // has no support for special || or \|
//////////////////////////////////////////////////////////////////////
// actuarialangle.dtx
defineMacro("\\angln", "{\\angl n}"); // Custom Khan Academy colors, should be moved to an optional package
defineMacro("\\blue", "\\textcolor{##6495ed}{#1}");
defineMacro("\\orange", "\\textcolor{##ffa500}{#1}");
defineMacro("\\pink", "\\textcolor{##ff00af}{#1}");
defineMacro("\\red", "\\textcolor{##df0030}{#1}");
defineMacro("\\green", "\\textcolor{##28ae7b}{#1}");
defineMacro("\\gray", "\\textcolor{gray}{#1}");
defineMacro("\\purple", "\\textcolor{##9d38bd}{#1}");
defineMacro("\\blueA", "\\textcolor{##ccfaff}{#1}");
defineMacro("\\blueB", "\\textcolor{##80f6ff}{#1}");
defineMacro("\\blueC", "\\textcolor{##63d9ea}{#1}");
defineMacro("\\blueD", "\\textcolor{##11accd}{#1}");
defineMacro("\\blueE", "\\textcolor{##0c7f99}{#1}");
defineMacro("\\tealA", "\\textcolor{##94fff5}{#1}");
defineMacro("\\tealB", "\\textcolor{##26edd5}{#1}");
defineMacro("\\tealC", "\\textcolor{##01d1c1}{#1}");
defineMacro("\\tealD", "\\textcolor{##01a995}{#1}");
defineMacro("\\tealE", "\\textcolor{##208170}{#1}");
defineMacro("\\greenA", "\\textcolor{##b6ffb0}{#1}");
defineMacro("\\greenB", "\\textcolor{##8af281}{#1}");
defineMacro("\\greenC", "\\textcolor{##74cf70}{#1}");
defineMacro("\\greenD", "\\textcolor{##1fab54}{#1}");
defineMacro("\\greenE", "\\textcolor{##0d923f}{#1}");
defineMacro("\\goldA", "\\textcolor{##ffd0a9}{#1}");
defineMacro("\\goldB", "\\textcolor{##ffbb71}{#1}");
defineMacro("\\goldC", "\\textcolor{##ff9c39}{#1}");
defineMacro("\\goldD", "\\textcolor{##e07d10}{#1}");
defineMacro("\\goldE", "\\textcolor{##a75a05}{#1}");
defineMacro("\\redA", "\\textcolor{##fca9a9}{#1}");
defineMacro("\\redB", "\\textcolor{##ff8482}{#1}");
defineMacro("\\redC", "\\textcolor{##f9685d}{#1}");
defineMacro("\\redD", "\\textcolor{##e84d39}{#1}");
defineMacro("\\redE", "\\textcolor{##bc2612}{#1}");
defineMacro("\\maroonA", "\\textcolor{##ffbde0}{#1}");
defineMacro("\\maroonB", "\\textcolor{##ff92c6}{#1}");
defineMacro("\\maroonC", "\\textcolor{##ed5fa6}{#1}");
defineMacro("\\maroonD", "\\textcolor{##ca337c}{#1}");
defineMacro("\\maroonE", "\\textcolor{##9e034e}{#1}");
defineMacro("\\purpleA", "\\textcolor{##ddd7ff}{#1}");
defineMacro("\\purpleB", "\\textcolor{##c6b9fc}{#1}");
defineMacro("\\purpleC", "\\textcolor{##aa87ff}{#1}");
defineMacro("\\purpleD", "\\textcolor{##7854ab}{#1}");
defineMacro("\\purpleE", "\\textcolor{##543b78}{#1}");
defineMacro("\\mintA", "\\textcolor{##f5f9e8}{#1}");
defineMacro("\\mintB", "\\textcolor{##edf2df}{#1}");
defineMacro("\\mintC", "\\textcolor{##e0e5cc}{#1}");
defineMacro("\\grayA", "\\textcolor{##f6f7f7}{#1}");
defineMacro("\\grayB", "\\textcolor{##f0f1f2}{#1}");
defineMacro("\\grayC", "\\textcolor{##e3e5e6}{#1}");
defineMacro("\\grayD", "\\textcolor{##d6d8da}{#1}");
defineMacro("\\grayE", "\\textcolor{##babec2}{#1}");
defineMacro("\\grayF", "\\textcolor{##888d93}{#1}");
defineMacro("\\grayG", "\\textcolor{##626569}{#1}");
defineMacro("\\grayH", "\\textcolor{##3b3e40}{#1}");
defineMacro("\\grayI", "\\textcolor{##21242c}{#1}");
defineMacro("\\kaBlue", "\\textcolor{##314453}{#1}");
defineMacro("\\kaGreen", "\\textcolor{##71B307}{#1}");
/**
* This file contains the “gullet” where macros are expanded
* until only non-macro tokens remain.
*/ // List of commands that act like macros but aren't defined as a macro,
// function, or symbol. Used in `isDefined`.
var implicitCommands = {
"^": true,
// Parser.js
"_": true,
// Parser.js
"\\limits": true,
// Parser.js
"\\nolimits": true // Parser.js
};
class MacroExpander {
constructor(input, settings, mode){
this.settings = void 0;
this.expansionCount = void 0;
this.lexer = void 0;
this.macros = void 0;
this.stack = void 0;
this.mode = void 0;
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) {
this.lexer = new Lexer(input, this.settings);
}
/**
* Switches between "text" and "math" modes.
*/ switchMode(newMode) {
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() {
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() {
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) {
this.stack.push(token);
}
/**
* Append an array of tokens to the token stack.
*/ pushTokens(tokens) {
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) {
var start;
var end;
var 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(;;){
var 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) {
// 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.
var tokens = [];
var 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 doesn’t use single spaces as undelimited arguments."
this.consumeSpaces();
var start = this.future();
var tok;
var depth = 0;
var 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, delimiters) {
if (delimiters) {
if (delimiters.length !== numArgs + 1) throw new ParseError("The length of delimiters doesn't match the number of args!");
var delims = delimiters[0];
for(var i = 0; i < delims.length; i++){
var tok = this.popToken();
if (delims[i] !== tok.text) throw new ParseError("Use of the macro doesn't match its definition", tok);
}
}
var args = [];
for(var _i = 0; _i < numArgs; _i++)args.push(this.consumeArg(delimiters && delimiters[_i + 1]).tokens);
return args;
}
/**
* 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) {
var topToken = this.popToken();
var name = topToken.text;
var 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.expansionCount++;
if (this.expansionCount > this.settings.maxExpand) throw new ParseError("Too many expansions: infinite loop or need to increase maxExpand setting");
var tokens = expansion.tokens;
var 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(var i = tokens.length - 1; i >= 0; --i){
var 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() {
this.expandOnce();
return this.future();
}
/**
* Recursively expand first token, then return first non-expandable token.
*/ expandNextToken() {
for(;;)if (this.expandOnce() === false) {
// fully expanded
var 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) {
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) {
var output = [];
var oldStackLength = this.stack.length;
this.pushTokens(tokens);
while(this.stack.length > oldStackLength)// Expand only expandable tokens
if (this.expandOnce(true) === false) {
// fully expanded
var token = this.stack.pop();
if (token.treatAsRelax) {
// the expansion of \noexpand is the token itself
token.noexpand = false;
token.treatAsRelax = false;
}
output.push(token);
}
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) {
var 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) {
var 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) {
var catcode = this.lexer.catcodes[name];
if (catcode != null && catcode !== 13) return;
}
var expansion = typeof definition === "function" ? definition(this) : definition;
if (typeof expansion === "string") {
var numArgs = 0;
if (expansion.indexOf("#") !== -1) {
var stripped = expansion.replace(/##/g, "");
while(stripped.indexOf("#" + (numArgs + 1)) !== -1)++numArgs;
}
var bodyLexer = new Lexer(expansion, this.settings);
var tokens = [];
var tok = bodyLexer.lex();
while(tok.text !== "EOF"){
tokens.push(tok);
tok = bodyLexer.lex();
}
tokens.reverse(); // to fit in with stack using push and pop
var 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) {
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) {
var macro = this.macros.get(name);
return macro != null ? typeof macro === "string" || typeof macro === "function" || !macro.unexpandable : functions.hasOwnProperty(name) && !functions[name].primitive;
}
}
// Helpers for Parser.js handling of Unicode (sub|super)script characters.
var unicodeSubRegEx = /^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/;
var 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': 'θ'
});
/* eslint no-constant-condition:0 */ var unicodeAccents = {
"́": {
"text": "\\'",
"math": "\\acute"
},
"̀": {
"text": "\\`",
"math": "\\grave"
},
"̈": {
"text": "\\\"",
"math": "\\ddot"
},
"̃": {
"text": "\\~",
"math": "\\tilde"
},
"̄": {
"text": "\\=",
"math": "\\bar"
},
"̆": {
"text": "\\u",
"math": "\\breve"
},
"̌": {
"text": "\\v",
"math": "\\check"
},
"̂": {
"text": "\\^",
"math": "\\hat"
},
"̇": {
"text": "\\.",
"math": "\\dot"
},
"̊": {
"text": "\\r",
"math": "\\mathring"
},
"̋": {
"text": "\\H"
},
"̧": {
"text": "\\c"
}
};
var unicodeSymbols = {
"á": "á",
"à": "à",
"ä": "ä",
"ǟ": "ǟ",
"ã": "ã",
"ā": "ā",
"ă": "ă",
"ắ": "ắ",
"ằ": "ằ",
"ẵ": "ẵ",
"ǎ": "ǎ",
"â": "â",
"ấ": "ấ",
"ầ": "ầ",
"ẫ": "ẫ",
"ȧ": "ȧ",
"ǡ": "ǡ",
"å": "å",
"ǻ": "ǻ",
"ḃ": "ḃ",
"ć": "ć",
"ḉ": "ḉ",
"č": "č",
"ĉ": "ĉ",
"ċ": "ċ",
"ç": "ç",
"ď": "ď",
"ḋ": "ḋ",
"ḑ": "ḑ",
"é": "é",
"è": "è",
"ë": "ë",
"ẽ": "ẽ",
"ē": "ē",
"ḗ": "ḗ",
"ḕ": "ḕ",
"ĕ": "ĕ",
"ḝ": "ḝ",
"ě": "ě",
"ê": "ê",
"ế": "ế",
"ề": "ề",
"ễ": "ễ",
"ė": "ė",
"ȩ": "ȩ",
"ḟ": "ḟ",
"ǵ": "ǵ",
"ḡ": "ḡ",
"ğ": "ğ",
"ǧ": "ǧ",
"ĝ": "ĝ",
"ġ": "ġ",
"ģ": "ģ",
"ḧ": "ḧ",
"ȟ": "ȟ",
"ĥ": "ĥ",
"ḣ": "ḣ",
"ḩ": "ḩ",
"í": "í",
"ì": "ì",
"ï": "ï",
"ḯ": "ḯ",
"ĩ": "ĩ",
"ī": "ī",
"ĭ": "ĭ",
"ǐ": "ǐ",
"î": "î",
"ǰ": "ǰ",
"ĵ": "ĵ",
"ḱ": "ḱ",
"ǩ": "ǩ",
"ķ": "ķ",
"ĺ": "ĺ",
"ľ": "ľ",
"ļ": "ļ",
"ḿ": "ḿ",
"ṁ": "ṁ",
"ń": "ń",
"ǹ": "ǹ",
"ñ": "ñ",
"ň": "ň",
"ṅ": "ṅ",
"ņ": "ņ",
"ó": "ó",
"ò": "ò",
"ö": "ö",
"ȫ": "ȫ",
"õ": "õ",
"ṍ": "ṍ",
"ṏ": "ṏ",
"ȭ": "ȭ",
"ō": "ō",
"ṓ": "ṓ",
"ṑ": "ṑ",
"ŏ": "ŏ",
"ǒ": "ǒ",
"ô": "ô",
"ố": "ố",
"ồ": "ồ",
"ỗ": "ỗ",
"ȯ": "ȯ",
"ȱ": "ȱ",
"ő": "ő",
"ṕ": "ṕ",
"ṗ": "ṗ",
"ŕ": "ŕ",
"ř": "ř",
"ṙ": "ṙ",
"ŗ": "ŗ",
"ś": "ś",
"ṥ": "ṥ",
"š": "š",
"ṧ": "ṧ",
"ŝ": "ŝ",
"ṡ": "ṡ",
"ş": "ş",
"ẗ": "ẗ",
"ť": "ť",
"ṫ": "ṫ",
"ţ": "ţ",
"ú": "ú",
"ù": "ù",
"ü": "ü",
"ǘ": "ǘ",
"ǜ": "ǜ",
"ǖ": "ǖ",
"ǚ": "ǚ",
"ũ": "ũ",
"ṹ": "ṹ",
"ū": "ū",
"ṻ": "ṻ",
"ŭ": "ŭ",
"ǔ": "ǔ",
"û": "û",
"ů": "ů",
"ű": "ű",
"ṽ": "ṽ",
"ẃ": "ẃ",
"ẁ": "ẁ",
"ẅ": "ẅ",
"ŵ": "ŵ",
"ẇ": "ẇ",
"ẘ": "ẘ",
"ẍ": "ẍ",
"ẋ": "ẋ",
"ý": "ý",
"ỳ": "ỳ",
"ÿ": "ÿ",
"ỹ": "ỹ",
"ȳ": "ȳ",
"ŷ": "ŷ",
"ẏ": "ẏ",
"ẙ": "ẙ",
"ź": "ź",
"ž": "ž",
"ẑ": "ẑ",
"ż": "ż",
"Á": "Á",
"À": "À",
"Ä": "Ä",
"Ǟ": "Ǟ",
"Ã": "Ã",
"Ā": "Ā",
"Ă": "Ă",
"Ắ": "Ắ",
"Ằ": "Ằ",
"Ẵ": "Ẵ",
"Ǎ": "Ǎ",
"Â": "Â",
"Ấ": "Ấ",
"Ầ": "Ầ",
"Ẫ": "Ẫ",
"Ȧ": "Ȧ",
"Ǡ": "Ǡ",
"Å": "Å",
"Ǻ": "Ǻ",
"Ḃ": "Ḃ",
"Ć": "Ć",
"Ḉ": "Ḉ",
"Č": "Č",
"Ĉ": "Ĉ",
"Ċ": "Ċ",
"Ç": "Ç",
"Ď": "Ď",
"Ḋ": "Ḋ",
"Ḑ": "Ḑ",
"É": "É",
"È": "È",
"Ë": "Ë",
"Ẽ": "Ẽ",
"Ē": "Ē",
"Ḗ": "Ḗ",
"Ḕ": "Ḕ",
"Ĕ": "Ĕ",
"Ḝ": "Ḝ",
"Ě": "Ě",
"Ê": "Ê",
"Ế": "Ế",
"Ề": "Ề",
"Ễ": "Ễ",
"Ė": "Ė",
"Ȩ": "Ȩ",
"Ḟ": "Ḟ",
"Ǵ": "Ǵ",
"Ḡ": "Ḡ",
"Ğ": "Ğ",
"Ǧ": "Ǧ",
"Ĝ": "Ĝ",
"Ġ": "Ġ",
"Ģ": "Ģ",
"Ḧ": "Ḧ",
"Ȟ": "Ȟ",
"Ĥ": "Ĥ",
"Ḣ": "Ḣ",
"Ḩ": "Ḩ",
"Í": "Í",
"Ì": "Ì",
"Ï": "Ï",
"Ḯ": "Ḯ",
"Ĩ": "Ĩ",
"Ī": "Ī",
"Ĭ": "Ĭ",
"Ǐ": "Ǐ",
"Î": "Î",
"İ": "İ",
"Ĵ": "Ĵ",
"Ḱ": "Ḱ",
"Ǩ": "Ǩ",
"Ķ": "Ķ",
"Ĺ": "Ĺ",
"Ľ": "Ľ",
"Ļ": "Ļ",
"Ḿ": "Ḿ",
"Ṁ": "Ṁ",
"Ń": "Ń",
"Ǹ": "Ǹ",
"Ñ": "Ñ",
"Ň": "Ň",
"Ṅ": "Ṅ",
"Ņ": "Ņ",
"Ó": "Ó",
"Ò": "Ò",
"Ö": "Ö",
"Ȫ": "Ȫ",
"Õ": "Õ",
"Ṍ": "Ṍ",
"Ṏ": "Ṏ",
"Ȭ": "Ȭ",
"Ō": "Ō",
"Ṓ": "Ṓ",
"Ṑ": "Ṑ",
"Ŏ": "Ŏ",
"Ǒ": "Ǒ",
"Ô": "Ô",
"Ố": "Ố",
"Ồ": "Ồ",
"Ỗ": "Ỗ",
"Ȯ": "Ȯ",
"Ȱ": "Ȱ",
"Ő": "Ő",
"Ṕ": "Ṕ",
"Ṗ": "Ṗ",
"Ŕ": "Ŕ",
"Ř": "Ř",
"Ṙ": "Ṙ",
"Ŗ": "Ŗ",
"Ś": "Ś",
"Ṥ": "Ṥ",
"Š": "Š",
"Ṧ": "Ṧ",
"Ŝ": "Ŝ",
"Ṡ": "Ṡ",
"Ş": "Ş",
"Ť": "Ť",
"Ṫ": "Ṫ",
"Ţ": "Ţ",
"Ú": "Ú",
"Ù": "Ù",
"Ü": "Ü",
"Ǘ": "Ǘ",
"Ǜ": "Ǜ",
"Ǖ": "Ǖ",
"Ǚ": "Ǚ",
"Ũ": "Ũ",
"Ṹ": "Ṹ",
"Ū": "Ū",
"Ṻ": "Ṻ",
"Ŭ": "Ŭ",
"Ǔ": "Ǔ",
"Û": "Û",
"Ů": "Ů",
"Ű": "Ű",
"Ṽ": "Ṽ",
"Ẃ": "Ẃ",
"Ẁ": "Ẁ",
"Ẅ": "Ẅ",
"Ŵ": "Ŵ",
"Ẇ": "Ẇ",
"Ẍ": "Ẍ",
"Ẋ": "Ẋ",
"Ý": "Ý",
"Ỳ": "Ỳ",
"Ÿ": "Ÿ",
"Ỹ": "Ỹ",
"Ȳ": "Ȳ",
"Ŷ": "Ŷ",
"Ẏ": "Ẏ",
"Ź": "Ź",
"Ž": "Ž",
"Ẑ": "Ẑ",
"Ż": "Ż",
"ά": "ά",
"ὰ": "ὰ",
"ᾱ": "ᾱ",
"ᾰ": "ᾰ",
"έ": "έ",
"ὲ": "ὲ",
"ή": "ή",
"ὴ": "ὴ",
"ί": "ί",
"ὶ": "ὶ",
"ϊ": "ϊ",
"ΐ": "ΐ",
"ῒ": "ῒ",
"ῑ": "ῑ",
"ῐ": "ῐ",
"ό": "ό",
"ὸ": "ὸ",
"ύ": "ύ",
"ὺ": "ὺ",
"ϋ": "ϋ",
"ΰ": "ΰ",
"ῢ": "ῢ",
"ῡ": "ῡ",
"ῠ": "ῠ",
"ώ": "ώ",
"ὼ": "ὼ",
"Ύ": "Ύ",
"Ὺ": "Ὺ",
"Ϋ": "Ϋ",
"Ῡ": "Ῡ",
"Ῠ": "Ῠ",
"Ώ": "Ώ",
"Ὼ": "Ὼ"
};
/**
* This file contains the parser used to parse out a TeX expression from the
* input. Since TeX isn't context-free, standard parsers don't work particularly
* well.
*
* The strategy of this parser is as such:
*
* The main functions (the `.parse...` ones) take a position in the current
* parse string to parse tokens from. The lexer (found in Lexer.js, stored at
* this.gullet.lexer) also supports pulling out tokens at arbitrary places. When
* individual tokens are needed at a position, the lexer is called to pull out a
* token, which is then used.
*
* The parser has a property called "mode" indicating the mode that
* the parser is currently in. Currently it has to be one of "math" or
* "text", which denotes whether the current environment is a math-y
* one or a text-y one (e.g. inside \text). Currently, this serves to
* limit the functions which can be used in text mode.
*
* The main functions then return an object which contains the useful data that
* was parsed at its given point, and a new position at the end of the parsed
* data. The main functions can call each other and continue the parsing by
* using the returned position as a new starting point.
*
* There are also extra `.handle...` functions, which pull out some reused
* functionality into self-contained functions.
*
* The functions return ParseNodes.
*/ class Parser {
constructor(input, settings){
this.mode = void 0;
this.gullet = void 0;
this.settings = void 0;
this.leftrightDepth = void 0;
this.nextToken = void 0;
// Start in math mode
this.mode = "math"; // Create a new macro expander (gullet) and (indirectly via that) also a
// new lexer (mouth) for this parser (stomach, in the language of TeX)
this.gullet = new MacroExpander(input, settings, this.mode); // Store the settings for use in parsing
this.settings = settings; // Count leftright depth (for \middle errors)
this.leftrightDepth = 0;
}
/**
* Checks a result to make sure it has the right type, and throws an
* appropriate error otherwise.
*/ expect(text, consume) {
if (consume === void 0) consume = true;
if (this.fetch().text !== text) throw new ParseError("Expected '" + text + "', got '" + this.fetch().text + "'", this.fetch());
if (consume) this.consume();
}
/**
* Discards the current lookahead token, considering it consumed.
*/ consume() {
this.nextToken = null;
}
/**
* Return the current lookahead token, or if there isn't one (at the
* beginning, or if the previous lookahead token was consume()d),
* fetch the next token as the new lookahead token and return it.
*/ fetch() {
if (this.nextToken == null) this.nextToken = this.gullet.expandNextToken();
return this.nextToken;
}
/**
* Switches between "text" and "math" modes.
*/ switchMode(newMode) {
this.mode = newMode;
this.gullet.switchMode(newMode);
}
/**
* Main parsing function, which parses an entire input.
*/ parse() {
if (!this.settings.globalGroup) // Create a group namespace for the math expression.
// (LaTeX creates a new group for every $...$, $$...$$, \[...\].)
this.gullet.beginGroup();
// Use old \color behavior (same as LaTeX's \textcolor) if requested.
// We do this within the group for the math expression, so it doesn't
// pollute settings.macros.
if (this.settings.colorIsTextColor) this.gullet.macros.set("\\color", "\\textcolor");
try {
// Try to parse the input
var parse = this.parseExpression(false); // If we succeeded, make sure there's an EOF at the end
this.expect("EOF"); // End the group namespace for the expression
if (!this.settings.globalGroup) this.gullet.endGroup();
return parse; // Close any leftover groups in case of a parse error.
} finally{
this.gullet.endGroups();
}
}
/**
* Fully parse a separate sequence of tokens as a separate job.
* Tokens should be specified in reverse order, as in a MacroDefinition.
*/ subparse(tokens) {
// Save the next token from the current job.
var oldToken = this.nextToken;
this.consume(); // Run the new job, terminating it with an excess '}'
this.gullet.pushToken(new Token("}"));
this.gullet.pushTokens(tokens);
var parse = this.parseExpression(false);
this.expect("}"); // Restore the next token from the current job.
this.nextToken = oldToken;
return parse;
}
/**
* Parses an "expression", which is a list of atoms.
*
* `breakOnInfix`: Should the parsing stop when we hit infix nodes? This
* happens when functions have higher precedence han infix
* nodes in implicit parses.
*
* `breakOnTokenText`: The text of the token that the expression should end
* with, or `null` if something else should end the
* expression.
*/ parseExpression(breakOnInfix, breakOnTokenText) {
var body = []; // Keep adding atoms to the body until we can't parse any more atoms (either
// we reached the end, a }, or a \right)
while(true){
// Ignore spaces in math mode
if (this.mode === "math") this.consumeSpaces();
var lex = this.fetch();
if (Parser.endOfExpression.indexOf(lex.text) !== -1) break;
if (breakOnTokenText && lex.text === breakOnTokenText) break;
if (breakOnInfix && functions[lex.text] && functions[lex.text].infix) break;
var atom = this.parseAtom(breakOnTokenText);
if (!atom) break;
else if (atom.type === "internal") continue;
body.push(atom);
}
if (this.mode === "text") this.formLigatures(body);
return this.handleInfixNodes(body);
}
/**
* Rewrites infix operators such as \over with corresponding commands such
* as \frac.
*
* There can only be one infix operator per group. If there's more than one
* then the expression is ambiguous. This can be resolved by adding {}.
*/ handleInfixNodes(body) {
var overIndex = -1;
var funcName;
for(var i = 0; i < body.length; i++)if (body[i].type === "infix") {
if (overIndex !== -1) throw new ParseError("only one infix operator per group", body[i].token);
overIndex = i;
funcName = body[i].replaceWith;
}
if (overIndex !== -1 && funcName) {
var numerNode;
var denomNode;
var numerBody = body.slice(0, overIndex);
var denomBody = body.slice(overIndex + 1);
if (numerBody.length === 1 && numerBody[0].type === "ordgroup") numerNode = numerBody[0];
else numerNode = {
type: "ordgroup",
mode: this.mode,
body: numerBody
};
if (denomBody.length === 1 && denomBody[0].type === "ordgroup") denomNode = denomBody[0];
else denomNode = {
type: "ordgroup",
mode: this.mode,
body: denomBody
};
var node;
if (funcName === "\\\\abovefrac") node = this.callFunction(funcName, [
numerNode,
body[overIndex],
denomNode
], []);
else node = this.callFunction(funcName, [
numerNode,
denomNode
], []);
return [
node
];
} else return body;
}
/**
* Handle a subscript or superscript with nice errors.
*/ handleSupSubscript(name // For error reporting.
) {
var symbolToken = this.fetch();
var symbol = symbolToken.text;
this.consume();
this.consumeSpaces(); // ignore spaces before sup/subscript argument
var group = this.parseGroup(name);
if (!group) throw new ParseError("Expected group after '" + symbol + "'", symbolToken);
return group;
}
/**
* Converts the textual input of an unsupported command into a text node
* contained within a color node whose color is determined by errorColor
*/ formatUnsupportedCmd(text) {
var textordArray = [];
for(var i = 0; i < text.length; i++)textordArray.push({
type: "textord",
mode: "text",
text: text[i]
});
var textNode = {
type: "text",
mode: this.mode,
body: textordArray
};
var colorNode = {
type: "color",
mode: this.mode,
color: this.settings.errorColor,
body: [
textNode
]
};
return colorNode;
}
/**
* Parses a group with optional super/subscripts.
*/ parseAtom(breakOnTokenText) {
// The body of an atom is an implicit group, so that things like
// \left(x\right)^2 work correctly.
var base = this.parseGroup("atom", breakOnTokenText); // In text mode, we don't have superscripts or subscripts
if (this.mode === "text") return base;
// Note that base may be empty (i.e. null) at this point.
var superscript;
var subscript;
while(true){
// Guaranteed in math mode, so eat any spaces first.
this.consumeSpaces(); // Lex the first token
var lex = this.fetch();
if (lex.text === "\\limits" || lex.text === "\\nolimits") {
// We got a limit control
if (base && base.type === "op") {
var limits = lex.text === "\\limits";
base.limits = limits;
base.alwaysHandleSupSub = true;
} else if (base && base.type === "operatorname") {
if (base.alwaysHandleSupSub) base.limits = lex.text === "\\limits";
} else throw new ParseError("Limit controls must follow a math operator", lex);
this.consume();
} else if (lex.text === "^") {
// We got a superscript start
if (superscript) throw new ParseError("Double superscript", lex);
superscript = this.handleSupSubscript("superscript");
} else if (lex.text === "_") {
// We got a subscript start
if (subscript) throw new ParseError("Double subscript", lex);
subscript = this.handleSupSubscript("subscript");
} else if (lex.text === "'") {
// We got a prime
if (superscript) throw new ParseError("Double superscript", lex);
var prime = {
type: "textord",
mode: this.mode,
text: "\\prime"
}; // Many primes can be grouped together, so we handle this here
var primes = [
prime
];
this.consume(); // Keep lexing tokens until we get something that's not a prime
while(this.fetch().text === "'"){
// For each one, add another prime to the list
primes.push(prime);
this.consume();
} // If there's a superscript following the primes, combine that
// superscript in with the primes.
if (this.fetch().text === "^") primes.push(this.handleSupSubscript("superscript"));
// Put everything into an ordgroup as the superscript
superscript = {
type: "ordgroup",
mode: this.mode,
body: primes
};
} else if (uSubsAndSups[lex.text]) {
// A Unicode subscript or superscript character.
// We treat these similarly to the unicode-math package.
// So we render a string of Unicode (sub|super)scripts the
// same as a (sub|super)script of regular characters.
var str = uSubsAndSups[lex.text];
var isSub = unicodeSubRegEx.test(lex.text);
this.consume(); // Continue fetching tokens to fill out the string.
while(true){
var token = this.fetch().text;
if (!uSubsAndSups[token]) break;
if (unicodeSubRegEx.test(token) !== isSub) break;
this.consume();
str += uSubsAndSups[token];
} // Now create a (sub|super)script.
var body = new Parser(str, this.settings).parse();
if (isSub) subscript = {
type: "ordgroup",
mode: "math",
body
};
else superscript = {
type: "ordgroup",
mode: "math",
body
};
} else break;
} // Base must be set if superscript or subscript are set per logic above,
// but need to check here for type check to pass.
if (superscript || subscript) // If we got either a superscript or subscript, create a supsub
return {
type: "supsub",
mode: this.mode,
base: base,
sup: superscript,
sub: subscript
};
else // Otherwise return the original body
return base;
}
/**
* Parses an entire function, including its base and all of its arguments.
*/ parseFunction(breakOnTokenText, name // For determining its context
) {
var token = this.fetch();
var func = token.text;
var funcData = functions[func];
if (!funcData) return null;
this.consume(); // consume command token
if (name && name !== "atom" && !funcData.allowedInArgument) throw new ParseError("Got function '" + func + "' with no arguments" + (name ? " as " + name : ""), token);
else if (this.mode === "text" && !funcData.allowedInText) throw new ParseError("Can't use function '" + func + "' in text mode", token);
else if (this.mode === "math" && funcData.allowedInMath === false) throw new ParseError("Can't use function '" + func + "' in math mode", token);
var { args, optArgs } = this.parseArguments(func, funcData);
return this.callFunction(func, args, optArgs, token, breakOnTokenText);
}
/**
* Call a function handler with a suitable context and arguments.
*/ callFunction(name, args, optArgs, token, breakOnTokenText) {
var context = {
funcName: name,
parser: this,
token,
breakOnTokenText
};
var func = functions[name];
if (func && func.handler) return func.handler(context, args, optArgs);
else throw new ParseError("No function handler for " + name);
}
/**
* Parses the arguments of a function or environment
*/ parseArguments(func, funcData) {
var totalArgs = funcData.numArgs + funcData.numOptionalArgs;
if (totalArgs === 0) return {
args: [],
optArgs: []
};
var args = [];
var optArgs = [];
for(var i = 0; i < totalArgs; i++){
var argType = funcData.argTypes && funcData.argTypes[i];
var isOptional = i < funcData.numOptionalArgs;
if (funcData.primitive && argType == null || // \sqrt expands into primitive if optional argument doesn't exist
funcData.type === "sqrt" && i === 1 && optArgs[0] == null) argType = "primitive";
var arg = this.parseGroupOfType("argument to '" + func + "'", argType, isOptional);
if (isOptional) optArgs.push(arg);
else if (arg != null) args.push(arg);
else // should be unreachable
throw new ParseError("Null argument, please report this as a bug");
}
return {
args,
optArgs
};
}
/**
* Parses a group when the mode is changing.
*/ parseGroupOfType(name, type, optional) {
switch(type){
case "color":
return this.parseColorGroup(optional);
case "size":
return this.parseSizeGroup(optional);
case "url":
return this.parseUrlGroup(optional);
case "math":
case "text":
return this.parseArgumentGroup(optional, type);
case "hbox":
// hbox argument type wraps the argument in the equivalent of
// \hbox, which is like \text but switching to \textstyle size.
var group = this.parseArgumentGroup(optional, "text");
return group != null ? {
type: "styling",
mode: group.mode,
body: [
group
],
style: "text" // simulate \textstyle
} : null;
case "raw":
var token = this.parseStringGroup("raw", optional);
return token != null ? {
type: "raw",
mode: "text",
string: token.text
} : null;
case "primitive":
if (optional) throw new ParseError("A primitive argument cannot be optional");
var _group = this.parseGroup(name);
if (_group == null) throw new ParseError("Expected group as " + name, this.fetch());
return _group;
case "original":
case null:
case undefined:
return this.parseArgumentGroup(optional);
default:
throw new ParseError("Unknown group type as " + name, this.fetch());
}
}
/**
* Discard any space tokens, fetching the next non-space token.
*/ consumeSpaces() {
while(this.fetch().text === " ")this.consume();
}
/**
* Parses a group, essentially returning the string formed by the
* brace-enclosed tokens plus some position information.
*/ parseStringGroup(modeName, optional) {
var argToken = this.gullet.scanArgument(optional);
if (argToken == null) return null;
var str = "";
var nextToken;
while((nextToken = this.fetch()).text !== "EOF"){
str += nextToken.text;
this.consume();
}
this.consume(); // consume the end of the argument
argToken.text = str;
return argToken;
}
/**
* Parses a regex-delimited group: the largest sequence of tokens
* whose concatenated strings match `regex`. Returns the string
* formed by the tokens plus some position information.
*/ parseRegexGroup(regex, modeName // Used to describe the mode in error messages.
) {
var firstToken = this.fetch();
var lastToken = firstToken;
var str = "";
var nextToken;
while((nextToken = this.fetch()).text !== "EOF" && regex.test(str + nextToken.text)){
lastToken = nextToken;
str += lastToken.text;
this.consume();
}
if (str === "") throw new ParseError("Invalid " + modeName + ": '" + firstToken.text + "'", firstToken);
return firstToken.range(lastToken, str);
}
/**
* Parses a color description.
*/ parseColorGroup(optional) {
var res = this.parseStringGroup("color", optional);
if (res == null) return null;
var match = /^(#[a-f0-9]{3}|#?[a-f0-9]{6}|[a-z]+)$/i.exec(res.text);
if (!match) throw new ParseError("Invalid color: '" + res.text + "'", res);
var color = match[0];
if (/^[0-9a-f]{6}$/i.test(color)) // We allow a 6-digit HTML color spec without a leading "#".
// This follows the xcolor package's HTML color model.
// Predefined color names are all missed by this RegEx pattern.
color = "#" + color;
return {
type: "color-token",
mode: this.mode,
color
};
}
/**
* Parses a size specification, consisting of magnitude and unit.
*/ parseSizeGroup(optional) {
var res;
var isBlank = false; // don't expand before parseStringGroup
this.gullet.consumeSpaces();
if (!optional && this.gullet.future().text !== "{") res = this.parseRegexGroup(/^[-+]? *(?:$|\d+|\d+\.\d*|\.\d*) *[a-z]{0,2} *$/, "size");
else res = this.parseStringGroup("size", optional);
if (!res) return null;
if (!optional && res.text.length === 0) {
// Because we've tested for what is !optional, this block won't
// affect \kern, \hspace, etc. It will capture the mandatory arguments
// to \genfrac and \above.
res.text = "0pt"; // Enable \above{}
isBlank = true; // This is here specifically for \genfrac
}
var match = /([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(res.text);
if (!match) throw new ParseError("Invalid size: '" + res.text + "'", res);
var data = {
number: +(match[1] + match[2]),
// sign + magnitude, cast to number
unit: match[3]
};
if (!validUnit(data)) throw new ParseError("Invalid unit: '" + data.unit + "'", res);
return {
type: "size",
mode: this.mode,
value: data,
isBlank
};
}
/**
* Parses an URL, checking escaped letters and allowed protocols,
* and setting the catcode of % as an active character (as in \hyperref).
*/ parseUrlGroup(optional) {
this.gullet.lexer.setCatcode("%", 13); // active character
this.gullet.lexer.setCatcode("~", 12); // other character
var res = this.parseStringGroup("url", optional);
this.gullet.lexer.setCatcode("%", 14); // comment character
this.gullet.lexer.setCatcode("~", 13); // active character
if (res == null) return null;
// hyperref package allows backslashes alone in href, but doesn't
// generate valid links in such cases; we interpret this as
// "undefined" behaviour, and keep them as-is. Some browser will
// replace backslashes with forward slashes.
var url = res.text.replace(/\\([#$%&~_^{}])/g, '$1');
return {
type: "url",
mode: this.mode,
url
};
}
/**
* Parses an argument with the mode specified.
*/ parseArgumentGroup(optional, mode) {
var argToken = this.gullet.scanArgument(optional);
if (argToken == null) return null;
var outerMode = this.mode;
if (mode) // Switch to specified mode
this.switchMode(mode);
this.gullet.beginGroup();
var expression = this.parseExpression(false, "EOF"); // TODO: find an alternative way to denote the end
this.expect("EOF"); // expect the end of the argument
this.gullet.endGroup();
var result = {
type: "ordgroup",
mode: this.mode,
loc: argToken.loc,
body: expression
};
if (mode) // Switch mode back
this.switchMode(outerMode);
return result;
}
/**
* Parses an ordinary group, which is either a single nucleus (like "x")
* or an expression in braces (like "{x+y}") or an implicit group, a group
* that starts at the current position, and ends right before a higher explicit
* group ends, or at EOF.
*/ parseGroup(name, breakOnTokenText) {
var firstToken = this.fetch();
var text = firstToken.text;
var result; // Try to parse an open brace or \begingroup
if (text === "{" || text === "\\begingroup") {
this.consume();
var groupEnd = text === "{" ? "}" : "\\endgroup";
this.gullet.beginGroup(); // If we get a brace, parse an expression
var expression = this.parseExpression(false, groupEnd);
var lastToken = this.fetch();
this.expect(groupEnd); // Check that we got a matching closing brace
this.gullet.endGroup();
result = {
type: "ordgroup",
mode: this.mode,
loc: SourceLocation.range(firstToken, lastToken),
body: expression,
// A group formed by \begingroup...\endgroup is a semi-simple group
// which doesn't affect spacing in math mode, i.e., is transparent.
// https://tex.stackexchange.com/questions/1930/when-should-one-
// use-begingroup-instead-of-bgroup
semisimple: text === "\\begingroup" || undefined
};
} else {
// If there exists a function with this name, parse the function.
// Otherwise, just return a nucleus
result = this.parseFunction(breakOnTokenText, name) || this.parseSymbol();
if (result == null && text[0] === "\\" && !implicitCommands.hasOwnProperty(text)) {
if (this.settings.throwOnError) throw new ParseError("Undefined control sequence: " + text, firstToken);
result = this.formatUnsupportedCmd(text);
this.consume();
}
}
return result;
}
/**
* Form ligature-like combinations of characters for text mode.
* This includes inputs like "--", "---", "``" and "''".
* The result will simply replace multiple textord nodes with a single
* character in each value by a single textord node having multiple
* characters in its value. The representation is still ASCII source.
* The group will be modified in place.
*/ formLigatures(group) {
var n = group.length - 1;
for(var i = 0; i < n; ++i){
var a = group[i]; // $FlowFixMe: Not every node type has a `text` property.
var v = a.text;
if (v === "-" && group[i + 1].text === "-") {
if (i + 1 < n && group[i + 2].text === "-") {
group.splice(i, 3, {
type: "textord",
mode: "text",
loc: SourceLocation.range(a, group[i + 2]),
text: "---"
});
n -= 2;
} else {
group.splice(i, 2, {
type: "textord",
mode: "text",
loc: SourceLocation.range(a, group[i + 1]),
text: "--"
});
n -= 1;
}
}
if ((v === "'" || v === "`") && group[i + 1].text === v) {
group.splice(i, 2, {
type: "textord",
mode: "text",
loc: SourceLocation.range(a, group[i + 1]),
text: v + v
});
n -= 1;
}
}
}
/**
* Parse a single symbol out of the string. Here, we handle single character
* symbols and special functions like \verb.
*/ parseSymbol() {
var nucleus = this.fetch();
var text = nucleus.text;
if (/^\\verb[^a-zA-Z]/.test(text)) {
this.consume();
var arg = text.slice(5);
var star = arg.charAt(0) === "*";
if (star) arg = arg.slice(1);
// Lexer's tokenRegex is constructed to always have matching
// first/last characters.
if (arg.length < 2 || arg.charAt(0) !== arg.slice(-1)) throw new ParseError("\\verb assertion failed --\n please report what input caused this bug");
arg = arg.slice(1, -1); // remove first and last char
return {
type: "verb",
mode: "text",
body: arg,
star
};
} // At this point, we should have a symbol, possibly with accents.
// First expand any accented base symbol according to unicodeSymbols.
if (unicodeSymbols.hasOwnProperty(text[0]) && !symbols[this.mode][text[0]]) {
// This behavior is not strict (XeTeX-compatible) in math mode.
if (this.settings.strict && this.mode === "math") this.settings.reportNonstrict("unicodeTextInMathMode", "Accented Unicode text character \"" + text[0] + "\" used in " + "math mode", nucleus);
text = unicodeSymbols[text[0]] + text.slice(1);
} // Strip off any combining characters
var match = combiningDiacriticalMarksEndRegex.exec(text);
if (match) {
text = text.substring(0, match.index);
if (text === 'i') text = '\u0131'; // dotless i, in math and text mode
else if (text === 'j') text = '\u0237'; // dotless j, in math and text mode
} // Recognize base symbol
var symbol;
if (symbols[this.mode][text]) {
if (this.settings.strict && this.mode === 'math' && extraLatin.indexOf(text) >= 0) this.settings.reportNonstrict("unicodeTextInMathMode", "Latin-1/Unicode text character \"" + text[0] + "\" used in " + "math mode", nucleus);
var group = symbols[this.mode][text].group;
var loc = SourceLocation.range(nucleus);
var s;
if (ATOMS.hasOwnProperty(group)) {
// $FlowFixMe
var family = group;
s = {
type: "atom",
mode: this.mode,
family,
loc,
text
};
} else // $FlowFixMe
s = {
type: group,
mode: this.mode,
loc,
text
};
// $FlowFixMe
symbol = s;
} else if (text.charCodeAt(0) >= 0x80) {
// no symbol for e.g. ^
if (this.settings.strict) {
if (!supportedCodepoint(text.charCodeAt(0))) this.settings.reportNonstrict("unknownSymbol", "Unrecognized Unicode character \"" + text[0] + "\"" + (" (" + text.charCodeAt(0) + ")"), nucleus);
else if (this.mode === "math") this.settings.reportNonstrict("unicodeTextInMathMode", "Unicode text character \"" + text[0] + "\" used in math mode", nucleus);
} // All nonmathematical Unicode characters are rendered as if they
// are in text mode (wrapped in \text) because that's what it
// takes to render them in LaTeX. Setting `mode: this.mode` is
// another natural choice (the user requested math mode), but
// this makes it more difficult for getCharacterMetrics() to
// distinguish Unicode characters without metrics and those for
// which we want to simulate the letter M.
symbol = {
type: "textord",
mode: "text",
loc: SourceLocation.range(nucleus),
text
};
} else return null; // EOF, ^, _, {, }, etc.
this.consume(); // Transform combining characters into accents
if (match) for(var i = 0; i < match[0].length; i++){
var accent = match[0][i];
if (!unicodeAccents[accent]) throw new ParseError("Unknown accent ' " + accent + "'", nucleus);
var command = unicodeAccents[accent][this.mode] || unicodeAccents[accent].text;
if (!command) throw new ParseError("Accent " + accent + " unsupported in " + this.mode + " mode", nucleus);
symbol = {
type: "accent",
mode: this.mode,
loc: SourceLocation.range(nucleus),
label: command,
isStretchy: false,
isShifty: true,
// $FlowFixMe
base: symbol
};
}
// $FlowFixMe
return symbol;
}
}
Parser.endOfExpression = [
"}",
"\\endgroup",
"\\end",
"\\right",
"&"
];
/**
* Provides a single function for parsing an expression using a Parser
* TODO(emily): Remove this
*/ /**
* Parses an expression using a Parser, then returns the parsed result.
*/ var parseTree = function parseTree(toParse, settings) {
if (!(typeof toParse === 'string' || toParse instanceof String)) throw new TypeError('KaTeX can only parse string typed expression');
var parser = new Parser(toParse, settings); // Blank out any \df@tag to avoid spurious "Duplicate \tag" errors
delete parser.gullet.macros.current["\\df@tag"];
var 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;
};
/* eslint no-console:0 */ /**
* Parse and build an expression, and place that expression in the DOM node
* given.
*/ var render = function render(expression, baseNode, options) {
baseNode.textContent = "";
var node = renderToDomTree(expression, options).toNode();
baseNode.appendChild(node);
}; // KaTeX's styles don't work properly in quirks mode. Print out an error, and
// disable rendering.
if (typeof document !== "undefined") {
if (document.compatMode !== "CSS1Compat") {
typeof console !== "undefined" && console.warn("Warning: KaTeX doesn't work in quirks mode. Make sure your website has a suitable doctype.");
render = function render() {
throw new ParseError("KaTeX doesn't work in quirks mode.");
};
}
}
/**
* Parse and build an expression, and return the markup for that.
*/ var renderToString = function renderToString(expression, options) {
var markup = renderToDomTree(expression, options).toMarkup();
return markup;
};
/**
* Parse an expression and return the parse tree.
*/ var generateParseTree = function generateParseTree(expression, options) {
var settings = new Settings(options);
return parseTree(expression, settings);
};
/**
* If the given error is a KaTeX ParseError and options.throwOnError is false,
* renders the invalid LaTeX as a span with hover title giving the KaTeX
* error message. Otherwise, simply throws the error.
*/ var renderError = function renderError(error, expression, options) {
if (options.throwOnError || !(error instanceof ParseError)) throw error;
var node = buildCommon.makeSpan([
"katex-error"
], [
new SymbolNode(expression)
]);
node.setAttribute("title", error.toString());
node.setAttribute("style", "color:" + options.errorColor);
return node;
};
/**
* Generates and returns the katex build tree. This is used for advanced
* use cases (like rendering to custom output).
*/ var renderToDomTree = function renderToDomTree(expression, options) {
var settings = new Settings(options);
try {
var tree = parseTree(expression, settings);
return buildTree(tree, expression, settings);
} catch (error) {
return renderError(error, expression, settings);
}
};
/**
* Generates and returns the katex build tree, with just HTML (no MathML).
* This is used for advanced use cases (like rendering to custom output).
*/ var renderToHTMLTree = function renderToHTMLTree(expression, options) {
var settings = new Settings(options);
try {
var tree = parseTree(expression, settings);
return buildHTMLTree(tree, expression, settings);
} catch (error) {
return renderError(error, expression, settings);
}
};
var katex = {
/**
* Current KaTeX version
*/ version: "0.16.9",
/**
* Renders the given LaTeX into an HTML+MathML combination, and adds
* it as a child to the specified DOM node.
*/ render,
/**
* Renders the given LaTeX into an HTML+MathML combination string,
* for sending to the client.
*/ renderToString,
/**
* KaTeX error, usually during parsing.
*/ ParseError,
/**
* The shema of Settings
*/ SETTINGS_SCHEMA,
/**
* Parses the given LaTeX into KaTeX's internal parse tree structure,
* without rendering to HTML or MathML.
*
* NOTE: This method is not currently recommended for public use.
* The internal tree representation is unstable and is very likely
* to change. Use at your own risk.
*/ __parse: generateParseTree,
/**
* Renders the given LaTeX into an HTML+MathML internal DOM tree
* representation, without flattening that representation to a string.
*
* NOTE: This method is not currently recommended for public use.
* The internal tree representation is unstable and is very likely
* to change. Use at your own risk.
*/ __renderToDomTree: renderToDomTree,
/**
* Renders the given LaTeX into an HTML internal DOM tree representation,
* without MathML and without flattening that representation to a string.
*
* NOTE: This method is not currently recommended for public use.
* The internal tree representation is unstable and is very likely
* to change. Use at your own risk.
*/ __renderToHTMLTree: renderToHTMLTree,
/**
* extends internal font metrics object with a new object
* each key in the new object represents a font name
*/ __setFontMetrics: setFontMetrics,
/**
* adds a new symbol to builtin symbols table
*/ __defineSymbol: defineSymbol,
/**
* adds a new function to builtin function list,
* which directly produce parse tree elements
* and have their own html/mathml builders
*/ __defineFunction: defineFunction,
/**
* adds a new macro to builtin macro list
*/ __defineMacro: defineMacro,
/**
* Expose the dom tree node types, which can be useful for type checking nodes.
*
* NOTE: This method is not currently recommended for public use.
* The internal tree representation is unstable and is very likely
* to change. Use at your own risk.
*/ __domTree: {
Span,
Anchor,
SymbolNode,
SvgNode,
PathNode,
LineNode
}
};
}),
"./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/index.js": (function (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
math: function() { return _lib_syntax_js__WEBPACK_IMPORTED_MODULE_0__.math; },
mathHtml: function() { return _lib_html_js__WEBPACK_IMPORTED_MODULE_1__.mathHtml; }
});
/* harmony import */var _lib_syntax_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./lib/syntax.js */"./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/syntax.js");
/* harmony import */var _lib_html_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./lib/html.js */"./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/html.js");
// Note: types exported from `index.d.ts`.
}),
"./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/html.js": (function (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
mathHtml: function() { return mathHtml; }
});
/* harmony import */var katex__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! katex */"./node_modules/.pnpm/katex@0.16.9/node_modules/katex/dist/katex.mjs");
/**
* @typedef {import('katex').KatexOptions} KatexOptions
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension
*/ /**
* @typedef {Omit<KatexOptions, 'displayMode'>} Options
* Configuration for HTML output.
*
* > 👉 **Note**: passed to `katex.renderToString`.
* > `displayMode` is overwritten by this plugin, to `false` for math in
* > text (inline), and `true` for math in flow (block).
*/
/** @type {import('katex')['default']['renderToString']} */ // @ts-expect-error: types are incorrect.
const renderToString = katex__WEBPACK_IMPORTED_MODULE_0__["default"].renderToString;
/**
* Create an extension for `micromark` to support math when serializing to
* HTML.
*
* > 👉 **Note**: this uses KaTeX to render math.
*
* @param {Options | null | undefined} [options={}]
* Configuration (default: `{}`).
* @returns {HtmlExtension}
* Extension for `micromark` that can be passed in `htmlExtensions`, to
* support math when serializing to HTML.
*/ function mathHtml(options) {
return {
enter: {
mathFlow () {
this.lineEndingIfNeeded();
this.tag('<div class="math math-display">');
},
mathFlowFenceMeta () {
this.buffer();
},
mathText () {
// Double?
this.tag('<span class="math math-inline">');
this.buffer();
}
},
exit: {
mathFlow () {
const value = this.resume();
this.tag(math(value.replace(/(?:\r?\n|\r)$/, ''), true));
this.tag('</div>');
this.setData('mathFlowOpen');
this.setData('slurpOneLineEnding');
},
mathFlowFence () {
// After the first fence.
if (!this.getData('mathFlowOpen')) {
this.setData('mathFlowOpen', true);
this.setData('slurpOneLineEnding', true);
this.buffer();
}
},
mathFlowFenceMeta () {
this.resume();
},
mathFlowValue (token) {
this.raw(this.sliceSerialize(token));
},
mathText () {
const value = this.resume();
this.tag(math(value, false));
this.tag('</span>');
},
mathTextData (token) {
this.raw(this.sliceSerialize(token));
}
}
};
/**
* @param {string} value
* Math text.
* @param {boolean} displayMode
* Whether the math is in display mode.
* @returns {string}
* HTML.
*/ function math(value, displayMode) {
return renderToString(value, {
...options,
displayMode
});
}
}
}),
"./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/math-flow.js": (function (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
mathFlow: function() { return mathFlow; }
});
/* harmony import */var devlop__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! devlop */"./node_modules/.pnpm/devlop@1.1.0/node_modules/devlop/lib/development.js");
/* harmony import */var micromark_factory_space__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! micromark-factory-space */"./node_modules/.pnpm/micromark-factory-space@2.0.0/node_modules/micromark-factory-space/dev/index.js");
/* harmony import */var micromark_util_character__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! micromark-util-character */"./node_modules/.pnpm/micromark-util-character@2.0.1/node_modules/micromark-util-character/dev/index.js");
/* harmony import */var micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! micromark-util-symbol */"./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/default.js");
/**
* @typedef {import('micromark-util-types').Construct} Construct
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
*/
/** @type {Construct} */ const mathFlow = {
tokenize: tokenizeMathFenced,
concrete: true
};
/** @type {Construct} */ const nonLazyContinuation = {
tokenize: tokenizeNonLazyContinuation,
partial: true
};
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/ function tokenizeMathFenced(effects, ok, nok) {
const self = this;
const tail = self.events[self.events.length - 1];
const initialSize = tail && tail[1].type === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.linePrefix ? tail[2].sliceSerialize(tail[1], true).length : 0;
let sizeOpen = 0;
return start;
/**
* Start of math.
*
* ```markdown
* > | $$
* ^
* | \frac{1}{2}
* | $$
* ```
*
* @type {State}
*/ function start(code) {
(0, devlop__WEBPACK_IMPORTED_MODULE_0__.ok)(code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.codes.dollarSign, 'expected `$`');
effects.enter('mathFlow');
effects.enter('mathFlowFence');
effects.enter('mathFlowFenceSequence');
return sequenceOpen(code);
}
/**
* In opening fence sequence.
*
* ```markdown
* > | $$
* ^
* | \frac{1}{2}
* | $$
* ```
*
* @type {State}
*/ function sequenceOpen(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.codes.dollarSign) {
effects.consume(code);
sizeOpen++;
return sequenceOpen;
}
if (sizeOpen < 2) return nok(code);
effects.exit('mathFlowFenceSequence');
return (0, micromark_factory_space__WEBPACK_IMPORTED_MODULE_1__.factorySpace)(effects, metaBefore, micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.whitespace)(code);
}
/**
* In opening fence, before meta.
*
* ```markdown
* > | $$asciimath
* ^
* | x < y
* | $$
* ```
*
* @type {State}
*/ function metaBefore(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.codes.eof || (0, micromark_util_character__WEBPACK_IMPORTED_MODULE_2__.markdownLineEnding)(code)) return metaAfter(code);
effects.enter('mathFlowFenceMeta');
effects.enter(micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.chunkString, {
contentType: micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.constants.contentTypeString
});
return meta(code);
}
/**
* In meta.
*
* ```markdown
* > | $$asciimath
* ^
* | x < y
* | $$
* ```
*
* @type {State}
*/ function meta(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.codes.eof || (0, micromark_util_character__WEBPACK_IMPORTED_MODULE_2__.markdownLineEnding)(code)) {
effects.exit(micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.chunkString);
effects.exit('mathFlowFenceMeta');
return metaAfter(code);
}
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.codes.dollarSign) return nok(code);
effects.consume(code);
return meta;
}
/**
* After meta.
*
* ```markdown
* > | $$
* ^
* | \frac{1}{2}
* | $$
* ```
*
* @type {State}
*/ function metaAfter(code) {
// Guaranteed to be eol/eof.
effects.exit('mathFlowFence');
if (self.interrupt) return ok(code);
return effects.attempt(nonLazyContinuation, beforeNonLazyContinuation, after)(code);
}
/**
* After eol/eof in math, at a non-lazy closing fence or content.
*
* ```markdown
* | $$
* > | \frac{1}{2}
* ^
* > | $$
* ^
* ```
*
* @type {State}
*/ function beforeNonLazyContinuation(code) {
return effects.attempt({
tokenize: tokenizeClosingFence,
partial: true
}, after, contentStart)(code);
}
/**
* Before math content, definitely not before a closing fence.
*
* ```markdown
* | $$
* > | \frac{1}{2}
* ^
* | $$
* ```
*
* @type {State}
*/ function contentStart(code) {
return (initialSize ? (0, micromark_factory_space__WEBPACK_IMPORTED_MODULE_1__.factorySpace)(effects, beforeContentChunk, micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.linePrefix, initialSize + 1) : beforeContentChunk)(code);
}
/**
* Before math content, after optional prefix.
*
* ```markdown
* | $$
* > | \frac{1}{2}
* ^
* | $$
* ```
*
* @type {State}
*/ function beforeContentChunk(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.codes.eof) return after(code);
if ((0, micromark_util_character__WEBPACK_IMPORTED_MODULE_2__.markdownLineEnding)(code)) return effects.attempt(nonLazyContinuation, beforeNonLazyContinuation, after)(code);
effects.enter('mathFlowValue');
return contentChunk(code);
}
/**
* In math content.
*
* ```markdown
* | $$
* > | \frac{1}{2}
* ^
* | $$
* ```
*
* @type {State}
*/ function contentChunk(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.codes.eof || (0, micromark_util_character__WEBPACK_IMPORTED_MODULE_2__.markdownLineEnding)(code)) {
effects.exit('mathFlowValue');
return beforeContentChunk(code);
}
effects.consume(code);
return contentChunk;
}
/**
* After math (ha!).
*
* ```markdown
* | $$
* | \frac{1}{2}
* > | $$
* ^
* ```
*
* @type {State}
*/ function after(code) {
effects.exit('mathFlow');
return ok(code);
}
/** @type {Tokenizer} */ function tokenizeClosingFence(effects, ok, nok) {
let size = 0;
(0, devlop__WEBPACK_IMPORTED_MODULE_0__.ok)(self.parser.constructs.disable.null, 'expected `disable.null`');
/**
* Before closing fence, at optional whitespace.
*
* ```markdown
* | $$
* | \frac{1}{2}
* > | $$
* ^
* ```
*/ return (0, micromark_factory_space__WEBPACK_IMPORTED_MODULE_1__.factorySpace)(effects, beforeSequenceClose, micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.linePrefix, self.parser.constructs.disable.null.includes('codeIndented') ? undefined : micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.constants.tabSize);
/**
* In closing fence, after optional whitespace, at sequence.
*
* ```markdown
* | $$
* | \frac{1}{2}
* > | $$
* ^
* ```
*
* @type {State}
*/ function beforeSequenceClose(code) {
effects.enter('mathFlowFence');
effects.enter('mathFlowFenceSequence');
return sequenceClose(code);
}
/**
* In closing fence sequence.
*
* ```markdown
* | $$
* | \frac{1}{2}
* > | $$
* ^
* ```
*
* @type {State}
*/ function sequenceClose(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.codes.dollarSign) {
size++;
effects.consume(code);
return sequenceClose;
}
if (size < sizeOpen) return nok(code);
effects.exit('mathFlowFenceSequence');
return (0, micromark_factory_space__WEBPACK_IMPORTED_MODULE_1__.factorySpace)(effects, afterSequenceClose, micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.whitespace)(code);
}
/**
* After closing fence sequence, after optional whitespace.
*
* ```markdown
* | $$
* | \frac{1}{2}
* > | $$
* ^
* ```
*
* @type {State}
*/ function afterSequenceClose(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.codes.eof || (0, micromark_util_character__WEBPACK_IMPORTED_MODULE_2__.markdownLineEnding)(code)) {
effects.exit('mathFlowFence');
return ok(code);
}
return nok(code);
}
}
}
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/ function tokenizeNonLazyContinuation(effects, ok, nok) {
const self = this;
return start;
/** @type {State} */ function start(code) {
if (code === null) return ok(code);
(0, devlop__WEBPACK_IMPORTED_MODULE_0__.ok)((0, micromark_util_character__WEBPACK_IMPORTED_MODULE_2__.markdownLineEnding)(code), 'expected eol');
effects.enter(micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.lineEnding);
effects.consume(code);
effects.exit(micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.lineEnding);
return lineStart;
}
/** @type {State} */ function lineStart(code) {
return self.parser.lazy[self.now().line] ? nok(code) : ok(code);
}
}
}),
"./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/math-text.js": (function (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
mathText: function() { return mathText; }
});
/* harmony import */var devlop__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! devlop */"./node_modules/.pnpm/devlop@1.1.0/node_modules/devlop/lib/development.js");
/* harmony import */var micromark_util_character__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! micromark-util-character */"./node_modules/.pnpm/micromark-util-character@2.0.1/node_modules/micromark-util-character/dev/index.js");
/* harmony import */var micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! micromark-util-symbol */"./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/default.js");
/**
* @typedef {import('micromark-util-types').Construct} Construct
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
* @typedef {import('micromark-util-types').Previous} Previous
* @typedef {import('micromark-util-types').Resolver} Resolver
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').Token} Token
*
* @typedef Options
* Configuration.
* @property {boolean | null | undefined} [singleDollarTextMath=true]
* Whether to support math (text) with a single dollar (default: `true`).
*
* Single dollars work in Pandoc and many other places, but often interfere
* with “normal” dollars in text.
* If you turn this off, you can use two or more dollars for text math.
*/ // To do: next major: clean spaces in HTML compiler.
// This has to be coordinated together with `mdast-util-math`.
/**
* @param {Options | null | undefined} [options={}]
* Configuration (default: `{}`).
* @returns {Construct}
* Construct.
*/ function mathText(options) {
const options_ = options || {};
let single = options_.singleDollarTextMath;
if (single === null || single === undefined) single = true;
return {
tokenize: tokenizeMathText,
resolve: resolveMathText,
previous
};
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/ function tokenizeMathText(effects, ok, nok) {
const self = this;
let sizeOpen = 0;
/** @type {number} */ let size;
/** @type {Token} */ let token;
return start;
/**
* Start of math (text).
*
* ```markdown
* > | $a$
* ^
* > | \$a$
* ^
* ```
*
* @type {State}
*/ function start(code) {
(0, devlop__WEBPACK_IMPORTED_MODULE_0__.ok)(code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.dollarSign, 'expected `$`');
(0, devlop__WEBPACK_IMPORTED_MODULE_0__.ok)(previous.call(self, self.previous), 'expected correct previous');
effects.enter('mathText');
effects.enter('mathTextSequence');
return sequenceOpen(code);
}
/**
* In opening sequence.
*
* ```markdown
* > | $a$
* ^
* ```
*
* @type {State}
*/ function sequenceOpen(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.dollarSign) {
effects.consume(code);
sizeOpen++;
return sequenceOpen;
}
// Not enough markers in the sequence.
if (sizeOpen < 2 && !single) return nok(code);
effects.exit('mathTextSequence');
return between(code);
}
/**
* Between something and something else.
*
* ```markdown
* > | $a$
* ^^
* ```
*
* @type {State}
*/ function between(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.eof) return nok(code);
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.dollarSign) {
token = effects.enter('mathTextSequence');
size = 0;
return sequenceClose(code);
}
// Tabs don’t work, and virtual spaces don’t make sense.
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.space) {
effects.enter('space');
effects.consume(code);
effects.exit('space');
return between;
}
if ((0, micromark_util_character__WEBPACK_IMPORTED_MODULE_1__.markdownLineEnding)(code)) {
effects.enter(micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.types.lineEnding);
effects.consume(code);
effects.exit(micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.types.lineEnding);
return between;
}
// Data.
effects.enter('mathTextData');
return data(code);
}
/**
* In data.
*
* ```markdown
* > | $a$
* ^
* ```
*
* @type {State}
*/ function data(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.eof || code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.space || code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.dollarSign || (0, micromark_util_character__WEBPACK_IMPORTED_MODULE_1__.markdownLineEnding)(code)) {
effects.exit('mathTextData');
return between(code);
}
effects.consume(code);
return data;
}
/**
* In closing sequence.
*
* ```markdown
* > | `a`
* ^
* ```
*
* @type {State}
*/ function sequenceClose(code) {
// More.
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.dollarSign) {
effects.consume(code);
size++;
return sequenceClose;
}
// Done!
if (size === sizeOpen) {
effects.exit('mathTextSequence');
effects.exit('mathText');
return ok(code);
}
// More or less accents: mark as data.
token.type = 'mathTextData';
return data(code);
}
}
}
/** @type {Resolver} */ function resolveMathText(events) {
let tailExitIndex = events.length - 4;
let headEnterIndex = 3;
/** @type {number} */ let index;
/** @type {number | undefined} */ let enter;
// If we start and end with an EOL or a space.
if ((events[headEnterIndex][1].type === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.types.lineEnding || events[headEnterIndex][1].type === 'space') && (events[tailExitIndex][1].type === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.types.lineEnding || events[tailExitIndex][1].type === 'space')) {
index = headEnterIndex;
// And we have data.
while(++index < tailExitIndex)if (events[index][1].type === 'mathTextData') {
// Then we have padding.
events[tailExitIndex][1].type = 'mathTextPadding';
events[headEnterIndex][1].type = 'mathTextPadding';
headEnterIndex += 2;
tailExitIndex -= 2;
break;
}
}
// Merge adjacent spaces and data.
index = headEnterIndex - 1;
tailExitIndex++;
while(++index <= tailExitIndex){
if (enter === undefined) {
if (index !== tailExitIndex && events[index][1].type !== micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.types.lineEnding) enter = index;
} else if (index === tailExitIndex || events[index][1].type === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.types.lineEnding) {
events[enter][1].type = 'mathTextData';
if (index !== enter + 2) {
events[enter][1].end = events[index - 1][1].end;
events.splice(enter + 2, index - enter - 2);
tailExitIndex -= index - enter - 2;
index = enter + 2;
}
enter = undefined;
}
}
return events;
}
/**
* @this {TokenizeContext}
* @type {Previous}
*/ function previous(code) {
// If there is a previous code, there will always be a tail.
return code !== micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.dollarSign || this.events[this.events.length - 1][1].type === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.types.characterEscape;
}
}),
"./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/syntax.js": (function (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
math: function() { return math; }
});
/* harmony import */var micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! micromark-util-symbol */"./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/default.js");
/* harmony import */var _math_flow_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./math-flow.js */"./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/math-flow.js");
/* harmony import */var _math_text_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./math-text.js */"./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/math-text.js");
/**
* @typedef {import('micromark-util-types').Extension} Extension
* @typedef {import('./math-text.js').Options} Options
*/
/**
* Create an extension for `micromark` to enable math syntax.
*
* @param {Options | null | undefined} [options={}]
* Configuration (default: `{}`).
* @returns {Extension}
* Extension for `micromark` that can be passed in `extensions`, to
* enable math syntax.
*/ function math(options) {
return {
flow: {
[micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.dollarSign]: _math_flow_js__WEBPACK_IMPORTED_MODULE_1__.mathFlow
},
text: {
[micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.dollarSign]: (0, _math_text_js__WEBPACK_IMPORTED_MODULE_2__.mathText)(options)
}
};
}
}),
"./node_modules/.pnpm/micromark-factory-space@2.0.0/node_modules/micromark-factory-space/dev/index.js": (function (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
factorySpace: function() { return factorySpace; }
});
/* harmony import */var micromark_util_character__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! micromark-util-character */"./node_modules/.pnpm/micromark-util-character@2.0.1/node_modules/micromark-util-character/dev/index.js");
/**
* @typedef {import('micromark-util-types').Effects} Effects
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenType} TokenType
*/
// To do: implement `spaceOrTab`, `spaceOrTabMinMax`, `spaceOrTabWithOptions`.
/**
* Parse spaces and tabs.
*
* There is no `nok` parameter:
*
* * spaces in markdown are often optional, in which case this factory can be
* used and `ok` will be switched to whether spaces were found or not
* * one line ending or space can be detected with `markdownSpace(code)` right
* before using `factorySpace`
*
* ###### Examples
*
* Where `␉` represents a tab (plus how much it expands) and `␠` represents a
* single space.
*
* ```markdown
* ␉
* ␠␠␠␠
* ␉␠
* ```
*
* @param {Effects} effects
* Context.
* @param {State} ok
* State switched to when successful.
* @param {TokenType} type
* Type (`' \t'`).
* @param {number | undefined} [max=Infinity]
* Max (exclusive).
* @returns {State}
* Start state.
*/ function factorySpace(effects, ok, type, max) {
const limit = max ? max - 1 : Number.POSITIVE_INFINITY;
let size = 0;
return start;
/** @type {State} */ function start(code) {
if ((0, micromark_util_character__WEBPACK_IMPORTED_MODULE_0__.markdownSpace)(code)) {
effects.enter(type);
return prefix(code);
}
return ok(code);
}
/** @type {State} */ function prefix(code) {
if ((0, micromark_util_character__WEBPACK_IMPORTED_MODULE_0__.markdownSpace)(code) && size++ < limit) {
effects.consume(code);
return prefix;
}
effects.exit(type);
return ok(code);
}
}
}),
"./node_modules/.pnpm/micromark-util-character@2.0.1/node_modules/micromark-util-character/dev/index.js": (function (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
asciiAlpha: function() { return asciiAlpha; },
asciiAlphanumeric: function() { return asciiAlphanumeric; },
asciiAtext: function() { return asciiAtext; },
asciiControl: function() { return asciiControl; },
asciiDigit: function() { return asciiDigit; },
asciiHexDigit: function() { return asciiHexDigit; },
asciiPunctuation: function() { return asciiPunctuation; },
markdownLineEnding: function() { return markdownLineEnding; },
markdownLineEndingOrSpace: function() { return markdownLineEndingOrSpace; },
markdownSpace: function() { return markdownSpace; },
unicodePunctuation: function() { return unicodePunctuation; },
unicodeWhitespace: function() { return unicodeWhitespace; }
});
/* harmony import */var micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! micromark-util-symbol */"./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/default.js");
/**
* @typedef {import('micromark-util-types').Code} Code
*/
const unicodePunctuationInternal = regexCheck(/\p{P}/u);
/**
* Check whether the character code represents an ASCII alpha (`a` through `z`,
* case insensitive).
*
* An **ASCII alpha** is an ASCII upper alpha or ASCII lower alpha.
*
* An **ASCII upper alpha** is a character in the inclusive range U+0041 (`A`)
* to U+005A (`Z`).
*
* An **ASCII lower alpha** is a character in the inclusive range U+0061 (`a`)
* to U+007A (`z`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/ const asciiAlpha = regexCheck(/[A-Za-z]/);
/**
* Check whether the character code represents an ASCII alphanumeric (`a`
* through `z`, case insensitive, or `0` through `9`).
*
* An **ASCII alphanumeric** is an ASCII digit (see `asciiDigit`) or ASCII alpha
* (see `asciiAlpha`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/ const asciiAlphanumeric = regexCheck(/[\dA-Za-z]/);
/**
* Check whether the character code represents an ASCII atext.
*
* atext is an ASCII alphanumeric (see `asciiAlphanumeric`), or a character in
* the inclusive ranges U+0023 NUMBER SIGN (`#`) to U+0027 APOSTROPHE (`'`),
* U+002A ASTERISK (`*`), U+002B PLUS SIGN (`+`), U+002D DASH (`-`), U+002F
* SLASH (`/`), U+003D EQUALS TO (`=`), U+003F QUESTION MARK (`?`), U+005E
* CARET (`^`) to U+0060 GRAVE ACCENT (`` ` ``), or U+007B LEFT CURLY BRACE
* (`{`) to U+007E TILDE (`~`).
*
* See:
* **\[RFC5322]**:
* [Internet Message Format](https://tools.ietf.org/html/rfc5322).
* P. Resnick.
* IETF.
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/ const asciiAtext = regexCheck(/[#-'*+\--9=?A-Z^-~]/);
/**
* Check whether a character code is an ASCII control character.
*
* An **ASCII control** is a character in the inclusive range U+0000 NULL (NUL)
* to U+001F (US), or U+007F (DEL).
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/ function asciiControl(code) {
return(// Special whitespace codes (which have negative values), C0 and Control
// character DEL
code !== null && (code < micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.space || code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.del));
}
/**
* Check whether the character code represents an ASCII digit (`0` through `9`).
*
* An **ASCII digit** is a character in the inclusive range U+0030 (`0`) to
* U+0039 (`9`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/ const asciiDigit = regexCheck(/\d/);
/**
* Check whether the character code represents an ASCII hex digit (`a` through
* `f`, case insensitive, or `0` through `9`).
*
* An **ASCII hex digit** is an ASCII digit (see `asciiDigit`), ASCII upper hex
* digit, or an ASCII lower hex digit.
*
* An **ASCII upper hex digit** is a character in the inclusive range U+0041
* (`A`) to U+0046 (`F`).
*
* An **ASCII lower hex digit** is a character in the inclusive range U+0061
* (`a`) to U+0066 (`f`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/ const asciiHexDigit = regexCheck(/[\dA-Fa-f]/);
/**
* Check whether the character code represents ASCII punctuation.
*
* An **ASCII punctuation** is a character in the inclusive ranges U+0021
* EXCLAMATION MARK (`!`) to U+002F SLASH (`/`), U+003A COLON (`:`) to U+0040 AT
* SIGN (`@`), U+005B LEFT SQUARE BRACKET (`[`) to U+0060 GRAVE ACCENT
* (`` ` ``), or U+007B LEFT CURLY BRACE (`{`) to U+007E TILDE (`~`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/ const asciiPunctuation = regexCheck(/[!-/:-@[-`{-~]/);
/**
* Check whether a character code is a markdown line ending.
*
* A **markdown line ending** is the virtual characters M-0003 CARRIAGE RETURN
* LINE FEED (CRLF), M-0004 LINE FEED (LF) and M-0005 CARRIAGE RETURN (CR).
*
* In micromark, the actual character U+000A LINE FEED (LF) and U+000D CARRIAGE
* RETURN (CR) are replaced by these virtual characters depending on whether
* they occurred together.
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/ function markdownLineEnding(code) {
return code !== null && code < micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.horizontalTab;
}
/**
* Check whether a character code is a markdown line ending (see
* `markdownLineEnding`) or markdown space (see `markdownSpace`).
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/ function markdownLineEndingOrSpace(code) {
return code !== null && (code < micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.nul || code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.space);
}
/**
* Check whether a character code is a markdown space.
*
* A **markdown space** is the concrete character U+0020 SPACE (SP) and the
* virtual characters M-0001 VIRTUAL SPACE (VS) and M-0002 HORIZONTAL TAB (HT).
*
* In micromark, the actual character U+0009 CHARACTER TABULATION (HT) is
* replaced by one M-0002 HORIZONTAL TAB (HT) and between 0 and 3 M-0001 VIRTUAL
* SPACE (VS) characters, depending on the column at which the tab occurred.
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/ function markdownSpace(code) {
return code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.horizontalTab || code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.virtualSpace || code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.space;
}
// Size note: removing ASCII from the regex and using `asciiPunctuation` here
// In fact adds to the bundle size.
/**
* Check whether the character code represents Unicode punctuation.
*
* A **Unicode punctuation** is a character in the Unicode `Pc` (Punctuation,
* Connector), `Pd` (Punctuation, Dash), `Pe` (Punctuation, Close), `Pf`
* (Punctuation, Final quote), `Pi` (Punctuation, Initial quote), `Po`
* (Punctuation, Other), or `Ps` (Punctuation, Open) categories, or an ASCII
* punctuation (see `asciiPunctuation`).
*
* See:
* **\[UNICODE]**:
* [The Unicode Standard](https://www.unicode.org/versions/).
* Unicode Consortium.
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/ function unicodePunctuation(code) {
return asciiPunctuation(code) || unicodePunctuationInternal(code);
}
/**
* Check whether the character code represents Unicode whitespace.
*
* Note that this does handle micromark specific markdown whitespace characters.
* See `markdownLineEndingOrSpace` to check that.
*
* A **Unicode whitespace** is a character in the Unicode `Zs` (Separator,
* Space) category, or U+0009 CHARACTER TABULATION (HT), U+000A LINE FEED (LF),
* U+000C (FF), or U+000D CARRIAGE RETURN (CR) (**\[UNICODE]**).
*
* See:
* **\[UNICODE]**:
* [The Unicode Standard](https://www.unicode.org/versions/).
* Unicode Consortium.
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/ const unicodeWhitespace = regexCheck(/\s/);
/**
* Create a code check from a regex.
*
* @param {RegExp} regex
* @returns {(code: Code) => boolean}
*/ function regexCheck(regex) {
return check;
/**
* Check whether a code matches the bound regex.
*
* @param {Code} code
* Character code.
* @returns {boolean}
* Whether the character code matches the bound regex.
*/ function check(code) {
return code !== null && code > -1 && regex.test(String.fromCharCode(code));
}
}
}),
"./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/codes.js": (function (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
codes: function() { return codes; }
});
/**
* Character codes.
*
* This module is compiled away!
*
* micromark works based on character codes.
* This module contains constants for the ASCII block and the replacement
* character.
* A couple of them are handled in a special way, such as the line endings
* (CR, LF, and CR+LF, commonly known as end-of-line: EOLs), the tab (horizontal
* tab) and its expansion based on what column it’s at (virtual space),
* and the end-of-file (eof) character.
* As values are preprocessed before handling them, the actual characters LF,
* CR, HT, and NUL (which is present as the replacement character), are
* guaranteed to not exist.
*
* Unicode basic latin block.
*/ const codes = {
carriageReturn: -5,
lineFeed: -4,
carriageReturnLineFeed: -3,
horizontalTab: -2,
virtualSpace: -1,
eof: null,
nul: 0,
soh: 1,
stx: 2,
etx: 3,
eot: 4,
enq: 5,
ack: 6,
bel: 7,
bs: 8,
ht: 9,
lf: 10,
vt: 11,
ff: 12,
cr: 13,
so: 14,
si: 15,
dle: 16,
dc1: 17,
dc2: 18,
dc3: 19,
dc4: 20,
nak: 21,
syn: 22,
etb: 23,
can: 24,
em: 25,
sub: 26,
esc: 27,
fs: 28,
gs: 29,
rs: 30,
us: 31,
space: 32,
exclamationMark: 33,
quotationMark: 34,
numberSign: 35,
dollarSign: 36,
percentSign: 37,
ampersand: 38,
apostrophe: 39,
leftParenthesis: 40,
rightParenthesis: 41,
asterisk: 42,
plusSign: 43,
comma: 44,
dash: 45,
dot: 46,
slash: 47,
digit0: 48,
digit1: 49,
digit2: 50,
digit3: 51,
digit4: 52,
digit5: 53,
digit6: 54,
digit7: 55,
digit8: 56,
digit9: 57,
colon: 58,
semicolon: 59,
lessThan: 60,
equalsTo: 61,
greaterThan: 62,
questionMark: 63,
atSign: 64,
uppercaseA: 65,
uppercaseB: 66,
uppercaseC: 67,
uppercaseD: 68,
uppercaseE: 69,
uppercaseF: 70,
uppercaseG: 71,
uppercaseH: 72,
uppercaseI: 73,
uppercaseJ: 74,
uppercaseK: 75,
uppercaseL: 76,
uppercaseM: 77,
uppercaseN: 78,
uppercaseO: 79,
uppercaseP: 80,
uppercaseQ: 81,
uppercaseR: 82,
uppercaseS: 83,
uppercaseT: 84,
uppercaseU: 85,
uppercaseV: 86,
uppercaseW: 87,
uppercaseX: 88,
uppercaseY: 89,
uppercaseZ: 90,
leftSquareBracket: 91,
backslash: 92,
rightSquareBracket: 93,
caret: 94,
underscore: 95,
graveAccent: 96,
lowercaseA: 97,
lowercaseB: 98,
lowercaseC: 99,
lowercaseD: 100,
lowercaseE: 101,
lowercaseF: 102,
lowercaseG: 103,
lowercaseH: 104,
lowercaseI: 105,
lowercaseJ: 106,
lowercaseK: 107,
lowercaseL: 108,
lowercaseM: 109,
lowercaseN: 110,
lowercaseO: 111,
lowercaseP: 112,
lowercaseQ: 113,
lowercaseR: 114,
lowercaseS: 115,
lowercaseT: 116,
lowercaseU: 117,
lowercaseV: 118,
lowercaseW: 119,
lowercaseX: 120,
lowercaseY: 121,
lowercaseZ: 122,
leftCurlyBrace: 123,
verticalBar: 124,
rightCurlyBrace: 125,
tilde: 126,
del: 127,
// Unicode Specials block.
byteOrderMarker: 65279,
// Unicode Specials block.
replacementCharacter: 65533 // `�`
};
}),
"./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/constants.js": (function (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
constants: function() { return constants; }
});
/**
* This module is compiled away!
*
* Parsing markdown comes with a couple of constants, such as minimum or maximum
* sizes of certain sequences.
* Additionally, there are a couple symbols used inside micromark.
* These are all defined here, but compiled away by scripts.
*/ const constants = {
attentionSideBefore: 1,
attentionSideAfter: 2,
atxHeadingOpeningFenceSizeMax: 6,
autolinkDomainSizeMax: 63,
autolinkSchemeSizeMax: 32,
cdataOpeningString: 'CDATA[',
characterGroupWhitespace: 1,
characterGroupPunctuation: 2,
characterReferenceDecimalSizeMax: 7,
characterReferenceHexadecimalSizeMax: 6,
characterReferenceNamedSizeMax: 31,
codeFencedSequenceSizeMin: 3,
contentTypeDocument: 'document',
contentTypeFlow: 'flow',
contentTypeContent: 'content',
contentTypeString: 'string',
contentTypeText: 'text',
hardBreakPrefixSizeMin: 2,
htmlRaw: 1,
htmlComment: 2,
htmlInstruction: 3,
htmlDeclaration: 4,
htmlCdata: 5,
htmlBasic: 6,
htmlComplete: 7,
htmlRawSizeMax: 8,
linkResourceDestinationBalanceMax: 32,
linkReferenceSizeMax: 999,
listItemValueSizeMax: 10,
numericBaseDecimal: 10,
numericBaseHexadecimal: 0x10,
tabSize: 4,
thematicBreakMarkerCountMin: 3,
v8MaxSafeChunkSize: 10000 // V8 (and potentially others) have problems injecting giant arrays into other arrays, hence we operate in chunks.
};
}),
"./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/default.js": (function (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
codes: function() { return _codes_js__WEBPACK_IMPORTED_MODULE_0__.codes; },
constants: function() { return _constants_js__WEBPACK_IMPORTED_MODULE_1__.constants; },
types: function() { return _types_js__WEBPACK_IMPORTED_MODULE_2__.types; },
values: function() { return _values_js__WEBPACK_IMPORTED_MODULE_3__.values; }
});
/* harmony import */var _codes_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./codes.js */"./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/codes.js");
/* harmony import */var _constants_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constants.js */"./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/constants.js");
/* harmony import */var _types_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./types.js */"./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/types.js");
/* harmony import */var _values_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./values.js */"./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/values.js");
}),
"./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/types.js": (function (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
types: function() { return types; }
});
/**
* This module is compiled away!
*
* Here is the list of all types of tokens exposed by micromark, with a short
* explanation of what they include and where they are found.
* In picking names, generally, the rule is to be as explicit as possible
* instead of reusing names.
* For example, there is a `definitionDestination` and a `resourceDestination`,
* instead of one shared name.
*/ // Note: when changing the next record, you must also change `TokenTypeMap`
// in `micromark-util-types/index.d.ts`.
const types = {
// Generic type for data, such as in a title, a destination, etc.
data: 'data',
// Generic type for syntactic whitespace (tabs, virtual spaces, spaces).
// Such as, between a fenced code fence and an info string.
whitespace: 'whitespace',
// Generic type for line endings (line feed, carriage return, carriage return +
// line feed).
lineEnding: 'lineEnding',
// A line ending, but ending a blank line.
lineEndingBlank: 'lineEndingBlank',
// Generic type for whitespace (tabs, virtual spaces, spaces) at the start of a
// line.
linePrefix: 'linePrefix',
// Generic type for whitespace (tabs, virtual spaces, spaces) at the end of a
// line.
lineSuffix: 'lineSuffix',
// Whole ATX heading:
//
// ```markdown
// #
// ## Alpha
// ### Bravo ###
// ```
//
// Includes `atxHeadingSequence`, `whitespace`, `atxHeadingText`.
atxHeading: 'atxHeading',
// Sequence of number signs in an ATX heading (`###`).
atxHeadingSequence: 'atxHeadingSequence',
// Content in an ATX heading (`alpha`).
// Includes text.
atxHeadingText: 'atxHeadingText',
// Whole autolink (`<https://example.com>` or `<admin@example.com>`)
// Includes `autolinkMarker` and `autolinkProtocol` or `autolinkEmail`.
autolink: 'autolink',
// Email autolink w/o markers (`admin@example.com`)
autolinkEmail: 'autolinkEmail',
// Marker around an `autolinkProtocol` or `autolinkEmail` (`<` or `>`).
autolinkMarker: 'autolinkMarker',
// Protocol autolink w/o markers (`https://example.com`)
autolinkProtocol: 'autolinkProtocol',
// A whole character escape (`\-`).
// Includes `escapeMarker` and `characterEscapeValue`.
characterEscape: 'characterEscape',
// The escaped character (`-`).
characterEscapeValue: 'characterEscapeValue',
// A whole character reference (`&`, `≠`, or `𝌆`).
// Includes `characterReferenceMarker`, an optional
// `characterReferenceMarkerNumeric`, in which case an optional
// `characterReferenceMarkerHexadecimal`, and a `characterReferenceValue`.
characterReference: 'characterReference',
// The start or end marker (`&` or `;`).
characterReferenceMarker: 'characterReferenceMarker',
// Mark reference as numeric (`#`).
characterReferenceMarkerNumeric: 'characterReferenceMarkerNumeric',
// Mark reference as numeric (`x` or `X`).
characterReferenceMarkerHexadecimal: 'characterReferenceMarkerHexadecimal',
// Value of character reference w/o markers (`amp`, `8800`, or `1D306`).
characterReferenceValue: 'characterReferenceValue',
// Whole fenced code:
//
// ````markdown
// ```js
// alert(1)
// ```
// ````
codeFenced: 'codeFenced',
// A fenced code fence, including whitespace, sequence, info, and meta
// (` ```js `).
codeFencedFence: 'codeFencedFence',
// Sequence of grave accent or tilde characters (` ``` `) in a fence.
codeFencedFenceSequence: 'codeFencedFenceSequence',
// Info word (`js`) in a fence.
// Includes string.
codeFencedFenceInfo: 'codeFencedFenceInfo',
// Meta words (`highlight="1"`) in a fence.
// Includes string.
codeFencedFenceMeta: 'codeFencedFenceMeta',
// A line of code.
codeFlowValue: 'codeFlowValue',
// Whole indented code:
//
// ```markdown
// alert(1)
// ```
//
// Includes `lineEnding`, `linePrefix`, and `codeFlowValue`.
codeIndented: 'codeIndented',
// A text code (``` `alpha` ```).
// Includes `codeTextSequence`, `codeTextData`, `lineEnding`, and can include
// `codeTextPadding`.
codeText: 'codeText',
codeTextData: 'codeTextData',
// A space or line ending right after or before a tick.
codeTextPadding: 'codeTextPadding',
// A text code fence (` `` `).
codeTextSequence: 'codeTextSequence',
// Whole content:
//
// ```markdown
// [a]: b
// c
// =
// d
// ```
//
// Includes `paragraph` and `definition`.
content: 'content',
// Whole definition:
//
// ```markdown
// [micromark]: https://github.com/micromark/micromark
// ```
//
// Includes `definitionLabel`, `definitionMarker`, `whitespace`,
// `definitionDestination`, and optionally `lineEnding` and `definitionTitle`.
definition: 'definition',
// Destination of a definition (`https://github.com/micromark/micromark` or
// `<https://github.com/micromark/micromark>`).
// Includes `definitionDestinationLiteral` or `definitionDestinationRaw`.
definitionDestination: 'definitionDestination',
// Enclosed destination of a definition
// (`<https://github.com/micromark/micromark>`).
// Includes `definitionDestinationLiteralMarker` and optionally
// `definitionDestinationString`.
definitionDestinationLiteral: 'definitionDestinationLiteral',
// Markers of an enclosed definition destination (`<` or `>`).
definitionDestinationLiteralMarker: 'definitionDestinationLiteralMarker',
// Unenclosed destination of a definition
// (`https://github.com/micromark/micromark`).
// Includes `definitionDestinationString`.
definitionDestinationRaw: 'definitionDestinationRaw',
// Text in an destination (`https://github.com/micromark/micromark`).
// Includes string.
definitionDestinationString: 'definitionDestinationString',
// Label of a definition (`[micromark]`).
// Includes `definitionLabelMarker` and `definitionLabelString`.
definitionLabel: 'definitionLabel',
// Markers of a definition label (`[` or `]`).
definitionLabelMarker: 'definitionLabelMarker',
// Value of a definition label (`micromark`).
// Includes string.
definitionLabelString: 'definitionLabelString',
// Marker between a label and a destination (`:`).
definitionMarker: 'definitionMarker',
// Title of a definition (`"x"`, `'y'`, or `(z)`).
// Includes `definitionTitleMarker` and optionally `definitionTitleString`.
definitionTitle: 'definitionTitle',
// Marker around a title of a definition (`"`, `'`, `(`, or `)`).
definitionTitleMarker: 'definitionTitleMarker',
// Data without markers in a title (`z`).
// Includes string.
definitionTitleString: 'definitionTitleString',
// Emphasis (`*alpha*`).
// Includes `emphasisSequence` and `emphasisText`.
emphasis: 'emphasis',
// Sequence of emphasis markers (`*` or `_`).
emphasisSequence: 'emphasisSequence',
// Emphasis text (`alpha`).
// Includes text.
emphasisText: 'emphasisText',
// The character escape marker (`\`).
escapeMarker: 'escapeMarker',
// A hard break created with a backslash (`\\n`).
// Note: does not include the line ending.
hardBreakEscape: 'hardBreakEscape',
// A hard break created with trailing spaces (` \n`).
// Does not include the line ending.
hardBreakTrailing: 'hardBreakTrailing',
// Flow HTML:
//
// ```markdown
// <div
// ```
//
// Inlcudes `lineEnding`, `htmlFlowData`.
htmlFlow: 'htmlFlow',
htmlFlowData: 'htmlFlowData',
// HTML in text (the tag in `a <i> b`).
// Includes `lineEnding`, `htmlTextData`.
htmlText: 'htmlText',
htmlTextData: 'htmlTextData',
// Whole image (``, `![alpha][bravo]`, `![alpha][]`, or
// `![alpha]`).
// Includes `label` and an optional `resource` or `reference`.
image: 'image',
// Whole link label (`[*alpha*]`).
// Includes `labelLink` or `labelImage`, `labelText`, and `labelEnd`.
label: 'label',
// Text in an label (`*alpha*`).
// Includes text.
labelText: 'labelText',
// Start a link label (`[`).
// Includes a `labelMarker`.
labelLink: 'labelLink',
// Start an image label (`![`).
// Includes `labelImageMarker` and `labelMarker`.
labelImage: 'labelImage',
// Marker of a label (`[` or `]`).
labelMarker: 'labelMarker',
// Marker to start an image (`!`).
labelImageMarker: 'labelImageMarker',
// End a label (`]`).
// Includes `labelMarker`.
labelEnd: 'labelEnd',
// Whole link (`[alpha](bravo)`, `[alpha][bravo]`, `[alpha][]`, or `[alpha]`).
// Includes `label` and an optional `resource` or `reference`.
link: 'link',
// Whole paragraph:
//
// ```markdown
// alpha
// bravo.
// ```
//
// Includes text.
paragraph: 'paragraph',
// A reference (`[alpha]` or `[]`).
// Includes `referenceMarker` and an optional `referenceString`.
reference: 'reference',
// A reference marker (`[` or `]`).
referenceMarker: 'referenceMarker',
// Reference text (`alpha`).
// Includes string.
referenceString: 'referenceString',
// A resource (`(https://example.com "alpha")`).
// Includes `resourceMarker`, an optional `resourceDestination` with an optional
// `whitespace` and `resourceTitle`.
resource: 'resource',
// A resource destination (`https://example.com`).
// Includes `resourceDestinationLiteral` or `resourceDestinationRaw`.
resourceDestination: 'resourceDestination',
// A literal resource destination (`<https://example.com>`).
// Includes `resourceDestinationLiteralMarker` and optionally
// `resourceDestinationString`.
resourceDestinationLiteral: 'resourceDestinationLiteral',
// A resource destination marker (`<` or `>`).
resourceDestinationLiteralMarker: 'resourceDestinationLiteralMarker',
// A raw resource destination (`https://example.com`).
// Includes `resourceDestinationString`.
resourceDestinationRaw: 'resourceDestinationRaw',
// Resource destination text (`https://example.com`).
// Includes string.
resourceDestinationString: 'resourceDestinationString',
// A resource marker (`(` or `)`).
resourceMarker: 'resourceMarker',
// A resource title (`"alpha"`, `'alpha'`, or `(alpha)`).
// Includes `resourceTitleMarker` and optionally `resourceTitleString`.
resourceTitle: 'resourceTitle',
// A resource title marker (`"`, `'`, `(`, or `)`).
resourceTitleMarker: 'resourceTitleMarker',
// Resource destination title (`alpha`).
// Includes string.
resourceTitleString: 'resourceTitleString',
// Whole setext heading:
//
// ```markdown
// alpha
// bravo
// =====
// ```
//
// Includes `setextHeadingText`, `lineEnding`, `linePrefix`, and
// `setextHeadingLine`.
setextHeading: 'setextHeading',
// Content in a setext heading (`alpha\nbravo`).
// Includes text.
setextHeadingText: 'setextHeadingText',
// Underline in a setext heading, including whitespace suffix (`==`).
// Includes `setextHeadingLineSequence`.
setextHeadingLine: 'setextHeadingLine',
// Sequence of equals or dash characters in underline in a setext heading (`-`).
setextHeadingLineSequence: 'setextHeadingLineSequence',
// Strong (`**alpha**`).
// Includes `strongSequence` and `strongText`.
strong: 'strong',
// Sequence of strong markers (`**` or `__`).
strongSequence: 'strongSequence',
// Strong text (`alpha`).
// Includes text.
strongText: 'strongText',
// Whole thematic break:
//
// ```markdown
// * * *
// ```
//
// Includes `thematicBreakSequence` and `whitespace`.
thematicBreak: 'thematicBreak',
// A sequence of one or more thematic break markers (`***`).
thematicBreakSequence: 'thematicBreakSequence',
// Whole block quote:
//
// ```markdown
// > a
// >
// > b
// ```
//
// Includes `blockQuotePrefix` and flow.
blockQuote: 'blockQuote',
// The `>` or `> ` of a block quote.
blockQuotePrefix: 'blockQuotePrefix',
// The `>` of a block quote prefix.
blockQuoteMarker: 'blockQuoteMarker',
// The optional ` ` of a block quote prefix.
blockQuotePrefixWhitespace: 'blockQuotePrefixWhitespace',
// Whole unordered list:
//
// ```markdown
// - a
// b
// ```
//
// Includes `listItemPrefix`, flow, and optionally `listItemIndent` on further
// lines.
listOrdered: 'listOrdered',
// Whole ordered list:
//
// ```markdown
// 1. a
// b
// ```
//
// Includes `listItemPrefix`, flow, and optionally `listItemIndent` on further
// lines.
listUnordered: 'listUnordered',
// The indent of further list item lines.
listItemIndent: 'listItemIndent',
// A marker, as in, `*`, `+`, `-`, `.`, or `)`.
listItemMarker: 'listItemMarker',
// The thing that starts a list item, such as `1. `.
// Includes `listItemValue` if ordered, `listItemMarker`, and
// `listItemPrefixWhitespace` (unless followed by a line ending).
listItemPrefix: 'listItemPrefix',
// The whitespace after a marker.
listItemPrefixWhitespace: 'listItemPrefixWhitespace',
// The numerical value of an ordered item.
listItemValue: 'listItemValue',
// Internal types used for subtokenizers, compiled away
chunkDocument: 'chunkDocument',
chunkContent: 'chunkContent',
chunkFlow: 'chunkFlow',
chunkText: 'chunkText',
chunkString: 'chunkString'
};
}),
"./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/values.js": (function (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
values: function() { return values; }
});
/**
* This module is compiled away!
*
* While micromark works based on character codes, this module includes the
* string versions of ’em.
* The C0 block, except for LF, CR, HT, and w/ the replacement character added,
* are available here.
*/ const values = {
ht: '\t',
lf: '\n',
cr: '\r',
space: ' ',
exclamationMark: '!',
quotationMark: '"',
numberSign: '#',
dollarSign: '$',
percentSign: '%',
ampersand: '&',
apostrophe: "'",
leftParenthesis: '(',
rightParenthesis: ')',
asterisk: '*',
plusSign: '+',
comma: ',',
dash: '-',
dot: '.',
slash: '/',
digit0: '0',
digit1: '1',
digit2: '2',
digit3: '3',
digit4: '4',
digit5: '5',
digit6: '6',
digit7: '7',
digit8: '8',
digit9: '9',
colon: ':',
semicolon: ';',
lessThan: '<',
equalsTo: '=',
greaterThan: '>',
questionMark: '?',
atSign: '@',
uppercaseA: 'A',
uppercaseB: 'B',
uppercaseC: 'C',
uppercaseD: 'D',
uppercaseE: 'E',
uppercaseF: 'F',
uppercaseG: 'G',
uppercaseH: 'H',
uppercaseI: 'I',
uppercaseJ: 'J',
uppercaseK: 'K',
uppercaseL: 'L',
uppercaseM: 'M',
uppercaseN: 'N',
uppercaseO: 'O',
uppercaseP: 'P',
uppercaseQ: 'Q',
uppercaseR: 'R',
uppercaseS: 'S',
uppercaseT: 'T',
uppercaseU: 'U',
uppercaseV: 'V',
uppercaseW: 'W',
uppercaseX: 'X',
uppercaseY: 'Y',
uppercaseZ: 'Z',
leftSquareBracket: '[',
backslash: '\\',
rightSquareBracket: ']',
caret: '^',
underscore: '_',
graveAccent: '`',
lowercaseA: 'a',
lowercaseB: 'b',
lowercaseC: 'c',
lowercaseD: 'd',
lowercaseE: 'e',
lowercaseF: 'f',
lowercaseG: 'g',
lowercaseH: 'h',
lowercaseI: 'i',
lowercaseJ: 'j',
lowercaseK: 'k',
lowercaseL: 'l',
lowercaseM: 'm',
lowercaseN: 'n',
lowercaseO: 'o',
lowercaseP: 'p',
lowercaseQ: 'q',
lowercaseR: 'r',
lowercaseS: 's',
lowercaseT: 't',
lowercaseU: 'u',
lowercaseV: 'v',
lowercaseW: 'w',
lowercaseX: 'x',
lowercaseY: 'y',
lowercaseZ: 'z',
leftCurlyBrace: '{',
verticalBar: '|',
rightCurlyBrace: '}',
tilde: '~',
replacementCharacter: '�'
};
}),
}
// The module cache
var __webpack_module_cache__ = {};
function __webpack_require__(moduleId) {
// Check if module is in cache
var cachedModule = __webpack_module_cache__[moduleId];
if (cachedModule !== undefined) {
return cachedModule.exports;
}
// Create a new module (and put it into the cache)
var module = (__webpack_module_cache__[moduleId] = {
exports: {}
});
// Execute the module function
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
// Return the exports of the module
return module.exports;
}
// webpack/runtime/load_chunk_with_block
!function() {
var map = {};
__webpack_require__.el = function(module) {
var chunkIds = map[module];
if (chunkIds === undefined) return Promise.resolve();
if (chunkIds.length > 1) return Promise.all(chunkIds.map(__webpack_require__.e));
return __webpack_require__.e(chunkIds[0]);
}
}();
// webpack/runtime/ensure_chunk
!function() {
__webpack_require__.f = {};
// This file contains only the entry chunk.
// The chunk loading function for additional chunks
__webpack_require__.e = function (chunkId) {
return Promise.all(
Object.keys(__webpack_require__.f).reduce(function (promises, key) {
__webpack_require__.f[key](chunkId, promises);
return promises;
}, [])
);
};
}();
// webpack/runtime/has_own_property
!function() {
__webpack_require__.o = function (obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
};
}();
// webpack/runtime/define_property_getters
!function() {
__webpack_require__.d = function(exports, definition) {
for(var key in definition) {
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
}
}
};
}();
// webpack/runtime/make_namespace_object
!function() {
// define __esModule on exports
__webpack_require__.r = function(exports) {
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
}
Object.defineProperty(exports, '__esModule', { value: true });
};
}();
var __webpack_exports__ = __webpack_require__("./src/index.js");
})()
|
07akioni/rspack-treeshaking-issue-reprod
| 0
|
JavaScript
|
07akioni
|
07akioni
|
DeepSeek
|
|
src/index.js
|
JavaScript
|
import { math } from "micromark-extension-math";
console.log(math);
import("katex").then((katex) => {
console.log(katex);
});
|
07akioni/rspack-treeshaking-issue-reprod
| 0
|
JavaScript
|
07akioni
|
07akioni
|
DeepSeek
|
|
src/render.css
|
CSS
|
.text {
color: blue;
}
|
07akioni/rspack-treeshaking-issue-reprod
| 0
|
JavaScript
|
07akioni
|
07akioni
|
DeepSeek
|
|
src/render.js
|
JavaScript
|
import './render.css'
export function render() {
const el = document.createElement('div')
el.classList.add('text')
document.getElementsByTagName('body')[0].appendChild(el)
el.innerHTML = 'hello, world'
}
|
07akioni/rspack-treeshaking-issue-reprod
| 0
|
JavaScript
|
07akioni
|
07akioni
|
DeepSeek
|
|
webpack-dist/index.html
|
HTML
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Webpack App</title>
<meta name="viewport" content="width=device-width, initial-scale=1"><script defer src="main.js"></script></head>
<body>
</body>
</html>
|
07akioni/rspack-treeshaking-issue-reprod
| 0
|
JavaScript
|
07akioni
|
07akioni
|
DeepSeek
|
|
webpack-dist/main.js
|
JavaScript
|
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/dist/index.mjs":
/*!****************************************************************************!*\
!*** ./node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/dist/index.mjs ***!
\****************************************************************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ dequal: () => (/* binding */ dequal)
/* harmony export */ });
var has = Object.prototype.hasOwnProperty;
function find(iter, tar, key) {
for (key of iter.keys()) {
if (dequal(key, tar)) return key;
}
}
function dequal(foo, bar) {
var ctor, len, tmp;
if (foo === bar) return true;
if (foo && bar && (ctor=foo.constructor) === bar.constructor) {
if (ctor === Date) return foo.getTime() === bar.getTime();
if (ctor === RegExp) return foo.toString() === bar.toString();
if (ctor === Array) {
if ((len=foo.length) === bar.length) {
while (len-- && dequal(foo[len], bar[len]));
}
return len === -1;
}
if (ctor === Set) {
if (foo.size !== bar.size) {
return false;
}
for (len of foo) {
tmp = len;
if (tmp && typeof tmp === 'object') {
tmp = find(bar, tmp);
if (!tmp) return false;
}
if (!bar.has(tmp)) return false;
}
return true;
}
if (ctor === Map) {
if (foo.size !== bar.size) {
return false;
}
for (len of foo) {
tmp = len[0];
if (tmp && typeof tmp === 'object') {
tmp = find(bar, tmp);
if (!tmp) return false;
}
if (!dequal(len[1], bar.get(tmp))) {
return false;
}
}
return true;
}
if (ctor === ArrayBuffer) {
foo = new Uint8Array(foo);
bar = new Uint8Array(bar);
} else if (ctor === DataView) {
if ((len=foo.byteLength) === bar.byteLength) {
while (len-- && foo.getInt8(len) === bar.getInt8(len));
}
return len === -1;
}
if (ArrayBuffer.isView(foo)) {
if ((len=foo.byteLength) === bar.byteLength) {
while (len-- && foo[len] === bar[len]);
}
return len === -1;
}
if (!ctor || typeof foo === 'object') {
len = 0;
for (ctor in foo) {
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
}
return Object.keys(bar).length === len;
}
}
return foo !== foo && bar !== bar;
}
/***/ }),
/***/ "./node_modules/.pnpm/devlop@1.1.0/node_modules/devlop/lib/development.js":
/*!********************************************************************************!*\
!*** ./node_modules/.pnpm/devlop@1.1.0/node_modules/devlop/lib/development.js ***!
\********************************************************************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ deprecate: () => (/* binding */ deprecate),
/* harmony export */ equal: () => (/* binding */ equal),
/* harmony export */ ok: () => (/* binding */ ok),
/* harmony export */ unreachable: () => (/* binding */ unreachable)
/* harmony export */ });
/* harmony import */ var dequal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! dequal */ "./node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/dist/index.mjs");
/**
* @type {Set<string>}
*/
const codesWarned = new Set()
class AssertionError extends Error {
name = /** @type {const} */ ('Assertion')
code = /** @type {const} */ ('ERR_ASSERTION')
/**
* Create an assertion error.
*
* @param {string} message
* Message explaining error.
* @param {unknown} actual
* Value.
* @param {unknown} expected
* Baseline.
* @param {string} operator
* Name of equality operation.
* @param {boolean} generated
* Whether `message` is a custom message or not
* @returns
* Instance.
*/
// eslint-disable-next-line max-params
constructor(message, actual, expected, operator, generated) {
super(message)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor)
}
/**
* @type {unknown}
*/
this.actual = actual
/**
* @type {unknown}
*/
this.expected = expected
/**
* @type {boolean}
*/
this.generated = generated
/**
* @type {string}
*/
this.operator = operator
}
}
class DeprecationError extends Error {
name = /** @type {const} */ ('DeprecationWarning')
/**
* Create a deprecation message.
*
* @param {string} message
* Message explaining deprecation.
* @param {string | undefined} code
* Deprecation identifier; deprecation messages will be generated only once per code.
* @returns
* Instance.
*/
constructor(message, code) {
super(message)
/**
* @type {string | undefined}
*/
this.code = code
}
}
/**
* Wrap a function or class to show a deprecation message when first called.
*
* > 👉 **Important**: only shows a message when the `development` condition is
* > used, does nothing in production.
*
* When the resulting wrapped `fn` is called, emits a warning once to
* `console.error` (`stderr`).
* If a code is given, one warning message will be emitted in total per code.
*
* @template {Function} T
* Function or class kind.
* @param {T} fn
* Function or class.
* @param {string} message
* Message explaining deprecation.
* @param {string | null | undefined} [code]
* Deprecation identifier (optional); deprecation messages will be generated
* only once per code.
* @returns {T}
* Wrapped `fn`.
*/
function deprecate(fn, message, code) {
let warned = false
// The wrapper will keep the same prototype as fn to maintain prototype chain
Object.setPrototypeOf(deprecated, fn)
// @ts-expect-error: it’s perfect, typescript…
return deprecated
/**
* @this {unknown}
* @param {...Array<unknown>} args
* @returns {unknown}
*/
function deprecated(...args) {
if (!warned) {
warned = true
if (typeof code === 'string' && codesWarned.has(code)) {
// Empty.
} else {
console.error(new DeprecationError(message, code || undefined))
if (typeof code === 'string') codesWarned.add(code)
}
}
return new.target
? Reflect.construct(fn, args, new.target)
: Reflect.apply(fn, this, args)
}
}
/**
* Assert deep strict equivalence.
*
* > 👉 **Important**: only asserts when the `development` condition is used,
* > does nothing in production.
*
* @template {unknown} T
* Expected kind.
* @param {unknown} actual
* Value.
* @param {T} expected
* Baseline.
* @param {Error | string | null | undefined} [message]
* Message for assertion error (default: `'Expected values to be deeply equal'`).
* @returns {asserts actual is T}
* Nothing; throws when `actual` is not deep strict equal to `expected`.
* @throws {AssertionError}
* Throws when `actual` is not deep strict equal to `expected`.
*/
function equal(actual, expected, message) {
assert(
(0,dequal__WEBPACK_IMPORTED_MODULE_0__.dequal)(actual, expected),
actual,
expected,
'equal',
'Expected values to be deeply equal',
message
)
}
/**
* Assert if `value` is truthy.
*
* > 👉 **Important**: only asserts when the `development` condition is used,
* > does nothing in production.
*
* @param {unknown} value
* Value to assert.
* @param {Error | string | null | undefined} [message]
* Message for assertion error (default: `'Expected value to be truthy'`).
* @returns {asserts value}
* Nothing; throws when `value` is falsey.
* @throws {AssertionError}
* Throws when `value` is falsey.
*/
function ok(value, message) {
assert(
Boolean(value),
false,
true,
'ok',
'Expected value to be truthy',
message
)
}
/**
* Assert that a code path never happens.
*
* > 👉 **Important**: only asserts when the `development` condition is used,
* > does nothing in production.
*
* @param {Error | string | null | undefined} [message]
* Message for assertion error (default: `'Unreachable'`).
* @returns {never}
* Nothing; always throws.
* @throws {AssertionError}
* Throws when `value` is falsey.
*/
function unreachable(message) {
assert(false, false, true, 'ok', 'Unreachable', message)
}
/**
* @param {boolean} bool
* Whether to skip this operation.
* @param {unknown} actual
* Actual value.
* @param {unknown} expected
* Expected value.
* @param {string} operator
* Operator.
* @param {string} defaultMessage
* Default message for operation.
* @param {Error | string | null | undefined} userMessage
* User-provided message.
* @returns {asserts bool}
* Nothing; throws when falsey.
*/
// eslint-disable-next-line max-params
function assert(bool, actual, expected, operator, defaultMessage, userMessage) {
if (!bool) {
throw userMessage instanceof Error
? userMessage
: new AssertionError(
userMessage || defaultMessage,
actual,
expected,
operator,
!userMessage
)
}
}
/***/ }),
/***/ "./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/math-flow.js":
/*!**********************************************************************************************************************!*\
!*** ./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/math-flow.js ***!
\**********************************************************************************************************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ mathFlow: () => (/* binding */ mathFlow)
/* harmony export */ });
/* harmony import */ var devlop__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! devlop */ "./node_modules/.pnpm/devlop@1.1.0/node_modules/devlop/lib/development.js");
/* harmony import */ var micromark_factory_space__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! micromark-factory-space */ "./node_modules/.pnpm/micromark-factory-space@2.0.0/node_modules/micromark-factory-space/dev/index.js");
/* harmony import */ var micromark_util_character__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! micromark-util-character */ "./node_modules/.pnpm/micromark-util-character@2.0.1/node_modules/micromark-util-character/dev/index.js");
/* harmony import */ var micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! micromark-util-symbol */ "./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/types.js");
/* harmony import */ var micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! micromark-util-symbol */ "./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/codes.js");
/* harmony import */ var micromark_util_symbol__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! micromark-util-symbol */ "./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/constants.js");
/**
* @typedef {import('micromark-util-types').Construct} Construct
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
*/
/** @type {Construct} */
const mathFlow = {
tokenize: tokenizeMathFenced,
concrete: true
}
/** @type {Construct} */
const nonLazyContinuation = {
tokenize: tokenizeNonLazyContinuation,
partial: true
}
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeMathFenced(effects, ok, nok) {
const self = this
const tail = self.events[self.events.length - 1]
const initialSize =
tail && tail[1].type === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.types.linePrefix
? tail[2].sliceSerialize(tail[1], true).length
: 0
let sizeOpen = 0
return start
/**
* Start of math.
*
* ```markdown
* > | $$
* ^
* | \frac{1}{2}
* | $$
* ```
*
* @type {State}
*/
function start(code) {
;(0,devlop__WEBPACK_IMPORTED_MODULE_1__.ok)(code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.dollarSign, 'expected `$`')
effects.enter('mathFlow')
effects.enter('mathFlowFence')
effects.enter('mathFlowFenceSequence')
return sequenceOpen(code)
}
/**
* In opening fence sequence.
*
* ```markdown
* > | $$
* ^
* | \frac{1}{2}
* | $$
* ```
*
* @type {State}
*/
function sequenceOpen(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.dollarSign) {
effects.consume(code)
sizeOpen++
return sequenceOpen
}
if (sizeOpen < 2) {
return nok(code)
}
effects.exit('mathFlowFenceSequence')
return (0,micromark_factory_space__WEBPACK_IMPORTED_MODULE_3__.factorySpace)(effects, metaBefore, micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.types.whitespace)(code)
}
/**
* In opening fence, before meta.
*
* ```markdown
* > | $$asciimath
* ^
* | x < y
* | $$
* ```
*
* @type {State}
*/
function metaBefore(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.eof || (0,micromark_util_character__WEBPACK_IMPORTED_MODULE_4__.markdownLineEnding)(code)) {
return metaAfter(code)
}
effects.enter('mathFlowFenceMeta')
effects.enter(micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.types.chunkString, {contentType: micromark_util_symbol__WEBPACK_IMPORTED_MODULE_5__.constants.contentTypeString})
return meta(code)
}
/**
* In meta.
*
* ```markdown
* > | $$asciimath
* ^
* | x < y
* | $$
* ```
*
* @type {State}
*/
function meta(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.eof || (0,micromark_util_character__WEBPACK_IMPORTED_MODULE_4__.markdownLineEnding)(code)) {
effects.exit(micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.types.chunkString)
effects.exit('mathFlowFenceMeta')
return metaAfter(code)
}
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.dollarSign) {
return nok(code)
}
effects.consume(code)
return meta
}
/**
* After meta.
*
* ```markdown
* > | $$
* ^
* | \frac{1}{2}
* | $$
* ```
*
* @type {State}
*/
function metaAfter(code) {
// Guaranteed to be eol/eof.
effects.exit('mathFlowFence')
if (self.interrupt) {
return ok(code)
}
return effects.attempt(
nonLazyContinuation,
beforeNonLazyContinuation,
after
)(code)
}
/**
* After eol/eof in math, at a non-lazy closing fence or content.
*
* ```markdown
* | $$
* > | \frac{1}{2}
* ^
* > | $$
* ^
* ```
*
* @type {State}
*/
function beforeNonLazyContinuation(code) {
return effects.attempt(
{tokenize: tokenizeClosingFence, partial: true},
after,
contentStart
)(code)
}
/**
* Before math content, definitely not before a closing fence.
*
* ```markdown
* | $$
* > | \frac{1}{2}
* ^
* | $$
* ```
*
* @type {State}
*/
function contentStart(code) {
return (
initialSize
? (0,micromark_factory_space__WEBPACK_IMPORTED_MODULE_3__.factorySpace)(
effects,
beforeContentChunk,
micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.types.linePrefix,
initialSize + 1
)
: beforeContentChunk
)(code)
}
/**
* Before math content, after optional prefix.
*
* ```markdown
* | $$
* > | \frac{1}{2}
* ^
* | $$
* ```
*
* @type {State}
*/
function beforeContentChunk(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.eof) {
return after(code)
}
if ((0,micromark_util_character__WEBPACK_IMPORTED_MODULE_4__.markdownLineEnding)(code)) {
return effects.attempt(
nonLazyContinuation,
beforeNonLazyContinuation,
after
)(code)
}
effects.enter('mathFlowValue')
return contentChunk(code)
}
/**
* In math content.
*
* ```markdown
* | $$
* > | \frac{1}{2}
* ^
* | $$
* ```
*
* @type {State}
*/
function contentChunk(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.eof || (0,micromark_util_character__WEBPACK_IMPORTED_MODULE_4__.markdownLineEnding)(code)) {
effects.exit('mathFlowValue')
return beforeContentChunk(code)
}
effects.consume(code)
return contentChunk
}
/**
* After math (ha!).
*
* ```markdown
* | $$
* | \frac{1}{2}
* > | $$
* ^
* ```
*
* @type {State}
*/
function after(code) {
effects.exit('mathFlow')
return ok(code)
}
/** @type {Tokenizer} */
function tokenizeClosingFence(effects, ok, nok) {
let size = 0
;(0,devlop__WEBPACK_IMPORTED_MODULE_1__.ok)(self.parser.constructs.disable.null, 'expected `disable.null`')
/**
* Before closing fence, at optional whitespace.
*
* ```markdown
* | $$
* | \frac{1}{2}
* > | $$
* ^
* ```
*/
return (0,micromark_factory_space__WEBPACK_IMPORTED_MODULE_3__.factorySpace)(
effects,
beforeSequenceClose,
micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.types.linePrefix,
self.parser.constructs.disable.null.includes('codeIndented')
? undefined
: micromark_util_symbol__WEBPACK_IMPORTED_MODULE_5__.constants.tabSize
)
/**
* In closing fence, after optional whitespace, at sequence.
*
* ```markdown
* | $$
* | \frac{1}{2}
* > | $$
* ^
* ```
*
* @type {State}
*/
function beforeSequenceClose(code) {
effects.enter('mathFlowFence')
effects.enter('mathFlowFenceSequence')
return sequenceClose(code)
}
/**
* In closing fence sequence.
*
* ```markdown
* | $$
* | \frac{1}{2}
* > | $$
* ^
* ```
*
* @type {State}
*/
function sequenceClose(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.dollarSign) {
size++
effects.consume(code)
return sequenceClose
}
if (size < sizeOpen) {
return nok(code)
}
effects.exit('mathFlowFenceSequence')
return (0,micromark_factory_space__WEBPACK_IMPORTED_MODULE_3__.factorySpace)(effects, afterSequenceClose, micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.types.whitespace)(code)
}
/**
* After closing fence sequence, after optional whitespace.
*
* ```markdown
* | $$
* | \frac{1}{2}
* > | $$
* ^
* ```
*
* @type {State}
*/
function afterSequenceClose(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_2__.codes.eof || (0,micromark_util_character__WEBPACK_IMPORTED_MODULE_4__.markdownLineEnding)(code)) {
effects.exit('mathFlowFence')
return ok(code)
}
return nok(code)
}
}
}
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeNonLazyContinuation(effects, ok, nok) {
const self = this
return start
/** @type {State} */
function start(code) {
if (code === null) {
return ok(code)
}
(0,devlop__WEBPACK_IMPORTED_MODULE_1__.ok)((0,micromark_util_character__WEBPACK_IMPORTED_MODULE_4__.markdownLineEnding)(code), 'expected eol')
effects.enter(micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.types.lineEnding)
effects.consume(code)
effects.exit(micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.types.lineEnding)
return lineStart
}
/** @type {State} */
function lineStart(code) {
return self.parser.lazy[self.now().line] ? nok(code) : ok(code)
}
}
/***/ }),
/***/ "./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/math-text.js":
/*!**********************************************************************************************************************!*\
!*** ./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/math-text.js ***!
\**********************************************************************************************************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ mathText: () => (/* binding */ mathText)
/* harmony export */ });
/* harmony import */ var devlop__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! devlop */ "./node_modules/.pnpm/devlop@1.1.0/node_modules/devlop/lib/development.js");
/* harmony import */ var micromark_util_character__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! micromark-util-character */ "./node_modules/.pnpm/micromark-util-character@2.0.1/node_modules/micromark-util-character/dev/index.js");
/* harmony import */ var micromark_util_symbol__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! micromark-util-symbol */ "./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/codes.js");
/* harmony import */ var micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! micromark-util-symbol */ "./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/types.js");
/**
* @typedef {import('micromark-util-types').Construct} Construct
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
* @typedef {import('micromark-util-types').Previous} Previous
* @typedef {import('micromark-util-types').Resolver} Resolver
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').Token} Token
*
* @typedef Options
* Configuration.
* @property {boolean | null | undefined} [singleDollarTextMath=true]
* Whether to support math (text) with a single dollar (default: `true`).
*
* Single dollars work in Pandoc and many other places, but often interfere
* with “normal” dollars in text.
* If you turn this off, you can use two or more dollars for text math.
*/
// To do: next major: clean spaces in HTML compiler.
// This has to be coordinated together with `mdast-util-math`.
/**
* @param {Options | null | undefined} [options={}]
* Configuration (default: `{}`).
* @returns {Construct}
* Construct.
*/
function mathText(options) {
const options_ = options || {}
let single = options_.singleDollarTextMath
if (single === null || single === undefined) {
single = true
}
return {
tokenize: tokenizeMathText,
resolve: resolveMathText,
previous
}
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeMathText(effects, ok, nok) {
const self = this
let sizeOpen = 0
/** @type {number} */
let size
/** @type {Token} */
let token
return start
/**
* Start of math (text).
*
* ```markdown
* > | $a$
* ^
* > | \$a$
* ^
* ```
*
* @type {State}
*/
function start(code) {
;(0,devlop__WEBPACK_IMPORTED_MODULE_0__.ok)(code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_1__.codes.dollarSign, 'expected `$`')
;(0,devlop__WEBPACK_IMPORTED_MODULE_0__.ok)(previous.call(self, self.previous), 'expected correct previous')
effects.enter('mathText')
effects.enter('mathTextSequence')
return sequenceOpen(code)
}
/**
* In opening sequence.
*
* ```markdown
* > | $a$
* ^
* ```
*
* @type {State}
*/
function sequenceOpen(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_1__.codes.dollarSign) {
effects.consume(code)
sizeOpen++
return sequenceOpen
}
// Not enough markers in the sequence.
if (sizeOpen < 2 && !single) {
return nok(code)
}
effects.exit('mathTextSequence')
return between(code)
}
/**
* Between something and something else.
*
* ```markdown
* > | $a$
* ^^
* ```
*
* @type {State}
*/
function between(code) {
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_1__.codes.eof) {
return nok(code)
}
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_1__.codes.dollarSign) {
token = effects.enter('mathTextSequence')
size = 0
return sequenceClose(code)
}
// Tabs don’t work, and virtual spaces don’t make sense.
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_1__.codes.space) {
effects.enter('space')
effects.consume(code)
effects.exit('space')
return between
}
if ((0,micromark_util_character__WEBPACK_IMPORTED_MODULE_2__.markdownLineEnding)(code)) {
effects.enter(micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.lineEnding)
effects.consume(code)
effects.exit(micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.lineEnding)
return between
}
// Data.
effects.enter('mathTextData')
return data(code)
}
/**
* In data.
*
* ```markdown
* > | $a$
* ^
* ```
*
* @type {State}
*/
function data(code) {
if (
code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_1__.codes.eof ||
code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_1__.codes.space ||
code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_1__.codes.dollarSign ||
(0,micromark_util_character__WEBPACK_IMPORTED_MODULE_2__.markdownLineEnding)(code)
) {
effects.exit('mathTextData')
return between(code)
}
effects.consume(code)
return data
}
/**
* In closing sequence.
*
* ```markdown
* > | `a`
* ^
* ```
*
* @type {State}
*/
function sequenceClose(code) {
// More.
if (code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_1__.codes.dollarSign) {
effects.consume(code)
size++
return sequenceClose
}
// Done!
if (size === sizeOpen) {
effects.exit('mathTextSequence')
effects.exit('mathText')
return ok(code)
}
// More or less accents: mark as data.
token.type = 'mathTextData'
return data(code)
}
}
}
/** @type {Resolver} */
function resolveMathText(events) {
let tailExitIndex = events.length - 4
let headEnterIndex = 3
/** @type {number} */
let index
/** @type {number | undefined} */
let enter
// If we start and end with an EOL or a space.
if (
(events[headEnterIndex][1].type === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.lineEnding ||
events[headEnterIndex][1].type === 'space') &&
(events[tailExitIndex][1].type === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.lineEnding ||
events[tailExitIndex][1].type === 'space')
) {
index = headEnterIndex
// And we have data.
while (++index < tailExitIndex) {
if (events[index][1].type === 'mathTextData') {
// Then we have padding.
events[tailExitIndex][1].type = 'mathTextPadding'
events[headEnterIndex][1].type = 'mathTextPadding'
headEnterIndex += 2
tailExitIndex -= 2
break
}
}
}
// Merge adjacent spaces and data.
index = headEnterIndex - 1
tailExitIndex++
while (++index <= tailExitIndex) {
if (enter === undefined) {
if (
index !== tailExitIndex &&
events[index][1].type !== micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.lineEnding
) {
enter = index
}
} else if (
index === tailExitIndex ||
events[index][1].type === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.lineEnding
) {
events[enter][1].type = 'mathTextData'
if (index !== enter + 2) {
events[enter][1].end = events[index - 1][1].end
events.splice(enter + 2, index - enter - 2)
tailExitIndex -= index - enter - 2
index = enter + 2
}
enter = undefined
}
}
return events
}
/**
* @this {TokenizeContext}
* @type {Previous}
*/
function previous(code) {
// If there is a previous code, there will always be a tail.
return (
code !== micromark_util_symbol__WEBPACK_IMPORTED_MODULE_1__.codes.dollarSign ||
this.events[this.events.length - 1][1].type === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_3__.types.characterEscape
)
}
/***/ }),
/***/ "./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/syntax.js":
/*!*******************************************************************************************************************!*\
!*** ./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/syntax.js ***!
\*******************************************************************************************************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ math: () => (/* binding */ math)
/* harmony export */ });
/* harmony import */ var micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! micromark-util-symbol */ "./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/codes.js");
/* harmony import */ var _math_flow_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./math-flow.js */ "./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/math-flow.js");
/* harmony import */ var _math_text_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./math-text.js */ "./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/math-text.js");
/**
* @typedef {import('micromark-util-types').Extension} Extension
* @typedef {import('./math-text.js').Options} Options
*/
/**
* Create an extension for `micromark` to enable math syntax.
*
* @param {Options | null | undefined} [options={}]
* Configuration (default: `{}`).
* @returns {Extension}
* Extension for `micromark` that can be passed in `extensions`, to
* enable math syntax.
*/
function math(options) {
return {
flow: {[micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.dollarSign]: _math_flow_js__WEBPACK_IMPORTED_MODULE_1__.mathFlow},
text: {[micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.dollarSign]: (0,_math_text_js__WEBPACK_IMPORTED_MODULE_2__.mathText)(options)}
}
}
/***/ }),
/***/ "./node_modules/.pnpm/micromark-factory-space@2.0.0/node_modules/micromark-factory-space/dev/index.js":
/*!************************************************************************************************************!*\
!*** ./node_modules/.pnpm/micromark-factory-space@2.0.0/node_modules/micromark-factory-space/dev/index.js ***!
\************************************************************************************************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ factorySpace: () => (/* binding */ factorySpace)
/* harmony export */ });
/* harmony import */ var micromark_util_character__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! micromark-util-character */ "./node_modules/.pnpm/micromark-util-character@2.0.1/node_modules/micromark-util-character/dev/index.js");
/**
* @typedef {import('micromark-util-types').Effects} Effects
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenType} TokenType
*/
// To do: implement `spaceOrTab`, `spaceOrTabMinMax`, `spaceOrTabWithOptions`.
/**
* Parse spaces and tabs.
*
* There is no `nok` parameter:
*
* * spaces in markdown are often optional, in which case this factory can be
* used and `ok` will be switched to whether spaces were found or not
* * one line ending or space can be detected with `markdownSpace(code)` right
* before using `factorySpace`
*
* ###### Examples
*
* Where `␉` represents a tab (plus how much it expands) and `␠` represents a
* single space.
*
* ```markdown
* ␉
* ␠␠␠␠
* ␉␠
* ```
*
* @param {Effects} effects
* Context.
* @param {State} ok
* State switched to when successful.
* @param {TokenType} type
* Type (`' \t'`).
* @param {number | undefined} [max=Infinity]
* Max (exclusive).
* @returns {State}
* Start state.
*/
function factorySpace(effects, ok, type, max) {
const limit = max ? max - 1 : Number.POSITIVE_INFINITY
let size = 0
return start
/** @type {State} */
function start(code) {
if ((0,micromark_util_character__WEBPACK_IMPORTED_MODULE_0__.markdownSpace)(code)) {
effects.enter(type)
return prefix(code)
}
return ok(code)
}
/** @type {State} */
function prefix(code) {
if ((0,micromark_util_character__WEBPACK_IMPORTED_MODULE_0__.markdownSpace)(code) && size++ < limit) {
effects.consume(code)
return prefix
}
effects.exit(type)
return ok(code)
}
}
/***/ }),
/***/ "./node_modules/.pnpm/micromark-util-character@2.0.1/node_modules/micromark-util-character/dev/index.js":
/*!**************************************************************************************************************!*\
!*** ./node_modules/.pnpm/micromark-util-character@2.0.1/node_modules/micromark-util-character/dev/index.js ***!
\**************************************************************************************************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ asciiAlpha: () => (/* binding */ asciiAlpha),
/* harmony export */ asciiAlphanumeric: () => (/* binding */ asciiAlphanumeric),
/* harmony export */ asciiAtext: () => (/* binding */ asciiAtext),
/* harmony export */ asciiControl: () => (/* binding */ asciiControl),
/* harmony export */ asciiDigit: () => (/* binding */ asciiDigit),
/* harmony export */ asciiHexDigit: () => (/* binding */ asciiHexDigit),
/* harmony export */ asciiPunctuation: () => (/* binding */ asciiPunctuation),
/* harmony export */ markdownLineEnding: () => (/* binding */ markdownLineEnding),
/* harmony export */ markdownLineEndingOrSpace: () => (/* binding */ markdownLineEndingOrSpace),
/* harmony export */ markdownSpace: () => (/* binding */ markdownSpace),
/* harmony export */ unicodePunctuation: () => (/* binding */ unicodePunctuation),
/* harmony export */ unicodeWhitespace: () => (/* binding */ unicodeWhitespace)
/* harmony export */ });
/* harmony import */ var micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! micromark-util-symbol */ "./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/codes.js");
/**
* @typedef {import('micromark-util-types').Code} Code
*/
const unicodePunctuationInternal = regexCheck(/\p{P}/u)
/**
* Check whether the character code represents an ASCII alpha (`a` through `z`,
* case insensitive).
*
* An **ASCII alpha** is an ASCII upper alpha or ASCII lower alpha.
*
* An **ASCII upper alpha** is a character in the inclusive range U+0041 (`A`)
* to U+005A (`Z`).
*
* An **ASCII lower alpha** is a character in the inclusive range U+0061 (`a`)
* to U+007A (`z`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
const asciiAlpha = regexCheck(/[A-Za-z]/)
/**
* Check whether the character code represents an ASCII alphanumeric (`a`
* through `z`, case insensitive, or `0` through `9`).
*
* An **ASCII alphanumeric** is an ASCII digit (see `asciiDigit`) or ASCII alpha
* (see `asciiAlpha`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
const asciiAlphanumeric = regexCheck(/[\dA-Za-z]/)
/**
* Check whether the character code represents an ASCII atext.
*
* atext is an ASCII alphanumeric (see `asciiAlphanumeric`), or a character in
* the inclusive ranges U+0023 NUMBER SIGN (`#`) to U+0027 APOSTROPHE (`'`),
* U+002A ASTERISK (`*`), U+002B PLUS SIGN (`+`), U+002D DASH (`-`), U+002F
* SLASH (`/`), U+003D EQUALS TO (`=`), U+003F QUESTION MARK (`?`), U+005E
* CARET (`^`) to U+0060 GRAVE ACCENT (`` ` ``), or U+007B LEFT CURLY BRACE
* (`{`) to U+007E TILDE (`~`).
*
* See:
* **\[RFC5322]**:
* [Internet Message Format](https://tools.ietf.org/html/rfc5322).
* P. Resnick.
* IETF.
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
const asciiAtext = regexCheck(/[#-'*+\--9=?A-Z^-~]/)
/**
* Check whether a character code is an ASCII control character.
*
* An **ASCII control** is a character in the inclusive range U+0000 NULL (NUL)
* to U+001F (US), or U+007F (DEL).
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
function asciiControl(code) {
return (
// Special whitespace codes (which have negative values), C0 and Control
// character DEL
code !== null && (code < micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.space || code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.del)
)
}
/**
* Check whether the character code represents an ASCII digit (`0` through `9`).
*
* An **ASCII digit** is a character in the inclusive range U+0030 (`0`) to
* U+0039 (`9`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
const asciiDigit = regexCheck(/\d/)
/**
* Check whether the character code represents an ASCII hex digit (`a` through
* `f`, case insensitive, or `0` through `9`).
*
* An **ASCII hex digit** is an ASCII digit (see `asciiDigit`), ASCII upper hex
* digit, or an ASCII lower hex digit.
*
* An **ASCII upper hex digit** is a character in the inclusive range U+0041
* (`A`) to U+0046 (`F`).
*
* An **ASCII lower hex digit** is a character in the inclusive range U+0061
* (`a`) to U+0066 (`f`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
const asciiHexDigit = regexCheck(/[\dA-Fa-f]/)
/**
* Check whether the character code represents ASCII punctuation.
*
* An **ASCII punctuation** is a character in the inclusive ranges U+0021
* EXCLAMATION MARK (`!`) to U+002F SLASH (`/`), U+003A COLON (`:`) to U+0040 AT
* SIGN (`@`), U+005B LEFT SQUARE BRACKET (`[`) to U+0060 GRAVE ACCENT
* (`` ` ``), or U+007B LEFT CURLY BRACE (`{`) to U+007E TILDE (`~`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
const asciiPunctuation = regexCheck(/[!-/:-@[-`{-~]/)
/**
* Check whether a character code is a markdown line ending.
*
* A **markdown line ending** is the virtual characters M-0003 CARRIAGE RETURN
* LINE FEED (CRLF), M-0004 LINE FEED (LF) and M-0005 CARRIAGE RETURN (CR).
*
* In micromark, the actual character U+000A LINE FEED (LF) and U+000D CARRIAGE
* RETURN (CR) are replaced by these virtual characters depending on whether
* they occurred together.
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
function markdownLineEnding(code) {
return code !== null && code < micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.horizontalTab
}
/**
* Check whether a character code is a markdown line ending (see
* `markdownLineEnding`) or markdown space (see `markdownSpace`).
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
function markdownLineEndingOrSpace(code) {
return code !== null && (code < micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.nul || code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.space)
}
/**
* Check whether a character code is a markdown space.
*
* A **markdown space** is the concrete character U+0020 SPACE (SP) and the
* virtual characters M-0001 VIRTUAL SPACE (VS) and M-0002 HORIZONTAL TAB (HT).
*
* In micromark, the actual character U+0009 CHARACTER TABULATION (HT) is
* replaced by one M-0002 HORIZONTAL TAB (HT) and between 0 and 3 M-0001 VIRTUAL
* SPACE (VS) characters, depending on the column at which the tab occurred.
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
function markdownSpace(code) {
return (
code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.horizontalTab ||
code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.virtualSpace ||
code === micromark_util_symbol__WEBPACK_IMPORTED_MODULE_0__.codes.space
)
}
// Size note: removing ASCII from the regex and using `asciiPunctuation` here
// In fact adds to the bundle size.
/**
* Check whether the character code represents Unicode punctuation.
*
* A **Unicode punctuation** is a character in the Unicode `Pc` (Punctuation,
* Connector), `Pd` (Punctuation, Dash), `Pe` (Punctuation, Close), `Pf`
* (Punctuation, Final quote), `Pi` (Punctuation, Initial quote), `Po`
* (Punctuation, Other), or `Ps` (Punctuation, Open) categories, or an ASCII
* punctuation (see `asciiPunctuation`).
*
* See:
* **\[UNICODE]**:
* [The Unicode Standard](https://www.unicode.org/versions/).
* Unicode Consortium.
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
function unicodePunctuation(code) {
return asciiPunctuation(code) || unicodePunctuationInternal(code)
}
/**
* Check whether the character code represents Unicode whitespace.
*
* Note that this does handle micromark specific markdown whitespace characters.
* See `markdownLineEndingOrSpace` to check that.
*
* A **Unicode whitespace** is a character in the Unicode `Zs` (Separator,
* Space) category, or U+0009 CHARACTER TABULATION (HT), U+000A LINE FEED (LF),
* U+000C (FF), or U+000D CARRIAGE RETURN (CR) (**\[UNICODE]**).
*
* See:
* **\[UNICODE]**:
* [The Unicode Standard](https://www.unicode.org/versions/).
* Unicode Consortium.
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
const unicodeWhitespace = regexCheck(/\s/)
/**
* Create a code check from a regex.
*
* @param {RegExp} regex
* @returns {(code: Code) => boolean}
*/
function regexCheck(regex) {
return check
/**
* Check whether a code matches the bound regex.
*
* @param {Code} code
* Character code.
* @returns {boolean}
* Whether the character code matches the bound regex.
*/
function check(code) {
return code !== null && code > -1 && regex.test(String.fromCharCode(code))
}
}
/***/ }),
/***/ "./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/codes.js":
/*!********************************************************************************************************!*\
!*** ./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/codes.js ***!
\********************************************************************************************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ codes: () => (/* binding */ codes)
/* harmony export */ });
/**
* Character codes.
*
* This module is compiled away!
*
* micromark works based on character codes.
* This module contains constants for the ASCII block and the replacement
* character.
* A couple of them are handled in a special way, such as the line endings
* (CR, LF, and CR+LF, commonly known as end-of-line: EOLs), the tab (horizontal
* tab) and its expansion based on what column it’s at (virtual space),
* and the end-of-file (eof) character.
* As values are preprocessed before handling them, the actual characters LF,
* CR, HT, and NUL (which is present as the replacement character), are
* guaranteed to not exist.
*
* Unicode basic latin block.
*/
const codes = /** @type {const} */ ({
carriageReturn: -5,
lineFeed: -4,
carriageReturnLineFeed: -3,
horizontalTab: -2,
virtualSpace: -1,
eof: null,
nul: 0,
soh: 1,
stx: 2,
etx: 3,
eot: 4,
enq: 5,
ack: 6,
bel: 7,
bs: 8,
ht: 9, // `\t`
lf: 10, // `\n`
vt: 11, // `\v`
ff: 12, // `\f`
cr: 13, // `\r`
so: 14,
si: 15,
dle: 16,
dc1: 17,
dc2: 18,
dc3: 19,
dc4: 20,
nak: 21,
syn: 22,
etb: 23,
can: 24,
em: 25,
sub: 26,
esc: 27,
fs: 28,
gs: 29,
rs: 30,
us: 31,
space: 32,
exclamationMark: 33, // `!`
quotationMark: 34, // `"`
numberSign: 35, // `#`
dollarSign: 36, // `$`
percentSign: 37, // `%`
ampersand: 38, // `&`
apostrophe: 39, // `'`
leftParenthesis: 40, // `(`
rightParenthesis: 41, // `)`
asterisk: 42, // `*`
plusSign: 43, // `+`
comma: 44, // `,`
dash: 45, // `-`
dot: 46, // `.`
slash: 47, // `/`
digit0: 48, // `0`
digit1: 49, // `1`
digit2: 50, // `2`
digit3: 51, // `3`
digit4: 52, // `4`
digit5: 53, // `5`
digit6: 54, // `6`
digit7: 55, // `7`
digit8: 56, // `8`
digit9: 57, // `9`
colon: 58, // `:`
semicolon: 59, // `;`
lessThan: 60, // `<`
equalsTo: 61, // `=`
greaterThan: 62, // `>`
questionMark: 63, // `?`
atSign: 64, // `@`
uppercaseA: 65, // `A`
uppercaseB: 66, // `B`
uppercaseC: 67, // `C`
uppercaseD: 68, // `D`
uppercaseE: 69, // `E`
uppercaseF: 70, // `F`
uppercaseG: 71, // `G`
uppercaseH: 72, // `H`
uppercaseI: 73, // `I`
uppercaseJ: 74, // `J`
uppercaseK: 75, // `K`
uppercaseL: 76, // `L`
uppercaseM: 77, // `M`
uppercaseN: 78, // `N`
uppercaseO: 79, // `O`
uppercaseP: 80, // `P`
uppercaseQ: 81, // `Q`
uppercaseR: 82, // `R`
uppercaseS: 83, // `S`
uppercaseT: 84, // `T`
uppercaseU: 85, // `U`
uppercaseV: 86, // `V`
uppercaseW: 87, // `W`
uppercaseX: 88, // `X`
uppercaseY: 89, // `Y`
uppercaseZ: 90, // `Z`
leftSquareBracket: 91, // `[`
backslash: 92, // `\`
rightSquareBracket: 93, // `]`
caret: 94, // `^`
underscore: 95, // `_`
graveAccent: 96, // `` ` ``
lowercaseA: 97, // `a`
lowercaseB: 98, // `b`
lowercaseC: 99, // `c`
lowercaseD: 100, // `d`
lowercaseE: 101, // `e`
lowercaseF: 102, // `f`
lowercaseG: 103, // `g`
lowercaseH: 104, // `h`
lowercaseI: 105, // `i`
lowercaseJ: 106, // `j`
lowercaseK: 107, // `k`
lowercaseL: 108, // `l`
lowercaseM: 109, // `m`
lowercaseN: 110, // `n`
lowercaseO: 111, // `o`
lowercaseP: 112, // `p`
lowercaseQ: 113, // `q`
lowercaseR: 114, // `r`
lowercaseS: 115, // `s`
lowercaseT: 116, // `t`
lowercaseU: 117, // `u`
lowercaseV: 118, // `v`
lowercaseW: 119, // `w`
lowercaseX: 120, // `x`
lowercaseY: 121, // `y`
lowercaseZ: 122, // `z`
leftCurlyBrace: 123, // `{`
verticalBar: 124, // `|`
rightCurlyBrace: 125, // `}`
tilde: 126, // `~`
del: 127,
// Unicode Specials block.
byteOrderMarker: 65279,
// Unicode Specials block.
replacementCharacter: 65533 // `�`
})
/***/ }),
/***/ "./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/constants.js":
/*!************************************************************************************************************!*\
!*** ./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/constants.js ***!
\************************************************************************************************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ constants: () => (/* binding */ constants)
/* harmony export */ });
/**
* This module is compiled away!
*
* Parsing markdown comes with a couple of constants, such as minimum or maximum
* sizes of certain sequences.
* Additionally, there are a couple symbols used inside micromark.
* These are all defined here, but compiled away by scripts.
*/
const constants = /** @type {const} */ ({
attentionSideBefore: 1, // Symbol to mark an attention sequence as before content: `*a`
attentionSideAfter: 2, // Symbol to mark an attention sequence as after content: `a*`
atxHeadingOpeningFenceSizeMax: 6, // 6 number signs is fine, 7 isn’t.
autolinkDomainSizeMax: 63, // 63 characters is fine, 64 is too many.
autolinkSchemeSizeMax: 32, // 32 characters is fine, 33 is too many.
cdataOpeningString: 'CDATA[', // And preceded by `<![`.
characterGroupWhitespace: 1, // Symbol used to indicate a character is whitespace
characterGroupPunctuation: 2, // Symbol used to indicate a character is punctuation
characterReferenceDecimalSizeMax: 7, // `�`.
characterReferenceHexadecimalSizeMax: 6, // `�`.
characterReferenceNamedSizeMax: 31, // `∳`.
codeFencedSequenceSizeMin: 3, // At least 3 ticks or tildes are needed.
contentTypeDocument: 'document',
contentTypeFlow: 'flow',
contentTypeContent: 'content',
contentTypeString: 'string',
contentTypeText: 'text',
hardBreakPrefixSizeMin: 2, // At least 2 trailing spaces are needed.
htmlRaw: 1, // Symbol for `<script>`
htmlComment: 2, // Symbol for `<!---->`
htmlInstruction: 3, // Symbol for `<?php?>`
htmlDeclaration: 4, // Symbol for `<!doctype>`
htmlCdata: 5, // Symbol for `<![CDATA[]]>`
htmlBasic: 6, // Symbol for `<div`
htmlComplete: 7, // Symbol for `<x>`
htmlRawSizeMax: 8, // Length of `textarea`.
linkResourceDestinationBalanceMax: 32, // See: <https://spec.commonmark.org/0.30/#link-destination>, <https://github.com/remarkjs/react-markdown/issues/658#issuecomment-984345577>
linkReferenceSizeMax: 999, // See: <https://spec.commonmark.org/0.30/#link-label>
listItemValueSizeMax: 10, // See: <https://spec.commonmark.org/0.30/#ordered-list-marker>
numericBaseDecimal: 10,
numericBaseHexadecimal: 0x10,
tabSize: 4, // Tabs have a hard-coded size of 4, per CommonMark.
thematicBreakMarkerCountMin: 3, // At least 3 asterisks, dashes, or underscores are needed.
v8MaxSafeChunkSize: 10000 // V8 (and potentially others) have problems injecting giant arrays into other arrays, hence we operate in chunks.
})
/***/ }),
/***/ "./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/types.js":
/*!********************************************************************************************************!*\
!*** ./node_modules/.pnpm/micromark-util-symbol@2.0.0/node_modules/micromark-util-symbol/lib/types.js ***!
\********************************************************************************************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ types: () => (/* binding */ types)
/* harmony export */ });
/**
* This module is compiled away!
*
* Here is the list of all types of tokens exposed by micromark, with a short
* explanation of what they include and where they are found.
* In picking names, generally, the rule is to be as explicit as possible
* instead of reusing names.
* For example, there is a `definitionDestination` and a `resourceDestination`,
* instead of one shared name.
*/
// Note: when changing the next record, you must also change `TokenTypeMap`
// in `micromark-util-types/index.d.ts`.
const types = /** @type {const} */ ({
// Generic type for data, such as in a title, a destination, etc.
data: 'data',
// Generic type for syntactic whitespace (tabs, virtual spaces, spaces).
// Such as, between a fenced code fence and an info string.
whitespace: 'whitespace',
// Generic type for line endings (line feed, carriage return, carriage return +
// line feed).
lineEnding: 'lineEnding',
// A line ending, but ending a blank line.
lineEndingBlank: 'lineEndingBlank',
// Generic type for whitespace (tabs, virtual spaces, spaces) at the start of a
// line.
linePrefix: 'linePrefix',
// Generic type for whitespace (tabs, virtual spaces, spaces) at the end of a
// line.
lineSuffix: 'lineSuffix',
// Whole ATX heading:
//
// ```markdown
// #
// ## Alpha
// ### Bravo ###
// ```
//
// Includes `atxHeadingSequence`, `whitespace`, `atxHeadingText`.
atxHeading: 'atxHeading',
// Sequence of number signs in an ATX heading (`###`).
atxHeadingSequence: 'atxHeadingSequence',
// Content in an ATX heading (`alpha`).
// Includes text.
atxHeadingText: 'atxHeadingText',
// Whole autolink (`<https://example.com>` or `<admin@example.com>`)
// Includes `autolinkMarker` and `autolinkProtocol` or `autolinkEmail`.
autolink: 'autolink',
// Email autolink w/o markers (`admin@example.com`)
autolinkEmail: 'autolinkEmail',
// Marker around an `autolinkProtocol` or `autolinkEmail` (`<` or `>`).
autolinkMarker: 'autolinkMarker',
// Protocol autolink w/o markers (`https://example.com`)
autolinkProtocol: 'autolinkProtocol',
// A whole character escape (`\-`).
// Includes `escapeMarker` and `characterEscapeValue`.
characterEscape: 'characterEscape',
// The escaped character (`-`).
characterEscapeValue: 'characterEscapeValue',
// A whole character reference (`&`, `≠`, or `𝌆`).
// Includes `characterReferenceMarker`, an optional
// `characterReferenceMarkerNumeric`, in which case an optional
// `characterReferenceMarkerHexadecimal`, and a `characterReferenceValue`.
characterReference: 'characterReference',
// The start or end marker (`&` or `;`).
characterReferenceMarker: 'characterReferenceMarker',
// Mark reference as numeric (`#`).
characterReferenceMarkerNumeric: 'characterReferenceMarkerNumeric',
// Mark reference as numeric (`x` or `X`).
characterReferenceMarkerHexadecimal: 'characterReferenceMarkerHexadecimal',
// Value of character reference w/o markers (`amp`, `8800`, or `1D306`).
characterReferenceValue: 'characterReferenceValue',
// Whole fenced code:
//
// ````markdown
// ```js
// alert(1)
// ```
// ````
codeFenced: 'codeFenced',
// A fenced code fence, including whitespace, sequence, info, and meta
// (` ```js `).
codeFencedFence: 'codeFencedFence',
// Sequence of grave accent or tilde characters (` ``` `) in a fence.
codeFencedFenceSequence: 'codeFencedFenceSequence',
// Info word (`js`) in a fence.
// Includes string.
codeFencedFenceInfo: 'codeFencedFenceInfo',
// Meta words (`highlight="1"`) in a fence.
// Includes string.
codeFencedFenceMeta: 'codeFencedFenceMeta',
// A line of code.
codeFlowValue: 'codeFlowValue',
// Whole indented code:
//
// ```markdown
// alert(1)
// ```
//
// Includes `lineEnding`, `linePrefix`, and `codeFlowValue`.
codeIndented: 'codeIndented',
// A text code (``` `alpha` ```).
// Includes `codeTextSequence`, `codeTextData`, `lineEnding`, and can include
// `codeTextPadding`.
codeText: 'codeText',
codeTextData: 'codeTextData',
// A space or line ending right after or before a tick.
codeTextPadding: 'codeTextPadding',
// A text code fence (` `` `).
codeTextSequence: 'codeTextSequence',
// Whole content:
//
// ```markdown
// [a]: b
// c
// =
// d
// ```
//
// Includes `paragraph` and `definition`.
content: 'content',
// Whole definition:
//
// ```markdown
// [micromark]: https://github.com/micromark/micromark
// ```
//
// Includes `definitionLabel`, `definitionMarker`, `whitespace`,
// `definitionDestination`, and optionally `lineEnding` and `definitionTitle`.
definition: 'definition',
// Destination of a definition (`https://github.com/micromark/micromark` or
// `<https://github.com/micromark/micromark>`).
// Includes `definitionDestinationLiteral` or `definitionDestinationRaw`.
definitionDestination: 'definitionDestination',
// Enclosed destination of a definition
// (`<https://github.com/micromark/micromark>`).
// Includes `definitionDestinationLiteralMarker` and optionally
// `definitionDestinationString`.
definitionDestinationLiteral: 'definitionDestinationLiteral',
// Markers of an enclosed definition destination (`<` or `>`).
definitionDestinationLiteralMarker: 'definitionDestinationLiteralMarker',
// Unenclosed destination of a definition
// (`https://github.com/micromark/micromark`).
// Includes `definitionDestinationString`.
definitionDestinationRaw: 'definitionDestinationRaw',
// Text in an destination (`https://github.com/micromark/micromark`).
// Includes string.
definitionDestinationString: 'definitionDestinationString',
// Label of a definition (`[micromark]`).
// Includes `definitionLabelMarker` and `definitionLabelString`.
definitionLabel: 'definitionLabel',
// Markers of a definition label (`[` or `]`).
definitionLabelMarker: 'definitionLabelMarker',
// Value of a definition label (`micromark`).
// Includes string.
definitionLabelString: 'definitionLabelString',
// Marker between a label and a destination (`:`).
definitionMarker: 'definitionMarker',
// Title of a definition (`"x"`, `'y'`, or `(z)`).
// Includes `definitionTitleMarker` and optionally `definitionTitleString`.
definitionTitle: 'definitionTitle',
// Marker around a title of a definition (`"`, `'`, `(`, or `)`).
definitionTitleMarker: 'definitionTitleMarker',
// Data without markers in a title (`z`).
// Includes string.
definitionTitleString: 'definitionTitleString',
// Emphasis (`*alpha*`).
// Includes `emphasisSequence` and `emphasisText`.
emphasis: 'emphasis',
// Sequence of emphasis markers (`*` or `_`).
emphasisSequence: 'emphasisSequence',
// Emphasis text (`alpha`).
// Includes text.
emphasisText: 'emphasisText',
// The character escape marker (`\`).
escapeMarker: 'escapeMarker',
// A hard break created with a backslash (`\\n`).
// Note: does not include the line ending.
hardBreakEscape: 'hardBreakEscape',
// A hard break created with trailing spaces (` \n`).
// Does not include the line ending.
hardBreakTrailing: 'hardBreakTrailing',
// Flow HTML:
//
// ```markdown
// <div
// ```
//
// Inlcudes `lineEnding`, `htmlFlowData`.
htmlFlow: 'htmlFlow',
htmlFlowData: 'htmlFlowData',
// HTML in text (the tag in `a <i> b`).
// Includes `lineEnding`, `htmlTextData`.
htmlText: 'htmlText',
htmlTextData: 'htmlTextData',
// Whole image (``, `![alpha][bravo]`, `![alpha][]`, or
// `![alpha]`).
// Includes `label` and an optional `resource` or `reference`.
image: 'image',
// Whole link label (`[*alpha*]`).
// Includes `labelLink` or `labelImage`, `labelText`, and `labelEnd`.
label: 'label',
// Text in an label (`*alpha*`).
// Includes text.
labelText: 'labelText',
// Start a link label (`[`).
// Includes a `labelMarker`.
labelLink: 'labelLink',
// Start an image label (`![`).
// Includes `labelImageMarker` and `labelMarker`.
labelImage: 'labelImage',
// Marker of a label (`[` or `]`).
labelMarker: 'labelMarker',
// Marker to start an image (`!`).
labelImageMarker: 'labelImageMarker',
// End a label (`]`).
// Includes `labelMarker`.
labelEnd: 'labelEnd',
// Whole link (`[alpha](bravo)`, `[alpha][bravo]`, `[alpha][]`, or `[alpha]`).
// Includes `label` and an optional `resource` or `reference`.
link: 'link',
// Whole paragraph:
//
// ```markdown
// alpha
// bravo.
// ```
//
// Includes text.
paragraph: 'paragraph',
// A reference (`[alpha]` or `[]`).
// Includes `referenceMarker` and an optional `referenceString`.
reference: 'reference',
// A reference marker (`[` or `]`).
referenceMarker: 'referenceMarker',
// Reference text (`alpha`).
// Includes string.
referenceString: 'referenceString',
// A resource (`(https://example.com "alpha")`).
// Includes `resourceMarker`, an optional `resourceDestination` with an optional
// `whitespace` and `resourceTitle`.
resource: 'resource',
// A resource destination (`https://example.com`).
// Includes `resourceDestinationLiteral` or `resourceDestinationRaw`.
resourceDestination: 'resourceDestination',
// A literal resource destination (`<https://example.com>`).
// Includes `resourceDestinationLiteralMarker` and optionally
// `resourceDestinationString`.
resourceDestinationLiteral: 'resourceDestinationLiteral',
// A resource destination marker (`<` or `>`).
resourceDestinationLiteralMarker: 'resourceDestinationLiteralMarker',
// A raw resource destination (`https://example.com`).
// Includes `resourceDestinationString`.
resourceDestinationRaw: 'resourceDestinationRaw',
// Resource destination text (`https://example.com`).
// Includes string.
resourceDestinationString: 'resourceDestinationString',
// A resource marker (`(` or `)`).
resourceMarker: 'resourceMarker',
// A resource title (`"alpha"`, `'alpha'`, or `(alpha)`).
// Includes `resourceTitleMarker` and optionally `resourceTitleString`.
resourceTitle: 'resourceTitle',
// A resource title marker (`"`, `'`, `(`, or `)`).
resourceTitleMarker: 'resourceTitleMarker',
// Resource destination title (`alpha`).
// Includes string.
resourceTitleString: 'resourceTitleString',
// Whole setext heading:
//
// ```markdown
// alpha
// bravo
// =====
// ```
//
// Includes `setextHeadingText`, `lineEnding`, `linePrefix`, and
// `setextHeadingLine`.
setextHeading: 'setextHeading',
// Content in a setext heading (`alpha\nbravo`).
// Includes text.
setextHeadingText: 'setextHeadingText',
// Underline in a setext heading, including whitespace suffix (`==`).
// Includes `setextHeadingLineSequence`.
setextHeadingLine: 'setextHeadingLine',
// Sequence of equals or dash characters in underline in a setext heading (`-`).
setextHeadingLineSequence: 'setextHeadingLineSequence',
// Strong (`**alpha**`).
// Includes `strongSequence` and `strongText`.
strong: 'strong',
// Sequence of strong markers (`**` or `__`).
strongSequence: 'strongSequence',
// Strong text (`alpha`).
// Includes text.
strongText: 'strongText',
// Whole thematic break:
//
// ```markdown
// * * *
// ```
//
// Includes `thematicBreakSequence` and `whitespace`.
thematicBreak: 'thematicBreak',
// A sequence of one or more thematic break markers (`***`).
thematicBreakSequence: 'thematicBreakSequence',
// Whole block quote:
//
// ```markdown
// > a
// >
// > b
// ```
//
// Includes `blockQuotePrefix` and flow.
blockQuote: 'blockQuote',
// The `>` or `> ` of a block quote.
blockQuotePrefix: 'blockQuotePrefix',
// The `>` of a block quote prefix.
blockQuoteMarker: 'blockQuoteMarker',
// The optional ` ` of a block quote prefix.
blockQuotePrefixWhitespace: 'blockQuotePrefixWhitespace',
// Whole unordered list:
//
// ```markdown
// - a
// b
// ```
//
// Includes `listItemPrefix`, flow, and optionally `listItemIndent` on further
// lines.
listOrdered: 'listOrdered',
// Whole ordered list:
//
// ```markdown
// 1. a
// b
// ```
//
// Includes `listItemPrefix`, flow, and optionally `listItemIndent` on further
// lines.
listUnordered: 'listUnordered',
// The indent of further list item lines.
listItemIndent: 'listItemIndent',
// A marker, as in, `*`, `+`, `-`, `.`, or `)`.
listItemMarker: 'listItemMarker',
// The thing that starts a list item, such as `1. `.
// Includes `listItemValue` if ordered, `listItemMarker`, and
// `listItemPrefixWhitespace` (unless followed by a line ending).
listItemPrefix: 'listItemPrefix',
// The whitespace after a marker.
listItemPrefixWhitespace: 'listItemPrefixWhitespace',
// The numerical value of an ordered item.
listItemValue: 'listItemValue',
// Internal types used for subtokenizers, compiled away
chunkDocument: 'chunkDocument',
chunkContent: 'chunkContent',
chunkFlow: 'chunkFlow',
chunkText: 'chunkText',
chunkString: 'chunkString'
})
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = __webpack_modules__;
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/ensure chunk */
/******/ (() => {
/******/ __webpack_require__.f = {};
/******/ // This file contains only the entry chunk.
/******/ // The chunk loading function for additional chunks
/******/ __webpack_require__.e = (chunkId) => {
/******/ return Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key) => {
/******/ __webpack_require__.f[key](chunkId, promises);
/******/ return promises;
/******/ }, []));
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/get css chunk filename */
/******/ (() => {
/******/ // This function allow to reference async chunks
/******/ __webpack_require__.k = (chunkId) => {
/******/ // return url for filenames based on template
/******/ return "" + chunkId + ".css";
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/get javascript chunk filename */
/******/ (() => {
/******/ // This function allow to reference async chunks
/******/ __webpack_require__.u = (chunkId) => {
/******/ // return url for filenames based on template
/******/ return "" + chunkId + ".js";
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/global */
/******/ (() => {
/******/ __webpack_require__.g = (function() {
/******/ if (typeof globalThis === 'object') return globalThis;
/******/ try {
/******/ return this || new Function('return this')();
/******/ } catch (e) {
/******/ if (typeof window === 'object') return window;
/******/ }
/******/ })();
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/load script */
/******/ (() => {
/******/ var inProgress = {};
/******/ var dataWebpackPrefix = "rspack-repro:";
/******/ // loadScript function to load a script via script tag
/******/ __webpack_require__.l = (url, done, key, chunkId) => {
/******/ if(inProgress[url]) { inProgress[url].push(done); return; }
/******/ var script, needAttach;
/******/ if(key !== undefined) {
/******/ var scripts = document.getElementsByTagName("script");
/******/ for(var i = 0; i < scripts.length; i++) {
/******/ var s = scripts[i];
/******/ if(s.getAttribute("src") == url || s.getAttribute("data-webpack") == dataWebpackPrefix + key) { script = s; break; }
/******/ }
/******/ }
/******/ if(!script) {
/******/ needAttach = true;
/******/ script = document.createElement('script');
/******/
/******/ script.charset = 'utf-8';
/******/ script.timeout = 120;
/******/ if (__webpack_require__.nc) {
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/ script.setAttribute("data-webpack", dataWebpackPrefix + key);
/******/
/******/ script.src = url;
/******/ }
/******/ inProgress[url] = [done];
/******/ var onScriptComplete = (prev, event) => {
/******/ // avoid mem leaks in IE.
/******/ script.onerror = script.onload = null;
/******/ clearTimeout(timeout);
/******/ var doneFns = inProgress[url];
/******/ delete inProgress[url];
/******/ script.parentNode && script.parentNode.removeChild(script);
/******/ doneFns && doneFns.forEach((fn) => (fn(event)));
/******/ if(prev) return prev(event);
/******/ }
/******/ var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), 120000);
/******/ script.onerror = onScriptComplete.bind(null, script.onerror);
/******/ script.onload = onScriptComplete.bind(null, script.onload);
/******/ needAttach && document.head.appendChild(script);
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/publicPath */
/******/ (() => {
/******/ var scriptUrl;
/******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
/******/ var document = __webpack_require__.g.document;
/******/ if (!scriptUrl && document) {
/******/ if (document.currentScript)
/******/ scriptUrl = document.currentScript.src;
/******/ if (!scriptUrl) {
/******/ var scripts = document.getElementsByTagName("script");
/******/ if(scripts.length) {
/******/ var i = scripts.length - 1;
/******/ while (i > -1 && !scriptUrl) scriptUrl = scripts[i--].src;
/******/ }
/******/ }
/******/ }
/******/ // When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration
/******/ // or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.
/******/ if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");
/******/ scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
/******/ __webpack_require__.p = scriptUrl;
/******/ })();
/******/
/******/ /* webpack/runtime/jsonp chunk loading */
/******/ (() => {
/******/ // no baseURI
/******/
/******/ // object to store loaded and loading chunks
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
/******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
/******/ var installedChunks = {
/******/ "main": 0
/******/ };
/******/
/******/ __webpack_require__.f.j = (chunkId, promises) => {
/******/ // JSONP chunk loading for javascript
/******/ var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;
/******/ if(installedChunkData !== 0) { // 0 means "already installed".
/******/
/******/ // a Promise means "currently loading".
/******/ if(installedChunkData) {
/******/ promises.push(installedChunkData[2]);
/******/ } else {
/******/ if(true) { // all chunks have JS
/******/ // setup Promise in chunk cache
/******/ var promise = new Promise((resolve, reject) => (installedChunkData = installedChunks[chunkId] = [resolve, reject]));
/******/ promises.push(installedChunkData[2] = promise);
/******/
/******/ // start chunk loading
/******/ var url = __webpack_require__.p + __webpack_require__.u(chunkId);
/******/ // create error before stack unwound to get useful stacktrace later
/******/ var error = new Error();
/******/ var loadingEnded = (event) => {
/******/ if(__webpack_require__.o(installedChunks, chunkId)) {
/******/ installedChunkData = installedChunks[chunkId];
/******/ if(installedChunkData !== 0) installedChunks[chunkId] = undefined;
/******/ if(installedChunkData) {
/******/ var errorType = event && (event.type === 'load' ? 'missing' : event.type);
/******/ var realSrc = event && event.target && event.target.src;
/******/ error.message = 'Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')';
/******/ error.name = 'ChunkLoadError';
/******/ error.type = errorType;
/******/ error.request = realSrc;
/******/ installedChunkData[1](error);
/******/ }
/******/ }
/******/ };
/******/ __webpack_require__.l(url, loadingEnded, "chunk-" + chunkId, chunkId);
/******/ }
/******/ }
/******/ }
/******/ };
/******/
/******/ // no prefetching
/******/
/******/ // no preloaded
/******/
/******/ // no HMR
/******/
/******/ // no HMR manifest
/******/
/******/ // no on chunks loaded
/******/
/******/ // install a JSONP callback for chunk loading
/******/ var webpackJsonpCallback = (parentChunkLoadingFunction, data) => {
/******/ var [chunkIds, moreModules, runtime] = data;
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0;
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(runtime) var result = runtime(__webpack_require__);
/******/ }
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
/******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {
/******/ installedChunks[chunkId][0]();
/******/ }
/******/ installedChunks[chunkId] = 0;
/******/ }
/******/
/******/ }
/******/
/******/ var chunkLoadingGlobal = self["webpackChunkrspack_repro"] = self["webpackChunkrspack_repro"] || [];
/******/ chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));
/******/ chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));
/******/ })();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
/*!**********************!*\
!*** ./src/index.js ***!
\**********************/
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var micromark_extension_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! micromark-extension-math */ "./node_modules/.pnpm/micromark-extension-math@3.0.0/node_modules/micromark-extension-math/dev/lib/syntax.js");
console.log(micromark_extension_math__WEBPACK_IMPORTED_MODULE_0__.math);
__webpack_require__.e(/*! import() */ "vendors-node_modules_pnpm_katex_0_16_9_node_modules_katex_dist_katex_mjs").then(__webpack_require__.bind(__webpack_require__, /*! katex */ "./node_modules/.pnpm/katex@0.16.9/node_modules/katex/dist/katex.mjs")).then((katex) => {
console.log(katex);
});
})();
/******/ })()
;
|
07akioni/rspack-treeshaking-issue-reprod
| 0
|
JavaScript
|
07akioni
|
07akioni
|
DeepSeek
|
|
webpack-dist/vendors-node_modules_pnpm_katex_0_16_9_node_modules_katex_dist_katex_mjs.js
|
JavaScript
|
"use strict";
(self["webpackChunkrspack_repro"] = self["webpackChunkrspack_repro"] || []).push([["vendors-node_modules_pnpm_katex_0_16_9_node_modules_katex_dist_katex_mjs"],{
/***/ "./node_modules/.pnpm/katex@0.16.9/node_modules/katex/dist/katex.mjs":
/*!***************************************************************************!*\
!*** ./node_modules/.pnpm/katex@0.16.9/node_modules/katex/dist/katex.mjs ***!
\***************************************************************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (/* binding */ katex)
/* harmony export */ });
/**
* Lexing or parsing positional information for error reporting.
* This object is immutable.
*/
class SourceLocation {
// The + prefix indicates that these fields aren't writeable
// Lexer holding the input string.
// Start offset, zero-based inclusive.
// End offset, zero-based exclusive.
constructor(lexer, start, end) {
this.lexer = void 0;
this.start = void 0;
this.end = void 0;
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, second) {
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);
}
}
}
/**
* Interface required to break circular dependency between Token, Lexer, and
* ParseError.
*/
/**
* 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.
*/
class Token {
// don't expand the token
// used in \noexpand
constructor(text, // the text of this token
loc) {
this.text = void 0;
this.loc = void 0;
this.noexpand = void 0;
this.treatAsRelax = void 0;
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, // last token of the range, inclusive
text // the text of the newly constructed token
) {
return new Token(text, SourceLocation.range(this, endToken));
}
}
/**
* 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 {
// Error start position based on passed-in Token or ParseNode.
// Length of affected text based on passed-in Token or ParseNode.
// The underlying error message without any context added.
constructor(message, // The error message
token // An object providing position information
) {
this.name = void 0;
this.position = void 0;
this.length = void 0;
this.rawMessage = void 0;
var error = "KaTeX parse error: " + message;
var start;
var end;
var 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
var 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
var underlined = input.slice(start, end).replace(/[^]/g, "$&\u0332"); // Extract some context from the input and add it to the error
var left;
if (start > 15) {
left = "…" + input.slice(start - 15, start);
} else {
left = input.slice(0, start);
}
var 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
var self = 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;
/**
* This file contains a list of utility functions which are useful in other
* files.
*/
/**
* Return whether an element is contained in a list
*/
var contains = function contains(list, elem) {
return list.indexOf(elem) !== -1;
};
/**
* Provide a default value if a setting is undefined
* NOTE: Couldn't use `T` as the output type due to facebook/flow#5022.
*/
var deflt = function deflt(setting, defaultIfUndefined) {
return setting === undefined ? defaultIfUndefined : setting;
}; // hyphenate and escape adapted from Facebook's React under Apache 2 license
var uppercase = /([A-Z])/g;
var hyphenate = function hyphenate(str) {
return str.replace(uppercase, "-$1").toLowerCase();
};
var ESCAPE_LOOKUP = {
"&": "&",
">": ">",
"<": "<",
"\"": """,
"'": "'"
};
var ESCAPE_REGEX = /[&><"']/g;
/**
* Escapes text to prevent scripting attacks.
*/
function escape(text) {
return String(text).replace(ESCAPE_REGEX, match => ESCAPE_LOOKUP[match]);
}
/**
* Sometimes we want to pull out the innermost element of a group. In most
* cases, this will just be the group itself, but when ordgroups and colors have
* a single element, we want to pull that out.
*/
var getBaseElem = function getBaseElem(group) {
if (group.type === "ordgroup") {
if (group.body.length === 1) {
return getBaseElem(group.body[0]);
} else {
return group;
}
} else if (group.type === "color") {
if (group.body.length === 1) {
return getBaseElem(group.body[0]);
} else {
return group;
}
} else if (group.type === "font") {
return getBaseElem(group.body);
} else {
return group;
}
};
/**
* TeXbook algorithms often reference "character boxes", which are simply groups
* with a single character in them. To decide if something is a character box,
* we find its innermost group, and see if it is a single character.
*/
var isCharacterBox = function isCharacterBox(group) {
var baseElem = getBaseElem(group); // These are all they types of groups which hold single characters
return baseElem.type === "mathord" || baseElem.type === "textord" || baseElem.type === "atom";
};
var assert = function assert(value) {
if (!value) {
throw new Error('Expected non-null, but got ' + String(value));
}
return value;
};
/**
* Return the protocol of a URL, or "_relative" if the URL does not specify a
* protocol (and thus is relative).
*/
var protocolFromUrl = function protocolFromUrl(url) {
var protocol = /^\s*([^\\/#]*?)(?::|�*58|�*3a)/i.exec(url);
return protocol != null ? protocol[1] : "_relative";
};
var utils = {
contains,
deflt,
escape,
hyphenate,
getBaseElem,
isCharacterBox,
protocolFromUrl
};
/* eslint no-console:0 */
// TODO: automatically generate documentation
// TODO: check all properties on Settings exist
// TODO: check the type of a property on Settings matches
var SETTINGS_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) {
if (schema.default) {
return schema.default;
}
var type = schema.type;
var 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.
*/
class Settings {
constructor(options) {
this.displayMode = void 0;
this.output = void 0;
this.leqno = void 0;
this.fleqn = void 0;
this.throwOnError = void 0;
this.errorColor = void 0;
this.macros = void 0;
this.minRuleThickness = void 0;
this.colorIsTextColor = void 0;
this.strict = void 0;
this.trust = void 0;
this.maxSize = void 0;
this.maxExpand = void 0;
this.globalGroup = void 0;
// allow null options
options = options || {};
for (var prop in SETTINGS_SCHEMA) {
if (SETTINGS_SCHEMA.hasOwnProperty(prop)) {
// $FlowFixMe
var 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, errorMsg, token) {
var 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, errorMsg, token) {
var 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) {
if (context.url && !context.protocol) {
context.protocol = utils.protocolFromUrl(context.url);
}
var trust = typeof this.trust === "function" ? this.trust(context) : this.trust;
return Boolean(trust);
}
}
/**
* 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 {
constructor(id, size, cramped) {
this.id = void 0;
this.size = void 0;
this.cramped = void 0;
this.id = id;
this.size = size;
this.cramped = cramped;
}
/**
* Get the style of a superscript given a base in the current style.
*/
sup() {
return styles[sup[this.id]];
}
/**
* Get the style of a subscript given a base in the current style.
*/
sub() {
return styles[sub[this.id]];
}
/**
* Get the style of a fraction numerator given the fraction in the current
* style.
*/
fracNum() {
return styles[fracNum[this.id]];
}
/**
* Get the style of a fraction denominator given the fraction in the current
* style.
*/
fracDen() {
return styles[fracDen[this.id]];
}
/**
* Get the cramped version of a style (in particular, cramping a cramped style
* doesn't change the style).
*/
cramp() {
return styles[cramp[this.id]];
}
/**
* Get a text or display version of this style.
*/
text() {
return styles[text$1[this.id]];
}
/**
* Return true if this style is tightly spaced (scriptstyle/scriptscriptstyle)
*/
isTight() {
return this.size >= 2;
}
} // Export an interface for type checking, but don't expose the implementation.
// This way, no more styles can be generated.
// IDs of the different styles
var D = 0;
var Dc = 1;
var T = 2;
var Tc = 3;
var S = 4;
var Sc = 5;
var SS = 6;
var SSc = 7; // Instances of the different styles
var 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
var sup = [S, Sc, S, Sc, SS, SSc, SS, SSc];
var sub = [Sc, Sc, Sc, Sc, SSc, SSc, SSc, SSc];
var fracNum = [T, Tc, S, Sc, SS, SSc, SS, SSc];
var fracDen = [Tc, Tc, Sc, Sc, SSc, SSc, SSc, SSc];
var cramp = [Dc, Dc, Tc, Tc, Sc, Sc, SSc, SSc];
var text$1 = [D, Dc, T, Tc, T, Tc, T, Tc]; // We only export some of the styles.
var Style$1 = {
DISPLAY: styles[D],
TEXT: styles[T],
SCRIPT: styles[S],
SCRIPTSCRIPT: styles[SS]
};
/*
* 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.
*/
/**
* 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.
*/
var scriptData = [{
// 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 (0900–097F)
// Bengali (0980–09FF)
// Gurmukhi (0A00–0A7F)
// Gujarati (0A80–0AFF)
// Oriya (0B00–0B7F)
// Tamil (0B80–0BFF)
// Telugu (0C00–0C7F)
// Kannada (0C80–0CFF)
// Malayalam (0D00–0D7F)
// Sinhala (0D80–0DFF)
// Thai (0E00–0E7F)
// Lao (0E80–0EFF)
// Tibetan (0F00–0FFF)
// Myanmar (1000–109F)
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
*/
function scriptFromCodepoint(codepoint) {
for (var i = 0; i < scriptData.length; i++) {
var script = scriptData[i];
for (var _i = 0; _i < script.blocks.length; _i++) {
var 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.
*/
var allBlocks = [];
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.
*/
function supportedCodepoint(codepoint) {
for (var i = 0; i < allBlocks.length; i += 2) {
if (codepoint >= allBlocks[i] && codepoint <= allBlocks[i + 1]) {
return true;
}
}
return false;
}
/**
* 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.
var 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
*/
var sqrtMain = function sqrtMain(extraVinculum, hLinePad) {
// sqrtMain path geometry is from glyph U221A in the font KaTeX Main
return "M95," + (622 + extraVinculum + hLinePad) + "\nc-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14\nc0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54\nc44.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\ns173,378,173,378c0.7,0,35.3,-71,104,-213c68.7,-142,137.5,-285,206.5,-429\nc69,-144,104.5,-217.7,106.5,-221\nl" + extraVinculum / 2.075 + " -" + extraVinculum + "\nc5.3,-9.3,12,-14,20,-14\nH400000v" + (40 + extraVinculum) + "H845.2724\ns-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7\nc-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z\nM" + (834 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "h-400000z";
};
var sqrtSize1 = function sqrtSize1(extraVinculum, hLinePad) {
// size1 is from glyph U221A in the font KaTeX_Size1-Regular
return "M263," + (601 + extraVinculum + hLinePad) + "c0.7,0,18,39.7,52,119\nc34,79.3,68.167,158.7,102.5,238c34.3,79.3,51.8,119.3,52.5,120\nc340,-704.7,510.7,-1060.3,512,-1067\nl" + extraVinculum / 2.084 + " -" + extraVinculum + "\nc4.7,-7.3,11,-11,19,-11\nH40000v" + (40 + extraVinculum) + "H1012.3\ns-271.3,567,-271.3,567c-38.7,80.7,-84,175,-136,283c-52,108,-89.167,185.3,-111.5,232\nc-22.3,46.7,-33.8,70.3,-34.5,71c-4.7,4.7,-12.3,7,-23,7s-12,-1,-12,-1\ns-109,-253,-109,-253c-72.7,-168,-109.3,-252,-110,-252c-10.7,8,-22,16.7,-34,26\nc-22,17.3,-33.3,26,-34,26s-26,-26,-26,-26s76,-59,76,-59s76,-60,76,-60z\nM" + (1001 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "h-400000z";
};
var sqrtSize2 = function sqrtSize2(extraVinculum, hLinePad) {
// size2 is from glyph U221A in the font KaTeX_Size2-Regular
return "M983 " + (10 + extraVinculum + hLinePad) + "\nl" + extraVinculum / 3.13 + " -" + extraVinculum + "\nc4,-6.7,10,-10,18,-10 H400000v" + (40 + extraVinculum) + "\nH1013.1s-83.4,268,-264.1,840c-180.7,572,-277,876.3,-289,913c-4.7,4.7,-12.7,7,-24,7\ns-12,0,-12,0c-1.3,-3.3,-3.7,-11.7,-7,-25c-35.3,-125.3,-106.7,-373.3,-214,-744\nc-10,12,-21,25,-33,39s-32,39,-32,39c-6,-5.3,-15,-14,-27,-26s25,-30,25,-30\nc26.7,-32.7,52,-63,76,-91s52,-60,52,-60s208,722,208,722\nc56,-175.3,126.3,-397.3,211,-666c84.7,-268.7,153.8,-488.2,207.5,-658.5\nc53.7,-170.3,84.5,-266.8,92.5,-289.5z\nM" + (1001 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "h-400000z";
};
var sqrtSize3 = function sqrtSize3(extraVinculum, hLinePad) {
// size3 is from glyph U221A in the font KaTeX_Size3-Regular
return "M424," + (2398 + extraVinculum + hLinePad) + "\nc-1.3,-0.7,-38.5,-172,-111.5,-514c-73,-342,-109.8,-513.3,-110.5,-514\nc0,-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\ns-5,7,-5,7c-4,-3.3,-8.3,-7.7,-13,-13s-13,-13,-13,-13s76,-122,76,-122s77,-121,77,-121\ns209,968,209,968c0,-2,84.7,-361.7,254,-1079c169.3,-717.3,254.7,-1077.7,256,-1081\nl" + extraVinculum / 4.223 + " -" + extraVinculum + "c4,-6.7,10,-10,18,-10 H400000\nv" + (40 + extraVinculum) + "H1014.6\ns-87.3,378.7,-272.6,1166c-185.3,787.3,-279.3,1182.3,-282,1185\nc-2,6,-10,9,-24,9\nc-8,0,-12,-0.7,-12,-2z M" + (1001 + extraVinculum) + " " + hLinePad + "\nh400000v" + (40 + extraVinculum) + "h-400000z";
};
var sqrtSize4 = function sqrtSize4(extraVinculum, hLinePad) {
// size4 is from glyph U221A in the font KaTeX_Size4-Regular
return "M473," + (2713 + extraVinculum + hLinePad) + "\nc339.3,-1799.3,509.3,-2700,510,-2702 l" + extraVinculum / 5.298 + " -" + extraVinculum + "\nc3.3,-7.3,9.3,-11,18,-11 H400000v" + (40 + extraVinculum) + "H1017.7\ns-90.5,478,-276.2,1466c-185.7,988,-279.5,1483,-281.5,1485c-2,6,-10,9,-24,9\nc-8,0,-12,-0.7,-12,-2c0,-1.3,-5.3,-32,-16,-92c-50.7,-293.3,-119.7,-693.3,-207,-1200\nc0,-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\ns76,-153,76,-153s77,-151,77,-151c0.7,0.7,35.7,202,105,604c67.3,400.7,102,602.7,104,\n606zM" + (1001 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "H1017.7z";
};
var phasePath = function phasePath(y) {
var x = y / 2; // x coordinate at top of angle
return "M400000 " + y + " H0 L" + x + " 0 l65 45 L145 " + (y - 80) + " H400000z";
};
var sqrtTall = function sqrtTall(extraVinculum, hLinePad, viewBoxHeight) {
// 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:
var vertSegment = viewBoxHeight - 54 - hLinePad - extraVinculum;
return "M702 " + (extraVinculum + hLinePad) + "H400000" + (40 + extraVinculum) + "\nH742v" + 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\nh-12l-28-84c-16.667-52-96.667 -294.333-240-727l-212 -643 -85 170\nc-4-3.333-8.333-7.667-13 -13l-13-13l77-155 77-156c66 199.333 139 419.667\n219 661 l218 661zM702 " + hLinePad + "H400000v" + (40 + extraVinculum) + "H742z";
};
var sqrtPath = function sqrtPath(size, extraVinculum, viewBoxHeight) {
extraVinculum = 1000 * extraVinculum; // Convert from document ems to viewBox.
var 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;
};
var innerPath = function innerPath(name, height) {
// 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 "";
}
};
var path = {
// The doubleleftarrow geometry is from glyph U+21D0 in the font KaTeX Main
doubleleftarrow: "M262 157\nl10-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\n 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\n 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\nc2 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\n 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\n-86-123l-10-10h399738v-40H218c328 0 0 0 0 0l-10-8c-26.7-20-65.7-43-117-69 2.7\n-2 6-3.7 10-5 36.7-16 72.3-37.3 107-64l10-8h399782v-40z\nm8 0v40h399730v-40zm0 194v40h399730v-40z",
// doublerightarrow is from glyph U+21D2 in font KaTeX Main
doublerightarrow: "M399738 392l\n-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\n 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\n-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\n-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\n-13h-6c-12 .7-18 4-18 10 0 2 1.7 7 5 15 23.3 46 52 87 86 123l10 10H0v40h399782\nc-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\n-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\n 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\n-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\nc-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\n 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\n 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\n 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\n-45 179-50h399577v120H403c-43.3 7-81 15-113 26-100.7 33-179.7 91-237 174-2.7\n 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\n 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\n 0 2 .3 4 1 18.688 2.7 76 4.3 172 5h399450v120H429l-6-1c-124.688-8-235-61.7\n-331-161C60.687 138.7 32.312 99.3 7 54L0 41V6z",
// overgroup is from the MnSymbol package (public domain)
leftgroup: "M400000 80\nH435C64 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\n 435 0h399565z",
leftgroupunder: "M400000 262\nH435C64 262 168.3 112.6 21 82c-5.9-1.2-18 0-18 0-2 0-3 1-3 3v38c76 158 257 219\n 435 219h399565z",
// Harpoons are from glyph U+21BD in font KaTeX Main
leftharpoon: "M0 267c.7 5.3 3 10 7 14h399993v-40H93c3.3\n-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\n-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\n-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\n 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\n-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\n-10.7 8-12 10-1.3 2-2 5.7-2 11zm100-26v40h399900v-40zM0 435v40h400000v-40z\nm0 0v40h400000v-40z",
leftharpoondown: "M7 241c-4 4-6.333 8.667-7 14 0 5.333.667 9 2 11s5.333\n 5.333 12 10c90.667 54 156 130 196 228 3.333 10.667 6.333 16.333 9 17 2 .667 5\n 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\n-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\n 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\n-2 18-6 2-2.7 1-9.7-3-21-32-87.3-82.7-157.7-152-211l-3-3h399907v-40H7zm93 0\nv40h399900v-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\n-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\n-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\n 71.5 23h399859zM103 281v-40h399897v40z",
leftlinesegment: "M40 281 V428 H0 V94 H40 V241 H400000 v40z\nM40 281 V428 H0 V94 H40 V241 H400000 v40z",
leftmapsto: "M40 281 V448H0V74H40V241H400000v40z\nM40 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\n-.3 23-1 0-1.3-5.3-13.7-16-37-18-35.3-41.3-69-70-101l-7-8h399905v-40H95l7-8\nc28.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\n 68 321 0 361zm0-174v-40h399900v40zm100 154v40h399900v-40z",
longequal: "M0 50 h400000 v40H0z m0 194h40000v40H0z\nM0 50 h400000 v40H0z m0 194h40000v40H0z",
midbrace: "M200428 334\nc-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\n-53.3 86.7-123.7 153-211 199-66.7 36-137.3 56.3-212 62H0V214h199568c178.3-11.7\n 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\n 12 44.7 59.3 101.3 106.3 170 141s145.3 54.3 229 60h199572v120z",
midbraceunder: "M199572 214\nc100.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\n 53.3-86.7 123.7-153 211-199 66.7-36 137.3-56.3 212-62h199568v120H200432c-178.3\n 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\n-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\n-320.3 177.6S193.1 320.6 193.1 249.8c0-71.4 46.9-178.2 319.5-178.2z\nm368.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\n60.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\n-451.1 228.8-386.3 0-452.7-137.5-452.7-228.8 0-92.4 66.4-230 452.7-230z\nm502.4 230c0-111.2-82.4-277.2-502.4-277.2s-504 166-504 277.2\nc0 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\n-480.5 177.6S202.1 320.6 202.1 249.8c0-71.4 70.5-178.2 479.3-178.2z\nm525.8 178.2c0-86.4-86.8-215.4-525.7-215.4-437.9 0-524.7 129-524.7 215.4 0\n85.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\n-707.8 275.8-606 0-710.2-165.8-710.2-275.8C311 218.8 415.2 53 1021.2 53z\nm770.4 277.1c0-131.2-126.4-327.6-770.5-327.6S248.4 198.9 248.4 330.1\nc0 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\n-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\n 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\n 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\n-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\n-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\n 151.7 139 205zm0 0v40h399900v-40z",
rightbrace: "M400000 542l\n-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\ns-117.2-55.8-184.5-66.5c-.7 0-2-.3-4-1-18.7-2.7-76-4.3-172-5H0V214h399571l6 1\nc124.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\n 28.7-117 45-179 50H-300V214h399897c43.3-7 81-15 113-26 100.7-33 179.7-91 237\n-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\n 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\n 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\n-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\n-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\n 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\n-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\n 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\nm0 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\n 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\n-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\n-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\n 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\n 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\n-64.7 57-92 95-27.3 38-48.7 77.7-64 119-3.3 8.7-5 14-5 16zM0 435v40h399900v-40z\nm0-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\n 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\n-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\n 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\nM399960 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\n 1 0 1.3 5.3 13.7 16 37 18 35.3 41.3 69 70 101l7 8H0v40h399905l-7 8c-28.7 32\n-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\n-167z M100 147v40h399900v-40zM0 341v40h399900v-40z",
// twoheadleftarrow is from glyph U+219E in font KaTeX AMS Regular
twoheadleftarrow: "M0 167c68 40\n 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\n-70-101l-7-8h125l9 7c50.7 39.3 85 86 103 140h46c0-4.7-6.3-18.7-19-42-18-35.3\n-40-67.3-66-96l-9-9h399716v-40H284l9-9c26-28.7 48-60.7 66-96 12.7-23.333 19\n-37.333 19-42h-46c-18 54-52.3 100.7-103 140l-9 7H95l7-8c28.7-32 52-65.7 70-101\n 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\nc-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\n 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\n 18 35.3 40 67.3 66 96l9 9H0v40h399716l-9 9c-26 28.7-48 60.7-66 96-12.7 23.333\n-19 37.333-19 42h46c18-54 52.3-100.7 103-140l9-7h125l-7 8c-28.7 32-52 65.7-70\n 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\n-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\n 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\n 4.35-2 7.613-5 9.788l-19 13.05c-92 63.077-116.937 75.308-183 76.128\n-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\n-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\n 31.9 283 0 358 0c148 0 188 122 331 122s314-97 326-97c4 0 8 2 10 7l7 21.114\nc1 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\n 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\n-11-10.37L.15 138c-1-7 3-12 10-13l19.2-6.4C378.4 40.7 634.3 0 804.3 0c337 0\n 411.8 157 746.8 157 328 0 754-112 773-112 5 0 10 3 11 9l1 14.075c1 8.066-.697\n 16.595-6.697 17.492l-21.052 7.31c-367.9 98.146-609.15 122.696-778.15 122.696\n -338 0-409-156.573-744-156.573z",
tilde4: "M786 58C457 58 32 177.487 13 177.487c-6 0-10-3.345\n-11-10.035L.15 143c-1-7 3-12 10-13l22-6.7C381.2 35 637.15 0 807.15 0c337 0 409\n 177 744 177 328 0 754-127 773-127 5 0 10 3 11 9l1 14.794c1 7.805-3 13.38-9\n 14.495l-20.7 5.574c-366.85 99.79-607.3 139.372-776.3 139.372-338 0-409\n -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\n3.333 2.667 6.667 9 10 19 6.667 24.667 20.333 43.667 41 57 7.333 4.667 11\n10.667 11 18 0 6-1 10-3 12s-6.667 5-14 9c-28.667 14.667-53.667 35.667-75 63\n-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\n-7 1c-4.667 0-9.167-1.833-13.5-5.5S337 184 337 178c0-12.667 15.667-32.333 47-59\nH213l-171-1c-8.667-6-13-12.333-13-19 0-4.667 4.333-11.333 13-20h359\nc-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\nc-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\n-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\n-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\n-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,\n-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,\n-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,\n-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,\n-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\nc4 -14.7 6 -23 6 -25c0 -7.3 -7 -11 -21 -11c-8 0 -13.2 0.8 -15.5 2.5\nc-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\ns-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\n121.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\ns2.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\nc0 -2 -2 -10.3 -6 -25c-20 -79.3 -65 -146.7 -135 -202l-3 -3h399890z\nM100 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\n-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\n13.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\n-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\n-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\n-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\n151.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\nc1.3,2,5.3,5.3,12,10c90.7,54,156,130,196,228c3.3,10.7,6.3,16.3,9,17\nc2,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\nc-32,-87.3,-82.7,-157.7,-152,-211c0,0,-3,-3,-3,-3l399351,0l0,-40\nc-398570,0,-399437,0,-399437,0z M593 435 v40 H399500 v-40z\nM0 281 v-40 H399908 v40z M0 281 v-40 H399908 v40z",
rightharpoonaboveshortbar: "M0,241 l0,40c399126,0,399993,0,399993,0\nc4.7,-4.7,7,-9.3,7,-14c0,-9.3,-3.7,-15.3,-11,-18c-92.7,-56.7,-159,-133.7,-199,\n-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\nc-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\nM0 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\nc1.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,\n1c0,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,\n-152,-211c0,0,-3,-3,-3,-3l399907,0l0,-40c-399126,0,-399993,0,-399993,0z\nM93 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\nc4.7,-4.7,7,-9.3,7,-14c0,-9.3,-3.7,-15.3,-11,-18c-92.7,-56.7,-159,-133.7,-199,\n-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\nc-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\nM500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z"
};
var tallDelim = function tallDelim(label, midHeight) {
switch (label) {
case "lbrack":
return "M403 1759 V84 H666 V0 H319 V1759 v" + midHeight + " v1759 h347 v-84\nH403z 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\nM347 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\nc10,0,16.667,-5,20,-15 v-585 v" + -midHeight + " v-585 c-2.667,-10,-9.667,-15,-21,-15\nc-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\nc10,0,16.667,-5,20,-15 v-585 v" + -midHeight + " v-585 c-2.667,-10,-9.667,-15,-21,-15\nc-10,0,-16.667,5,-20,15z M188 15 H145 v585 v" + midHeight + " v585 h43z\nM367 15 v585 v" + midHeight + " v585 c2.667,10,9.667,15,21,15\nc10,0,16.667,-5,20,-15 v-585 v" + -midHeight + " v-585 c-2.667,-10,-9.667,-15,-21,-15\nc-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\nMM319 602 V0 H403 V602 v" + midHeight + " v1715 H319z";
case "rfloor":
return "M319 602 V0 H403 V602 v" + midHeight + " v1799 H0 v-84 H319z\nMM319 602 V0 H403 V602 v" + midHeight + " v1715 H319z";
case "lceil":
return "M403 1759 V84 H666 V0 H319 V1759 v" + midHeight + " v602 h84z\nM403 1759 V0 H319 V1759 v" + midHeight + " v602 h84z";
case "rceil":
return "M347 1759 V0 H0 V84 H263 V1759 v" + midHeight + " v602 h84z\nM347 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\nc-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,\n-36,557 l0," + (midHeight + 84) + "c0.2,6,0,26,0,60c2,159.3,10,310.7,24,454c53.3,528,210,\n949.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\nc0,-2.7,-3.3,-8.7,-10,-18c-135.3,-192.7,-235.5,-414.3,-300.5,-665c-65,-250.7,-102.5,\n-544.7,-112.5,-882c-2,-104,-3,-167,-3,-189\nl0,-" + (midHeight + 92) + "c0,-162.7,5.7,-314,17,-454c20.7,-272,63.7,-513,129,-723c65.3,\n-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,\n63,95c96.7,156.7,172.8,332.5,228.5,527.5c55.7,195,92.8,416.5,111.5,664.5\nc11.3,139.3,17,290.7,17,454c0,28,1.7,43,3.3,45l0," + (midHeight + 9) + "\nc-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\nc-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\nc0,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\nc242.7,-294.7,395.3,-681.7,458,-1161c21.3,-164.7,33.3,-350.7,36,-558\nl0,-" + (midHeight + 144) + "c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,\n-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.");
}
};
/**
* 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.
*/
class DocumentFragment {
// HtmlDomNode
// Never used; needed for satisfying interface.
constructor(children) {
this.children = void 0;
this.classes = void 0;
this.height = void 0;
this.depth = void 0;
this.maxFontSize = void 0;
this.style = void 0;
this.children = children;
this.classes = [];
this.height = 0;
this.depth = 0;
this.maxFontSize = 0;
this.style = {};
}
hasClass(className) {
return utils.contains(this.classes, className);
}
/** Convert the fragment into a node. */
toNode() {
var frag = document.createDocumentFragment();
for (var i = 0; i < this.children.length; i++) {
frag.appendChild(this.children[i].toNode());
}
return frag;
}
/** Convert the fragment into HTML markup. */
toMarkup() {
var markup = ""; // Simply concatenate the markup for the children together.
for (var 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() {
// 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.
var toText = child => child.toText();
return this.children.map(toText).join("");
}
}
// This file is GENERATED by buildMetrics.sh. DO NOT MODIFY.
var fontMetricsData = {
"AMS-Regular": {
"32": [0, 0, 0, 0, 0.25],
"65": [0, 0.68889, 0, 0, 0.72222],
"66": [0, 0.68889, 0, 0, 0.66667],
"67": [0, 0.68889, 0, 0, 0.72222],
"68": [0, 0.68889, 0, 0, 0.72222],
"69": [0, 0.68889, 0, 0, 0.66667],
"70": [0, 0.68889, 0, 0, 0.61111],
"71": [0, 0.68889, 0, 0, 0.77778],
"72": [0, 0.68889, 0, 0, 0.77778],
"73": [0, 0.68889, 0, 0, 0.38889],
"74": [0.16667, 0.68889, 0, 0, 0.5],
"75": [0, 0.68889, 0, 0, 0.77778],
"76": [0, 0.68889, 0, 0, 0.66667],
"77": [0, 0.68889, 0, 0, 0.94445],
"78": [0, 0.68889, 0, 0, 0.72222],
"79": [0.16667, 0.68889, 0, 0, 0.77778],
"80": [0, 0.68889, 0, 0, 0.61111],
"81": [0.16667, 0.68889, 0, 0, 0.77778],
"82": [0, 0.68889, 0, 0, 0.72222],
"83": [0, 0.68889, 0, 0, 0.55556],
"84": [0, 0.68889, 0, 0, 0.66667],
"85": [0, 0.68889, 0, 0, 0.72222],
"86": [0, 0.68889, 0, 0, 0.72222],
"87": [0, 0.68889, 0, 0, 1.0],
"88": [0, 0.68889, 0, 0, 0.72222],
"89": [0, 0.68889, 0, 0, 0.72222],
"90": [0, 0.68889, 0, 0, 0.66667],
"107": [0, 0.68889, 0, 0, 0.55556],
"160": [0, 0, 0, 0, 0.25],
"165": [0, 0.675, 0.025, 0, 0.75],
"174": [0.15559, 0.69224, 0, 0, 0.94666],
"240": [0, 0.68889, 0, 0, 0.55556],
"295": [0, 0.68889, 0, 0, 0.54028],
"710": [0, 0.825, 0, 0, 2.33334],
"732": [0, 0.9, 0, 0, 2.33334],
"770": [0, 0.825, 0, 0, 2.33334],
"771": [0, 0.9, 0, 0, 2.33334],
"989": [0.08167, 0.58167, 0, 0, 0.77778],
"1008": [0, 0.43056, 0.04028, 0, 0.66667],
"8245": [0, 0.54986, 0, 0, 0.275],
"8463": [0, 0.68889, 0, 0, 0.54028],
"8487": [0, 0.68889, 0, 0, 0.72222],
"8498": [0, 0.68889, 0, 0, 0.55556],
"8502": [0, 0.68889, 0, 0, 0.66667],
"8503": [0, 0.68889, 0, 0, 0.44445],
"8504": [0, 0.68889, 0, 0, 0.66667],
"8513": [0, 0.68889, 0, 0, 0.63889],
"8592": [-0.03598, 0.46402, 0, 0, 0.5],
"8594": [-0.03598, 0.46402, 0, 0, 0.5],
"8602": [-0.13313, 0.36687, 0, 0, 1.0],
"8603": [-0.13313, 0.36687, 0, 0, 1.0],
"8606": [0.01354, 0.52239, 0, 0, 1.0],
"8608": [0.01354, 0.52239, 0, 0, 1.0],
"8610": [0.01354, 0.52239, 0, 0, 1.11111],
"8611": [0.01354, 0.52239, 0, 0, 1.11111],
"8619": [0, 0.54986, 0, 0, 1.0],
"8620": [0, 0.54986, 0, 0, 1.0],
"8621": [-0.13313, 0.37788, 0, 0, 1.38889],
"8622": [-0.13313, 0.36687, 0, 0, 1.0],
"8624": [0, 0.69224, 0, 0, 0.5],
"8625": [0, 0.69224, 0, 0, 0.5],
"8630": [0, 0.43056, 0, 0, 1.0],
"8631": [0, 0.43056, 0, 0, 1.0],
"8634": [0.08198, 0.58198, 0, 0, 0.77778],
"8635": [0.08198, 0.58198, 0, 0, 0.77778],
"8638": [0.19444, 0.69224, 0, 0, 0.41667],
"8639": [0.19444, 0.69224, 0, 0, 0.41667],
"8642": [0.19444, 0.69224, 0, 0, 0.41667],
"8643": [0.19444, 0.69224, 0, 0, 0.41667],
"8644": [0.1808, 0.675, 0, 0, 1.0],
"8646": [0.1808, 0.675, 0, 0, 1.0],
"8647": [0.1808, 0.675, 0, 0, 1.0],
"8648": [0.19444, 0.69224, 0, 0, 0.83334],
"8649": [0.1808, 0.675, 0, 0, 1.0],
"8650": [0.19444, 0.69224, 0, 0, 0.83334],
"8651": [0.01354, 0.52239, 0, 0, 1.0],
"8652": [0.01354, 0.52239, 0, 0, 1.0],
"8653": [-0.13313, 0.36687, 0, 0, 1.0],
"8654": [-0.13313, 0.36687, 0, 0, 1.0],
"8655": [-0.13313, 0.36687, 0, 0, 1.0],
"8666": [0.13667, 0.63667, 0, 0, 1.0],
"8667": [0.13667, 0.63667, 0, 0, 1.0],
"8669": [-0.13313, 0.37788, 0, 0, 1.0],
"8672": [-0.064, 0.437, 0, 0, 1.334],
"8674": [-0.064, 0.437, 0, 0, 1.334],
"8705": [0, 0.825, 0, 0, 0.5],
"8708": [0, 0.68889, 0, 0, 0.55556],
"8709": [0.08167, 0.58167, 0, 0, 0.77778],
"8717": [0, 0.43056, 0, 0, 0.42917],
"8722": [-0.03598, 0.46402, 0, 0, 0.5],
"8724": [0.08198, 0.69224, 0, 0, 0.77778],
"8726": [0.08167, 0.58167, 0, 0, 0.77778],
"8733": [0, 0.69224, 0, 0, 0.77778],
"8736": [0, 0.69224, 0, 0, 0.72222],
"8737": [0, 0.69224, 0, 0, 0.72222],
"8738": [0.03517, 0.52239, 0, 0, 0.72222],
"8739": [0.08167, 0.58167, 0, 0, 0.22222],
"8740": [0.25142, 0.74111, 0, 0, 0.27778],
"8741": [0.08167, 0.58167, 0, 0, 0.38889],
"8742": [0.25142, 0.74111, 0, 0, 0.5],
"8756": [0, 0.69224, 0, 0, 0.66667],
"8757": [0, 0.69224, 0, 0, 0.66667],
"8764": [-0.13313, 0.36687, 0, 0, 0.77778],
"8765": [-0.13313, 0.37788, 0, 0, 0.77778],
"8769": [-0.13313, 0.36687, 0, 0, 0.77778],
"8770": [-0.03625, 0.46375, 0, 0, 0.77778],
"8774": [0.30274, 0.79383, 0, 0, 0.77778],
"8776": [-0.01688, 0.48312, 0, 0, 0.77778],
"8778": [0.08167, 0.58167, 0, 0, 0.77778],
"8782": [0.06062, 0.54986, 0, 0, 0.77778],
"8783": [0.06062, 0.54986, 0, 0, 0.77778],
"8785": [0.08198, 0.58198, 0, 0, 0.77778],
"8786": [0.08198, 0.58198, 0, 0, 0.77778],
"8787": [0.08198, 0.58198, 0, 0, 0.77778],
"8790": [0, 0.69224, 0, 0, 0.77778],
"8791": [0.22958, 0.72958, 0, 0, 0.77778],
"8796": [0.08198, 0.91667, 0, 0, 0.77778],
"8806": [0.25583, 0.75583, 0, 0, 0.77778],
"8807": [0.25583, 0.75583, 0, 0, 0.77778],
"8808": [0.25142, 0.75726, 0, 0, 0.77778],
"8809": [0.25142, 0.75726, 0, 0, 0.77778],
"8812": [0.25583, 0.75583, 0, 0, 0.5],
"8814": [0.20576, 0.70576, 0, 0, 0.77778],
"8815": [0.20576, 0.70576, 0, 0, 0.77778],
"8816": [0.30274, 0.79383, 0, 0, 0.77778],
"8817": [0.30274, 0.79383, 0, 0, 0.77778],
"8818": [0.22958, 0.72958, 0, 0, 0.77778],
"8819": [0.22958, 0.72958, 0, 0, 0.77778],
"8822": [0.1808, 0.675, 0, 0, 0.77778],
"8823": [0.1808, 0.675, 0, 0, 0.77778],
"8828": [0.13667, 0.63667, 0, 0, 0.77778],
"8829": [0.13667, 0.63667, 0, 0, 0.77778],
"8830": [0.22958, 0.72958, 0, 0, 0.77778],
"8831": [0.22958, 0.72958, 0, 0, 0.77778],
"8832": [0.20576, 0.70576, 0, 0, 0.77778],
"8833": [0.20576, 0.70576, 0, 0, 0.77778],
"8840": [0.30274, 0.79383, 0, 0, 0.77778],
"8841": [0.30274, 0.79383, 0, 0, 0.77778],
"8842": [0.13597, 0.63597, 0, 0, 0.77778],
"8843": [0.13597, 0.63597, 0, 0, 0.77778],
"8847": [0.03517, 0.54986, 0, 0, 0.77778],
"8848": [0.03517, 0.54986, 0, 0, 0.77778],
"8858": [0.08198, 0.58198, 0, 0, 0.77778],
"8859": [0.08198, 0.58198, 0, 0, 0.77778],
"8861": [0.08198, 0.58198, 0, 0, 0.77778],
"8862": [0, 0.675, 0, 0, 0.77778],
"8863": [0, 0.675, 0, 0, 0.77778],
"8864": [0, 0.675, 0, 0, 0.77778],
"8865": [0, 0.675, 0, 0, 0.77778],
"8872": [0, 0.69224, 0, 0, 0.61111],
"8873": [0, 0.69224, 0, 0, 0.72222],
"8874": [0, 0.69224, 0, 0, 0.88889],
"8876": [0, 0.68889, 0, 0, 0.61111],
"8877": [0, 0.68889, 0, 0, 0.61111],
"8878": [0, 0.68889, 0, 0, 0.72222],
"8879": [0, 0.68889, 0, 0, 0.72222],
"8882": [0.03517, 0.54986, 0, 0, 0.77778],
"8883": [0.03517, 0.54986, 0, 0, 0.77778],
"8884": [0.13667, 0.63667, 0, 0, 0.77778],
"8885": [0.13667, 0.63667, 0, 0, 0.77778],
"8888": [0, 0.54986, 0, 0, 1.11111],
"8890": [0.19444, 0.43056, 0, 0, 0.55556],
"8891": [0.19444, 0.69224, 0, 0, 0.61111],
"8892": [0.19444, 0.69224, 0, 0, 0.61111],
"8901": [0, 0.54986, 0, 0, 0.27778],
"8903": [0.08167, 0.58167, 0, 0, 0.77778],
"8905": [0.08167, 0.58167, 0, 0, 0.77778],
"8906": [0.08167, 0.58167, 0, 0, 0.77778],
"8907": [0, 0.69224, 0, 0, 0.77778],
"8908": [0, 0.69224, 0, 0, 0.77778],
"8909": [-0.03598, 0.46402, 0, 0, 0.77778],
"8910": [0, 0.54986, 0, 0, 0.76042],
"8911": [0, 0.54986, 0, 0, 0.76042],
"8912": [0.03517, 0.54986, 0, 0, 0.77778],
"8913": [0.03517, 0.54986, 0, 0, 0.77778],
"8914": [0, 0.54986, 0, 0, 0.66667],
"8915": [0, 0.54986, 0, 0, 0.66667],
"8916": [0, 0.69224, 0, 0, 0.66667],
"8918": [0.0391, 0.5391, 0, 0, 0.77778],
"8919": [0.0391, 0.5391, 0, 0, 0.77778],
"8920": [0.03517, 0.54986, 0, 0, 1.33334],
"8921": [0.03517, 0.54986, 0, 0, 1.33334],
"8922": [0.38569, 0.88569, 0, 0, 0.77778],
"8923": [0.38569, 0.88569, 0, 0, 0.77778],
"8926": [0.13667, 0.63667, 0, 0, 0.77778],
"8927": [0.13667, 0.63667, 0, 0, 0.77778],
"8928": [0.30274, 0.79383, 0, 0, 0.77778],
"8929": [0.30274, 0.79383, 0, 0, 0.77778],
"8934": [0.23222, 0.74111, 0, 0, 0.77778],
"8935": [0.23222, 0.74111, 0, 0, 0.77778],
"8936": [0.23222, 0.74111, 0, 0, 0.77778],
"8937": [0.23222, 0.74111, 0, 0, 0.77778],
"8938": [0.20576, 0.70576, 0, 0, 0.77778],
"8939": [0.20576, 0.70576, 0, 0, 0.77778],
"8940": [0.30274, 0.79383, 0, 0, 0.77778],
"8941": [0.30274, 0.79383, 0, 0, 0.77778],
"8994": [0.19444, 0.69224, 0, 0, 0.77778],
"8995": [0.19444, 0.69224, 0, 0, 0.77778],
"9416": [0.15559, 0.69224, 0, 0, 0.90222],
"9484": [0, 0.69224, 0, 0, 0.5],
"9488": [0, 0.69224, 0, 0, 0.5],
"9492": [0, 0.37788, 0, 0, 0.5],
"9496": [0, 0.37788, 0, 0, 0.5],
"9585": [0.19444, 0.68889, 0, 0, 0.88889],
"9586": [0.19444, 0.74111, 0, 0, 0.88889],
"9632": [0, 0.675, 0, 0, 0.77778],
"9633": [0, 0.675, 0, 0, 0.77778],
"9650": [0, 0.54986, 0, 0, 0.72222],
"9651": [0, 0.54986, 0, 0, 0.72222],
"9654": [0.03517, 0.54986, 0, 0, 0.77778],
"9660": [0, 0.54986, 0, 0, 0.72222],
"9661": [0, 0.54986, 0, 0, 0.72222],
"9664": [0.03517, 0.54986, 0, 0, 0.77778],
"9674": [0.11111, 0.69224, 0, 0, 0.66667],
"9733": [0.19444, 0.69224, 0, 0, 0.94445],
"10003": [0, 0.69224, 0, 0, 0.83334],
"10016": [0, 0.69224, 0, 0, 0.83334],
"10731": [0.11111, 0.69224, 0, 0, 0.66667],
"10846": [0.19444, 0.75583, 0, 0, 0.61111],
"10877": [0.13667, 0.63667, 0, 0, 0.77778],
"10878": [0.13667, 0.63667, 0, 0, 0.77778],
"10885": [0.25583, 0.75583, 0, 0, 0.77778],
"10886": [0.25583, 0.75583, 0, 0, 0.77778],
"10887": [0.13597, 0.63597, 0, 0, 0.77778],
"10888": [0.13597, 0.63597, 0, 0, 0.77778],
"10889": [0.26167, 0.75726, 0, 0, 0.77778],
"10890": [0.26167, 0.75726, 0, 0, 0.77778],
"10891": [0.48256, 0.98256, 0, 0, 0.77778],
"10892": [0.48256, 0.98256, 0, 0, 0.77778],
"10901": [0.13667, 0.63667, 0, 0, 0.77778],
"10902": [0.13667, 0.63667, 0, 0, 0.77778],
"10933": [0.25142, 0.75726, 0, 0, 0.77778],
"10934": [0.25142, 0.75726, 0, 0, 0.77778],
"10935": [0.26167, 0.75726, 0, 0, 0.77778],
"10936": [0.26167, 0.75726, 0, 0, 0.77778],
"10937": [0.26167, 0.75726, 0, 0, 0.77778],
"10938": [0.26167, 0.75726, 0, 0, 0.77778],
"10949": [0.25583, 0.75583, 0, 0, 0.77778],
"10950": [0.25583, 0.75583, 0, 0, 0.77778],
"10955": [0.28481, 0.79383, 0, 0, 0.77778],
"10956": [0.28481, 0.79383, 0, 0, 0.77778],
"57350": [0.08167, 0.58167, 0, 0, 0.22222],
"57351": [0.08167, 0.58167, 0, 0, 0.38889],
"57352": [0.08167, 0.58167, 0, 0, 0.77778],
"57353": [0, 0.43056, 0.04028, 0, 0.66667],
"57356": [0.25142, 0.75726, 0, 0, 0.77778],
"57357": [0.25142, 0.75726, 0, 0, 0.77778],
"57358": [0.41951, 0.91951, 0, 0, 0.77778],
"57359": [0.30274, 0.79383, 0, 0, 0.77778],
"57360": [0.30274, 0.79383, 0, 0, 0.77778],
"57361": [0.41951, 0.91951, 0, 0, 0.77778],
"57366": [0.25142, 0.75726, 0, 0, 0.77778],
"57367": [0.25142, 0.75726, 0, 0, 0.77778],
"57368": [0.25142, 0.75726, 0, 0, 0.77778],
"57369": [0.25142, 0.75726, 0, 0, 0.77778],
"57370": [0.13597, 0.63597, 0, 0, 0.77778],
"57371": [0.13597, 0.63597, 0, 0, 0.77778]
},
"Caligraphic-Regular": {
"32": [0, 0, 0, 0, 0.25],
"65": [0, 0.68333, 0, 0.19445, 0.79847],
"66": [0, 0.68333, 0.03041, 0.13889, 0.65681],
"67": [0, 0.68333, 0.05834, 0.13889, 0.52653],
"68": [0, 0.68333, 0.02778, 0.08334, 0.77139],
"69": [0, 0.68333, 0.08944, 0.11111, 0.52778],
"70": [0, 0.68333, 0.09931, 0.11111, 0.71875],
"71": [0.09722, 0.68333, 0.0593, 0.11111, 0.59487],
"72": [0, 0.68333, 0.00965, 0.11111, 0.84452],
"73": [0, 0.68333, 0.07382, 0, 0.54452],
"74": [0.09722, 0.68333, 0.18472, 0.16667, 0.67778],
"75": [0, 0.68333, 0.01445, 0.05556, 0.76195],
"76": [0, 0.68333, 0, 0.13889, 0.68972],
"77": [0, 0.68333, 0, 0.13889, 1.2009],
"78": [0, 0.68333, 0.14736, 0.08334, 0.82049],
"79": [0, 0.68333, 0.02778, 0.11111, 0.79611],
"80": [0, 0.68333, 0.08222, 0.08334, 0.69556],
"81": [0.09722, 0.68333, 0, 0.11111, 0.81667],
"82": [0, 0.68333, 0, 0.08334, 0.8475],
"83": [0, 0.68333, 0.075, 0.13889, 0.60556],
"84": [0, 0.68333, 0.25417, 0, 0.54464],
"85": [0, 0.68333, 0.09931, 0.08334, 0.62583],
"86": [0, 0.68333, 0.08222, 0, 0.61278],
"87": [0, 0.68333, 0.08222, 0.08334, 0.98778],
"88": [0, 0.68333, 0.14643, 0.13889, 0.7133],
"89": [0.09722, 0.68333, 0.08222, 0.08334, 0.66834],
"90": [0, 0.68333, 0.07944, 0.13889, 0.72473],
"160": [0, 0, 0, 0, 0.25]
},
"Fraktur-Regular": {
"32": [0, 0, 0, 0, 0.25],
"33": [0, 0.69141, 0, 0, 0.29574],
"34": [0, 0.69141, 0, 0, 0.21471],
"38": [0, 0.69141, 0, 0, 0.73786],
"39": [0, 0.69141, 0, 0, 0.21201],
"40": [0.24982, 0.74947, 0, 0, 0.38865],
"41": [0.24982, 0.74947, 0, 0, 0.38865],
"42": [0, 0.62119, 0, 0, 0.27764],
"43": [0.08319, 0.58283, 0, 0, 0.75623],
"44": [0, 0.10803, 0, 0, 0.27764],
"45": [0.08319, 0.58283, 0, 0, 0.75623],
"46": [0, 0.10803, 0, 0, 0.27764],
"47": [0.24982, 0.74947, 0, 0, 0.50181],
"48": [0, 0.47534, 0, 0, 0.50181],
"49": [0, 0.47534, 0, 0, 0.50181],
"50": [0, 0.47534, 0, 0, 0.50181],
"51": [0.18906, 0.47534, 0, 0, 0.50181],
"52": [0.18906, 0.47534, 0, 0, 0.50181],
"53": [0.18906, 0.47534, 0, 0, 0.50181],
"54": [0, 0.69141, 0, 0, 0.50181],
"55": [0.18906, 0.47534, 0, 0, 0.50181],
"56": [0, 0.69141, 0, 0, 0.50181],
"57": [0.18906, 0.47534, 0, 0, 0.50181],
"58": [0, 0.47534, 0, 0, 0.21606],
"59": [0.12604, 0.47534, 0, 0, 0.21606],
"61": [-0.13099, 0.36866, 0, 0, 0.75623],
"63": [0, 0.69141, 0, 0, 0.36245],
"65": [0, 0.69141, 0, 0, 0.7176],
"66": [0, 0.69141, 0, 0, 0.88397],
"67": [0, 0.69141, 0, 0, 0.61254],
"68": [0, 0.69141, 0, 0, 0.83158],
"69": [0, 0.69141, 0, 0, 0.66278],
"70": [0.12604, 0.69141, 0, 0, 0.61119],
"71": [0, 0.69141, 0, 0, 0.78539],
"72": [0.06302, 0.69141, 0, 0, 0.7203],
"73": [0, 0.69141, 0, 0, 0.55448],
"74": [0.12604, 0.69141, 0, 0, 0.55231],
"75": [0, 0.69141, 0, 0, 0.66845],
"76": [0, 0.69141, 0, 0, 0.66602],
"77": [0, 0.69141, 0, 0, 1.04953],
"78": [0, 0.69141, 0, 0, 0.83212],
"79": [0, 0.69141, 0, 0, 0.82699],
"80": [0.18906, 0.69141, 0, 0, 0.82753],
"81": [0.03781, 0.69141, 0, 0, 0.82699],
"82": [0, 0.69141, 0, 0, 0.82807],
"83": [0, 0.69141, 0, 0, 0.82861],
"84": [0, 0.69141, 0, 0, 0.66899],
"85": [0, 0.69141, 0, 0, 0.64576],
"86": [0, 0.69141, 0, 0, 0.83131],
"87": [0, 0.69141, 0, 0, 1.04602],
"88": [0, 0.69141, 0, 0, 0.71922],
"89": [0.18906, 0.69141, 0, 0, 0.83293],
"90": [0.12604, 0.69141, 0, 0, 0.60201],
"91": [0.24982, 0.74947, 0, 0, 0.27764],
"93": [0.24982, 0.74947, 0, 0, 0.27764],
"94": [0, 0.69141, 0, 0, 0.49965],
"97": [0, 0.47534, 0, 0, 0.50046],
"98": [0, 0.69141, 0, 0, 0.51315],
"99": [0, 0.47534, 0, 0, 0.38946],
"100": [0, 0.62119, 0, 0, 0.49857],
"101": [0, 0.47534, 0, 0, 0.40053],
"102": [0.18906, 0.69141, 0, 0, 0.32626],
"103": [0.18906, 0.47534, 0, 0, 0.5037],
"104": [0.18906, 0.69141, 0, 0, 0.52126],
"105": [0, 0.69141, 0, 0, 0.27899],
"106": [0, 0.69141, 0, 0, 0.28088],
"107": [0, 0.69141, 0, 0, 0.38946],
"108": [0, 0.69141, 0, 0, 0.27953],
"109": [0, 0.47534, 0, 0, 0.76676],
"110": [0, 0.47534, 0, 0, 0.52666],
"111": [0, 0.47534, 0, 0, 0.48885],
"112": [0.18906, 0.52396, 0, 0, 0.50046],
"113": [0.18906, 0.47534, 0, 0, 0.48912],
"114": [0, 0.47534, 0, 0, 0.38919],
"115": [0, 0.47534, 0, 0, 0.44266],
"116": [0, 0.62119, 0, 0, 0.33301],
"117": [0, 0.47534, 0, 0, 0.5172],
"118": [0, 0.52396, 0, 0, 0.5118],
"119": [0, 0.52396, 0, 0, 0.77351],
"120": [0.18906, 0.47534, 0, 0, 0.38865],
"121": [0.18906, 0.47534, 0, 0, 0.49884],
"122": [0.18906, 0.47534, 0, 0, 0.39054],
"160": [0, 0, 0, 0, 0.25],
"8216": [0, 0.69141, 0, 0, 0.21471],
"8217": [0, 0.69141, 0, 0, 0.21471],
"58112": [0, 0.62119, 0, 0, 0.49749],
"58113": [0, 0.62119, 0, 0, 0.4983],
"58114": [0.18906, 0.69141, 0, 0, 0.33328],
"58115": [0.18906, 0.69141, 0, 0, 0.32923],
"58116": [0.18906, 0.47534, 0, 0, 0.50343],
"58117": [0, 0.69141, 0, 0, 0.33301],
"58118": [0, 0.62119, 0, 0, 0.33409],
"58119": [0, 0.47534, 0, 0, 0.50073]
},
"Main-Bold": {
"32": [0, 0, 0, 0, 0.25],
"33": [0, 0.69444, 0, 0, 0.35],
"34": [0, 0.69444, 0, 0, 0.60278],
"35": [0.19444, 0.69444, 0, 0, 0.95833],
"36": [0.05556, 0.75, 0, 0, 0.575],
"37": [0.05556, 0.75, 0, 0, 0.95833],
"38": [0, 0.69444, 0, 0, 0.89444],
"39": [0, 0.69444, 0, 0, 0.31944],
"40": [0.25, 0.75, 0, 0, 0.44722],
"41": [0.25, 0.75, 0, 0, 0.44722],
"42": [0, 0.75, 0, 0, 0.575],
"43": [0.13333, 0.63333, 0, 0, 0.89444],
"44": [0.19444, 0.15556, 0, 0, 0.31944],
"45": [0, 0.44444, 0, 0, 0.38333],
"46": [0, 0.15556, 0, 0, 0.31944],
"47": [0.25, 0.75, 0, 0, 0.575],
"48": [0, 0.64444, 0, 0, 0.575],
"49": [0, 0.64444, 0, 0, 0.575],
"50": [0, 0.64444, 0, 0, 0.575],
"51": [0, 0.64444, 0, 0, 0.575],
"52": [0, 0.64444, 0, 0, 0.575],
"53": [0, 0.64444, 0, 0, 0.575],
"54": [0, 0.64444, 0, 0, 0.575],
"55": [0, 0.64444, 0, 0, 0.575],
"56": [0, 0.64444, 0, 0, 0.575],
"57": [0, 0.64444, 0, 0, 0.575],
"58": [0, 0.44444, 0, 0, 0.31944],
"59": [0.19444, 0.44444, 0, 0, 0.31944],
"60": [0.08556, 0.58556, 0, 0, 0.89444],
"61": [-0.10889, 0.39111, 0, 0, 0.89444],
"62": [0.08556, 0.58556, 0, 0, 0.89444],
"63": [0, 0.69444, 0, 0, 0.54305],
"64": [0, 0.69444, 0, 0, 0.89444],
"65": [0, 0.68611, 0, 0, 0.86944],
"66": [0, 0.68611, 0, 0, 0.81805],
"67": [0, 0.68611, 0, 0, 0.83055],
"68": [0, 0.68611, 0, 0, 0.88194],
"69": [0, 0.68611, 0, 0, 0.75555],
"70": [0, 0.68611, 0, 0, 0.72361],
"71": [0, 0.68611, 0, 0, 0.90416],
"72": [0, 0.68611, 0, 0, 0.9],
"73": [0, 0.68611, 0, 0, 0.43611],
"74": [0, 0.68611, 0, 0, 0.59444],
"75": [0, 0.68611, 0, 0, 0.90138],
"76": [0, 0.68611, 0, 0, 0.69166],
"77": [0, 0.68611, 0, 0, 1.09166],
"78": [0, 0.68611, 0, 0, 0.9],
"79": [0, 0.68611, 0, 0, 0.86388],
"80": [0, 0.68611, 0, 0, 0.78611],
"81": [0.19444, 0.68611, 0, 0, 0.86388],
"82": [0, 0.68611, 0, 0, 0.8625],
"83": [0, 0.68611, 0, 0, 0.63889],
"84": [0, 0.68611, 0, 0, 0.8],
"85": [0, 0.68611, 0, 0, 0.88472],
"86": [0, 0.68611, 0.01597, 0, 0.86944],
"87": [0, 0.68611, 0.01597, 0, 1.18888],
"88": [0, 0.68611, 0, 0, 0.86944],
"89": [0, 0.68611, 0.02875, 0, 0.86944],
"90": [0, 0.68611, 0, 0, 0.70277],
"91": [0.25, 0.75, 0, 0, 0.31944],
"92": [0.25, 0.75, 0, 0, 0.575],
"93": [0.25, 0.75, 0, 0, 0.31944],
"94": [0, 0.69444, 0, 0, 0.575],
"95": [0.31, 0.13444, 0.03194, 0, 0.575],
"97": [0, 0.44444, 0, 0, 0.55902],
"98": [0, 0.69444, 0, 0, 0.63889],
"99": [0, 0.44444, 0, 0, 0.51111],
"100": [0, 0.69444, 0, 0, 0.63889],
"101": [0, 0.44444, 0, 0, 0.52708],
"102": [0, 0.69444, 0.10903, 0, 0.35139],
"103": [0.19444, 0.44444, 0.01597, 0, 0.575],
"104": [0, 0.69444, 0, 0, 0.63889],
"105": [0, 0.69444, 0, 0, 0.31944],
"106": [0.19444, 0.69444, 0, 0, 0.35139],
"107": [0, 0.69444, 0, 0, 0.60694],
"108": [0, 0.69444, 0, 0, 0.31944],
"109": [0, 0.44444, 0, 0, 0.95833],
"110": [0, 0.44444, 0, 0, 0.63889],
"111": [0, 0.44444, 0, 0, 0.575],
"112": [0.19444, 0.44444, 0, 0, 0.63889],
"113": [0.19444, 0.44444, 0, 0, 0.60694],
"114": [0, 0.44444, 0, 0, 0.47361],
"115": [0, 0.44444, 0, 0, 0.45361],
"116": [0, 0.63492, 0, 0, 0.44722],
"117": [0, 0.44444, 0, 0, 0.63889],
"118": [0, 0.44444, 0.01597, 0, 0.60694],
"119": [0, 0.44444, 0.01597, 0, 0.83055],
"120": [0, 0.44444, 0, 0, 0.60694],
"121": [0.19444, 0.44444, 0.01597, 0, 0.60694],
"122": [0, 0.44444, 0, 0, 0.51111],
"123": [0.25, 0.75, 0, 0, 0.575],
"124": [0.25, 0.75, 0, 0, 0.31944],
"125": [0.25, 0.75, 0, 0, 0.575],
"126": [0.35, 0.34444, 0, 0, 0.575],
"160": [0, 0, 0, 0, 0.25],
"163": [0, 0.69444, 0, 0, 0.86853],
"168": [0, 0.69444, 0, 0, 0.575],
"172": [0, 0.44444, 0, 0, 0.76666],
"176": [0, 0.69444, 0, 0, 0.86944],
"177": [0.13333, 0.63333, 0, 0, 0.89444],
"184": [0.17014, 0, 0, 0, 0.51111],
"198": [0, 0.68611, 0, 0, 1.04166],
"215": [0.13333, 0.63333, 0, 0, 0.89444],
"216": [0.04861, 0.73472, 0, 0, 0.89444],
"223": [0, 0.69444, 0, 0, 0.59722],
"230": [0, 0.44444, 0, 0, 0.83055],
"247": [0.13333, 0.63333, 0, 0, 0.89444],
"248": [0.09722, 0.54167, 0, 0, 0.575],
"305": [0, 0.44444, 0, 0, 0.31944],
"338": [0, 0.68611, 0, 0, 1.16944],
"339": [0, 0.44444, 0, 0, 0.89444],
"567": [0.19444, 0.44444, 0, 0, 0.35139],
"710": [0, 0.69444, 0, 0, 0.575],
"711": [0, 0.63194, 0, 0, 0.575],
"713": [0, 0.59611, 0, 0, 0.575],
"714": [0, 0.69444, 0, 0, 0.575],
"715": [0, 0.69444, 0, 0, 0.575],
"728": [0, 0.69444, 0, 0, 0.575],
"729": [0, 0.69444, 0, 0, 0.31944],
"730": [0, 0.69444, 0, 0, 0.86944],
"732": [0, 0.69444, 0, 0, 0.575],
"733": [0, 0.69444, 0, 0, 0.575],
"915": [0, 0.68611, 0, 0, 0.69166],
"916": [0, 0.68611, 0, 0, 0.95833],
"920": [0, 0.68611, 0, 0, 0.89444],
"923": [0, 0.68611, 0, 0, 0.80555],
"926": [0, 0.68611, 0, 0, 0.76666],
"928": [0, 0.68611, 0, 0, 0.9],
"931": [0, 0.68611, 0, 0, 0.83055],
"933": [0, 0.68611, 0, 0, 0.89444],
"934": [0, 0.68611, 0, 0, 0.83055],
"936": [0, 0.68611, 0, 0, 0.89444],
"937": [0, 0.68611, 0, 0, 0.83055],
"8211": [0, 0.44444, 0.03194, 0, 0.575],
"8212": [0, 0.44444, 0.03194, 0, 1.14999],
"8216": [0, 0.69444, 0, 0, 0.31944],
"8217": [0, 0.69444, 0, 0, 0.31944],
"8220": [0, 0.69444, 0, 0, 0.60278],
"8221": [0, 0.69444, 0, 0, 0.60278],
"8224": [0.19444, 0.69444, 0, 0, 0.51111],
"8225": [0.19444, 0.69444, 0, 0, 0.51111],
"8242": [0, 0.55556, 0, 0, 0.34444],
"8407": [0, 0.72444, 0.15486, 0, 0.575],
"8463": [0, 0.69444, 0, 0, 0.66759],
"8465": [0, 0.69444, 0, 0, 0.83055],
"8467": [0, 0.69444, 0, 0, 0.47361],
"8472": [0.19444, 0.44444, 0, 0, 0.74027],
"8476": [0, 0.69444, 0, 0, 0.83055],
"8501": [0, 0.69444, 0, 0, 0.70277],
"8592": [-0.10889, 0.39111, 0, 0, 1.14999],
"8593": [0.19444, 0.69444, 0, 0, 0.575],
"8594": [-0.10889, 0.39111, 0, 0, 1.14999],
"8595": [0.19444, 0.69444, 0, 0, 0.575],
"8596": [-0.10889, 0.39111, 0, 0, 1.14999],
"8597": [0.25, 0.75, 0, 0, 0.575],
"8598": [0.19444, 0.69444, 0, 0, 1.14999],
"8599": [0.19444, 0.69444, 0, 0, 1.14999],
"8600": [0.19444, 0.69444, 0, 0, 1.14999],
"8601": [0.19444, 0.69444, 0, 0, 1.14999],
"8636": [-0.10889, 0.39111, 0, 0, 1.14999],
"8637": [-0.10889, 0.39111, 0, 0, 1.14999],
"8640": [-0.10889, 0.39111, 0, 0, 1.14999],
"8641": [-0.10889, 0.39111, 0, 0, 1.14999],
"8656": [-0.10889, 0.39111, 0, 0, 1.14999],
"8657": [0.19444, 0.69444, 0, 0, 0.70277],
"8658": [-0.10889, 0.39111, 0, 0, 1.14999],
"8659": [0.19444, 0.69444, 0, 0, 0.70277],
"8660": [-0.10889, 0.39111, 0, 0, 1.14999],
"8661": [0.25, 0.75, 0, 0, 0.70277],
"8704": [0, 0.69444, 0, 0, 0.63889],
"8706": [0, 0.69444, 0.06389, 0, 0.62847],
"8707": [0, 0.69444, 0, 0, 0.63889],
"8709": [0.05556, 0.75, 0, 0, 0.575],
"8711": [0, 0.68611, 0, 0, 0.95833],
"8712": [0.08556, 0.58556, 0, 0, 0.76666],
"8715": [0.08556, 0.58556, 0, 0, 0.76666],
"8722": [0.13333, 0.63333, 0, 0, 0.89444],
"8723": [0.13333, 0.63333, 0, 0, 0.89444],
"8725": [0.25, 0.75, 0, 0, 0.575],
"8726": [0.25, 0.75, 0, 0, 0.575],
"8727": [-0.02778, 0.47222, 0, 0, 0.575],
"8728": [-0.02639, 0.47361, 0, 0, 0.575],
"8729": [-0.02639, 0.47361, 0, 0, 0.575],
"8730": [0.18, 0.82, 0, 0, 0.95833],
"8733": [0, 0.44444, 0, 0, 0.89444],
"8734": [0, 0.44444, 0, 0, 1.14999],
"8736": [0, 0.69224, 0, 0, 0.72222],
"8739": [0.25, 0.75, 0, 0, 0.31944],
"8741": [0.25, 0.75, 0, 0, 0.575],
"8743": [0, 0.55556, 0, 0, 0.76666],
"8744": [0, 0.55556, 0, 0, 0.76666],
"8745": [0, 0.55556, 0, 0, 0.76666],
"8746": [0, 0.55556, 0, 0, 0.76666],
"8747": [0.19444, 0.69444, 0.12778, 0, 0.56875],
"8764": [-0.10889, 0.39111, 0, 0, 0.89444],
"8768": [0.19444, 0.69444, 0, 0, 0.31944],
"8771": [0.00222, 0.50222, 0, 0, 0.89444],
"8773": [0.027, 0.638, 0, 0, 0.894],
"8776": [0.02444, 0.52444, 0, 0, 0.89444],
"8781": [0.00222, 0.50222, 0, 0, 0.89444],
"8801": [0.00222, 0.50222, 0, 0, 0.89444],
"8804": [0.19667, 0.69667, 0, 0, 0.89444],
"8805": [0.19667, 0.69667, 0, 0, 0.89444],
"8810": [0.08556, 0.58556, 0, 0, 1.14999],
"8811": [0.08556, 0.58556, 0, 0, 1.14999],
"8826": [0.08556, 0.58556, 0, 0, 0.89444],
"8827": [0.08556, 0.58556, 0, 0, 0.89444],
"8834": [0.08556, 0.58556, 0, 0, 0.89444],
"8835": [0.08556, 0.58556, 0, 0, 0.89444],
"8838": [0.19667, 0.69667, 0, 0, 0.89444],
"8839": [0.19667, 0.69667, 0, 0, 0.89444],
"8846": [0, 0.55556, 0, 0, 0.76666],
"8849": [0.19667, 0.69667, 0, 0, 0.89444],
"8850": [0.19667, 0.69667, 0, 0, 0.89444],
"8851": [0, 0.55556, 0, 0, 0.76666],
"8852": [0, 0.55556, 0, 0, 0.76666],
"8853": [0.13333, 0.63333, 0, 0, 0.89444],
"8854": [0.13333, 0.63333, 0, 0, 0.89444],
"8855": [0.13333, 0.63333, 0, 0, 0.89444],
"8856": [0.13333, 0.63333, 0, 0, 0.89444],
"8857": [0.13333, 0.63333, 0, 0, 0.89444],
"8866": [0, 0.69444, 0, 0, 0.70277],
"8867": [0, 0.69444, 0, 0, 0.70277],
"8868": [0, 0.69444, 0, 0, 0.89444],
"8869": [0, 0.69444, 0, 0, 0.89444],
"8900": [-0.02639, 0.47361, 0, 0, 0.575],
"8901": [-0.02639, 0.47361, 0, 0, 0.31944],
"8902": [-0.02778, 0.47222, 0, 0, 0.575],
"8968": [0.25, 0.75, 0, 0, 0.51111],
"8969": [0.25, 0.75, 0, 0, 0.51111],
"8970": [0.25, 0.75, 0, 0, 0.51111],
"8971": [0.25, 0.75, 0, 0, 0.51111],
"8994": [-0.13889, 0.36111, 0, 0, 1.14999],
"8995": [-0.13889, 0.36111, 0, 0, 1.14999],
"9651": [0.19444, 0.69444, 0, 0, 1.02222],
"9657": [-0.02778, 0.47222, 0, 0, 0.575],
"9661": [0.19444, 0.69444, 0, 0, 1.02222],
"9667": [-0.02778, 0.47222, 0, 0, 0.575],
"9711": [0.19444, 0.69444, 0, 0, 1.14999],
"9824": [0.12963, 0.69444, 0, 0, 0.89444],
"9825": [0.12963, 0.69444, 0, 0, 0.89444],
"9826": [0.12963, 0.69444, 0, 0, 0.89444],
"9827": [0.12963, 0.69444, 0, 0, 0.89444],
"9837": [0, 0.75, 0, 0, 0.44722],
"9838": [0.19444, 0.69444, 0, 0, 0.44722],
"9839": [0.19444, 0.69444, 0, 0, 0.44722],
"10216": [0.25, 0.75, 0, 0, 0.44722],
"10217": [0.25, 0.75, 0, 0, 0.44722],
"10815": [0, 0.68611, 0, 0, 0.9],
"10927": [0.19667, 0.69667, 0, 0, 0.89444],
"10928": [0.19667, 0.69667, 0, 0, 0.89444],
"57376": [0.19444, 0.69444, 0, 0, 0]
},
"Main-BoldItalic": {
"32": [0, 0, 0, 0, 0.25],
"33": [0, 0.69444, 0.11417, 0, 0.38611],
"34": [0, 0.69444, 0.07939, 0, 0.62055],
"35": [0.19444, 0.69444, 0.06833, 0, 0.94444],
"37": [0.05556, 0.75, 0.12861, 0, 0.94444],
"38": [0, 0.69444, 0.08528, 0, 0.88555],
"39": [0, 0.69444, 0.12945, 0, 0.35555],
"40": [0.25, 0.75, 0.15806, 0, 0.47333],
"41": [0.25, 0.75, 0.03306, 0, 0.47333],
"42": [0, 0.75, 0.14333, 0, 0.59111],
"43": [0.10333, 0.60333, 0.03306, 0, 0.88555],
"44": [0.19444, 0.14722, 0, 0, 0.35555],
"45": [0, 0.44444, 0.02611, 0, 0.41444],
"46": [0, 0.14722, 0, 0, 0.35555],
"47": [0.25, 0.75, 0.15806, 0, 0.59111],
"48": [0, 0.64444, 0.13167, 0, 0.59111],
"49": [0, 0.64444, 0.13167, 0, 0.59111],
"50": [0, 0.64444, 0.13167, 0, 0.59111],
"51": [0, 0.64444, 0.13167, 0, 0.59111],
"52": [0.19444, 0.64444, 0.13167, 0, 0.59111],
"53": [0, 0.64444, 0.13167, 0, 0.59111],
"54": [0, 0.64444, 0.13167, 0, 0.59111],
"55": [0.19444, 0.64444, 0.13167, 0, 0.59111],
"56": [0, 0.64444, 0.13167, 0, 0.59111],
"57": [0, 0.64444, 0.13167, 0, 0.59111],
"58": [0, 0.44444, 0.06695, 0, 0.35555],
"59": [0.19444, 0.44444, 0.06695, 0, 0.35555],
"61": [-0.10889, 0.39111, 0.06833, 0, 0.88555],
"63": [0, 0.69444, 0.11472, 0, 0.59111],
"64": [0, 0.69444, 0.09208, 0, 0.88555],
"65": [0, 0.68611, 0, 0, 0.86555],
"66": [0, 0.68611, 0.0992, 0, 0.81666],
"67": [0, 0.68611, 0.14208, 0, 0.82666],
"68": [0, 0.68611, 0.09062, 0, 0.87555],
"69": [0, 0.68611, 0.11431, 0, 0.75666],
"70": [0, 0.68611, 0.12903, 0, 0.72722],
"71": [0, 0.68611, 0.07347, 0, 0.89527],
"72": [0, 0.68611, 0.17208, 0, 0.8961],
"73": [0, 0.68611, 0.15681, 0, 0.47166],
"74": [0, 0.68611, 0.145, 0, 0.61055],
"75": [0, 0.68611, 0.14208, 0, 0.89499],
"76": [0, 0.68611, 0, 0, 0.69777],
"77": [0, 0.68611, 0.17208, 0, 1.07277],
"78": [0, 0.68611, 0.17208, 0, 0.8961],
"79": [0, 0.68611, 0.09062, 0, 0.85499],
"80": [0, 0.68611, 0.0992, 0, 0.78721],
"81": [0.19444, 0.68611, 0.09062, 0, 0.85499],
"82": [0, 0.68611, 0.02559, 0, 0.85944],
"83": [0, 0.68611, 0.11264, 0, 0.64999],
"84": [0, 0.68611, 0.12903, 0, 0.7961],
"85": [0, 0.68611, 0.17208, 0, 0.88083],
"86": [0, 0.68611, 0.18625, 0, 0.86555],
"87": [0, 0.68611, 0.18625, 0, 1.15999],
"88": [0, 0.68611, 0.15681, 0, 0.86555],
"89": [0, 0.68611, 0.19803, 0, 0.86555],
"90": [0, 0.68611, 0.14208, 0, 0.70888],
"91": [0.25, 0.75, 0.1875, 0, 0.35611],
"93": [0.25, 0.75, 0.09972, 0, 0.35611],
"94": [0, 0.69444, 0.06709, 0, 0.59111],
"95": [0.31, 0.13444, 0.09811, 0, 0.59111],
"97": [0, 0.44444, 0.09426, 0, 0.59111],
"98": [0, 0.69444, 0.07861, 0, 0.53222],
"99": [0, 0.44444, 0.05222, 0, 0.53222],
"100": [0, 0.69444, 0.10861, 0, 0.59111],
"101": [0, 0.44444, 0.085, 0, 0.53222],
"102": [0.19444, 0.69444, 0.21778, 0, 0.4],
"103": [0.19444, 0.44444, 0.105, 0, 0.53222],
"104": [0, 0.69444, 0.09426, 0, 0.59111],
"105": [0, 0.69326, 0.11387, 0, 0.35555],
"106": [0.19444, 0.69326, 0.1672, 0, 0.35555],
"107": [0, 0.69444, 0.11111, 0, 0.53222],
"108": [0, 0.69444, 0.10861, 0, 0.29666],
"109": [0, 0.44444, 0.09426, 0, 0.94444],
"110": [0, 0.44444, 0.09426, 0, 0.64999],
"111": [0, 0.44444, 0.07861, 0, 0.59111],
"112": [0.19444, 0.44444, 0.07861, 0, 0.59111],
"113": [0.19444, 0.44444, 0.105, 0, 0.53222],
"114": [0, 0.44444, 0.11111, 0, 0.50167],
"115": [0, 0.44444, 0.08167, 0, 0.48694],
"116": [0, 0.63492, 0.09639, 0, 0.385],
"117": [0, 0.44444, 0.09426, 0, 0.62055],
"118": [0, 0.44444, 0.11111, 0, 0.53222],
"119": [0, 0.44444, 0.11111, 0, 0.76777],
"120": [0, 0.44444, 0.12583, 0, 0.56055],
"121": [0.19444, 0.44444, 0.105, 0, 0.56166],
"122": [0, 0.44444, 0.13889, 0, 0.49055],
"126": [0.35, 0.34444, 0.11472, 0, 0.59111],
"160": [0, 0, 0, 0, 0.25],
"168": [0, 0.69444, 0.11473, 0, 0.59111],
"176": [0, 0.69444, 0, 0, 0.94888],
"184": [0.17014, 0, 0, 0, 0.53222],
"198": [0, 0.68611, 0.11431, 0, 1.02277],
"216": [0.04861, 0.73472, 0.09062, 0, 0.88555],
"223": [0.19444, 0.69444, 0.09736, 0, 0.665],
"230": [0, 0.44444, 0.085, 0, 0.82666],
"248": [0.09722, 0.54167, 0.09458, 0, 0.59111],
"305": [0, 0.44444, 0.09426, 0, 0.35555],
"338": [0, 0.68611, 0.11431, 0, 1.14054],
"339": [0, 0.44444, 0.085, 0, 0.82666],
"567": [0.19444, 0.44444, 0.04611, 0, 0.385],
"710": [0, 0.69444, 0.06709, 0, 0.59111],
"711": [0, 0.63194, 0.08271, 0, 0.59111],
"713": [0, 0.59444, 0.10444, 0, 0.59111],
"714": [0, 0.69444, 0.08528, 0, 0.59111],
"715": [0, 0.69444, 0, 0, 0.59111],
"728": [0, 0.69444, 0.10333, 0, 0.59111],
"729": [0, 0.69444, 0.12945, 0, 0.35555],
"730": [0, 0.69444, 0, 0, 0.94888],
"732": [0, 0.69444, 0.11472, 0, 0.59111],
"733": [0, 0.69444, 0.11472, 0, 0.59111],
"915": [0, 0.68611, 0.12903, 0, 0.69777],
"916": [0, 0.68611, 0, 0, 0.94444],
"920": [0, 0.68611, 0.09062, 0, 0.88555],
"923": [0, 0.68611, 0, 0, 0.80666],
"926": [0, 0.68611, 0.15092, 0, 0.76777],
"928": [0, 0.68611, 0.17208, 0, 0.8961],
"931": [0, 0.68611, 0.11431, 0, 0.82666],
"933": [0, 0.68611, 0.10778, 0, 0.88555],
"934": [0, 0.68611, 0.05632, 0, 0.82666],
"936": [0, 0.68611, 0.10778, 0, 0.88555],
"937": [0, 0.68611, 0.0992, 0, 0.82666],
"8211": [0, 0.44444, 0.09811, 0, 0.59111],
"8212": [0, 0.44444, 0.09811, 0, 1.18221],
"8216": [0, 0.69444, 0.12945, 0, 0.35555],
"8217": [0, 0.69444, 0.12945, 0, 0.35555],
"8220": [0, 0.69444, 0.16772, 0, 0.62055],
"8221": [0, 0.69444, 0.07939, 0, 0.62055]
},
"Main-Italic": {
"32": [0, 0, 0, 0, 0.25],
"33": [0, 0.69444, 0.12417, 0, 0.30667],
"34": [0, 0.69444, 0.06961, 0, 0.51444],
"35": [0.19444, 0.69444, 0.06616, 0, 0.81777],
"37": [0.05556, 0.75, 0.13639, 0, 0.81777],
"38": [0, 0.69444, 0.09694, 0, 0.76666],
"39": [0, 0.69444, 0.12417, 0, 0.30667],
"40": [0.25, 0.75, 0.16194, 0, 0.40889],
"41": [0.25, 0.75, 0.03694, 0, 0.40889],
"42": [0, 0.75, 0.14917, 0, 0.51111],
"43": [0.05667, 0.56167, 0.03694, 0, 0.76666],
"44": [0.19444, 0.10556, 0, 0, 0.30667],
"45": [0, 0.43056, 0.02826, 0, 0.35778],
"46": [0, 0.10556, 0, 0, 0.30667],
"47": [0.25, 0.75, 0.16194, 0, 0.51111],
"48": [0, 0.64444, 0.13556, 0, 0.51111],
"49": [0, 0.64444, 0.13556, 0, 0.51111],
"50": [0, 0.64444, 0.13556, 0, 0.51111],
"51": [0, 0.64444, 0.13556, 0, 0.51111],
"52": [0.19444, 0.64444, 0.13556, 0, 0.51111],
"53": [0, 0.64444, 0.13556, 0, 0.51111],
"54": [0, 0.64444, 0.13556, 0, 0.51111],
"55": [0.19444, 0.64444, 0.13556, 0, 0.51111],
"56": [0, 0.64444, 0.13556, 0, 0.51111],
"57": [0, 0.64444, 0.13556, 0, 0.51111],
"58": [0, 0.43056, 0.0582, 0, 0.30667],
"59": [0.19444, 0.43056, 0.0582, 0, 0.30667],
"61": [-0.13313, 0.36687, 0.06616, 0, 0.76666],
"63": [0, 0.69444, 0.1225, 0, 0.51111],
"64": [0, 0.69444, 0.09597, 0, 0.76666],
"65": [0, 0.68333, 0, 0, 0.74333],
"66": [0, 0.68333, 0.10257, 0, 0.70389],
"67": [0, 0.68333, 0.14528, 0, 0.71555],
"68": [0, 0.68333, 0.09403, 0, 0.755],
"69": [0, 0.68333, 0.12028, 0, 0.67833],
"70": [0, 0.68333, 0.13305, 0, 0.65277],
"71": [0, 0.68333, 0.08722, 0, 0.77361],
"72": [0, 0.68333, 0.16389, 0, 0.74333],
"73": [0, 0.68333, 0.15806, 0, 0.38555],
"74": [0, 0.68333, 0.14028, 0, 0.525],
"75": [0, 0.68333, 0.14528, 0, 0.76888],
"76": [0, 0.68333, 0, 0, 0.62722],
"77": [0, 0.68333, 0.16389, 0, 0.89666],
"78": [0, 0.68333, 0.16389, 0, 0.74333],
"79": [0, 0.68333, 0.09403, 0, 0.76666],
"80": [0, 0.68333, 0.10257, 0, 0.67833],
"81": [0.19444, 0.68333, 0.09403, 0, 0.76666],
"82": [0, 0.68333, 0.03868, 0, 0.72944],
"83": [0, 0.68333, 0.11972, 0, 0.56222],
"84": [0, 0.68333, 0.13305, 0, 0.71555],
"85": [0, 0.68333, 0.16389, 0, 0.74333],
"86": [0, 0.68333, 0.18361, 0, 0.74333],
"87": [0, 0.68333, 0.18361, 0, 0.99888],
"88": [0, 0.68333, 0.15806, 0, 0.74333],
"89": [0, 0.68333, 0.19383, 0, 0.74333],
"90": [0, 0.68333, 0.14528, 0, 0.61333],
"91": [0.25, 0.75, 0.1875, 0, 0.30667],
"93": [0.25, 0.75, 0.10528, 0, 0.30667],
"94": [0, 0.69444, 0.06646, 0, 0.51111],
"95": [0.31, 0.12056, 0.09208, 0, 0.51111],
"97": [0, 0.43056, 0.07671, 0, 0.51111],
"98": [0, 0.69444, 0.06312, 0, 0.46],
"99": [0, 0.43056, 0.05653, 0, 0.46],
"100": [0, 0.69444, 0.10333, 0, 0.51111],
"101": [0, 0.43056, 0.07514, 0, 0.46],
"102": [0.19444, 0.69444, 0.21194, 0, 0.30667],
"103": [0.19444, 0.43056, 0.08847, 0, 0.46],
"104": [0, 0.69444, 0.07671, 0, 0.51111],
"105": [0, 0.65536, 0.1019, 0, 0.30667],
"106": [0.19444, 0.65536, 0.14467, 0, 0.30667],
"107": [0, 0.69444, 0.10764, 0, 0.46],
"108": [0, 0.69444, 0.10333, 0, 0.25555],
"109": [0, 0.43056, 0.07671, 0, 0.81777],
"110": [0, 0.43056, 0.07671, 0, 0.56222],
"111": [0, 0.43056, 0.06312, 0, 0.51111],
"112": [0.19444, 0.43056, 0.06312, 0, 0.51111],
"113": [0.19444, 0.43056, 0.08847, 0, 0.46],
"114": [0, 0.43056, 0.10764, 0, 0.42166],
"115": [0, 0.43056, 0.08208, 0, 0.40889],
"116": [0, 0.61508, 0.09486, 0, 0.33222],
"117": [0, 0.43056, 0.07671, 0, 0.53666],
"118": [0, 0.43056, 0.10764, 0, 0.46],
"119": [0, 0.43056, 0.10764, 0, 0.66444],
"120": [0, 0.43056, 0.12042, 0, 0.46389],
"121": [0.19444, 0.43056, 0.08847, 0, 0.48555],
"122": [0, 0.43056, 0.12292, 0, 0.40889],
"126": [0.35, 0.31786, 0.11585, 0, 0.51111],
"160": [0, 0, 0, 0, 0.25],
"168": [0, 0.66786, 0.10474, 0, 0.51111],
"176": [0, 0.69444, 0, 0, 0.83129],
"184": [0.17014, 0, 0, 0, 0.46],
"198": [0, 0.68333, 0.12028, 0, 0.88277],
"216": [0.04861, 0.73194, 0.09403, 0, 0.76666],
"223": [0.19444, 0.69444, 0.10514, 0, 0.53666],
"230": [0, 0.43056, 0.07514, 0, 0.71555],
"248": [0.09722, 0.52778, 0.09194, 0, 0.51111],
"338": [0, 0.68333, 0.12028, 0, 0.98499],
"339": [0, 0.43056, 0.07514, 0, 0.71555],
"710": [0, 0.69444, 0.06646, 0, 0.51111],
"711": [0, 0.62847, 0.08295, 0, 0.51111],
"713": [0, 0.56167, 0.10333, 0, 0.51111],
"714": [0, 0.69444, 0.09694, 0, 0.51111],
"715": [0, 0.69444, 0, 0, 0.51111],
"728": [0, 0.69444, 0.10806, 0, 0.51111],
"729": [0, 0.66786, 0.11752, 0, 0.30667],
"730": [0, 0.69444, 0, 0, 0.83129],
"732": [0, 0.66786, 0.11585, 0, 0.51111],
"733": [0, 0.69444, 0.1225, 0, 0.51111],
"915": [0, 0.68333, 0.13305, 0, 0.62722],
"916": [0, 0.68333, 0, 0, 0.81777],
"920": [0, 0.68333, 0.09403, 0, 0.76666],
"923": [0, 0.68333, 0, 0, 0.69222],
"926": [0, 0.68333, 0.15294, 0, 0.66444],
"928": [0, 0.68333, 0.16389, 0, 0.74333],
"931": [0, 0.68333, 0.12028, 0, 0.71555],
"933": [0, 0.68333, 0.11111, 0, 0.76666],
"934": [0, 0.68333, 0.05986, 0, 0.71555],
"936": [0, 0.68333, 0.11111, 0, 0.76666],
"937": [0, 0.68333, 0.10257, 0, 0.71555],
"8211": [0, 0.43056, 0.09208, 0, 0.51111],
"8212": [0, 0.43056, 0.09208, 0, 1.02222],
"8216": [0, 0.69444, 0.12417, 0, 0.30667],
"8217": [0, 0.69444, 0.12417, 0, 0.30667],
"8220": [0, 0.69444, 0.1685, 0, 0.51444],
"8221": [0, 0.69444, 0.06961, 0, 0.51444],
"8463": [0, 0.68889, 0, 0, 0.54028]
},
"Main-Regular": {
"32": [0, 0, 0, 0, 0.25],
"33": [0, 0.69444, 0, 0, 0.27778],
"34": [0, 0.69444, 0, 0, 0.5],
"35": [0.19444, 0.69444, 0, 0, 0.83334],
"36": [0.05556, 0.75, 0, 0, 0.5],
"37": [0.05556, 0.75, 0, 0, 0.83334],
"38": [0, 0.69444, 0, 0, 0.77778],
"39": [0, 0.69444, 0, 0, 0.27778],
"40": [0.25, 0.75, 0, 0, 0.38889],
"41": [0.25, 0.75, 0, 0, 0.38889],
"42": [0, 0.75, 0, 0, 0.5],
"43": [0.08333, 0.58333, 0, 0, 0.77778],
"44": [0.19444, 0.10556, 0, 0, 0.27778],
"45": [0, 0.43056, 0, 0, 0.33333],
"46": [0, 0.10556, 0, 0, 0.27778],
"47": [0.25, 0.75, 0, 0, 0.5],
"48": [0, 0.64444, 0, 0, 0.5],
"49": [0, 0.64444, 0, 0, 0.5],
"50": [0, 0.64444, 0, 0, 0.5],
"51": [0, 0.64444, 0, 0, 0.5],
"52": [0, 0.64444, 0, 0, 0.5],
"53": [0, 0.64444, 0, 0, 0.5],
"54": [0, 0.64444, 0, 0, 0.5],
"55": [0, 0.64444, 0, 0, 0.5],
"56": [0, 0.64444, 0, 0, 0.5],
"57": [0, 0.64444, 0, 0, 0.5],
"58": [0, 0.43056, 0, 0, 0.27778],
"59": [0.19444, 0.43056, 0, 0, 0.27778],
"60": [0.0391, 0.5391, 0, 0, 0.77778],
"61": [-0.13313, 0.36687, 0, 0, 0.77778],
"62": [0.0391, 0.5391, 0, 0, 0.77778],
"63": [0, 0.69444, 0, 0, 0.47222],
"64": [0, 0.69444, 0, 0, 0.77778],
"65": [0, 0.68333, 0, 0, 0.75],
"66": [0, 0.68333, 0, 0, 0.70834],
"67": [0, 0.68333, 0, 0, 0.72222],
"68": [0, 0.68333, 0, 0, 0.76389],
"69": [0, 0.68333, 0, 0, 0.68056],
"70": [0, 0.68333, 0, 0, 0.65278],
"71": [0, 0.68333, 0, 0, 0.78472],
"72": [0, 0.68333, 0, 0, 0.75],
"73": [0, 0.68333, 0, 0, 0.36111],
"74": [0, 0.68333, 0, 0, 0.51389],
"75": [0, 0.68333, 0, 0, 0.77778],
"76": [0, 0.68333, 0, 0, 0.625],
"77": [0, 0.68333, 0, 0, 0.91667],
"78": [0, 0.68333, 0, 0, 0.75],
"79": [0, 0.68333, 0, 0, 0.77778],
"80": [0, 0.68333, 0, 0, 0.68056],
"81": [0.19444, 0.68333, 0, 0, 0.77778],
"82": [0, 0.68333, 0, 0, 0.73611],
"83": [0, 0.68333, 0, 0, 0.55556],
"84": [0, 0.68333, 0, 0, 0.72222],
"85": [0, 0.68333, 0, 0, 0.75],
"86": [0, 0.68333, 0.01389, 0, 0.75],
"87": [0, 0.68333, 0.01389, 0, 1.02778],
"88": [0, 0.68333, 0, 0, 0.75],
"89": [0, 0.68333, 0.025, 0, 0.75],
"90": [0, 0.68333, 0, 0, 0.61111],
"91": [0.25, 0.75, 0, 0, 0.27778],
"92": [0.25, 0.75, 0, 0, 0.5],
"93": [0.25, 0.75, 0, 0, 0.27778],
"94": [0, 0.69444, 0, 0, 0.5],
"95": [0.31, 0.12056, 0.02778, 0, 0.5],
"97": [0, 0.43056, 0, 0, 0.5],
"98": [0, 0.69444, 0, 0, 0.55556],
"99": [0, 0.43056, 0, 0, 0.44445],
"100": [0, 0.69444, 0, 0, 0.55556],
"101": [0, 0.43056, 0, 0, 0.44445],
"102": [0, 0.69444, 0.07778, 0, 0.30556],
"103": [0.19444, 0.43056, 0.01389, 0, 0.5],
"104": [0, 0.69444, 0, 0, 0.55556],
"105": [0, 0.66786, 0, 0, 0.27778],
"106": [0.19444, 0.66786, 0, 0, 0.30556],
"107": [0, 0.69444, 0, 0, 0.52778],
"108": [0, 0.69444, 0, 0, 0.27778],
"109": [0, 0.43056, 0, 0, 0.83334],
"110": [0, 0.43056, 0, 0, 0.55556],
"111": [0, 0.43056, 0, 0, 0.5],
"112": [0.19444, 0.43056, 0, 0, 0.55556],
"113": [0.19444, 0.43056, 0, 0, 0.52778],
"114": [0, 0.43056, 0, 0, 0.39167],
"115": [0, 0.43056, 0, 0, 0.39445],
"116": [0, 0.61508, 0, 0, 0.38889],
"117": [0, 0.43056, 0, 0, 0.55556],
"118": [0, 0.43056, 0.01389, 0, 0.52778],
"119": [0, 0.43056, 0.01389, 0, 0.72222],
"120": [0, 0.43056, 0, 0, 0.52778],
"121": [0.19444, 0.43056, 0.01389, 0, 0.52778],
"122": [0, 0.43056, 0, 0, 0.44445],
"123": [0.25, 0.75, 0, 0, 0.5],
"124": [0.25, 0.75, 0, 0, 0.27778],
"125": [0.25, 0.75, 0, 0, 0.5],
"126": [0.35, 0.31786, 0, 0, 0.5],
"160": [0, 0, 0, 0, 0.25],
"163": [0, 0.69444, 0, 0, 0.76909],
"167": [0.19444, 0.69444, 0, 0, 0.44445],
"168": [0, 0.66786, 0, 0, 0.5],
"172": [0, 0.43056, 0, 0, 0.66667],
"176": [0, 0.69444, 0, 0, 0.75],
"177": [0.08333, 0.58333, 0, 0, 0.77778],
"182": [0.19444, 0.69444, 0, 0, 0.61111],
"184": [0.17014, 0, 0, 0, 0.44445],
"198": [0, 0.68333, 0, 0, 0.90278],
"215": [0.08333, 0.58333, 0, 0, 0.77778],
"216": [0.04861, 0.73194, 0, 0, 0.77778],
"223": [0, 0.69444, 0, 0, 0.5],
"230": [0, 0.43056, 0, 0, 0.72222],
"247": [0.08333, 0.58333, 0, 0, 0.77778],
"248": [0.09722, 0.52778, 0, 0, 0.5],
"305": [0, 0.43056, 0, 0, 0.27778],
"338": [0, 0.68333, 0, 0, 1.01389],
"339": [0, 0.43056, 0, 0, 0.77778],
"567": [0.19444, 0.43056, 0, 0, 0.30556],
"710": [0, 0.69444, 0, 0, 0.5],
"711": [0, 0.62847, 0, 0, 0.5],
"713": [0, 0.56778, 0, 0, 0.5],
"714": [0, 0.69444, 0, 0, 0.5],
"715": [0, 0.69444, 0, 0, 0.5],
"728": [0, 0.69444, 0, 0, 0.5],
"729": [0, 0.66786, 0, 0, 0.27778],
"730": [0, 0.69444, 0, 0, 0.75],
"732": [0, 0.66786, 0, 0, 0.5],
"733": [0, 0.69444, 0, 0, 0.5],
"915": [0, 0.68333, 0, 0, 0.625],
"916": [0, 0.68333, 0, 0, 0.83334],
"920": [0, 0.68333, 0, 0, 0.77778],
"923": [0, 0.68333, 0, 0, 0.69445],
"926": [0, 0.68333, 0, 0, 0.66667],
"928": [0, 0.68333, 0, 0, 0.75],
"931": [0, 0.68333, 0, 0, 0.72222],
"933": [0, 0.68333, 0, 0, 0.77778],
"934": [0, 0.68333, 0, 0, 0.72222],
"936": [0, 0.68333, 0, 0, 0.77778],
"937": [0, 0.68333, 0, 0, 0.72222],
"8211": [0, 0.43056, 0.02778, 0, 0.5],
"8212": [0, 0.43056, 0.02778, 0, 1.0],
"8216": [0, 0.69444, 0, 0, 0.27778],
"8217": [0, 0.69444, 0, 0, 0.27778],
"8220": [0, 0.69444, 0, 0, 0.5],
"8221": [0, 0.69444, 0, 0, 0.5],
"8224": [0.19444, 0.69444, 0, 0, 0.44445],
"8225": [0.19444, 0.69444, 0, 0, 0.44445],
"8230": [0, 0.123, 0, 0, 1.172],
"8242": [0, 0.55556, 0, 0, 0.275],
"8407": [0, 0.71444, 0.15382, 0, 0.5],
"8463": [0, 0.68889, 0, 0, 0.54028],
"8465": [0, 0.69444, 0, 0, 0.72222],
"8467": [0, 0.69444, 0, 0.11111, 0.41667],
"8472": [0.19444, 0.43056, 0, 0.11111, 0.63646],
"8476": [0, 0.69444, 0, 0, 0.72222],
"8501": [0, 0.69444, 0, 0, 0.61111],
"8592": [-0.13313, 0.36687, 0, 0, 1.0],
"8593": [0.19444, 0.69444, 0, 0, 0.5],
"8594": [-0.13313, 0.36687, 0, 0, 1.0],
"8595": [0.19444, 0.69444, 0, 0, 0.5],
"8596": [-0.13313, 0.36687, 0, 0, 1.0],
"8597": [0.25, 0.75, 0, 0, 0.5],
"8598": [0.19444, 0.69444, 0, 0, 1.0],
"8599": [0.19444, 0.69444, 0, 0, 1.0],
"8600": [0.19444, 0.69444, 0, 0, 1.0],
"8601": [0.19444, 0.69444, 0, 0, 1.0],
"8614": [0.011, 0.511, 0, 0, 1.0],
"8617": [0.011, 0.511, 0, 0, 1.126],
"8618": [0.011, 0.511, 0, 0, 1.126],
"8636": [-0.13313, 0.36687, 0, 0, 1.0],
"8637": [-0.13313, 0.36687, 0, 0, 1.0],
"8640": [-0.13313, 0.36687, 0, 0, 1.0],
"8641": [-0.13313, 0.36687, 0, 0, 1.0],
"8652": [0.011, 0.671, 0, 0, 1.0],
"8656": [-0.13313, 0.36687, 0, 0, 1.0],
"8657": [0.19444, 0.69444, 0, 0, 0.61111],
"8658": [-0.13313, 0.36687, 0, 0, 1.0],
"8659": [0.19444, 0.69444, 0, 0, 0.61111],
"8660": [-0.13313, 0.36687, 0, 0, 1.0],
"8661": [0.25, 0.75, 0, 0, 0.61111],
"8704": [0, 0.69444, 0, 0, 0.55556],
"8706": [0, 0.69444, 0.05556, 0.08334, 0.5309],
"8707": [0, 0.69444, 0, 0, 0.55556],
"8709": [0.05556, 0.75, 0, 0, 0.5],
"8711": [0, 0.68333, 0, 0, 0.83334],
"8712": [0.0391, 0.5391, 0, 0, 0.66667],
"8715": [0.0391, 0.5391, 0, 0, 0.66667],
"8722": [0.08333, 0.58333, 0, 0, 0.77778],
"8723": [0.08333, 0.58333, 0, 0, 0.77778],
"8725": [0.25, 0.75, 0, 0, 0.5],
"8726": [0.25, 0.75, 0, 0, 0.5],
"8727": [-0.03472, 0.46528, 0, 0, 0.5],
"8728": [-0.05555, 0.44445, 0, 0, 0.5],
"8729": [-0.05555, 0.44445, 0, 0, 0.5],
"8730": [0.2, 0.8, 0, 0, 0.83334],
"8733": [0, 0.43056, 0, 0, 0.77778],
"8734": [0, 0.43056, 0, 0, 1.0],
"8736": [0, 0.69224, 0, 0, 0.72222],
"8739": [0.25, 0.75, 0, 0, 0.27778],
"8741": [0.25, 0.75, 0, 0, 0.5],
"8743": [0, 0.55556, 0, 0, 0.66667],
"8744": [0, 0.55556, 0, 0, 0.66667],
"8745": [0, 0.55556, 0, 0, 0.66667],
"8746": [0, 0.55556, 0, 0, 0.66667],
"8747": [0.19444, 0.69444, 0.11111, 0, 0.41667],
"8764": [-0.13313, 0.36687, 0, 0, 0.77778],
"8768": [0.19444, 0.69444, 0, 0, 0.27778],
"8771": [-0.03625, 0.46375, 0, 0, 0.77778],
"8773": [-0.022, 0.589, 0, 0, 0.778],
"8776": [-0.01688, 0.48312, 0, 0, 0.77778],
"8781": [-0.03625, 0.46375, 0, 0, 0.77778],
"8784": [-0.133, 0.673, 0, 0, 0.778],
"8801": [-0.03625, 0.46375, 0, 0, 0.77778],
"8804": [0.13597, 0.63597, 0, 0, 0.77778],
"8805": [0.13597, 0.63597, 0, 0, 0.77778],
"8810": [0.0391, 0.5391, 0, 0, 1.0],
"8811": [0.0391, 0.5391, 0, 0, 1.0],
"8826": [0.0391, 0.5391, 0, 0, 0.77778],
"8827": [0.0391, 0.5391, 0, 0, 0.77778],
"8834": [0.0391, 0.5391, 0, 0, 0.77778],
"8835": [0.0391, 0.5391, 0, 0, 0.77778],
"8838": [0.13597, 0.63597, 0, 0, 0.77778],
"8839": [0.13597, 0.63597, 0, 0, 0.77778],
"8846": [0, 0.55556, 0, 0, 0.66667],
"8849": [0.13597, 0.63597, 0, 0, 0.77778],
"8850": [0.13597, 0.63597, 0, 0, 0.77778],
"8851": [0, 0.55556, 0, 0, 0.66667],
"8852": [0, 0.55556, 0, 0, 0.66667],
"8853": [0.08333, 0.58333, 0, 0, 0.77778],
"8854": [0.08333, 0.58333, 0, 0, 0.77778],
"8855": [0.08333, 0.58333, 0, 0, 0.77778],
"8856": [0.08333, 0.58333, 0, 0, 0.77778],
"8857": [0.08333, 0.58333, 0, 0, 0.77778],
"8866": [0, 0.69444, 0, 0, 0.61111],
"8867": [0, 0.69444, 0, 0, 0.61111],
"8868": [0, 0.69444, 0, 0, 0.77778],
"8869": [0, 0.69444, 0, 0, 0.77778],
"8872": [0.249, 0.75, 0, 0, 0.867],
"8900": [-0.05555, 0.44445, 0, 0, 0.5],
"8901": [-0.05555, 0.44445, 0, 0, 0.27778],
"8902": [-0.03472, 0.46528, 0, 0, 0.5],
"8904": [0.005, 0.505, 0, 0, 0.9],
"8942": [0.03, 0.903, 0, 0, 0.278],
"8943": [-0.19, 0.313, 0, 0, 1.172],
"8945": [-0.1, 0.823, 0, 0, 1.282],
"8968": [0.25, 0.75, 0, 0, 0.44445],
"8969": [0.25, 0.75, 0, 0, 0.44445],
"8970": [0.25, 0.75, 0, 0, 0.44445],
"8971": [0.25, 0.75, 0, 0, 0.44445],
"8994": [-0.14236, 0.35764, 0, 0, 1.0],
"8995": [-0.14236, 0.35764, 0, 0, 1.0],
"9136": [0.244, 0.744, 0, 0, 0.412],
"9137": [0.244, 0.745, 0, 0, 0.412],
"9651": [0.19444, 0.69444, 0, 0, 0.88889],
"9657": [-0.03472, 0.46528, 0, 0, 0.5],
"9661": [0.19444, 0.69444, 0, 0, 0.88889],
"9667": [-0.03472, 0.46528, 0, 0, 0.5],
"9711": [0.19444, 0.69444, 0, 0, 1.0],
"9824": [0.12963, 0.69444, 0, 0, 0.77778],
"9825": [0.12963, 0.69444, 0, 0, 0.77778],
"9826": [0.12963, 0.69444, 0, 0, 0.77778],
"9827": [0.12963, 0.69444, 0, 0, 0.77778],
"9837": [0, 0.75, 0, 0, 0.38889],
"9838": [0.19444, 0.69444, 0, 0, 0.38889],
"9839": [0.19444, 0.69444, 0, 0, 0.38889],
"10216": [0.25, 0.75, 0, 0, 0.38889],
"10217": [0.25, 0.75, 0, 0, 0.38889],
"10222": [0.244, 0.744, 0, 0, 0.412],
"10223": [0.244, 0.745, 0, 0, 0.412],
"10229": [0.011, 0.511, 0, 0, 1.609],
"10230": [0.011, 0.511, 0, 0, 1.638],
"10231": [0.011, 0.511, 0, 0, 1.859],
"10232": [0.024, 0.525, 0, 0, 1.609],
"10233": [0.024, 0.525, 0, 0, 1.638],
"10234": [0.024, 0.525, 0, 0, 1.858],
"10236": [0.011, 0.511, 0, 0, 1.638],
"10815": [0, 0.68333, 0, 0, 0.75],
"10927": [0.13597, 0.63597, 0, 0, 0.77778],
"10928": [0.13597, 0.63597, 0, 0, 0.77778],
"57376": [0.19444, 0.69444, 0, 0, 0]
},
"Math-BoldItalic": {
"32": [0, 0, 0, 0, 0.25],
"48": [0, 0.44444, 0, 0, 0.575],
"49": [0, 0.44444, 0, 0, 0.575],
"50": [0, 0.44444, 0, 0, 0.575],
"51": [0.19444, 0.44444, 0, 0, 0.575],
"52": [0.19444, 0.44444, 0, 0, 0.575],
"53": [0.19444, 0.44444, 0, 0, 0.575],
"54": [0, 0.64444, 0, 0, 0.575],
"55": [0.19444, 0.44444, 0, 0, 0.575],
"56": [0, 0.64444, 0, 0, 0.575],
"57": [0.19444, 0.44444, 0, 0, 0.575],
"65": [0, 0.68611, 0, 0, 0.86944],
"66": [0, 0.68611, 0.04835, 0, 0.8664],
"67": [0, 0.68611, 0.06979, 0, 0.81694],
"68": [0, 0.68611, 0.03194, 0, 0.93812],
"69": [0, 0.68611, 0.05451, 0, 0.81007],
"70": [0, 0.68611, 0.15972, 0, 0.68889],
"71": [0, 0.68611, 0, 0, 0.88673],
"72": [0, 0.68611, 0.08229, 0, 0.98229],
"73": [0, 0.68611, 0.07778, 0, 0.51111],
"74": [0, 0.68611, 0.10069, 0, 0.63125],
"75": [0, 0.68611, 0.06979, 0, 0.97118],
"76": [0, 0.68611, 0, 0, 0.75555],
"77": [0, 0.68611, 0.11424, 0, 1.14201],
"78": [0, 0.68611, 0.11424, 0, 0.95034],
"79": [0, 0.68611, 0.03194, 0, 0.83666],
"80": [0, 0.68611, 0.15972, 0, 0.72309],
"81": [0.19444, 0.68611, 0, 0, 0.86861],
"82": [0, 0.68611, 0.00421, 0, 0.87235],
"83": [0, 0.68611, 0.05382, 0, 0.69271],
"84": [0, 0.68611, 0.15972, 0, 0.63663],
"85": [0, 0.68611, 0.11424, 0, 0.80027],
"86": [0, 0.68611, 0.25555, 0, 0.67778],
"87": [0, 0.68611, 0.15972, 0, 1.09305],
"88": [0, 0.68611, 0.07778, 0, 0.94722],
"89": [0, 0.68611, 0.25555, 0, 0.67458],
"90": [0, 0.68611, 0.06979, 0, 0.77257],
"97": [0, 0.44444, 0, 0, 0.63287],
"98": [0, 0.69444, 0, 0, 0.52083],
"99": [0, 0.44444, 0, 0, 0.51342],
"100": [0, 0.69444, 0, 0, 0.60972],
"101": [0, 0.44444, 0, 0, 0.55361],
"102": [0.19444, 0.69444, 0.11042, 0, 0.56806],
"103": [0.19444, 0.44444, 0.03704, 0, 0.5449],
"104": [0, 0.69444, 0, 0, 0.66759],
"105": [0, 0.69326, 0, 0, 0.4048],
"106": [0.19444, 0.69326, 0.0622, 0, 0.47083],
"107": [0, 0.69444, 0.01852, 0, 0.6037],
"108": [0, 0.69444, 0.0088, 0, 0.34815],
"109": [0, 0.44444, 0, 0, 1.0324],
"110": [0, 0.44444, 0, 0, 0.71296],
"111": [0, 0.44444, 0, 0, 0.58472],
"112": [0.19444, 0.44444, 0, 0, 0.60092],
"113": [0.19444, 0.44444, 0.03704, 0, 0.54213],
"114": [0, 0.44444, 0.03194, 0, 0.5287],
"115": [0, 0.44444, 0, 0, 0.53125],
"116": [0, 0.63492, 0, 0, 0.41528],
"117": [0, 0.44444, 0, 0, 0.68102],
"118": [0, 0.44444, 0.03704, 0, 0.56666],
"119": [0, 0.44444, 0.02778, 0, 0.83148],
"120": [0, 0.44444, 0, 0, 0.65903],
"121": [0.19444, 0.44444, 0.03704, 0, 0.59028],
"122": [0, 0.44444, 0.04213, 0, 0.55509],
"160": [0, 0, 0, 0, 0.25],
"915": [0, 0.68611, 0.15972, 0, 0.65694],
"916": [0, 0.68611, 0, 0, 0.95833],
"920": [0, 0.68611, 0.03194, 0, 0.86722],
"923": [0, 0.68611, 0, 0, 0.80555],
"926": [0, 0.68611, 0.07458, 0, 0.84125],
"928": [0, 0.68611, 0.08229, 0, 0.98229],
"931": [0, 0.68611, 0.05451, 0, 0.88507],
"933": [0, 0.68611, 0.15972, 0, 0.67083],
"934": [0, 0.68611, 0, 0, 0.76666],
"936": [0, 0.68611, 0.11653, 0, 0.71402],
"937": [0, 0.68611, 0.04835, 0, 0.8789],
"945": [0, 0.44444, 0, 0, 0.76064],
"946": [0.19444, 0.69444, 0.03403, 0, 0.65972],
"947": [0.19444, 0.44444, 0.06389, 0, 0.59003],
"948": [0, 0.69444, 0.03819, 0, 0.52222],
"949": [0, 0.44444, 0, 0, 0.52882],
"950": [0.19444, 0.69444, 0.06215, 0, 0.50833],
"951": [0.19444, 0.44444, 0.03704, 0, 0.6],
"952": [0, 0.69444, 0.03194, 0, 0.5618],
"953": [0, 0.44444, 0, 0, 0.41204],
"954": [0, 0.44444, 0, 0, 0.66759],
"955": [0, 0.69444, 0, 0, 0.67083],
"956": [0.19444, 0.44444, 0, 0, 0.70787],
"957": [0, 0.44444, 0.06898, 0, 0.57685],
"958": [0.19444, 0.69444, 0.03021, 0, 0.50833],
"959": [0, 0.44444, 0, 0, 0.58472],
"960": [0, 0.44444, 0.03704, 0, 0.68241],
"961": [0.19444, 0.44444, 0, 0, 0.6118],
"962": [0.09722, 0.44444, 0.07917, 0, 0.42361],
"963": [0, 0.44444, 0.03704, 0, 0.68588],
"964": [0, 0.44444, 0.13472, 0, 0.52083],
"965": [0, 0.44444, 0.03704, 0, 0.63055],
"966": [0.19444, 0.44444, 0, 0, 0.74722],
"967": [0.19444, 0.44444, 0, 0, 0.71805],
"968": [0.19444, 0.69444, 0.03704, 0, 0.75833],
"969": [0, 0.44444, 0.03704, 0, 0.71782],
"977": [0, 0.69444, 0, 0, 0.69155],
"981": [0.19444, 0.69444, 0, 0, 0.7125],
"982": [0, 0.44444, 0.03194, 0, 0.975],
"1009": [0.19444, 0.44444, 0, 0, 0.6118],
"1013": [0, 0.44444, 0, 0, 0.48333],
"57649": [0, 0.44444, 0, 0, 0.39352],
"57911": [0.19444, 0.44444, 0, 0, 0.43889]
},
"Math-Italic": {
"32": [0, 0, 0, 0, 0.25],
"48": [0, 0.43056, 0, 0, 0.5],
"49": [0, 0.43056, 0, 0, 0.5],
"50": [0, 0.43056, 0, 0, 0.5],
"51": [0.19444, 0.43056, 0, 0, 0.5],
"52": [0.19444, 0.43056, 0, 0, 0.5],
"53": [0.19444, 0.43056, 0, 0, 0.5],
"54": [0, 0.64444, 0, 0, 0.5],
"55": [0.19444, 0.43056, 0, 0, 0.5],
"56": [0, 0.64444, 0, 0, 0.5],
"57": [0.19444, 0.43056, 0, 0, 0.5],
"65": [0, 0.68333, 0, 0.13889, 0.75],
"66": [0, 0.68333, 0.05017, 0.08334, 0.75851],
"67": [0, 0.68333, 0.07153, 0.08334, 0.71472],
"68": [0, 0.68333, 0.02778, 0.05556, 0.82792],
"69": [0, 0.68333, 0.05764, 0.08334, 0.7382],
"70": [0, 0.68333, 0.13889, 0.08334, 0.64306],
"71": [0, 0.68333, 0, 0.08334, 0.78625],
"72": [0, 0.68333, 0.08125, 0.05556, 0.83125],
"73": [0, 0.68333, 0.07847, 0.11111, 0.43958],
"74": [0, 0.68333, 0.09618, 0.16667, 0.55451],
"75": [0, 0.68333, 0.07153, 0.05556, 0.84931],
"76": [0, 0.68333, 0, 0.02778, 0.68056],
"77": [0, 0.68333, 0.10903, 0.08334, 0.97014],
"78": [0, 0.68333, 0.10903, 0.08334, 0.80347],
"79": [0, 0.68333, 0.02778, 0.08334, 0.76278],
"80": [0, 0.68333, 0.13889, 0.08334, 0.64201],
"81": [0.19444, 0.68333, 0, 0.08334, 0.79056],
"82": [0, 0.68333, 0.00773, 0.08334, 0.75929],
"83": [0, 0.68333, 0.05764, 0.08334, 0.6132],
"84": [0, 0.68333, 0.13889, 0.08334, 0.58438],
"85": [0, 0.68333, 0.10903, 0.02778, 0.68278],
"86": [0, 0.68333, 0.22222, 0, 0.58333],
"87": [0, 0.68333, 0.13889, 0, 0.94445],
"88": [0, 0.68333, 0.07847, 0.08334, 0.82847],
"89": [0, 0.68333, 0.22222, 0, 0.58056],
"90": [0, 0.68333, 0.07153, 0.08334, 0.68264],
"97": [0, 0.43056, 0, 0, 0.52859],
"98": [0, 0.69444, 0, 0, 0.42917],
"99": [0, 0.43056, 0, 0.05556, 0.43276],
"100": [0, 0.69444, 0, 0.16667, 0.52049],
"101": [0, 0.43056, 0, 0.05556, 0.46563],
"102": [0.19444, 0.69444, 0.10764, 0.16667, 0.48959],
"103": [0.19444, 0.43056, 0.03588, 0.02778, 0.47697],
"104": [0, 0.69444, 0, 0, 0.57616],
"105": [0, 0.65952, 0, 0, 0.34451],
"106": [0.19444, 0.65952, 0.05724, 0, 0.41181],
"107": [0, 0.69444, 0.03148, 0, 0.5206],
"108": [0, 0.69444, 0.01968, 0.08334, 0.29838],
"109": [0, 0.43056, 0, 0, 0.87801],
"110": [0, 0.43056, 0, 0, 0.60023],
"111": [0, 0.43056, 0, 0.05556, 0.48472],
"112": [0.19444, 0.43056, 0, 0.08334, 0.50313],
"113": [0.19444, 0.43056, 0.03588, 0.08334, 0.44641],
"114": [0, 0.43056, 0.02778, 0.05556, 0.45116],
"115": [0, 0.43056, 0, 0.05556, 0.46875],
"116": [0, 0.61508, 0, 0.08334, 0.36111],
"117": [0, 0.43056, 0, 0.02778, 0.57246],
"118": [0, 0.43056, 0.03588, 0.02778, 0.48472],
"119": [0, 0.43056, 0.02691, 0.08334, 0.71592],
"120": [0, 0.43056, 0, 0.02778, 0.57153],
"121": [0.19444, 0.43056, 0.03588, 0.05556, 0.49028],
"122": [0, 0.43056, 0.04398, 0.05556, 0.46505],
"160": [0, 0, 0, 0, 0.25],
"915": [0, 0.68333, 0.13889, 0.08334, 0.61528],
"916": [0, 0.68333, 0, 0.16667, 0.83334],
"920": [0, 0.68333, 0.02778, 0.08334, 0.76278],
"923": [0, 0.68333, 0, 0.16667, 0.69445],
"926": [0, 0.68333, 0.07569, 0.08334, 0.74236],
"928": [0, 0.68333, 0.08125, 0.05556, 0.83125],
"931": [0, 0.68333, 0.05764, 0.08334, 0.77986],
"933": [0, 0.68333, 0.13889, 0.05556, 0.58333],
"934": [0, 0.68333, 0, 0.08334, 0.66667],
"936": [0, 0.68333, 0.11, 0.05556, 0.61222],
"937": [0, 0.68333, 0.05017, 0.08334, 0.7724],
"945": [0, 0.43056, 0.0037, 0.02778, 0.6397],
"946": [0.19444, 0.69444, 0.05278, 0.08334, 0.56563],
"947": [0.19444, 0.43056, 0.05556, 0, 0.51773],
"948": [0, 0.69444, 0.03785, 0.05556, 0.44444],
"949": [0, 0.43056, 0, 0.08334, 0.46632],
"950": [0.19444, 0.69444, 0.07378, 0.08334, 0.4375],
"951": [0.19444, 0.43056, 0.03588, 0.05556, 0.49653],
"952": [0, 0.69444, 0.02778, 0.08334, 0.46944],
"953": [0, 0.43056, 0, 0.05556, 0.35394],
"954": [0, 0.43056, 0, 0, 0.57616],
"955": [0, 0.69444, 0, 0, 0.58334],
"956": [0.19444, 0.43056, 0, 0.02778, 0.60255],
"957": [0, 0.43056, 0.06366, 0.02778, 0.49398],
"958": [0.19444, 0.69444, 0.04601, 0.11111, 0.4375],
"959": [0, 0.43056, 0, 0.05556, 0.48472],
"960": [0, 0.43056, 0.03588, 0, 0.57003],
"961": [0.19444, 0.43056, 0, 0.08334, 0.51702],
"962": [0.09722, 0.43056, 0.07986, 0.08334, 0.36285],
"963": [0, 0.43056, 0.03588, 0, 0.57141],
"964": [0, 0.43056, 0.1132, 0.02778, 0.43715],
"965": [0, 0.43056, 0.03588, 0.02778, 0.54028],
"966": [0.19444, 0.43056, 0, 0.08334, 0.65417],
"967": [0.19444, 0.43056, 0, 0.05556, 0.62569],
"968": [0.19444, 0.69444, 0.03588, 0.11111, 0.65139],
"969": [0, 0.43056, 0.03588, 0, 0.62245],
"977": [0, 0.69444, 0, 0.08334, 0.59144],
"981": [0.19444, 0.69444, 0, 0.08334, 0.59583],
"982": [0, 0.43056, 0.02778, 0, 0.82813],
"1009": [0.19444, 0.43056, 0, 0.08334, 0.51702],
"1013": [0, 0.43056, 0, 0.05556, 0.4059],
"57649": [0, 0.43056, 0, 0.02778, 0.32246],
"57911": [0.19444, 0.43056, 0, 0.08334, 0.38403]
},
"SansSerif-Bold": {
"32": [0, 0, 0, 0, 0.25],
"33": [0, 0.69444, 0, 0, 0.36667],
"34": [0, 0.69444, 0, 0, 0.55834],
"35": [0.19444, 0.69444, 0, 0, 0.91667],
"36": [0.05556, 0.75, 0, 0, 0.55],
"37": [0.05556, 0.75, 0, 0, 1.02912],
"38": [0, 0.69444, 0, 0, 0.83056],
"39": [0, 0.69444, 0, 0, 0.30556],
"40": [0.25, 0.75, 0, 0, 0.42778],
"41": [0.25, 0.75, 0, 0, 0.42778],
"42": [0, 0.75, 0, 0, 0.55],
"43": [0.11667, 0.61667, 0, 0, 0.85556],
"44": [0.10556, 0.13056, 0, 0, 0.30556],
"45": [0, 0.45833, 0, 0, 0.36667],
"46": [0, 0.13056, 0, 0, 0.30556],
"47": [0.25, 0.75, 0, 0, 0.55],
"48": [0, 0.69444, 0, 0, 0.55],
"49": [0, 0.69444, 0, 0, 0.55],
"50": [0, 0.69444, 0, 0, 0.55],
"51": [0, 0.69444, 0, 0, 0.55],
"52": [0, 0.69444, 0, 0, 0.55],
"53": [0, 0.69444, 0, 0, 0.55],
"54": [0, 0.69444, 0, 0, 0.55],
"55": [0, 0.69444, 0, 0, 0.55],
"56": [0, 0.69444, 0, 0, 0.55],
"57": [0, 0.69444, 0, 0, 0.55],
"58": [0, 0.45833, 0, 0, 0.30556],
"59": [0.10556, 0.45833, 0, 0, 0.30556],
"61": [-0.09375, 0.40625, 0, 0, 0.85556],
"63": [0, 0.69444, 0, 0, 0.51945],
"64": [0, 0.69444, 0, 0, 0.73334],
"65": [0, 0.69444, 0, 0, 0.73334],
"66": [0, 0.69444, 0, 0, 0.73334],
"67": [0, 0.69444, 0, 0, 0.70278],
"68": [0, 0.69444, 0, 0, 0.79445],
"69": [0, 0.69444, 0, 0, 0.64167],
"70": [0, 0.69444, 0, 0, 0.61111],
"71": [0, 0.69444, 0, 0, 0.73334],
"72": [0, 0.69444, 0, 0, 0.79445],
"73": [0, 0.69444, 0, 0, 0.33056],
"74": [0, 0.69444, 0, 0, 0.51945],
"75": [0, 0.69444, 0, 0, 0.76389],
"76": [0, 0.69444, 0, 0, 0.58056],
"77": [0, 0.69444, 0, 0, 0.97778],
"78": [0, 0.69444, 0, 0, 0.79445],
"79": [0, 0.69444, 0, 0, 0.79445],
"80": [0, 0.69444, 0, 0, 0.70278],
"81": [0.10556, 0.69444, 0, 0, 0.79445],
"82": [0, 0.69444, 0, 0, 0.70278],
"83": [0, 0.69444, 0, 0, 0.61111],
"84": [0, 0.69444, 0, 0, 0.73334],
"85": [0, 0.69444, 0, 0, 0.76389],
"86": [0, 0.69444, 0.01528, 0, 0.73334],
"87": [0, 0.69444, 0.01528, 0, 1.03889],
"88": [0, 0.69444, 0, 0, 0.73334],
"89": [0, 0.69444, 0.0275, 0, 0.73334],
"90": [0, 0.69444, 0, 0, 0.67223],
"91": [0.25, 0.75, 0, 0, 0.34306],
"93": [0.25, 0.75, 0, 0, 0.34306],
"94": [0, 0.69444, 0, 0, 0.55],
"95": [0.35, 0.10833, 0.03056, 0, 0.55],
"97": [0, 0.45833, 0, 0, 0.525],
"98": [0, 0.69444, 0, 0, 0.56111],
"99": [0, 0.45833, 0, 0, 0.48889],
"100": [0, 0.69444, 0, 0, 0.56111],
"101": [0, 0.45833, 0, 0, 0.51111],
"102": [0, 0.69444, 0.07639, 0, 0.33611],
"103": [0.19444, 0.45833, 0.01528, 0, 0.55],
"104": [0, 0.69444, 0, 0, 0.56111],
"105": [0, 0.69444, 0, 0, 0.25556],
"106": [0.19444, 0.69444, 0, 0, 0.28611],
"107": [0, 0.69444, 0, 0, 0.53056],
"108": [0, 0.69444, 0, 0, 0.25556],
"109": [0, 0.45833, 0, 0, 0.86667],
"110": [0, 0.45833, 0, 0, 0.56111],
"111": [0, 0.45833, 0, 0, 0.55],
"112": [0.19444, 0.45833, 0, 0, 0.56111],
"113": [0.19444, 0.45833, 0, 0, 0.56111],
"114": [0, 0.45833, 0.01528, 0, 0.37222],
"115": [0, 0.45833, 0, 0, 0.42167],
"116": [0, 0.58929, 0, 0, 0.40417],
"117": [0, 0.45833, 0, 0, 0.56111],
"118": [0, 0.45833, 0.01528, 0, 0.5],
"119": [0, 0.45833, 0.01528, 0, 0.74445],
"120": [0, 0.45833, 0, 0, 0.5],
"121": [0.19444, 0.45833, 0.01528, 0, 0.5],
"122": [0, 0.45833, 0, 0, 0.47639],
"126": [0.35, 0.34444, 0, 0, 0.55],
"160": [0, 0, 0, 0, 0.25],
"168": [0, 0.69444, 0, 0, 0.55],
"176": [0, 0.69444, 0, 0, 0.73334],
"180": [0, 0.69444, 0, 0, 0.55],
"184": [0.17014, 0, 0, 0, 0.48889],
"305": [0, 0.45833, 0, 0, 0.25556],
"567": [0.19444, 0.45833, 0, 0, 0.28611],
"710": [0, 0.69444, 0, 0, 0.55],
"711": [0, 0.63542, 0, 0, 0.55],
"713": [0, 0.63778, 0, 0, 0.55],
"728": [0, 0.69444, 0, 0, 0.55],
"729": [0, 0.69444, 0, 0, 0.30556],
"730": [0, 0.69444, 0, 0, 0.73334],
"732": [0, 0.69444, 0, 0, 0.55],
"733": [0, 0.69444, 0, 0, 0.55],
"915": [0, 0.69444, 0, 0, 0.58056],
"916": [0, 0.69444, 0, 0, 0.91667],
"920": [0, 0.69444, 0, 0, 0.85556],
"923": [0, 0.69444, 0, 0, 0.67223],
"926": [0, 0.69444, 0, 0, 0.73334],
"928": [0, 0.69444, 0, 0, 0.79445],
"931": [0, 0.69444, 0, 0, 0.79445],
"933": [0, 0.69444, 0, 0, 0.85556],
"934": [0, 0.69444, 0, 0, 0.79445],
"936": [0, 0.69444, 0, 0, 0.85556],
"937": [0, 0.69444, 0, 0, 0.79445],
"8211": [0, 0.45833, 0.03056, 0, 0.55],
"8212": [0, 0.45833, 0.03056, 0, 1.10001],
"8216": [0, 0.69444, 0, 0, 0.30556],
"8217": [0, 0.69444, 0, 0, 0.30556],
"8220": [0, 0.69444, 0, 0, 0.55834],
"8221": [0, 0.69444, 0, 0, 0.55834]
},
"SansSerif-Italic": {
"32": [0, 0, 0, 0, 0.25],
"33": [0, 0.69444, 0.05733, 0, 0.31945],
"34": [0, 0.69444, 0.00316, 0, 0.5],
"35": [0.19444, 0.69444, 0.05087, 0, 0.83334],
"36": [0.05556, 0.75, 0.11156, 0, 0.5],
"37": [0.05556, 0.75, 0.03126, 0, 0.83334],
"38": [0, 0.69444, 0.03058, 0, 0.75834],
"39": [0, 0.69444, 0.07816, 0, 0.27778],
"40": [0.25, 0.75, 0.13164, 0, 0.38889],
"41": [0.25, 0.75, 0.02536, 0, 0.38889],
"42": [0, 0.75, 0.11775, 0, 0.5],
"43": [0.08333, 0.58333, 0.02536, 0, 0.77778],
"44": [0.125, 0.08333, 0, 0, 0.27778],
"45": [0, 0.44444, 0.01946, 0, 0.33333],
"46": [0, 0.08333, 0, 0, 0.27778],
"47": [0.25, 0.75, 0.13164, 0, 0.5],
"48": [0, 0.65556, 0.11156, 0, 0.5],
"49": [0, 0.65556, 0.11156, 0, 0.5],
"50": [0, 0.65556, 0.11156, 0, 0.5],
"51": [0, 0.65556, 0.11156, 0, 0.5],
"52": [0, 0.65556, 0.11156, 0, 0.5],
"53": [0, 0.65556, 0.11156, 0, 0.5],
"54": [0, 0.65556, 0.11156, 0, 0.5],
"55": [0, 0.65556, 0.11156, 0, 0.5],
"56": [0, 0.65556, 0.11156, 0, 0.5],
"57": [0, 0.65556, 0.11156, 0, 0.5],
"58": [0, 0.44444, 0.02502, 0, 0.27778],
"59": [0.125, 0.44444, 0.02502, 0, 0.27778],
"61": [-0.13, 0.37, 0.05087, 0, 0.77778],
"63": [0, 0.69444, 0.11809, 0, 0.47222],
"64": [0, 0.69444, 0.07555, 0, 0.66667],
"65": [0, 0.69444, 0, 0, 0.66667],
"66": [0, 0.69444, 0.08293, 0, 0.66667],
"67": [0, 0.69444, 0.11983, 0, 0.63889],
"68": [0, 0.69444, 0.07555, 0, 0.72223],
"69": [0, 0.69444, 0.11983, 0, 0.59722],
"70": [0, 0.69444, 0.13372, 0, 0.56945],
"71": [0, 0.69444, 0.11983, 0, 0.66667],
"72": [0, 0.69444, 0.08094, 0, 0.70834],
"73": [0, 0.69444, 0.13372, 0, 0.27778],
"74": [0, 0.69444, 0.08094, 0, 0.47222],
"75": [0, 0.69444, 0.11983, 0, 0.69445],
"76": [0, 0.69444, 0, 0, 0.54167],
"77": [0, 0.69444, 0.08094, 0, 0.875],
"78": [0, 0.69444, 0.08094, 0, 0.70834],
"79": [0, 0.69444, 0.07555, 0, 0.73611],
"80": [0, 0.69444, 0.08293, 0, 0.63889],
"81": [0.125, 0.69444, 0.07555, 0, 0.73611],
"82": [0, 0.69444, 0.08293, 0, 0.64584],
"83": [0, 0.69444, 0.09205, 0, 0.55556],
"84": [0, 0.69444, 0.13372, 0, 0.68056],
"85": [0, 0.69444, 0.08094, 0, 0.6875],
"86": [0, 0.69444, 0.1615, 0, 0.66667],
"87": [0, 0.69444, 0.1615, 0, 0.94445],
"88": [0, 0.69444, 0.13372, 0, 0.66667],
"89": [0, 0.69444, 0.17261, 0, 0.66667],
"90": [0, 0.69444, 0.11983, 0, 0.61111],
"91": [0.25, 0.75, 0.15942, 0, 0.28889],
"93": [0.25, 0.75, 0.08719, 0, 0.28889],
"94": [0, 0.69444, 0.0799, 0, 0.5],
"95": [0.35, 0.09444, 0.08616, 0, 0.5],
"97": [0, 0.44444, 0.00981, 0, 0.48056],
"98": [0, 0.69444, 0.03057, 0, 0.51667],
"99": [0, 0.44444, 0.08336, 0, 0.44445],
"100": [0, 0.69444, 0.09483, 0, 0.51667],
"101": [0, 0.44444, 0.06778, 0, 0.44445],
"102": [0, 0.69444, 0.21705, 0, 0.30556],
"103": [0.19444, 0.44444, 0.10836, 0, 0.5],
"104": [0, 0.69444, 0.01778, 0, 0.51667],
"105": [0, 0.67937, 0.09718, 0, 0.23889],
"106": [0.19444, 0.67937, 0.09162, 0, 0.26667],
"107": [0, 0.69444, 0.08336, 0, 0.48889],
"108": [0, 0.69444, 0.09483, 0, 0.23889],
"109": [0, 0.44444, 0.01778, 0, 0.79445],
"110": [0, 0.44444, 0.01778, 0, 0.51667],
"111": [0, 0.44444, 0.06613, 0, 0.5],
"112": [0.19444, 0.44444, 0.0389, 0, 0.51667],
"113": [0.19444, 0.44444, 0.04169, 0, 0.51667],
"114": [0, 0.44444, 0.10836, 0, 0.34167],
"115": [0, 0.44444, 0.0778, 0, 0.38333],
"116": [0, 0.57143, 0.07225, 0, 0.36111],
"117": [0, 0.44444, 0.04169, 0, 0.51667],
"118": [0, 0.44444, 0.10836, 0, 0.46111],
"119": [0, 0.44444, 0.10836, 0, 0.68334],
"120": [0, 0.44444, 0.09169, 0, 0.46111],
"121": [0.19444, 0.44444, 0.10836, 0, 0.46111],
"122": [0, 0.44444, 0.08752, 0, 0.43472],
"126": [0.35, 0.32659, 0.08826, 0, 0.5],
"160": [0, 0, 0, 0, 0.25],
"168": [0, 0.67937, 0.06385, 0, 0.5],
"176": [0, 0.69444, 0, 0, 0.73752],
"184": [0.17014, 0, 0, 0, 0.44445],
"305": [0, 0.44444, 0.04169, 0, 0.23889],
"567": [0.19444, 0.44444, 0.04169, 0, 0.26667],
"710": [0, 0.69444, 0.0799, 0, 0.5],
"711": [0, 0.63194, 0.08432, 0, 0.5],
"713": [0, 0.60889, 0.08776, 0, 0.5],
"714": [0, 0.69444, 0.09205, 0, 0.5],
"715": [0, 0.69444, 0, 0, 0.5],
"728": [0, 0.69444, 0.09483, 0, 0.5],
"729": [0, 0.67937, 0.07774, 0, 0.27778],
"730": [0, 0.69444, 0, 0, 0.73752],
"732": [0, 0.67659, 0.08826, 0, 0.5],
"733": [0, 0.69444, 0.09205, 0, 0.5],
"915": [0, 0.69444, 0.13372, 0, 0.54167],
"916": [0, 0.69444, 0, 0, 0.83334],
"920": [0, 0.69444, 0.07555, 0, 0.77778],
"923": [0, 0.69444, 0, 0, 0.61111],
"926": [0, 0.69444, 0.12816, 0, 0.66667],
"928": [0, 0.69444, 0.08094, 0, 0.70834],
"931": [0, 0.69444, 0.11983, 0, 0.72222],
"933": [0, 0.69444, 0.09031, 0, 0.77778],
"934": [0, 0.69444, 0.04603, 0, 0.72222],
"936": [0, 0.69444, 0.09031, 0, 0.77778],
"937": [0, 0.69444, 0.08293, 0, 0.72222],
"8211": [0, 0.44444, 0.08616, 0, 0.5],
"8212": [0, 0.44444, 0.08616, 0, 1.0],
"8216": [0, 0.69444, 0.07816, 0, 0.27778],
"8217": [0, 0.69444, 0.07816, 0, 0.27778],
"8220": [0, 0.69444, 0.14205, 0, 0.5],
"8221": [0, 0.69444, 0.00316, 0, 0.5]
},
"SansSerif-Regular": {
"32": [0, 0, 0, 0, 0.25],
"33": [0, 0.69444, 0, 0, 0.31945],
"34": [0, 0.69444, 0, 0, 0.5],
"35": [0.19444, 0.69444, 0, 0, 0.83334],
"36": [0.05556, 0.75, 0, 0, 0.5],
"37": [0.05556, 0.75, 0, 0, 0.83334],
"38": [0, 0.69444, 0, 0, 0.75834],
"39": [0, 0.69444, 0, 0, 0.27778],
"40": [0.25, 0.75, 0, 0, 0.38889],
"41": [0.25, 0.75, 0, 0, 0.38889],
"42": [0, 0.75, 0, 0, 0.5],
"43": [0.08333, 0.58333, 0, 0, 0.77778],
"44": [0.125, 0.08333, 0, 0, 0.27778],
"45": [0, 0.44444, 0, 0, 0.33333],
"46": [0, 0.08333, 0, 0, 0.27778],
"47": [0.25, 0.75, 0, 0, 0.5],
"48": [0, 0.65556, 0, 0, 0.5],
"49": [0, 0.65556, 0, 0, 0.5],
"50": [0, 0.65556, 0, 0, 0.5],
"51": [0, 0.65556, 0, 0, 0.5],
"52": [0, 0.65556, 0, 0, 0.5],
"53": [0, 0.65556, 0, 0, 0.5],
"54": [0, 0.65556, 0, 0, 0.5],
"55": [0, 0.65556, 0, 0, 0.5],
"56": [0, 0.65556, 0, 0, 0.5],
"57": [0, 0.65556, 0, 0, 0.5],
"58": [0, 0.44444, 0, 0, 0.27778],
"59": [0.125, 0.44444, 0, 0, 0.27778],
"61": [-0.13, 0.37, 0, 0, 0.77778],
"63": [0, 0.69444, 0, 0, 0.47222],
"64": [0, 0.69444, 0, 0, 0.66667],
"65": [0, 0.69444, 0, 0, 0.66667],
"66": [0, 0.69444, 0, 0, 0.66667],
"67": [0, 0.69444, 0, 0, 0.63889],
"68": [0, 0.69444, 0, 0, 0.72223],
"69": [0, 0.69444, 0, 0, 0.59722],
"70": [0, 0.69444, 0, 0, 0.56945],
"71": [0, 0.69444, 0, 0, 0.66667],
"72": [0, 0.69444, 0, 0, 0.70834],
"73": [0, 0.69444, 0, 0, 0.27778],
"74": [0, 0.69444, 0, 0, 0.47222],
"75": [0, 0.69444, 0, 0, 0.69445],
"76": [0, 0.69444, 0, 0, 0.54167],
"77": [0, 0.69444, 0, 0, 0.875],
"78": [0, 0.69444, 0, 0, 0.70834],
"79": [0, 0.69444, 0, 0, 0.73611],
"80": [0, 0.69444, 0, 0, 0.63889],
"81": [0.125, 0.69444, 0, 0, 0.73611],
"82": [0, 0.69444, 0, 0, 0.64584],
"83": [0, 0.69444, 0, 0, 0.55556],
"84": [0, 0.69444, 0, 0, 0.68056],
"85": [0, 0.69444, 0, 0, 0.6875],
"86": [0, 0.69444, 0.01389, 0, 0.66667],
"87": [0, 0.69444, 0.01389, 0, 0.94445],
"88": [0, 0.69444, 0, 0, 0.66667],
"89": [0, 0.69444, 0.025, 0, 0.66667],
"90": [0, 0.69444, 0, 0, 0.61111],
"91": [0.25, 0.75, 0, 0, 0.28889],
"93": [0.25, 0.75, 0, 0, 0.28889],
"94": [0, 0.69444, 0, 0, 0.5],
"95": [0.35, 0.09444, 0.02778, 0, 0.5],
"97": [0, 0.44444, 0, 0, 0.48056],
"98": [0, 0.69444, 0, 0, 0.51667],
"99": [0, 0.44444, 0, 0, 0.44445],
"100": [0, 0.69444, 0, 0, 0.51667],
"101": [0, 0.44444, 0, 0, 0.44445],
"102": [0, 0.69444, 0.06944, 0, 0.30556],
"103": [0.19444, 0.44444, 0.01389, 0, 0.5],
"104": [0, 0.69444, 0, 0, 0.51667],
"105": [0, 0.67937, 0, 0, 0.23889],
"106": [0.19444, 0.67937, 0, 0, 0.26667],
"107": [0, 0.69444, 0, 0, 0.48889],
"108": [0, 0.69444, 0, 0, 0.23889],
"109": [0, 0.44444, 0, 0, 0.79445],
"110": [0, 0.44444, 0, 0, 0.51667],
"111": [0, 0.44444, 0, 0, 0.5],
"112": [0.19444, 0.44444, 0, 0, 0.51667],
"113": [0.19444, 0.44444, 0, 0, 0.51667],
"114": [0, 0.44444, 0.01389, 0, 0.34167],
"115": [0, 0.44444, 0, 0, 0.38333],
"116": [0, 0.57143, 0, 0, 0.36111],
"117": [0, 0.44444, 0, 0, 0.51667],
"118": [0, 0.44444, 0.01389, 0, 0.46111],
"119": [0, 0.44444, 0.01389, 0, 0.68334],
"120": [0, 0.44444, 0, 0, 0.46111],
"121": [0.19444, 0.44444, 0.01389, 0, 0.46111],
"122": [0, 0.44444, 0, 0, 0.43472],
"126": [0.35, 0.32659, 0, 0, 0.5],
"160": [0, 0, 0, 0, 0.25],
"168": [0, 0.67937, 0, 0, 0.5],
"176": [0, 0.69444, 0, 0, 0.66667],
"184": [0.17014, 0, 0, 0, 0.44445],
"305": [0, 0.44444, 0, 0, 0.23889],
"567": [0.19444, 0.44444, 0, 0, 0.26667],
"710": [0, 0.69444, 0, 0, 0.5],
"711": [0, 0.63194, 0, 0, 0.5],
"713": [0, 0.60889, 0, 0, 0.5],
"714": [0, 0.69444, 0, 0, 0.5],
"715": [0, 0.69444, 0, 0, 0.5],
"728": [0, 0.69444, 0, 0, 0.5],
"729": [0, 0.67937, 0, 0, 0.27778],
"730": [0, 0.69444, 0, 0, 0.66667],
"732": [0, 0.67659, 0, 0, 0.5],
"733": [0, 0.69444, 0, 0, 0.5],
"915": [0, 0.69444, 0, 0, 0.54167],
"916": [0, 0.69444, 0, 0, 0.83334],
"920": [0, 0.69444, 0, 0, 0.77778],
"923": [0, 0.69444, 0, 0, 0.61111],
"926": [0, 0.69444, 0, 0, 0.66667],
"928": [0, 0.69444, 0, 0, 0.70834],
"931": [0, 0.69444, 0, 0, 0.72222],
"933": [0, 0.69444, 0, 0, 0.77778],
"934": [0, 0.69444, 0, 0, 0.72222],
"936": [0, 0.69444, 0, 0, 0.77778],
"937": [0, 0.69444, 0, 0, 0.72222],
"8211": [0, 0.44444, 0.02778, 0, 0.5],
"8212": [0, 0.44444, 0.02778, 0, 1.0],
"8216": [0, 0.69444, 0, 0, 0.27778],
"8217": [0, 0.69444, 0, 0, 0.27778],
"8220": [0, 0.69444, 0, 0, 0.5],
"8221": [0, 0.69444, 0, 0, 0.5]
},
"Script-Regular": {
"32": [0, 0, 0, 0, 0.25],
"65": [0, 0.7, 0.22925, 0, 0.80253],
"66": [0, 0.7, 0.04087, 0, 0.90757],
"67": [0, 0.7, 0.1689, 0, 0.66619],
"68": [0, 0.7, 0.09371, 0, 0.77443],
"69": [0, 0.7, 0.18583, 0, 0.56162],
"70": [0, 0.7, 0.13634, 0, 0.89544],
"71": [0, 0.7, 0.17322, 0, 0.60961],
"72": [0, 0.7, 0.29694, 0, 0.96919],
"73": [0, 0.7, 0.19189, 0, 0.80907],
"74": [0.27778, 0.7, 0.19189, 0, 1.05159],
"75": [0, 0.7, 0.31259, 0, 0.91364],
"76": [0, 0.7, 0.19189, 0, 0.87373],
"77": [0, 0.7, 0.15981, 0, 1.08031],
"78": [0, 0.7, 0.3525, 0, 0.9015],
"79": [0, 0.7, 0.08078, 0, 0.73787],
"80": [0, 0.7, 0.08078, 0, 1.01262],
"81": [0, 0.7, 0.03305, 0, 0.88282],
"82": [0, 0.7, 0.06259, 0, 0.85],
"83": [0, 0.7, 0.19189, 0, 0.86767],
"84": [0, 0.7, 0.29087, 0, 0.74697],
"85": [0, 0.7, 0.25815, 0, 0.79996],
"86": [0, 0.7, 0.27523, 0, 0.62204],
"87": [0, 0.7, 0.27523, 0, 0.80532],
"88": [0, 0.7, 0.26006, 0, 0.94445],
"89": [0, 0.7, 0.2939, 0, 0.70961],
"90": [0, 0.7, 0.24037, 0, 0.8212],
"160": [0, 0, 0, 0, 0.25]
},
"Size1-Regular": {
"32": [0, 0, 0, 0, 0.25],
"40": [0.35001, 0.85, 0, 0, 0.45834],
"41": [0.35001, 0.85, 0, 0, 0.45834],
"47": [0.35001, 0.85, 0, 0, 0.57778],
"91": [0.35001, 0.85, 0, 0, 0.41667],
"92": [0.35001, 0.85, 0, 0, 0.57778],
"93": [0.35001, 0.85, 0, 0, 0.41667],
"123": [0.35001, 0.85, 0, 0, 0.58334],
"125": [0.35001, 0.85, 0, 0, 0.58334],
"160": [0, 0, 0, 0, 0.25],
"710": [0, 0.72222, 0, 0, 0.55556],
"732": [0, 0.72222, 0, 0, 0.55556],
"770": [0, 0.72222, 0, 0, 0.55556],
"771": [0, 0.72222, 0, 0, 0.55556],
"8214": [-0.00099, 0.601, 0, 0, 0.77778],
"8593": [1e-05, 0.6, 0, 0, 0.66667],
"8595": [1e-05, 0.6, 0, 0, 0.66667],
"8657": [1e-05, 0.6, 0, 0, 0.77778],
"8659": [1e-05, 0.6, 0, 0, 0.77778],
"8719": [0.25001, 0.75, 0, 0, 0.94445],
"8720": [0.25001, 0.75, 0, 0, 0.94445],
"8721": [0.25001, 0.75, 0, 0, 1.05556],
"8730": [0.35001, 0.85, 0, 0, 1.0],
"8739": [-0.00599, 0.606, 0, 0, 0.33333],
"8741": [-0.00599, 0.606, 0, 0, 0.55556],
"8747": [0.30612, 0.805, 0.19445, 0, 0.47222],
"8748": [0.306, 0.805, 0.19445, 0, 0.47222],
"8749": [0.306, 0.805, 0.19445, 0, 0.47222],
"8750": [0.30612, 0.805, 0.19445, 0, 0.47222],
"8896": [0.25001, 0.75, 0, 0, 0.83334],
"8897": [0.25001, 0.75, 0, 0, 0.83334],
"8898": [0.25001, 0.75, 0, 0, 0.83334],
"8899": [0.25001, 0.75, 0, 0, 0.83334],
"8968": [0.35001, 0.85, 0, 0, 0.47222],
"8969": [0.35001, 0.85, 0, 0, 0.47222],
"8970": [0.35001, 0.85, 0, 0, 0.47222],
"8971": [0.35001, 0.85, 0, 0, 0.47222],
"9168": [-0.00099, 0.601, 0, 0, 0.66667],
"10216": [0.35001, 0.85, 0, 0, 0.47222],
"10217": [0.35001, 0.85, 0, 0, 0.47222],
"10752": [0.25001, 0.75, 0, 0, 1.11111],
"10753": [0.25001, 0.75, 0, 0, 1.11111],
"10754": [0.25001, 0.75, 0, 0, 1.11111],
"10756": [0.25001, 0.75, 0, 0, 0.83334],
"10758": [0.25001, 0.75, 0, 0, 0.83334]
},
"Size2-Regular": {
"32": [0, 0, 0, 0, 0.25],
"40": [0.65002, 1.15, 0, 0, 0.59722],
"41": [0.65002, 1.15, 0, 0, 0.59722],
"47": [0.65002, 1.15, 0, 0, 0.81111],
"91": [0.65002, 1.15, 0, 0, 0.47222],
"92": [0.65002, 1.15, 0, 0, 0.81111],
"93": [0.65002, 1.15, 0, 0, 0.47222],
"123": [0.65002, 1.15, 0, 0, 0.66667],
"125": [0.65002, 1.15, 0, 0, 0.66667],
"160": [0, 0, 0, 0, 0.25],
"710": [0, 0.75, 0, 0, 1.0],
"732": [0, 0.75, 0, 0, 1.0],
"770": [0, 0.75, 0, 0, 1.0],
"771": [0, 0.75, 0, 0, 1.0],
"8719": [0.55001, 1.05, 0, 0, 1.27778],
"8720": [0.55001, 1.05, 0, 0, 1.27778],
"8721": [0.55001, 1.05, 0, 0, 1.44445],
"8730": [0.65002, 1.15, 0, 0, 1.0],
"8747": [0.86225, 1.36, 0.44445, 0, 0.55556],
"8748": [0.862, 1.36, 0.44445, 0, 0.55556],
"8749": [0.862, 1.36, 0.44445, 0, 0.55556],
"8750": [0.86225, 1.36, 0.44445, 0, 0.55556],
"8896": [0.55001, 1.05, 0, 0, 1.11111],
"8897": [0.55001, 1.05, 0, 0, 1.11111],
"8898": [0.55001, 1.05, 0, 0, 1.11111],
"8899": [0.55001, 1.05, 0, 0, 1.11111],
"8968": [0.65002, 1.15, 0, 0, 0.52778],
"8969": [0.65002, 1.15, 0, 0, 0.52778],
"8970": [0.65002, 1.15, 0, 0, 0.52778],
"8971": [0.65002, 1.15, 0, 0, 0.52778],
"10216": [0.65002, 1.15, 0, 0, 0.61111],
"10217": [0.65002, 1.15, 0, 0, 0.61111],
"10752": [0.55001, 1.05, 0, 0, 1.51112],
"10753": [0.55001, 1.05, 0, 0, 1.51112],
"10754": [0.55001, 1.05, 0, 0, 1.51112],
"10756": [0.55001, 1.05, 0, 0, 1.11111],
"10758": [0.55001, 1.05, 0, 0, 1.11111]
},
"Size3-Regular": {
"32": [0, 0, 0, 0, 0.25],
"40": [0.95003, 1.45, 0, 0, 0.73611],
"41": [0.95003, 1.45, 0, 0, 0.73611],
"47": [0.95003, 1.45, 0, 0, 1.04445],
"91": [0.95003, 1.45, 0, 0, 0.52778],
"92": [0.95003, 1.45, 0, 0, 1.04445],
"93": [0.95003, 1.45, 0, 0, 0.52778],
"123": [0.95003, 1.45, 0, 0, 0.75],
"125": [0.95003, 1.45, 0, 0, 0.75],
"160": [0, 0, 0, 0, 0.25],
"710": [0, 0.75, 0, 0, 1.44445],
"732": [0, 0.75, 0, 0, 1.44445],
"770": [0, 0.75, 0, 0, 1.44445],
"771": [0, 0.75, 0, 0, 1.44445],
"8730": [0.95003, 1.45, 0, 0, 1.0],
"8968": [0.95003, 1.45, 0, 0, 0.58334],
"8969": [0.95003, 1.45, 0, 0, 0.58334],
"8970": [0.95003, 1.45, 0, 0, 0.58334],
"8971": [0.95003, 1.45, 0, 0, 0.58334],
"10216": [0.95003, 1.45, 0, 0, 0.75],
"10217": [0.95003, 1.45, 0, 0, 0.75]
},
"Size4-Regular": {
"32": [0, 0, 0, 0, 0.25],
"40": [1.25003, 1.75, 0, 0, 0.79167],
"41": [1.25003, 1.75, 0, 0, 0.79167],
"47": [1.25003, 1.75, 0, 0, 1.27778],
"91": [1.25003, 1.75, 0, 0, 0.58334],
"92": [1.25003, 1.75, 0, 0, 1.27778],
"93": [1.25003, 1.75, 0, 0, 0.58334],
"123": [1.25003, 1.75, 0, 0, 0.80556],
"125": [1.25003, 1.75, 0, 0, 0.80556],
"160": [0, 0, 0, 0, 0.25],
"710": [0, 0.825, 0, 0, 1.8889],
"732": [0, 0.825, 0, 0, 1.8889],
"770": [0, 0.825, 0, 0, 1.8889],
"771": [0, 0.825, 0, 0, 1.8889],
"8730": [1.25003, 1.75, 0, 0, 1.0],
"8968": [1.25003, 1.75, 0, 0, 0.63889],
"8969": [1.25003, 1.75, 0, 0, 0.63889],
"8970": [1.25003, 1.75, 0, 0, 0.63889],
"8971": [1.25003, 1.75, 0, 0, 0.63889],
"9115": [0.64502, 1.155, 0, 0, 0.875],
"9116": [1e-05, 0.6, 0, 0, 0.875],
"9117": [0.64502, 1.155, 0, 0, 0.875],
"9118": [0.64502, 1.155, 0, 0, 0.875],
"9119": [1e-05, 0.6, 0, 0, 0.875],
"9120": [0.64502, 1.155, 0, 0, 0.875],
"9121": [0.64502, 1.155, 0, 0, 0.66667],
"9122": [-0.00099, 0.601, 0, 0, 0.66667],
"9123": [0.64502, 1.155, 0, 0, 0.66667],
"9124": [0.64502, 1.155, 0, 0, 0.66667],
"9125": [-0.00099, 0.601, 0, 0, 0.66667],
"9126": [0.64502, 1.155, 0, 0, 0.66667],
"9127": [1e-05, 0.9, 0, 0, 0.88889],
"9128": [0.65002, 1.15, 0, 0, 0.88889],
"9129": [0.90001, 0, 0, 0, 0.88889],
"9130": [0, 0.3, 0, 0, 0.88889],
"9131": [1e-05, 0.9, 0, 0, 0.88889],
"9132": [0.65002, 1.15, 0, 0, 0.88889],
"9133": [0.90001, 0, 0, 0, 0.88889],
"9143": [0.88502, 0.915, 0, 0, 1.05556],
"10216": [1.25003, 1.75, 0, 0, 0.80556],
"10217": [1.25003, 1.75, 0, 0, 0.80556],
"57344": [-0.00499, 0.605, 0, 0, 1.05556],
"57345": [-0.00499, 0.605, 0, 0, 1.05556],
"57680": [0, 0.12, 0, 0, 0.45],
"57681": [0, 0.12, 0, 0, 0.45],
"57682": [0, 0.12, 0, 0, 0.45],
"57683": [0, 0.12, 0, 0, 0.45]
},
"Typewriter-Regular": {
"32": [0, 0, 0, 0, 0.525],
"33": [0, 0.61111, 0, 0, 0.525],
"34": [0, 0.61111, 0, 0, 0.525],
"35": [0, 0.61111, 0, 0, 0.525],
"36": [0.08333, 0.69444, 0, 0, 0.525],
"37": [0.08333, 0.69444, 0, 0, 0.525],
"38": [0, 0.61111, 0, 0, 0.525],
"39": [0, 0.61111, 0, 0, 0.525],
"40": [0.08333, 0.69444, 0, 0, 0.525],
"41": [0.08333, 0.69444, 0, 0, 0.525],
"42": [0, 0.52083, 0, 0, 0.525],
"43": [-0.08056, 0.53055, 0, 0, 0.525],
"44": [0.13889, 0.125, 0, 0, 0.525],
"45": [-0.08056, 0.53055, 0, 0, 0.525],
"46": [0, 0.125, 0, 0, 0.525],
"47": [0.08333, 0.69444, 0, 0, 0.525],
"48": [0, 0.61111, 0, 0, 0.525],
"49": [0, 0.61111, 0, 0, 0.525],
"50": [0, 0.61111, 0, 0, 0.525],
"51": [0, 0.61111, 0, 0, 0.525],
"52": [0, 0.61111, 0, 0, 0.525],
"53": [0, 0.61111, 0, 0, 0.525],
"54": [0, 0.61111, 0, 0, 0.525],
"55": [0, 0.61111, 0, 0, 0.525],
"56": [0, 0.61111, 0, 0, 0.525],
"57": [0, 0.61111, 0, 0, 0.525],
"58": [0, 0.43056, 0, 0, 0.525],
"59": [0.13889, 0.43056, 0, 0, 0.525],
"60": [-0.05556, 0.55556, 0, 0, 0.525],
"61": [-0.19549, 0.41562, 0, 0, 0.525],
"62": [-0.05556, 0.55556, 0, 0, 0.525],
"63": [0, 0.61111, 0, 0, 0.525],
"64": [0, 0.61111, 0, 0, 0.525],
"65": [0, 0.61111, 0, 0, 0.525],
"66": [0, 0.61111, 0, 0, 0.525],
"67": [0, 0.61111, 0, 0, 0.525],
"68": [0, 0.61111, 0, 0, 0.525],
"69": [0, 0.61111, 0, 0, 0.525],
"70": [0, 0.61111, 0, 0, 0.525],
"71": [0, 0.61111, 0, 0, 0.525],
"72": [0, 0.61111, 0, 0, 0.525],
"73": [0, 0.61111, 0, 0, 0.525],
"74": [0, 0.61111, 0, 0, 0.525],
"75": [0, 0.61111, 0, 0, 0.525],
"76": [0, 0.61111, 0, 0, 0.525],
"77": [0, 0.61111, 0, 0, 0.525],
"78": [0, 0.61111, 0, 0, 0.525],
"79": [0, 0.61111, 0, 0, 0.525],
"80": [0, 0.61111, 0, 0, 0.525],
"81": [0.13889, 0.61111, 0, 0, 0.525],
"82": [0, 0.61111, 0, 0, 0.525],
"83": [0, 0.61111, 0, 0, 0.525],
"84": [0, 0.61111, 0, 0, 0.525],
"85": [0, 0.61111, 0, 0, 0.525],
"86": [0, 0.61111, 0, 0, 0.525],
"87": [0, 0.61111, 0, 0, 0.525],
"88": [0, 0.61111, 0, 0, 0.525],
"89": [0, 0.61111, 0, 0, 0.525],
"90": [0, 0.61111, 0, 0, 0.525],
"91": [0.08333, 0.69444, 0, 0, 0.525],
"92": [0.08333, 0.69444, 0, 0, 0.525],
"93": [0.08333, 0.69444, 0, 0, 0.525],
"94": [0, 0.61111, 0, 0, 0.525],
"95": [0.09514, 0, 0, 0, 0.525],
"96": [0, 0.61111, 0, 0, 0.525],
"97": [0, 0.43056, 0, 0, 0.525],
"98": [0, 0.61111, 0, 0, 0.525],
"99": [0, 0.43056, 0, 0, 0.525],
"100": [0, 0.61111, 0, 0, 0.525],
"101": [0, 0.43056, 0, 0, 0.525],
"102": [0, 0.61111, 0, 0, 0.525],
"103": [0.22222, 0.43056, 0, 0, 0.525],
"104": [0, 0.61111, 0, 0, 0.525],
"105": [0, 0.61111, 0, 0, 0.525],
"106": [0.22222, 0.61111, 0, 0, 0.525],
"107": [0, 0.61111, 0, 0, 0.525],
"108": [0, 0.61111, 0, 0, 0.525],
"109": [0, 0.43056, 0, 0, 0.525],
"110": [0, 0.43056, 0, 0, 0.525],
"111": [0, 0.43056, 0, 0, 0.525],
"112": [0.22222, 0.43056, 0, 0, 0.525],
"113": [0.22222, 0.43056, 0, 0, 0.525],
"114": [0, 0.43056, 0, 0, 0.525],
"115": [0, 0.43056, 0, 0, 0.525],
"116": [0, 0.55358, 0, 0, 0.525],
"117": [0, 0.43056, 0, 0, 0.525],
"118": [0, 0.43056, 0, 0, 0.525],
"119": [0, 0.43056, 0, 0, 0.525],
"120": [0, 0.43056, 0, 0, 0.525],
"121": [0.22222, 0.43056, 0, 0, 0.525],
"122": [0, 0.43056, 0, 0, 0.525],
"123": [0.08333, 0.69444, 0, 0, 0.525],
"124": [0.08333, 0.69444, 0, 0, 0.525],
"125": [0.08333, 0.69444, 0, 0, 0.525],
"126": [0, 0.61111, 0, 0, 0.525],
"127": [0, 0.61111, 0, 0, 0.525],
"160": [0, 0, 0, 0, 0.525],
"176": [0, 0.61111, 0, 0, 0.525],
"184": [0.19445, 0, 0, 0, 0.525],
"305": [0, 0.43056, 0, 0, 0.525],
"567": [0.22222, 0.43056, 0, 0, 0.525],
"711": [0, 0.56597, 0, 0, 0.525],
"713": [0, 0.56555, 0, 0, 0.525],
"714": [0, 0.61111, 0, 0, 0.525],
"715": [0, 0.61111, 0, 0, 0.525],
"728": [0, 0.61111, 0, 0, 0.525],
"730": [0, 0.61111, 0, 0, 0.525],
"770": [0, 0.61111, 0, 0, 0.525],
"771": [0, 0.61111, 0, 0, 0.525],
"776": [0, 0.61111, 0, 0, 0.525],
"915": [0, 0.61111, 0, 0, 0.525],
"916": [0, 0.61111, 0, 0, 0.525],
"920": [0, 0.61111, 0, 0, 0.525],
"923": [0, 0.61111, 0, 0, 0.525],
"926": [0, 0.61111, 0, 0, 0.525],
"928": [0, 0.61111, 0, 0, 0.525],
"931": [0, 0.61111, 0, 0, 0.525],
"933": [0, 0.61111, 0, 0, 0.525],
"934": [0, 0.61111, 0, 0, 0.525],
"936": [0, 0.61111, 0, 0, 0.525],
"937": [0, 0.61111, 0, 0, 0.525],
"8216": [0, 0.61111, 0, 0, 0.525],
"8217": [0, 0.61111, 0, 0, 0.525],
"8242": [0, 0.61111, 0, 0, 0.525],
"9251": [0.11111, 0.21944, 0, 0, 0.525]
}
};
/**
* 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.
var 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.less; 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
// 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.
var 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'
};
/**
* This function adds new font metrics to default metricMap
* It can also override existing metrics
*/
function setFontMetrics(fontName, metrics) {
fontMetricsData[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`.
*/
function getCharacterMetrics(character, font, mode) {
if (!fontMetricsData[font]) {
throw new Error("Font metrics not found for font: " + font + ".");
}
var ch = character.charCodeAt(0);
var metrics = fontMetricsData[font][ch];
if (!metrics && character[0] in extraCharacterMap) {
ch = extraCharacterMap[character[0]].charCodeAt(0);
metrics = fontMetricsData[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 = fontMetricsData[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]
};
}
}
var fontMetricsBySizeIndex = {};
/**
* Get the font metrics for a given size.
*/
function getGlobalMetrics(size) {
var sizeIndex;
if (size >= 5) {
sizeIndex = 0;
} else if (size >= 3) {
sizeIndex = 1;
} else {
sizeIndex = 2;
}
if (!fontMetricsBySizeIndex[sizeIndex]) {
var metrics = fontMetricsBySizeIndex[sizeIndex] = {
cssEmPerMu: sigmasAndXis.quad[sizeIndex] / 18
};
for (var key in sigmasAndXis) {
if (sigmasAndXis.hasOwnProperty(key)) {
metrics[key] = sigmasAndXis[key][sizeIndex];
}
}
}
return fontMetricsBySizeIndex[sizeIndex];
}
/**
* 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.
*/
var 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
];
var 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];
var sizeAtStyle = function sizeAtStyle(size, style) {
return style.size < 2 ? size : sizeStyleMap[size - 1][style.size - 1];
}; // In these types, "" (empty string) means "no change".
/**
* 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 {
// 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
/**
* The base size index.
*/
constructor(data) {
this.style = void 0;
this.color = void 0;
this.size = void 0;
this.textSize = void 0;
this.phantom = void 0;
this.font = void 0;
this.fontFamily = void 0;
this.fontWeight = void 0;
this.fontShape = void 0;
this.sizeMultiplier = void 0;
this.maxSize = void 0;
this.minRuleThickness = void 0;
this._fontMetrics = void 0;
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) {
var 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 (var 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) {
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() {
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) {
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) {
style = style || this.style.text();
var 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() {
var 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) {
return this.extend({
color: color
});
}
/**
* Create a new options object with "phantom" set to true.
*/
withPhantom() {
return this.extend({
phantom: true
});
}
/**
* Creates a new options object with the given math font or old text font.
* @type {[type]}
*/
withFont(font) {
return this.extend({
font
});
}
/**
* Create a new options objects with the given fontFamily.
*/
withTextFontFamily(fontFamily) {
return this.extend({
fontFamily,
font: ""
});
}
/**
* Creates a new options object with the given font weight
*/
withTextFontWeight(fontWeight) {
return this.extend({
fontWeight,
font: ""
});
}
/**
* Creates a new options object with the given font weight
*/
withTextFontShape(fontShape) {
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) {
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() {
if (this.size !== Options.BASESIZE) {
return ["sizing", "reset-size" + this.size, "size" + Options.BASESIZE];
} else {
return [];
}
}
/**
* Return the font metrics for this size.
*/
fontMetrics() {
if (!this._fontMetrics) {
this._fontMetrics = getGlobalMetrics(this.size);
}
return this._fontMetrics;
}
/**
* Gets the CSS color of the current options object
*/
getColor() {
if (this.phantom) {
return "transparent";
} else {
return this.color;
}
}
}
Options.BASESIZE = 6;
/**
* This file does conversion between units. In particular, it provides
* calculateSize to convert other units into ems.
*/
// Thus, multiplying a length by this number converts the length from units
// into pts. Dividing the result by ptPerEm gives the number of ems
// *assuming* a font size of ptPerEm (normal size, normal style).
var ptPerUnit = {
// https://en.wikibooks.org/wiki/LaTeX/Lengths and
// https://tex.stackexchange.com/a/8263
"pt": 1,
// TeX point
"mm": 7227 / 2540,
// millimeter
"cm": 7227 / 254,
// centimeter
"in": 72.27,
// inch
"bp": 803 / 800,
// big (PostScript) points
"pc": 12,
// pica
"dd": 1238 / 1157,
// didot
"cc": 14856 / 1157,
// cicero (12 didot)
"nd": 685 / 642,
// new didot
"nc": 1370 / 107,
// new cicero (12 new didot)
"sp": 1 / 65536,
// scaled point (TeX's internal smallest unit)
// https://tex.stackexchange.com/a/41371
"px": 803 / 800 // \pdfpxdimen defaults to 1 bp in pdfTeX and LuaTeX
}; // Dictionary of relative units, for fast validity testing.
var relativeUnit = {
"ex": true,
"em": true,
"mu": true
};
/**
* Determine whether the specified unit (either a string defining the unit
* or a "size" parse node containing a unit field) is valid.
*/
var validUnit = function validUnit(unit) {
if (typeof unit !== "string") {
unit = unit.unit;
}
return unit in ptPerUnit || unit in relativeUnit || unit === "ex";
};
/*
* Convert a "size" parse node (with numeric "number" and string "unit" fields,
* as parsed by functions.js argType "size") into a CSS em value for the
* current style/scale. `options` gives the current options.
*/
var calculateSize = function calculateSize(sizeValue, options) {
var scale;
if (sizeValue.unit in ptPerUnit) {
// Absolute units
scale = ptPerUnit[sizeValue.unit] // Convert unit to pt
/ options.fontMetrics().ptPerEm // Convert pt to CSS em
/ options.sizeMultiplier; // Unscale to make absolute units
} else if (sizeValue.unit === "mu") {
// `mu` units scale with scriptstyle/scriptscriptstyle.
scale = options.fontMetrics().cssEmPerMu;
} else {
// Other relative units always refer to the *textstyle* font
// in the current size.
var unitOptions;
if (options.style.isTight()) {
// isTight() means current style is script/scriptscript.
unitOptions = options.havingStyle(options.style.text());
} else {
unitOptions = options;
} // TODO: In TeX these units are relative to the quad of the current
// *text* font, e.g. cmr10. KaTeX instead uses values from the
// comparably-sized *Computer Modern symbol* font. At 10pt, these
// match. At 7pt and 5pt, they differ: cmr7=1.138894, cmsy7=1.170641;
// cmr5=1.361133, cmsy5=1.472241. Consider $\scriptsize a\kern1emb$.
// TeX \showlists shows a kern of 1.13889 * fontsize;
// KaTeX shows a kern of 1.171 * fontsize.
if (sizeValue.unit === "ex") {
scale = unitOptions.fontMetrics().xHeight;
} else if (sizeValue.unit === "em") {
scale = unitOptions.fontMetrics().quad;
} else {
throw new ParseError("Invalid unit: '" + sizeValue.unit + "'");
}
if (unitOptions !== options) {
scale *= unitOptions.sizeMultiplier / options.sizeMultiplier;
}
}
return Math.min(sizeValue.number * scale, options.maxSize);
};
/**
* Round `n` to 4 decimal places, or to the nearest 1/10,000th em. See
* https://github.com/KaTeX/KaTeX/pull/2460.
*/
var makeEm = function makeEm(n) {
return +n.toFixed(4) + "em";
};
/**
* 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
*/
/**
* Create an HTML className based on a list of classes. In addition to joining
* with spaces, we also remove empty classes.
*/
var createClass = function createClass(classes) {
return classes.filter(cls => cls).join(" ");
};
var initNode = function initNode(classes, options, style) {
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");
}
var color = options.getColor();
if (color) {
this.style.color = color;
}
}
};
/**
* Convert into an HTML node
*/
var toNode = function toNode(tagName) {
var node = document.createElement(tagName); // Apply the class
node.className = createClass(this.classes); // Apply inline styles
for (var 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 (var attr in this.attributes) {
if (this.attributes.hasOwnProperty(attr)) {
node.setAttribute(attr, this.attributes[attr]);
}
} // Append the children, also as HTML nodes
for (var i = 0; i < this.children.length; i++) {
node.appendChild(this.children[i].toNode());
}
return node;
};
/**
* Convert into an HTML markup string
*/
var toMarkup = function toMarkup(tagName) {
var markup = "<" + tagName; // Add the class
if (this.classes.length) {
markup += " class=\"" + utils.escape(createClass(this.classes)) + "\"";
}
var styles = ""; // Add the styles, after hyphenation
for (var 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 (var attr in this.attributes) {
if (this.attributes.hasOwnProperty(attr)) {
markup += " " + attr + "=\"" + utils.escape(this.attributes[attr]) + "\"";
}
}
markup += ">"; // Add the markup of the children, also as markup
for (var 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.
/**
* 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.
*/
class Span {
constructor(classes, children, options, style) {
this.children = void 0;
this.attributes = void 0;
this.classes = void 0;
this.height = void 0;
this.depth = void 0;
this.width = void 0;
this.maxFontSize = void 0;
this.style = void 0;
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, value) {
this.attributes[attribute] = value;
}
hasClass(className) {
return utils.contains(this.classes, className);
}
toNode() {
return toNode.call(this, "span");
}
toMarkup() {
return toMarkup.call(this, "span");
}
}
/**
* This node represents an anchor (<a>) element with a hyperlink. See `span`
* for further details.
*/
class Anchor {
constructor(href, classes, children, options) {
this.children = void 0;
this.attributes = void 0;
this.classes = void 0;
this.height = void 0;
this.depth = void 0;
this.maxFontSize = void 0;
this.style = void 0;
initNode.call(this, classes, options);
this.children = children || [];
this.setAttribute('href', href);
}
setAttribute(attribute, value) {
this.attributes[attribute] = value;
}
hasClass(className) {
return utils.contains(this.classes, className);
}
toNode() {
return toNode.call(this, "a");
}
toMarkup() {
return toMarkup.call(this, "a");
}
}
/**
* This node represents an image embed (<img>) element.
*/
class Img {
constructor(src, alt, style) {
this.src = void 0;
this.alt = void 0;
this.classes = void 0;
this.height = void 0;
this.depth = void 0;
this.maxFontSize = void 0;
this.style = void 0;
this.alt = alt;
this.src = src;
this.classes = ["mord"];
this.style = style;
}
hasClass(className) {
return utils.contains(this.classes, className);
}
toNode() {
var node = document.createElement("img");
node.src = this.src;
node.alt = this.alt;
node.className = "mord"; // Apply inline styles
for (var style in this.style) {
if (this.style.hasOwnProperty(style)) {
// $FlowFixMe
node.style[style] = this.style[style];
}
}
return node;
}
toMarkup() {
var markup = "<img src='" + this.src + " 'alt='" + this.alt + "' "; // Add the styles, after hyphenation
var styles = "";
for (var 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;
}
}
var 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.
*/
class SymbolNode {
constructor(text, height, depth, italic, skew, width, classes, style) {
this.text = void 0;
this.height = void 0;
this.depth = void 0;
this.italic = void 0;
this.skew = void 0;
this.width = void 0;
this.maxFontSize = void 0;
this.classes = void 0;
this.style = void 0;
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
var 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) {
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() {
var node = document.createTextNode(this.text);
var 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 (var 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() {
// TODO(alpert): More duplication than I'd like from
// span.prototype.toMarkup and symbolNode.prototype.toNode...
var needsSpan = false;
var markup = "<span";
if (this.classes.length) {
needsSpan = true;
markup += " class=\"";
markup += utils.escape(createClass(this.classes));
markup += "\"";
}
var styles = "";
if (this.italic > 0) {
styles += "margin-right:" + this.italic + "em;";
}
for (var 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) + "\"";
}
var 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.
*/
class SvgNode {
constructor(children, attributes) {
this.children = void 0;
this.attributes = void 0;
this.children = children || [];
this.attributes = attributes || {};
}
toNode() {
var svgNS = "http://www.w3.org/2000/svg";
var node = document.createElementNS(svgNS, "svg"); // Apply attributes
for (var attr in this.attributes) {
if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
node.setAttribute(attr, this.attributes[attr]);
}
}
for (var i = 0; i < this.children.length; i++) {
node.appendChild(this.children[i].toNode());
}
return node;
}
toMarkup() {
var markup = "<svg xmlns=\"http://www.w3.org/2000/svg\""; // Apply attributes
for (var attr in this.attributes) {
if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
markup += " " + attr + "='" + this.attributes[attr] + "'";
}
}
markup += ">";
for (var i = 0; i < this.children.length; i++) {
markup += this.children[i].toMarkup();
}
markup += "</svg>";
return markup;
}
}
class PathNode {
constructor(pathName, alternate) {
this.pathName = void 0;
this.alternate = void 0;
this.pathName = pathName;
this.alternate = alternate; // Used only for \sqrt, \phase, & tall delims
}
toNode() {
var svgNS = "http://www.w3.org/2000/svg";
var node = document.createElementNS(svgNS, "path");
if (this.alternate) {
node.setAttribute("d", this.alternate);
} else {
node.setAttribute("d", path[this.pathName]);
}
return node;
}
toMarkup() {
if (this.alternate) {
return "<path d='" + this.alternate + "'/>";
} else {
return "<path d='" + path[this.pathName] + "'/>";
}
}
}
class LineNode {
constructor(attributes) {
this.attributes = void 0;
this.attributes = attributes || {};
}
toNode() {
var svgNS = "http://www.w3.org/2000/svg";
var node = document.createElementNS(svgNS, "line"); // Apply attributes
for (var attr in this.attributes) {
if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
node.setAttribute(attr, this.attributes[attr]);
}
}
return node;
}
toMarkup() {
var markup = "<line";
for (var attr in this.attributes) {
if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
markup += " " + attr + "='" + this.attributes[attr] + "'";
}
}
markup += "/>";
return markup;
}
}
function assertSymbolDomNode(group) {
if (group instanceof SymbolNode) {
return group;
} else {
throw new Error("Expected symbolNode but got " + String(group) + ".");
}
}
function assertSpan(group) {
if (group instanceof Span) {
return group;
} else {
throw new Error("Expected span<HtmlDomNode> but got " + String(group) + ".");
}
}
/**
* 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").
*/
// 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.
var ATOMS = {
"bin": 1,
"close": 1,
"inner": 1,
"open": 1,
"punct": 1,
"rel": 1
};
var NON_ATOMS = {
"accent-token": 1,
"mathord": 1,
"op-token": 1,
"spacing": 1,
"textord": 1
};
var symbols = {
"math": {},
"text": {}
};
/** `acceptUnicodeChar = true` is only applicable if `replace` is set. */
function defineSymbol(mode, font, group, replace, name, acceptUnicodeChar) {
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:
var math = "math";
var text = "text"; // fonts:
var main = "main";
var ams = "ams"; // groups:
var accent = "accent-token";
var bin = "bin";
var close = "close";
var inner = "inner";
var mathord = "mathord";
var op = "op-token";
var open = "open";
var punct = "punct";
var rel = "rel";
var spacing = "spacing";
var 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 preceeded 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);
defineSymbol(math, main, textord, "\u22ee", "\\varvdots"); // \vdots is a macro
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", '\\"'); // diaresis
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`.
var 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
var mathTextSymbols = "0123456789/@.\"";
for (var i = 0; i < mathTextSymbols.length; i++) {
var ch = mathTextSymbols.charAt(i);
defineSymbol(math, main, textord, ch, ch);
} // All of these are textords in text mode
var textSymbols = "0123456789!@*()-=+\";:?/.,";
for (var _i = 0; _i < textSymbols.length; _i++) {
var _ch = textSymbols.charAt(_i);
defineSymbol(text, main, textord, _ch, _ch);
} // All of these are textords in text mode, and mathords in math mode
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for (var _i2 = 0; _i2 < letters.length; _i2++) {
var _ch2 = letters.charAt(_i2);
defineSymbol(math, main, mathord, _ch2, _ch2);
defineSymbol(text, main, textord, _ch2, _ch2);
} // 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.
var wideChar = "";
for (var _i3 = 0; _i3 < letters.length; _i3++) {
var _ch3 = letters.charAt(_i3); // 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 + _i3); // A-Z a-z bold
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDC34 + _i3); // A-Z a-z italic
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDC68 + _i3); // A-Z a-z bold italic
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDD04 + _i3); // A-Z a-z Fractur
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDD6C + _i3); // A-Z a-z bold Fractur
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDDA0 + _i3); // A-Z a-z sans-serif
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDDD4 + _i3); // A-Z a-z sans bold
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDE08 + _i3); // A-Z a-z sans italic
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDE70 + _i3); // A-Z a-z monospace
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
if (_i3 < 26) {
// KaTeX fonts have only capital letters for blackboard bold and script.
// See exception for k below.
wideChar = String.fromCharCode(0xD835, 0xDD38 + _i3); // A-Z double struck
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDC9C + _i3); // A-Z script
defineSymbol(math, main, mathord, _ch3, wideChar);
defineSymbol(text, main, textord, _ch3, 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 (var _i4 = 0; _i4 < 10; _i4++) {
var _ch4 = _i4.toString();
wideChar = String.fromCharCode(0xD835, 0xDFCE + _i4); // 0-9 bold
defineSymbol(math, main, mathord, _ch4, wideChar);
defineSymbol(text, main, textord, _ch4, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDFE2 + _i4); // 0-9 sans serif
defineSymbol(math, main, mathord, _ch4, wideChar);
defineSymbol(text, main, textord, _ch4, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDFEC + _i4); // 0-9 bold sans
defineSymbol(math, main, mathord, _ch4, wideChar);
defineSymbol(text, main, textord, _ch4, wideChar);
wideChar = String.fromCharCode(0xD835, 0xDFF6 + _i4); // 0-9 monospace
defineSymbol(math, main, mathord, _ch4, wideChar);
defineSymbol(text, main, textord, _ch4, 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.
var extraLatin = "\u00d0\u00de\u00fe";
for (var _i5 = 0; _i5 < extraLatin.length; _i5++) {
var _ch5 = extraLatin.charAt(_i5);
defineSymbol(math, main, mathord, _ch5, _ch5);
defineSymbol(text, main, textord, _ch5, _ch5);
}
/**
* This file provides support for Unicode range U+1D400 to U+1D7FF,
* Mathematical Alphanumeric Symbols.
*
* Function wideCharacterFont takes a wide character as input and returns
* the font information necessary to render it properly.
*/
/**
* Data below is from https://www.unicode.org/charts/PDF/U1D400.pdf
* That document sorts characters into groups by font type, say bold or italic.
*
* In the arrays below, each subarray consists three elements:
* * The CSS class of that group when in math mode.
* * The CSS class of that group when in text mode.
* * The font name, so that KaTeX can get font metrics.
*/
var wideLatinLetterData = [["mathbf", "textbf", "Main-Bold"], // A-Z bold upright
["mathbf", "textbf", "Main-Bold"], // a-z bold upright
["mathnormal", "textit", "Math-Italic"], // A-Z italic
["mathnormal", "textit", "Math-Italic"], // a-z italic
["boldsymbol", "boldsymbol", "Main-BoldItalic"], // A-Z bold italic
["boldsymbol", "boldsymbol", "Main-BoldItalic"], // a-z bold italic
// Map fancy A-Z letters to script, not calligraphic.
// This aligns with unicode-math and math fonts (except Cambria Math).
["mathscr", "textscr", "Script-Regular"], // A-Z script
["", "", ""], // a-z script. No font
["", "", ""], // A-Z bold script. No font
["", "", ""], // a-z bold script. No font
["mathfrak", "textfrak", "Fraktur-Regular"], // A-Z Fraktur
["mathfrak", "textfrak", "Fraktur-Regular"], // a-z Fraktur
["mathbb", "textbb", "AMS-Regular"], // A-Z double-struck
["mathbb", "textbb", "AMS-Regular"], // k double-struck
// Note that we are using a bold font, but font metrics for regular Fraktur.
["mathboldfrak", "textboldfrak", "Fraktur-Regular"], // A-Z bold Fraktur
["mathboldfrak", "textboldfrak", "Fraktur-Regular"], // a-z bold Fraktur
["mathsf", "textsf", "SansSerif-Regular"], // A-Z sans-serif
["mathsf", "textsf", "SansSerif-Regular"], // a-z sans-serif
["mathboldsf", "textboldsf", "SansSerif-Bold"], // A-Z bold sans-serif
["mathboldsf", "textboldsf", "SansSerif-Bold"], // a-z bold sans-serif
["mathitsf", "textitsf", "SansSerif-Italic"], // A-Z italic sans-serif
["mathitsf", "textitsf", "SansSerif-Italic"], // a-z italic sans-serif
["", "", ""], // A-Z bold italic sans. No font
["", "", ""], // a-z bold italic sans. No font
["mathtt", "texttt", "Typewriter-Regular"], // A-Z monospace
["mathtt", "texttt", "Typewriter-Regular"] // a-z monospace
];
var wideNumeralData = [["mathbf", "textbf", "Main-Bold"], // 0-9 bold
["", "", ""], // 0-9 double-struck. No KaTeX font.
["mathsf", "textsf", "SansSerif-Regular"], // 0-9 sans-serif
["mathboldsf", "textboldsf", "SansSerif-Bold"], // 0-9 bold sans-serif
["mathtt", "texttt", "Typewriter-Regular"] // 0-9 monospace
];
var wideCharacterFont = function wideCharacterFont(wideChar, mode) {
// IE doesn't support codePointAt(). So work with the surrogate pair.
var H = wideChar.charCodeAt(0); // high surrogate
var L = wideChar.charCodeAt(1); // low surrogate
var codePoint = (H - 0xD800) * 0x400 + (L - 0xDC00) + 0x10000;
var j = mode === "math" ? 0 : 1; // column index for CSS class.
if (0x1D400 <= codePoint && codePoint < 0x1D6A4) {
// wideLatinLetterData contains exactly 26 chars on each row.
// So we can calculate the relevant row. No traverse necessary.
var i = Math.floor((codePoint - 0x1D400) / 26);
return [wideLatinLetterData[i][2], wideLatinLetterData[i][j]];
} else if (0x1D7CE <= codePoint && codePoint <= 0x1D7FF) {
// Numerals, ten per row.
var _i = Math.floor((codePoint - 0x1D7CE) / 10);
return [wideNumeralData[_i][2], wideNumeralData[_i][j]];
} else if (codePoint === 0x1D6A5 || codePoint === 0x1D6A6) {
// dotless i or j
return [wideLatinLetterData[0][2], wideLatinLetterData[0][j]];
} else if (0x1D6A6 < codePoint && codePoint < 0x1D7CE) {
// Greek letters. Not supported, yet.
return ["", ""];
} else {
// We don't support any wide characters outside 1D400–1D7FF.
throw new ParseError("Unsupported character: " + wideChar);
}
};
/* eslint no-console:0 */
/**
* Looks up the given symbol in fontMetrics, after applying any symbol
* replacements defined in symbol.js
*/
var lookupSymbol = function lookupSymbol(value, // TODO(#963): Use a union type for this.
fontName, mode) {
// 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.
*/
var makeSymbol = function makeSymbol(value, fontName, mode, options, classes) {
var lookup = lookupSymbol(value, fontName, mode);
var metrics = lookup.metrics;
value = lookup.value;
var symbolNode;
if (metrics) {
var 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");
}
var 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.
*/
var mathsym = function mathsym(value, mode, options, classes) {
if (classes === void 0) {
classes = [];
}
// 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".
*/
var boldsymbol = function boldsymbol(value, mode, options, classes, type) {
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.
*/
var makeOrd = function makeOrd(group, options, type) {
var mode = group.mode;
var text = group.text;
var classes = ["mord"]; // Math mode or Old font (i.e. \rm)
var isFont = mode === "math" || mode === "text" && options.font;
var fontOrFamily = isFont ? options.font : options.fontFamily;
var wideFontName = "";
var 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) {
var fontName;
var fontClasses;
if (fontOrFamily === "boldsymbol") {
var 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).
var parts = [];
for (var 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") {
var font = symbols[mode][text] && symbols[mode][text].font;
if (font === "ams") {
var _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) {
var _fontName2 = retrieveTextFontName("textrm", options.fontWeight, options.fontShape);
return makeSymbol(text, _fontName2, mode, options, classes.concat(options.fontWeight, options.fontShape));
} else {
// fonts added by plugins
var _fontName3 = retrieveTextFontName(font, options.fontWeight, options.fontShape); // We add font name as a css class
return makeSymbol(text, _fontName3, mode, options, classes.concat(_fontName3, 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.
*/
var canCombine = (prev, next) => {
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) {
var cls = prev.classes[0];
if (cls === "mbin" || cls === "mord") {
return false;
}
}
for (var style in prev.style) {
if (prev.style.hasOwnProperty(style) && prev.style[style] !== next.style[style]) {
return false;
}
}
for (var _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.
*/
var tryCombineChars = chars => {
for (var i = 0; i < chars.length - 1; i++) {
var prev = chars[i];
var 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.
*/
var sizeElementFromChildren = function sizeElementFromChildren(elem) {
var height = 0;
var depth = 0;
var maxFontSize = 0;
for (var i = 0; i < elem.children.length; i++) {
var 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`.
*/
var makeSpan$2 = function makeSpan(classes, children, options, style) {
var 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.
var makeSvgSpan = (classes, children, options, style) => new Span(classes, children, options, style);
var makeLineSpan = function makeLineSpan(className, options, thickness) {
var line = makeSpan$2([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.
*/
var makeAnchor = function makeAnchor(href, classes, children, options) {
var anchor = new Anchor(href, classes, children, options);
sizeElementFromChildren(anchor);
return anchor;
};
/**
* Makes a document fragment with the given list of children.
*/
var makeFragment = function makeFragment(children) {
var 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
*/
var wrapFragment = function wrapFragment(group, options) {
if (group instanceof DocumentFragment) {
return makeSpan$2([], [group], options);
}
return group;
}; // These are exact object types to catch typos in the names of the optional fields.
// 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.
var getVListChildrenAndDepth = function getVListChildrenAndDepth(params) {
if (params.positionType === "individualShift") {
var oldChildren = params.children;
var children = [oldChildren[0]]; // Add in kerns to the list of params.children to get each element to be
// shifted to the correct specified shift
var _depth = -oldChildren[0].shift - oldChildren[0].elem.depth;
var currPos = _depth;
for (var i = 1; i < oldChildren.length; i++) {
var diff = -oldChildren[i].shift - currPos - oldChildren[i].elem.depth;
var 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: _depth
};
}
var depth;
if (params.positionType === "top") {
// We always start at the bottom, so calculate the bottom by adding up
// all the sizes
var bottom = params.positionData;
for (var _i = 0; _i < params.children.length; _i++) {
var 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 {
var 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.
*/
var makeVList = function makeVList(params, options) {
var {
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.
var pstrutSize = 0;
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child.type === "elem") {
var elem = child.elem;
pstrutSize = Math.max(pstrutSize, elem.maxFontSize, elem.height);
}
}
pstrutSize += 2;
var pstrut = makeSpan$2(["pstrut"], []);
pstrut.style.height = makeEm(pstrutSize); // Create a new list of actual children at the correct offsets
var realChildren = [];
var minPos = depth;
var maxPos = depth;
var currPos = depth;
for (var _i2 = 0; _i2 < children.length; _i2++) {
var _child = children[_i2];
if (_child.type === "kern") {
currPos += _child.size;
} else {
var _elem = _child.elem;
var classes = _child.wrapperClasses || [];
var style = _child.wrapperStyle || {};
var childWrap = makeSpan$2(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.
var vlist = makeSpan$2(["vlist"], realChildren);
vlist.style.height = makeEm(maxPos); // A second row is used if necessary to represent the vlist's depth.
var 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.
var emptySpan = makeSpan$2([], []);
var depthStrut = makeSpan$2(["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.
var topStrut = makeSpan$2(["vlist-s"], [new SymbolNode("\u200b")]);
rows = [makeSpan$2(["vlist-r"], [vlist, topStrut]), makeSpan$2(["vlist-r"], [depthStrut])];
} else {
rows = [makeSpan$2(["vlist-r"], [vlist])];
}
var vtable = makeSpan$2(["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.
var makeGlue = (measurement, options) => {
// Make an empty span for the space
var rule = makeSpan$2(["mspace"], [], options);
var size = calculateSize(measurement, options);
rule.style.marginRight = makeEm(size);
return rule;
}; // Takes font options, and returns the appropriate fontLookup name
var retrieveTextFontName = function retrieveTextFontName(fontFamily, fontWeight, fontShape) {
var 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
}
var 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
var fontMap = {
// 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"
},
// "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"
}
};
var svgData = {
// 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]
};
var staticSvg = function staticSvg(value, options) {
// Create a span with inline SVG for the element.
var [pathName, width, height] = svgData[value];
var path = new PathNode(pathName);
var 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"
});
var span = makeSvgSpan(["overlay"], [svgNode], options);
span.height = height;
span.style.height = makeEm(height);
span.style.width = makeEm(width);
return span;
};
var buildCommon = {
fontMap,
makeSymbol,
mathsym,
makeSpan: makeSpan$2,
makeSvgSpan,
makeLineSpan,
makeAnchor,
makeFragment,
wrapFragment,
makeVList,
makeOrd,
makeGlue,
staticSvg,
svgData,
tryCombineChars
};
/**
* Describes spaces between different classes of atoms.
*/
var thinspace = {
number: 3,
unit: "mu"
};
var mediumspace = {
number: 4,
unit: "mu"
};
var thickspace = {
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.
// Spacing relationships for display and text styles
var 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
var tightSpacings = {
mord: {
mop: thinspace
},
mop: {
mord: thinspace,
mop: thinspace
},
mbin: {},
mrel: {},
mopen: {},
mclose: {
mop: thinspace
},
mpunct: {},
minner: {
mop: thinspace
}
};
/** Context provided to function handlers for error messages. */
// Note: reverse the order of the return type union will cause a flow error.
// See https://github.com/facebook/flow/issues/3663.
// 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.
/**
* 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.
*/
/**
* All registered functions.
* `functions.js` just exports this same dictionary again and makes it public.
* `Parser.js` requires this dictionary.
*/
var _functions = {};
/**
* All HTML builders. Should be only used in the `define*` and the `build*ML`
* functions.
*/
var _htmlGroupBuilders = {};
/**
* All MathML builders. Should be only used in the `define*` and the `build*ML`
* functions.
*/
var _mathmlGroupBuilders = {};
function defineFunction(_ref) {
var {
type,
names,
props,
handler,
htmlBuilder,
mathmlBuilder
} = _ref;
// Set default values of functions
var 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 (var 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`).
*/
function defineFunctionBuilders(_ref2) {
var {
type,
htmlBuilder,
mathmlBuilder
} = _ref2;
defineFunction({
type,
names: [],
props: {
numArgs: 0
},
handler() {
throw new Error('Should never be called.');
},
htmlBuilder,
mathmlBuilder
});
}
var normalizeArgument = function normalizeArgument(arg) {
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
var ordargument = function ordargument(arg) {
return arg.type === "ordgroup" ? arg.body : [arg];
};
/**
* 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.
*/
var makeSpan$1 = 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.
var binLeftCanceller = ["leftmost", "mbin", "mopen", "mrel", "mop", "mpunct"];
var binRightCanceller = ["rightmost", "mrel", "mclose", "mpunct"];
var styleMap$1 = {
"display": Style$1.DISPLAY,
"text": Style$1.TEXT,
"script": Style$1.SCRIPT,
"scriptscript": Style$1.SCRIPTSCRIPT
};
var DomEnum = {
mord: "mord",
mop: "mop",
mbin: "mbin",
mrel: "mrel",
mopen: "mopen",
mclose: "mclose",
mpunct: "mpunct",
minner: "minner"
};
/**
* 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.
*/
var buildExpression$1 = function buildExpression(expression, options, isRealGroup, surrounding) {
if (surrounding === void 0) {
surrounding = [null, null];
}
// Parse expressions into `groups`.
var groups = [];
for (var i = 0; i < expression.length; i++) {
var output = buildGroup$1(expression[i], options);
if (output instanceof DocumentFragment) {
var children = 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;
}
var glueOptions = options;
if (expression.length === 1) {
var node = expression[0];
if (node.type === "sizing") {
glueOptions = options.havingSize(node.size);
} else if (node.type === "styling") {
glueOptions = options.havingStyle(styleMap$1[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.
var dummyPrev = makeSpan$1([surrounding[0] || "leftmost"], [], options);
var dummyNext = makeSpan$1([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.
var isRoot = isRealGroup === "root";
traverseNonSpaceNodes(groups, (node, prev) => {
var prevType = prev.classes[0];
var 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) => {
var prevType = getTypeOfDomTree(prev);
var type = getTypeOfDomTree(node); // 'mtight' indicates that the node is script or scriptscript style.
var 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.
var traverseNonSpaceNodes = function traverseNonSpaceNodes(nodes, callback, prev, next, isRoot) {
if (next) {
// temporarily append the right node, if exists
nodes.push(next);
}
var i = 0;
for (; i < nodes.length; i++) {
var node = nodes[i];
var 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
var nonspace = !node.hasClass("mspace");
if (nonspace) {
var 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$1(["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.
var checkPartialGroup = function checkPartialGroup(node) {
if (node instanceof DocumentFragment || node instanceof Anchor || node instanceof Span && node.hasClass("enclosing")) {
return node;
}
return null;
}; // Return the outermost node of a domTree.
var getOutermostNode = function getOutermostNode(node, side) {
var partialGroup = checkPartialGroup(node);
if (partialGroup) {
var 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.
var getTypeOfDomTree = function getTypeOfDomTree(node, side) {
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;
};
var makeNullDelimiter = function makeNullDelimiter(options, classes) {
var moreClasses = ["nulldelimiter"].concat(options.baseSizingClasses());
return makeSpan$1(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.
*/
var buildGroup$1 = function buildGroup(group, options, baseOptions) {
if (!group) {
return makeSpan$1();
}
if (_htmlGroupBuilders[group.type]) {
// Call the groupBuilders function
// $FlowFixMe
var groupNode = _htmlGroupBuilders[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$1(options.sizingClasses(baseOptions), [groupNode], options);
var 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.
var body = makeSpan$1(["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.
var strut = makeSpan$1(["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.
*/
function buildHTML(tree, options) {
// Strip off outer tag wrapper for processing below.
var 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
var expression = buildExpression$1(tree, options, "root");
var eqnNum;
if (expression.length === 2 && expression[1].hasClass("tag")) {
// An environment with automatic equation numbers, e.g. {gather}.
eqnNum = expression.pop();
}
var 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)."
var parts = [];
for (var 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.
var 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.
var tagChild;
if (tag) {
tagChild = buildHTMLUnbreakable(buildExpression$1(tag, options, true));
tagChild.classes = ["tag"];
children.push(tagChild);
} else if (eqnNum) {
children.push(eqnNum);
}
var htmlNode = makeSpan$1(["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) {
var strut = tagChild.children[0];
strut.style.height = makeEm(htmlNode.height + htmlNode.depth);
if (htmlNode.depth) {
strut.style.verticalAlign = makeEm(-htmlNode.depth);
}
}
return htmlNode;
}
/**
* 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.
*/
function newDocumentFragment(children) {
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).
*/
class MathNode {
constructor(type, children, classes) {
this.type = void 0;
this.attributes = void 0;
this.children = void 0;
this.classes = void 0;
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, value) {
this.attributes[name] = value;
}
/**
* Gets an attribute on a MathML node.
*/
getAttribute(name) {
return this.attributes[name];
}
/**
* Converts the math node into a MathML-namespaced DOM element.
*/
toNode() {
var node = document.createElementNS("http://www.w3.org/1998/Math/MathML", this.type);
for (var 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 (var i = 0; i < this.children.length; i++) {
node.appendChild(this.children[i].toNode());
}
return node;
}
/**
* Converts the math node into an HTML markup string.
*/
toMarkup() {
var markup = "<" + this.type; // Add the attributes
for (var 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 (var 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() {
return this.children.map(child => child.toText()).join("");
}
}
/**
* This node represents a piece of text.
*/
class TextNode {
constructor(text) {
this.text = void 0;
this.text = text;
}
/**
* Converts the text node into a DOM text node.
*/
toNode() {
return document.createTextNode(this.text);
}
/**
* Converts the text node into escaped HTML markup
* (representing the text itself).
*/
toMarkup() {
return utils.escape(this.toText());
}
/**
* Converts the text node into a string
* (representing the text itself).
*/
toText() {
return this.text;
}
}
/**
* This node represents a space, but may render as <mspace.../> or as text,
* depending on the width.
*/
class SpaceNode {
/**
* Create a Space node with width given in CSS ems.
*/
constructor(width) {
this.width = void 0;
this.character = void 0;
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"; //  
} else if (width >= 0.1666 && width <= 0.1667) {
this.character = "\u2009"; //  
} else if (width >= 0.2222 && width <= 0.2223) {
this.character = "\u2005"; //  
} else if (width >= 0.2777 && width <= 0.2778) {
this.character = "\u2005\u200a"; //   
} else if (width >= -0.05556 && width <= -0.05555) {
this.character = "\u200a\u2063"; // ​
} else if (width >= -0.1667 && width <= -0.1666) {
this.character = "\u2009\u2063"; // ​
} else if (width >= -0.2223 && width <= -0.2222) {
this.character = "\u205f\u2063"; // ​
} else if (width >= -0.2778 && width <= -0.2777) {
this.character = "\u2005\u2063"; // ​
} else {
this.character = null;
}
}
/**
* Converts the math node into a MathML-namespaced DOM element.
*/
toNode() {
if (this.character) {
return document.createTextNode(this.character);
} else {
var 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() {
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() {
if (this.character) {
return this.character;
} else {
return " ";
}
}
}
var mathMLTree = {
MathNode,
TextNode,
SpaceNode,
newDocumentFragment
};
/**
* 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.
*/
/**
* Takes a symbol and converts it into a MathML text node after performing
* optional replacement from symbols.js.
*/
var makeText = function makeText(text, mode, options) {
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.
*/
var makeRow = function makeRow(body) {
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.
*/
var getVariant = function getVariant(group, options) {
// 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";
}
var font = options.font;
if (!font || font === "mathnormal") {
return null;
}
var 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 === "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";
}
var text = group.text;
if (utils.contains(["\\imath", "\\jmath"], text)) {
return null;
}
if (symbols[mode][text] && symbols[mode][text].replace) {
text = symbols[mode][text].replace;
}
var fontName = buildCommon.fontMap[font].fontName;
if (getCharacterMetrics(text, fontName, mode)) {
return buildCommon.fontMap[font].variant;
}
return null;
};
/**
* 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.
*/
var buildExpression = function buildExpression(expression, options, isOrdgroup) {
if (expression.length === 1) {
var 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];
}
var groups = [];
var lastGroup;
for (var i = 0; i < expression.length; i++) {
var _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 (_group.type === 'mi' && _group.children.length === 1 && lastGroup.type === 'mn') {
var child = _group.children[0];
if (child instanceof TextNode && child.text === '.') {
lastGroup.children.push(..._group.children);
continue;
}
} else if (lastGroup.type === 'mi' && lastGroup.children.length === 1) {
var lastChild = lastGroup.children[0];
if (lastChild instanceof TextNode && lastChild.text === '\u0338' && (_group.type === 'mo' || _group.type === 'mi' || _group.type === 'mn')) {
var _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.
*/
var buildExpressionRow = function buildExpressionRow(expression, options, isOrdgroup) {
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.
*/
var buildGroup = function buildGroup(group, options) {
if (!group) {
return new mathMLTree.MathNode("mrow");
}
if (_mathmlGroupBuilders[group.type]) {
// Call the groupBuilders function
// $FlowFixMe
var result = _mathmlGroupBuilders[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.
*/
function buildMathML(tree, texExpression, options, isDisplayMode, forMathmlOnly) {
var 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>.
var 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
var annotation = new mathMLTree.MathNode("annotation", [new mathMLTree.TextNode(texExpression)]);
annotation.setAttribute("encoding", "application/x-tex");
var semantics = new mathMLTree.MathNode("semantics", [wrapper, annotation]);
var 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.
var wrapperClass = forMathmlOnly ? "katex" : "katex-mathml"; // $FlowFixMe
return buildCommon.makeSpan([wrapperClass], [math]);
}
var optionsFromSettings = function optionsFromSettings(settings) {
return new Options({
style: settings.displayMode ? Style$1.DISPLAY : Style$1.TEXT,
maxSize: settings.maxSize,
minRuleThickness: settings.minRuleThickness
});
};
var displayWrap = function displayWrap(node, settings) {
if (settings.displayMode) {
var classes = ["katex-display"];
if (settings.leqno) {
classes.push("leqno");
}
if (settings.fleqn) {
classes.push("fleqn");
}
node = buildCommon.makeSpan(classes, [node]);
}
return node;
};
var buildTree = function buildTree(tree, expression, settings) {
var options = optionsFromSettings(settings);
var katexNode;
if (settings.output === "mathml") {
return buildMathML(tree, expression, options, settings.displayMode, true);
} else if (settings.output === "html") {
var htmlNode = buildHTML(tree, options);
katexNode = buildCommon.makeSpan(["katex"], [htmlNode]);
} else {
var mathMLNode = buildMathML(tree, expression, options, settings.displayMode, false);
var _htmlNode = buildHTML(tree, options);
katexNode = buildCommon.makeSpan(["katex"], [mathMLNode, _htmlNode]);
}
return displayWrap(katexNode, settings);
};
var buildHTMLTree = function buildHTMLTree(tree, expression, settings) {
var options = optionsFromSettings(settings);
var htmlNode = buildHTML(tree, options);
var katexNode = buildCommon.makeSpan(["katex"], [htmlNode]);
return displayWrap(katexNode, settings);
};
/**
* This file provides support to buildMathML.js and buildHTML.js
* for stretchy wide elements rendered from SVG files
* and other CSS trickery.
*/
var stretchyCodePoint = {
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": "="
};
var mathMLnode = function mathMLnode(label) {
var 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.
var katexImagesData = {
// 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]
};
var groupLength = function groupLength(arg) {
if (arg.type === "ordgroup") {
return arg.body.length;
} else {
return 1;
}
};
var svgSpan = function svgSpan(group, options) {
// Create a span with inline SVG for the element.
function buildSvgSpan_() {
var viewBoxWidth = 400000; // default
var 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
var grp = group; // There are four SVG images available for each function.
// Choose a taller image when there are more characters.
var numChars = groupLength(grp.base);
var viewBoxHeight;
var pathName;
var _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 {
var 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;
}
}
var path = new PathNode(pathName);
var 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: _height
};
} else {
var spans = [];
var data = katexImagesData[label];
var [paths, _minWidth, _viewBoxHeight] = data;
var _height2 = _viewBoxHeight / 1000;
var numSvgChildren = paths.length;
var widthClasses;
var aligns;
if (numSvgChildren === 1) {
// $FlowFixMe: All these cases must be of the 4-tuple type.
var align1 = 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\n " + numSvgChildren + " children.");
}
for (var i = 0; i < numSvgChildren; i++) {
var _path = new PathNode(paths[i]);
var _svgNode = new SvgNode([_path], {
"width": "400em",
"height": makeEm(_height2),
"viewBox": "0 0 " + viewBoxWidth + " " + _viewBoxHeight,
"preserveAspectRatio": aligns[i] + " slice"
});
var _span = buildCommon.makeSvgSpan([widthClasses[i]], [_svgNode], options);
if (numSvgChildren === 1) {
return {
span: _span,
minWidth: _minWidth,
height: _height2
};
} else {
_span.style.height = makeEm(_height2);
spans.push(_span);
}
}
return {
span: buildCommon.makeSpan(["stretchy"], spans, options),
minWidth: _minWidth,
height: _height2
};
}
} // buildSvgSpan_()
var {
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;
};
var encloseSpan = function encloseSpan(inner, label, topPad, bottomPad, options) {
// Return an image span for \cancel, \bcancel, \xcancel, \fbox, or \angl
var img;
var totalHeight = inner.height + inner.depth + topPad + bottomPad;
if (/fbox|color|angl/.test(label)) {
img = buildCommon.makeSpan(["stretchy", label], [], options);
if (label === "fbox") {
var 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.
var 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"
}));
}
var svgNode = new SvgNode(lines, {
"width": "100%",
"height": makeEm(totalHeight)
});
img = buildCommon.makeSvgSpan([], [svgNode], options);
}
img.height = totalHeight;
img.style.height = makeEm(totalHeight);
return img;
};
var stretchy = {
encloseSpan,
mathMLnode,
svgSpan
};
/**
* Asserts that the node is of the given type and returns it with stricter
* typing. Throws if the node's type does not match.
*/
function assertNodeType(node, type) {
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.
*/
function assertSymbolNodeType(node) {
var 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.
*/
function checkSymbolNodeType(node) {
if (node && (node.type === "atom" || NON_ATOMS.hasOwnProperty(node.type))) {
// $FlowFixMe
return node;
}
return null;
}
// NOTE: Unlike most `htmlBuilder`s, this one handles not only "accent", but
// also "supsub" since an accent can affect super/subscripting.
var htmlBuilder$a = (grp, options) => {
// Accents are handled in the TeXbook pg. 443, rule 12.
var base;
var group;
var 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(buildGroup$1(grp, options)); // reset original base
grp.base = group;
} else {
group = assertNodeType(grp, "accent");
base = group.base;
} // Build the base group
var body = buildGroup$1(base, options.havingCrampedStyle()); // Does the accent need to shift for the skew of a character?
var 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.
var 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:
var baseChar = utils.getBaseElem(base); // Then, we render its group to get the symbol inside it
var baseGroup = buildGroup$1(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
}
var accentBelow = group.label === "\\c"; // calculate the amount of space between the body and the accent
var clearance = accentBelow ? body.height + body.depth : Math.min(body.height, options.fontMetrics().xHeight); // Build the accent
var accentBody;
if (!group.isStretchy) {
var accent;
var width;
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.
var accentFull = group.label === "\\textcircled";
if (accentFull) {
accentBody.classes.push('accent-full');
clearance = body.height;
} // Shift the accent over by the skew.
var 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);
}
var 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;
}
};
var mathmlBuilder$9 = (group, options) => {
var accentNode = group.isStretchy ? stretchy.mathMLnode(group.label) : new mathMLTree.MathNode("mo", [makeText(group.label, group.mode)]);
var node = new mathMLTree.MathNode("mover", [buildGroup(group.base, options), accentNode]);
node.setAttribute("accent", "true");
return node;
};
var 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) => {
var base = normalizeArgument(args[0]);
var isStretchy = !NON_STRETCHY_ACCENT_REGEX.test(context.funcName);
var 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: htmlBuilder$a,
mathmlBuilder: mathmlBuilder$9
}); // 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) => {
var base = args[0];
var 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: htmlBuilder$a,
mathmlBuilder: mathmlBuilder$9
});
// Horizontal overlap functions
defineFunction({
type: "accentUnder",
names: ["\\underleftarrow", "\\underrightarrow", "\\underleftrightarrow", "\\undergroup", "\\underlinesegment", "\\utilde"],
props: {
numArgs: 1
},
handler: (_ref, args) => {
var {
parser,
funcName
} = _ref;
var base = args[0];
return {
type: "accentUnder",
mode: parser.mode,
label: funcName,
base: base
};
},
htmlBuilder: (group, options) => {
// Treat under accents much like underlines.
var innerGroup = buildGroup$1(group.base, options);
var accentBody = stretchy.svgSpan(group, options);
var kern = group.label === "\\utilde" ? 0.12 : 0; // Generate the vlist, with the appropriate kerns
var 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) => {
var accentNode = stretchy.mathMLnode(group.label);
var node = new mathMLTree.MathNode("munder", [buildGroup(group.base, options), accentNode]);
node.setAttribute("accentunder", "true");
return node;
}
});
// Helper function
var paddedNode = group => {
var 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(_ref, args, optArgs) {
var {
parser,
funcName
} = _ref;
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, options) {
var 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.
var newOptions = options.havingStyle(style.sup());
var upperGroup = buildCommon.wrapFragment(buildGroup$1(group.body, newOptions, options), options);
var arrowPrefix = group.label.slice(0, 2) === "\\x" ? "x" : "cd";
upperGroup.classes.push(arrowPrefix + "-arrow-pad");
var lowerGroup;
if (group.below) {
// Build the lower group
newOptions = options.havingStyle(style.sub());
lowerGroup = buildCommon.wrapFragment(buildGroup$1(group.below, newOptions, options), options);
lowerGroup.classes.push(arrowPrefix + "-arrow-pad");
}
var 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.
var arrowShift = -options.fontMetrics().axisHeight + 0.5 * arrowBody.height; // 2 mu kern. Ref: amsmath.dtx: #7\if0#2\else\mkern#2mu\fi
var 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
var vlist;
if (lowerGroup) {
var 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) {
var arrowNode = stretchy.mathMLnode(group.label);
arrowNode.setAttribute("minsize", group.label.charAt(0) === "x" ? "1.75em" : "3.0em");
var node;
if (group.body) {
var upperNode = paddedNode(buildGroup(group.body, options));
if (group.below) {
var lowerNode = paddedNode(buildGroup(group.below, options));
node = new mathMLTree.MathNode("munderover", [arrowNode, lowerNode, upperNode]);
} else {
node = new mathMLTree.MathNode("mover", [arrowNode, upperNode]);
}
} else if (group.below) {
var _lowerNode = paddedNode(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;
}
});
var makeSpan = buildCommon.makeSpan;
function htmlBuilder$9(group, options) {
var elements = buildExpression$1(group.body, options, true);
return makeSpan([group.mclass], elements, options);
}
function mathmlBuilder$8(group, options) {
var node;
var inner = 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(_ref, args) {
var {
parser,
funcName
} = _ref;
var 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: htmlBuilder$9,
mathmlBuilder: mathmlBuilder$8
});
var binrelClass = arg => {
// \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.
var 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(_ref2, args) {
var {
parser
} = _ref2;
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(_ref3, args) {
var {
parser,
funcName
} = _ref3;
var baseArg = args[1];
var shiftedArg = args[0];
var mclass;
if (funcName !== "\\stackrel") {
// LaTeX applies \binrel spacing to \overset and \underset.
mclass = binrelClass(baseArg);
} else {
mclass = "mrel"; // for \stackrel
}
var baseOp = {
type: "op",
mode: baseArg.mode,
limits: true,
alwaysHandleSupSub: true,
parentIsSupSub: false,
symbol: false,
suppressBaseShift: funcName !== "\\stackrel",
body: ordargument(baseArg)
};
var 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: htmlBuilder$9,
mathmlBuilder: mathmlBuilder$8
});
// \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(_ref, args) {
var {
parser
} = _ref;
return {
type: "pmb",
mode: parser.mode,
mclass: binrelClass(args[0]),
body: ordargument(args[0])
};
},
htmlBuilder(group, options) {
var elements = buildExpression$1(group.body, options, true);
var node = buildCommon.makeSpan([group.mclass], elements, options);
node.style.textShadow = "0.02em 0.01em 0.04px";
return node;
},
mathmlBuilder(group, style) {
var inner = buildExpression(group.body, style); // Wrap with an <mstyle> element.
var node = new mathMLTree.MathNode("mstyle", inner);
node.setAttribute("style", "text-shadow: 0.02em 0.01em 0.04px");
return node;
}
});
var cdArrowFunctionName = {
">": "\\\\cdrightarrow",
"<": "\\\\cdleftarrow",
"=": "\\\\cdlongequal",
"A": "\\uparrow",
"V": "\\downarrow",
"|": "\\Vert",
".": "no arrow"
};
var 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"
};
};
var isStartOfArrow = node => {
return node.type === "textord" && node.text === "@";
};
var isLabelEnd = (node, endChar) => {
return (node.type === "mathord" || node.type === "atom") && node.text === endChar;
};
function cdArrow(arrowChar, labels, parser) {
// Return a parse tree of an arrow and its labels.
// This acts in a way similar to a macro expansion.
var funcName = cdArrowFunctionName[arrowChar];
switch (funcName) {
case "\\\\cdrightarrow":
case "\\\\cdleftarrow":
return parser.callFunction(funcName, [labels[0]], [labels[1]]);
case "\\uparrow":
case "\\downarrow":
{
var leftLabel = parser.callFunction("\\\\cdleft", [labels[0]], []);
var bareArrow = {
type: "atom",
text: funcName,
mode: "math",
family: "rel"
};
var sizedArrow = parser.callFunction("\\Big", [bareArrow], []);
var rightLabel = parser.callFunction("\\\\cdright", [labels[1]], []);
var arrowGroup = {
type: "ordgroup",
mode: "math",
body: [leftLabel, sizedArrow, rightLabel]
};
return parser.callFunction("\\\\cdparent", [arrowGroup], []);
}
case "\\\\cdlongequal":
return parser.callFunction("\\\\cdlongequal", [], []);
case "\\Vert":
{
var arrow = {
type: "textord",
text: "\\Vert",
mode: "math"
};
return parser.callFunction("\\Big", [arrow], []);
}
default:
return {
type: "textord",
text: " ",
mode: "math"
};
}
}
function parseCD(parser) {
// Get the array's parse nodes with \\ temporarily mapped to \cr.
var parsedRows = [];
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();
var 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);
}
}
var row = [];
var body = [row]; // Loop thru the parse nodes. Collect them into cells and arrows.
for (var i = 0; i < parsedRows.length; i++) {
// Start a new row.
var rowNodes = parsedRows[i]; // Create the first cell.
var cell = newCell();
for (var 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;
var arrowChar = assertSymbolNodeType(rowNodes[j]).text; // Create two empty label nodes. We may or may not use them.
var labels = new Array(2);
labels[0] = {
type: "ordgroup",
mode: "math",
body: []
};
labels[1] = {
type: "ordgroup",
mode: "math",
body: []
}; // Process the arrow.
if ("=|.".indexOf(arrowChar) > -1) ; 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 (var labelNum = 0; labelNum < 2; labelNum++) {
var inLabel = true;
for (var 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.
var arrow = cdArrow(arrowChar, labels, parser); // Wrap the arrow in ParseNode<"styling">.
// This is done to match parseArray() behavior.
var 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.
var 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(_ref, args) {
var {
parser,
funcName
} = _ref;
return {
type: "cdlabel",
mode: parser.mode,
side: funcName.slice(4),
label: args[0]
};
},
htmlBuilder(group, options) {
var newOptions = options.havingStyle(options.style.sup());
var label = buildCommon.wrapFragment(buildGroup$1(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) {
var label = new mathMLTree.MathNode("mrow", [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(_ref2, args) {
var {
parser
} = _ref2;
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.
var parent = buildCommon.wrapFragment(buildGroup$1(group.fragment, options), options);
parent.classes.push("cd-vert-arrow");
return parent;
},
mathmlBuilder(group, options) {
return new mathMLTree.MathNode("mrow", [buildGroup(group.fragment, options)]);
}
});
// {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(_ref, args) {
var {
parser
} = _ref;
var arg = assertNodeType(args[0], "ordgroup");
var group = arg.body;
var number = "";
for (var i = 0; i < group.length; i++) {
var node = assertNodeType(group[i], "textord");
number += node.text;
}
var code = parseInt(number);
var 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
};
}
});
var htmlBuilder$8 = (group, options) => {
var elements = buildExpression$1(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);
};
var mathmlBuilder$7 = (group, options) => {
var inner = buildExpression(group.body, options.withColor(group.color));
var 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(_ref, args) {
var {
parser
} = _ref;
var color = assertNodeType(args[0], "color-token").color;
var body = args[1];
return {
type: "color",
mode: parser.mode,
color,
body: ordargument(body)
};
},
htmlBuilder: htmlBuilder$8,
mathmlBuilder: mathmlBuilder$7
});
defineFunction({
type: "color",
names: ["\\color"],
props: {
numArgs: 1,
allowedInText: true,
argTypes: ["color"]
},
handler(_ref2, args) {
var {
parser,
breakOnTokenText
} = _ref2;
var 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.
var body = parser.parseExpression(true, breakOnTokenText);
return {
type: "color",
mode: parser.mode,
color,
body
};
},
htmlBuilder: htmlBuilder$8,
mathmlBuilder: mathmlBuilder$7
});
// Row breaks within tabular environments, and line breaks at top level
defineFunction({
type: "cr",
names: ["\\\\"],
props: {
numArgs: 0,
numOptionalArgs: 0,
allowedInText: true
},
handler(_ref, args, optArgs) {
var {
parser
} = _ref;
var size = parser.gullet.future().text === "[" ? parser.parseSizeGroup(true) : null;
var 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) {
var 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) {
var 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;
}
});
var globalMap = {
"\\global": "\\global",
"\\long": "\\\\globallong",
"\\\\globallong": "\\\\globallong",
"\\def": "\\gdef",
"\\gdef": "\\gdef",
"\\edef": "\\xdef",
"\\xdef": "\\xdef",
"\\let": "\\\\globallet",
"\\futurelet": "\\\\globalfuture"
};
var checkControlSequence = tok => {
var name = tok.text;
if (/^(?:[\\{}$&#^_]|EOF)$/.test(name)) {
throw new ParseError("Expected a control sequence", tok);
}
return name;
};
var getRHS = parser => {
var 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;
};
var letCommand = (parser, name, tok, global) => {
var 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" // can’t be entered directly
],
props: {
numArgs: 0,
allowedInText: true
},
handler(_ref) {
var {
parser,
funcName
} = _ref;
parser.consumeSpaces();
var 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(_ref2) {
var {
parser,
funcName
} = _ref2;
var tok = parser.gullet.popToken();
var name = tok.text;
if (/^(?:[\\{}$&#^_]|EOF)$/.test(name)) {
throw new ParseError("Expected a control sequence", tok);
}
var numArgs = 0;
var insert;
var 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
var {
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" // can’t be entered directly
],
props: {
numArgs: 0,
allowedInText: true,
primitive: true
},
handler(_ref3) {
var {
parser,
funcName
} = _ref3;
var name = checkControlSequence(parser.gullet.popToken());
parser.gullet.consumeSpaces();
var 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" // can’t be entered directly
],
props: {
numArgs: 0,
allowedInText: true,
primitive: true
},
handler(_ref4) {
var {
parser,
funcName
} = _ref4;
var name = checkControlSequence(parser.gullet.popToken());
var middle = parser.gullet.popToken();
var tok = parser.gullet.popToken();
letCommand(parser, name, tok, funcName === "\\\\globalfuture");
parser.gullet.pushToken(tok);
parser.gullet.pushToken(middle);
return {
type: "internal",
mode: parser.mode
};
}
});
/**
* 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`.
*/
/**
* Get the metrics for a given symbol and font, after transformation (i.e.
* after following replacement from symbols.js)
*/
var getMetrics = function getMetrics(symbol, font, mode) {
var replace = symbols.math[symbol] && symbols.math[symbol].replace;
var 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.
*/
var styleWrap = function styleWrap(delim, toStyle, options, classes) {
var newOptions = options.havingBaseStyle(toStyle);
var span = buildCommon.makeSpan(classes.concat(newOptions.sizingClasses(options)), [delim], options);
var delimSizeMultiplier = newOptions.sizeMultiplier / options.sizeMultiplier;
span.height *= delimSizeMultiplier;
span.depth *= delimSizeMultiplier;
span.maxFontSize = newOptions.sizeMultiplier;
return span;
};
var centerSpan = function centerSpan(span, options, style) {
var newOptions = options.havingBaseStyle(style);
var 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.
*/
var makeSmallDelim = function makeSmallDelim(delim, style, center, options, mode, classes) {
var text = buildCommon.makeSymbol(delim, "Main-Regular", mode, options);
var 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)
*/
var mathrmSize = function mathrmSize(value, size, mode, options) {
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.
*/
var makeLargeDelim = function makeLargeDelim(delim, size, center, options, mode, classes) {
var inner = mathrmSize(delim, size, mode, options);
var span = styleWrap(buildCommon.makeSpan(["delimsizing", "size" + size], [inner], options), Style$1.TEXT, options, classes);
if (center) {
centerSpan(span, options, Style$1.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.
*/
var makeGlyphSpan = function makeGlyphSpan(symbol, font, mode) {
var 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";
}
var 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
};
};
var makeInner = function makeInner(ch, height, options) {
// Create a span with inline SVG for the inner part of a tall stacked delimiter.
var width = fontMetricsData['Size4-Regular'][ch.charCodeAt(0)] ? fontMetricsData['Size4-Regular'][ch.charCodeAt(0)][4] : fontMetricsData['Size1-Regular'][ch.charCodeAt(0)][4];
var path = new PathNode("inner", innerPath(ch, Math.round(1000 * height)));
var 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"
});
var 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
var lapInEms = 0.008;
var lap = {
type: "kern",
size: -1 * lapInEms
};
var verts = ["|", "\\lvert", "\\rvert", "\\vert"];
var 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.
*/
var makeStackedDelim = function makeStackedDelim(delim, heightTotal, center, options, mode, classes) {
// There are four parts, the top, an optional middle, a repeated part, and a
// bottom.
var top;
var middle;
var repeat;
var bottom;
var svgLabel = "";
var viewBoxWidth = 0;
top = repeat = bottom = delim;
middle = null; // Also keep track of what font the delimiters are in
var 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
var topMetrics = getMetrics(top, font, mode);
var topHeightTotal = topMetrics.height + topMetrics.depth;
var repeatMetrics = getMetrics(repeat, font, mode);
var repeatHeightTotal = repeatMetrics.height + repeatMetrics.depth;
var bottomMetrics = getMetrics(bottom, font, mode);
var bottomHeightTotal = bottomMetrics.height + bottomMetrics.depth;
var middleHeightTotal = 0;
var middleFactor = 1;
if (middle !== null) {
var 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.
var minHeight = topHeightTotal + bottomHeightTotal + middleHeightTotal; // Compute the number of copies of the repeat symbol we will need
var repeatCount = Math.max(0, Math.ceil((heightTotal - minHeight) / (middleFactor * repeatHeightTotal))); // Compute the total height of the delimiter including all the symbols
var 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.
var axisHeight = options.fontMetrics().axisHeight;
if (center) {
axisHeight *= options.sizeMultiplier;
} // Calculate the depth
var 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
var stack = [];
if (svgLabel.length > 0) {
// Instead of stacking glyphs, create a single SVG.
// This evades browser problems with imprecise positioning of spans.
var midHeight = realHeightTotal - topHeightTotal - bottomHeightTotal;
var viewBoxHeight = Math.round(realHeightTotal * 1000);
var pathStr = tallDelim(svgLabel, Math.round(midHeight * 1000));
var path = new PathNode(svgLabel, pathStr);
var width = (viewBoxWidth / 1000).toFixed(3) + "em";
var height = (viewBoxHeight / 1000).toFixed(3) + "em";
var svg = new SvgNode([path], {
"width": width,
"height": height,
"viewBox": "0 0 " + viewBoxWidth + " " + viewBoxHeight
});
var 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.
var 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
var _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
var newOptions = options.havingBaseStyle(Style$1.TEXT);
var inner = buildCommon.makeVList({
positionType: "bottom",
positionData: depth,
children: stack
}, newOptions);
return styleWrap(buildCommon.makeSpan(["delimsizing", "mult"], [inner], newOptions), Style$1.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.
var vbPad = 80; // padding above the surd, measured inside the viewBox.
var emPad = 0.08; // padding, in ems, measured in the document.
var sqrtSvg = function sqrtSvg(sqrtName, height, viewBoxHeight, extraVinculum, options) {
var path = sqrtPath(sqrtName, extraVinculum, viewBoxHeight);
var pathNode = new PathNode(sqrtName, path);
var 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,
*/
var makeSqrtImage = function makeSqrtImage(height, options) {
// 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.
var newOptions = options.havingBaseSizing(); // Pick the desired surd glyph from a sequence of surds.
var delim = traverseSequence("\\surd", height * newOptions.sizeMultiplier, stackLargeDelimiterSequence, newOptions);
var 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.
var extraVinculum = Math.max(0, options.minRuleThickness - options.fontMetrics().sqrtRuleThickness); // Create a span containing an SVG image of a sqrt symbol.
var span;
var spanHeight = 0;
var texHeight = 0;
var viewBoxHeight = 0;
var 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
var stackLargeDelimiters = ["(", "\\lparen", ")", "\\rparen", "[", "\\lbrack", "]", "\\rbrack", "\\{", "\\lbrace", "\\}", "\\rbrace", "\\lfloor", "\\rfloor", "\u230a", "\u230b", "\\lceil", "\\rceil", "\u2308", "\u2309", "\\surd"]; // delimiters that always stack
var 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
var 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.
var 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.
*/
var makeSizedDelim = function makeSizedDelim(delim, size, options, mode, classes) {
// < 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.
*/
// Delimiters that never stack try small delimiters and large delimiters only
var stackNeverDelimiterSequence = [{
type: "small",
style: Style$1.SCRIPTSCRIPT
}, {
type: "small",
style: Style$1.SCRIPT
}, {
type: "small",
style: Style$1.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
var stackAlwaysDelimiterSequence = [{
type: "small",
style: Style$1.SCRIPTSCRIPT
}, {
type: "small",
style: Style$1.SCRIPT
}, {
type: "small",
style: Style$1.TEXT
}, {
type: "stack"
}]; // Delimiters that stack when large try the small and then large delimiters, and
// stack afterwards
var stackLargeDelimiterSequence = [{
type: "small",
style: Style$1.SCRIPTSCRIPT
}, {
type: "small",
style: Style$1.SCRIPT
}, {
type: "small",
style: Style$1.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.
*/
var delimTypeToFont = function delimTypeToFont(type) {
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.
*/
var traverseSequence = function traverseSequence(delim, height, sequence, options) {
// 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
var start = Math.min(2, 3 - options.style.size);
for (var 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;
}
var metrics = getMetrics(delim, delimTypeToFont(sequence[i]), "math");
var 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") {
var 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.
*/
var makeCustomSizedDelim = function makeCustomSizedDelim(delim, height, center, options, mode, classes) {
if (delim === "<" || delim === "\\lt" || delim === "\u27e8") {
delim = "\\langle";
} else if (delim === ">" || delim === "\\gt" || delim === "\u27e9") {
delim = "\\rangle";
} // Decide what sequence to use
var sequence;
if (utils.contains(stackNeverDelimiters, delim)) {
sequence = stackNeverDelimiterSequence;
} else if (utils.contains(stackLargeDelimiters, delim)) {
sequence = stackLargeDelimiterSequence;
} else {
sequence = stackAlwaysDelimiterSequence;
} // Look through the sequence
var 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.
*/
var makeLeftRightDelim = function makeLeftRightDelim(delim, height, depth, options, mode, classes) {
// We always center \left/\right delimiters, so the axis is always shifted
var axisHeight = options.fontMetrics().axisHeight * options.sizeMultiplier; // Taken from TeX source, tex.web, function make_left_right
var delimiterFactor = 901;
var delimiterExtend = 5.0 / options.fontMetrics().ptPerEm;
var maxDistFromAxis = Math.max(height - axisHeight, depth + axisHeight);
var 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);
};
var delimiter = {
sqrtImage: makeSqrtImage,
sizedDelim: makeSizedDelim,
sizeToMaxHeight: sizeToMaxHeight,
customSizedDelim: makeCustomSizedDelim,
leftRightDelim: makeLeftRightDelim
};
// Extra data needed for the delimiter handler down below
var 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
}
};
var 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", "."];
// Delimiter functions
function checkDelimiter(delim, context) {
var 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) => {
var 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 => {
var children = [];
if (group.delim !== ".") {
children.push(makeText(group.delim, group.mode));
}
var 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");
var size = makeEm(delimiter.sizeToMaxHeight[group.size]);
node.setAttribute("minsize", size);
node.setAttribute("maxsize", size);
return node;
}
});
function assertParsed(group) {
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.
var 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) => {
var delim = checkDelimiter(args[0], context);
var parser = context.parser; // Parse out the implicit body
++parser.leftrightDepth; // parseExpression stops before '\\right'
var body = parser.parseExpression(false);
--parser.leftrightDepth; // Check the next token
parser.expect("\\right", false);
var 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
var inner = buildExpression$1(group.body, options, true, ["mopen", "mclose"]);
var innerHeight = 0;
var innerDepth = 0;
var hadMiddle = false; // Calculate its height and depth
for (var 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;
var leftDelim;
if (group.left === ".") {
// Empty delimiters in \left and \right make null delimiter spaces.
leftDelim = 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 (var _i = 1; _i < inner.length; _i++) {
var middleDelim = inner[_i]; // Property `isMiddle` not defined on `span`. See comment in
// "middle"'s htmlBuilder.
// $FlowFixMe
var 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, []);
}
}
}
var rightDelim; // Same for the right delimiter, but using color specified by \color
if (group.right === ".") {
rightDelim = makeNullDelimiter(options, ["mclose"]);
} else {
var 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);
var inner = buildExpression(group.body, options);
if (group.left !== ".") {
var leftNode = new mathMLTree.MathNode("mo", [makeText(group.left, group.mode)]);
leftNode.setAttribute("fence", "true");
inner.unshift(leftNode);
}
if (group.right !== ".") {
var rightNode = new mathMLTree.MathNode("mo", [makeText(group.right, group.mode)]);
rightNode.setAttribute("fence", "true");
if (group.rightColor) {
rightNode.setAttribute("mathcolor", group.rightColor);
}
inner.push(rightNode);
}
return makeRow(inner);
}
});
defineFunction({
type: "middle",
names: ["\\middle"],
props: {
numArgs: 1,
primitive: true
},
handler: (context, args) => {
var 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) => {
var middleDelim;
if (group.delim === ".") {
middleDelim = makeNullDelimiter(options, []);
} else {
middleDelim = delimiter.sizedDelim(group.delim, 1, options, group.mode, []);
var 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.
var textNode = group.delim === "\\vert" || group.delim === "|" ? makeText("|", "text") : makeText(group.delim, group.mode);
var 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;
}
});
var htmlBuilder$7 = (group, options) => {
// \cancel, \bcancel, \xcancel, \sout, \fbox, \colorbox, \fcolorbox, \phase
// Some groups can return document fragments. Handle those by wrapping
// them in a span.
var inner = buildCommon.wrapFragment(buildGroup$1(group.body, options), options);
var label = group.label.slice(1);
var scale = options.sizeMultiplier;
var img;
var 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.
var 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.
var lineWeight = calculateSize({
number: 0.6,
unit: "pt"
}, options);
var clearance = calculateSize({
number: 0.35,
unit: "ex"
}, options); // Prevent size changes like \Huge from affecting line thickness
var newOptions = options.havingBaseSizing();
scale = scale / newOptions.sizeMultiplier;
var angleHeight = inner.height + inner.depth + lineWeight + clearance; // Reserve a left pad for the angle.
inner.style.paddingLeft = makeEm(angleHeight / 2 + lineWeight); // Create an SVG
var viewBoxHeight = Math.floor(1000 * angleHeight * scale);
var path = phasePath(viewBoxHeight);
var 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
var topPad = 0;
var bottomPad = 0;
var 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;
}
}
}
var 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 {
var 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);
}
};
var mathmlBuilder$6 = (group, options) => {
var fboxsep = 0;
var node = new mathMLTree.MathNode(group.label.indexOf("colorbox") > -1 ? "mpadded" : "menclose", [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") {
var 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(_ref, args, optArgs) {
var {
parser,
funcName
} = _ref;
var color = assertNodeType(args[0], "color-token").color;
var body = args[1];
return {
type: "enclose",
mode: parser.mode,
label: funcName,
backgroundColor: color,
body
};
},
htmlBuilder: htmlBuilder$7,
mathmlBuilder: mathmlBuilder$6
});
defineFunction({
type: "enclose",
names: ["\\fcolorbox"],
props: {
numArgs: 3,
allowedInText: true,
argTypes: ["color", "color", "text"]
},
handler(_ref2, args, optArgs) {
var {
parser,
funcName
} = _ref2;
var borderColor = assertNodeType(args[0], "color-token").color;
var backgroundColor = assertNodeType(args[1], "color-token").color;
var body = args[2];
return {
type: "enclose",
mode: parser.mode,
label: funcName,
backgroundColor,
borderColor,
body
};
},
htmlBuilder: htmlBuilder$7,
mathmlBuilder: mathmlBuilder$6
});
defineFunction({
type: "enclose",
names: ["\\fbox"],
props: {
numArgs: 1,
argTypes: ["hbox"],
allowedInText: true
},
handler(_ref3, args) {
var {
parser
} = _ref3;
return {
type: "enclose",
mode: parser.mode,
label: "\\fbox",
body: args[0]
};
}
});
defineFunction({
type: "enclose",
names: ["\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\phase"],
props: {
numArgs: 1
},
handler(_ref4, args) {
var {
parser,
funcName
} = _ref4;
var body = args[0];
return {
type: "enclose",
mode: parser.mode,
label: funcName,
body
};
},
htmlBuilder: htmlBuilder$7,
mathmlBuilder: mathmlBuilder$6
});
defineFunction({
type: "enclose",
names: ["\\angl"],
props: {
numArgs: 1,
argTypes: ["hbox"],
allowedInText: false
},
handler(_ref5, args) {
var {
parser
} = _ref5;
return {
type: "enclose",
mode: parser.mode,
label: "\\angl",
body: args[0]
};
}
});
/**
* All registered environments.
* `environments.js` exports this same dictionary again and makes it public.
* `Parser.js` requires this dictionary via `environments.js`.
*/
var _environments = {};
function defineEnvironment(_ref) {
var {
type,
names,
props,
handler,
htmlBuilder,
mathmlBuilder
} = _ref;
// Set default values of environments.
var data = {
type,
numArgs: props.numArgs || 0,
allowedInText: false,
numOptionalArgs: 0,
handler
};
for (var 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;
}
}
/**
* 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`.
*/
var _macros = {}; // This function might one day accept an additional argument and do more things.
function defineMacro(name, body) {
_macros[name] = body;
}
// Helper functions
function getHLines(parser) {
// Return an array. The array length = number of hlines.
// Each element in the array tells if the line is dashed.
var hlineInfo = [];
parser.consumeSpaces();
var nxt = parser.fetch().text;
if (nxt === "\\relax") {
// \relax is an artifact of the \cr macro below
parser.consume();
parser.consumeSpaces();
nxt = parser.fetch().text;
}
while (nxt === "\\hline" || nxt === "\\hdashline") {
parser.consume();
hlineInfo.push(nxt === "\\hdashline");
parser.consumeSpaces();
nxt = parser.fetch().text;
}
return hlineInfo;
}
var validateAmsEnvironmentContext = context => {
var settings = context.parser.settings;
if (!settings.displayMode) {
throw new ParseError("{" + context.envName + "} can be used only in" + " display mode.");
}
}; // autoTag (an argument to parseArray) can be one of three values:
// * undefined: Regular (not-top-level) array; no tags on each row
// * true: Automatic equation numbering, overridable by \tag
// * false: Tags allowed on each row, but no automatic numbering
// This function *doesn't* work with the "split" environment name.
function getAutoTag(name) {
if (name.indexOf("ed") === -1) {
return name.indexOf("*") === -1;
} // return undefined;
}
/**
* Parse the body of the environment, with rows delimited by \\ and
* columns delimited by &, and create a nested list in row-major order
* with one group per cell. If given an optional argument style
* ("text", "display", etc.), then each cell is cast into that style.
*/
function parseArray(parser, _ref, style) {
var {
hskipBeforeAndAfter,
addJot,
cols,
arraystretch,
colSeparationType,
autoTag,
singleRow,
emptySingleRow,
maxNumCols,
leqno
} = _ref;
parser.gullet.beginGroup();
if (!singleRow) {
// \cr is equivalent to \\ without the optional size argument (see below)
// TODO: provide helpful error when \cr is used outside array environment
parser.gullet.macros.set("\\cr", "\\\\\\relax");
} // Get current arraystretch if it's not set by the environment
if (!arraystretch) {
var stretch = parser.gullet.expandMacroAsText("\\arraystretch");
if (stretch == null) {
// Default \arraystretch from lttab.dtx
arraystretch = 1;
} else {
arraystretch = parseFloat(stretch);
if (!arraystretch || arraystretch < 0) {
throw new ParseError("Invalid \\arraystretch: " + stretch);
}
}
} // Start group for first cell
parser.gullet.beginGroup();
var row = [];
var body = [row];
var rowGaps = [];
var hLinesBeforeRow = [];
var tags = autoTag != null ? [] : undefined; // amsmath uses \global\@eqnswtrue and \global\@eqnswfalse to represent
// whether this row should have an equation number. Simulate this with
// a \@eqnsw macro set to 1 or 0.
function beginRow() {
if (autoTag) {
parser.gullet.macros.set("\\@eqnsw", "1", true);
}
}
function endRow() {
if (tags) {
if (parser.gullet.macros.get("\\df@tag")) {
tags.push(parser.subparse([new Token("\\df@tag")]));
parser.gullet.macros.set("\\df@tag", undefined, true);
} else {
tags.push(Boolean(autoTag) && parser.gullet.macros.get("\\@eqnsw") === "1");
}
}
}
beginRow(); // Test for \hline at the top of the array.
hLinesBeforeRow.push(getHLines(parser));
while (true) {
// eslint-disable-line no-constant-condition
// Parse each cell in its own group (namespace)
var cell = parser.parseExpression(false, singleRow ? "\\end" : "\\\\");
parser.gullet.endGroup();
parser.gullet.beginGroup();
cell = {
type: "ordgroup",
mode: parser.mode,
body: cell
};
if (style) {
cell = {
type: "styling",
mode: parser.mode,
style,
body: [cell]
};
}
row.push(cell);
var next = parser.fetch().text;
if (next === "&") {
if (maxNumCols && row.length === maxNumCols) {
if (singleRow || colSeparationType) {
// {equation} or {split}
throw new ParseError("Too many tab characters: &", parser.nextToken);
} else {
// {array} environment
parser.settings.reportNonstrict("textEnv", "Too few columns " + "specified in the {array} column argument.");
}
}
parser.consume();
} else if (next === "\\end") {
endRow(); // Arrays terminate newlines with `\crcr` which consumes a `\cr` if
// the last line is empty. However, AMS environments keep the
// empty row if it's the only one.
// NOTE: Currently, `cell` is the last item added into `row`.
if (row.length === 1 && cell.type === "styling" && cell.body[0].body.length === 0 && (body.length > 1 || !emptySingleRow)) {
body.pop();
}
if (hLinesBeforeRow.length < body.length + 1) {
hLinesBeforeRow.push([]);
}
break;
} else if (next === "\\\\") {
parser.consume();
var size = void 0; // \def\Let@{\let\\\math@cr}
// \def\math@cr{...\math@cr@}
// \def\math@cr@{\new@ifnextchar[\math@cr@@{\math@cr@@[\z@]}}
// \def\math@cr@@[#1]{...\math@cr@@@...}
// \def\math@cr@@@{\cr}
if (parser.gullet.future().text !== " ") {
size = parser.parseSizeGroup(true);
}
rowGaps.push(size ? size.value : null);
endRow(); // check for \hline(s) following the row separator
hLinesBeforeRow.push(getHLines(parser));
row = [];
body.push(row);
beginRow();
} else {
throw new ParseError("Expected & or \\\\ or \\cr or \\end", parser.nextToken);
}
} // End cell group
parser.gullet.endGroup(); // End array group defining \cr
parser.gullet.endGroup();
return {
type: "array",
mode: parser.mode,
addJot,
arraystretch,
body,
cols,
rowGaps,
hskipBeforeAndAfter,
hLinesBeforeRow,
colSeparationType,
tags,
leqno
};
} // Decides on a style for cells in an array according to whether the given
// environment name starts with the letter 'd'.
function dCellStyle(envName) {
if (envName.slice(0, 1) === "d") {
return "display";
} else {
return "text";
}
}
var htmlBuilder$6 = function htmlBuilder(group, options) {
var r;
var c;
var nr = group.body.length;
var hLinesBeforeRow = group.hLinesBeforeRow;
var nc = 0;
var body = new Array(nr);
var hlines = [];
var ruleThickness = Math.max( // From LaTeX \showthe\arrayrulewidth. Equals 0.04 em.
options.fontMetrics().arrayRuleWidth, options.minRuleThickness // User override.
); // Horizontal spacing
var pt = 1 / options.fontMetrics().ptPerEm;
var arraycolsep = 5 * pt; // default value, i.e. \arraycolsep in article.cls
if (group.colSeparationType && group.colSeparationType === "small") {
// We're in a {smallmatrix}. Default column space is \thickspace,
// i.e. 5/18em = 0.2778em, per amsmath.dtx for {smallmatrix}.
// But that needs adjustment because LaTeX applies \scriptstyle to the
// entire array, including the colspace, but this function applies
// \scriptstyle only inside each element.
var localMultiplier = options.havingStyle(Style$1.SCRIPT).sizeMultiplier;
arraycolsep = 0.2778 * (localMultiplier / options.sizeMultiplier);
} // Vertical spacing
var baselineskip = group.colSeparationType === "CD" ? calculateSize({
number: 3,
unit: "ex"
}, options) : 12 * pt; // see size10.clo
// Default \jot from ltmath.dtx
// TODO(edemaine): allow overriding \jot via \setlength (#687)
var jot = 3 * pt;
var arrayskip = group.arraystretch * baselineskip;
var arstrutHeight = 0.7 * arrayskip; // \strutbox in ltfsstrc.dtx and
var arstrutDepth = 0.3 * arrayskip; // \@arstrutbox in lttab.dtx
var totalHeight = 0; // Set a position for \hline(s) at the top of the array, if any.
function setHLinePos(hlinesInGap) {
for (var i = 0; i < hlinesInGap.length; ++i) {
if (i > 0) {
totalHeight += 0.25;
}
hlines.push({
pos: totalHeight,
isDashed: hlinesInGap[i]
});
}
}
setHLinePos(hLinesBeforeRow[0]);
for (r = 0; r < group.body.length; ++r) {
var inrow = group.body[r];
var height = arstrutHeight; // \@array adds an \@arstrut
var depth = arstrutDepth; // to each tow (via the template)
if (nc < inrow.length) {
nc = inrow.length;
}
var outrow = new Array(inrow.length);
for (c = 0; c < inrow.length; ++c) {
var elt = buildGroup$1(inrow[c], options);
if (depth < elt.depth) {
depth = elt.depth;
}
if (height < elt.height) {
height = elt.height;
}
outrow[c] = elt;
}
var rowGap = group.rowGaps[r];
var gap = 0;
if (rowGap) {
gap = calculateSize(rowGap, options);
if (gap > 0) {
// \@argarraycr
gap += arstrutDepth;
if (depth < gap) {
depth = gap; // \@xargarraycr
}
gap = 0;
}
} // In AMS multiline environments such as aligned and gathered, rows
// correspond to lines that have additional \jot added to the
// \baselineskip via \openup.
if (group.addJot) {
depth += jot;
}
outrow.height = height;
outrow.depth = depth;
totalHeight += height;
outrow.pos = totalHeight;
totalHeight += depth + gap; // \@yargarraycr
body[r] = outrow; // Set a position for \hline(s), if any.
setHLinePos(hLinesBeforeRow[r + 1]);
}
var offset = totalHeight / 2 + options.fontMetrics().axisHeight;
var colDescriptions = group.cols || [];
var cols = [];
var colSep;
var colDescrNum;
var tagSpans = [];
if (group.tags && group.tags.some(tag => tag)) {
// An environment with manual tags and/or automatic equation numbers.
// Create node(s), the latter of which trigger CSS counter increment.
for (r = 0; r < nr; ++r) {
var rw = body[r];
var shift = rw.pos - offset;
var tag = group.tags[r];
var tagSpan = void 0;
if (tag === true) {
// automatic numbering
tagSpan = buildCommon.makeSpan(["eqn-num"], [], options);
} else if (tag === false) {
// \nonumber/\notag or starred environment
tagSpan = buildCommon.makeSpan([], [], options);
} else {
// manual \tag
tagSpan = buildCommon.makeSpan([], buildExpression$1(tag, options, true), options);
}
tagSpan.depth = rw.depth;
tagSpan.height = rw.height;
tagSpans.push({
type: "elem",
elem: tagSpan,
shift
});
}
}
for (c = 0, colDescrNum = 0; // Continue while either there are more columns or more column
// descriptions, so trailing separators don't get lost.
c < nc || colDescrNum < colDescriptions.length; ++c, ++colDescrNum) {
var colDescr = colDescriptions[colDescrNum] || {};
var firstSeparator = true;
while (colDescr.type === "separator") {
// If there is more than one separator in a row, add a space
// between them.
if (!firstSeparator) {
colSep = buildCommon.makeSpan(["arraycolsep"], []);
colSep.style.width = makeEm(options.fontMetrics().doubleRuleSep);
cols.push(colSep);
}
if (colDescr.separator === "|" || colDescr.separator === ":") {
var lineType = colDescr.separator === "|" ? "solid" : "dashed";
var separator = buildCommon.makeSpan(["vertical-separator"], [], options);
separator.style.height = makeEm(totalHeight);
separator.style.borderRightWidth = makeEm(ruleThickness);
separator.style.borderRightStyle = lineType;
separator.style.margin = "0 " + makeEm(-ruleThickness / 2);
var _shift = totalHeight - offset;
if (_shift) {
separator.style.verticalAlign = makeEm(-_shift);
}
cols.push(separator);
} else {
throw new ParseError("Invalid separator type: " + colDescr.separator);
}
colDescrNum++;
colDescr = colDescriptions[colDescrNum] || {};
firstSeparator = false;
}
if (c >= nc) {
continue;
}
var sepwidth = void 0;
if (c > 0 || group.hskipBeforeAndAfter) {
sepwidth = utils.deflt(colDescr.pregap, arraycolsep);
if (sepwidth !== 0) {
colSep = buildCommon.makeSpan(["arraycolsep"], []);
colSep.style.width = makeEm(sepwidth);
cols.push(colSep);
}
}
var col = [];
for (r = 0; r < nr; ++r) {
var row = body[r];
var elem = row[c];
if (!elem) {
continue;
}
var _shift2 = row.pos - offset;
elem.depth = row.depth;
elem.height = row.height;
col.push({
type: "elem",
elem: elem,
shift: _shift2
});
}
col = buildCommon.makeVList({
positionType: "individualShift",
children: col
}, options);
col = buildCommon.makeSpan(["col-align-" + (colDescr.align || "c")], [col]);
cols.push(col);
if (c < nc - 1 || group.hskipBeforeAndAfter) {
sepwidth = utils.deflt(colDescr.postgap, arraycolsep);
if (sepwidth !== 0) {
colSep = buildCommon.makeSpan(["arraycolsep"], []);
colSep.style.width = makeEm(sepwidth);
cols.push(colSep);
}
}
}
body = buildCommon.makeSpan(["mtable"], cols); // Add \hline(s), if any.
if (hlines.length > 0) {
var line = buildCommon.makeLineSpan("hline", options, ruleThickness);
var dashes = buildCommon.makeLineSpan("hdashline", options, ruleThickness);
var vListElems = [{
type: "elem",
elem: body,
shift: 0
}];
while (hlines.length > 0) {
var hline = hlines.pop();
var lineShift = hline.pos - offset;
if (hline.isDashed) {
vListElems.push({
type: "elem",
elem: dashes,
shift: lineShift
});
} else {
vListElems.push({
type: "elem",
elem: line,
shift: lineShift
});
}
}
body = buildCommon.makeVList({
positionType: "individualShift",
children: vListElems
}, options);
}
if (tagSpans.length === 0) {
return buildCommon.makeSpan(["mord"], [body], options);
} else {
var eqnNumCol = buildCommon.makeVList({
positionType: "individualShift",
children: tagSpans
}, options);
eqnNumCol = buildCommon.makeSpan(["tag"], [eqnNumCol], options);
return buildCommon.makeFragment([body, eqnNumCol]);
}
};
var alignMap = {
c: "center ",
l: "left ",
r: "right "
};
var mathmlBuilder$5 = function mathmlBuilder(group, options) {
var tbl = [];
var glue = new mathMLTree.MathNode("mtd", [], ["mtr-glue"]);
var tag = new mathMLTree.MathNode("mtd", [], ["mml-eqn-num"]);
for (var i = 0; i < group.body.length; i++) {
var rw = group.body[i];
var row = [];
for (var j = 0; j < rw.length; j++) {
row.push(new mathMLTree.MathNode("mtd", [buildGroup(rw[j], options)]));
}
if (group.tags && group.tags[i]) {
row.unshift(glue);
row.push(glue);
if (group.leqno) {
row.unshift(tag);
} else {
row.push(tag);
}
}
tbl.push(new mathMLTree.MathNode("mtr", row));
}
var table = new mathMLTree.MathNode("mtable", tbl); // Set column alignment, row spacing, column spacing, and
// array lines by setting attributes on the table element.
// Set the row spacing. In MathML, we specify a gap distance.
// We do not use rowGap[] because MathML automatically increases
// cell height with the height/depth of the element content.
// LaTeX \arraystretch multiplies the row baseline-to-baseline distance.
// We simulate this by adding (arraystretch - 1)em to the gap. This
// does a reasonable job of adjusting arrays containing 1 em tall content.
// The 0.16 and 0.09 values are found empirically. They produce an array
// similar to LaTeX and in which content does not interfere with \hlines.
var gap = group.arraystretch === 0.5 ? 0.1 // {smallmatrix}, {subarray}
: 0.16 + group.arraystretch - 1 + (group.addJot ? 0.09 : 0);
table.setAttribute("rowspacing", makeEm(gap)); // MathML table lines go only between cells.
// To place a line on an edge we'll use <menclose>, if necessary.
var menclose = "";
var align = "";
if (group.cols && group.cols.length > 0) {
// Find column alignment, column spacing, and vertical lines.
var cols = group.cols;
var columnLines = "";
var prevTypeWasAlign = false;
var iStart = 0;
var iEnd = cols.length;
if (cols[0].type === "separator") {
menclose += "top ";
iStart = 1;
}
if (cols[cols.length - 1].type === "separator") {
menclose += "bottom ";
iEnd -= 1;
}
for (var _i = iStart; _i < iEnd; _i++) {
if (cols[_i].type === "align") {
align += alignMap[cols[_i].align];
if (prevTypeWasAlign) {
columnLines += "none ";
}
prevTypeWasAlign = true;
} else if (cols[_i].type === "separator") {
// MathML accepts only single lines between cells.
// So we read only the first of consecutive separators.
if (prevTypeWasAlign) {
columnLines += cols[_i].separator === "|" ? "solid " : "dashed ";
prevTypeWasAlign = false;
}
}
}
table.setAttribute("columnalign", align.trim());
if (/[sd]/.test(columnLines)) {
table.setAttribute("columnlines", columnLines.trim());
}
} // Set column spacing.
if (group.colSeparationType === "align") {
var _cols = group.cols || [];
var spacing = "";
for (var _i2 = 1; _i2 < _cols.length; _i2++) {
spacing += _i2 % 2 ? "0em " : "1em ";
}
table.setAttribute("columnspacing", spacing.trim());
} else if (group.colSeparationType === "alignat" || group.colSeparationType === "gather") {
table.setAttribute("columnspacing", "0em");
} else if (group.colSeparationType === "small") {
table.setAttribute("columnspacing", "0.2778em");
} else if (group.colSeparationType === "CD") {
table.setAttribute("columnspacing", "0.5em");
} else {
table.setAttribute("columnspacing", "1em");
} // Address \hline and \hdashline
var rowLines = "";
var hlines = group.hLinesBeforeRow;
menclose += hlines[0].length > 0 ? "left " : "";
menclose += hlines[hlines.length - 1].length > 0 ? "right " : "";
for (var _i3 = 1; _i3 < hlines.length - 1; _i3++) {
rowLines += hlines[_i3].length === 0 ? "none " // MathML accepts only a single line between rows. Read one element.
: hlines[_i3][0] ? "dashed " : "solid ";
}
if (/[sd]/.test(rowLines)) {
table.setAttribute("rowlines", rowLines.trim());
}
if (menclose !== "") {
table = new mathMLTree.MathNode("menclose", [table]);
table.setAttribute("notation", menclose.trim());
}
if (group.arraystretch && group.arraystretch < 1) {
// A small array. Wrap in scriptstyle so row gap is not too large.
table = new mathMLTree.MathNode("mstyle", [table]);
table.setAttribute("scriptlevel", "1");
}
return table;
}; // Convenience function for align, align*, aligned, alignat, alignat*, alignedat.
var alignedHandler = function alignedHandler(context, args) {
if (context.envName.indexOf("ed") === -1) {
validateAmsEnvironmentContext(context);
}
var cols = [];
var separationType = context.envName.indexOf("at") > -1 ? "alignat" : "align";
var isSplit = context.envName === "split";
var res = parseArray(context.parser, {
cols,
addJot: true,
autoTag: isSplit ? undefined : getAutoTag(context.envName),
emptySingleRow: true,
colSeparationType: separationType,
maxNumCols: isSplit ? 2 : undefined,
leqno: context.parser.settings.leqno
}, "display"); // Determining number of columns.
// 1. If the first argument is given, we use it as a number of columns,
// and makes sure that each row doesn't exceed that number.
// 2. Otherwise, just count number of columns = maximum number
// of cells in each row ("aligned" mode -- isAligned will be true).
//
// At the same time, prepend empty group {} at beginning of every second
// cell in each row (starting with second cell) so that operators become
// binary. This behavior is implemented in amsmath's \start@aligned.
var numMaths;
var numCols = 0;
var emptyGroup = {
type: "ordgroup",
mode: context.mode,
body: []
};
if (args[0] && args[0].type === "ordgroup") {
var arg0 = "";
for (var i = 0; i < args[0].body.length; i++) {
var textord = assertNodeType(args[0].body[i], "textord");
arg0 += textord.text;
}
numMaths = Number(arg0);
numCols = numMaths * 2;
}
var isAligned = !numCols;
res.body.forEach(function (row) {
for (var _i4 = 1; _i4 < row.length; _i4 += 2) {
// Modify ordgroup node within styling node
var styling = assertNodeType(row[_i4], "styling");
var ordgroup = assertNodeType(styling.body[0], "ordgroup");
ordgroup.body.unshift(emptyGroup);
}
if (!isAligned) {
// Case 1
var curMaths = row.length / 2;
if (numMaths < curMaths) {
throw new ParseError("Too many math in a row: " + ("expected " + numMaths + ", but got " + curMaths), row[0]);
}
} else if (numCols < row.length) {
// Case 2
numCols = row.length;
}
}); // Adjusting alignment.
// In aligned mode, we add one \qquad between columns;
// otherwise we add nothing.
for (var _i5 = 0; _i5 < numCols; ++_i5) {
var align = "r";
var pregap = 0;
if (_i5 % 2 === 1) {
align = "l";
} else if (_i5 > 0 && isAligned) {
// "aligned" mode.
pregap = 1; // add one \quad
}
cols[_i5] = {
type: "align",
align: align,
pregap: pregap,
postgap: 0
};
}
res.colSeparationType = isAligned ? "align" : "alignat";
return res;
}; // Arrays are part of LaTeX, defined in lttab.dtx so its documentation
// is part of the source2e.pdf file of LaTeX2e source documentation.
// {darray} is an {array} environment where cells are set in \displaystyle,
// as defined in nccmath.sty.
defineEnvironment({
type: "array",
names: ["array", "darray"],
props: {
numArgs: 1
},
handler(context, args) {
// Since no types are specified above, the two possibilities are
// - The argument is wrapped in {} or [], in which case Parser's
// parseGroup() returns an "ordgroup" wrapping some symbol node.
// - The argument is a bare symbol node.
var symNode = checkSymbolNodeType(args[0]);
var colalign = symNode ? [args[0]] : assertNodeType(args[0], "ordgroup").body;
var cols = colalign.map(function (nde) {
var node = assertSymbolNodeType(nde);
var ca = node.text;
if ("lcr".indexOf(ca) !== -1) {
return {
type: "align",
align: ca
};
} else if (ca === "|") {
return {
type: "separator",
separator: "|"
};
} else if (ca === ":") {
return {
type: "separator",
separator: ":"
};
}
throw new ParseError("Unknown column alignment: " + ca, nde);
});
var res = {
cols,
hskipBeforeAndAfter: true,
// \@preamble in lttab.dtx
maxNumCols: cols.length
};
return parseArray(context.parser, res, dCellStyle(context.envName));
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
}); // The matrix environments of amsmath builds on the array environment
// of LaTeX, which is discussed above.
// The mathtools package adds starred versions of the same environments.
// These have an optional argument to choose left|center|right justification.
defineEnvironment({
type: "array",
names: ["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix", "matrix*", "pmatrix*", "bmatrix*", "Bmatrix*", "vmatrix*", "Vmatrix*"],
props: {
numArgs: 0
},
handler(context) {
var delimiters = {
"matrix": null,
"pmatrix": ["(", ")"],
"bmatrix": ["[", "]"],
"Bmatrix": ["\\{", "\\}"],
"vmatrix": ["|", "|"],
"Vmatrix": ["\\Vert", "\\Vert"]
}[context.envName.replace("*", "")]; // \hskip -\arraycolsep in amsmath
var colAlign = "c";
var payload = {
hskipBeforeAndAfter: false,
cols: [{
type: "align",
align: colAlign
}]
};
if (context.envName.charAt(context.envName.length - 1) === "*") {
// It's one of the mathtools starred functions.
// Parse the optional alignment argument.
var parser = context.parser;
parser.consumeSpaces();
if (parser.fetch().text === "[") {
parser.consume();
parser.consumeSpaces();
colAlign = parser.fetch().text;
if ("lcr".indexOf(colAlign) === -1) {
throw new ParseError("Expected l or c or r", parser.nextToken);
}
parser.consume();
parser.consumeSpaces();
parser.expect("]");
parser.consume();
payload.cols = [{
type: "align",
align: colAlign
}];
}
}
var res = parseArray(context.parser, payload, dCellStyle(context.envName)); // Populate cols with the correct number of column alignment specs.
var numCols = Math.max(0, ...res.body.map(row => row.length));
res.cols = new Array(numCols).fill({
type: "align",
align: colAlign
});
return delimiters ? {
type: "leftright",
mode: context.mode,
body: [res],
left: delimiters[0],
right: delimiters[1],
rightColor: undefined // \right uninfluenced by \color in array
} : res;
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
});
defineEnvironment({
type: "array",
names: ["smallmatrix"],
props: {
numArgs: 0
},
handler(context) {
var payload = {
arraystretch: 0.5
};
var res = parseArray(context.parser, payload, "script");
res.colSeparationType = "small";
return res;
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
});
defineEnvironment({
type: "array",
names: ["subarray"],
props: {
numArgs: 1
},
handler(context, args) {
// Parsing of {subarray} is similar to {array}
var symNode = checkSymbolNodeType(args[0]);
var colalign = symNode ? [args[0]] : assertNodeType(args[0], "ordgroup").body;
var cols = colalign.map(function (nde) {
var node = assertSymbolNodeType(nde);
var ca = node.text; // {subarray} only recognizes "l" & "c"
if ("lc".indexOf(ca) !== -1) {
return {
type: "align",
align: ca
};
}
throw new ParseError("Unknown column alignment: " + ca, nde);
});
if (cols.length > 1) {
throw new ParseError("{subarray} can contain only one column");
}
var res = {
cols,
hskipBeforeAndAfter: false,
arraystretch: 0.5
};
res = parseArray(context.parser, res, "script");
if (res.body.length > 0 && res.body[0].length > 1) {
throw new ParseError("{subarray} can contain only one column");
}
return res;
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
}); // A cases environment (in amsmath.sty) is almost equivalent to
// \def\arraystretch{1.2}%
// \left\{\begin{array}{@{}l@{\quad}l@{}} … \end{array}\right.
// {dcases} is a {cases} environment where cells are set in \displaystyle,
// as defined in mathtools.sty.
// {rcases} is another mathtools environment. It's brace is on the right side.
defineEnvironment({
type: "array",
names: ["cases", "dcases", "rcases", "drcases"],
props: {
numArgs: 0
},
handler(context) {
var payload = {
arraystretch: 1.2,
cols: [{
type: "align",
align: "l",
pregap: 0,
// TODO(kevinb) get the current style.
// For now we use the metrics for TEXT style which is what we were
// doing before. Before attempting to get the current style we
// should look at TeX's behavior especially for \over and matrices.
postgap: 1.0
/* 1em quad */
}, {
type: "align",
align: "l",
pregap: 0,
postgap: 0
}]
};
var res = parseArray(context.parser, payload, dCellStyle(context.envName));
return {
type: "leftright",
mode: context.mode,
body: [res],
left: context.envName.indexOf("r") > -1 ? "." : "\\{",
right: context.envName.indexOf("r") > -1 ? "\\}" : ".",
rightColor: undefined
};
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
}); // In the align environment, one uses ampersands, &, to specify number of
// columns in each row, and to locate spacing between each column.
// align gets automatic numbering. align* and aligned do not.
// The alignedat environment can be used in math mode.
// Note that we assume \nomallineskiplimit to be zero,
// so that \strut@ is the same as \strut.
defineEnvironment({
type: "array",
names: ["align", "align*", "aligned", "split"],
props: {
numArgs: 0
},
handler: alignedHandler,
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
}); // A gathered environment is like an array environment with one centered
// column, but where rows are considered lines so get \jot line spacing
// and contents are set in \displaystyle.
defineEnvironment({
type: "array",
names: ["gathered", "gather", "gather*"],
props: {
numArgs: 0
},
handler(context) {
if (utils.contains(["gather", "gather*"], context.envName)) {
validateAmsEnvironmentContext(context);
}
var res = {
cols: [{
type: "align",
align: "c"
}],
addJot: true,
colSeparationType: "gather",
autoTag: getAutoTag(context.envName),
emptySingleRow: true,
leqno: context.parser.settings.leqno
};
return parseArray(context.parser, res, "display");
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
}); // alignat environment is like an align environment, but one must explicitly
// specify maximum number of columns in each row, and can adjust spacing between
// each columns.
defineEnvironment({
type: "array",
names: ["alignat", "alignat*", "alignedat"],
props: {
numArgs: 1
},
handler: alignedHandler,
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
});
defineEnvironment({
type: "array",
names: ["equation", "equation*"],
props: {
numArgs: 0
},
handler(context) {
validateAmsEnvironmentContext(context);
var res = {
autoTag: getAutoTag(context.envName),
emptySingleRow: true,
singleRow: true,
maxNumCols: 1,
leqno: context.parser.settings.leqno
};
return parseArray(context.parser, res, "display");
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
});
defineEnvironment({
type: "array",
names: ["CD"],
props: {
numArgs: 0
},
handler(context) {
validateAmsEnvironmentContext(context);
return parseCD(context.parser);
},
htmlBuilder: htmlBuilder$6,
mathmlBuilder: mathmlBuilder$5
});
defineMacro("\\nonumber", "\\gdef\\@eqnsw{0}");
defineMacro("\\notag", "\\nonumber"); // Catch \hline outside array environment
defineFunction({
type: "text",
// Doesn't matter what this is.
names: ["\\hline", "\\hdashline"],
props: {
numArgs: 0,
allowedInText: true,
allowedInMath: true
},
handler(context, args) {
throw new ParseError(context.funcName + " valid only within array environment");
}
});
var environments = _environments;
// defineEnvironment definitions.
defineFunction({
type: "environment",
names: ["\\begin", "\\end"],
props: {
numArgs: 1,
argTypes: ["text"]
},
handler(_ref, args) {
var {
parser,
funcName
} = _ref;
var nameGroup = args[0];
if (nameGroup.type !== "ordgroup") {
throw new ParseError("Invalid environment name", nameGroup);
}
var envName = "";
for (var 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.
var env = environments[envName];
var {
args: _args,
optArgs
} = parser.parseArguments("\\begin{" + envName + "}", env);
var context = {
mode: parser.mode,
envName,
parser
};
var result = env.handler(context, _args, optArgs);
parser.expect("\\end", false);
var endNameToken = parser.nextToken;
var 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
};
}
});
// TODO(kevinb): implement \\sl and \\sc
var htmlBuilder$5 = (group, options) => {
var font = group.font;
var newOptions = options.withFont(font);
return buildGroup$1(group.body, newOptions);
};
var mathmlBuilder$4 = (group, options) => {
var font = group.font;
var newOptions = options.withFont(font);
return buildGroup(group.body, newOptions);
};
var fontAliases = {
"\\Bbb": "\\mathbb",
"\\bold": "\\mathbf",
"\\frak": "\\mathfrak",
"\\bm": "\\boldsymbol"
};
defineFunction({
type: "font",
names: [// styles, except \boldsymbol defined below
"\\mathrm", "\\mathit", "\\mathbf", "\\mathnormal", // families
"\\mathbb", "\\mathcal", "\\mathfrak", "\\mathscr", "\\mathsf", "\\mathtt", // aliases, except \bm defined below
"\\Bbb", "\\bold", "\\frak"],
props: {
numArgs: 1,
allowedInArgument: true
},
handler: (_ref, args) => {
var {
parser,
funcName
} = _ref;
var body = normalizeArgument(args[0]);
var func = funcName;
if (func in fontAliases) {
func = fontAliases[func];
}
return {
type: "font",
mode: parser.mode,
font: func.slice(1),
body
};
},
htmlBuilder: htmlBuilder$5,
mathmlBuilder: mathmlBuilder$4
});
defineFunction({
type: "mclass",
names: ["\\boldsymbol", "\\bm"],
props: {
numArgs: 1
},
handler: (_ref2, args) => {
var {
parser
} = _ref2;
var body = args[0];
var 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: (_ref3, args) => {
var {
parser,
funcName,
breakOnTokenText
} = _ref3;
var {
mode
} = parser;
var body = parser.parseExpression(true, breakOnTokenText);
var style = "math" + funcName.slice(1);
return {
type: "font",
mode: mode,
font: style,
body: {
type: "ordgroup",
mode: parser.mode,
body
}
};
},
htmlBuilder: htmlBuilder$5,
mathmlBuilder: mathmlBuilder$4
});
var adjustStyle = (size, originalStyle) => {
// Figure out what style this fraction should be in based on the
// function used
var 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$1.SCRIPT.id ? style.text() : Style$1.DISPLAY;
} else if (size === "text" && style.size === Style$1.DISPLAY.size) {
// We're in a \tfrac but incoming style is displaystyle, so:
style = Style$1.TEXT;
} else if (size === "script") {
style = Style$1.SCRIPT;
} else if (size === "scriptscript") {
style = Style$1.SCRIPTSCRIPT;
}
return style;
};
var htmlBuilder$4 = (group, options) => {
// Fractions are handled in the TeXbook on pages 444-445, rules 15(a-e).
var style = adjustStyle(group.size, options.style);
var nstyle = style.fracNum();
var dstyle = style.fracDen();
var newOptions;
newOptions = options.havingStyle(nstyle);
var numerm = buildGroup$1(group.numer, newOptions, options);
if (group.continued) {
// \cfrac inserts a \strut into the numerator.
// Get \strut dimensions from TeXbook page 353.
var hStrut = 8.5 / options.fontMetrics().ptPerEm;
var 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);
var denomm = buildGroup$1(group.denom, newOptions, options);
var rule;
var ruleWidth;
var 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
var numShift;
var clearance;
var denomShift;
if (style.size === Style$1.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;
}
var frac;
if (!rule) {
// Rule 15c
var 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
var 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));
}
var 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
var delimSize;
if (style.size === Style$1.DISPLAY.size) {
delimSize = options.fontMetrics().delim1;
} else if (style.size === Style$1.SCRIPTSCRIPT.size) {
delimSize = options.havingStyle(Style$1.SCRIPT).fontMetrics().delim2;
} else {
delimSize = options.fontMetrics().delim2;
}
var leftDelim;
var rightDelim;
if (group.leftDelim == null) {
leftDelim = 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 = 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);
};
var mathmlBuilder$3 = (group, options) => {
var node = new mathMLTree.MathNode("mfrac", [buildGroup(group.numer, options), buildGroup(group.denom, options)]);
if (!group.hasBarLine) {
node.setAttribute("linethickness", "0px");
} else if (group.barSize) {
var ruleWidth = calculateSize(group.barSize, options);
node.setAttribute("linethickness", makeEm(ruleWidth));
}
var style = adjustStyle(group.size, options.style);
if (style.size !== options.style.size) {
node = new mathMLTree.MathNode("mstyle", [node]);
var isDisplay = style.size === Style$1.DISPLAY.size ? "true" : "false";
node.setAttribute("displaystyle", isDisplay);
node.setAttribute("scriptlevel", "0");
}
if (group.leftDelim != null || group.rightDelim != null) {
var withDelims = [];
if (group.leftDelim != null) {
var 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) {
var rightOp = new mathMLTree.MathNode("mo", [new mathMLTree.TextNode(group.rightDelim.replace("\\", ""))]);
rightOp.setAttribute("fence", "true");
withDelims.push(rightOp);
}
return makeRow(withDelims);
}
return node;
};
defineFunction({
type: "genfrac",
names: ["\\dfrac", "\\frac", "\\tfrac", "\\dbinom", "\\binom", "\\tbinom", "\\\\atopfrac", // can’t be entered directly
"\\\\bracefrac", "\\\\brackfrac" // ditto
],
props: {
numArgs: 2,
allowedInArgument: true
},
handler: (_ref, args) => {
var {
parser,
funcName
} = _ref;
var numer = args[0];
var denom = args[1];
var hasBarLine;
var leftDelim = null;
var rightDelim = null;
var 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: htmlBuilder$4,
mathmlBuilder: mathmlBuilder$3
});
defineFunction({
type: "genfrac",
names: ["\\cfrac"],
props: {
numArgs: 2
},
handler: (_ref2, args) => {
var {
parser,
funcName
} = _ref2;
var numer = args[0];
var 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(_ref3) {
var {
parser,
funcName,
token
} = _ref3;
var 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
};
}
});
var stylArray = ["display", "text", "script", "scriptscript"];
var delimFromValue = function delimFromValue(delimString) {
var 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(_ref4, args) {
var {
parser
} = _ref4;
var numer = args[4];
var denom = args[5]; // Look into the parse nodes to get the desired delimiters.
var leftNode = normalizeArgument(args[0]);
var leftDelim = leftNode.type === "atom" && leftNode.family === "open" ? delimFromValue(leftNode.text) : null;
var rightNode = normalizeArgument(args[1]);
var rightDelim = rightNode.type === "atom" && rightNode.family === "close" ? delimFromValue(rightNode.text) : null;
var barNode = assertNodeType(args[2], "size");
var hasBarLine;
var 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.
var size = "auto";
var styl = args[3];
if (styl.type === "ordgroup") {
if (styl.body.length > 0) {
var 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: htmlBuilder$4,
mathmlBuilder: mathmlBuilder$3
}); // \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(_ref5, args) {
var {
parser,
funcName,
token
} = _ref5;
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: (_ref6, args) => {
var {
parser,
funcName
} = _ref6;
var numer = args[0];
var barSize = assert(assertNodeType(args[1], "infix").size);
var denom = args[2];
var hasBarLine = barSize.number > 0;
return {
type: "genfrac",
mode: parser.mode,
numer,
denom,
continued: false,
hasBarLine,
barSize,
leftDelim: null,
rightDelim: null,
size: "auto"
};
},
htmlBuilder: htmlBuilder$4,
mathmlBuilder: mathmlBuilder$3
});
// NOTE: Unlike most `htmlBuilder`s, this one handles not only "horizBrace", but
// also "supsub" since an over/underbrace can affect super/subscripting.
var htmlBuilder$3 = (grp, options) => {
var style = options.style; // Pull out the `ParseNode<"horizBrace">` if `grp` is a "supsub" node.
var supSubGroup;
var group;
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 ? buildGroup$1(grp.sup, options.havingStyle(style.sup()), options) : buildGroup$1(grp.sub, options.havingStyle(style.sub()), options);
group = assertNodeType(grp.base, "horizBrace");
} else {
group = assertNodeType(grp, "horizBrace");
} // Build the base group
var body = buildGroup$1(group.base, options.havingBaseStyle(Style$1.DISPLAY)); // Create the stretchy element
var braceBody = stretchy.svgSpan(group, options); // Generate the vlist, with the appropriate kerns ┏━━━━━━━━┓
// This first vlist contains the content and the brace: equation
var 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
var 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);
};
var mathmlBuilder$2 = (group, options) => {
var accentNode = stretchy.mathMLnode(group.label);
return new mathMLTree.MathNode(group.isOver ? "mover" : "munder", [buildGroup(group.base, options), accentNode]);
}; // Horizontal stretchy braces
defineFunction({
type: "horizBrace",
names: ["\\overbrace", "\\underbrace"],
props: {
numArgs: 1
},
handler(_ref, args) {
var {
parser,
funcName
} = _ref;
return {
type: "horizBrace",
mode: parser.mode,
label: funcName,
isOver: /^\\over/.test(funcName),
base: args[0]
};
},
htmlBuilder: htmlBuilder$3,
mathmlBuilder: mathmlBuilder$2
});
defineFunction({
type: "href",
names: ["\\href"],
props: {
numArgs: 2,
argTypes: ["url", "original"],
allowedInText: true
},
handler: (_ref, args) => {
var {
parser
} = _ref;
var body = args[1];
var 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) => {
var elements = buildExpression$1(group.body, options, false);
return buildCommon.makeAnchor(group.href, [], elements, options);
},
mathmlBuilder: (group, options) => {
var math = 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: (_ref2, args) => {
var {
parser
} = _ref2;
var href = assertNodeType(args[0], "url").url;
if (!parser.settings.isTrusted({
command: "\\url",
url: href
})) {
return parser.formatUnsupportedCmd("\\url");
}
var chars = [];
for (var i = 0; i < href.length; i++) {
var c = href[i];
if (c === "~") {
c = "\\textasciitilde";
}
chars.push({
type: "textord",
mode: "text",
text: c
});
}
var body = {
type: "text",
mode: parser.mode,
font: "\\texttt",
body: chars
};
return {
type: "href",
mode: parser.mode,
href,
body: ordargument(body)
};
}
});
// 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(_ref, args) {
var {
parser
} = _ref;
return {
type: "hbox",
mode: parser.mode,
body: ordargument(args[0])
};
},
htmlBuilder(group, options) {
var elements = buildExpression$1(group.body, options, false);
return buildCommon.makeFragment(elements);
},
mathmlBuilder(group, options) {
return new mathMLTree.MathNode("mrow", buildExpression(group.body, options));
}
});
defineFunction({
type: "html",
names: ["\\htmlClass", "\\htmlId", "\\htmlStyle", "\\htmlData"],
props: {
numArgs: 2,
argTypes: ["raw", "original"],
allowedInText: true
},
handler: (_ref, args) => {
var {
parser,
funcName,
token
} = _ref;
var value = assertNodeType(args[0], "raw").string;
var body = args[1];
if (parser.settings.strict) {
parser.settings.reportNonstrict("htmlExtension", "HTML extension is disabled on strict mode");
}
var trustContext;
var 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":
{
var data = value.split(",");
for (var i = 0; i < data.length; i++) {
var 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) => {
var elements = buildExpression$1(group.body, options, false);
var classes = ["enclosing"];
if (group.attributes.class) {
classes.push(...group.attributes.class.trim().split(/\s+/));
}
var span = buildCommon.makeSpan(classes, elements, options);
for (var attr in group.attributes) {
if (attr !== "class" && group.attributes.hasOwnProperty(attr)) {
span.setAttribute(attr, group.attributes[attr]);
}
}
return span;
},
mathmlBuilder: (group, options) => {
return buildExpressionRow(group.body, options);
}
});
defineFunction({
type: "htmlmathml",
names: ["\\html@mathml"],
props: {
numArgs: 2,
allowedInText: true
},
handler: (_ref, args) => {
var {
parser
} = _ref;
return {
type: "htmlmathml",
mode: parser.mode,
html: ordargument(args[0]),
mathml: ordargument(args[1])
};
},
htmlBuilder: (group, options) => {
var elements = buildExpression$1(group.html, options, false);
return buildCommon.makeFragment(elements);
},
mathmlBuilder: (group, options) => {
return buildExpressionRow(group.mathml, options);
}
});
var sizeData = function sizeData(str) {
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 {
var match = /([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(str);
if (!match) {
throw new ParseError("Invalid size: '" + str + "' in \\includegraphics");
}
var 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: (_ref, args, optArgs) => {
var {
parser
} = _ref;
var width = {
number: 0,
unit: "em"
};
var height = {
number: 0.9,
unit: "em"
}; // sorta character sized.
var totalheight = {
number: 0,
unit: "em"
};
var alt = "";
if (optArgs[0]) {
var attributeStr = assertNodeType(optArgs[0], "raw").string; // Parser.js does not parse key/value pairs. We get a string.
var attributes = attributeStr.split(",");
for (var i = 0; i < attributes.length; i++) {
var keyVal = attributes[i].split("=");
if (keyVal.length === 2) {
var 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.");
}
}
}
}
var 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) => {
var height = calculateSize(group.height, options);
var depth = 0;
if (group.totalheight.number > 0) {
depth = calculateSize(group.totalheight, options) - height;
}
var width = 0;
if (group.width.number > 0) {
width = calculateSize(group.width, options);
}
var style = {
height: makeEm(height + depth)
};
if (width > 0) {
style.width = makeEm(width);
}
if (depth > 0) {
style.verticalAlign = makeEm(-depth);
}
var node = new Img(group.src, group.alt, style);
node.height = height;
node.depth = depth;
return node;
},
mathmlBuilder: (group, options) => {
var node = new mathMLTree.MathNode("mglyph", []);
node.setAttribute("alt", group.alt);
var height = calculateSize(group.height, options);
var 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) {
var width = calculateSize(group.width, options);
node.setAttribute("width", makeEm(width));
}
node.setAttribute("src", group.src);
return node;
}
});
// Horizontal spacing commands
defineFunction({
type: "kern",
names: ["\\kern", "\\mkern", "\\hskip", "\\mskip"],
props: {
numArgs: 1,
argTypes: ["size"],
primitive: true,
allowedInText: true
},
handler(_ref, args) {
var {
parser,
funcName
} = _ref;
var size = assertNodeType(args[0], "size");
if (parser.settings.strict) {
var mathFunction = funcName[1] === 'm'; // \mkern, \mskip
var 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) {
var dimension = calculateSize(group.dimension, options);
return new mathMLTree.SpaceNode(dimension);
}
});
// Horizontal overlap functions
defineFunction({
type: "lap",
names: ["\\mathllap", "\\mathrlap", "\\mathclap"],
props: {
numArgs: 1,
allowedInText: true
},
handler: (_ref, args) => {
var {
parser,
funcName
} = _ref;
var body = args[0];
return {
type: "lap",
mode: parser.mode,
alignment: funcName.slice(5),
body
};
},
htmlBuilder: (group, options) => {
// mathllap, mathrlap, mathclap
var inner;
if (group.alignment === "clap") {
// ref: https://www.math.lsu.edu/~aperlis/publications/mathclap/
inner = buildCommon.makeSpan([], [buildGroup$1(group.body, options)]); // wrap, since CSS will center a .clap > .inner > span
inner = buildCommon.makeSpan(["inner"], [inner], options);
} else {
inner = buildCommon.makeSpan(["inner"], [buildGroup$1(group.body, options)]);
}
var fix = buildCommon.makeSpan(["fix"], []);
var 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
var 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
var node = new mathMLTree.MathNode("mpadded", [buildGroup(group.body, options)]);
if (group.alignment !== "rlap") {
var offset = group.alignment === "llap" ? "-1" : "-0.5";
node.setAttribute("lspace", offset + "width");
}
node.setAttribute("width", "0px");
return node;
}
});
defineFunction({
type: "styling",
names: ["\\(", "$"],
props: {
numArgs: 0,
allowedInText: true,
allowedInMath: false
},
handler(_ref, args) {
var {
funcName,
parser
} = _ref;
var outerMode = parser.mode;
parser.switchMode("math");
var close = funcName === "\\(" ? "\\)" : "$";
var 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);
}
});
var chooseMathStyle = (group, options) => {
switch (options.style.size) {
case Style$1.DISPLAY.size:
return group.display;
case Style$1.TEXT.size:
return group.text;
case Style$1.SCRIPT.size:
return group.script;
case Style$1.SCRIPTSCRIPT.size:
return group.scriptscript;
default:
return group.text;
}
};
defineFunction({
type: "mathchoice",
names: ["\\mathchoice"],
props: {
numArgs: 4,
primitive: true
},
handler: (_ref, args) => {
var {
parser
} = _ref;
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) => {
var body = chooseMathStyle(group, options);
var elements = buildExpression$1(body, options, false);
return buildCommon.makeFragment(elements);
},
mathmlBuilder: (group, options) => {
var body = chooseMathStyle(group, options);
return buildExpressionRow(body, options);
}
});
var assembleSupSub = (base, supGroup, subGroup, options, style, slant, baseShift) => {
base = buildCommon.makeSpan([], [base]);
var subIsSingleCharacter = subGroup && utils.isCharacterBox(subGroup);
var sub;
var sup; // We manually have to handle the superscripts and subscripts. This,
// aside from the kern calculations, is copied from supsub.
if (supGroup) {
var elem = buildGroup$1(supGroup, options.havingStyle(style.sup()), options);
sup = {
elem,
kern: Math.max(options.fontMetrics().bigOpSpacing1, options.fontMetrics().bigOpSpacing3 - elem.depth)
};
}
if (subGroup) {
var _elem = buildGroup$1(subGroup, options.havingStyle(style.sub()), options);
sub = {
elem: _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.
var finalGroup;
if (sup && sub) {
var 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) {
var 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) {
var _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;
}
var 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.
var spacer = buildCommon.makeSpan(["mspace"], [], options);
spacer.style.marginRight = makeEm(slant);
parts.unshift(spacer);
}
return buildCommon.makeSpan(["mop", "op-limits"], parts, options);
};
// Limits, symbols
// Most operators have a large successor symbol, but these don't.
var 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.
var htmlBuilder$2 = (grp, options) => {
// Operators are handled in the TeXbook pg. 443-444, rule 13(a).
var supGroup;
var subGroup;
var hasLimits = false;
var group;
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");
}
var style = options.style;
var large = false;
if (style.size === Style$1.DISPLAY.size && group.symbol && !utils.contains(noSuccessor, group.name)) {
// Most symbol operators get larger in displaystyle (rule 13)
large = true;
}
var base;
if (group.symbol) {
// If this is a symbol, create the symbol.
var fontName = large ? "Size2-Regular" : "Size1-Regular";
var 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.
var italic = base.italic;
var 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.
var inner = buildExpression$1(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.
var output = [];
for (var 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.
var baseShift = 0;
var 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;
}
};
var mathmlBuilder$1 = (group, options) => {
var node;
if (group.symbol) {
// This is a symbol. Just add the symbol.
node = new MathNode("mo", [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 MathNode("mo", buildExpression(group.body, options));
} else {
// This is a text operator. Add all of the characters from the
// operator's name.
node = new MathNode("mi", [new TextNode(group.name.slice(1))]); // Append an <mo>⁡</mo>.
// ref: https://www.w3.org/TR/REC-MathML/chap3_2.html#sec3.2.4
var operator = new MathNode("mo", [makeText("\u2061", "text")]);
if (group.parentIsSupSub) {
node = new MathNode("mrow", [node, operator]);
} else {
node = newDocumentFragment([node, operator]);
}
}
return node;
};
var singleCharBigOps = {
"\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: (_ref, args) => {
var {
parser,
funcName
} = _ref;
var fName = funcName;
if (fName.length === 1) {
fName = singleCharBigOps[fName];
}
return {
type: "op",
mode: parser.mode,
limits: true,
parentIsSupSub: false,
symbol: true,
name: fName
};
},
htmlBuilder: htmlBuilder$2,
mathmlBuilder: mathmlBuilder$1
}); // 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: (_ref2, args) => {
var {
parser
} = _ref2;
var body = args[0];
return {
type: "op",
mode: parser.mode,
limits: false,
parentIsSupSub: false,
symbol: false,
body: ordargument(body)
};
},
htmlBuilder: htmlBuilder$2,
mathmlBuilder: mathmlBuilder$1
}); // 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.
var singleCharIntegrals = {
"\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(_ref3) {
var {
parser,
funcName
} = _ref3;
return {
type: "op",
mode: parser.mode,
limits: false,
parentIsSupSub: false,
symbol: false,
name: funcName
};
},
htmlBuilder: htmlBuilder$2,
mathmlBuilder: mathmlBuilder$1
}); // Limits, not symbols
defineFunction({
type: "op",
names: ["\\det", "\\gcd", "\\inf", "\\lim", "\\max", "\\min", "\\Pr", "\\sup"],
props: {
numArgs: 0
},
handler(_ref4) {
var {
parser,
funcName
} = _ref4;
return {
type: "op",
mode: parser.mode,
limits: true,
parentIsSupSub: false,
symbol: false,
name: funcName
};
},
htmlBuilder: htmlBuilder$2,
mathmlBuilder: mathmlBuilder$1
}); // No limits, symbols
defineFunction({
type: "op",
names: ["\\int", "\\iint", "\\iiint", "\\oint", "\\oiint", "\\oiiint", "\u222b", "\u222c", "\u222d", "\u222e", "\u222f", "\u2230"],
props: {
numArgs: 0
},
handler(_ref5) {
var {
parser,
funcName
} = _ref5;
var fName = funcName;
if (fName.length === 1) {
fName = singleCharIntegrals[fName];
}
return {
type: "op",
mode: parser.mode,
limits: false,
parentIsSupSub: false,
symbol: true,
name: fName
};
},
htmlBuilder: htmlBuilder$2,
mathmlBuilder: mathmlBuilder$1
});
// NOTE: Unlike most `htmlBuilder`s, this one handles not only
// "operatorname", but also "supsub" since \operatorname* can
// affect super/subscripting.
var htmlBuilder$1 = (grp, options) => {
// Operators are handled in the TeXbook pg. 443-444, rule 13(a).
var supGroup;
var subGroup;
var hasLimits = false;
var group;
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");
}
var base;
if (group.body.length > 0) {
var body = group.body.map(child => {
// $FlowFixMe: Check if the node has a string `text` property.
var childText = child.text;
if (typeof childText === "string") {
return {
type: "textord",
mode: child.mode,
text: childText
};
} else {
return child;
}
}); // Consolidate function names into symbol characters.
var expression = buildExpression$1(body, options.withFont("mathrm"), true);
for (var i = 0; i < expression.length; i++) {
var 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;
}
};
var mathmlBuilder = (group, options) => {
// The steps taken here are similar to the html version.
var expression = buildExpression(group.body, options.withFont("mathrm")); // Is expression a string or has it something like a fraction?
var isAllString = true; // default
for (var i = 0; i < expression.length; i++) {
var node = expression[i];
if (node instanceof mathMLTree.SpaceNode) ; 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":
{
var 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.
var word = expression.map(node => node.toText()).join("");
expression = [new mathMLTree.TextNode(word)];
}
var identifier = new mathMLTree.MathNode("mi", expression);
identifier.setAttribute("mathvariant", "normal"); // \u2061 is the same as ⁡
// ref: https://www.w3schools.com/charsets/ref_html_entities_a.asp
var operator = new mathMLTree.MathNode("mo", [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: (_ref, args) => {
var {
parser,
funcName
} = _ref;
var body = args[0];
return {
type: "operatorname",
mode: parser.mode,
body: ordargument(body),
alwaysHandleSupSub: funcName === "\\operatornamewithlimits",
limits: false,
parentIsSupSub: false
};
},
htmlBuilder: htmlBuilder$1,
mathmlBuilder
});
defineMacro("\\operatorname", "\\@ifstar\\operatornamewithlimits\\operatorname@");
defineFunctionBuilders({
type: "ordgroup",
htmlBuilder(group, options) {
if (group.semisimple) {
return buildCommon.makeFragment(buildExpression$1(group.body, options, false));
}
return buildCommon.makeSpan(["mord"], buildExpression$1(group.body, options, true), options);
},
mathmlBuilder(group, options) {
return buildExpressionRow(group.body, options, true);
}
});
defineFunction({
type: "overline",
names: ["\\overline"],
props: {
numArgs: 1
},
handler(_ref, args) {
var {
parser
} = _ref;
var 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.
var innerGroup = buildGroup$1(group.body, options.havingCrampedStyle()); // Create the line above the body
var line = buildCommon.makeLineSpan("overline-line", options); // Generate the vlist, with the appropriate kerns
var defaultRuleThickness = options.fontMetrics().defaultRuleThickness;
var 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) {
var operator = new mathMLTree.MathNode("mo", [new mathMLTree.TextNode("\u203e")]);
operator.setAttribute("stretchy", "true");
var node = new mathMLTree.MathNode("mover", [buildGroup(group.body, options), operator]);
node.setAttribute("accent", "true");
return node;
}
});
defineFunction({
type: "phantom",
names: ["\\phantom"],
props: {
numArgs: 1,
allowedInText: true
},
handler: (_ref, args) => {
var {
parser
} = _ref;
var body = args[0];
return {
type: "phantom",
mode: parser.mode,
body: ordargument(body)
};
},
htmlBuilder: (group, options) => {
var elements = buildExpression$1(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) => {
var inner = buildExpression(group.body, options);
return new mathMLTree.MathNode("mphantom", inner);
}
});
defineFunction({
type: "hphantom",
names: ["\\hphantom"],
props: {
numArgs: 1,
allowedInText: true
},
handler: (_ref2, args) => {
var {
parser
} = _ref2;
var body = args[0];
return {
type: "hphantom",
mode: parser.mode,
body
};
},
htmlBuilder: (group, options) => {
var node = buildCommon.makeSpan([], [buildGroup$1(group.body, options.withPhantom())]);
node.height = 0;
node.depth = 0;
if (node.children) {
for (var 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) => {
var inner = buildExpression(ordargument(group.body), options);
var phantom = new mathMLTree.MathNode("mphantom", inner);
var 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: (_ref3, args) => {
var {
parser
} = _ref3;
var body = args[0];
return {
type: "vphantom",
mode: parser.mode,
body
};
},
htmlBuilder: (group, options) => {
var inner = buildCommon.makeSpan(["inner"], [buildGroup$1(group.body, options.withPhantom())]);
var fix = buildCommon.makeSpan(["fix"], []);
return buildCommon.makeSpan(["mord", "rlap"], [inner, fix], options);
},
mathmlBuilder: (group, options) => {
var inner = buildExpression(ordargument(group.body), options);
var phantom = new mathMLTree.MathNode("mphantom", inner);
var node = new mathMLTree.MathNode("mpadded", [phantom]);
node.setAttribute("width", "0px");
return node;
}
});
defineFunction({
type: "raisebox",
names: ["\\raisebox"],
props: {
numArgs: 2,
argTypes: ["size", "hbox"],
allowedInText: true
},
handler(_ref, args) {
var {
parser
} = _ref;
var amount = assertNodeType(args[0], "size").value;
var body = args[1];
return {
type: "raisebox",
mode: parser.mode,
dy: amount,
body
};
},
htmlBuilder(group, options) {
var body = buildGroup$1(group.body, options);
var dy = calculateSize(group.dy, options);
return buildCommon.makeVList({
positionType: "shift",
positionData: -dy,
children: [{
type: "elem",
elem: body
}]
}, options);
},
mathmlBuilder(group, options) {
var node = new mathMLTree.MathNode("mpadded", [buildGroup(group.body, options)]);
var dy = group.dy.number + group.dy.unit;
node.setAttribute("voffset", dy);
return node;
}
});
defineFunction({
type: "internal",
names: ["\\relax"],
props: {
numArgs: 0,
allowedInText: true
},
handler(_ref) {
var {
parser
} = _ref;
return {
type: "internal",
mode: parser.mode
};
}
});
defineFunction({
type: "rule",
names: ["\\rule"],
props: {
numArgs: 2,
numOptionalArgs: 1,
argTypes: ["size", "size", "size"]
},
handler(_ref, args, optArgs) {
var {
parser
} = _ref;
var shift = optArgs[0];
var width = assertNodeType(args[0], "size");
var 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
var rule = buildCommon.makeSpan(["mord", "rule"], [], options); // Calculate the shift, width, and height of the rule, and account for units
var width = calculateSize(group.width, options);
var height = calculateSize(group.height, options);
var 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) {
var width = calculateSize(group.width, options);
var height = calculateSize(group.height, options);
var shift = group.shift ? calculateSize(group.shift, options) : 0;
var color = options.color && options.getColor() || "black";
var rule = new mathMLTree.MathNode("mspace");
rule.setAttribute("mathbackground", color);
rule.setAttribute("width", makeEm(width));
rule.setAttribute("height", makeEm(height));
var 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;
}
});
function sizingGroup(value, options, baseOptions) {
var inner = buildExpression$1(value, options, false);
var multiplier = options.sizeMultiplier / baseOptions.sizeMultiplier; // Add size-resetting classes to the inner list and set maxFontSize
// manually. Handle nested size changes.
for (var i = 0; i < inner.length; i++) {
var 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);
}
var sizeFuncs = ["\\tiny", "\\sixptsize", "\\scriptsize", "\\footnotesize", "\\small", "\\normalsize", "\\large", "\\Large", "\\LARGE", "\\huge", "\\Huge"];
var htmlBuilder = (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.
var newOptions = options.havingSize(group.size);
return sizingGroup(group.body, newOptions, options);
};
defineFunction({
type: "sizing",
names: sizeFuncs,
props: {
numArgs: 0,
allowedInText: true
},
handler: (_ref, args) => {
var {
breakOnTokenText,
funcName,
parser
} = _ref;
var 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) => {
var newOptions = options.havingSize(group.size);
var inner = buildExpression(group.body, newOptions);
var 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;
}
});
// smash, with optional [tb], as in AMS
defineFunction({
type: "smash",
names: ["\\smash"],
props: {
numArgs: 1,
numOptionalArgs: 1,
allowedInText: true
},
handler: (_ref, args, optArgs) => {
var {
parser
} = _ref;
var smashHeight = false;
var smashDepth = false;
var 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}%
var letter = "";
for (var i = 0; i < tbArg.body.length; ++i) {
var 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;
}
var body = args[0];
return {
type: "smash",
mode: parser.mode,
body,
smashHeight,
smashDepth
};
},
htmlBuilder: (group, options) => {
var node = buildCommon.makeSpan([], [buildGroup$1(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 (var i = 0; i < node.children.length; i++) {
node.children[i].height = 0;
}
}
}
if (group.smashDepth) {
node.depth = 0;
if (node.children) {
for (var _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.
var 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) => {
var node = new mathMLTree.MathNode("mpadded", [buildGroup(group.body, options)]);
if (group.smashHeight) {
node.setAttribute("height", "0px");
}
if (group.smashDepth) {
node.setAttribute("depth", "0px");
}
return node;
}
});
defineFunction({
type: "sqrt",
names: ["\\sqrt"],
props: {
numArgs: 1,
numOptionalArgs: 1
},
handler(_ref, args, optArgs) {
var {
parser
} = _ref;
var index = optArgs[0];
var 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
var inner = buildGroup$1(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
var metrics = options.fontMetrics();
var theta = metrics.defaultRuleThickness;
var phi = theta;
if (options.style.id < Style$1.TEXT.id) {
phi = options.fontMetrics().xHeight;
} // Calculate the clearance between the body and line
var lineClearance = theta + phi / 4;
var minDelimiterHeight = inner.height + inner.depth + lineClearance + theta; // Create a sqrt SVG of the required minimum size
var {
span: img,
ruleWidth,
advanceWidth
} = delimiter.sqrtImage(minDelimiterHeight, options);
var 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
var imgShift = img.height - inner.height - lineClearance - ruleWidth;
inner.style.paddingLeft = makeEm(advanceWidth); // Overlay the image and the argument.
var 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
var newOptions = options.havingStyle(Style$1.SCRIPTSCRIPT);
var rootm = buildGroup$1(group.index, newOptions, options); // The amount the index is shifted by. This is taken from the TeX
// source, in the definition of `\r@@t`.
var toShift = 0.6 * (body.height - body.depth); // Build a VList with the superscript shifted up correctly
var 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
var rootVListWrap = buildCommon.makeSpan(["root"], [rootVList]);
return buildCommon.makeSpan(["mord", "sqrt"], [rootVListWrap, body], options);
}
},
mathmlBuilder(group, options) {
var {
body,
index
} = group;
return index ? new mathMLTree.MathNode("mroot", [buildGroup(body, options), buildGroup(index, options)]) : new mathMLTree.MathNode("msqrt", [buildGroup(body, options)]);
}
});
var styleMap = {
"display": Style$1.DISPLAY,
"text": Style$1.TEXT,
"script": Style$1.SCRIPT,
"scriptscript": Style$1.SCRIPTSCRIPT
};
defineFunction({
type: "styling",
names: ["\\displaystyle", "\\textstyle", "\\scriptstyle", "\\scriptscriptstyle"],
props: {
numArgs: 0,
allowedInText: true,
primitive: true
},
handler(_ref, args) {
var {
breakOnTokenText,
funcName,
parser
} = _ref;
// parse out the implicit body
var 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.
var style = 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.
var newStyle = styleMap[group.style];
var newOptions = options.havingStyle(newStyle).withFont('');
return sizingGroup(group.body, newOptions, options);
},
mathmlBuilder(group, options) {
// Figure out what style we're changing to.
var newStyle = styleMap[group.style];
var newOptions = options.havingStyle(newStyle);
var inner = buildExpression(group.body, newOptions);
var node = new mathMLTree.MathNode("mstyle", inner);
var styleAttributes = {
"display": ["0", "true"],
"text": ["0", "false"],
"script": ["1", "false"],
"scriptscript": ["2", "false"]
};
var attr = styleAttributes[group.style];
node.setAttribute("scriptlevel", attr[0]);
node.setAttribute("displaystyle", attr[1]);
return node;
}
});
/**
* 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.
*/
var htmlBuilderDelegate = function htmlBuilderDelegate(group, options) {
var 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`)
var delegate = base.limits && (options.style.size === Style$1.DISPLAY.size || base.alwaysHandleSupSub);
return delegate ? htmlBuilder$2 : null;
} else if (base.type === "operatorname") {
var _delegate = base.alwaysHandleSupSub && (options.style.size === Style$1.DISPLAY.size || base.limits);
return _delegate ? htmlBuilder$1 : null;
} else if (base.type === "accent") {
return utils.isCharacterBox(base.base) ? htmlBuilder$a : null;
} else if (base.type === "horizBrace") {
var isSup = !group.sub;
return isSup === base.isOver ? htmlBuilder$3 : 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.
var builderDelegate = htmlBuilderDelegate(group, options);
if (builderDelegate) {
return builderDelegate(group, options);
}
var {
base: valueBase,
sup: valueSup,
sub: valueSub
} = group;
var base = buildGroup$1(valueBase, options);
var supm;
var subm;
var metrics = options.fontMetrics(); // Rule 18a
var supShift = 0;
var subShift = 0;
var isCharacterBox = valueBase && utils.isCharacterBox(valueBase);
if (valueSup) {
var newOptions = options.havingStyle(options.style.sup());
supm = buildGroup$1(valueSup, newOptions, options);
if (!isCharacterBox) {
supShift = base.height - newOptions.fontMetrics().supDrop * newOptions.sizeMultiplier / options.sizeMultiplier;
}
}
if (valueSub) {
var _newOptions = options.havingStyle(options.style.sub());
subm = buildGroup$1(valueSub, _newOptions, options);
if (!isCharacterBox) {
subShift = base.depth + _newOptions.fontMetrics().subDrop * _newOptions.sizeMultiplier / options.sizeMultiplier;
}
} // Rule 18c
var minSupShift;
if (options.style === Style$1.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.
var multiplier = options.sizeMultiplier;
var marginRight = makeEm(0.5 / metrics.ptPerEm / multiplier);
var 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.
var 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);
}
}
var supsub;
if (supm && subm) {
supShift = Math.max(supShift, minSupShift, supm.depth + 0.25 * metrics.xHeight);
subShift = Math.max(subShift, metrics.sub2);
var ruleWidth = metrics.defaultRuleThickness; // Rule 18e
var maxWidth = 4 * ruleWidth;
if (supShift - supm.depth - (subm.height - subShift) < maxWidth) {
subShift = maxWidth - (supShift - supm.depth) + subm.height;
var psi = 0.8 * metrics.xHeight - (supShift - supm.depth);
if (psi > 0) {
supShift += psi;
subShift -= psi;
}
}
var 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);
var _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.
var mclass = getTypeOfDomTree(base, "right") || "mord";
return buildCommon.makeSpan([mclass], [base, buildCommon.makeSpan(["msupsub"], [supsub])], options);
},
mathmlBuilder(group, options) {
// Is the inner group a relevant horizonal brace?
var isBrace = false;
var isOver;
var 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;
}
var children = [buildGroup(group.base, options)];
if (group.sub) {
children.push(buildGroup(group.sub, options));
}
if (group.sup) {
children.push(buildGroup(group.sup, options));
}
var nodeType;
if (isBrace) {
nodeType = isOver ? "mover" : "munder";
} else if (!group.sub) {
var base = group.base;
if (base && base.type === "op" && base.limits && (options.style === Style$1.DISPLAY || base.alwaysHandleSupSub)) {
nodeType = "mover";
} else if (base && base.type === "operatorname" && base.alwaysHandleSupSub && (base.limits || options.style === Style$1.DISPLAY)) {
nodeType = "mover";
} else {
nodeType = "msup";
}
} else if (!group.sup) {
var _base = group.base;
if (_base && _base.type === "op" && _base.limits && (options.style === Style$1.DISPLAY || _base.alwaysHandleSupSub)) {
nodeType = "munder";
} else if (_base && _base.type === "operatorname" && _base.alwaysHandleSupSub && (_base.limits || options.style === Style$1.DISPLAY)) {
nodeType = "munder";
} else {
nodeType = "msub";
}
} else {
var _base2 = group.base;
if (_base2 && _base2.type === "op" && _base2.limits && options.style === Style$1.DISPLAY) {
nodeType = "munderover";
} else if (_base2 && _base2.type === "operatorname" && _base2.alwaysHandleSupSub && (options.style === Style$1.DISPLAY || _base2.limits)) {
nodeType = "munderover";
} else {
nodeType = "msubsup";
}
}
return new mathMLTree.MathNode(nodeType, children);
}
});
defineFunctionBuilders({
type: "atom",
htmlBuilder(group, options) {
return buildCommon.mathsym(group.text, group.mode, options, ["m" + group.family]);
},
mathmlBuilder(group, options) {
var node = new mathMLTree.MathNode("mo", [makeText(group.text, group.mode)]);
if (group.family === "bin") {
var variant = 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;
}
});
// "mathord" and "textord" ParseNodes created in Parser.js from symbol Groups in
// src/symbols.js.
var defaultVariant = {
"mi": "italic",
"mn": "normal",
"mtext": "normal"
};
defineFunctionBuilders({
type: "mathord",
htmlBuilder(group, options) {
return buildCommon.makeOrd(group, options, "mathord");
},
mathmlBuilder(group, options) {
var node = new mathMLTree.MathNode("mi", [makeText(group.text, group.mode, options)]);
var variant = 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, options) {
var text = makeText(group.text, group.mode, options);
var variant = getVariant(group, options) || "normal";
var 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;
}
});
var cssSpace = {
"\\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`.
var regularSpace = {
" ": {},
"\\ ": {},
"~": {
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)) {
var 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") {
var 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) {
var 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;
}
});
var pad = () => {
var padNode = new mathMLTree.MathNode("mtd", []);
padNode.setAttribute("width", "50%");
return padNode;
};
defineFunctionBuilders({
type: "tag",
mathmlBuilder(group, options) {
var table = new mathMLTree.MathNode("mtable", [new mathMLTree.MathNode("mtr", [pad(), new mathMLTree.MathNode("mtd", [buildExpressionRow(group.body, options)]), pad(), new mathMLTree.MathNode("mtd", [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.
}
});
var textFontFamilies = {
"\\text": undefined,
"\\textrm": "textrm",
"\\textsf": "textsf",
"\\texttt": "texttt",
"\\textnormal": "textrm"
};
var textFontWeights = {
"\\textbf": "textbf",
"\\textmd": "textmd"
};
var textFontShapes = {
"\\textit": "textit",
"\\textup": "textup"
};
var optionsWithFont = (group, options) => {
var 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 {
return options.withTextFontShape(textFontShapes[font]);
}
};
defineFunction({
type: "text",
names: [// Font families
"\\text", "\\textrm", "\\textsf", "\\texttt", "\\textnormal", // Font weights
"\\textbf", "\\textmd", // Font Shapes
"\\textit", "\\textup"],
props: {
numArgs: 1,
argTypes: ["text"],
allowedInArgument: true,
allowedInText: true
},
handler(_ref, args) {
var {
parser,
funcName
} = _ref;
var body = args[0];
return {
type: "text",
mode: parser.mode,
body: ordargument(body),
font: funcName
};
},
htmlBuilder(group, options) {
var newOptions = optionsWithFont(group, options);
var inner = buildExpression$1(group.body, newOptions, true);
return buildCommon.makeSpan(["mord", "text"], inner, newOptions);
},
mathmlBuilder(group, options) {
var newOptions = optionsWithFont(group, options);
return buildExpressionRow(group.body, newOptions);
}
});
defineFunction({
type: "underline",
names: ["\\underline"],
props: {
numArgs: 1,
allowedInText: true
},
handler(_ref, args) {
var {
parser
} = _ref;
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.
var innerGroup = buildGroup$1(group.body, options); // Create the line to go below the body
var line = buildCommon.makeLineSpan("underline-line", options); // Generate the vlist, with the appropriate kerns
var defaultRuleThickness = options.fontMetrics().defaultRuleThickness;
var 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) {
var operator = new mathMLTree.MathNode("mo", [new mathMLTree.TextNode("\u203e")]);
operator.setAttribute("stretchy", "true");
var node = new mathMLTree.MathNode("munder", [buildGroup(group.body, options), operator]);
node.setAttribute("accentunder", "true");
return node;
}
});
defineFunction({
type: "vcenter",
names: ["\\vcenter"],
props: {
numArgs: 1,
argTypes: ["original"],
// In LaTeX, \vcenter can act only on a box.
allowedInText: false
},
handler(_ref, args) {
var {
parser
} = _ref;
return {
type: "vcenter",
mode: parser.mode,
body: args[0]
};
},
htmlBuilder(group, options) {
var body = buildGroup$1(group.body, options);
var axisHeight = options.fontMetrics().axisHeight;
var 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", [buildGroup(group.body, options)], ["vcenter"]);
}
});
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) {
var text = makeVerb(group);
var body = []; // \verb enters text mode and therefore is sized like \textstyle
var newOptions = options.havingStyle(options.style.text());
for (var i = 0; i < text.length; i++) {
var 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) {
var text = new mathMLTree.TextNode(makeVerb(group));
var 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
*/
var makeVerb = group => group.body.replace(/ /g, group.star ? '\u2423' : '\xA0');
/** Include this to ensure that all functions are defined. */
var functions = _functions;
/**
* 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.
*/
/* 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.
*/
var spaceRegexString = "[ \r\n\t]";
var controlWordRegexString = "\\\\[a-zA-Z@]+";
var controlSymbolRegexString = "\\\\[^\uD800-\uDFFF]";
var controlWordWhitespaceRegexString = "(" + controlWordRegexString + ")" + spaceRegexString + "*";
var controlSpaceRegexString = "\\\\(\n|[ \r\t]+\n?)[ \r\t]*";
var combiningDiacriticalMarkString = "[\u0300-\u036f]";
var combiningDiacriticalMarksEndRegex = new RegExp(combiningDiacriticalMarkString + "+$");
var 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 */
class Lexer {
// Category codes. The lexer only supports comment characters (14) for now.
// MacroExpander additionally distinguishes active (13).
constructor(input, settings) {
this.input = void 0;
this.settings = void 0;
this.tokenRegex = void 0;
this.catcodes = void 0;
// 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, code) {
this.catcodes[char] = code;
}
/**
* This function lexes a single token.
*/
lex() {
var input = this.input;
var pos = this.tokenRegex.lastIndex;
if (pos === input.length) {
return new Token("EOF", new SourceLocation(this, pos, pos));
}
var 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)));
}
var text = match[6] || match[3] || (match[2] ? "\\ " : " ");
if (this.catcodes[text] === 14) {
// comment character
var 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));
}
}
/**
* 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.
*/
class Namespace {
/**
* 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, globalMacros) {
if (builtins === void 0) {
builtins = {};
}
if (globalMacros === void 0) {
globalMacros = {};
}
this.current = void 0;
this.builtins = void 0;
this.undefStack = void 0;
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");
}
var undefs = this.undefStack.pop();
for (var 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) {
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) {
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, value, global) {
if (global === void 0) {
global = 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 (var 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.
var 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;
}
}
}
/**
* Predefined macros for KaTeX.
* This can be used to define some commands in terms of others.
*/
var macros = _macros;
// macro tools
defineMacro("\\noexpand", function (context) {
// The expansion is the token itself; but that token is interpreted
// as if its meaning were ‘\relax’ if it is a control sequence that
// would ordinarily be expanded by TeX’s expansion rules.
var t = context.popToken();
if (context.isExpandable(t.text)) {
t.noexpand = true;
t.treatAsRelax = true;
}
return {
tokens: [t],
numArgs: 0
};
});
defineMacro("\\expandafter", function (context) {
// TeX first reads the token that comes immediately after \expandafter,
// without expanding it; let’s call this token t. Then TeX reads the
// token that comes after t (and possibly more tokens, if that token
// has an argument), replacing it by its expansion. Finally TeX puts
// t back in front of that expansion.
var t = context.popToken();
context.expandOnce(true); // expand only an expandable token
return {
tokens: [t],
numArgs: 0
};
}); // LaTeX's \@firstoftwo{#1}{#2} expands to #1, skipping #2
// TeX source: \long\def\@firstoftwo#1#2{#1}
defineMacro("\\@firstoftwo", function (context) {
var args = context.consumeArgs(2);
return {
tokens: args[0],
numArgs: 0
};
}); // LaTeX's \@secondoftwo{#1}{#2} expands to #2, skipping #1
// TeX source: \long\def\@secondoftwo#1#2{#2}
defineMacro("\\@secondoftwo", function (context) {
var args = context.consumeArgs(2);
return {
tokens: args[1],
numArgs: 0
};
}); // LaTeX's \@ifnextchar{#1}{#2}{#3} looks ahead to the next (unexpanded)
// symbol that isn't a space, consuming any spaces but not consuming the
// first nonspace character. If that nonspace character matches #1, then
// the macro expands to #2; otherwise, it expands to #3.
defineMacro("\\@ifnextchar", function (context) {
var args = context.consumeArgs(3); // symbol, if, else
context.consumeSpaces();
var nextToken = context.future();
if (args[0].length === 1 && args[0][0].text === nextToken.text) {
return {
tokens: args[1],
numArgs: 0
};
} else {
return {
tokens: args[2],
numArgs: 0
};
}
}); // LaTeX's \@ifstar{#1}{#2} looks ahead to the next (unexpanded) symbol.
// If it is `*`, then it consumes the symbol, and the macro expands to #1;
// otherwise, the macro expands to #2 (without consuming the symbol).
// TeX source: \def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}}
defineMacro("\\@ifstar", "\\@ifnextchar *{\\@firstoftwo{#1}}"); // LaTeX's \TextOrMath{#1}{#2} expands to #1 in text mode, #2 in math mode
defineMacro("\\TextOrMath", function (context) {
var args = context.consumeArgs(2);
if (context.mode === 'text') {
return {
tokens: args[0],
numArgs: 0
};
} else {
return {
tokens: args[1],
numArgs: 0
};
}
}); // Lookup table for parsing numbers in base 8 through 16
var digitToNumber = {
"0": 0,
"1": 1,
"2": 2,
"3": 3,
"4": 4,
"5": 5,
"6": 6,
"7": 7,
"8": 8,
"9": 9,
"a": 10,
"A": 10,
"b": 11,
"B": 11,
"c": 12,
"C": 12,
"d": 13,
"D": 13,
"e": 14,
"E": 14,
"f": 15,
"F": 15
}; // TeX \char makes a literal character (catcode 12) using the following forms:
// (see The TeXBook, p. 43)
// \char123 -- decimal
// \char'123 -- octal
// \char"123 -- hex
// \char`x -- character that can be written (i.e. isn't active)
// \char`\x -- character that cannot be written (e.g. %)
// These all refer to characters from the font, so we turn them into special
// calls to a function \@char dealt with in the Parser.
defineMacro("\\char", function (context) {
var token = context.popToken();
var base;
var number = '';
if (token.text === "'") {
base = 8;
token = context.popToken();
} else if (token.text === '"') {
base = 16;
token = context.popToken();
} else if (token.text === "`") {
token = context.popToken();
if (token.text[0] === "\\") {
number = token.text.charCodeAt(1);
} else if (token.text === "EOF") {
throw new ParseError("\\char` missing argument");
} else {
number = token.text.charCodeAt(0);
}
} else {
base = 10;
}
if (base) {
// Parse a number in the given base, starting with first `token`.
number = digitToNumber[token.text];
if (number == null || number >= base) {
throw new ParseError("Invalid base-" + base + " digit " + token.text);
}
var digit;
while ((digit = digitToNumber[context.future().text]) != null && digit < base) {
number *= base;
number += digit;
context.popToken();
}
}
return "\\@char{" + number + "}";
}); // \newcommand{\macro}[args]{definition}
// \renewcommand{\macro}[args]{definition}
// TODO: Optional arguments: \newcommand{\macro}[args][default]{definition}
var newcommand = (context, existsOK, nonexistsOK) => {
var arg = context.consumeArg().tokens;
if (arg.length !== 1) {
throw new ParseError("\\newcommand's first argument must be a macro name");
}
var name = arg[0].text;
var exists = context.isDefined(name);
if (exists && !existsOK) {
throw new ParseError("\\newcommand{" + name + "} attempting to redefine " + (name + "; use \\renewcommand"));
}
if (!exists && !nonexistsOK) {
throw new ParseError("\\renewcommand{" + name + "} when command " + name + " " + "does not yet exist; use \\newcommand");
}
var numArgs = 0;
arg = context.consumeArg().tokens;
if (arg.length === 1 && arg[0].text === "[") {
var argText = '';
var token = context.expandNextToken();
while (token.text !== "]" && token.text !== "EOF") {
// TODO: Should properly expand arg, e.g., ignore {}s
argText += token.text;
token = context.expandNextToken();
}
if (!argText.match(/^\s*[0-9]+\s*$/)) {
throw new ParseError("Invalid number of arguments: " + argText);
}
numArgs = parseInt(argText);
arg = context.consumeArg().tokens;
} // Final arg is the expansion of the macro
context.macros.set(name, {
tokens: arg,
numArgs
});
return '';
};
defineMacro("\\newcommand", context => newcommand(context, false, true));
defineMacro("\\renewcommand", context => newcommand(context, true, false));
defineMacro("\\providecommand", context => newcommand(context, true, true)); // terminal (console) tools
defineMacro("\\message", context => {
var arg = context.consumeArgs(1)[0]; // eslint-disable-next-line no-console
console.log(arg.reverse().map(token => token.text).join(""));
return '';
});
defineMacro("\\errmessage", context => {
var arg = context.consumeArgs(1)[0]; // eslint-disable-next-line no-console
console.error(arg.reverse().map(token => token.text).join(""));
return '';
});
defineMacro("\\show", context => {
var tok = context.popToken();
var name = tok.text; // eslint-disable-next-line no-console
console.log(tok, context.macros.get(name), functions[name], symbols.math[name], symbols.text[name]);
return '';
}); //////////////////////////////////////////////////////////////////////
// Grouping
// \let\bgroup={ \let\egroup=}
defineMacro("\\bgroup", "{");
defineMacro("\\egroup", "}"); // Symbols from latex.ltx:
// \def~{\nobreakspace{}}
// \def\lq{`}
// \def\rq{'}
// \def \aa {\r a}
// \def \AA {\r A}
defineMacro("~", "\\nobreakspace");
defineMacro("\\lq", "`");
defineMacro("\\rq", "'");
defineMacro("\\aa", "\\r a");
defineMacro("\\AA", "\\r A"); // Copyright (C) and registered (R) symbols. Use raw symbol in MathML.
// \DeclareTextCommandDefault{\textcopyright}{\textcircled{c}}
// \DeclareTextCommandDefault{\textregistered}{\textcircled{%
// \check@mathfonts\fontsize\sf@size\z@\math@fontsfalse\selectfont R}}
// \DeclareRobustCommand{\copyright}{%
// \ifmmode{\nfss@text{\textcopyright}}\else\textcopyright\fi}
defineMacro("\\textcopyright", "\\html@mathml{\\textcircled{c}}{\\char`©}");
defineMacro("\\copyright", "\\TextOrMath{\\textcopyright}{\\text{\\textcopyright}}");
defineMacro("\\textregistered", "\\html@mathml{\\textcircled{\\scriptsize R}}{\\char`®}"); // Characters omitted from Unicode range 1D400–1D7FF
defineMacro("\u212C", "\\mathscr{B}"); // script
defineMacro("\u2130", "\\mathscr{E}");
defineMacro("\u2131", "\\mathscr{F}");
defineMacro("\u210B", "\\mathscr{H}");
defineMacro("\u2110", "\\mathscr{I}");
defineMacro("\u2112", "\\mathscr{L}");
defineMacro("\u2133", "\\mathscr{M}");
defineMacro("\u211B", "\\mathscr{R}");
defineMacro("\u212D", "\\mathfrak{C}"); // Fraktur
defineMacro("\u210C", "\\mathfrak{H}");
defineMacro("\u2128", "\\mathfrak{Z}"); // Define \Bbbk with a macro that works in both HTML and MathML.
defineMacro("\\Bbbk", "\\Bbb{k}"); // Unicode middle dot
// The KaTeX fonts do not contain U+00B7. Instead, \cdotp displays
// the dot at U+22C5 and gives it punct spacing.
defineMacro("\u00b7", "\\cdotp"); // \llap and \rlap render their contents in text mode
defineMacro("\\llap", "\\mathllap{\\textrm{#1}}");
defineMacro("\\rlap", "\\mathrlap{\\textrm{#1}}");
defineMacro("\\clap", "\\mathclap{\\textrm{#1}}"); // \mathstrut from the TeXbook, p 360
defineMacro("\\mathstrut", "\\vphantom{(}"); // \underbar from TeXbook p 353
defineMacro("\\underbar", "\\underline{\\text{#1}}"); // \not is defined by base/fontmath.ltx via
// \DeclareMathSymbol{\not}{\mathrel}{symbols}{"36}
// It's thus treated like a \mathrel, but defined by a symbol that has zero
// width but extends to the right. We use \rlap to get that spacing.
// For MathML we write U+0338 here. buildMathML.js will then do the overlay.
defineMacro("\\not", '\\html@mathml{\\mathrel{\\mathrlap\\@not}}{\\char"338}'); // Negated symbols from base/fontmath.ltx:
// \def\neq{\not=} \let\ne=\neq
// \DeclareRobustCommand
// \notin{\mathrel{\m@th\mathpalette\c@ncel\in}}
// \def\c@ncel#1#2{\m@th\ooalign{$\hfil#1\mkern1mu/\hfil$\crcr$#1#2$}}
defineMacro("\\neq", "\\html@mathml{\\mathrel{\\not=}}{\\mathrel{\\char`≠}}");
defineMacro("\\ne", "\\neq");
defineMacro("\u2260", "\\neq");
defineMacro("\\notin", "\\html@mathml{\\mathrel{{\\in}\\mathllap{/\\mskip1mu}}}" + "{\\mathrel{\\char`∉}}");
defineMacro("\u2209", "\\notin"); // Unicode stacked relations
defineMacro("\u2258", "\\html@mathml{" + "\\mathrel{=\\kern{-1em}\\raisebox{0.4em}{$\\scriptsize\\frown$}}" + "}{\\mathrel{\\char`\u2258}}");
defineMacro("\u2259", "\\html@mathml{\\stackrel{\\tiny\\wedge}{=}}{\\mathrel{\\char`\u2258}}");
defineMacro("\u225A", "\\html@mathml{\\stackrel{\\tiny\\vee}{=}}{\\mathrel{\\char`\u225A}}");
defineMacro("\u225B", "\\html@mathml{\\stackrel{\\scriptsize\\star}{=}}" + "{\\mathrel{\\char`\u225B}}");
defineMacro("\u225D", "\\html@mathml{\\stackrel{\\tiny\\mathrm{def}}{=}}" + "{\\mathrel{\\char`\u225D}}");
defineMacro("\u225E", "\\html@mathml{\\stackrel{\\tiny\\mathrm{m}}{=}}" + "{\\mathrel{\\char`\u225E}}");
defineMacro("\u225F", "\\html@mathml{\\stackrel{\\tiny?}{=}}{\\mathrel{\\char`\u225F}}"); // Misc Unicode
defineMacro("\u27C2", "\\perp");
defineMacro("\u203C", "\\mathclose{!\\mkern-0.8mu!}");
defineMacro("\u220C", "\\notni");
defineMacro("\u231C", "\\ulcorner");
defineMacro("\u231D", "\\urcorner");
defineMacro("\u231E", "\\llcorner");
defineMacro("\u231F", "\\lrcorner");
defineMacro("\u00A9", "\\copyright");
defineMacro("\u00AE", "\\textregistered");
defineMacro("\uFE0F", "\\textregistered"); // The KaTeX fonts have corners at codepoints that don't match Unicode.
// For MathML purposes, use the Unicode code point.
defineMacro("\\ulcorner", "\\html@mathml{\\@ulcorner}{\\mathop{\\char\"231c}}");
defineMacro("\\urcorner", "\\html@mathml{\\@urcorner}{\\mathop{\\char\"231d}}");
defineMacro("\\llcorner", "\\html@mathml{\\@llcorner}{\\mathop{\\char\"231e}}");
defineMacro("\\lrcorner", "\\html@mathml{\\@lrcorner}{\\mathop{\\char\"231f}}"); //////////////////////////////////////////////////////////////////////
// LaTeX_2ε
// \vdots{\vbox{\baselineskip4\p@ \lineskiplimit\z@
// \kern6\p@\hbox{.}\hbox{.}\hbox{.}}}
// We'll call \varvdots, which gets a glyph from symbols.js.
// The zero-width rule gets us an equivalent to the vertical 6pt kern.
defineMacro("\\vdots", "\\mathord{\\varvdots\\rule{0pt}{15pt}}");
defineMacro("\u22ee", "\\vdots"); //////////////////////////////////////////////////////////////////////
// amsmath.sty
// http://mirrors.concertpass.com/tex-archive/macros/latex/required/amsmath/amsmath.pdf
// Italic Greek capital letters. AMS defines these with \DeclareMathSymbol,
// but they are equivalent to \mathit{\Letter}.
defineMacro("\\varGamma", "\\mathit{\\Gamma}");
defineMacro("\\varDelta", "\\mathit{\\Delta}");
defineMacro("\\varTheta", "\\mathit{\\Theta}");
defineMacro("\\varLambda", "\\mathit{\\Lambda}");
defineMacro("\\varXi", "\\mathit{\\Xi}");
defineMacro("\\varPi", "\\mathit{\\Pi}");
defineMacro("\\varSigma", "\\mathit{\\Sigma}");
defineMacro("\\varUpsilon", "\\mathit{\\Upsilon}");
defineMacro("\\varPhi", "\\mathit{\\Phi}");
defineMacro("\\varPsi", "\\mathit{\\Psi}");
defineMacro("\\varOmega", "\\mathit{\\Omega}"); //\newcommand{\substack}[1]{\subarray{c}#1\endsubarray}
defineMacro("\\substack", "\\begin{subarray}{c}#1\\end{subarray}"); // \renewcommand{\colon}{\nobreak\mskip2mu\mathpunct{}\nonscript
// \mkern-\thinmuskip{:}\mskip6muplus1mu\relax}
defineMacro("\\colon", "\\nobreak\\mskip2mu\\mathpunct{}" + "\\mathchoice{\\mkern-3mu}{\\mkern-3mu}{}{}{:}\\mskip6mu\\relax"); // \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}
defineMacro("\\boxed", "\\fbox{$\\displaystyle{#1}$}"); // \def\iff{\DOTSB\;\Longleftrightarrow\;}
// \def\implies{\DOTSB\;\Longrightarrow\;}
// \def\impliedby{\DOTSB\;\Longleftarrow\;}
defineMacro("\\iff", "\\DOTSB\\;\\Longleftrightarrow\\;");
defineMacro("\\implies", "\\DOTSB\\;\\Longrightarrow\\;");
defineMacro("\\impliedby", "\\DOTSB\\;\\Longleftarrow\\;"); // AMSMath's automatic \dots, based on \mdots@@ macro.
var dotsByToken = {
',': '\\dotsc',
'\\not': '\\dotsb',
// \keybin@ checks for the following:
'+': '\\dotsb',
'=': '\\dotsb',
'<': '\\dotsb',
'>': '\\dotsb',
'-': '\\dotsb',
'*': '\\dotsb',
':': '\\dotsb',
// Symbols whose definition starts with \DOTSB:
'\\DOTSB': '\\dotsb',
'\\coprod': '\\dotsb',
'\\bigvee': '\\dotsb',
'\\bigwedge': '\\dotsb',
'\\biguplus': '\\dotsb',
'\\bigcap': '\\dotsb',
'\\bigcup': '\\dotsb',
'\\prod': '\\dotsb',
'\\sum': '\\dotsb',
'\\bigotimes': '\\dotsb',
'\\bigoplus': '\\dotsb',
'\\bigodot': '\\dotsb',
'\\bigsqcup': '\\dotsb',
'\\And': '\\dotsb',
'\\longrightarrow': '\\dotsb',
'\\Longrightarrow': '\\dotsb',
'\\longleftarrow': '\\dotsb',
'\\Longleftarrow': '\\dotsb',
'\\longleftrightarrow': '\\dotsb',
'\\Longleftrightarrow': '\\dotsb',
'\\mapsto': '\\dotsb',
'\\longmapsto': '\\dotsb',
'\\hookrightarrow': '\\dotsb',
'\\doteq': '\\dotsb',
// Symbols whose definition starts with \mathbin:
'\\mathbin': '\\dotsb',
// Symbols whose definition starts with \mathrel:
'\\mathrel': '\\dotsb',
'\\relbar': '\\dotsb',
'\\Relbar': '\\dotsb',
'\\xrightarrow': '\\dotsb',
'\\xleftarrow': '\\dotsb',
// Symbols whose definition starts with \DOTSI:
'\\DOTSI': '\\dotsi',
'\\int': '\\dotsi',
'\\oint': '\\dotsi',
'\\iint': '\\dotsi',
'\\iiint': '\\dotsi',
'\\iiiint': '\\dotsi',
'\\idotsint': '\\dotsi',
// Symbols whose definition starts with \DOTSX:
'\\DOTSX': '\\dotsx'
};
defineMacro("\\dots", function (context) {
// TODO: If used in text mode, should expand to \textellipsis.
// However, in KaTeX, \textellipsis and \ldots behave the same
// (in text mode), and it's unlikely we'd see any of the math commands
// that affect the behavior of \dots when in text mode. So fine for now
// (until we support \ifmmode ... \else ... \fi).
var thedots = '\\dotso';
var next = context.expandAfterFuture().text;
if (next in dotsByToken) {
thedots = dotsByToken[next];
} else if (next.slice(0, 4) === '\\not') {
thedots = '\\dotsb';
} else if (next in symbols.math) {
if (utils.contains(['bin', 'rel'], symbols.math[next].group)) {
thedots = '\\dotsb';
}
}
return thedots;
});
var spaceAfterDots = {
// \rightdelim@ checks for the following:
')': true,
']': true,
'\\rbrack': true,
'\\}': true,
'\\rbrace': true,
'\\rangle': true,
'\\rceil': true,
'\\rfloor': true,
'\\rgroup': true,
'\\rmoustache': true,
'\\right': true,
'\\bigr': true,
'\\biggr': true,
'\\Bigr': true,
'\\Biggr': true,
// \extra@ also tests for the following:
'$': true,
// \extrap@ checks for the following:
';': true,
'.': true,
',': true
};
defineMacro("\\dotso", function (context) {
var next = context.future().text;
if (next in spaceAfterDots) {
return "\\ldots\\,";
} else {
return "\\ldots";
}
});
defineMacro("\\dotsc", function (context) {
var next = context.future().text; // \dotsc uses \extra@ but not \extrap@, instead specially checking for
// ';' and '.', but doesn't check for ','.
if (next in spaceAfterDots && next !== ',') {
return "\\ldots\\,";
} else {
return "\\ldots";
}
});
defineMacro("\\cdots", function (context) {
var next = context.future().text;
if (next in spaceAfterDots) {
return "\\@cdots\\,";
} else {
return "\\@cdots";
}
});
defineMacro("\\dotsb", "\\cdots");
defineMacro("\\dotsm", "\\cdots");
defineMacro("\\dotsi", "\\!\\cdots"); // amsmath doesn't actually define \dotsx, but \dots followed by a macro
// starting with \DOTSX implies \dotso, and then \extra@ detects this case
// and forces the added `\,`.
defineMacro("\\dotsx", "\\ldots\\,"); // \let\DOTSI\relax
// \let\DOTSB\relax
// \let\DOTSX\relax
defineMacro("\\DOTSI", "\\relax");
defineMacro("\\DOTSB", "\\relax");
defineMacro("\\DOTSX", "\\relax"); // Spacing, based on amsmath.sty's override of LaTeX defaults
// \DeclareRobustCommand{\tmspace}[3]{%
// \ifmmode\mskip#1#2\else\kern#1#3\fi\relax}
defineMacro("\\tmspace", "\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax"); // \renewcommand{\,}{\tmspace+\thinmuskip{.1667em}}
// TODO: math mode should use \thinmuskip
defineMacro("\\,", "\\tmspace+{3mu}{.1667em}"); // \let\thinspace\,
defineMacro("\\thinspace", "\\,"); // \def\>{\mskip\medmuskip}
// \renewcommand{\:}{\tmspace+\medmuskip{.2222em}}
// TODO: \> and math mode of \: should use \medmuskip = 4mu plus 2mu minus 4mu
defineMacro("\\>", "\\mskip{4mu}");
defineMacro("\\:", "\\tmspace+{4mu}{.2222em}"); // \let\medspace\:
defineMacro("\\medspace", "\\:"); // \renewcommand{\;}{\tmspace+\thickmuskip{.2777em}}
// TODO: math mode should use \thickmuskip = 5mu plus 5mu
defineMacro("\\;", "\\tmspace+{5mu}{.2777em}"); // \let\thickspace\;
defineMacro("\\thickspace", "\\;"); // \renewcommand{\!}{\tmspace-\thinmuskip{.1667em}}
// TODO: math mode should use \thinmuskip
defineMacro("\\!", "\\tmspace-{3mu}{.1667em}"); // \let\negthinspace\!
defineMacro("\\negthinspace", "\\!"); // \newcommand{\negmedspace}{\tmspace-\medmuskip{.2222em}}
// TODO: math mode should use \medmuskip
defineMacro("\\negmedspace", "\\tmspace-{4mu}{.2222em}"); // \newcommand{\negthickspace}{\tmspace-\thickmuskip{.2777em}}
// TODO: math mode should use \thickmuskip
defineMacro("\\negthickspace", "\\tmspace-{5mu}{.277em}"); // \def\enspace{\kern.5em }
defineMacro("\\enspace", "\\kern.5em "); // \def\enskip{\hskip.5em\relax}
defineMacro("\\enskip", "\\hskip.5em\\relax"); // \def\quad{\hskip1em\relax}
defineMacro("\\quad", "\\hskip1em\\relax"); // \def\qquad{\hskip2em\relax}
defineMacro("\\qquad", "\\hskip2em\\relax"); // \tag@in@display form of \tag
defineMacro("\\tag", "\\@ifstar\\tag@literal\\tag@paren");
defineMacro("\\tag@paren", "\\tag@literal{({#1})}");
defineMacro("\\tag@literal", context => {
if (context.macros.get("\\df@tag")) {
throw new ParseError("Multiple \\tag");
}
return "\\gdef\\df@tag{\\text{#1}}";
}); // \renewcommand{\bmod}{\nonscript\mskip-\medmuskip\mkern5mu\mathbin
// {\operator@font mod}\penalty900
// \mkern5mu\nonscript\mskip-\medmuskip}
// \newcommand{\pod}[1]{\allowbreak
// \if@display\mkern18mu\else\mkern8mu\fi(#1)}
// \renewcommand{\pmod}[1]{\pod{{\operator@font mod}\mkern6mu#1}}
// \newcommand{\mod}[1]{\allowbreak\if@display\mkern18mu
// \else\mkern12mu\fi{\operator@font mod}\,\,#1}
// TODO: math mode should use \medmuskip = 4mu plus 2mu minus 4mu
defineMacro("\\bmod", "\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}" + "\\mathbin{\\rm mod}" + "\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}");
defineMacro("\\pod", "\\allowbreak" + "\\mathchoice{\\mkern18mu}{\\mkern8mu}{\\mkern8mu}{\\mkern8mu}(#1)");
defineMacro("\\pmod", "\\pod{{\\rm mod}\\mkern6mu#1}");
defineMacro("\\mod", "\\allowbreak" + "\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}" + "{\\rm mod}\\,\\,#1"); //////////////////////////////////////////////////////////////////////
// LaTeX source2e
// \expandafter\let\expandafter\@normalcr
// \csname\expandafter\@gobble\string\\ \endcsname
// \DeclareRobustCommand\newline{\@normalcr\relax}
defineMacro("\\newline", "\\\\\\relax"); // \def\TeX{T\kern-.1667em\lower.5ex\hbox{E}\kern-.125emX\@}
// TODO: Doesn't normally work in math mode because \@ fails. KaTeX doesn't
// support \@ yet, so that's omitted, and we add \text so that the result
// doesn't look funny in math mode.
defineMacro("\\TeX", "\\textrm{\\html@mathml{" + "T\\kern-.1667em\\raisebox{-.5ex}{E}\\kern-.125emX" + "}{TeX}}"); // \DeclareRobustCommand{\LaTeX}{L\kern-.36em%
// {\sbox\z@ T%
// \vbox to\ht\z@{\hbox{\check@mathfonts
// \fontsize\sf@size\z@
// \math@fontsfalse\selectfont
// A}%
// \vss}%
// }%
// \kern-.15em%
// \TeX}
// This code aligns the top of the A with the T (from the perspective of TeX's
// boxes, though visually the A appears to extend above slightly).
// We compute the corresponding \raisebox when A is rendered in \normalsize
// \scriptstyle, which has a scale factor of 0.7 (see Options.js).
var latexRaiseA = makeEm(fontMetricsData['Main-Regular']["T".charCodeAt(0)][1] - 0.7 * fontMetricsData['Main-Regular']["A".charCodeAt(0)][1]);
defineMacro("\\LaTeX", "\\textrm{\\html@mathml{" + ("L\\kern-.36em\\raisebox{" + latexRaiseA + "}{\\scriptstyle A}") + "\\kern-.15em\\TeX}{LaTeX}}"); // New KaTeX logo based on tweaking LaTeX logo
defineMacro("\\KaTeX", "\\textrm{\\html@mathml{" + ("K\\kern-.17em\\raisebox{" + latexRaiseA + "}{\\scriptstyle A}") + "\\kern-.15em\\TeX}{KaTeX}}"); // \DeclareRobustCommand\hspace{\@ifstar\@hspacer\@hspace}
// \def\@hspace#1{\hskip #1\relax}
// \def\@hspacer#1{\vrule \@width\z@\nobreak
// \hskip #1\hskip \z@skip}
defineMacro("\\hspace", "\\@ifstar\\@hspacer\\@hspace");
defineMacro("\\@hspace", "\\hskip #1\\relax");
defineMacro("\\@hspacer", "\\rule{0pt}{0pt}\\hskip #1\\relax"); //////////////////////////////////////////////////////////////////////
// mathtools.sty
//\providecommand\ordinarycolon{:}
defineMacro("\\ordinarycolon", ":"); //\def\vcentcolon{\mathrel{\mathop\ordinarycolon}}
//TODO(edemaine): Not yet centered. Fix via \raisebox or #726
defineMacro("\\vcentcolon", "\\mathrel{\\mathop\\ordinarycolon}"); // \providecommand*\dblcolon{\vcentcolon\mathrel{\mkern-.9mu}\vcentcolon}
defineMacro("\\dblcolon", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-.9mu}\\vcentcolon}}" + "{\\mathop{\\char\"2237}}"); // \providecommand*\coloneqq{\vcentcolon\mathrel{\mkern-1.2mu}=}
defineMacro("\\coloneqq", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}=}}" + "{\\mathop{\\char\"2254}}"); // ≔
// \providecommand*\Coloneqq{\dblcolon\mathrel{\mkern-1.2mu}=}
defineMacro("\\Coloneqq", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}=}}" + "{\\mathop{\\char\"2237\\char\"3d}}"); // \providecommand*\coloneq{\vcentcolon\mathrel{\mkern-1.2mu}\mathrel{-}}
defineMacro("\\coloneq", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}" + "{\\mathop{\\char\"3a\\char\"2212}}"); // \providecommand*\Coloneq{\dblcolon\mathrel{\mkern-1.2mu}\mathrel{-}}
defineMacro("\\Coloneq", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}" + "{\\mathop{\\char\"2237\\char\"2212}}"); // \providecommand*\eqqcolon{=\mathrel{\mkern-1.2mu}\vcentcolon}
defineMacro("\\eqqcolon", "\\html@mathml{" + "\\mathrel{=\\mathrel{\\mkern-1.2mu}\\vcentcolon}}" + "{\\mathop{\\char\"2255}}"); // ≕
// \providecommand*\Eqqcolon{=\mathrel{\mkern-1.2mu}\dblcolon}
defineMacro("\\Eqqcolon", "\\html@mathml{" + "\\mathrel{=\\mathrel{\\mkern-1.2mu}\\dblcolon}}" + "{\\mathop{\\char\"3d\\char\"2237}}"); // \providecommand*\eqcolon{\mathrel{-}\mathrel{\mkern-1.2mu}\vcentcolon}
defineMacro("\\eqcolon", "\\html@mathml{" + "\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\vcentcolon}}" + "{\\mathop{\\char\"2239}}"); // \providecommand*\Eqcolon{\mathrel{-}\mathrel{\mkern-1.2mu}\dblcolon}
defineMacro("\\Eqcolon", "\\html@mathml{" + "\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\dblcolon}}" + "{\\mathop{\\char\"2212\\char\"2237}}"); // \providecommand*\colonapprox{\vcentcolon\mathrel{\mkern-1.2mu}\approx}
defineMacro("\\colonapprox", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\approx}}" + "{\\mathop{\\char\"3a\\char\"2248}}"); // \providecommand*\Colonapprox{\dblcolon\mathrel{\mkern-1.2mu}\approx}
defineMacro("\\Colonapprox", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\approx}}" + "{\\mathop{\\char\"2237\\char\"2248}}"); // \providecommand*\colonsim{\vcentcolon\mathrel{\mkern-1.2mu}\sim}
defineMacro("\\colonsim", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\sim}}" + "{\\mathop{\\char\"3a\\char\"223c}}"); // \providecommand*\Colonsim{\dblcolon\mathrel{\mkern-1.2mu}\sim}
defineMacro("\\Colonsim", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\sim}}" + "{\\mathop{\\char\"2237\\char\"223c}}"); // Some Unicode characters are implemented with macros to mathtools functions.
defineMacro("\u2237", "\\dblcolon"); // ::
defineMacro("\u2239", "\\eqcolon"); // -:
defineMacro("\u2254", "\\coloneqq"); // :=
defineMacro("\u2255", "\\eqqcolon"); // =:
defineMacro("\u2A74", "\\Coloneqq"); // ::=
//////////////////////////////////////////////////////////////////////
// colonequals.sty
// Alternate names for mathtools's macros:
defineMacro("\\ratio", "\\vcentcolon");
defineMacro("\\coloncolon", "\\dblcolon");
defineMacro("\\colonequals", "\\coloneqq");
defineMacro("\\coloncolonequals", "\\Coloneqq");
defineMacro("\\equalscolon", "\\eqqcolon");
defineMacro("\\equalscoloncolon", "\\Eqqcolon");
defineMacro("\\colonminus", "\\coloneq");
defineMacro("\\coloncolonminus", "\\Coloneq");
defineMacro("\\minuscolon", "\\eqcolon");
defineMacro("\\minuscoloncolon", "\\Eqcolon"); // \colonapprox name is same in mathtools and colonequals.
defineMacro("\\coloncolonapprox", "\\Colonapprox"); // \colonsim name is same in mathtools and colonequals.
defineMacro("\\coloncolonsim", "\\Colonsim"); // Additional macros, implemented by analogy with mathtools definitions:
defineMacro("\\simcolon", "\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\vcentcolon}");
defineMacro("\\simcoloncolon", "\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\dblcolon}");
defineMacro("\\approxcolon", "\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\vcentcolon}");
defineMacro("\\approxcoloncolon", "\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\dblcolon}"); // Present in newtxmath, pxfonts and txfonts
defineMacro("\\notni", "\\html@mathml{\\not\\ni}{\\mathrel{\\char`\u220C}}");
defineMacro("\\limsup", "\\DOTSB\\operatorname*{lim\\,sup}");
defineMacro("\\liminf", "\\DOTSB\\operatorname*{lim\\,inf}"); //////////////////////////////////////////////////////////////////////
// From amsopn.sty
defineMacro("\\injlim", "\\DOTSB\\operatorname*{inj\\,lim}");
defineMacro("\\projlim", "\\DOTSB\\operatorname*{proj\\,lim}");
defineMacro("\\varlimsup", "\\DOTSB\\operatorname*{\\overline{lim}}");
defineMacro("\\varliminf", "\\DOTSB\\operatorname*{\\underline{lim}}");
defineMacro("\\varinjlim", "\\DOTSB\\operatorname*{\\underrightarrow{lim}}");
defineMacro("\\varprojlim", "\\DOTSB\\operatorname*{\\underleftarrow{lim}}"); //////////////////////////////////////////////////////////////////////
// MathML alternates for KaTeX glyphs in the Unicode private area
defineMacro("\\gvertneqq", "\\html@mathml{\\@gvertneqq}{\u2269}");
defineMacro("\\lvertneqq", "\\html@mathml{\\@lvertneqq}{\u2268}");
defineMacro("\\ngeqq", "\\html@mathml{\\@ngeqq}{\u2271}");
defineMacro("\\ngeqslant", "\\html@mathml{\\@ngeqslant}{\u2271}");
defineMacro("\\nleqq", "\\html@mathml{\\@nleqq}{\u2270}");
defineMacro("\\nleqslant", "\\html@mathml{\\@nleqslant}{\u2270}");
defineMacro("\\nshortmid", "\\html@mathml{\\@nshortmid}{∤}");
defineMacro("\\nshortparallel", "\\html@mathml{\\@nshortparallel}{∦}");
defineMacro("\\nsubseteqq", "\\html@mathml{\\@nsubseteqq}{\u2288}");
defineMacro("\\nsupseteqq", "\\html@mathml{\\@nsupseteqq}{\u2289}");
defineMacro("\\varsubsetneq", "\\html@mathml{\\@varsubsetneq}{⊊}");
defineMacro("\\varsubsetneqq", "\\html@mathml{\\@varsubsetneqq}{⫋}");
defineMacro("\\varsupsetneq", "\\html@mathml{\\@varsupsetneq}{⊋}");
defineMacro("\\varsupsetneqq", "\\html@mathml{\\@varsupsetneqq}{⫌}");
defineMacro("\\imath", "\\html@mathml{\\@imath}{\u0131}");
defineMacro("\\jmath", "\\html@mathml{\\@jmath}{\u0237}"); //////////////////////////////////////////////////////////////////////
// stmaryrd and semantic
// The stmaryrd and semantic packages render the next four items by calling a
// glyph. Those glyphs do not exist in the KaTeX fonts. Hence the macros.
defineMacro("\\llbracket", "\\html@mathml{" + "\\mathopen{[\\mkern-3.2mu[}}" + "{\\mathopen{\\char`\u27e6}}");
defineMacro("\\rrbracket", "\\html@mathml{" + "\\mathclose{]\\mkern-3.2mu]}}" + "{\\mathclose{\\char`\u27e7}}");
defineMacro("\u27e6", "\\llbracket"); // blackboard bold [
defineMacro("\u27e7", "\\rrbracket"); // blackboard bold ]
defineMacro("\\lBrace", "\\html@mathml{" + "\\mathopen{\\{\\mkern-3.2mu[}}" + "{\\mathopen{\\char`\u2983}}");
defineMacro("\\rBrace", "\\html@mathml{" + "\\mathclose{]\\mkern-3.2mu\\}}}" + "{\\mathclose{\\char`\u2984}}");
defineMacro("\u2983", "\\lBrace"); // blackboard bold {
defineMacro("\u2984", "\\rBrace"); // blackboard bold }
// TODO: Create variable sized versions of the last two items. I believe that
// will require new font glyphs.
// The stmaryrd function `\minuso` provides a "Plimsoll" symbol that
// superimposes the characters \circ and \mathminus. Used in chemistry.
defineMacro("\\minuso", "\\mathbin{\\html@mathml{" + "{\\mathrlap{\\mathchoice{\\kern{0.145em}}{\\kern{0.145em}}" + "{\\kern{0.1015em}}{\\kern{0.0725em}}\\circ}{-}}}" + "{\\char`⦵}}");
defineMacro("⦵", "\\minuso"); //////////////////////////////////////////////////////////////////////
// texvc.sty
// The texvc package contains macros available in mediawiki pages.
// We omit the functions deprecated at
// https://en.wikipedia.org/wiki/Help:Displaying_a_formula#Deprecated_syntax
// We also omit texvc's \O, which conflicts with \text{\O}
defineMacro("\\darr", "\\downarrow");
defineMacro("\\dArr", "\\Downarrow");
defineMacro("\\Darr", "\\Downarrow");
defineMacro("\\lang", "\\langle");
defineMacro("\\rang", "\\rangle");
defineMacro("\\uarr", "\\uparrow");
defineMacro("\\uArr", "\\Uparrow");
defineMacro("\\Uarr", "\\Uparrow");
defineMacro("\\N", "\\mathbb{N}");
defineMacro("\\R", "\\mathbb{R}");
defineMacro("\\Z", "\\mathbb{Z}");
defineMacro("\\alef", "\\aleph");
defineMacro("\\alefsym", "\\aleph");
defineMacro("\\Alpha", "\\mathrm{A}");
defineMacro("\\Beta", "\\mathrm{B}");
defineMacro("\\bull", "\\bullet");
defineMacro("\\Chi", "\\mathrm{X}");
defineMacro("\\clubs", "\\clubsuit");
defineMacro("\\cnums", "\\mathbb{C}");
defineMacro("\\Complex", "\\mathbb{C}");
defineMacro("\\Dagger", "\\ddagger");
defineMacro("\\diamonds", "\\diamondsuit");
defineMacro("\\empty", "\\emptyset");
defineMacro("\\Epsilon", "\\mathrm{E}");
defineMacro("\\Eta", "\\mathrm{H}");
defineMacro("\\exist", "\\exists");
defineMacro("\\harr", "\\leftrightarrow");
defineMacro("\\hArr", "\\Leftrightarrow");
defineMacro("\\Harr", "\\Leftrightarrow");
defineMacro("\\hearts", "\\heartsuit");
defineMacro("\\image", "\\Im");
defineMacro("\\infin", "\\infty");
defineMacro("\\Iota", "\\mathrm{I}");
defineMacro("\\isin", "\\in");
defineMacro("\\Kappa", "\\mathrm{K}");
defineMacro("\\larr", "\\leftarrow");
defineMacro("\\lArr", "\\Leftarrow");
defineMacro("\\Larr", "\\Leftarrow");
defineMacro("\\lrarr", "\\leftrightarrow");
defineMacro("\\lrArr", "\\Leftrightarrow");
defineMacro("\\Lrarr", "\\Leftrightarrow");
defineMacro("\\Mu", "\\mathrm{M}");
defineMacro("\\natnums", "\\mathbb{N}");
defineMacro("\\Nu", "\\mathrm{N}");
defineMacro("\\Omicron", "\\mathrm{O}");
defineMacro("\\plusmn", "\\pm");
defineMacro("\\rarr", "\\rightarrow");
defineMacro("\\rArr", "\\Rightarrow");
defineMacro("\\Rarr", "\\Rightarrow");
defineMacro("\\real", "\\Re");
defineMacro("\\reals", "\\mathbb{R}");
defineMacro("\\Reals", "\\mathbb{R}");
defineMacro("\\Rho", "\\mathrm{P}");
defineMacro("\\sdot", "\\cdot");
defineMacro("\\sect", "\\S");
defineMacro("\\spades", "\\spadesuit");
defineMacro("\\sub", "\\subset");
defineMacro("\\sube", "\\subseteq");
defineMacro("\\supe", "\\supseteq");
defineMacro("\\Tau", "\\mathrm{T}");
defineMacro("\\thetasym", "\\vartheta"); // TODO: defineMacro("\\varcoppa", "\\\mbox{\\coppa}");
defineMacro("\\weierp", "\\wp");
defineMacro("\\Zeta", "\\mathrm{Z}"); //////////////////////////////////////////////////////////////////////
// statmath.sty
// https://ctan.math.illinois.edu/macros/latex/contrib/statmath/statmath.pdf
defineMacro("\\argmin", "\\DOTSB\\operatorname*{arg\\,min}");
defineMacro("\\argmax", "\\DOTSB\\operatorname*{arg\\,max}");
defineMacro("\\plim", "\\DOTSB\\mathop{\\operatorname{plim}}\\limits"); //////////////////////////////////////////////////////////////////////
// braket.sty
// http://ctan.math.washington.edu/tex-archive/macros/latex/contrib/braket/braket.pdf
defineMacro("\\bra", "\\mathinner{\\langle{#1}|}");
defineMacro("\\ket", "\\mathinner{|{#1}\\rangle}");
defineMacro("\\braket", "\\mathinner{\\langle{#1}\\rangle}");
defineMacro("\\Bra", "\\left\\langle#1\\right|");
defineMacro("\\Ket", "\\left|#1\\right\\rangle");
var braketHelper = one => context => {
var left = context.consumeArg().tokens;
var middle = context.consumeArg().tokens;
var middleDouble = context.consumeArg().tokens;
var right = context.consumeArg().tokens;
var oldMiddle = context.macros.get("|");
var oldMiddleDouble = context.macros.get("\\|");
context.macros.beginGroup();
var midMacro = double => context => {
if (one) {
// Only modify the first instance of | or \|
context.macros.set("|", oldMiddle);
if (middleDouble.length) {
context.macros.set("\\|", oldMiddleDouble);
}
}
var doubled = double;
if (!double && middleDouble.length) {
// Mimic \@ifnextchar
var nextToken = context.future();
if (nextToken.text === "|") {
context.popToken();
doubled = true;
}
}
return {
tokens: doubled ? middleDouble : middle,
numArgs: 0
};
};
context.macros.set("|", midMacro(false));
if (middleDouble.length) {
context.macros.set("\\|", midMacro(true));
}
var arg = context.consumeArg().tokens;
var expanded = context.expandTokens([...right, ...arg, ...left // reversed
]);
context.macros.endGroup();
return {
tokens: expanded.reverse(),
numArgs: 0
};
};
defineMacro("\\bra@ket", braketHelper(false));
defineMacro("\\bra@set", braketHelper(true));
defineMacro("\\Braket", "\\bra@ket{\\left\\langle}" + "{\\,\\middle\\vert\\,}{\\,\\middle\\vert\\,}{\\right\\rangle}");
defineMacro("\\Set", "\\bra@set{\\left\\{\\:}" + "{\\;\\middle\\vert\\;}{\\;\\middle\\Vert\\;}{\\:\\right\\}}");
defineMacro("\\set", "\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}"); // has no support for special || or \|
//////////////////////////////////////////////////////////////////////
// actuarialangle.dtx
defineMacro("\\angln", "{\\angl n}"); // Custom Khan Academy colors, should be moved to an optional package
defineMacro("\\blue", "\\textcolor{##6495ed}{#1}");
defineMacro("\\orange", "\\textcolor{##ffa500}{#1}");
defineMacro("\\pink", "\\textcolor{##ff00af}{#1}");
defineMacro("\\red", "\\textcolor{##df0030}{#1}");
defineMacro("\\green", "\\textcolor{##28ae7b}{#1}");
defineMacro("\\gray", "\\textcolor{gray}{#1}");
defineMacro("\\purple", "\\textcolor{##9d38bd}{#1}");
defineMacro("\\blueA", "\\textcolor{##ccfaff}{#1}");
defineMacro("\\blueB", "\\textcolor{##80f6ff}{#1}");
defineMacro("\\blueC", "\\textcolor{##63d9ea}{#1}");
defineMacro("\\blueD", "\\textcolor{##11accd}{#1}");
defineMacro("\\blueE", "\\textcolor{##0c7f99}{#1}");
defineMacro("\\tealA", "\\textcolor{##94fff5}{#1}");
defineMacro("\\tealB", "\\textcolor{##26edd5}{#1}");
defineMacro("\\tealC", "\\textcolor{##01d1c1}{#1}");
defineMacro("\\tealD", "\\textcolor{##01a995}{#1}");
defineMacro("\\tealE", "\\textcolor{##208170}{#1}");
defineMacro("\\greenA", "\\textcolor{##b6ffb0}{#1}");
defineMacro("\\greenB", "\\textcolor{##8af281}{#1}");
defineMacro("\\greenC", "\\textcolor{##74cf70}{#1}");
defineMacro("\\greenD", "\\textcolor{##1fab54}{#1}");
defineMacro("\\greenE", "\\textcolor{##0d923f}{#1}");
defineMacro("\\goldA", "\\textcolor{##ffd0a9}{#1}");
defineMacro("\\goldB", "\\textcolor{##ffbb71}{#1}");
defineMacro("\\goldC", "\\textcolor{##ff9c39}{#1}");
defineMacro("\\goldD", "\\textcolor{##e07d10}{#1}");
defineMacro("\\goldE", "\\textcolor{##a75a05}{#1}");
defineMacro("\\redA", "\\textcolor{##fca9a9}{#1}");
defineMacro("\\redB", "\\textcolor{##ff8482}{#1}");
defineMacro("\\redC", "\\textcolor{##f9685d}{#1}");
defineMacro("\\redD", "\\textcolor{##e84d39}{#1}");
defineMacro("\\redE", "\\textcolor{##bc2612}{#1}");
defineMacro("\\maroonA", "\\textcolor{##ffbde0}{#1}");
defineMacro("\\maroonB", "\\textcolor{##ff92c6}{#1}");
defineMacro("\\maroonC", "\\textcolor{##ed5fa6}{#1}");
defineMacro("\\maroonD", "\\textcolor{##ca337c}{#1}");
defineMacro("\\maroonE", "\\textcolor{##9e034e}{#1}");
defineMacro("\\purpleA", "\\textcolor{##ddd7ff}{#1}");
defineMacro("\\purpleB", "\\textcolor{##c6b9fc}{#1}");
defineMacro("\\purpleC", "\\textcolor{##aa87ff}{#1}");
defineMacro("\\purpleD", "\\textcolor{##7854ab}{#1}");
defineMacro("\\purpleE", "\\textcolor{##543b78}{#1}");
defineMacro("\\mintA", "\\textcolor{##f5f9e8}{#1}");
defineMacro("\\mintB", "\\textcolor{##edf2df}{#1}");
defineMacro("\\mintC", "\\textcolor{##e0e5cc}{#1}");
defineMacro("\\grayA", "\\textcolor{##f6f7f7}{#1}");
defineMacro("\\grayB", "\\textcolor{##f0f1f2}{#1}");
defineMacro("\\grayC", "\\textcolor{##e3e5e6}{#1}");
defineMacro("\\grayD", "\\textcolor{##d6d8da}{#1}");
defineMacro("\\grayE", "\\textcolor{##babec2}{#1}");
defineMacro("\\grayF", "\\textcolor{##888d93}{#1}");
defineMacro("\\grayG", "\\textcolor{##626569}{#1}");
defineMacro("\\grayH", "\\textcolor{##3b3e40}{#1}");
defineMacro("\\grayI", "\\textcolor{##21242c}{#1}");
defineMacro("\\kaBlue", "\\textcolor{##314453}{#1}");
defineMacro("\\kaGreen", "\\textcolor{##71B307}{#1}");
/**
* This file contains the “gullet” where macros are expanded
* until only non-macro tokens remain.
*/
// List of commands that act like macros but aren't defined as a macro,
// function, or symbol. Used in `isDefined`.
var implicitCommands = {
"^": true,
// Parser.js
"_": true,
// Parser.js
"\\limits": true,
// Parser.js
"\\nolimits": true // Parser.js
};
class MacroExpander {
constructor(input, settings, mode) {
this.settings = void 0;
this.expansionCount = void 0;
this.lexer = void 0;
this.macros = void 0;
this.stack = void 0;
this.mode = void 0;
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) {
this.lexer = new Lexer(input, this.settings);
}
/**
* Switches between "text" and "math" modes.
*/
switchMode(newMode) {
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() {
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() {
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) {
this.stack.push(token);
}
/**
* Append an array of tokens to the token stack.
*/
pushTokens(tokens) {
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) {
var start;
var end;
var 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 (;;) {
var 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) {
// 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.
var tokens = [];
var 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 doesn’t use single spaces as undelimited arguments."
this.consumeSpaces();
}
var start = this.future();
var tok;
var depth = 0;
var 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, delimiters) {
if (delimiters) {
if (delimiters.length !== numArgs + 1) {
throw new ParseError("The length of delimiters doesn't match the number of args!");
}
var delims = delimiters[0];
for (var i = 0; i < delims.length; i++) {
var tok = this.popToken();
if (delims[i] !== tok.text) {
throw new ParseError("Use of the macro doesn't match its definition", tok);
}
}
}
var args = [];
for (var _i = 0; _i < numArgs; _i++) {
args.push(this.consumeArg(delimiters && delimiters[_i + 1]).tokens);
}
return args;
}
/**
* 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) {
var topToken = this.popToken();
var name = topToken.text;
var 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.expansionCount++;
if (this.expansionCount > this.settings.maxExpand) {
throw new ParseError("Too many expansions: infinite loop or " + "need to increase maxExpand setting");
}
var tokens = expansion.tokens;
var 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 (var i = tokens.length - 1; i >= 0; --i) {
var 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() {
this.expandOnce();
return this.future();
}
/**
* Recursively expand first token, then return first non-expandable token.
*/
expandNextToken() {
for (;;) {
if (this.expandOnce() === false) {
// fully expanded
var 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) {
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) {
var output = [];
var oldStackLength = this.stack.length;
this.pushTokens(tokens);
while (this.stack.length > oldStackLength) {
// Expand only expandable tokens
if (this.expandOnce(true) === false) {
// fully expanded
var token = this.stack.pop();
if (token.treatAsRelax) {
// the expansion of \noexpand is the token itself
token.noexpand = false;
token.treatAsRelax = false;
}
output.push(token);
}
}
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) {
var 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) {
var 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) {
var catcode = this.lexer.catcodes[name];
if (catcode != null && catcode !== 13) {
return;
}
}
var expansion = typeof definition === "function" ? definition(this) : definition;
if (typeof expansion === "string") {
var numArgs = 0;
if (expansion.indexOf("#") !== -1) {
var stripped = expansion.replace(/##/g, "");
while (stripped.indexOf("#" + (numArgs + 1)) !== -1) {
++numArgs;
}
}
var bodyLexer = new Lexer(expansion, this.settings);
var tokens = [];
var tok = bodyLexer.lex();
while (tok.text !== "EOF") {
tokens.push(tok);
tok = bodyLexer.lex();
}
tokens.reverse(); // to fit in with stack using push and pop
var 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) {
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) {
var macro = this.macros.get(name);
return macro != null ? typeof macro === "string" || typeof macro === "function" || !macro.unexpandable : functions.hasOwnProperty(name) && !functions[name].primitive;
}
}
// Helpers for Parser.js handling of Unicode (sub|super)script characters.
var unicodeSubRegEx = /^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/;
var 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': 'θ'
});
/* eslint no-constant-condition:0 */
var unicodeAccents = {
"́": {
"text": "\\'",
"math": "\\acute"
},
"̀": {
"text": "\\`",
"math": "\\grave"
},
"̈": {
"text": "\\\"",
"math": "\\ddot"
},
"̃": {
"text": "\\~",
"math": "\\tilde"
},
"̄": {
"text": "\\=",
"math": "\\bar"
},
"̆": {
"text": "\\u",
"math": "\\breve"
},
"̌": {
"text": "\\v",
"math": "\\check"
},
"̂": {
"text": "\\^",
"math": "\\hat"
},
"̇": {
"text": "\\.",
"math": "\\dot"
},
"̊": {
"text": "\\r",
"math": "\\mathring"
},
"̋": {
"text": "\\H"
},
"̧": {
"text": "\\c"
}
};
var unicodeSymbols = {
"á": "á",
"à": "à",
"ä": "ä",
"ǟ": "ǟ",
"ã": "ã",
"ā": "ā",
"ă": "ă",
"ắ": "ắ",
"ằ": "ằ",
"ẵ": "ẵ",
"ǎ": "ǎ",
"â": "â",
"ấ": "ấ",
"ầ": "ầ",
"ẫ": "ẫ",
"ȧ": "ȧ",
"ǡ": "ǡ",
"å": "å",
"ǻ": "ǻ",
"ḃ": "ḃ",
"ć": "ć",
"ḉ": "ḉ",
"č": "č",
"ĉ": "ĉ",
"ċ": "ċ",
"ç": "ç",
"ď": "ď",
"ḋ": "ḋ",
"ḑ": "ḑ",
"é": "é",
"è": "è",
"ë": "ë",
"ẽ": "ẽ",
"ē": "ē",
"ḗ": "ḗ",
"ḕ": "ḕ",
"ĕ": "ĕ",
"ḝ": "ḝ",
"ě": "ě",
"ê": "ê",
"ế": "ế",
"ề": "ề",
"ễ": "ễ",
"ė": "ė",
"ȩ": "ȩ",
"ḟ": "ḟ",
"ǵ": "ǵ",
"ḡ": "ḡ",
"ğ": "ğ",
"ǧ": "ǧ",
"ĝ": "ĝ",
"ġ": "ġ",
"ģ": "ģ",
"ḧ": "ḧ",
"ȟ": "ȟ",
"ĥ": "ĥ",
"ḣ": "ḣ",
"ḩ": "ḩ",
"í": "í",
"ì": "ì",
"ï": "ï",
"ḯ": "ḯ",
"ĩ": "ĩ",
"ī": "ī",
"ĭ": "ĭ",
"ǐ": "ǐ",
"î": "î",
"ǰ": "ǰ",
"ĵ": "ĵ",
"ḱ": "ḱ",
"ǩ": "ǩ",
"ķ": "ķ",
"ĺ": "ĺ",
"ľ": "ľ",
"ļ": "ļ",
"ḿ": "ḿ",
"ṁ": "ṁ",
"ń": "ń",
"ǹ": "ǹ",
"ñ": "ñ",
"ň": "ň",
"ṅ": "ṅ",
"ņ": "ņ",
"ó": "ó",
"ò": "ò",
"ö": "ö",
"ȫ": "ȫ",
"õ": "õ",
"ṍ": "ṍ",
"ṏ": "ṏ",
"ȭ": "ȭ",
"ō": "ō",
"ṓ": "ṓ",
"ṑ": "ṑ",
"ŏ": "ŏ",
"ǒ": "ǒ",
"ô": "ô",
"ố": "ố",
"ồ": "ồ",
"ỗ": "ỗ",
"ȯ": "ȯ",
"ȱ": "ȱ",
"ő": "ő",
"ṕ": "ṕ",
"ṗ": "ṗ",
"ŕ": "ŕ",
"ř": "ř",
"ṙ": "ṙ",
"ŗ": "ŗ",
"ś": "ś",
"ṥ": "ṥ",
"š": "š",
"ṧ": "ṧ",
"ŝ": "ŝ",
"ṡ": "ṡ",
"ş": "ş",
"ẗ": "ẗ",
"ť": "ť",
"ṫ": "ṫ",
"ţ": "ţ",
"ú": "ú",
"ù": "ù",
"ü": "ü",
"ǘ": "ǘ",
"ǜ": "ǜ",
"ǖ": "ǖ",
"ǚ": "ǚ",
"ũ": "ũ",
"ṹ": "ṹ",
"ū": "ū",
"ṻ": "ṻ",
"ŭ": "ŭ",
"ǔ": "ǔ",
"û": "û",
"ů": "ů",
"ű": "ű",
"ṽ": "ṽ",
"ẃ": "ẃ",
"ẁ": "ẁ",
"ẅ": "ẅ",
"ŵ": "ŵ",
"ẇ": "ẇ",
"ẘ": "ẘ",
"ẍ": "ẍ",
"ẋ": "ẋ",
"ý": "ý",
"ỳ": "ỳ",
"ÿ": "ÿ",
"ỹ": "ỹ",
"ȳ": "ȳ",
"ŷ": "ŷ",
"ẏ": "ẏ",
"ẙ": "ẙ",
"ź": "ź",
"ž": "ž",
"ẑ": "ẑ",
"ż": "ż",
"Á": "Á",
"À": "À",
"Ä": "Ä",
"Ǟ": "Ǟ",
"Ã": "Ã",
"Ā": "Ā",
"Ă": "Ă",
"Ắ": "Ắ",
"Ằ": "Ằ",
"Ẵ": "Ẵ",
"Ǎ": "Ǎ",
"Â": "Â",
"Ấ": "Ấ",
"Ầ": "Ầ",
"Ẫ": "Ẫ",
"Ȧ": "Ȧ",
"Ǡ": "Ǡ",
"Å": "Å",
"Ǻ": "Ǻ",
"Ḃ": "Ḃ",
"Ć": "Ć",
"Ḉ": "Ḉ",
"Č": "Č",
"Ĉ": "Ĉ",
"Ċ": "Ċ",
"Ç": "Ç",
"Ď": "Ď",
"Ḋ": "Ḋ",
"Ḑ": "Ḑ",
"É": "É",
"È": "È",
"Ë": "Ë",
"Ẽ": "Ẽ",
"Ē": "Ē",
"Ḗ": "Ḗ",
"Ḕ": "Ḕ",
"Ĕ": "Ĕ",
"Ḝ": "Ḝ",
"Ě": "Ě",
"Ê": "Ê",
"Ế": "Ế",
"Ề": "Ề",
"Ễ": "Ễ",
"Ė": "Ė",
"Ȩ": "Ȩ",
"Ḟ": "Ḟ",
"Ǵ": "Ǵ",
"Ḡ": "Ḡ",
"Ğ": "Ğ",
"Ǧ": "Ǧ",
"Ĝ": "Ĝ",
"Ġ": "Ġ",
"Ģ": "Ģ",
"Ḧ": "Ḧ",
"Ȟ": "Ȟ",
"Ĥ": "Ĥ",
"Ḣ": "Ḣ",
"Ḩ": "Ḩ",
"Í": "Í",
"Ì": "Ì",
"Ï": "Ï",
"Ḯ": "Ḯ",
"Ĩ": "Ĩ",
"Ī": "Ī",
"Ĭ": "Ĭ",
"Ǐ": "Ǐ",
"Î": "Î",
"İ": "İ",
"Ĵ": "Ĵ",
"Ḱ": "Ḱ",
"Ǩ": "Ǩ",
"Ķ": "Ķ",
"Ĺ": "Ĺ",
"Ľ": "Ľ",
"Ļ": "Ļ",
"Ḿ": "Ḿ",
"Ṁ": "Ṁ",
"Ń": "Ń",
"Ǹ": "Ǹ",
"Ñ": "Ñ",
"Ň": "Ň",
"Ṅ": "Ṅ",
"Ņ": "Ņ",
"Ó": "Ó",
"Ò": "Ò",
"Ö": "Ö",
"Ȫ": "Ȫ",
"Õ": "Õ",
"Ṍ": "Ṍ",
"Ṏ": "Ṏ",
"Ȭ": "Ȭ",
"Ō": "Ō",
"Ṓ": "Ṓ",
"Ṑ": "Ṑ",
"Ŏ": "Ŏ",
"Ǒ": "Ǒ",
"Ô": "Ô",
"Ố": "Ố",
"Ồ": "Ồ",
"Ỗ": "Ỗ",
"Ȯ": "Ȯ",
"Ȱ": "Ȱ",
"Ő": "Ő",
"Ṕ": "Ṕ",
"Ṗ": "Ṗ",
"Ŕ": "Ŕ",
"Ř": "Ř",
"Ṙ": "Ṙ",
"Ŗ": "Ŗ",
"Ś": "Ś",
"Ṥ": "Ṥ",
"Š": "Š",
"Ṧ": "Ṧ",
"Ŝ": "Ŝ",
"Ṡ": "Ṡ",
"Ş": "Ş",
"Ť": "Ť",
"Ṫ": "Ṫ",
"Ţ": "Ţ",
"Ú": "Ú",
"Ù": "Ù",
"Ü": "Ü",
"Ǘ": "Ǘ",
"Ǜ": "Ǜ",
"Ǖ": "Ǖ",
"Ǚ": "Ǚ",
"Ũ": "Ũ",
"Ṹ": "Ṹ",
"Ū": "Ū",
"Ṻ": "Ṻ",
"Ŭ": "Ŭ",
"Ǔ": "Ǔ",
"Û": "Û",
"Ů": "Ů",
"Ű": "Ű",
"Ṽ": "Ṽ",
"Ẃ": "Ẃ",
"Ẁ": "Ẁ",
"Ẅ": "Ẅ",
"Ŵ": "Ŵ",
"Ẇ": "Ẇ",
"Ẍ": "Ẍ",
"Ẋ": "Ẋ",
"Ý": "Ý",
"Ỳ": "Ỳ",
"Ÿ": "Ÿ",
"Ỹ": "Ỹ",
"Ȳ": "Ȳ",
"Ŷ": "Ŷ",
"Ẏ": "Ẏ",
"Ź": "Ź",
"Ž": "Ž",
"Ẑ": "Ẑ",
"Ż": "Ż",
"ά": "ά",
"ὰ": "ὰ",
"ᾱ": "ᾱ",
"ᾰ": "ᾰ",
"έ": "έ",
"ὲ": "ὲ",
"ή": "ή",
"ὴ": "ὴ",
"ί": "ί",
"ὶ": "ὶ",
"ϊ": "ϊ",
"ΐ": "ΐ",
"ῒ": "ῒ",
"ῑ": "ῑ",
"ῐ": "ῐ",
"ό": "ό",
"ὸ": "ὸ",
"ύ": "ύ",
"ὺ": "ὺ",
"ϋ": "ϋ",
"ΰ": "ΰ",
"ῢ": "ῢ",
"ῡ": "ῡ",
"ῠ": "ῠ",
"ώ": "ώ",
"ὼ": "ὼ",
"Ύ": "Ύ",
"Ὺ": "Ὺ",
"Ϋ": "Ϋ",
"Ῡ": "Ῡ",
"Ῠ": "Ῠ",
"Ώ": "Ώ",
"Ὼ": "Ὼ"
};
/**
* This file contains the parser used to parse out a TeX expression from the
* input. Since TeX isn't context-free, standard parsers don't work particularly
* well.
*
* The strategy of this parser is as such:
*
* The main functions (the `.parse...` ones) take a position in the current
* parse string to parse tokens from. The lexer (found in Lexer.js, stored at
* this.gullet.lexer) also supports pulling out tokens at arbitrary places. When
* individual tokens are needed at a position, the lexer is called to pull out a
* token, which is then used.
*
* The parser has a property called "mode" indicating the mode that
* the parser is currently in. Currently it has to be one of "math" or
* "text", which denotes whether the current environment is a math-y
* one or a text-y one (e.g. inside \text). Currently, this serves to
* limit the functions which can be used in text mode.
*
* The main functions then return an object which contains the useful data that
* was parsed at its given point, and a new position at the end of the parsed
* data. The main functions can call each other and continue the parsing by
* using the returned position as a new starting point.
*
* There are also extra `.handle...` functions, which pull out some reused
* functionality into self-contained functions.
*
* The functions return ParseNodes.
*/
class Parser {
constructor(input, settings) {
this.mode = void 0;
this.gullet = void 0;
this.settings = void 0;
this.leftrightDepth = void 0;
this.nextToken = void 0;
// Start in math mode
this.mode = "math"; // Create a new macro expander (gullet) and (indirectly via that) also a
// new lexer (mouth) for this parser (stomach, in the language of TeX)
this.gullet = new MacroExpander(input, settings, this.mode); // Store the settings for use in parsing
this.settings = settings; // Count leftright depth (for \middle errors)
this.leftrightDepth = 0;
}
/**
* Checks a result to make sure it has the right type, and throws an
* appropriate error otherwise.
*/
expect(text, consume) {
if (consume === void 0) {
consume = true;
}
if (this.fetch().text !== text) {
throw new ParseError("Expected '" + text + "', got '" + this.fetch().text + "'", this.fetch());
}
if (consume) {
this.consume();
}
}
/**
* Discards the current lookahead token, considering it consumed.
*/
consume() {
this.nextToken = null;
}
/**
* Return the current lookahead token, or if there isn't one (at the
* beginning, or if the previous lookahead token was consume()d),
* fetch the next token as the new lookahead token and return it.
*/
fetch() {
if (this.nextToken == null) {
this.nextToken = this.gullet.expandNextToken();
}
return this.nextToken;
}
/**
* Switches between "text" and "math" modes.
*/
switchMode(newMode) {
this.mode = newMode;
this.gullet.switchMode(newMode);
}
/**
* Main parsing function, which parses an entire input.
*/
parse() {
if (!this.settings.globalGroup) {
// Create a group namespace for the math expression.
// (LaTeX creates a new group for every $...$, $$...$$, \[...\].)
this.gullet.beginGroup();
} // Use old \color behavior (same as LaTeX's \textcolor) if requested.
// We do this within the group for the math expression, so it doesn't
// pollute settings.macros.
if (this.settings.colorIsTextColor) {
this.gullet.macros.set("\\color", "\\textcolor");
}
try {
// Try to parse the input
var parse = this.parseExpression(false); // If we succeeded, make sure there's an EOF at the end
this.expect("EOF"); // End the group namespace for the expression
if (!this.settings.globalGroup) {
this.gullet.endGroup();
}
return parse; // Close any leftover groups in case of a parse error.
} finally {
this.gullet.endGroups();
}
}
/**
* Fully parse a separate sequence of tokens as a separate job.
* Tokens should be specified in reverse order, as in a MacroDefinition.
*/
subparse(tokens) {
// Save the next token from the current job.
var oldToken = this.nextToken;
this.consume(); // Run the new job, terminating it with an excess '}'
this.gullet.pushToken(new Token("}"));
this.gullet.pushTokens(tokens);
var parse = this.parseExpression(false);
this.expect("}"); // Restore the next token from the current job.
this.nextToken = oldToken;
return parse;
}
/**
* Parses an "expression", which is a list of atoms.
*
* `breakOnInfix`: Should the parsing stop when we hit infix nodes? This
* happens when functions have higher precedence han infix
* nodes in implicit parses.
*
* `breakOnTokenText`: The text of the token that the expression should end
* with, or `null` if something else should end the
* expression.
*/
parseExpression(breakOnInfix, breakOnTokenText) {
var body = []; // Keep adding atoms to the body until we can't parse any more atoms (either
// we reached the end, a }, or a \right)
while (true) {
// Ignore spaces in math mode
if (this.mode === "math") {
this.consumeSpaces();
}
var lex = this.fetch();
if (Parser.endOfExpression.indexOf(lex.text) !== -1) {
break;
}
if (breakOnTokenText && lex.text === breakOnTokenText) {
break;
}
if (breakOnInfix && functions[lex.text] && functions[lex.text].infix) {
break;
}
var atom = this.parseAtom(breakOnTokenText);
if (!atom) {
break;
} else if (atom.type === "internal") {
continue;
}
body.push(atom);
}
if (this.mode === "text") {
this.formLigatures(body);
}
return this.handleInfixNodes(body);
}
/**
* Rewrites infix operators such as \over with corresponding commands such
* as \frac.
*
* There can only be one infix operator per group. If there's more than one
* then the expression is ambiguous. This can be resolved by adding {}.
*/
handleInfixNodes(body) {
var overIndex = -1;
var funcName;
for (var i = 0; i < body.length; i++) {
if (body[i].type === "infix") {
if (overIndex !== -1) {
throw new ParseError("only one infix operator per group", body[i].token);
}
overIndex = i;
funcName = body[i].replaceWith;
}
}
if (overIndex !== -1 && funcName) {
var numerNode;
var denomNode;
var numerBody = body.slice(0, overIndex);
var denomBody = body.slice(overIndex + 1);
if (numerBody.length === 1 && numerBody[0].type === "ordgroup") {
numerNode = numerBody[0];
} else {
numerNode = {
type: "ordgroup",
mode: this.mode,
body: numerBody
};
}
if (denomBody.length === 1 && denomBody[0].type === "ordgroup") {
denomNode = denomBody[0];
} else {
denomNode = {
type: "ordgroup",
mode: this.mode,
body: denomBody
};
}
var node;
if (funcName === "\\\\abovefrac") {
node = this.callFunction(funcName, [numerNode, body[overIndex], denomNode], []);
} else {
node = this.callFunction(funcName, [numerNode, denomNode], []);
}
return [node];
} else {
return body;
}
}
/**
* Handle a subscript or superscript with nice errors.
*/
handleSupSubscript(name // For error reporting.
) {
var symbolToken = this.fetch();
var symbol = symbolToken.text;
this.consume();
this.consumeSpaces(); // ignore spaces before sup/subscript argument
var group = this.parseGroup(name);
if (!group) {
throw new ParseError("Expected group after '" + symbol + "'", symbolToken);
}
return group;
}
/**
* Converts the textual input of an unsupported command into a text node
* contained within a color node whose color is determined by errorColor
*/
formatUnsupportedCmd(text) {
var textordArray = [];
for (var i = 0; i < text.length; i++) {
textordArray.push({
type: "textord",
mode: "text",
text: text[i]
});
}
var textNode = {
type: "text",
mode: this.mode,
body: textordArray
};
var colorNode = {
type: "color",
mode: this.mode,
color: this.settings.errorColor,
body: [textNode]
};
return colorNode;
}
/**
* Parses a group with optional super/subscripts.
*/
parseAtom(breakOnTokenText) {
// The body of an atom is an implicit group, so that things like
// \left(x\right)^2 work correctly.
var base = this.parseGroup("atom", breakOnTokenText); // In text mode, we don't have superscripts or subscripts
if (this.mode === "text") {
return base;
} // Note that base may be empty (i.e. null) at this point.
var superscript;
var subscript;
while (true) {
// Guaranteed in math mode, so eat any spaces first.
this.consumeSpaces(); // Lex the first token
var lex = this.fetch();
if (lex.text === "\\limits" || lex.text === "\\nolimits") {
// We got a limit control
if (base && base.type === "op") {
var limits = lex.text === "\\limits";
base.limits = limits;
base.alwaysHandleSupSub = true;
} else if (base && base.type === "operatorname") {
if (base.alwaysHandleSupSub) {
base.limits = lex.text === "\\limits";
}
} else {
throw new ParseError("Limit controls must follow a math operator", lex);
}
this.consume();
} else if (lex.text === "^") {
// We got a superscript start
if (superscript) {
throw new ParseError("Double superscript", lex);
}
superscript = this.handleSupSubscript("superscript");
} else if (lex.text === "_") {
// We got a subscript start
if (subscript) {
throw new ParseError("Double subscript", lex);
}
subscript = this.handleSupSubscript("subscript");
} else if (lex.text === "'") {
// We got a prime
if (superscript) {
throw new ParseError("Double superscript", lex);
}
var prime = {
type: "textord",
mode: this.mode,
text: "\\prime"
}; // Many primes can be grouped together, so we handle this here
var primes = [prime];
this.consume(); // Keep lexing tokens until we get something that's not a prime
while (this.fetch().text === "'") {
// For each one, add another prime to the list
primes.push(prime);
this.consume();
} // If there's a superscript following the primes, combine that
// superscript in with the primes.
if (this.fetch().text === "^") {
primes.push(this.handleSupSubscript("superscript"));
} // Put everything into an ordgroup as the superscript
superscript = {
type: "ordgroup",
mode: this.mode,
body: primes
};
} else if (uSubsAndSups[lex.text]) {
// A Unicode subscript or superscript character.
// We treat these similarly to the unicode-math package.
// So we render a string of Unicode (sub|super)scripts the
// same as a (sub|super)script of regular characters.
var str = uSubsAndSups[lex.text];
var isSub = unicodeSubRegEx.test(lex.text);
this.consume(); // Continue fetching tokens to fill out the string.
while (true) {
var token = this.fetch().text;
if (!uSubsAndSups[token]) {
break;
}
if (unicodeSubRegEx.test(token) !== isSub) {
break;
}
this.consume();
str += uSubsAndSups[token];
} // Now create a (sub|super)script.
var body = new Parser(str, this.settings).parse();
if (isSub) {
subscript = {
type: "ordgroup",
mode: "math",
body
};
} else {
superscript = {
type: "ordgroup",
mode: "math",
body
};
}
} else {
// If it wasn't ^, _, or ', stop parsing super/subscripts
break;
}
} // Base must be set if superscript or subscript are set per logic above,
// but need to check here for type check to pass.
if (superscript || subscript) {
// If we got either a superscript or subscript, create a supsub
return {
type: "supsub",
mode: this.mode,
base: base,
sup: superscript,
sub: subscript
};
} else {
// Otherwise return the original body
return base;
}
}
/**
* Parses an entire function, including its base and all of its arguments.
*/
parseFunction(breakOnTokenText, name // For determining its context
) {
var token = this.fetch();
var func = token.text;
var funcData = functions[func];
if (!funcData) {
return null;
}
this.consume(); // consume command token
if (name && name !== "atom" && !funcData.allowedInArgument) {
throw new ParseError("Got function '" + func + "' with no arguments" + (name ? " as " + name : ""), token);
} else if (this.mode === "text" && !funcData.allowedInText) {
throw new ParseError("Can't use function '" + func + "' in text mode", token);
} else if (this.mode === "math" && funcData.allowedInMath === false) {
throw new ParseError("Can't use function '" + func + "' in math mode", token);
}
var {
args,
optArgs
} = this.parseArguments(func, funcData);
return this.callFunction(func, args, optArgs, token, breakOnTokenText);
}
/**
* Call a function handler with a suitable context and arguments.
*/
callFunction(name, args, optArgs, token, breakOnTokenText) {
var context = {
funcName: name,
parser: this,
token,
breakOnTokenText
};
var func = functions[name];
if (func && func.handler) {
return func.handler(context, args, optArgs);
} else {
throw new ParseError("No function handler for " + name);
}
}
/**
* Parses the arguments of a function or environment
*/
parseArguments(func, // Should look like "\name" or "\begin{name}".
funcData) {
var totalArgs = funcData.numArgs + funcData.numOptionalArgs;
if (totalArgs === 0) {
return {
args: [],
optArgs: []
};
}
var args = [];
var optArgs = [];
for (var i = 0; i < totalArgs; i++) {
var argType = funcData.argTypes && funcData.argTypes[i];
var isOptional = i < funcData.numOptionalArgs;
if (funcData.primitive && argType == null || // \sqrt expands into primitive if optional argument doesn't exist
funcData.type === "sqrt" && i === 1 && optArgs[0] == null) {
argType = "primitive";
}
var arg = this.parseGroupOfType("argument to '" + func + "'", argType, isOptional);
if (isOptional) {
optArgs.push(arg);
} else if (arg != null) {
args.push(arg);
} else {
// should be unreachable
throw new ParseError("Null argument, please report this as a bug");
}
}
return {
args,
optArgs
};
}
/**
* Parses a group when the mode is changing.
*/
parseGroupOfType(name, type, optional) {
switch (type) {
case "color":
return this.parseColorGroup(optional);
case "size":
return this.parseSizeGroup(optional);
case "url":
return this.parseUrlGroup(optional);
case "math":
case "text":
return this.parseArgumentGroup(optional, type);
case "hbox":
{
// hbox argument type wraps the argument in the equivalent of
// \hbox, which is like \text but switching to \textstyle size.
var group = this.parseArgumentGroup(optional, "text");
return group != null ? {
type: "styling",
mode: group.mode,
body: [group],
style: "text" // simulate \textstyle
} : null;
}
case "raw":
{
var token = this.parseStringGroup("raw", optional);
return token != null ? {
type: "raw",
mode: "text",
string: token.text
} : null;
}
case "primitive":
{
if (optional) {
throw new ParseError("A primitive argument cannot be optional");
}
var _group = this.parseGroup(name);
if (_group == null) {
throw new ParseError("Expected group as " + name, this.fetch());
}
return _group;
}
case "original":
case null:
case undefined:
return this.parseArgumentGroup(optional);
default:
throw new ParseError("Unknown group type as " + name, this.fetch());
}
}
/**
* Discard any space tokens, fetching the next non-space token.
*/
consumeSpaces() {
while (this.fetch().text === " ") {
this.consume();
}
}
/**
* Parses a group, essentially returning the string formed by the
* brace-enclosed tokens plus some position information.
*/
parseStringGroup(modeName, // Used to describe the mode in error messages.
optional) {
var argToken = this.gullet.scanArgument(optional);
if (argToken == null) {
return null;
}
var str = "";
var nextToken;
while ((nextToken = this.fetch()).text !== "EOF") {
str += nextToken.text;
this.consume();
}
this.consume(); // consume the end of the argument
argToken.text = str;
return argToken;
}
/**
* Parses a regex-delimited group: the largest sequence of tokens
* whose concatenated strings match `regex`. Returns the string
* formed by the tokens plus some position information.
*/
parseRegexGroup(regex, modeName // Used to describe the mode in error messages.
) {
var firstToken = this.fetch();
var lastToken = firstToken;
var str = "";
var nextToken;
while ((nextToken = this.fetch()).text !== "EOF" && regex.test(str + nextToken.text)) {
lastToken = nextToken;
str += lastToken.text;
this.consume();
}
if (str === "") {
throw new ParseError("Invalid " + modeName + ": '" + firstToken.text + "'", firstToken);
}
return firstToken.range(lastToken, str);
}
/**
* Parses a color description.
*/
parseColorGroup(optional) {
var res = this.parseStringGroup("color", optional);
if (res == null) {
return null;
}
var match = /^(#[a-f0-9]{3}|#?[a-f0-9]{6}|[a-z]+)$/i.exec(res.text);
if (!match) {
throw new ParseError("Invalid color: '" + res.text + "'", res);
}
var color = match[0];
if (/^[0-9a-f]{6}$/i.test(color)) {
// We allow a 6-digit HTML color spec without a leading "#".
// This follows the xcolor package's HTML color model.
// Predefined color names are all missed by this RegEx pattern.
color = "#" + color;
}
return {
type: "color-token",
mode: this.mode,
color
};
}
/**
* Parses a size specification, consisting of magnitude and unit.
*/
parseSizeGroup(optional) {
var res;
var isBlank = false; // don't expand before parseStringGroup
this.gullet.consumeSpaces();
if (!optional && this.gullet.future().text !== "{") {
res = this.parseRegexGroup(/^[-+]? *(?:$|\d+|\d+\.\d*|\.\d*) *[a-z]{0,2} *$/, "size");
} else {
res = this.parseStringGroup("size", optional);
}
if (!res) {
return null;
}
if (!optional && res.text.length === 0) {
// Because we've tested for what is !optional, this block won't
// affect \kern, \hspace, etc. It will capture the mandatory arguments
// to \genfrac and \above.
res.text = "0pt"; // Enable \above{}
isBlank = true; // This is here specifically for \genfrac
}
var match = /([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(res.text);
if (!match) {
throw new ParseError("Invalid size: '" + res.text + "'", res);
}
var data = {
number: +(match[1] + match[2]),
// sign + magnitude, cast to number
unit: match[3]
};
if (!validUnit(data)) {
throw new ParseError("Invalid unit: '" + data.unit + "'", res);
}
return {
type: "size",
mode: this.mode,
value: data,
isBlank
};
}
/**
* Parses an URL, checking escaped letters and allowed protocols,
* and setting the catcode of % as an active character (as in \hyperref).
*/
parseUrlGroup(optional) {
this.gullet.lexer.setCatcode("%", 13); // active character
this.gullet.lexer.setCatcode("~", 12); // other character
var res = this.parseStringGroup("url", optional);
this.gullet.lexer.setCatcode("%", 14); // comment character
this.gullet.lexer.setCatcode("~", 13); // active character
if (res == null) {
return null;
} // hyperref package allows backslashes alone in href, but doesn't
// generate valid links in such cases; we interpret this as
// "undefined" behaviour, and keep them as-is. Some browser will
// replace backslashes with forward slashes.
var url = res.text.replace(/\\([#$%&~_^{}])/g, '$1');
return {
type: "url",
mode: this.mode,
url
};
}
/**
* Parses an argument with the mode specified.
*/
parseArgumentGroup(optional, mode) {
var argToken = this.gullet.scanArgument(optional);
if (argToken == null) {
return null;
}
var outerMode = this.mode;
if (mode) {
// Switch to specified mode
this.switchMode(mode);
}
this.gullet.beginGroup();
var expression = this.parseExpression(false, "EOF"); // TODO: find an alternative way to denote the end
this.expect("EOF"); // expect the end of the argument
this.gullet.endGroup();
var result = {
type: "ordgroup",
mode: this.mode,
loc: argToken.loc,
body: expression
};
if (mode) {
// Switch mode back
this.switchMode(outerMode);
}
return result;
}
/**
* Parses an ordinary group, which is either a single nucleus (like "x")
* or an expression in braces (like "{x+y}") or an implicit group, a group
* that starts at the current position, and ends right before a higher explicit
* group ends, or at EOF.
*/
parseGroup(name, // For error reporting.
breakOnTokenText) {
var firstToken = this.fetch();
var text = firstToken.text;
var result; // Try to parse an open brace or \begingroup
if (text === "{" || text === "\\begingroup") {
this.consume();
var groupEnd = text === "{" ? "}" : "\\endgroup";
this.gullet.beginGroup(); // If we get a brace, parse an expression
var expression = this.parseExpression(false, groupEnd);
var lastToken = this.fetch();
this.expect(groupEnd); // Check that we got a matching closing brace
this.gullet.endGroup();
result = {
type: "ordgroup",
mode: this.mode,
loc: SourceLocation.range(firstToken, lastToken),
body: expression,
// A group formed by \begingroup...\endgroup is a semi-simple group
// which doesn't affect spacing in math mode, i.e., is transparent.
// https://tex.stackexchange.com/questions/1930/when-should-one-
// use-begingroup-instead-of-bgroup
semisimple: text === "\\begingroup" || undefined
};
} else {
// If there exists a function with this name, parse the function.
// Otherwise, just return a nucleus
result = this.parseFunction(breakOnTokenText, name) || this.parseSymbol();
if (result == null && text[0] === "\\" && !implicitCommands.hasOwnProperty(text)) {
if (this.settings.throwOnError) {
throw new ParseError("Undefined control sequence: " + text, firstToken);
}
result = this.formatUnsupportedCmd(text);
this.consume();
}
}
return result;
}
/**
* Form ligature-like combinations of characters for text mode.
* This includes inputs like "--", "---", "``" and "''".
* The result will simply replace multiple textord nodes with a single
* character in each value by a single textord node having multiple
* characters in its value. The representation is still ASCII source.
* The group will be modified in place.
*/
formLigatures(group) {
var n = group.length - 1;
for (var i = 0; i < n; ++i) {
var a = group[i]; // $FlowFixMe: Not every node type has a `text` property.
var v = a.text;
if (v === "-" && group[i + 1].text === "-") {
if (i + 1 < n && group[i + 2].text === "-") {
group.splice(i, 3, {
type: "textord",
mode: "text",
loc: SourceLocation.range(a, group[i + 2]),
text: "---"
});
n -= 2;
} else {
group.splice(i, 2, {
type: "textord",
mode: "text",
loc: SourceLocation.range(a, group[i + 1]),
text: "--"
});
n -= 1;
}
}
if ((v === "'" || v === "`") && group[i + 1].text === v) {
group.splice(i, 2, {
type: "textord",
mode: "text",
loc: SourceLocation.range(a, group[i + 1]),
text: v + v
});
n -= 1;
}
}
}
/**
* Parse a single symbol out of the string. Here, we handle single character
* symbols and special functions like \verb.
*/
parseSymbol() {
var nucleus = this.fetch();
var text = nucleus.text;
if (/^\\verb[^a-zA-Z]/.test(text)) {
this.consume();
var arg = text.slice(5);
var star = arg.charAt(0) === "*";
if (star) {
arg = arg.slice(1);
} // Lexer's tokenRegex is constructed to always have matching
// first/last characters.
if (arg.length < 2 || arg.charAt(0) !== arg.slice(-1)) {
throw new ParseError("\\verb assertion failed --\n please report what input caused this bug");
}
arg = arg.slice(1, -1); // remove first and last char
return {
type: "verb",
mode: "text",
body: arg,
star
};
} // At this point, we should have a symbol, possibly with accents.
// First expand any accented base symbol according to unicodeSymbols.
if (unicodeSymbols.hasOwnProperty(text[0]) && !symbols[this.mode][text[0]]) {
// This behavior is not strict (XeTeX-compatible) in math mode.
if (this.settings.strict && this.mode === "math") {
this.settings.reportNonstrict("unicodeTextInMathMode", "Accented Unicode text character \"" + text[0] + "\" used in " + "math mode", nucleus);
}
text = unicodeSymbols[text[0]] + text.slice(1);
} // Strip off any combining characters
var match = combiningDiacriticalMarksEndRegex.exec(text);
if (match) {
text = text.substring(0, match.index);
if (text === 'i') {
text = '\u0131'; // dotless i, in math and text mode
} else if (text === 'j') {
text = '\u0237'; // dotless j, in math and text mode
}
} // Recognize base symbol
var symbol;
if (symbols[this.mode][text]) {
if (this.settings.strict && this.mode === 'math' && extraLatin.indexOf(text) >= 0) {
this.settings.reportNonstrict("unicodeTextInMathMode", "Latin-1/Unicode text character \"" + text[0] + "\" used in " + "math mode", nucleus);
}
var group = symbols[this.mode][text].group;
var loc = SourceLocation.range(nucleus);
var s;
if (ATOMS.hasOwnProperty(group)) {
// $FlowFixMe
var family = group;
s = {
type: "atom",
mode: this.mode,
family,
loc,
text
};
} else {
// $FlowFixMe
s = {
type: group,
mode: this.mode,
loc,
text
};
} // $FlowFixMe
symbol = s;
} else if (text.charCodeAt(0) >= 0x80) {
// no symbol for e.g. ^
if (this.settings.strict) {
if (!supportedCodepoint(text.charCodeAt(0))) {
this.settings.reportNonstrict("unknownSymbol", "Unrecognized Unicode character \"" + text[0] + "\"" + (" (" + text.charCodeAt(0) + ")"), nucleus);
} else if (this.mode === "math") {
this.settings.reportNonstrict("unicodeTextInMathMode", "Unicode text character \"" + text[0] + "\" used in math mode", nucleus);
}
} // All nonmathematical Unicode characters are rendered as if they
// are in text mode (wrapped in \text) because that's what it
// takes to render them in LaTeX. Setting `mode: this.mode` is
// another natural choice (the user requested math mode), but
// this makes it more difficult for getCharacterMetrics() to
// distinguish Unicode characters without metrics and those for
// which we want to simulate the letter M.
symbol = {
type: "textord",
mode: "text",
loc: SourceLocation.range(nucleus),
text
};
} else {
return null; // EOF, ^, _, {, }, etc.
}
this.consume(); // Transform combining characters into accents
if (match) {
for (var i = 0; i < match[0].length; i++) {
var accent = match[0][i];
if (!unicodeAccents[accent]) {
throw new ParseError("Unknown accent ' " + accent + "'", nucleus);
}
var command = unicodeAccents[accent][this.mode] || unicodeAccents[accent].text;
if (!command) {
throw new ParseError("Accent " + accent + " unsupported in " + this.mode + " mode", nucleus);
}
symbol = {
type: "accent",
mode: this.mode,
loc: SourceLocation.range(nucleus),
label: command,
isStretchy: false,
isShifty: true,
// $FlowFixMe
base: symbol
};
}
} // $FlowFixMe
return symbol;
}
}
Parser.endOfExpression = ["}", "\\endgroup", "\\end", "\\right", "&"];
/**
* Provides a single function for parsing an expression using a Parser
* TODO(emily): Remove this
*/
/**
* Parses an expression using a Parser, then returns the parsed result.
*/
var parseTree = function parseTree(toParse, settings) {
if (!(typeof toParse === 'string' || toParse instanceof String)) {
throw new TypeError('KaTeX can only parse string typed expression');
}
var parser = new Parser(toParse, settings); // Blank out any \df@tag to avoid spurious "Duplicate \tag" errors
delete parser.gullet.macros.current["\\df@tag"];
var 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;
};
/* eslint no-console:0 */
/**
* Parse and build an expression, and place that expression in the DOM node
* given.
*/
var render = function render(expression, baseNode, options) {
baseNode.textContent = "";
var node = renderToDomTree(expression, options).toNode();
baseNode.appendChild(node);
}; // KaTeX's styles don't work properly in quirks mode. Print out an error, and
// disable rendering.
if (typeof document !== "undefined") {
if (document.compatMode !== "CSS1Compat") {
typeof console !== "undefined" && console.warn("Warning: KaTeX doesn't work in quirks mode. Make sure your " + "website has a suitable doctype.");
render = function render() {
throw new ParseError("KaTeX doesn't work in quirks mode.");
};
}
}
/**
* Parse and build an expression, and return the markup for that.
*/
var renderToString = function renderToString(expression, options) {
var markup = renderToDomTree(expression, options).toMarkup();
return markup;
};
/**
* Parse an expression and return the parse tree.
*/
var generateParseTree = function generateParseTree(expression, options) {
var settings = new Settings(options);
return parseTree(expression, settings);
};
/**
* If the given error is a KaTeX ParseError and options.throwOnError is false,
* renders the invalid LaTeX as a span with hover title giving the KaTeX
* error message. Otherwise, simply throws the error.
*/
var renderError = function renderError(error, expression, options) {
if (options.throwOnError || !(error instanceof ParseError)) {
throw error;
}
var node = buildCommon.makeSpan(["katex-error"], [new SymbolNode(expression)]);
node.setAttribute("title", error.toString());
node.setAttribute("style", "color:" + options.errorColor);
return node;
};
/**
* Generates and returns the katex build tree. This is used for advanced
* use cases (like rendering to custom output).
*/
var renderToDomTree = function renderToDomTree(expression, options) {
var settings = new Settings(options);
try {
var tree = parseTree(expression, settings);
return buildTree(tree, expression, settings);
} catch (error) {
return renderError(error, expression, settings);
}
};
/**
* Generates and returns the katex build tree, with just HTML (no MathML).
* This is used for advanced use cases (like rendering to custom output).
*/
var renderToHTMLTree = function renderToHTMLTree(expression, options) {
var settings = new Settings(options);
try {
var tree = parseTree(expression, settings);
return buildHTMLTree(tree, expression, settings);
} catch (error) {
return renderError(error, expression, settings);
}
};
var katex = {
/**
* Current KaTeX version
*/
version: "0.16.9",
/**
* Renders the given LaTeX into an HTML+MathML combination, and adds
* it as a child to the specified DOM node.
*/
render,
/**
* Renders the given LaTeX into an HTML+MathML combination string,
* for sending to the client.
*/
renderToString,
/**
* KaTeX error, usually during parsing.
*/
ParseError,
/**
* The shema of Settings
*/
SETTINGS_SCHEMA,
/**
* Parses the given LaTeX into KaTeX's internal parse tree structure,
* without rendering to HTML or MathML.
*
* NOTE: This method is not currently recommended for public use.
* The internal tree representation is unstable and is very likely
* to change. Use at your own risk.
*/
__parse: generateParseTree,
/**
* Renders the given LaTeX into an HTML+MathML internal DOM tree
* representation, without flattening that representation to a string.
*
* NOTE: This method is not currently recommended for public use.
* The internal tree representation is unstable and is very likely
* to change. Use at your own risk.
*/
__renderToDomTree: renderToDomTree,
/**
* Renders the given LaTeX into an HTML internal DOM tree representation,
* without MathML and without flattening that representation to a string.
*
* NOTE: This method is not currently recommended for public use.
* The internal tree representation is unstable and is very likely
* to change. Use at your own risk.
*/
__renderToHTMLTree: renderToHTMLTree,
/**
* extends internal font metrics object with a new object
* each key in the new object represents a font name
*/
__setFontMetrics: setFontMetrics,
/**
* adds a new symbol to builtin symbols table
*/
__defineSymbol: defineSymbol,
/**
* adds a new function to builtin function list,
* which directly produce parse tree elements
* and have their own html/mathml builders
*/
__defineFunction: defineFunction,
/**
* adds a new macro to builtin macro list
*/
__defineMacro: defineMacro,
/**
* Expose the dom tree node types, which can be useful for type checking nodes.
*
* NOTE: This method is not currently recommended for public use.
* The internal tree representation is unstable and is very likely
* to change. Use at your own risk.
*/
__domTree: {
Span,
Anchor,
SymbolNode,
SvgNode,
PathNode,
LineNode
}
};
/***/ })
}]);
|
07akioni/rspack-treeshaking-issue-reprod
| 0
|
JavaScript
|
07akioni
|
07akioni
|
DeepSeek
|
|
mkdocs_argparse/__init__.py
|
Python
|
import importlib
import re
from typing import Callable, Iterable, Iterator
from markdown.extensions import Extension
from markdown.preprocessors import Preprocessor
import argparse
import json
import mistune
__all__ = ["MKArgparseExtension", "MkDocsArgparseException", "makeExtension"]
def makeExtension() -> Extension:
return MKArgparseExtension()
class MkDocsArgparseException(Exception):
pass
class MKArgparseExtension(Extension):
def extendMarkdown(self, md: any) -> None:
md.registerExtension(self)
processor = ArgparseProcessor(md.parser)
md.preprocessors.register(processor, "mk_argparse", 142)
class ArgparseProcessor(Preprocessor):
def run(self, lines: list[str]) -> list[str]:
return list(
replace_blocks(lines, title="mkdocs-argparse", replace=replace_parser_docs)
)
def load_parser(module: str, attribute: str) -> argparse.ArgumentParser:
function = _load_obj(module, attribute)
if not isinstance(parser := function(), argparse.ArgumentParser):
raise MkDocsArgparseException(
f"{attribute!r} must be an 'argparse.ArgumentParser' object, got {type(parser)}"
)
return parser
def _load_obj(module: str, attribute: str) -> any:
try:
mod = importlib.import_module(module)
except SystemExit:
raise MkDocsArgparseException("the module appeared to call sys.exit()")
try:
return getattr(mod, attribute)
except AttributeError:
raise MkDocsArgparseException(
f"Module {module!r} has no attribute {attribute!r}"
)
def replace_parser_docs(**options: any) -> Iterator[str]:
for option in ("module", "function"):
if option not in options:
raise MkDocsArgparseException(f"Option {option!r} is required")
module = options["module"]
function = options["function"]
depth = int(options.get("depth", 0))
return make_parser_docs(load_parser(module, function), level=depth)
def make_parser_docs(parser: argparse.ArgumentParser, level: int = 0) -> Iterator[str]:
yield "#" * (level + 1) + " " + parser.prog
yield ""
if description := parser.description:
yield from description.splitlines()
yield ""
yield "Usage:"
yield ""
yield "```"
yield parser.format_usage().removeprefix("usage: ")
yield "```"
optional, positional = [], []
for action in parser._actions:
if action.dest == "help":
continue
if action.default and not action.required:
action.help += " (default: %(default))"
action.help = action.help.replace("%(default)", json.dumps(action.default))
if action.option_strings:
optional += [action]
else:
positional += [action]
if optional:
yield ""
yield "Options:"
yield ""
for action in optional:
name = " / ".join(f"`{option}`" for option in action.option_strings)
yield f"* {name} — {mistune.escape(action.help)}"
if positional:
yield ""
yield "Arguments:"
yield ""
for action in positional:
name = action.metavar or action.dest
yield f"* `{name}` — {mistune.escape(action.help)}"
yield ""
for action in parser._actions:
if isinstance(action, argparse._SubParsersAction):
for parser in sorted(
action.choices.values(), key=lambda parser: parser.prog
):
yield from make_parser_docs(parser, level=level + 1)
def replace_blocks(
lines: Iterable[str], title: str, replace: Callable[..., Iterable[str]]
) -> Iterator[str]:
options = {}
in_block_section = False
for line in lines:
if in_block_section:
match = re.search(r"^\s+:(?P<key>.+):(?:\s+(?P<value>\S+))?", line)
if match is not None:
key = match.group("key")
value = match.group("value") or ""
options[key] = value
continue
in_block_section = False
yield from replace(**options)
yield line
continue
match = re.search(rf"^::: {title}", line)
if match is not None:
in_block_section = True
options = {}
else:
yield line
|
0x2b3bfa0/mkdocs-argparse
| 4
|
An MkDocs extension to generate documentation for argparse command-line applications
|
Python
|
0x2b3bfa0
|
Helio Machado
|
iterative
|
examples/boringssl_server.rs
|
Rust
|
//! Run with `cargo run --all-features --example boringssl_server` command.
//!
//! To connect through browser, navigate to "https://localhost:3000" url.
use axum::{routing::get, Router};
use axum_server2::{self as axum_server2, tls_boringssl::BoringSSLConfig};
use std::net::SocketAddr;
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = BoringSSLConfig::from_pem_file(
"examples/self-signed-certs/cert.pem",
"examples/self-signed-certs/key.pem",
)
.unwrap();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum_server2::bind_boringssl(addr, config)
.serve(app.into_make_service())
.await
.unwrap();
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
examples/configure_addr_incoming.rs
|
Rust
|
//! Run with `cargo run --example configure_http` command.
//!
//! To connect through browser, navigate to "http://localhost:3000" url.
use axum::{routing::get, Router};
use axum_server2::AddrIncomingConfig;
use std::net::SocketAddr;
use std::time::Duration;
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = AddrIncomingConfig::new()
.tcp_nodelay(true)
.tcp_sleep_on_accept_errors(true)
.tcp_keepalive(Some(Duration::from_secs(32)))
.tcp_keepalive_interval(Some(Duration::from_secs(1)))
.tcp_keepalive_retries(Some(1))
.build();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum_server2::bind(addr)
.addr_incoming_config(config)
.serve(app.into_make_service())
.await
.unwrap();
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
examples/configure_http.rs
|
Rust
|
//! Run with `cargo run --example configure_http` command.
//!
//! To connect through browser, navigate to "http://localhost:3000" url.
use axum::{routing::get, Router};
use axum_server2::HttpConfig;
use std::net::SocketAddr;
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = HttpConfig::new()
.http1_only(true)
.http2_only(false)
.max_buf_size(8192)
.build();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum_server2::bind(addr)
.http_config(config)
.serve(app.into_make_service())
.await
.unwrap();
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
examples/from_std_listener.rs
|
Rust
|
//! Run with `cargo run --example from_std_listener` command.
//!
//! To connect through browser, navigate to "http://localhost:3000" url.
use axum::{routing::get, Router};
use std::net::{SocketAddr, TcpListener};
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
let listener = TcpListener::bind(addr).unwrap();
println!("listening on {}", addr);
axum_server2::from_tcp(listener)
.serve(app.into_make_service())
.await
.unwrap();
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
examples/from_std_listener_rustls.rs
|
Rust
|
//! Run with `cargo run --all-features --example from_std_listener_rustls`
//! command.
//!
//! To connect through browser, navigate to "https://localhost:3000" url.
use axum::{routing::get, Router};
use axum_server2::tls_rustls::RustlsConfig;
use std::net::{SocketAddr, TcpListener};
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = RustlsConfig::from_pem_file(
"examples/self-signed-certs/cert.pem",
"examples/self-signed-certs/key.pem",
)
.await
.unwrap();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
let listener = TcpListener::bind(addr).unwrap();
println!("listening on {}", addr);
axum_server2::from_tcp_rustls(listener, config)
.serve(app.into_make_service())
.await
.unwrap();
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
examples/graceful_shutdown.rs
|
Rust
|
//! Run with `cargo run --example graceful_shutdown` command.
//!
//! To connect through browser, navigate to "http://localhost:3000" url.
//!
//! After 10 seconds:
//! - If there aren't any connections alive, server will shutdown.
//! - If there are connections alive, server will wait until deadline is elapsed.
//! - Deadline is 30 seconds. Server will shutdown anyways when deadline is elapsed.
use axum::{routing::get, Router};
use axum_server2::Handle;
use std::{net::SocketAddr, time::Duration};
use tokio::time::sleep;
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let handle = Handle::new();
// Spawn a task to gracefully shutdown server.
tokio::spawn(graceful_shutdown(handle.clone()));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum_server2::bind(addr)
.handle(handle)
.serve(app.into_make_service())
.await
.unwrap();
println!("server is shut down");
}
async fn graceful_shutdown(handle: Handle) {
// Wait 10 seconds.
sleep(Duration::from_secs(10)).await;
println!("sending graceful shutdown signal");
// Signal the server to shutdown using Handle.
handle.graceful_shutdown(Some(Duration::from_secs(30)));
// Print alive connection count every second.
loop {
sleep(Duration::from_secs(1)).await;
println!("alive connections: {}", handle.connection_count());
}
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
examples/hello_world.rs
|
Rust
|
//! Run with `cargo run --example hello_world` command.
//!
//! To connect through browser, navigate to "http://localhost:3000" url.
use axum::{routing::get, Router};
use std::net::SocketAddr;
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum_server2::bind(addr)
.serve(app.into_make_service())
.await
.unwrap();
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
examples/http_and_https.rs
|
Rust
|
//! Run with `cargo run --all-features --example http_and_https` command.
//!
//! To connect through browser, navigate to "http://localhost:3000" url which should redirect to
//! "https://localhost:3443".
use axum::{http::uri::Uri, response::Redirect, routing::get, Router};
use axum_server2::tls_rustls::RustlsConfig;
use std::net::SocketAddr;
#[tokio::main]
async fn main() {
let http = tokio::spawn(http_server());
let https = tokio::spawn(https_server());
// Ignore errors.
let _ = tokio::join!(http, https);
}
async fn http_server() {
let app = Router::new().route("/", get(http_handler));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("http listening on {}", addr);
axum_server2::bind(addr)
.serve(app.into_make_service())
.await
.unwrap();
}
async fn http_handler(uri: Uri) -> Redirect {
let uri = format!("https://127.0.0.1:3443{}", uri.path());
Redirect::temporary(&uri)
}
async fn https_server() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = RustlsConfig::from_pem_file(
"examples/self-signed-certs/cert.pem",
"examples/self-signed-certs/key.pem",
)
.await
.unwrap();
let addr = SocketAddr::from(([127, 0, 0, 1], 3443));
println!("https listening on {}", addr);
axum_server2::bind_rustls(addr, config)
.serve(app.into_make_service())
.await
.unwrap();
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
examples/remote_address.rs
|
Rust
|
//! Run with `cargo run --example remote_address` command.
//!
//! To connect through browser, navigate to "http://localhost:3000" url.
use axum::{extract::ConnectInfo, routing::get, Router};
use std::net::SocketAddr;
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/", get(handler))
.into_make_service_with_connect_info::<SocketAddr>();
axum_server2::Server::bind(SocketAddr::from(([127, 0, 0, 1], 3000)))
.serve(app)
.await
.unwrap();
}
async fn handler(ConnectInfo(addr): ConnectInfo<SocketAddr>) -> String {
format!("your ip address is: {}", addr)
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
examples/remote_address_using_tower.rs
|
Rust
|
//! Run with `cargo run --example remote_address_using_tower` command.
//!
//! To connect through browser, navigate to "http://localhost:3000" url.
use hyper::{server::conn::AddrStream, Body, Request, Response};
use std::{convert::Infallible, net::SocketAddr};
use tower::service_fn;
use tower_http::add_extension::AddExtension;
#[tokio::main]
async fn main() {
let service = service_fn(|mut req: Request<Body>| async move {
let addr: SocketAddr = req.extensions_mut().remove().unwrap();
let body = Body::from(format!("IP Address: {}", addr));
Ok::<_, Infallible>(Response::new(body))
});
axum_server2::bind(SocketAddr::from(([127, 0, 0, 1], 3000)))
.serve(service_fn(|addr: &AddrStream| {
let addr = addr.remote_addr();
async move { Ok::<_, Infallible>(AddExtension::new(service, addr)) }
}))
.await
.unwrap();
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
examples/rustls_reload.rs
|
Rust
|
//! Run with `cargo run --all-features --example rustls_reload` command.
//!
//! To connect through browser, navigate to "https://localhost:3000" url.
//!
//! Certificate common name will be "localhost".
//!
//! After 20 seconds, certificate common name will be "reloaded".
use axum::{routing::get, Router};
use axum_server2::tls_rustls::RustlsConfig;
use std::{net::SocketAddr, time::Duration};
use tokio::time::sleep;
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = RustlsConfig::from_pem_file(
"examples/self-signed-certs/cert.pem",
"examples/self-signed-certs/key.pem",
)
.await
.unwrap();
// Spawn a task to reload tls.
tokio::spawn(reload(config.clone()));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum_server2::bind_rustls(addr, config)
.serve(app.into_make_service())
.await
.unwrap();
}
async fn reload(config: RustlsConfig) {
// Wait for 20 seconds.
sleep(Duration::from_secs(20)).await;
println!("reloading rustls configuration");
// Reload rustls configuration from new files.
config
.reload_from_pem_file(
"examples/self-signed-certs/reload/cert.pem",
"examples/self-signed-certs/reload/key.pem",
)
.await
.unwrap();
println!("rustls configuration reloaded");
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
examples/rustls_server.rs
|
Rust
|
//! Run with `cargo run --all-features --example rustls_server` command.
//!
//! To connect through browser, navigate to "https://localhost:3000" url.
use axum::{routing::get, Router};
use axum_server2::tls_rustls::RustlsConfig;
use std::net::SocketAddr;
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = RustlsConfig::from_pem_file(
"examples/self-signed-certs/cert.pem",
"examples/self-signed-certs/key.pem",
)
.await
.unwrap();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum_server2::bind_rustls(addr, config)
.serve(app.into_make_service())
.await
.unwrap();
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
examples/rustls_session.rs
|
Rust
|
//! Run with `cargo run --all-features --example rustls_session` command.
//!
//! To connect through browser, navigate to "https://localhost:3000" url.
use axum::{middleware::AddExtension, routing::get, Extension, Router};
use axum_server2::{
accept::Accept,
tls_rustls::{RustlsAcceptor, RustlsConfig},
};
use futures_util::future::BoxFuture;
use std::{io, net::SocketAddr, sync::Arc};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_rustls::server::TlsStream;
use tower::Layer;
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(handler));
let config = RustlsConfig::from_pem_file(
"examples/self-signed-certs/cert.pem",
"examples/self-signed-certs/key.pem",
)
.await
.unwrap();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
let acceptor = CustomAcceptor::new(RustlsAcceptor::new(config));
let server = axum_server2::bind(addr).acceptor(acceptor);
server.serve(app.into_make_service()).await.unwrap();
}
async fn handler(tls_data: Extension<TlsData>) -> String {
format!("{:?}", tls_data)
}
#[derive(Debug, Clone)]
struct TlsData {
_hostname: Option<Arc<str>>,
}
#[derive(Debug, Clone)]
struct CustomAcceptor {
inner: RustlsAcceptor,
}
impl CustomAcceptor {
fn new(inner: RustlsAcceptor) -> Self {
Self { inner }
}
}
impl<I, S> Accept<I, S> for CustomAcceptor
where
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
S: Send + 'static,
{
type Stream = TlsStream<I>;
type Service = AddExtension<S, TlsData>;
type Future = BoxFuture<'static, io::Result<(Self::Stream, Self::Service)>>;
fn accept(&self, stream: I, service: S) -> Self::Future {
let acceptor = self.inner.clone();
Box::pin(async move {
let (stream, service) = acceptor.accept(stream, service).await?;
let server_conn = stream.get_ref().1;
let sni_hostname = TlsData {
_hostname: server_conn.server_name().map(From::from),
};
let service = Extension(sni_hostname).layer(service);
Ok((stream, service))
})
}
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
examples/shutdown.rs
|
Rust
|
//! Run with `cargo run --example shutdown` command.
//!
//! To connect through browser, navigate to "http://localhost:3000" url.
//!
//! Server will shutdown in 20 seconds.
use axum::{routing::get, Router};
use axum_server2::Handle;
use std::{net::SocketAddr, time::Duration};
use tokio::time::sleep;
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let handle = Handle::new();
// Spawn a task to shutdown server.
tokio::spawn(shutdown(handle.clone()));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum_server2::bind(addr)
.handle(handle)
.serve(app.into_make_service())
.await
.unwrap();
println!("server is shut down");
}
async fn shutdown(handle: Handle) {
// Wait 20 seconds.
sleep(Duration::from_secs(20)).await;
println!("sending shutdown signal");
// Signal the server to shutdown using Handle.
handle.shutdown();
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
src/accept.rs
|
Rust
|
//! [`Accept`] trait and utilities.
use std::{
future::{Future, Ready},
io,
};
/// An asynchronous function to modify io stream and service.
pub trait Accept<I, S> {
/// IO stream produced by accept.
type Stream;
/// Service produced by accept.
type Service;
/// Future return value.
type Future: Future<Output = io::Result<(Self::Stream, Self::Service)>>;
/// Process io stream and service asynchronously.
fn accept(&self, stream: I, service: S) -> Self::Future;
}
/// A no-op acceptor.
#[derive(Clone, Copy, Debug, Default)]
pub struct DefaultAcceptor;
impl DefaultAcceptor {
/// Create a new default acceptor.
pub fn new() -> Self {
Self::default()
}
}
impl<I, S> Accept<I, S> for DefaultAcceptor {
type Stream = I;
type Service = S;
type Future = Ready<io::Result<(Self::Stream, Self::Service)>>;
fn accept(&self, stream: I, service: S) -> Self::Future {
std::future::ready(Ok((stream, service)))
}
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
src/addr_incoming_config.rs
|
Rust
|
use std::time::Duration;
/// A configuration for [`AddrIncoming`](hyper::server::conn::AddrIncoming).
#[derive(Debug, Clone)]
pub struct AddrIncomingConfig {
pub(crate) tcp_sleep_on_accept_errors: bool,
pub(crate) tcp_keepalive: Option<Duration>,
pub(crate) tcp_keepalive_interval: Option<Duration>,
pub(crate) tcp_keepalive_retries: Option<u32>,
pub(crate) tcp_nodelay: bool,
}
impl Default for AddrIncomingConfig {
fn default() -> Self {
Self::new()
}
}
impl AddrIncomingConfig {
/// Creates a default [`AddrIncoming`](hyper::server::conn::AddrIncoming) config.
pub fn new() -> AddrIncomingConfig {
Self {
tcp_sleep_on_accept_errors: true,
tcp_keepalive: None,
tcp_keepalive_interval: None,
tcp_keepalive_retries: None,
tcp_nodelay: false,
}
}
/// Builds the config, creating an owned version of it.
pub fn build(&mut self) -> Self {
self.clone()
}
/// Set whether to sleep on accept errors, to avoid exhausting file descriptor limits.
///
/// Default is `true`.
pub fn tcp_sleep_on_accept_errors(&mut self, val: bool) -> &mut Self {
self.tcp_sleep_on_accept_errors = val;
self
}
/// Set how often to send TCP keepalive probes.
///
/// By default TCP keepalive probes is disabled.
pub fn tcp_keepalive(&mut self, val: Option<Duration>) -> &mut Self {
self.tcp_keepalive = val;
self
}
/// Set the duration between two successive TCP keepalive retransmissions,
/// if acknowledgement to the previous keepalive transmission is not received.
///
/// Default is no interval.
pub fn tcp_keepalive_interval(&mut self, val: Option<Duration>) -> &mut Self {
self.tcp_keepalive_interval = val;
self
}
/// Set the number of retransmissions to be carried out before declaring that remote end is not available.
///
/// Default is no retry.
pub fn tcp_keepalive_retries(&mut self, val: Option<u32>) -> &mut Self {
self.tcp_keepalive_retries = val;
self
}
/// Set the value of `TCP_NODELAY` option for accepted connections.
///
/// Default is `false`.
pub fn tcp_nodelay(&mut self, val: bool) -> &mut Self {
self.tcp_nodelay = val;
self
}
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
src/handle.rs
|
Rust
|
use crate::notify_once::NotifyOnce;
use std::{
net::SocketAddr,
sync::{
atomic::{AtomicUsize, Ordering},
Arc, Mutex,
},
time::Duration,
};
use tokio::{sync::Notify, time::sleep};
/// A handle for [`Server`](crate::server::Server).
#[derive(Clone, Debug, Default)]
pub struct Handle {
inner: Arc<HandleInner>,
}
#[derive(Debug, Default)]
struct HandleInner {
addr: Mutex<Option<SocketAddr>>,
addr_notify: Notify,
conn_count: AtomicUsize,
shutdown: NotifyOnce,
graceful: NotifyOnce,
graceful_dur: Mutex<Option<Duration>>,
conn_end: NotifyOnce,
}
impl Handle {
/// Create a new handle.
pub fn new() -> Self {
Self::default()
}
/// Get the number of connections.
pub fn connection_count(&self) -> usize {
self.inner.conn_count.load(Ordering::SeqCst)
}
/// Shutdown the server.
pub fn shutdown(&self) {
self.inner.shutdown.notify_waiters();
}
/// Gracefully shutdown the server.
///
/// `None` means indefinite grace period.
pub fn graceful_shutdown(&self, duration: Option<Duration>) {
*self.inner.graceful_dur.lock().unwrap() = duration;
self.inner.graceful.notify_waiters();
}
/// Returns local address and port when server starts listening.
///
/// Returns `None` if server fails to bind.
pub async fn listening(&self) -> Option<SocketAddr> {
let notified = self.inner.addr_notify.notified();
if let Some(addr) = *self.inner.addr.lock().unwrap() {
return Some(addr);
}
notified.await;
*self.inner.addr.lock().unwrap()
}
pub(crate) fn notify_listening(&self, addr: Option<SocketAddr>) {
*self.inner.addr.lock().unwrap() = addr;
self.inner.addr_notify.notify_waiters();
}
pub(crate) fn watcher(&self) -> Watcher {
Watcher::new(self.clone())
}
pub(crate) async fn wait_shutdown(&self) {
self.inner.shutdown.notified().await;
}
pub(crate) async fn wait_graceful_shutdown(&self) {
self.inner.graceful.notified().await;
}
pub(crate) async fn wait_connections_end(&self) {
if self.inner.conn_count.load(Ordering::SeqCst) == 0 {
return;
}
let deadline = *self.inner.graceful_dur.lock().unwrap();
match deadline {
Some(duration) => tokio::select! {
biased;
_ = sleep(duration) => self.shutdown(),
_ = self.inner.conn_end.notified() => (),
},
None => self.inner.conn_end.notified().await,
}
}
}
pub(crate) struct Watcher {
handle: Handle,
}
impl Watcher {
fn new(handle: Handle) -> Self {
handle.inner.conn_count.fetch_add(1, Ordering::SeqCst);
Self { handle }
}
pub(crate) async fn wait_graceful_shutdown(&self) {
self.handle.wait_graceful_shutdown().await
}
pub(crate) async fn wait_shutdown(&self) {
self.handle.wait_shutdown().await
}
}
impl Drop for Watcher {
fn drop(&mut self) {
let count = self.handle.inner.conn_count.fetch_sub(1, Ordering::SeqCst) - 1;
if count == 0 && self.handle.inner.graceful.is_notified() {
self.handle.inner.conn_end.notify_waiters();
}
}
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
src/http_config.rs
|
Rust
|
use hyper::server::conn::Http;
use std::time::Duration;
/// A configuration for [`Http`].
#[derive(Debug, Clone)]
pub struct HttpConfig {
pub(crate) inner: Http,
}
impl Default for HttpConfig {
fn default() -> Self {
Self::new()
}
}
impl HttpConfig {
/// Creates a default [`Http`] config.
pub fn new() -> HttpConfig {
Self { inner: Http::new() }
}
/// Builds the config, creating an owned version of it.
pub fn build(&mut self) -> Self {
self.clone()
}
/// Sets whether HTTP1 is required.
///
/// Default is `false`.
pub fn http1_only(&mut self, val: bool) -> &mut Self {
self.inner.http1_only(val);
self
}
/// Set whether HTTP/1 connections should support half-closures.
///
/// Clients can chose to shutdown their write-side while waiting
/// for the server to respond. Setting this to `true` will
/// prevent closing the connection immediately if `read`
/// detects an EOF in the middle of a request.
///
/// Default is `false`.
pub fn http1_half_close(&mut self, val: bool) -> &mut Self {
self.inner.http1_half_close(val);
self
}
/// Enables or disables HTTP/1 keep-alive.
///
/// Default is true.
pub fn http1_keep_alive(&mut self, val: bool) -> &mut Self {
self.inner.http1_keep_alive(val);
self
}
/// Set whether HTTP/1 connections will write header names as title case at
/// the socket level.
///
/// Note that this setting does not affect HTTP/2.
///
/// Default is false.
pub fn http1_title_case_headers(&mut self, enabled: bool) -> &mut Self {
self.inner.http1_title_case_headers(enabled);
self
}
/// Set whether HTTP/1 connections will write header names as provided
/// at the socket level.
///
/// Note that this setting does not affect HTTP/2.
///
/// Default is false.
pub fn http1_preserve_header_case(&mut self, enabled: bool) -> &mut Self {
self.inner.http1_preserve_header_case(enabled);
self
}
/// Set a timeout for reading client request headers. If a client does not
/// transmit the entire header within this time, the connection is closed.
///
/// Default is None.
pub fn http1_header_read_timeout(&mut self, val: Duration) -> &mut Self {
self.inner.http1_header_read_timeout(val);
self
}
/// Set whether HTTP/1 connections should try to use vectored writes,
/// or always flatten into a single buffer.
///
/// Note that setting this to false may mean more copies of body data,
/// but may also improve performance when an IO transport doesn't
/// support vectored writes well, such as most TLS implementations.
///
/// Setting this to true will force hyper to use queued strategy
/// which may eliminate unnecessary cloning on some TLS backends
///
/// Default is `auto`. In this mode hyper will try to guess which
/// mode to use
pub fn http1_writev(&mut self, val: bool) -> &mut Self {
self.inner.http1_writev(val);
self
}
/// Sets whether HTTP2 is required.
///
/// Default is false
pub fn http2_only(&mut self, val: bool) -> &mut Self {
self.inner.http2_only(val);
self
}
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
/// stream-level flow control.
///
/// Passing `None` will do nothing.
///
/// If not set, hyper will use a default.
///
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
pub fn http2_initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
self.inner.http2_initial_stream_window_size(sz);
self
}
/// Sets the max connection-level flow control for HTTP2.
///
/// Passing `None` will do nothing.
///
/// If not set, hyper will use a default.
pub fn http2_initial_connection_window_size(
&mut self,
sz: impl Into<Option<u32>>,
) -> &mut Self {
self.inner.http2_initial_connection_window_size(sz);
self
}
/// Sets whether to use an adaptive flow control.
///
/// Enabling this will override the limits set in
/// `http2_initial_stream_window_size` and
/// `http2_initial_connection_window_size`.
pub fn http2_adaptive_window(&mut self, enabled: bool) -> &mut Self {
self.inner.http2_adaptive_window(enabled);
self
}
/// Enables the [extended CONNECT protocol].
///
/// [extended CONNECT protocol]: https://datatracker.ietf.org/doc/html/rfc8441#section-4
pub fn http2_enable_connect_protocol(&mut self) -> &mut Self {
self.inner.http2_enable_connect_protocol();
self
}
/// Sets the maximum frame size to use for HTTP2.
///
/// Passing `None` will do nothing.
///
/// If not set, hyper will use a default.
pub fn http2_max_frame_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
self.inner.http2_max_frame_size(sz);
self
}
/// Sets the [`SETTINGS_MAX_CONCURRENT_STREAMS`][spec] option for HTTP2
/// connections.
///
/// Default is no limit (`std::u32::MAX`). Passing `None` will do nothing.
///
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_MAX_CONCURRENT_STREAMS
pub fn http2_max_concurrent_streams(&mut self, max: impl Into<Option<u32>>) -> &mut Self {
self.inner.http2_max_concurrent_streams(max);
self
}
/// Sets the max size of received header frames.
///
/// Default is currently ~16MB, but may change.
pub fn http2_max_header_list_size(&mut self, max: u32) -> &mut Self {
self.inner.http2_max_header_list_size(max);
self
}
/// Configures the maximum number of pending reset streams allowed before a GOAWAY will be sent.
///
/// This will default to the default value set by the [`h2` crate](https://crates.io/crates/h2).
/// As of v0.3.17, it is 20.
///
/// See <https://github.com/hyperium/hyper/issues/2877> for more information.
pub fn http2_max_pending_accept_reset_streams(
&mut self,
max: impl Into<Option<usize>>,
) -> &mut Self {
self.inner.http2_max_pending_accept_reset_streams(max);
self
}
/// Set the maximum write buffer size for each HTTP/2 stream.
///
/// Default is currently ~400KB, but may change.
///
/// # Panics
///
/// The value must be no larger than `u32::MAX`.
pub fn http2_max_send_buf_size(&mut self, max: usize) -> &mut Self {
self.inner.http2_max_send_buf_size(max);
self
}
/// Sets an interval for HTTP2 Ping frames should be sent to keep a
/// connection alive.
///
/// Pass `None` to disable HTTP2 keep-alive.
///
/// Default is currently disabled.
pub fn http2_keep_alive_interval(
&mut self,
interval: impl Into<Option<Duration>>,
) -> &mut Self {
self.inner.http2_keep_alive_interval(interval);
self
}
/// Sets a timeout for receiving an acknowledgement of the keep-alive ping.
///
/// If the ping is not acknowledged within the timeout, the connection will
/// be closed. Does nothing if `http2_keep_alive_interval` is disabled.
///
/// Default is 20 seconds.
pub fn http2_keep_alive_timeout(&mut self, timeout: Duration) -> &mut Self {
self.inner.http2_keep_alive_timeout(timeout);
self
}
/// Set the maximum buffer size for the HTTP/1 connection.
///
/// Default is ~400kb.
///
/// # Panics
///
/// The minimum value allowed is 8192. This method panics if the passed `max` is less than the minimum.
pub fn max_buf_size(&mut self, max: usize) -> &mut Self {
self.inner.max_buf_size(max);
self
}
/// Aggregates flushes to better support pipelined responses.
///
/// Experimental, may have bugs.
///
/// Default is false.
pub fn pipeline_flush(&mut self, enabled: bool) -> &mut Self {
self.inner.pipeline_flush(enabled);
self
}
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
src/lib.rs
|
Rust
|
//! axum-server2 is a [hyper] server implementation designed to be used with [axum] framework.
//!
//! # Features
//!
//! - HTTP/1 and HTTP/2
//! - HTTPS through [rustls] or [openssl].
//! - High performance through [hyper].
//! - Using [tower] make service API.
//! - Very good [axum] compatibility. Likely to work with future [axum] releases.
//!
//! # Guide
//!
//! axum-server2 can [`serve`] items that implement [`MakeService`] with some additional [trait
//! bounds](crate::service::MakeServiceRef). Make services that are [created] using [`axum`]
//! complies with those trait bounds out of the box. Therefore it is more convenient to use this
//! crate with [`axum`].
//!
//! All examples in this crate uses [`axum`]. If you want to use this crate without [`axum`] it is
//! highly recommended to learn how [tower] works.
//!
//! [`Server::bind`] or [`bind`] function can be called to create a server that will bind to
//! provided [`SocketAddr`] when [`serve`] is called.
//!
//! A [`Handle`] can be passed to [`Server`](Server::handle) for additional utilities like shutdown
//! and graceful shutdown.
//!
//! [`bind_rustls`] can be called by providing [`RustlsConfig`] to create a HTTPS [`Server`] that
//! will bind on provided [`SocketAddr`]. [`RustlsConfig`] can be cloned, reload methods can be
//! used on clone to reload tls configuration.
//!
//! # Features
//!
//! * `tls-rustls` - activate [rustls] support.
//! * `tls-openssl` - activate [openssl] support.
//!
//! # Example
//!
//! A simple hello world application can be served like:
//!
//! ```rust,no_run
//! use axum::{routing::get, Router};
//! use std::net::SocketAddr;
//!
//! #[tokio::main]
//! async fn main() {
//! let app = Router::new().route("/", get(|| async { "Hello, world!" }));
//!
//! let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
//! println!("listening on {}", addr);
//! axum_server2::bind(addr)
//! .serve(app.into_make_service())
//! .await
//! .unwrap();
//! }
//! ```
//!
//! You can find more examples in [repository].
//!
//! [axum]: https://crates.io/crates/axum
//! [bind]: crate::bind
//! [bind_rustls]: crate::bind_rustls
//! [created]: https://docs.rs/axum/0.3/axum/struct.Router.html#method.into_make_service
//! [hyper]: https://crates.io/crates/hyper
//! [openssl]: https://crates.io/crates/openssl
//! [repository]: https://github.com/programatik29/axum-server2/tree/v0.3.0/examples
//! [rustls]: https://crates.io/crates/rustls
//! [tower]: https://crates.io/crates/tower
//! [`axum`]: https://docs.rs/axum/0.3
//! [`serve`]: crate::server::Server::serve
//! [`MakeService`]: https://docs.rs/tower/0.4/tower/make/trait.MakeService.html
//! [`RustlsConfig`]: crate::tls_rustls::RustlsConfig
//! [`SocketAddr`]: std::net::SocketAddr
#![forbid(unsafe_code)]
#![warn(
clippy::await_holding_lock,
clippy::cargo_common_metadata,
clippy::dbg_macro,
clippy::doc_markdown,
clippy::empty_enum,
clippy::enum_glob_use,
clippy::inefficient_to_string,
clippy::mem_forget,
clippy::mutex_integer,
clippy::needless_continue,
clippy::todo,
clippy::unimplemented,
clippy::wildcard_imports,
future_incompatible,
missing_docs,
missing_debug_implementations,
unreachable_pub
)]
#![cfg_attr(docsrs, feature(doc_cfg))]
mod addr_incoming_config;
mod handle;
mod http_config;
mod notify_once;
mod server;
pub mod accept;
pub mod service;
pub use self::{
addr_incoming_config::AddrIncomingConfig,
handle::Handle,
http_config::HttpConfig,
server::{bind, from_tcp, Server},
};
#[cfg(feature = "tls-rustls")]
#[cfg_attr(docsrs, doc(cfg(feature = "tls-rustls")))]
pub mod tls_rustls;
#[doc(inline)]
#[cfg(feature = "tls-rustls")]
pub use self::tls_rustls::export::{bind_rustls, from_tcp_rustls};
#[cfg(feature = "tls-openssl")]
#[cfg_attr(docsrs, doc(cfg(feature = "tls-openssl")))]
pub mod tls_openssl;
#[doc(inline)]
#[cfg(feature = "tls-openssl")]
pub use self::tls_openssl::bind_openssl;
#[cfg(feature = "tls-boringssl")]
#[cfg_attr(docsrs, doc(cfg(feature = "tls-boringssl")))]
pub mod tls_boringssl;
#[doc(inline)]
#[cfg(feature = "tls-boringssl")]
pub use self::tls_boringssl::bind_boringssl;
#[doc(inline)]
#[cfg(feature = "tls-boringssl")]
pub use boring;
#[doc(inline)]
#[cfg(feature = "tls-boringssl")]
pub use tokio_boring;
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
src/notify_once.rs
|
Rust
|
use std::sync::atomic::{AtomicBool, Ordering};
use tokio::sync::Notify;
#[derive(Debug, Default)]
pub(crate) struct NotifyOnce {
notified: AtomicBool,
notify: Notify,
}
impl NotifyOnce {
pub(crate) fn notify_waiters(&self) {
self.notified.store(true, Ordering::SeqCst);
self.notify.notify_waiters();
}
pub(crate) fn is_notified(&self) -> bool {
self.notified.load(Ordering::SeqCst)
}
pub(crate) async fn notified(&self) {
let future = self.notify.notified();
if !self.notified.load(Ordering::SeqCst) {
future.await;
}
}
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
src/server.rs
|
Rust
|
use crate::{
accept::{Accept, DefaultAcceptor},
addr_incoming_config::AddrIncomingConfig,
handle::Handle,
http_config::HttpConfig,
service::{MakeServiceRef, SendService},
};
use futures_util::future::poll_fn;
use http::Request;
use hyper::server::{
accept::Accept as HyperAccept,
conn::{AddrIncoming, AddrStream},
};
use std::{
io::{self, ErrorKind},
net::SocketAddr,
pin::Pin,
};
use tokio::{
io::{AsyncRead, AsyncWrite},
net::TcpListener,
};
/// HTTP server.
#[derive(Debug)]
pub struct Server<A = DefaultAcceptor> {
acceptor: A,
listener: Listener,
addr_incoming_conf: AddrIncomingConfig,
handle: Handle,
http_conf: HttpConfig,
}
#[derive(Debug)]
enum Listener {
Bind(SocketAddr),
Std(std::net::TcpListener),
}
/// Create a [`Server`] that will bind to provided address.
pub fn bind(addr: SocketAddr) -> Server {
Server::bind(addr)
}
/// Create a [`Server`] from existing `std::net::TcpListener`.
pub fn from_tcp(listener: std::net::TcpListener) -> Server {
Server::from_tcp(listener)
}
impl Server {
/// Create a server that will bind to provided address.
pub fn bind(addr: SocketAddr) -> Self {
let acceptor = DefaultAcceptor::new();
let handle = Handle::new();
Self {
acceptor,
listener: Listener::Bind(addr),
addr_incoming_conf: AddrIncomingConfig::default(),
handle,
http_conf: HttpConfig::default(),
}
}
/// Create a server from existing `std::net::TcpListener`.
pub fn from_tcp(listener: std::net::TcpListener) -> Self {
let acceptor = DefaultAcceptor::new();
let handle = Handle::new();
Self {
acceptor,
listener: Listener::Std(listener),
addr_incoming_conf: AddrIncomingConfig::default(),
handle,
http_conf: HttpConfig::default(),
}
}
}
impl<A> Server<A> {
/// Overwrite acceptor.
pub fn acceptor<Acceptor>(self, acceptor: Acceptor) -> Server<Acceptor> {
Server {
acceptor,
listener: self.listener,
addr_incoming_conf: self.addr_incoming_conf,
handle: self.handle,
http_conf: self.http_conf,
}
}
/// Map acceptor.
pub fn map<Acceptor, F>(self, acceptor: F) -> Server<Acceptor>
where
F: FnOnce(A) -> Acceptor,
{
Server {
acceptor: acceptor(self.acceptor),
listener: self.listener,
addr_incoming_conf: self.addr_incoming_conf,
handle: self.handle,
http_conf: self.http_conf,
}
}
/// Returns a reference to the acceptor.
pub fn get_ref(&self) -> &A {
&self.acceptor
}
/// Returns a mutable reference to the acceptor.
pub fn get_mut(&mut self) -> &mut A {
&mut self.acceptor
}
/// Provide a handle for additional utilities.
pub fn handle(mut self, handle: Handle) -> Self {
self.handle = handle;
self
}
/// Overwrite http configuration.
pub fn http_config(mut self, config: HttpConfig) -> Self {
self.http_conf = config;
self
}
/// Overwrite addr incoming configuration.
pub fn addr_incoming_config(mut self, config: AddrIncomingConfig) -> Self {
self.addr_incoming_conf = config;
self
}
/// Serve provided [`MakeService`].
///
/// To create [`MakeService`] easily, `Shared` from [`tower`] can be used.
///
/// # Errors
///
/// An error will be returned when:
///
/// - Binding to an address fails.
/// - `make_service` returns an error when `poll_ready` is called. This never happens on
/// [`axum`] make services.
///
/// [`axum`]: https://docs.rs/axum/0.3
/// [`tower`]: https://docs.rs/tower
/// [`MakeService`]: https://docs.rs/tower/0.4/tower/make/trait.MakeService.html
pub async fn serve<M>(self, mut make_service: M) -> io::Result<()>
where
M: MakeServiceRef<AddrStream, Request<hyper::Body>>,
A: Accept<AddrStream, M::Service> + Clone + Send + Sync + 'static,
A::Stream: AsyncRead + AsyncWrite + Unpin + Send,
A::Service: SendService<Request<hyper::Body>> + Send,
A::Future: Send,
{
let acceptor = self.acceptor;
let addr_incoming_conf = self.addr_incoming_conf;
let handle = self.handle;
let http_conf = self.http_conf;
let mut incoming = match bind_incoming(self.listener, addr_incoming_conf).await {
Ok(v) => v,
Err(e) => {
handle.notify_listening(None);
return Err(e);
}
};
handle.notify_listening(Some(incoming.local_addr()));
let accept_loop_future = async {
loop {
let addr_stream = tokio::select! {
biased;
result = accept(&mut incoming) => result?,
_ = handle.wait_graceful_shutdown() => return Ok(()),
};
poll_fn(|cx| make_service.poll_ready(cx))
.await
.map_err(io_other)?;
let service = match make_service.make_service(&addr_stream).await {
Ok(service) => service,
Err(_) => continue,
};
let acceptor = acceptor.clone();
let watcher = handle.watcher();
let http_conf = http_conf.clone();
tokio::spawn(async move {
if let Ok((stream, send_service)) = acceptor.accept(addr_stream, service).await
{
let service = send_service.into_service();
let mut serve_future = http_conf
.inner
.serve_connection(stream, service)
.with_upgrades();
tokio::select! {
biased;
_ = watcher.wait_graceful_shutdown() => {
Pin::new(&mut serve_future).graceful_shutdown();
tokio::select! {
biased;
_ = watcher.wait_shutdown() => (),
_ = &mut serve_future => (),
}
}
_ = watcher.wait_shutdown() => (),
_ = &mut serve_future => (),
}
}
});
}
};
let result = tokio::select! {
biased;
_ = handle.wait_shutdown() => return Ok(()),
result = accept_loop_future => result,
};
if let Err(e) = result {
return Err(e);
}
handle.wait_connections_end().await;
Ok(())
}
}
async fn bind_incoming(
listener: Listener,
addr_incoming_conf: AddrIncomingConfig,
) -> io::Result<AddrIncoming> {
let listener = match listener {
Listener::Bind(addr) => TcpListener::bind(addr).await?,
Listener::Std(std_listener) => {
std_listener.set_nonblocking(true)?;
TcpListener::from_std(std_listener)?
}
};
let mut incoming = AddrIncoming::from_listener(listener).map_err(io_other)?;
incoming.set_sleep_on_errors(addr_incoming_conf.tcp_sleep_on_accept_errors);
incoming.set_keepalive(addr_incoming_conf.tcp_keepalive);
incoming.set_keepalive_interval(addr_incoming_conf.tcp_keepalive_interval);
incoming.set_keepalive_retries(addr_incoming_conf.tcp_keepalive_retries);
incoming.set_nodelay(addr_incoming_conf.tcp_nodelay);
Ok(incoming)
}
pub(crate) async fn accept(incoming: &mut AddrIncoming) -> io::Result<AddrStream> {
let mut incoming = Pin::new(incoming);
// Always [`Option::Some`].
// https://docs.rs/hyper/0.14.14/src/hyper/server/tcp.rs.html#165
poll_fn(|cx| incoming.as_mut().poll_accept(cx))
.await
.unwrap()
}
type BoxError = Box<dyn std::error::Error + Send + Sync>;
pub(crate) fn io_other<E: Into<BoxError>>(error: E) -> io::Error {
io::Error::new(ErrorKind::Other, error)
}
#[cfg(test)]
mod tests {
use crate::{handle::Handle, server::Server};
use axum::{routing::get, Router};
use bytes::Bytes;
use http::{response, Request};
use hyper::{
client::conn::{handshake, SendRequest},
Body,
};
use std::{io, net::SocketAddr, time::Duration};
use tokio::{net::TcpStream, task::JoinHandle, time::timeout};
use tower::{Service, ServiceExt};
#[tokio::test]
async fn start_and_request() {
let (_handle, _server_task, addr) = start_server().await;
let (mut client, _conn) = connect(addr).await;
let (_parts, body) = send_empty_request(&mut client).await;
assert_eq!(body.as_ref(), b"Hello, world!");
}
#[tokio::test]
async fn test_shutdown() {
let (handle, _server_task, addr) = start_server().await;
let (mut client, conn) = connect(addr).await;
handle.shutdown();
let response_future_result = client
.ready()
.await
.unwrap()
.call(Request::new(Body::empty()))
.await;
assert!(response_future_result.is_err());
// Connection task should finish soon.
let _ = timeout(Duration::from_secs(1), conn).await.unwrap();
}
#[tokio::test]
async fn test_graceful_shutdown() {
let (handle, server_task, addr) = start_server().await;
let (mut client, conn) = connect(addr).await;
handle.graceful_shutdown(None);
let (_parts, body) = send_empty_request(&mut client).await;
assert_eq!(body.as_ref(), b"Hello, world!");
// Disconnect client.
conn.abort();
// Server task should finish soon.
let server_result = timeout(Duration::from_secs(1), server_task)
.await
.unwrap()
.unwrap();
assert!(server_result.is_ok());
}
#[ignore]
#[tokio::test]
async fn test_graceful_shutdown_timed() {
let (handle, server_task, addr) = start_server().await;
let (mut client, _conn) = connect(addr).await;
handle.graceful_shutdown(Some(Duration::from_millis(250)));
let (_parts, body) = send_empty_request(&mut client).await;
assert_eq!(body.as_ref(), b"Hello, world!");
// Don't disconnect client.
// conn.abort();
// Server task should finish soon.
let server_result = timeout(Duration::from_secs(1), server_task)
.await
.unwrap()
.unwrap();
assert!(server_result.is_ok());
}
async fn start_server() -> (Handle, JoinHandle<io::Result<()>>, SocketAddr) {
let handle = Handle::new();
let server_handle = handle.clone();
let server_task = tokio::spawn(async move {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let addr = SocketAddr::from(([127, 0, 0, 1], 0));
Server::bind(addr)
.handle(server_handle)
.serve(app.into_make_service())
.await
});
let addr = handle.listening().await.unwrap();
(handle, server_task, addr)
}
async fn connect(addr: SocketAddr) -> (SendRequest<Body>, JoinHandle<()>) {
let stream = TcpStream::connect(addr).await.unwrap();
let (send_request, connection) = handshake(stream).await.unwrap();
let task = tokio::spawn(async move {
let _ = connection.await;
});
(send_request, task)
}
async fn send_empty_request(client: &mut SendRequest<Body>) -> (response::Parts, Bytes) {
let (parts, body) = client
.ready()
.await
.unwrap()
.call(Request::new(Body::empty()))
.await
.unwrap()
.into_parts();
let body = hyper::body::to_bytes(body).await.unwrap();
(parts, body)
}
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
src/service.rs
|
Rust
|
//! Service traits.
use http::Response;
use http_body::Body;
use std::{
future::Future,
task::{Context, Poll},
};
use tower_service::Service;
/// Trait alias for [`Service`] with bounds required for [`serve`](crate::server::Server::serve).
///
/// This trait is sealed and cannot be implemented for types outside this crate.
#[allow(missing_docs)]
pub trait SendService<Request>: send_service::Sealed<Request> {
type Service: Service<
Request,
Response = Response<Self::Body>,
Error = Self::Error,
Future = Self::Future,
> + Send
+ 'static;
type Body: Body<Data = Self::BodyData, Error = Self::BodyError> + Send + 'static;
type BodyData: Send + 'static;
type BodyError: Into<Box<dyn std::error::Error + Send + Sync>>;
type Error: Into<Box<dyn std::error::Error + Send + Sync>>;
type Future: Future<Output = Result<Response<Self::Body>, Self::Error>> + Send + 'static;
fn into_service(self) -> Self::Service;
}
impl<T, B, Request> send_service::Sealed<Request> for T
where
T: Service<Request, Response = Response<B>>,
T::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
T::Future: Send + 'static,
B: Body + Send + 'static,
B::Data: Send + 'static,
B::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
{
}
impl<T, B, Request> SendService<Request> for T
where
T: Service<Request, Response = Response<B>> + Send + 'static,
T::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
T::Future: Send + 'static,
B: Body + Send + 'static,
B::Data: Send + 'static,
B::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
{
type Service = T;
type Body = B;
type BodyData = B::Data;
type BodyError = B::Error;
type Error = T::Error;
type Future = T::Future;
fn into_service(self) -> Self::Service {
self
}
}
/// Modified version of [`MakeService`] that takes a `&Target` and has required trait bounds for
/// [`serve`](crate::server::Server::serve).
///
/// This trait is sealed and cannot be implemented for types outside this crate.
///
/// [`MakeService`]: https://docs.rs/tower/0.4/tower/make/trait.MakeService.html
#[allow(missing_docs)]
pub trait MakeServiceRef<Target, Request>: make_service_ref::Sealed<(Target, Request)> {
type Service: Service<
Request,
Response = Response<Self::Body>,
Error = Self::Error,
Future = Self::Future,
> + Send
+ 'static;
type Body: Body<Data = Self::BodyData, Error = Self::BodyError> + Send + 'static;
type BodyData: Send + 'static;
type BodyError: Into<Box<dyn std::error::Error + Send + Sync>>;
type Error: Into<Box<dyn std::error::Error + Send + Sync>>;
type Future: Future<Output = Result<Response<Self::Body>, Self::Error>> + Send + 'static;
type MakeError: Into<Box<dyn std::error::Error + Send + Sync>>;
type MakeFuture: Future<Output = Result<Self::Service, Self::MakeError>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::MakeError>>;
fn make_service(&mut self, target: &Target) -> Self::MakeFuture;
}
impl<T, S, B, E, F, Target, Request> make_service_ref::Sealed<(Target, Request)> for T
where
T: for<'a> Service<&'a Target, Response = S, Error = E, Future = F>,
S: Service<Request, Response = Response<B>> + Send + 'static,
S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
S::Future: Send + 'static,
B: Body + Send + 'static,
B::Data: Send + 'static,
B::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
E: Into<Box<dyn std::error::Error + Send + Sync>>,
F: Future<Output = Result<S, E>>,
{
}
impl<T, S, B, E, F, Target, Request> MakeServiceRef<Target, Request> for T
where
T: for<'a> Service<&'a Target, Response = S, Error = E, Future = F>,
S: Service<Request, Response = Response<B>> + Send + 'static,
S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
S::Future: Send + 'static,
B: Body + Send + 'static,
B::Data: Send + 'static,
B::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
E: Into<Box<dyn std::error::Error + Send + Sync>>,
F: Future<Output = Result<S, E>>,
{
type Service = S;
type Body = B;
type BodyData = B::Data;
type BodyError = B::Error;
type Error = S::Error;
type Future = S::Future;
type MakeError = E;
type MakeFuture = F;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::MakeError>> {
self.poll_ready(cx)
}
fn make_service(&mut self, target: &Target) -> Self::MakeFuture {
self.call(target)
}
}
mod send_service {
pub trait Sealed<T> {}
}
mod make_service_ref {
pub trait Sealed<T> {}
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
src/tls_boringssl/future.rs
|
Rust
|
//! Future types.
use super::BoringSSLConfig;
use futures_util::future::BoxFuture;
use pin_project_lite::pin_project;
use std::io::{Error, ErrorKind};
use std::time::Duration;
use std::{
fmt,
future::Future,
io,
pin::Pin,
task::{Context, Poll},
};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::time::{timeout, Timeout};
use boring::ssl::Ssl;
use tokio_boring::{HandshakeError, SslStream, SslStreamBuilder};
pin_project! {
/// Future type for [`BoringSSLSSLAcceptor`](crate::tls_boringssl::BoringSSSslAcceptor).
pub struct BoringSSLAcceptorFuture<F, I, S> {
#[pin]
inner: AcceptFuture<F, I, S>,
config: Option<BoringSSLConfig>,
}
}
impl<F, I, S> BoringSSLAcceptorFuture<F, I, S> {
pub(crate) fn new(future: F, config: BoringSSLConfig, handshake_timeout: Duration) -> Self {
let inner = AcceptFuture::InnerAccepting {
future,
handshake_timeout,
};
let config = Some(config);
Self { inner, config }
}
}
impl<F, I, S> fmt::Debug for BoringSSLAcceptorFuture<F, I, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("BoringSSLSSLAcceptorFuture").finish()
}
}
pin_project! {
#[project = AcceptFutureProj]
enum AcceptFuture<F, I, S> {
// We are waiting on the inner (lower) future to complete accept()
// so that we can begin installing TLS into the channel.
InnerAccepting {
#[pin]
future: F,
handshake_timeout: Duration,
},
// We are waiting for TLS to install into the channel so that we can
// proceed to return the SslStream.
TlsAccepting {
#[pin]
future: Timeout<BoxFuture<'static, Result<SslStream<I>, HandshakeError<I>>>>,
service: Option<S>,
}
}
}
impl<F, I, S> Future for BoringSSLAcceptorFuture<F, I, S>
where
F: Future<Output = io::Result<(I, S)>>,
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
type Output = io::Result<(SslStream<I>, S)>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut this = self.project();
// The inner future here is what is doing the lower level accept, such as
// our tcp socket.
//
// So we poll on that first, when it's ready we then swap our the inner future to
// one waiting for our ssl layer to accept/install.
//
// Then once that's ready we can then wrap and provide the SslStream back out.
// This loop exists to allow the Poll::Ready from InnerAccept on complete
// to re-poll immediately. Otherwise all other paths are immediate returns.
loop {
match this.inner.as_mut().project() {
AcceptFutureProj::InnerAccepting {
future,
handshake_timeout,
} => match future.poll(cx) {
Poll::Ready(Ok((stream, service))) => {
let server_config = this.config.take().expect(
"config is not set. this is a bug in axum-server2, please report",
);
// Change to poll::ready(err)
let ssl = match Ssl::new_from_ref(server_config.acceptor.context()) {
Ok(ssl) => ssl,
Err(e) => {
return Poll::Ready(Err(io::Error::new(io::ErrorKind::Other, e)))
}
};
let tls_builder = SslStreamBuilder::new(ssl, stream);
let accept_future: BoxFuture<'_, Result<SslStream<I>, HandshakeError<I>>> =
Box::pin(tls_builder.accept());
let service = Some(service);
let handshake_timeout = *handshake_timeout;
this.inner.set(AcceptFuture::TlsAccepting {
future: timeout(handshake_timeout, accept_future),
service,
});
// the loop is now triggered to immediately poll on
// ssl stream accept.
}
Poll::Ready(Err(e)) => return Poll::Ready(Err(e)),
Poll::Pending => return Poll::Pending,
},
AcceptFutureProj::TlsAccepting { future, service } => match future.poll(cx) {
Poll::Ready(Ok(Ok(stream))) => {
let service = service.take().expect("future polled after ready");
return Poll::Ready(Ok((stream, service)));
}
Poll::Ready(Ok(Err(e))) => {
return Poll::Ready(Err(io::Error::new(ErrorKind::Other, e.to_string())))
}
Poll::Ready(Err(timeout)) => {
return Poll::Ready(Err(Error::new(ErrorKind::TimedOut, timeout)))
}
Poll::Pending => return Poll::Pending,
},
}
}
}
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
src/tls_boringssl/mod.rs
|
Rust
|
//! Tls implementation using [`openssl`]
//!
//! # Example
//!
//! ```rust,no_run
//! use axum::{routing::get, Router};
//! use axum_server2::tls_boringssl::BoringSSLConfig;
//! use std::net::SocketAddr;
//!
//! #[tokio::main]
//! async fn main() {
//! let app = Router::new().route("/", get(|| async { "Hello, world!" }));
//!
//! let config = BoringSSLConfig::from_pem_file(
//! "examples/self-signed-certs/cert.pem",
//! "examples/self-signed-certs/key.pem",
//! )
//! .unwrap();
//!
//! let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
//! println!("listening on {}", addr);
//! axum_server2::bind_boringssl(addr, config)
//! .serve(app.into_make_service())
//! .await
//! .unwrap();
//! }
//! ```
use self::future::BoringSSLAcceptorFuture;
use crate::{
accept::{Accept, DefaultAcceptor},
server::Server,
};
pub use boring::ssl::Error as BoringSSLError;
use boring::ssl::{self, SslOptions, SslVersion};
use boring::ssl::{SslAcceptor, SslAcceptorBuilder, SslFiletype, SslMethod};
use std::{convert::TryFrom, fmt, net::SocketAddr, path::Path, sync::Arc, time::Duration};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_boring::SslStream;
pub mod future;
/// Create a TLS server that will be bound to the provided socket with a configuration. See
/// the [`crate::tls_boringssl`] module for more details.
pub fn bind_boringssl(addr: SocketAddr, config: BoringSSLConfig) -> Server<BoringSSLAcceptor> {
let acceptor = BoringSSLAcceptor::new(config);
Server::bind(addr).acceptor(acceptor)
}
/// Tls acceptor that uses BoringSSL. For details on how to use this see [`crate::tls_boringssl`] module
/// for more details.
#[derive(Clone)]
pub struct BoringSSLAcceptor<A = DefaultAcceptor> {
inner: A,
config: BoringSSLConfig,
handshake_timeout: Duration,
}
impl BoringSSLAcceptor {
/// Create a new BoringSSL acceptor based on the provided [`BoringSSLConfig`]. This is
/// generally used with manual calls to [`Server::bind`]. You may want [`bind_boringssl`]
/// instead.
pub fn new(config: BoringSSLConfig) -> Self {
let inner = DefaultAcceptor::new();
#[cfg(not(test))]
let handshake_timeout = Duration::from_secs(10);
// Don't force tests to wait too long.
#[cfg(test)]
let handshake_timeout = Duration::from_secs(1);
Self {
inner,
config,
handshake_timeout,
}
}
/// Override the default TLS handshake timeout of 10 seconds.
pub fn handshake_timeout(mut self, val: Duration) -> Self {
self.handshake_timeout = val;
self
}
}
impl<A, I, S> Accept<I, S> for BoringSSLAcceptor<A>
where
A: Accept<I, S>,
A::Stream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
type Stream = SslStream<A::Stream>;
type Service = A::Service;
type Future = BoringSSLAcceptorFuture<A::Future, A::Stream, A::Service>;
fn accept(&self, stream: I, service: S) -> Self::Future {
let inner_future = self.inner.accept(stream, service);
let config = self.config.clone();
BoringSSLAcceptorFuture::new(inner_future, config, self.handshake_timeout)
}
}
impl<A> fmt::Debug for BoringSSLAcceptor<A> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("BoringSSLAcceptor").finish()
}
}
/// BoringSSL configuration.
#[derive(Clone)]
pub struct BoringSSLConfig {
acceptor: Arc<SslAcceptor>,
}
impl BoringSSLConfig {
/// This helper will established a TLS server based on strong cipher suites
/// from a PEM formatted certificate and key.
pub fn from_pem_file<A: AsRef<Path>, B: AsRef<Path>>(
cert: A,
key: B,
) -> Result<Self, BoringSSLError> {
let mut tls_builder = default_acceptor_builder()?;
tls_builder.set_certificate_file(cert, SslFiletype::PEM)?;
tls_builder.set_private_key_file(key, SslFiletype::PEM)?;
tls_builder.check_private_key()?;
let acceptor = Arc::new(tls_builder.build());
Ok(BoringSSLConfig { acceptor })
}
/// This helper will established a TLS server based on strong cipher suites
/// from a PEM formatted certificate chain and key.
pub fn from_pem_chain_file<A: AsRef<Path>, B: AsRef<Path>>(
chain: A,
key: B,
) -> Result<Self, BoringSSLError> {
let mut tls_builder = default_acceptor_builder()?;
tls_builder.set_certificate_chain_file(chain)?;
tls_builder.set_private_key_file(key, SslFiletype::PEM)?;
tls_builder.check_private_key()?;
let acceptor = Arc::new(tls_builder.build());
Ok(BoringSSLConfig { acceptor })
}
}
impl TryFrom<SslAcceptorBuilder> for BoringSSLConfig {
type Error = BoringSSLError;
/// Build the [`BoringSSLConfig`] from an [`SslAcceptorBuilder`]. This allows precise
/// control over the settings that will be used by BoringSSL in this server.
///
/// # Example
/// ```
/// use axum_server2::tls_boringssl::BoringSSLConfig;
/// use boring::ssl::{SslAcceptor, SslMethod};
/// use std::convert::TryFrom;
///
/// #[tokio::main]
/// async fn main() {
/// let mut tls_builder = SslAcceptor::mozilla_intermediate_v5(SslMethod::tls())
/// .unwrap();
/// // Set configurations like set_certificate_chain_file or
/// // set_private_key_file.
/// // let tls_builder.set_ ... ;
/// let _config = BoringSSLConfig::try_from(tls_builder);
/// }
/// ```
fn try_from(tls_builder: SslAcceptorBuilder) -> Result<Self, Self::Error> {
// Any other checks?
tls_builder.check_private_key()?;
let acceptor = Arc::new(tls_builder.build());
Ok(BoringSSLConfig { acceptor })
}
}
impl fmt::Debug for BoringSSLConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("BoringSSLConfig").finish()
}
}
fn default_acceptor_builder() -> Result<SslAcceptorBuilder, BoringSSLError> {
let mut builder = SslAcceptor::mozilla_intermediate_v5(SslMethod::tls())?;
builder.set_alpn_select_callback(|_, client| {
ssl::select_next_proto(b"\x02h2\x08http/1.1", client).ok_or(ssl::AlpnError::ALERT_FATAL)
});
builder.set_options(SslOptions::ALL);
builder.set_min_proto_version(Some(SslVersion::TLS1))?;
builder.set_max_proto_version(Some(SslVersion::TLS1_3))?;
builder.set_permute_extensions(true);
Ok(builder)
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
src/tls_openssl/future.rs
|
Rust
|
//! Future types.
use super::OpenSSLConfig;
use pin_project_lite::pin_project;
use std::io::{Error, ErrorKind};
use std::time::Duration;
use std::{
fmt,
future::Future,
io,
pin::Pin,
task::{Context, Poll},
};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::time::{timeout, Timeout};
use openssl::ssl::Ssl;
use tokio_openssl::SslStream;
pin_project! {
/// Future type for [`OpenSSLAcceptor`](crate::tls_openssl::OpenSSLAcceptor).
pub struct OpenSSLAcceptorFuture<F, I, S> {
#[pin]
inner: AcceptFuture<F, I, S>,
config: Option<OpenSSLConfig>,
}
}
impl<F, I, S> OpenSSLAcceptorFuture<F, I, S> {
pub(crate) fn new(future: F, config: OpenSSLConfig, handshake_timeout: Duration) -> Self {
let inner = AcceptFuture::InnerAccepting {
future,
handshake_timeout,
};
let config = Some(config);
Self { inner, config }
}
}
impl<F, I, S> fmt::Debug for OpenSSLAcceptorFuture<F, I, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("OpenSSLAcceptorFuture").finish()
}
}
pin_project! {
struct TlsAccept<I> {
#[pin]
tls_stream: Option<SslStream<I>>,
}
}
impl<I> Future for TlsAccept<I>
where
I: AsyncRead + AsyncWrite + Unpin,
{
type Output = io::Result<SslStream<I>>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut this = self.project();
match this
.tls_stream
.as_mut()
.as_pin_mut()
.map(|inner| inner.poll_accept(cx))
.expect("tlsaccept polled after ready")
{
Poll::Ready(Ok(())) => {
let tls_stream = this.tls_stream.take().expect("tls stream vanished?");
Poll::Ready(Ok(tls_stream))
}
Poll::Ready(Err(e)) => Poll::Ready(Err(Error::new(ErrorKind::Other, e))),
Poll::Pending => Poll::Pending,
}
}
}
pin_project! {
#[project = AcceptFutureProj]
enum AcceptFuture<F, I, S> {
// We are waiting on the inner (lower) future to complete accept()
// so that we can begin installing TLS into the channel.
InnerAccepting {
#[pin]
future: F,
handshake_timeout: Duration,
},
// We are waiting for TLS to install into the channel so that we can
// proceed to return the SslStream.
TlsAccepting {
#[pin]
future: Timeout< TlsAccept<I> >,
service: Option<S>,
}
}
}
impl<F, I, S> Future for OpenSSLAcceptorFuture<F, I, S>
where
F: Future<Output = io::Result<(I, S)>>,
I: AsyncRead + AsyncWrite + Unpin,
{
type Output = io::Result<(SslStream<I>, S)>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut this = self.project();
// The inner future here is what is doing the lower level accept, such as
// our tcp socket.
//
// So we poll on that first, when it's ready we then swap our the inner future to
// one waiting for our ssl layer to accept/install.
//
// Then once that's ready we can then wrap and provide the SslStream back out.
// This loop exists to allow the Poll::Ready from InnerAccept on complete
// to re-poll immediately. Otherwise all other paths are immediate returns.
loop {
match this.inner.as_mut().project() {
AcceptFutureProj::InnerAccepting {
future,
handshake_timeout,
} => match future.poll(cx) {
Poll::Ready(Ok((stream, service))) => {
let server_config = this.config.take().expect(
"config is not set. this is a bug in axum-server2, please report",
);
// Change to poll::ready(err)
let ssl = Ssl::new(server_config.acceptor.context()).unwrap();
let tls_stream = SslStream::new(ssl, stream).unwrap();
let future = TlsAccept {
tls_stream: Some(tls_stream),
};
let service = Some(service);
let handshake_timeout = *handshake_timeout;
this.inner.set(AcceptFuture::TlsAccepting {
future: timeout(handshake_timeout, future),
service,
});
// the loop is now triggered to immediately poll on
// ssl stream accept.
}
Poll::Ready(Err(e)) => return Poll::Ready(Err(e)),
Poll::Pending => return Poll::Pending,
},
AcceptFutureProj::TlsAccepting { future, service } => match future.poll(cx) {
Poll::Ready(Ok(Ok(stream))) => {
let service = service.take().expect("future polled after ready");
return Poll::Ready(Ok((stream, service)));
}
Poll::Ready(Ok(Err(e))) => return Poll::Ready(Err(e)),
Poll::Ready(Err(timeout)) => {
return Poll::Ready(Err(Error::new(ErrorKind::TimedOut, timeout)))
}
Poll::Pending => return Poll::Pending,
},
}
}
}
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
src/tls_openssl/mod.rs
|
Rust
|
//! Tls implementation using [`openssl`]
//!
//! # Example
//!
//! ```rust,no_run
//! use axum::{routing::get, Router};
//! use axum_server2::tls_openssl::OpenSSLConfig;
//! use std::net::SocketAddr;
//!
//! #[tokio::main]
//! async fn main() {
//! let app = Router::new().route("/", get(|| async { "Hello, world!" }));
//!
//! let config = OpenSSLConfig::from_pem_file(
//! "examples/self-signed-certs/cert.pem",
//! "examples/self-signed-certs/key.pem",
//! )
//! .unwrap();
//!
//! let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
//! println!("listening on {}", addr);
//! axum_server2::bind_openssl(addr, config)
//! .serve(app.into_make_service())
//! .await
//! .unwrap();
//! }
//! ```
use self::future::OpenSSLAcceptorFuture;
use crate::{
accept::{Accept, DefaultAcceptor},
server::Server,
};
use openssl::ssl::Error as OpenSSLError;
use openssl::ssl::{SslAcceptor, SslAcceptorBuilder, SslFiletype, SslMethod};
use std::{convert::TryFrom, fmt, net::SocketAddr, path::Path, sync::Arc, time::Duration};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_openssl::SslStream;
pub mod future;
/// Create a TLS server that will be bound to the provided socket with a configuration. See
/// the [`crate::tls_openssl`] module for more details.
pub fn bind_openssl(addr: SocketAddr, config: OpenSSLConfig) -> Server<OpenSSLAcceptor> {
let acceptor = OpenSSLAcceptor::new(config);
Server::bind(addr).acceptor(acceptor)
}
/// Tls acceptor that uses OpenSSL. For details on how to use this see [`crate::tls_openssl`] module
/// for more details.
#[derive(Clone)]
pub struct OpenSSLAcceptor<A = DefaultAcceptor> {
inner: A,
config: OpenSSLConfig,
handshake_timeout: Duration,
}
impl OpenSSLAcceptor {
/// Create a new OpenSSL acceptor based on the provided [`OpenSSLConfig`]. This is
/// generally used with manual calls to [`Server::bind`]. You may want [`bind_openssl`]
/// instead.
pub fn new(config: OpenSSLConfig) -> Self {
let inner = DefaultAcceptor::new();
#[cfg(not(test))]
let handshake_timeout = Duration::from_secs(10);
// Don't force tests to wait too long.
#[cfg(test)]
let handshake_timeout = Duration::from_secs(1);
Self {
inner,
config,
handshake_timeout,
}
}
/// Override the default TLS handshake timeout of 10 seconds.
pub fn handshake_timeout(mut self, val: Duration) -> Self {
self.handshake_timeout = val;
self
}
}
impl<A, I, S> Accept<I, S> for OpenSSLAcceptor<A>
where
A: Accept<I, S>,
A::Stream: AsyncRead + AsyncWrite + Unpin,
{
type Stream = SslStream<A::Stream>;
type Service = A::Service;
type Future = OpenSSLAcceptorFuture<A::Future, A::Stream, A::Service>;
fn accept(&self, stream: I, service: S) -> Self::Future {
let inner_future = self.inner.accept(stream, service);
let config = self.config.clone();
OpenSSLAcceptorFuture::new(inner_future, config, self.handshake_timeout)
}
}
impl<A> fmt::Debug for OpenSSLAcceptor<A> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("OpenSSLAcceptor").finish()
}
}
/// OpenSSL configuration.
#[derive(Clone)]
pub struct OpenSSLConfig {
acceptor: Arc<SslAcceptor>,
}
impl OpenSSLConfig {
/// This helper will established a TLS server based on strong cipher suites
/// from a PEM formatted certificate and key.
pub fn from_pem_file<A: AsRef<Path>, B: AsRef<Path>>(
cert: A,
key: B,
) -> Result<Self, OpenSSLError> {
let mut tls_builder = SslAcceptor::mozilla_modern_v5(SslMethod::tls())?;
tls_builder.set_certificate_file(cert, SslFiletype::PEM)?;
tls_builder.set_private_key_file(key, SslFiletype::PEM)?;
tls_builder.check_private_key()?;
let acceptor = Arc::new(tls_builder.build());
Ok(OpenSSLConfig { acceptor })
}
/// This helper will established a TLS server based on strong cipher suites
/// from a PEM formatted certificate chain and key.
pub fn from_pem_chain_file<A: AsRef<Path>, B: AsRef<Path>>(
chain: A,
key: B,
) -> Result<Self, OpenSSLError> {
let mut tls_builder = SslAcceptor::mozilla_modern_v5(SslMethod::tls())?;
tls_builder.set_certificate_chain_file(chain)?;
tls_builder.set_private_key_file(key, SslFiletype::PEM)?;
tls_builder.check_private_key()?;
let acceptor = Arc::new(tls_builder.build());
Ok(OpenSSLConfig { acceptor })
}
}
impl TryFrom<SslAcceptorBuilder> for OpenSSLConfig {
type Error = OpenSSLError;
/// Build the [`OpenSSLConfig`] from an [`SslAcceptorBuilder`]. This allows precise
/// control over the settings that will be used by OpenSSL in this server.
///
/// # Example
/// ```
/// use axum_server2::tls_openssl::OpenSSLConfig;
/// use openssl::ssl::{SslAcceptor, SslMethod};
/// use std::convert::TryFrom;
///
/// #[tokio::main]
/// async fn main() {
/// let mut tls_builder = SslAcceptor::mozilla_modern_v5(SslMethod::tls())
/// .unwrap();
/// // Set configurations like set_certificate_chain_file or
/// // set_private_key_file.
/// // let tls_builder.set_ ... ;
/// let _config = OpenSSLConfig::try_from(tls_builder);
/// }
/// ```
fn try_from(tls_builder: SslAcceptorBuilder) -> Result<Self, Self::Error> {
// Any other checks?
tls_builder.check_private_key()?;
let acceptor = Arc::new(tls_builder.build());
Ok(OpenSSLConfig { acceptor })
}
}
impl fmt::Debug for OpenSSLConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("OpenSSLConfig").finish()
}
}
#[cfg(test)]
mod tests {
use crate::{
handle::Handle,
tls_openssl::{self, OpenSSLConfig},
};
use axum::{routing::get, Router};
use bytes::Bytes;
use http::{response, Request};
use hyper::{
client::conn::{handshake, SendRequest},
Body,
};
use std::{io, net::SocketAddr, time::Duration};
use tokio::{net::TcpStream, task::JoinHandle, time::timeout};
use tower::{Service, ServiceExt};
use openssl::ssl::{Ssl, SslConnector, SslMethod, SslVerifyMode};
use std::pin::Pin;
use tokio_openssl::SslStream;
#[tokio::test]
async fn start_and_request() {
let (_handle, _server_task, addr) = start_server().await;
let (mut client, _conn) = connect(addr).await;
let (_parts, body) = send_empty_request(&mut client).await;
assert_eq!(body.as_ref(), b"Hello, world!");
}
#[tokio::test]
async fn test_shutdown() {
let (handle, _server_task, addr) = start_server().await;
let (mut client, conn) = connect(addr).await;
handle.shutdown();
let response_future_result = client
.ready()
.await
.unwrap()
.call(Request::new(Body::empty()))
.await;
assert!(response_future_result.is_err());
// Connection task should finish soon.
let _ = timeout(Duration::from_secs(1), conn).await.unwrap();
}
#[tokio::test]
async fn test_graceful_shutdown() {
let (handle, server_task, addr) = start_server().await;
let (mut client, conn) = connect(addr).await;
handle.graceful_shutdown(None);
let (_parts, body) = send_empty_request(&mut client).await;
assert_eq!(body.as_ref(), b"Hello, world!");
// Disconnect client.
conn.abort();
// Server task should finish soon.
let server_result = timeout(Duration::from_secs(1), server_task)
.await
.unwrap()
.unwrap();
assert!(server_result.is_ok());
}
#[ignore]
#[tokio::test]
async fn test_graceful_shutdown_timed() {
let (handle, server_task, addr) = start_server().await;
let (mut client, _conn) = connect(addr).await;
handle.graceful_shutdown(Some(Duration::from_millis(250)));
let (_parts, body) = send_empty_request(&mut client).await;
assert_eq!(body.as_ref(), b"Hello, world!");
// Don't disconnect client.
// conn.abort();
// Server task should finish soon.
let server_result = timeout(Duration::from_secs(1), server_task)
.await
.unwrap()
.unwrap();
assert!(server_result.is_ok());
}
async fn start_server() -> (Handle, JoinHandle<io::Result<()>>, SocketAddr) {
let handle = Handle::new();
let server_handle = handle.clone();
let server_task = tokio::spawn(async move {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = OpenSSLConfig::from_pem_file(
"examples/self-signed-certs/cert.pem",
"examples/self-signed-certs/key.pem",
)
.unwrap();
let addr = SocketAddr::from(([127, 0, 0, 1], 0));
tls_openssl::bind_openssl(addr, config)
.handle(server_handle)
.serve(app.into_make_service())
.await
});
let addr = handle.listening().await.unwrap();
(handle, server_task, addr)
}
async fn connect(addr: SocketAddr) -> (SendRequest<Body>, JoinHandle<()>) {
let stream = TcpStream::connect(addr).await.unwrap();
let tls_stream = tls_connector(dns_name(), stream).await;
let (send_request, connection) = handshake(tls_stream).await.unwrap();
let task = tokio::spawn(async move {
let _ = connection.await;
});
(send_request, task)
}
async fn send_empty_request(client: &mut SendRequest<Body>) -> (response::Parts, Bytes) {
let (parts, body) = client
.ready()
.await
.unwrap()
.call(Request::new(Body::empty()))
.await
.unwrap()
.into_parts();
let body = hyper::body::to_bytes(body).await.unwrap();
(parts, body)
}
async fn tls_connector(hostname: &str, stream: TcpStream) -> SslStream<TcpStream> {
let mut tls_parms = SslConnector::builder(SslMethod::tls_client()).unwrap();
tls_parms.set_verify(SslVerifyMode::NONE);
let hostname_owned = hostname.to_string();
tls_parms.set_client_hello_callback(move |ssl_ref, _ssl_alert| {
ssl_ref
.set_hostname(hostname_owned.as_str())
.map(|()| openssl::ssl::ClientHelloResponse::SUCCESS)
});
let tls_parms = tls_parms.build();
let ssl = Ssl::new(tls_parms.context()).unwrap();
let mut tls_stream = SslStream::new(ssl, stream).unwrap();
SslStream::connect(Pin::new(&mut tls_stream)).await.unwrap();
tls_stream
}
fn dns_name() -> &'static str {
"localhost"
}
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
src/tls_rustls/future.rs
|
Rust
|
//! Future types.
use crate::tls_rustls::RustlsConfig;
use pin_project_lite::pin_project;
use std::io::{Error, ErrorKind};
use std::time::Duration;
use std::{
fmt,
future::Future,
io,
pin::Pin,
task::{Context, Poll},
};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::time::{timeout, Timeout};
use tokio_rustls::{server::TlsStream, Accept, TlsAcceptor};
pin_project! {
/// Future type for [`RustlsAcceptor`](crate::tls_rustls::RustlsAcceptor).
pub struct RustlsAcceptorFuture<F, I, S> {
#[pin]
inner: AcceptFuture<F, I, S>,
config: Option<RustlsConfig>,
}
}
impl<F, I, S> RustlsAcceptorFuture<F, I, S> {
pub(crate) fn new(future: F, config: RustlsConfig, handshake_timeout: Duration) -> Self {
let inner = AcceptFuture::Inner {
future,
handshake_timeout,
};
let config = Some(config);
Self { inner, config }
}
}
impl<F, I, S> fmt::Debug for RustlsAcceptorFuture<F, I, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RustlsAcceptorFuture").finish()
}
}
pin_project! {
#[project = AcceptFutureProj]
enum AcceptFuture<F, I, S> {
Inner {
#[pin]
future: F,
handshake_timeout: Duration,
},
Accept {
#[pin]
future: Timeout<Accept<I>>,
service: Option<S>,
},
}
}
impl<F, I, S> Future for RustlsAcceptorFuture<F, I, S>
where
F: Future<Output = io::Result<(I, S)>>,
I: AsyncRead + AsyncWrite + Unpin,
{
type Output = io::Result<(TlsStream<I>, S)>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut this = self.project();
loop {
match this.inner.as_mut().project() {
AcceptFutureProj::Inner {
future,
handshake_timeout,
} => {
match future.poll(cx) {
Poll::Ready(Ok((stream, service))) => {
let server_config = this.config
.take()
.expect("config is not set. this is a bug in axum-server2, please report")
.get_inner();
let acceptor = TlsAcceptor::from(server_config);
let future = acceptor.accept(stream);
let service = Some(service);
let handshake_timeout = *handshake_timeout;
this.inner.set(AcceptFuture::Accept {
future: timeout(handshake_timeout, future),
service,
});
}
Poll::Ready(Err(e)) => return Poll::Ready(Err(e)),
Poll::Pending => return Poll::Pending,
}
}
AcceptFutureProj::Accept { future, service } => match future.poll(cx) {
Poll::Ready(Ok(Ok(stream))) => {
let service = service.take().expect("future polled after ready");
return Poll::Ready(Ok((stream, service)));
}
Poll::Ready(Ok(Err(e))) => return Poll::Ready(Err(e)),
Poll::Ready(Err(timeout)) => {
return Poll::Ready(Err(Error::new(ErrorKind::TimedOut, timeout)))
}
Poll::Pending => return Poll::Pending,
},
}
}
}
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
src/tls_rustls/mod.rs
|
Rust
|
//! Tls implementation using [`rustls`].
//!
//! # Example
//!
//! ```rust,no_run
//! use axum::{routing::get, Router};
//! use axum_server2::tls_rustls::RustlsConfig;
//! use std::net::SocketAddr;
//!
//! #[tokio::main]
//! async fn main() {
//! let app = Router::new().route("/", get(|| async { "Hello, world!" }));
//!
//! let config = RustlsConfig::from_pem_file(
//! "examples/self-signed-certs/cert.pem",
//! "examples/self-signed-certs/key.pem",
//! )
//! .await
//! .unwrap();
//!
//! let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
//! println!("listening on {}", addr);
//! axum_server2::bind_rustls(addr, config)
//! .serve(app.into_make_service())
//! .await
//! .unwrap();
//! }
//! ```
use self::future::RustlsAcceptorFuture;
use crate::{
accept::{Accept, DefaultAcceptor},
server::{io_other, Server},
};
use arc_swap::ArcSwap;
use rustls::{Certificate, PrivateKey, ServerConfig};
use std::time::Duration;
use std::{fmt, io, net::SocketAddr, path::Path, sync::Arc};
use tokio::{
io::{AsyncRead, AsyncWrite},
task::spawn_blocking,
};
use tokio_rustls::server::TlsStream;
pub(crate) mod export {
use super::*;
/// Create a tls server that will bind to provided address.
#[cfg_attr(docsrs, doc(cfg(feature = "tls-rustls")))]
pub fn bind_rustls(addr: SocketAddr, config: RustlsConfig) -> Server<RustlsAcceptor> {
super::bind_rustls(addr, config)
}
/// Create a tls server from existing `std::net::TcpListener`.
#[cfg_attr(docsrs, doc(cfg(feature = "tls-rustls")))]
pub fn from_tcp_rustls(
listener: std::net::TcpListener,
config: RustlsConfig,
) -> Server<RustlsAcceptor> {
let acceptor = RustlsAcceptor::new(config);
Server::from_tcp(listener).acceptor(acceptor)
}
}
pub mod future;
/// Create a tls server that will bind to provided address.
pub fn bind_rustls(addr: SocketAddr, config: RustlsConfig) -> Server<RustlsAcceptor> {
let acceptor = RustlsAcceptor::new(config);
Server::bind(addr).acceptor(acceptor)
}
/// Create a tls server from existing `std::net::TcpListener`.
pub fn from_tcp_rustls(
listener: std::net::TcpListener,
config: RustlsConfig,
) -> Server<RustlsAcceptor> {
let acceptor = RustlsAcceptor::new(config);
Server::from_tcp(listener).acceptor(acceptor)
}
/// Tls acceptor using rustls.
#[derive(Clone)]
pub struct RustlsAcceptor<A = DefaultAcceptor> {
inner: A,
config: RustlsConfig,
handshake_timeout: Duration,
}
impl RustlsAcceptor {
/// Create a new rustls acceptor.
pub fn new(config: RustlsConfig) -> Self {
let inner = DefaultAcceptor::new();
#[cfg(not(test))]
let handshake_timeout = Duration::from_secs(10);
// Don't force tests to wait too long.
#[cfg(test)]
let handshake_timeout = Duration::from_secs(1);
Self {
inner,
config,
handshake_timeout,
}
}
/// Override the default TLS handshake timeout of 10 seconds, except during testing.
pub fn handshake_timeout(mut self, val: Duration) -> Self {
self.handshake_timeout = val;
self
}
}
impl<A> RustlsAcceptor<A> {
/// Overwrite inner acceptor.
pub fn acceptor<Acceptor>(self, acceptor: Acceptor) -> RustlsAcceptor<Acceptor> {
RustlsAcceptor {
inner: acceptor,
config: self.config,
handshake_timeout: self.handshake_timeout,
}
}
}
impl<A, I, S> Accept<I, S> for RustlsAcceptor<A>
where
A: Accept<I, S>,
A::Stream: AsyncRead + AsyncWrite + Unpin,
{
type Stream = TlsStream<A::Stream>;
type Service = A::Service;
type Future = RustlsAcceptorFuture<A::Future, A::Stream, A::Service>;
fn accept(&self, stream: I, service: S) -> Self::Future {
let inner_future = self.inner.accept(stream, service);
let config = self.config.clone();
RustlsAcceptorFuture::new(inner_future, config, self.handshake_timeout)
}
}
impl<A> fmt::Debug for RustlsAcceptor<A> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RustlsAcceptor").finish()
}
}
/// Rustls configuration.
#[derive(Clone)]
pub struct RustlsConfig {
inner: Arc<ArcSwap<ServerConfig>>,
}
impl RustlsConfig {
/// Create config from `Arc<`[`ServerConfig`]`>`.
///
/// NOTE: You need to set ALPN protocols (like `http/1.1` or `h2`) manually.
pub fn from_config(config: Arc<ServerConfig>) -> Self {
let inner = Arc::new(ArcSwap::new(config));
Self { inner }
}
/// Create config from DER-encoded data.
///
/// The certificate must be DER-encoded X.509.
///
/// The private key must be DER-encoded ASN.1 in either PKCS#8 or PKCS#1 format.
pub async fn from_der(cert: Vec<Vec<u8>>, key: Vec<u8>) -> io::Result<Self> {
let server_config = spawn_blocking(|| config_from_der(cert, key))
.await
.unwrap()?;
let inner = Arc::new(ArcSwap::from_pointee(server_config));
Ok(Self { inner })
}
/// Create config from PEM formatted data.
///
/// Certificate and private key must be in PEM format.
pub async fn from_pem(cert: Vec<u8>, key: Vec<u8>) -> io::Result<Self> {
let server_config = spawn_blocking(|| config_from_pem(cert, key))
.await
.unwrap()?;
let inner = Arc::new(ArcSwap::from_pointee(server_config));
Ok(Self { inner })
}
/// Create config from PEM formatted files.
///
/// Contents of certificate file and private key file must be in PEM format.
pub async fn from_pem_file(cert: impl AsRef<Path>, key: impl AsRef<Path>) -> io::Result<Self> {
let server_config = config_from_pem_file(cert, key).await?;
let inner = Arc::new(ArcSwap::from_pointee(server_config));
Ok(Self { inner })
}
/// Get inner `Arc<`[`ServerConfig`]`>`.
pub fn get_inner(&self) -> Arc<ServerConfig> {
self.inner.load_full()
}
/// Reload config from `Arc<`[`ServerConfig`]`>`.
pub fn reload_from_config(&self, config: Arc<ServerConfig>) {
self.inner.store(config);
}
/// Reload config from DER-encoded data.
///
/// The certificate must be DER-encoded X.509.
///
/// The private key must be DER-encoded ASN.1 in either PKCS#8 or PKCS#1 format.
pub async fn reload_from_der(&self, cert: Vec<Vec<u8>>, key: Vec<u8>) -> io::Result<()> {
let server_config = spawn_blocking(|| config_from_der(cert, key))
.await
.unwrap()?;
let inner = Arc::new(server_config);
self.inner.store(inner);
Ok(())
}
/// Reload config from PEM formatted data.
///
/// Certificate and private key must be in PEM format.
pub async fn reload_from_pem(&self, cert: Vec<u8>, key: Vec<u8>) -> io::Result<()> {
let server_config = spawn_blocking(|| config_from_pem(cert, key))
.await
.unwrap()?;
let inner = Arc::new(server_config);
self.inner.store(inner);
Ok(())
}
/// Reload config from PEM formatted files.
///
/// Contents of certificate file and private key file must be in PEM format.
pub async fn reload_from_pem_file(
&self,
cert: impl AsRef<Path>,
key: impl AsRef<Path>,
) -> io::Result<()> {
let server_config = config_from_pem_file(cert, key).await?;
let inner = Arc::new(server_config);
self.inner.store(inner);
Ok(())
}
}
impl fmt::Debug for RustlsConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RustlsConfig").finish()
}
}
fn config_from_der(cert: Vec<Vec<u8>>, key: Vec<u8>) -> io::Result<ServerConfig> {
let cert = cert.into_iter().map(Certificate).collect();
let key = PrivateKey(key);
let mut config = ServerConfig::builder()
.with_safe_defaults()
.with_no_client_auth()
.with_single_cert(cert, key)
.map_err(io_other)?;
config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
Ok(config)
}
fn config_from_pem(cert: Vec<u8>, key: Vec<u8>) -> io::Result<ServerConfig> {
use rustls_pemfile::Item;
let cert = rustls_pemfile::certs(&mut cert.as_ref())?;
let key = match rustls_pemfile::read_one(&mut key.as_ref())? {
Some(Item::RSAKey(key)) | Some(Item::PKCS8Key(key)) | Some(Item::ECKey(key)) => key,
_ => return Err(io_other("private key format not supported")),
};
config_from_der(cert, key)
}
async fn config_from_pem_file(
cert: impl AsRef<Path>,
key: impl AsRef<Path>,
) -> io::Result<ServerConfig> {
let cert = tokio::fs::read(cert.as_ref()).await?;
let key = tokio::fs::read(key.as_ref()).await?;
config_from_pem(cert, key)
}
#[cfg(test)]
mod tests {
use crate::{
handle::Handle,
tls_rustls::{self, RustlsConfig},
};
use axum::{routing::get, Router};
use bytes::Bytes;
use http::{response, Request};
use hyper::{
client::conn::{handshake, SendRequest},
Body,
};
use rustls::{
client::{ServerCertVerified, ServerCertVerifier},
Certificate, ClientConfig, ServerName,
};
use std::{
convert::TryFrom,
io,
net::SocketAddr,
sync::Arc,
time::{Duration, SystemTime},
};
use tokio::time::sleep;
use tokio::{net::TcpStream, task::JoinHandle, time::timeout};
use tokio_rustls::TlsConnector;
use tower::{Service, ServiceExt};
#[tokio::test]
async fn start_and_request() {
let (_handle, _server_task, addr) = start_server().await;
let (mut client, _conn) = connect(addr).await;
let (_parts, body) = send_empty_request(&mut client).await;
assert_eq!(body.as_ref(), b"Hello, world!");
}
#[ignore]
#[tokio::test]
async fn tls_timeout() {
let (handle, _server_task, addr) = start_server().await;
assert_eq!(handle.connection_count(), 0);
// We intentionally avoid driving a TLS handshake to completion.
let _stream = TcpStream::connect(addr).await.unwrap();
sleep(Duration::from_millis(500)).await;
assert_eq!(handle.connection_count(), 1);
tokio::time::sleep(Duration::from_millis(1000)).await;
// Timeout defaults to 1s during testing, and we have waited 1.5 seconds.
assert_eq!(handle.connection_count(), 0);
}
#[tokio::test]
async fn test_reload() {
let handle = Handle::new();
let config = RustlsConfig::from_pem_file(
"examples/self-signed-certs/cert.pem",
"examples/self-signed-certs/key.pem",
)
.await
.unwrap();
let server_handle = handle.clone();
let rustls_config = config.clone();
tokio::spawn(async move {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let addr = SocketAddr::from(([127, 0, 0, 1], 0));
tls_rustls::bind_rustls(addr, rustls_config)
.handle(server_handle)
.serve(app.into_make_service())
.await
});
let addr = handle.listening().await.unwrap();
let cert_a = get_first_cert(addr).await;
let mut cert_b = get_first_cert(addr).await;
assert_eq!(cert_a, cert_b);
config
.reload_from_pem_file(
"examples/self-signed-certs/reload/cert.pem",
"examples/self-signed-certs/reload/key.pem",
)
.await
.unwrap();
cert_b = get_first_cert(addr).await;
assert_ne!(cert_a, cert_b);
config
.reload_from_pem_file(
"examples/self-signed-certs/cert.pem",
"examples/self-signed-certs/key.pem",
)
.await
.unwrap();
cert_b = get_first_cert(addr).await;
assert_eq!(cert_a, cert_b);
}
#[tokio::test]
async fn test_shutdown() {
let (handle, _server_task, addr) = start_server().await;
let (mut client, conn) = connect(addr).await;
handle.shutdown();
let response_future_result = client
.ready()
.await
.unwrap()
.call(Request::new(Body::empty()))
.await;
assert!(response_future_result.is_err());
// Connection task should finish soon.
let _ = timeout(Duration::from_secs(1), conn).await.unwrap();
}
#[tokio::test]
async fn test_graceful_shutdown() {
let (handle, server_task, addr) = start_server().await;
let (mut client, conn) = connect(addr).await;
handle.graceful_shutdown(None);
let (_parts, body) = send_empty_request(&mut client).await;
assert_eq!(body.as_ref(), b"Hello, world!");
// Disconnect client.
conn.abort();
// Server task should finish soon.
let server_result = timeout(Duration::from_secs(1), server_task)
.await
.unwrap()
.unwrap();
assert!(server_result.is_ok());
}
#[ignore]
#[tokio::test]
async fn test_graceful_shutdown_timed() {
let (handle, server_task, addr) = start_server().await;
let (mut client, _conn) = connect(addr).await;
handle.graceful_shutdown(Some(Duration::from_millis(250)));
let (_parts, body) = send_empty_request(&mut client).await;
assert_eq!(body.as_ref(), b"Hello, world!");
// Don't disconnect client.
// conn.abort();
// Server task should finish soon.
let server_result = timeout(Duration::from_secs(1), server_task)
.await
.unwrap()
.unwrap();
assert!(server_result.is_ok());
}
async fn start_server() -> (Handle, JoinHandle<io::Result<()>>, SocketAddr) {
let handle = Handle::new();
let server_handle = handle.clone();
let server_task = tokio::spawn(async move {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = RustlsConfig::from_pem_file(
"examples/self-signed-certs/cert.pem",
"examples/self-signed-certs/key.pem",
)
.await?;
let addr = SocketAddr::from(([127, 0, 0, 1], 0));
tls_rustls::bind_rustls(addr, config)
.handle(server_handle)
.serve(app.into_make_service())
.await
});
let addr = handle.listening().await.unwrap();
(handle, server_task, addr)
}
async fn get_first_cert(addr: SocketAddr) -> Certificate {
let stream = TcpStream::connect(addr).await.unwrap();
let tls_stream = tls_connector().connect(dns_name(), stream).await.unwrap();
let (_io, client_connection) = tls_stream.into_inner();
client_connection.peer_certificates().unwrap()[0].clone()
}
async fn connect(addr: SocketAddr) -> (SendRequest<Body>, JoinHandle<()>) {
let stream = TcpStream::connect(addr).await.unwrap();
let tls_stream = tls_connector().connect(dns_name(), stream).await.unwrap();
let (send_request, connection) = handshake(tls_stream).await.unwrap();
let task = tokio::spawn(async move {
let _ = connection.await;
});
(send_request, task)
}
async fn send_empty_request(client: &mut SendRequest<Body>) -> (response::Parts, Bytes) {
let (parts, body) = client
.ready()
.await
.unwrap()
.call(Request::new(Body::empty()))
.await
.unwrap()
.into_parts();
let body = hyper::body::to_bytes(body).await.unwrap();
(parts, body)
}
fn tls_connector() -> TlsConnector {
struct NoVerify;
impl ServerCertVerifier for NoVerify {
fn verify_server_cert(
&self,
_end_entity: &Certificate,
_intermediates: &[Certificate],
_server_name: &ServerName,
_scts: &mut dyn Iterator<Item = &[u8]>,
_ocsp_response: &[u8],
_now: SystemTime,
) -> Result<ServerCertVerified, rustls::Error> {
Ok(ServerCertVerified::assertion())
}
}
let mut client_config = ClientConfig::builder()
.with_safe_defaults()
.with_custom_certificate_verifier(Arc::new(NoVerify))
.with_no_client_auth();
client_config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
TlsConnector::from(Arc::new(client_config))
}
fn dns_name() -> ServerName {
ServerName::try_from("localhost").unwrap()
}
}
|
0x676e67/axum-server2
| 3
|
High level server designed to be used with axum framework.
|
Rust
|
0x676e67
| ||
src/config.rs
|
Rust
|
use crate::{error::Error, proxy::Proxies};
use serde::{Deserialize, Serialize};
use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
path::PathBuf,
};
#[derive(Serialize, Deserialize, Clone)]
pub struct Config {
/// Debug model
pub debug: bool,
/// Server bind address
pub bind: SocketAddr,
/// Forward timeout (seconds)
pub timeout: u64,
/// Forward connect timeout (seconds)
pub connect_timeout: u64,
/// Forward TCP keepalive (seconds)
pub tcp_keepalive: Option<u64>,
/// Server Enforces a limit on the concurrent number of requests the underlying
pub concurrent: usize,
/// Upstream proxy, support multiple proxy
/// Type: interface/proxy/cidr
pub proxies: Vec<Proxies>,
/// TLS certificate file path
pub tls_cert: Option<PathBuf>,
/// TLS private key file path (EC/PKCS8/RSA)
pub tls_key: Option<PathBuf>,
/// Authentication Key
pub api_key: Option<String>,
}
impl Default for Config {
fn default() -> Self {
Self {
debug: false,
bind: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 8080),
timeout: 60,
connect_timeout: 10,
tcp_keepalive: Some(90),
concurrent: 100,
proxies: Default::default(),
tls_cert: Default::default(),
tls_key: Default::default(),
api_key: Default::default(),
}
}
}
pub fn generate_template(path: PathBuf) -> crate::Result<()> {
// Check if the output is a directory
if path.is_dir() {
return Err(Error::IOError(std::io::Error::new(
std::io::ErrorKind::InvalidData,
format!("{} is a directory", path.display()),
)));
}
// Check if the parent directory exists
if let Some(parent) = path.parent() {
if !parent.exists() {
std::fs::create_dir_all(parent)?;
}
}
let write = |out: PathBuf| -> crate::Result<()> {
#[cfg(target_family = "unix")]
{
use std::{fs::Permissions, os::unix::prelude::PermissionsExt};
std::fs::File::create(&out)?.set_permissions(Permissions::from_mode(0o755))?;
}
#[cfg(target_family = "windows")]
std::fs::File::create(&out)?;
let yaml_config = serde_yaml::to_string(&Config::default())?;
std::fs::write(out, yaml_config).map_err(Into::into)
};
if !path.exists() {
write(path)?;
}
Ok(())
}
|
0x676e67/duckai
| 40
|
DuckDuckGo AI to OpenAI API
|
Rust
|
0x676e67
| ||
src/daemon.rs
|
Rust
|
use crate::serve;
use daemonize::Daemonize;
use std::{
fs::{File, Permissions},
os::unix::fs::PermissionsExt,
path::{Path, PathBuf},
};
const PID_PATH: &str = "/var/run/duckai.pid";
const DEFAULT_STDOUT_PATH: &str = "/var/run/duckai.out";
const DEFAULT_STDERR_PATH: &str = "/var/run/duckai.err";
/// Get the pid of the daemon
fn get_pid() -> Option<String> {
if let Ok(data) = std::fs::read(PID_PATH) {
let binding = String::from_utf8(data).expect("pid file is not utf8");
return Some(binding.trim().to_string());
}
None
}
/// Check if the current user is root
pub fn root() {
if !nix::unistd::Uid::effective().is_root() {
println!("You must run this executable with root permissions");
std::process::exit(-1)
}
}
/// Start the daemon
pub fn start(mut config_path: PathBuf) -> crate::Result<()> {
if let Some(pid) = get_pid() {
println!("duckai is already running with pid: {}", pid);
return Ok(());
}
root();
// relative path
if config_path.is_relative() {
config_path = std::env::current_dir()?.join(config_path)
}
let pid_file = File::create(PID_PATH)?;
pid_file.set_permissions(Permissions::from_mode(0o755))?;
let stdout = File::create(DEFAULT_STDOUT_PATH)?;
stdout.set_permissions(Permissions::from_mode(0o755))?;
let stderr = File::create(DEFAULT_STDERR_PATH)?;
stdout.set_permissions(Permissions::from_mode(0o755))?;
let mut daemonize = Daemonize::new()
.pid_file(PID_PATH) // Every method except `new` and `start`
.chown_pid_file(true) // is optional, see `Daemonize` documentation
.umask(0o777) // Set umask, `0o027` by default.
.stdout(stdout) // Redirect stdout to `/tmp/daemon.out`.
.stderr(stderr) // Redirect stderr to `/tmp/daemon.err`.
.privileged_action(|| "Executed before drop privileges");
if let Ok(user) = std::env::var("SUDO_USER") {
if let Ok(Some(real_user)) = nix::unistd::User::from_name(&user) {
daemonize = daemonize
.user(real_user.name.as_str())
.group(real_user.gid.as_raw());
}
}
if let Some(err) = daemonize.start().err() {
eprintln!("Error: {err}");
std::process::exit(-1)
}
serve::run(config_path)
}
/// Stop the daemon
pub fn stop() -> crate::Result<()> {
use nix::{sys::signal, unistd::Pid};
root();
if let Some(pid) = get_pid() {
let pid = pid.parse::<i32>()?;
for _ in 0..360 {
if signal::kill(Pid::from_raw(pid), signal::SIGINT).is_err() {
break;
}
std::thread::sleep(std::time::Duration::from_secs(1))
}
let _ = std::fs::remove_file(PID_PATH);
}
Ok(())
}
/// Restart the daemon
pub fn restart(config_path: PathBuf) -> crate::Result<()> {
stop()?;
start(config_path)
}
/// Show the status of the daemon
pub fn status() -> crate::Result<()> {
match get_pid() {
Some(pid) => {
let mut sys = sysinfo::System::new();
// First, we update all information of our `System` struct.
sys.refresh_all();
// Display processes ID
for (raw_pid, process) in sys.processes().iter() {
if raw_pid.as_u32().eq(&(pid.parse::<u32>()?)) {
println!("{:<6} {:<6} {:<6}", "PID", "CPU(%)", "MEM(MB)");
println!(
"{:<6} {:<6.1} {:<6.1}",
raw_pid,
process.cpu_usage(),
(process.memory() as f64) / 1024.0 / 1024.0
);
}
}
}
None => println!("duckai is not running"),
}
Ok(())
}
/// Show the log of the daemon
pub fn log() -> crate::Result<()> {
fn read_and_print_file(file_path: &Path, placeholder: &str) -> crate::Result<()> {
if !file_path.exists() {
return Ok(());
}
// Check if the file is empty before opening it
let metadata = std::fs::metadata(file_path)?;
if metadata.len() == 0 {
return Ok(());
}
let file = File::open(file_path)?;
let reader = std::io::BufReader::new(file);
let mut start = true;
use std::io::BufRead;
for line in reader.lines() {
if let Ok(content) = line {
if start {
start = false;
println!("{placeholder}");
}
println!("{}", content);
} else if let Err(err) = line {
eprintln!("Error reading line: {}", err);
}
}
Ok(())
}
let stdout_path = Path::new(DEFAULT_STDOUT_PATH);
read_and_print_file(stdout_path, "STDOUT>")?;
let stderr_path = Path::new(DEFAULT_STDERR_PATH);
read_and_print_file(stderr_path, "STDERR>")?;
Ok(())
}
|
0x676e67/duckai
| 40
|
DuckDuckGo AI to OpenAI API
|
Rust
|
0x676e67
| ||
src/error.rs
|
Rust
|
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
IOError(#[from] std::io::Error),
#[error(transparent)]
ParseIntError(#[from] std::num::ParseIntError),
#[error(transparent)]
NetworkParseError(#[from] cidr::errors::NetworkParseError),
#[error(transparent)]
AddressParseError(#[from] std::net::AddrParseError),
#[cfg(target_family = "unix")]
#[error(transparent)]
NixError(#[from] nix::Error),
#[error(transparent)]
SerdeYamlError(#[from] serde_yaml::Error),
#[error(transparent)]
RequestError(#[from] rquest::Error),
#[error(transparent)]
LogParseError(#[from] tracing_subscriber::filter::ParseError),
#[error(transparent)]
LogSetGlobalDefaultError(#[from] tracing::subscriber::SetGlobalDefaultError),
#[error(transparent)]
ResolveError(#[from] hickory_resolver::error::ResolveError),
#[error(transparent)]
JsonExtractorRejection(#[from] axum::extract::rejection::JsonRejection),
#[error(transparent)]
AxumHttpError(#[from] axum::http::Error),
#[error("Missing or invalid 'x-vqd-4' header")]
MissingHeader,
#[error("{0}")]
BadRequest(String),
#[error("You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.")]
InvalidApiKey,
#[error(transparent)]
BoringSSLConfigError(#[from] rquest::boring::ssl::Error),
}
|
0x676e67/duckai
| 40
|
DuckDuckGo AI to OpenAI API
|
Rust
|
0x676e67
| ||
src/main.rs
|
Rust
|
mod config;
#[cfg(target_family = "unix")]
mod daemon;
mod error;
mod proxy;
mod serve;
use clap::{Args, Parser, Subcommand};
pub use error::Error;
use std::path::PathBuf;
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Parser)]
#[clap(author, version, about, arg_required_else_help = true)]
#[command(args_conflicts_with_subcommands = true)]
pub struct Opt {
#[clap(subcommand)]
pub commands: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
/// Run server
Run(ConfigPath),
/// Start server daemon
#[cfg(target_family = "unix")]
Start(ConfigPath),
/// Restart server daemon
#[cfg(target_family = "unix")]
Restart(ConfigPath),
/// Stop server daemon
#[cfg(target_family = "unix")]
Stop,
/// Show the server daemon log
#[cfg(target_family = "unix")]
Log,
/// Show the server daemon process
#[cfg(target_family = "unix")]
PS,
/// Generate config template file (yaml format file)
GT(ConfigPath),
}
#[derive(Args)]
pub struct ConfigPath {
/// Configuration filepath
#[clap(default_value = "duckai.yaml")]
pub config_path: PathBuf,
}
fn main() -> Result<()> {
let opt = Opt::parse();
match opt.commands {
Commands::Run(args) => serve::run(args.config_path),
#[cfg(target_family = "unix")]
Commands::Start(args) => daemon::start(args.config_path),
#[cfg(target_family = "unix")]
Commands::Restart(args) => daemon::restart(args.config_path),
#[cfg(target_family = "unix")]
Commands::Stop => daemon::stop(),
#[cfg(target_family = "unix")]
Commands::PS => daemon::status(),
#[cfg(target_family = "unix")]
Commands::Log => daemon::log(),
Commands::GT(path) => config::generate_template(path.config_path),
}
}
|
0x676e67/duckai
| 40
|
DuckDuckGo AI to OpenAI API
|
Rust
|
0x676e67
| ||
src/proxy.rs
|
Rust
|
use cidr::IpCidr;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use std::net::IpAddr;
use url::Url;
#[derive(Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Proxies {
/// Upstream proxy, supports http, https, socks4, socks5, socks5h
URL(Url),
/// Bind to interface, supports ipv4, ipv6
Iface(IpAddr),
/// Bind to ipv6/ipv4 CIDR, ramdomly generate ipv4/ipv6 address
CIDR(IpCidr),
}
impl Debug for Proxies {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Proxies::URL(url) => write!(f, "{}", url),
Proxies::Iface(ip_addr) => write!(f, "{}", ip_addr),
Proxies::CIDR(cidr) => write!(f, "{}", cidr),
}
}
}
impl From<Url> for Proxies {
fn from(url: Url) -> Self {
Proxies::URL(url)
}
}
impl From<IpAddr> for Proxies {
fn from(ip_addr: IpAddr) -> Self {
Proxies::Iface(ip_addr)
}
}
impl From<IpCidr> for Proxies {
fn from(cidr: IpCidr) -> Self {
Proxies::CIDR(cidr)
}
}
|
0x676e67/duckai
| 40
|
DuckDuckGo AI to OpenAI API
|
Rust
|
0x676e67
| ||
src/serve/client/build.rs
|
Rust
|
use super::dns;
use hickory_resolver::config::LookupIpStrategy;
use rand::seq::SliceRandom;
use rquest::{tls::Impersonate, Client, ClientBuilder, Proxy};
use std::{net::IpAddr, time::Duration};
use typed_builder::TypedBuilder;
use url::Url;
#[derive(TypedBuilder, Clone)]
pub struct HttpConfig {
/// Timeout for each request.
timeout: u64,
/// Timeout for each connecting.
connect_timeout: u64,
/// TCP keepalive interval.
tcp_keepalive: Option<u64>,
// interface address
#[builder(default, setter(into))]
iface: Option<IpAddr>,
// proxy
#[builder(default, setter(into))]
proxy_url: Option<Url>,
}
impl HttpConfig {
pub fn set_iface(&mut self, iface: Option<IpAddr>) {
self.iface = iface;
}
}
/// Build a client
pub async fn build_client(config: HttpConfig) -> Client {
init_builder(config)
.await
.build()
.expect("Failed to build Api client")
}
/// Initialize a client builder
pub async fn init_builder(config: HttpConfig) -> ClientBuilder {
let mut builder = Client::builder();
// set proxy
builder = set_proxy(builder, config.proxy_url);
// disable keep alive
builder = set_tcp_keepalive(builder, config.tcp_keepalive);
// return lookup ip strategy
let (builder, lookup_ip_strategy) =
set_local_address_and_lookup_ip_strategy(builder, config.iface);
// init dns resolver
set_dns_resolver(builder, lookup_ip_strategy)
.await
.impersonate(random_impersonate())
.cookie_store(true)
.timeout(Duration::from_secs(config.timeout))
.connect_timeout(Duration::from_secs(config.connect_timeout))
}
fn set_proxy(builder: ClientBuilder, proxy: Option<Url>) -> ClientBuilder {
if let Some(proxy) = proxy {
// If there is only one proxy, use it
let proxy = Proxy::all(proxy).expect("Failed to create proxy");
builder.proxy(proxy)
} else {
// If there is no proxy, use the system proxy
builder
}
}
fn set_tcp_keepalive(builder: ClientBuilder, tcp_keepalive: Option<u64>) -> rquest::ClientBuilder {
match tcp_keepalive {
Some(tcp_keepalive) => builder.tcp_keepalive(Duration::from_secs(tcp_keepalive)),
None => builder.tcp_keepalive(None).pool_max_idle_per_host(0),
}
}
fn set_local_address_and_lookup_ip_strategy(
mut builder: rquest::ClientBuilder,
preferred_addrs: Option<IpAddr>,
) -> (rquest::ClientBuilder, LookupIpStrategy) {
let lookup_ip_strategy = match preferred_addrs {
Some(ip_addr) => {
builder = builder.local_address(ip_addr);
if ip_addr.is_ipv4() {
LookupIpStrategy::Ipv4Only
} else {
LookupIpStrategy::Ipv6Only
}
}
None => LookupIpStrategy::Ipv4AndIpv6,
};
(builder, lookup_ip_strategy)
}
async fn set_dns_resolver(builder: ClientBuilder, ip_s: LookupIpStrategy) -> ClientBuilder {
let trust_dns_resolver = dns::get_dns_resolver(ip_s).await;
builder.dns_resolver(trust_dns_resolver)
}
fn random_impersonate() -> Impersonate {
static VERSIONS: &'static [Impersonate] = &[
Impersonate::Chrome100,
Impersonate::Chrome101,
Impersonate::Chrome104,
Impersonate::Chrome105,
Impersonate::Chrome106,
Impersonate::Chrome107,
Impersonate::Chrome108,
Impersonate::Chrome109,
Impersonate::Chrome114,
Impersonate::Chrome116,
Impersonate::Chrome117,
Impersonate::Chrome118,
Impersonate::Chrome119,
Impersonate::Chrome120,
Impersonate::Chrome123,
Impersonate::Chrome124,
Impersonate::Chrome126,
Impersonate::Chrome127,
Impersonate::Chrome128,
Impersonate::Chrome129,
Impersonate::Chrome130,
Impersonate::Chrome131,
Impersonate::SafariIos17_2,
Impersonate::SafariIos17_4_1,
Impersonate::SafariIos16_5,
Impersonate::Safari15_3,
Impersonate::Safari15_5,
Impersonate::Safari15_6_1,
Impersonate::Safari16,
Impersonate::Safari16_5,
Impersonate::Safari17_0,
Impersonate::Safari17_2_1,
Impersonate::Safari17_4_1,
Impersonate::Safari17_5,
Impersonate::Safari18,
Impersonate::SafariIos18_1_1,
Impersonate::Safari18_2,
Impersonate::SafariIPad18,
Impersonate::OkHttp3_9,
Impersonate::OkHttp3_11,
Impersonate::OkHttp3_13,
Impersonate::OkHttp3_14,
Impersonate::OkHttp4_9,
Impersonate::OkHttp4_10,
Impersonate::OkHttp5,
Impersonate::Edge101,
Impersonate::Edge122,
Impersonate::Edge127,
Impersonate::Edge131,
Impersonate::Firefox109,
Impersonate::Firefox117,
Impersonate::Firefox133,
];
*VERSIONS
.choose(&mut rand::thread_rng())
.unwrap_or(&Impersonate::default())
}
|
0x676e67/duckai
| 40
|
DuckDuckGo AI to OpenAI API
|
Rust
|
0x676e67
| ||
src/serve/client/dns/fast.rs
|
Rust
|
use std::time::Instant;
use futures_util::future::join_all;
use hickory_resolver::{
config::{LookupIpStrategy, ResolverConfig, ResolverOpts},
TokioAsyncResolver,
};
use tokio::sync::OnceCell;
pub const FASTEST_DNS_CONFIG: OnceCell<ResolverConfig> = OnceCell::const_new();
/// Fastest DNS resolver
pub async fn load_fastest_dns() -> crate::Result<ResolverConfig> {
let mut tasks = Vec::new();
let mut opts = ResolverOpts::default();
opts.ip_strategy = LookupIpStrategy::Ipv4AndIpv6;
let configs = vec![
ResolverConfig::google(),
ResolverConfig::quad9(),
ResolverConfig::cloudflare(),
];
for config in configs {
let resolver = TokioAsyncResolver::tokio(config.clone(), opts.clone());
let task = async move {
let start = Instant::now();
let ips = resolver.lookup_ip("duckduckgo.com").await?;
let elapsed = start.elapsed();
let ips = ips.iter().collect::<Vec<_>>();
tracing::debug!("Fastest DNS resovler: {ips:?} ({elapsed:?})");
Ok((elapsed, config))
};
tasks.push(task);
}
// Join all tasks and return the fastest DNS
let r = join_all(tasks)
.await
.into_iter()
.collect::<crate::Result<Vec<_>>>()?;
if let Some((elapsed, conf)) = r.into_iter().min_by_key(|(elapsed, _)| *elapsed) {
// '\n*' split fastest_dns_group
let mut fastest_dns_group = conf
.name_servers()
.iter()
.map(|ns| ns.socket_addr.to_string())
.collect::<Vec<_>>();
// this removes all duplicates
fastest_dns_group.dedup();
tracing::info!(
"Fastest DNS group ({elapsed:?}):\n* {}",
fastest_dns_group.join("\n* ")
);
return Ok(conf);
}
Ok(ResolverConfig::default())
}
|
0x676e67/duckai
| 40
|
DuckDuckGo AI to OpenAI API
|
Rust
|
0x676e67
| ||
src/serve/client/dns/mod.rs
|
Rust
|
//! DNS resolution via the [trust_dns_resolver](https://github.com/bluejekyll/trust-dns) crate
mod fast;
use std::{
io,
net::SocketAddr,
sync::{Arc, OnceLock},
};
pub use hickory_resolver::config::{ResolverConfig, ResolverOpts};
use hickory_resolver::{
config::{LookupIpStrategy, NameServerConfigGroup},
lookup_ip::LookupIpIntoIter,
system_conf, TokioAsyncResolver,
};
use moka::future::Cache;
use rquest::dns::{Addrs, Name, Resolve, Resolving};
use tokio::sync::OnceCell;
static DNS_RESOLVER: OnceLock<Cache<u8, Arc<HickoryDnsResolver>>> = OnceLock::new();
fn from_strategy(strategy: LookupIpStrategy) -> u8 {
match strategy {
LookupIpStrategy::Ipv4Only => 0,
LookupIpStrategy::Ipv6Only => 1,
LookupIpStrategy::Ipv4AndIpv6 => 2,
LookupIpStrategy::Ipv6thenIpv4 => 3,
LookupIpStrategy::Ipv4thenIpv6 => 4,
}
}
/// Create a DNS resolver
pub async fn get_dns_resolver(ip_strategy: LookupIpStrategy) -> Arc<HickoryDnsResolver> {
// maybe DNS_RESOLVER is not initialized
let cache = DNS_RESOLVER.get_or_init(|| Cache::builder().max_capacity(5).build());
// init dns resolver cache
cache
.get_with(from_strategy(ip_strategy), async move {
Arc::new(HickoryDnsResolver::new(ip_strategy))
})
.await
}
/// Wrapper around an `AsyncResolver`, which implements the `Resolve` trait.
#[derive(Debug, Clone)]
pub(crate) struct HickoryDnsResolver {
/// Since we might not have been called in the context of a
/// Tokio Runtime in initialization, so we must delay the actual
/// construction of the resolver.
state: Arc<OnceCell<TokioAsyncResolver>>,
/// The DNS strategy to use when resolving addresses.
ip_strategy: LookupIpStrategy,
}
impl HickoryDnsResolver {
/// Create a new `TrustDnsResolver` with the default configuration,
/// which reads from `/etc/resolve.conf`.
pub(crate) fn new(ip_strategy: LookupIpStrategy) -> Self {
Self {
state: Arc::new(OnceCell::new()),
ip_strategy,
}
}
}
struct SocketAddrs {
iter: LookupIpIntoIter,
}
impl Resolve for HickoryDnsResolver {
fn resolve(&self, name: Name) -> Resolving {
let resolver = self.clone();
Box::pin(async move {
let resolver = resolver
.state
.get_or_try_init(|| new_resolver(resolver.ip_strategy))
.await?;
let lookup = resolver.lookup_ip(name.as_str()).await?;
let addrs: Addrs = Box::new(SocketAddrs {
iter: lookup.into_iter(),
});
Ok(addrs)
})
}
}
impl Iterator for SocketAddrs {
type Item = SocketAddr;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|ip_addr| SocketAddr::new(ip_addr, 0))
}
}
/// Create a new resolver with the default configuration,
/// which reads from `/etc/resolve.conf`.
async fn new_resolver(ip_strategy: LookupIpStrategy) -> io::Result<TokioAsyncResolver> {
// If we can't read the system conf, just use the defaults.
let (default_config, mut opts) = match system_conf::read_system_conf() {
Ok((config, opts)) => (config, opts),
Err(err) => {
tracing::warn!("Error reading DNS system conf: {}", err);
// Use Google DNS, Cloudflare DNS and Quad9 DNS
let mut group = NameServerConfigGroup::new();
// Google DNS
group.extend(NameServerConfigGroup::google().into_inner());
// Cloudflare DNS
group.extend(NameServerConfigGroup::cloudflare().into_inner());
// Quad9 DNS
group.extend(NameServerConfigGroup::quad9().into_inner());
let config = ResolverConfig::from_parts(None, vec![], group);
(config, ResolverOpts::default())
}
};
// Check /ect/hosts file before dns requery (only works for unix like OS)
opts.use_hosts_file = true;
// The ip_strategy for the Resolver to use when lookup Ipv4 or Ipv6 addresses
opts.ip_strategy = ip_strategy;
// Use built-in fastest DNS group
let config = fast::FASTEST_DNS_CONFIG
.get_or_try_init(fast::load_fastest_dns)
.await
.cloned()
.unwrap_or(default_config);
Ok(TokioAsyncResolver::tokio(config, opts))
}
|
0x676e67/duckai
| 40
|
DuckDuckGo AI to OpenAI API
|
Rust
|
0x676e67
| ||
src/serve/client/mod.rs
|
Rust
|
mod build;
mod dns;
mod pool;
#[cfg(target_os = "linux")]
mod route;
use crate::config;
use pool::Pool;
use std::{ops::Deref, sync::Arc};
/// Client round-robin balancer
#[derive(Clone)]
pub struct ClientLoadBalancer {
pool: Arc<Pool>,
_priv: (),
}
impl ClientLoadBalancer {
pub async fn new(conf: config::Config) -> Self {
Self {
pool: Arc::new(Pool::new(conf).await),
_priv: (),
}
}
}
impl Deref for ClientLoadBalancer {
type Target = Arc<Pool>;
fn deref(&self) -> &Self::Target {
&self.pool
}
}
|
0x676e67/duckai
| 40
|
DuckDuckGo AI to OpenAI API
|
Rust
|
0x676e67
| ||
src/serve/client/pool.rs
|
Rust
|
use super::build::{self, HttpConfig};
use crate::{config::Config, proxy::Proxies};
use cidr::IpCidr;
use rand::Rng;
use rquest::Client;
use std::{
net::IpAddr,
sync::atomic::{AtomicUsize, Ordering},
};
pub enum Pool {
Default(Client),
Ifaces {
load_factor: AtomicUsize,
clients: Vec<Client>,
},
Proxy {
load_factor: AtomicUsize,
clients: Vec<Client>,
},
CIDR {
load_factor: AtomicUsize,
config: HttpConfig,
cidr: Vec<IpCidr>,
},
}
impl Pool {
pub async fn new(conf: Config) -> Self {
// split proxy
let (proxies, ifaces, cidr): (Vec<_>, Vec<_>, Vec<_>) = conf.proxies.into_iter().fold(
(vec![], vec![], vec![]),
|(mut proxies, mut interfaces, mut cidr), proxy| {
match proxy {
Proxies::URL(v) => proxies.push(v),
Proxies::Iface(v) => interfaces.push(v),
Proxies::CIDR(v) => cidr.push(v),
}
(proxies, interfaces, cidr)
},
);
#[cfg(target_os = "linux")]
for ip_cidr in cidr.iter() {
{
super::route::sysctl_ipv6_no_local_bind();
super::route::sysctl_route_add_cidr(&ip_cidr).await;
}
}
// Priority: cidr > proxies > ifaces
match (!cidr.is_empty(), !proxies.is_empty(), !ifaces.is_empty()) {
(true, _, _) => {
let config = HttpConfig::builder()
.timeout(conf.timeout)
.connect_timeout(conf.connect_timeout)
.tcp_keepalive(conf.tcp_keepalive)
.build();
Pool::CIDR {
config,
load_factor: AtomicUsize::new(0),
cidr,
}
}
(false, true, _) => {
let mut clients = vec![];
for proxy_url in proxies {
let config = HttpConfig::builder()
.timeout(conf.timeout)
.connect_timeout(conf.connect_timeout)
.tcp_keepalive(conf.tcp_keepalive)
.proxy_url(proxy_url)
.build();
let client = build::build_client(config).await;
clients.push(client);
}
Pool::Proxy {
load_factor: AtomicUsize::new(0),
clients,
}
}
(false, false, true) => {
let mut clients = vec![];
for iface in ifaces {
let config = HttpConfig::builder()
.timeout(conf.timeout)
.connect_timeout(conf.connect_timeout)
.tcp_keepalive(conf.tcp_keepalive)
.iface(iface)
.build();
let client = build::build_client(config).await;
clients.push(client);
}
Pool::Ifaces {
load_factor: AtomicUsize::new(0),
clients,
}
}
_ => {
let config = HttpConfig::builder()
.timeout(conf.timeout)
.connect_timeout(conf.connect_timeout)
.tcp_keepalive(conf.tcp_keepalive)
.build();
Pool::Default(build::build_client(config).await)
}
}
}
#[inline]
pub async fn load_client(&self) -> Client {
match self {
Pool::Default(client) => client.clone(),
Pool::Ifaces {
clients,
load_factor,
} => {
let index = round_robin_factor(clients.len(), load_factor);
clients[index].clone()
}
Pool::Proxy {
clients,
load_factor,
} => {
let index = round_robin_factor(clients.len(), load_factor);
clients[index].clone()
}
Pool::CIDR {
load_factor,
config,
cidr,
} => {
let index = round_robin_factor(cidr.len(), load_factor);
let cidr = cidr[index];
let addr = match cidr.first_address() {
IpAddr::V4(v4) => {
let v4 = u32::from(v4);
let prefix_len = cidr.network_length();
let rand: u32 = rand::thread_rng().gen();
let net_part = (v4 >> (32 - prefix_len)) << (32 - prefix_len);
let host_part = (rand << prefix_len) >> prefix_len;
Some(IpAddr::V4((net_part | host_part).into()))
}
IpAddr::V6(v6) => {
let ipv6 = u128::from(v6);
let prefix_len = cidr.network_length();
let rand: u128 = rand::thread_rng().gen();
let net_part = (ipv6 >> (128 - prefix_len)) << (128 - prefix_len);
let host_part = (rand << prefix_len) >> prefix_len;
Some(IpAddr::V6((net_part | host_part).into()))
}
};
let mut config = config.clone();
config.set_iface(addr);
build::build_client(config).await
}
}
}
}
pub fn round_robin_factor(len: usize, counter: &AtomicUsize) -> usize {
let mut old = counter.load(Ordering::Relaxed);
let mut new;
loop {
new = (old + 1) % len;
match counter.compare_exchange_weak(old, new, Ordering::SeqCst, Ordering::Relaxed) {
Ok(_) => break,
Err(x) => old = x,
}
}
new
}
|
0x676e67/duckai
| 40
|
DuckDuckGo AI to OpenAI API
|
Rust
|
0x676e67
| ||
src/serve/client/route.rs
|
Rust
|
use futures_util::TryStreamExt;
use netlink_packet_route::{
route::{RouteAddress, RouteAttribute, RouteProtocol, RouteScope, RouteType},
AddressFamily,
};
use rtnetlink::{new_connection, Error, Handle, IpVersion};
/// Attempts to add a route to the given subnet on the loopback interface.
///
/// This function uses the `ip` command to add a route to the loopback
/// interface. It checks if the current user has root privileges before
/// attempting to add the route. If the user does not have root privileges, the
/// function returns immediately. If the `ip` command fails, it prints an error
/// message to the console.
///
/// # Arguments
///
/// * `subnet` - The subnet for which to add a route.
///
/// # Example
///
/// ```
/// let subnet = cidr::IpCidr::from_str("192.168.1.0/24").unwrap();
/// sysctl_route_add_cidr(&subnet);
/// ```
pub async fn sysctl_route_add_cidr(subnet: &cidr::IpCidr) {
if !nix::unistd::Uid::effective().is_root() {
return;
}
let (connection, handle) = match new_connection() {
Ok((connection, handle, _)) => (connection, handle),
Err(e) => {
tracing::error!("Failed to establish a connection: {e}");
return;
}
};
tokio::spawn(connection);
if let Err(e) = add_route(handle.clone(), subnet).await {
tracing::error!("{e}");
}
}
async fn add_route(handle: Handle, cidr: &cidr::IpCidr) -> Result<(), Error> {
let route = handle.route();
let iface_idx = handle
.link()
.get()
.match_name("lo".to_owned())
.execute()
.try_next()
.await?
.unwrap()
.header
.index;
// Check if the route already exists
let route_check = |ip_version: IpVersion,
address_family: AddressFamily,
destination_prefix_length: u8,
route_address: RouteAddress| async move {
let mut routes = handle.route().get(ip_version).execute();
while let Some(route) = routes.try_next().await? {
let header = route.header;
if header.address_family == address_family
&& header.destination_prefix_length == destination_prefix_length
{
for attr in route.attributes.iter() {
if let RouteAttribute::Destination(dest) = attr {
if dest == &route_address {
return Ok(true);
}
}
}
}
}
Ok(false)
};
// Add a route to the loopback interface.
match cidr {
cidr::IpCidr::V4(v4) => {
if route_check(
IpVersion::V4,
AddressFamily::Inet,
v4.network_length(),
RouteAddress::Inet(v4.first_address()),
)
.await?
{
return Ok(());
}
route
.add()
.v4()
.destination_prefix(v4.first_address(), v4.network_length())
.kind(RouteType::Local)
.protocol(RouteProtocol::Boot)
.scope(RouteScope::Universe)
.output_interface(iface_idx)
.priority(1024)
.execute()
.await?
}
cidr::IpCidr::V6(v6) => {
if route_check(
IpVersion::V6,
AddressFamily::Inet6,
v6.network_length(),
RouteAddress::Inet6(v6.first_address()),
)
.await?
{
return Ok(());
}
route
.add()
.v6()
.destination_prefix(v6.first_address(), v6.network_length())
.kind(RouteType::Local)
.protocol(RouteProtocol::Boot)
.scope(RouteScope::Universe)
.output_interface(iface_idx)
.priority(1024)
.execute()
.await?
}
}
Ok(())
}
/// Tries to disable local binding for IPv6.
///
/// This function uses the `sysctl` command to disable local binding for IPv6.
/// It checks if the current user has root privileges before attempting to
/// change the setting. If the user does not have root privileges, the function
/// returns immediately. If the `sysctl` command fails, it prints an error
/// message to the console.
///
/// # Example
///
/// ```
/// sysctl_ipv6_no_local_bind();
/// ```
pub fn sysctl_ipv6_no_local_bind() {
if !nix::unistd::Uid::effective().is_root() {
return;
}
use sysctl::Sysctl;
const CTLNAME: &str = "net.ipv6.ip_nonlocal_bind";
let ctl = <sysctl::Ctl as Sysctl>::new(CTLNAME)
.expect(&format!("could not get sysctl '{}'", CTLNAME));
let _ = ctl.name().expect("could not get sysctl name");
let old_value = ctl.value_string().expect("could not get sysctl value");
let target_value = match old_value.as_ref() {
"0" => "1",
"1" | _ => &old_value,
};
if let Err(e) = ctl.set_value_string(target_value) {
tracing::error!("Failed to set sysctl: {e}");
}
}
|
0x676e67/duckai
| 40
|
DuckDuckGo AI to OpenAI API
|
Rust
|
0x676e67
| ||
src/serve/mod.rs
|
Rust
|
mod client;
mod model;
mod route;
mod signal;
use crate::Result;
use crate::{config::Config, error::Error};
use axum::Json;
use axum::{
extract::DefaultBodyLimit,
http::StatusCode,
response::IntoResponse,
routing::{get, post},
Router,
};
use axum_extra::headers::authorization::Bearer;
use axum_extra::headers::Authorization;
use axum_extra::TypedHeader;
use axum_server::{tls_boringssl::BoringSSLConfig, Handle};
use client::ClientLoadBalancer;
use hyper_util::rt::TokioTimer;
use serde::Serialize;
use std::ops::Deref;
use std::sync::Arc;
use std::{path::PathBuf, time::Duration};
use tower::limit::ConcurrencyLimitLayer;
use tower_http::{
cors::{AllowHeaders, AllowMethods, AllowOrigin, CorsLayer},
trace::{DefaultMakeSpan, DefaultOnFailure, DefaultOnResponse, TraceLayer},
};
use tracing::Level;
use tracing_subscriber::{EnvFilter, FmtSubscriber};
use typed_builder::TypedBuilder;
#[derive(Clone, TypedBuilder)]
pub struct AppState {
client: ClientLoadBalancer,
api_key: Arc<Option<String>>,
}
impl Deref for AppState {
type Target = ClientLoadBalancer;
fn deref(&self) -> &Self::Target {
&self.client
}
}
impl AppState {
#[inline]
pub fn valid_key(
&self,
bearer: Option<TypedHeader<Authorization<Bearer>>>,
) -> crate::Result<()> {
let api_key = bearer.as_deref().map(|b| b.token());
self.api_key.as_deref().map_or(Ok(()), |key| {
if api_key.map_or(false, |api_key| api_key == key) {
Ok(())
} else {
Err(crate::Error::InvalidApiKey)
}
})
}
}
#[tokio::main]
pub async fn run(path: PathBuf) -> Result<()> {
// init config
let config = init_config(path).await?;
// init logger
init_logger(config.debug)?;
// init boot message
boot_message(&config);
// init global layer provider
let global_layer = tower::ServiceBuilder::new()
.layer(
TraceLayer::new_for_http()
.make_span_with(DefaultMakeSpan::new().level(Level::INFO))
.on_response(DefaultOnResponse::new().level(Level::INFO))
.on_failure(DefaultOnFailure::new().level(Level::WARN)),
)
.layer(
CorsLayer::new()
.allow_credentials(true)
.allow_headers(AllowHeaders::mirror_request())
.allow_methods(AllowMethods::mirror_request())
.allow_origin(AllowOrigin::mirror_request()),
)
.layer(DefaultBodyLimit::max(209715200))
.layer(ConcurrencyLimitLayer::new(config.concurrent));
let app_state = AppState::builder()
.client(ClientLoadBalancer::new(config.clone()).await)
.api_key(Arc::new(config.api_key))
.build();
let router = Router::new()
.route("/ping", get(route::ping))
.route("/v1/models", get(route::models))
.route("/v1/chat/completions", post(route::chat_completions))
.fallback(route::manual_hello)
.with_state(app_state)
.layer(global_layer);
// Signal the server to shutdown using Handle.
let handle = Handle::new();
// Spawn a task to gracefully shutdown server.
tokio::spawn(signal::graceful_shutdown(handle.clone()));
// http server tcp keepalive
let tcp_keepalive = config.tcp_keepalive.map(Duration::from_secs);
// Run http server
match (config.tls_cert.as_ref(), config.tls_key.as_ref()) {
(Some(cert), Some(key)) => {
// Load TLS configuration
let tls_config = BoringSSLConfig::from_pem_chain_file(cert, key)?;
// Use TLS configuration to create a secure server
let mut server = axum_server::bind_boringssl(config.bind, tls_config);
server
.http_builder()
.http1()
.preserve_header_case(true)
.preserve_header_case(true)
.http2()
.timer(TokioTimer::new())
.keep_alive_interval(tcp_keepalive);
server
.handle(handle)
.serve(router.into_make_service())
.await
}
_ => {
// No TLS configuration, create a non-secure server
let mut server = axum_server::bind(config.bind);
server
.http_builder()
.http1()
.preserve_header_case(true)
.preserve_header_case(true)
.http2()
.timer(TokioTimer::new())
.keep_alive_interval(tcp_keepalive);
server
.handle(handle)
.serve(router.into_make_service())
.await
}
}
.map_err(Into::into)
}
/// Print boot info message
fn boot_message(config: &Config) {
// Server info
tracing::info!("OS: {}", std::env::consts::OS);
tracing::info!("Arch: {}", std::env::consts::ARCH);
tracing::info!("Version: {}", env!("CARGO_PKG_VERSION"));
tracing::info!("Timeout {} seconds", config.timeout);
tracing::info!("Connect timeout {} seconds", config.connect_timeout);
if let Some(tcp_keepalive) = config.tcp_keepalive {
tracing::info!("Keepalive {} seconds", tcp_keepalive);
}
tracing::info!("Concurrent limit: {}", config.concurrent);
config
.proxies
.iter()
.for_each(|p| tracing::info!("Proxy: {:?}", p));
tracing::info!("Bind address: {}", config.bind);
}
/// Initialize the logger with a filter that ignores WARN level logs for netlink_proto
fn init_logger(debug: bool) -> Result<()> {
let filter = EnvFilter::from_default_env()
.add_directive(if debug { Level::DEBUG } else { Level::INFO }.into())
.add_directive("netlink_proto=error".parse()?);
tracing::subscriber::set_global_default(
FmtSubscriber::builder().with_env_filter(filter).finish(),
)?;
Ok(())
}
/// Init configuration
async fn init_config(path: PathBuf) -> Result<Config> {
if !path.is_file() {
println!("Using the default configuration");
return Ok(Config::default());
}
let data = tokio::fs::read(path).await?;
serde_yaml::from_slice::<Config>(&data).map_err(Into::into)
}
impl IntoResponse for Error {
fn into_response(self) -> axum::response::Response {
#[derive(Serialize)]
struct RootError {
error: ResponseError,
}
#[derive(Serialize, TypedBuilder)]
struct ResponseError {
message: String,
#[serde(rename = "type")]
type_field: &'static str,
#[builder(default)]
param: Option<String>,
#[builder(default)]
code: Option<String>,
}
match self {
Error::JsonExtractorRejection(json_rejection) => (
StatusCode::BAD_REQUEST,
Json(RootError {
error: ResponseError::builder()
.message(json_rejection.body_text())
.type_field("invalid_request_error")
.build(),
}),
)
.into_response(),
Error::InvalidApiKey => (
StatusCode::UNAUTHORIZED,
Json(RootError {
error: ResponseError::builder()
.message(self.to_string())
.type_field("invalid_request_error")
.build(),
}),
)
.into_response(),
_ => (
StatusCode::INTERNAL_SERVER_ERROR,
Json(RootError {
error: ResponseError::builder()
.message(self.to_string())
.type_field("server_error")
.build(),
}),
)
.into_response(),
}
}
}
|
0x676e67/duckai
| 40
|
DuckDuckGo AI to OpenAI API
|
Rust
|
0x676e67
| ||
src/serve/model.rs
|
Rust
|
use serde::{Deserialize, Deserializer, Serialize};
use typed_builder::TypedBuilder;
/// A role of a message sender, can be:
/// - `System`, for starting system message, that sets the tone of model
/// - `Assistant`, for messages sent by ChatGPT
/// - `User`, for messages sent by user
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Role {
System,
Assistant,
User,
}
impl Role {
pub fn as_str(&self) -> &'static str {
match self {
Role::System => "system",
Role::Assistant => "assistant",
Role::User => "user",
}
}
}
// ==================== Request Body ====================
#[derive(Debug, Serialize, Deserialize)]
pub struct ChatRequest {
#[serde(deserialize_with = "deserialize_model")]
model: String,
#[serde(deserialize_with = "deserialize_message")]
messages: Vec<Message>,
#[serde(skip_serializing, default)]
stream: Option<bool>,
}
impl ChatRequest {
pub fn stream(&self) -> Option<bool> {
self.stream
}
pub fn model(self) -> String {
self.model
}
}
#[derive(Debug, Serialize, Deserialize, Default, TypedBuilder)]
pub struct Message {
#[builder(default, setter(into))]
role: Option<Role>,
#[builder(default, setter(into))]
content: Option<Content>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Content {
Text(String),
Vec(Vec<ContentItem>),
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ContentItem {
#[serde(rename = "type")]
r#type: String,
text: String,
}
fn deserialize_model<'de, D>(deserializer: D) -> Result<String, D::Error>
where
D: Deserializer<'de>,
{
let model = String::deserialize(deserializer)?;
let model = match model.as_str() {
"claude-3.5-haiku" => "claude-3-5-haiku-latest",
"llama-4-scout" => "meta-llama/Llama-4-Scout-17B-16E-Instruct",
"mistral-small-3" => "mistralai/Mistral-Small-24B-Instruct-2501",
"gpt-4o-mini" => "gpt-4o-mini",
"gpt-5-mini" => "gpt-5-mini",
_ => "gpt-4o-mini",
};
Ok(model.to_owned())
}
fn deserialize_message<'de, D>(deserializer: D) -> Result<Vec<Message>, D::Error>
where
D: Deserializer<'de>,
{
let message: Vec<Message> = Vec::deserialize(deserializer)?;
let mut compression_message = Vec::with_capacity(message.len());
for mut message in message {
if let (Some(role), Some(msg)) = (message.role.as_mut(), message.content) {
if matches!(role, Role::System) {
*role = Role::User;
}
match msg {
Content::Text(msg) => {
compression_message.push(format!("{}:{};", role.as_str(), msg))
}
Content::Vec(vec) => {
for item in vec {
compression_message.push(format!("{}:{};", role.as_str(), item.text));
}
}
}
}
}
Ok(vec![Message::builder()
.role(Role::User)
.content(Content::Text(compression_message.join("\n")))
.build()])
}
// ==================== Duck APi Response Body ====================
#[derive(Deserialize)]
pub struct DuckChatCompletion {
pub message: Option<String>,
pub created: u64,
#[serde(default = "default_id")]
pub id: String,
pub model: Option<String>,
}
fn default_id() -> String {
"chatcmpl-123".to_owned()
}
// ==================== Response Body ====================
#[derive(Serialize, TypedBuilder)]
pub struct ChatCompletion<'a> {
#[builder(default, setter(into))]
#[serde(default = "default_id")]
id: Option<String>,
object: &'static str,
#[builder(default, setter(into))]
created: Option<u64>,
model: &'a str,
choices: Vec<Choice>,
#[builder(default, setter(into))]
usage: Option<Usage>,
}
#[derive(Serialize, TypedBuilder)]
pub struct Choice {
index: usize,
#[builder(default, setter(into))]
#[serde(skip_serializing_if = "Option::is_none")]
message: Option<Message>,
#[builder(default, setter(into))]
#[serde(skip_serializing_if = "Option::is_none")]
delta: Option<Message>,
#[builder(setter(into))]
logprobs: Option<String>,
#[builder(setter(into))]
finish_reason: Option<&'static str>,
}
#[derive(Serialize, TypedBuilder)]
pub struct Usage {
prompt_tokens: i32,
completion_tokens: i32,
total_tokens: i32,
}
#[derive(Serialize)]
pub struct Pong {
pub message: &'static str,
}
#[derive(Serialize, TypedBuilder)]
pub struct Models {
object: &'static str,
data: &'static [ModelData; 5],
}
#[derive(Serialize, Deserialize, TypedBuilder)]
pub struct ModelData {
id: &'static str,
#[builder(default = "model")]
object: &'static str,
#[builder(default = 1686935002)]
created: i64,
owned_by: &'static str,
}
|
0x676e67/duckai
| 40
|
DuckDuckGo AI to OpenAI API
|
Rust
|
0x676e67
| ||
src/serve/route.rs
|
Rust
|
use super::{
model::{ChatRequest, ModelData, Models, Pong},
AppState,
};
use crate::error::Error;
use crate::Result;
use axum::{extract::State, response::Response, Json};
use axum_extra::{
extract::WithRejection,
headers::{authorization::Bearer, Authorization},
TypedHeader,
};
use process::ChatProcess;
use rquest::{header, Client};
use std::sync::LazyLock;
use tracing::Instrument;
const ORIGIN_API: &str = "https://duckduckgo.com";
pub async fn manual_hello() -> &'static str {
"DuckDuckGo AI to OpenAI, Developed by penumbra-x. Go to /v1/chat/completions with POST. https://github.com/penumbra-x/duckai"
}
pub async fn ping() -> Json<Pong> {
Json(Pong { message: "pong" })
}
pub async fn models(
State(state): State<AppState>,
bearer: Option<TypedHeader<Authorization<Bearer>>>,
) -> Result<Json<Models>> {
state.valid_key(bearer)?;
static MODEL_DATA: LazyLock<[ModelData; 5]> = LazyLock::new(|| {
[
ModelData::builder()
.id("gpt-4o-mini")
.owned_by("openai")
.build(),
ModelData::builder()
.id("claude-3-haiku")
.owned_by("claude")
.build(),
ModelData::builder()
.id("llama-3.3-70b")
.owned_by("meta-llama")
.build(),
ModelData::builder()
.id("mistral-small-3")
.owned_by("mistral ai")
.build(),
ModelData::builder()
.id("o3-mini")
.owned_by("openai")
.build(),
]
});
Ok(Json(
Models::builder().object("list").data(&MODEL_DATA).build(),
))
}
pub async fn chat_completions(
State(state): State<AppState>,
bearer: Option<TypedHeader<Authorization<Bearer>>>,
WithRejection(Json(body), _): WithRejection<Json<ChatRequest>, Error>,
) -> crate::Result<Response> {
state.valid_key(bearer)?;
let client = state.load_client().await;
let token = load_token(&client).await?;
let span = tracing::info_span!("x-vqd-4", token);
send_request(client, token, body).instrument(span).await
}
async fn send_request(client: Client, token: String, body: ChatRequest) -> Result<Response> {
let resp = client
.post("https://duckduckgo.com/duckchat/v1/chat")
.header(header::ACCEPT, "text/event-stream")
.header(header::ORIGIN, ORIGIN_API)
.header(header::REFERER, ORIGIN_API)
.header("x-vqd-4", token)
.json(&body)
.send()
.await?;
ChatProcess::builder()
.resp(resp)
.stream(body.stream())
.model(body.model())
.build()
.into_response()
.await
}
async fn load_token(client: &Client) -> Result<String> {
let resp = client
.get("https://duckduckgo.com/duckchat/v1/status")
.header(header::REFERER, ORIGIN_API)
.header("x-vqd-accept", "1")
.send()
.await?
.error_for_status()?;
let token = resp
.headers()
.get("x-vqd-4")
.and_then(|header| header.to_str().ok())
.ok_or_else(|| crate::Error::MissingHeader)?;
Ok(token.to_string())
}
mod process {
use crate::serve::model::{
ChatCompletion, Choice, Content, DuckChatCompletion, Message, Role, Usage,
};
use axum::{
response::{sse::Event, IntoResponse, Response, Sse},
Error, Json,
};
use eventsource_stream::Eventsource;
use futures_util::{Stream, StreamExt};
type EventResult = Result<Event, axum::Error>;
#[derive(typed_builder::TypedBuilder)]
pub struct ChatProcess {
stream: Option<bool>,
model: String,
resp: rquest::Response,
}
impl ChatProcess {
pub async fn into_response(self) -> crate::Result<Response> {
if self.resp.error_for_status_ref().err().is_some() {
let bad_data = self.resp.text().await?;
return Err(crate::Error::BadRequest(bad_data));
}
let raw_model = self.model;
if self.stream.unwrap_or_default() {
let mut first_message = true;
let sse_stream = process_stream_with_chunk(
self.resp,
move |body| {
if let Some(content) = body.message {
let role = if first_message {
first_message = false;
Some(Role::Assistant)
} else {
None
};
let chat_completion = ChatCompletion::builder()
.id(body.id)
.model(&raw_model)
.object("chat.completion.chunk")
.created(body.created)
.choices(vec![Choice::builder()
.index(0)
.delta(
Message::builder()
.role(role)
.content(Content::Text(content))
.build(),
)
.logprobs(None)
.finish_reason(None)
.build()])
.build();
return Event::default()
.json_data(chat_completion)
.map_err(Error::new);
}
let chat_completion = ChatCompletion::builder()
.id(body.id)
.model(&raw_model)
.object("chat.completion.chunk")
.created(body.created)
.choices(vec![Choice::builder()
.index(0)
.delta(Message::default())
.logprobs(None)
.finish_reason("stop")
.build()])
.build();
if let Some(ref model) = body.model {
tracing::info!("model mapper: {} -> {}", raw_model, model);
}
Event::default()
.json_data(chat_completion)
.map_err(Error::new)
},
|event| Ok(Event::default().data(event.data)),
);
return Ok(Sse::new(sse_stream).into_response());
}
let mut id = None;
let mut created = None;
let mut model = None;
let mut content = String::new();
process_stream(self.resp, |body| {
// Update id
if id.is_none() {
id = Some(body.id);
}
// Update created time
if created.is_none() {
created = Some(body.created);
}
// Update model
if model.is_none() {
model = Some(body.model);
}
// Append chat message
if let Some(message) = body.message {
content.push_str(&message);
}
})
.await;
if let Some(Some(model)) = model {
tracing::info!("model mapper: {} -> {}", raw_model, model);
}
let chat_completion = ChatCompletion::builder()
.id(id)
.model(&raw_model)
.object("chat.completion")
.created(created)
.choices(vec![Choice::builder()
.index(0)
.message(
Message::builder()
.role(Role::Assistant)
.content(Content::Text(content))
.build(),
)
.logprobs(None)
.finish_reason("stop")
.build()])
.usage(
Usage::builder()
.completion_tokens(0)
.prompt_tokens(0)
.total_tokens(0)
.build(),
)
.build();
Ok(Json(chat_completion).into_response())
}
}
async fn process_stream<H>(resp: rquest::Response, mut handler: H)
where
H: FnMut(DuckChatCompletion),
{
let mut event_source = resp.bytes_stream().eventsource();
while let Some(event_result) = event_source.next().await {
match event_result {
Ok(event) => {
if event.data.eq("[DONE]") {
break;
}
match serde_json::from_str::<DuckChatCompletion>(&event.data) {
Ok(body) => handler(body),
Err(err) => {
tracing::warn!("failed to parse upstream body: {err}");
}
}
}
Err(err) => {
tracing::warn!("failed read upstream bytes stream: {err}")
}
}
}
}
fn process_stream_with_chunk<S, E>(
resp: rquest::Response,
mut handler: S,
end_handler: E,
) -> impl Stream<Item = EventResult>
where
S: FnMut(DuckChatCompletion) -> EventResult,
E: FnOnce(eventsource_stream::Event) -> EventResult,
{
let mut event_source = resp.bytes_stream().eventsource();
async_stream::stream! {
while let Some(event_result) = event_source.next().await {
match event_result {
Ok(event) => {
if event.data.eq("[DONE]") {
yield end_handler(event);
break;
}
match serde_json::from_str::<DuckChatCompletion>(&event.data) {
Ok(body) => yield handler(body),
Err(err) => {
tracing::warn!("failed to parse upstream body: {err}");
}
}
}
Err(err) => {
tracing::warn!("failed read upstream bytes stream: {err}")
}
}
}
}
}
}
|
0x676e67/duckai
| 40
|
DuckDuckGo AI to OpenAI API
|
Rust
|
0x676e67
| ||
src/serve/signal.rs
|
Rust
|
use std::time::Duration;
use axum_server::Handle;
#[cfg(target_family = "unix")]
use tokio::signal::unix::{signal, SignalKind};
use tokio::time::sleep;
use tracing::info;
pub(super) async fn graceful_shutdown(handle: Handle) {
#[cfg(target_family = "windows")]
{
tokio::signal::ctrl_c()
.await
.expect("Ctrl+C signal hanlde error");
sending_graceful_shutdown_signal(handle, "SIGINT").await;
}
#[cfg(target_family = "unix")]
{
let mut sigterm = signal(SignalKind::terminate()).expect("SIGTERM signal hanlde error");
let mut sigquit = signal(SignalKind::quit()).expect("SIGQUIT signal hanlde error");
let mut sigchld = signal(SignalKind::child()).expect("SIGCHLD signal hanlde error");
let mut sighup = signal(SignalKind::hangup()).expect("SIGHUP signal hanlde error");
tokio::select! {
_ = sigterm.recv() => {
sending_graceful_shutdown_signal(handle, "SIGTERM").await;
},
_ = sigquit.recv() => {
sending_graceful_shutdown_signal(handle, "SIGQUIT").await;
},
_ = sigchld.recv() => {
sending_graceful_shutdown_signal(handle, "SIGCHLD").await;
},
_ = sighup.recv() => {
sending_graceful_shutdown_signal(handle, "SIGHUP").await;
},
_ = tokio::signal::ctrl_c() => {
sending_graceful_shutdown_signal(handle, "SIGINT").await;
}
};
}
}
async fn sending_graceful_shutdown_signal(handle: Handle, signal: &'static str) {
info!("{signal} received: starting graceful shutdown");
// Signal the server to shutdown using Handle.
handle.graceful_shutdown(Some(Duration::from_secs(1)));
// Print alive connection count every second.
loop {
sleep(Duration::from_secs(1)).await;
info!("Alive connections: {}", handle.connection_count());
}
}
|
0x676e67/duckai
| 40
|
DuckDuckGo AI to OpenAI API
|
Rust
|
0x676e67
| ||
benches/hashmemo.rs
|
Rust
|
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use hashmemo::HashMemo;
use std::{
collections::HashMap,
fmt::{Display, Formatter},
hash::{BuildHasher, Hash, RandomState},
};
use ahash::RandomState as AHashBuilder;
#[derive(Clone, Eq, PartialEq, Hash)]
struct BigStruct {
name: String,
data: [u64; 64],
payload: Vec<u8>,
}
impl BigStruct {
fn new(name: String) -> Self {
Self {
name,
data: [42; 64],
payload: vec![7; 1024],
}
}
}
#[inline]
fn move_things_around<T: Eq + Hash, S: BuildHasher>(
map1: &mut HashMap<T, (), S>,
map2: &mut HashMap<T, (), S>,
steps: usize,
) {
for _ in 0..steps {
for (k, v) in map1.drain() {
map2.insert(k, v);
}
for (k, v) in map2.drain() {
map1.insert(k, v);
}
}
}
struct Param {
map_size: usize,
word_length: usize,
steps: usize,
variant: &'static str,
}
impl Display for Param {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{} elems | word_len={} | steps={} | {}",
self.map_size, self.word_length, self.steps, self.variant
)
}
}
fn bench(c: &mut Criterion) {
let mut group = c.benchmark_group("HashMemo vs AHash");
for &map_size in [100, 1000].iter() {
for &word_length in [10, 100].iter() {
for &steps in [5].iter() {
// --- Data: small string keys ---
let string_keys: Vec<_> = (0..map_size)
.map(|i| i.to_string().repeat(word_length))
.collect();
// DefaultHasher
bench_hashmap::<_, RandomState>(
&mut group,
"String",
Param {
map_size,
word_length,
steps,
variant: "DefaultHasher",
},
&string_keys,
);
bench_hashmap::<HashMemo<String>, RandomState>(
&mut group,
"HashMemo<String>",
Param {
map_size,
word_length,
steps,
variant: "DefaultHasher",
},
&string_keys
.iter()
.cloned()
.map(HashMemo::new)
.collect::<Vec<_>>(),
);
// AHash
bench_hashmap::<_, AHashBuilder>(
&mut group,
"String",
Param {
map_size,
word_length,
steps,
variant: "AHash",
},
&string_keys,
);
bench_hashmap::<HashMemo<String>, AHashBuilder>(
&mut group,
"HashMemo<String>",
Param {
map_size,
word_length,
steps,
variant: "AHash",
},
&string_keys
.iter()
.cloned()
.map(HashMemo::new)
.collect::<Vec<_>>(),
);
// --- Data: big struct ---
let bigs: Vec<_> = (0..map_size)
.map(|i| BigStruct::new(i.to_string().repeat(word_length)))
.collect();
bench_hashmap::<_, RandomState>(
&mut group,
"BigStruct",
Param {
map_size,
word_length,
steps,
variant: "DefaultHasher",
},
&bigs,
);
bench_hashmap::<HashMemo<BigStruct>, RandomState>(
&mut group,
"HashMemo<BigStruct>",
Param {
map_size,
word_length,
steps,
variant: "DefaultHasher",
},
&bigs.iter().cloned().map(HashMemo::new).collect(),
);
bench_hashmap::<_, AHashBuilder>(
&mut group,
"BigStruct",
Param {
map_size,
word_length,
steps,
variant: "AHash",
},
&bigs,
);
bench_hashmap::<HashMemo<BigStruct, ahash::RandomState>, ahash::RandomState>(
&mut group,
"HashMemo<BigStruct>",
Param {
map_size,
word_length,
steps,
variant: "AHash",
},
&bigs
.iter()
.cloned()
.map(|b| HashMemo::with_hasher(b, ahash::RandomState::default()))
.collect::<Vec<_>>(),
);
}
}
}
group.finish();
}
fn bench_hashmap<T, S>(
group: &mut criterion::BenchmarkGroup<'_, criterion::measurement::WallTime>,
name: &str,
param: Param,
data: &Vec<T>,
) where
T: Eq + Hash + Clone,
S: BuildHasher + Default,
{
group.bench_with_input(BenchmarkId::new(name, ¶m), data, |b, data| {
b.iter(|| {
let mut map: HashMap<T, (), S> = HashMap::with_hasher(S::default());
for key in data.iter().cloned() {
map.insert(key, ());
}
move_things_around(
&mut map,
&mut HashMap::with_hasher(S::default()),
param.steps,
);
});
});
}
criterion_group!(benches, bench);
criterion_main!(benches);
|
0x676e67/hashmemo
| 0
|
Hash value memoization
|
Rust
|
0x676e67
| ||
src/lib.rs
|
Rust
|
//! # HashMemo - Hash Value Memoization
//!
//! A library for memoizing hash values of complex data structures to improve performance
//! when the same data is hashed multiple times.
//!
//! This library is particularly beneficial for **large data structures** where computing
//! hash values is expensive (e.g., large strings, vectors, complex nested structures).
//! By caching the hash value after first computation, subsequent hash operations become
//! O(1) instead of O(n) where n is the size of the data.
//!
//! ## Features
//!
//! - Lazy hash computation - only calculates when needed
//! - Thread-safe caching with atomic operations
//! - Minimal memory overhead with zero-sized hashers
//! - Works with any `BuildHasher` implementation
//!
//! ## Examples
//!
//! ```rust
//! use hashmemo::HashMemo;
//! use std::collections::HashMap;
//!
//! // Wrap a large string that will be hashed multiple times
//! let large_data = "a".repeat(10000); // 10KB string
//! let memo = HashMemo::new(large_data);
//!
//! // Use in HashMap - hash is computed once and cached
//! let mut map = HashMap::new();
//! map.insert(memo, "value");
//!
//! // Subsequent operations using the same data are much faster
//! // because the hash is already cached
//! ```
//!
//! ## Performance Benefits
//!
//! The performance improvement is most significant for:
//! - Large strings or byte arrays
//! - Complex nested data structures (Vec, HashMap, etc.)
//! - Data that will be used as hash keys multiple times
//! - Concurrent scenarios where the same data is hashed by multiple threads
use std::borrow::Borrow;
use std::hash::{BuildHasher, BuildHasherDefault, DefaultHasher, Hash, Hasher};
use std::num::NonZeroU64;
use std::sync::atomic::{AtomicU64, Ordering};
/// A wrapper that memoizes the hash value of its contained data.
#[derive(Debug)]
pub struct HashMemo<T, H: BuildHasher = BuildHasherDefault<DefaultHasher>>
where
T: Eq + PartialEq + Hash,
{
value: T,
hash: AtomicU64,
hasher: H,
}
impl<T, H> PartialOrd for HashMemo<T, H>
where
T: Eq + Hash + PartialOrd,
H: BuildHasher,
{
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.value.partial_cmp(&other.value)
}
}
impl<T, H> Ord for HashMemo<T, H>
where
T: Eq + Hash + Ord,
H: BuildHasher,
{
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.value.cmp(&other.value)
}
}
impl<T> HashMemo<T, BuildHasherDefault<DefaultHasher>>
where
T: Eq + Hash,
{
/// Creates a new `HashMemo` with the default hasher.
///
/// The default hasher is `BuildHasherDefault<DefaultHasher>`, which is a zero-sized
/// type that creates `DefaultHasher` instances.
///
/// # Examples
///
/// ```rust
/// use hashmemo::HashMemo;
///
/// let memo = HashMemo::new("hello world");
/// ```
pub fn new(value: T) -> Self {
Self::with_hasher(value, BuildHasherDefault::default())
}
}
impl<T, H> HashMemo<T, H>
where
T: Eq + Hash,
H: BuildHasher,
{
/// Creates a new `HashMemo` with a custom hasher.
///
/// This allows you to specify a custom `BuildHasher` implementation for
/// controlling how hash values are computed.
///
/// # Examples
///
/// ```rust
/// use hashmemo::HashMemo;
/// use std::hash::BuildHasherDefault;
/// use std::collections::hash_map::DefaultHasher;
///
/// let memo = HashMemo::with_hasher("hello", BuildHasherDefault::<DefaultHasher>::default());
/// ```
pub const fn with_hasher(value: T, hasher: H) -> Self {
Self {
value,
hash: AtomicU64::new(u64::MIN),
hasher,
}
}
/// Consumes the `HashMemo` and returns the wrapped value.
///
/// # Examples
///
/// ```rust
/// use hashmemo::HashMemo;
///
/// let memo = HashMemo::new("hello");
/// let value = memo.into_inner();
/// assert_eq!(value, "hello");
/// ```
#[inline]
#[must_use]
pub fn into_inner(self) -> T {
self.value
}
}
impl<T, H> PartialEq for HashMemo<T, H>
where
T: Eq + Hash,
H: BuildHasher,
{
fn eq(&self, other: &Self) -> bool {
self.value == other.value
}
}
impl<T, H> Eq for HashMemo<T, H>
where
T: Eq + Hash,
H: BuildHasher,
{
}
impl<T, H> Hash for HashMemo<T, H>
where
T: Eq + Hash,
H: BuildHasher,
{
fn hash<H2: Hasher>(&self, state: &mut H2) {
let hash = self.hash.load(Ordering::Relaxed);
if hash != 0 {
state.write_u64(hash);
return;
}
let computed_hash = NonZeroU64::new(self.hasher.hash_one(&self.value))
.map(NonZeroU64::get)
.unwrap_or(u64::MIN | 1);
let _ = self.hash.compare_exchange(
u64::MIN,
computed_hash,
Ordering::Relaxed,
Ordering::Relaxed,
);
state.write_u64(computed_hash);
}
}
impl<T, H> AsRef<T> for HashMemo<T, H>
where
T: Eq + Hash,
H: BuildHasher,
{
fn as_ref(&self) -> &T {
&self.value
}
}
impl<T, H> Borrow<T> for HashMemo<T, H>
where
T: Eq + Hash,
H: BuildHasher,
{
fn borrow(&self) -> &T {
&self.value
}
}
impl<T, H> From<T> for HashMemo<T, BuildHasherDefault<H>>
where
T: Eq + Hash,
H: Hasher + Default,
{
fn from(value: T) -> Self {
Self::with_hasher(value, BuildHasherDefault::<H>::default())
}
}
impl<T, H> Clone for HashMemo<T, H>
where
T: Eq + Hash + Clone,
H: BuildHasher + Clone,
{
fn clone(&self) -> Self {
Self {
value: self.value.clone(),
hash: AtomicU64::new(self.hash.load(Ordering::Relaxed)),
hasher: self.hasher.clone(),
}
}
}
#[cfg(test)]
mod tests {
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use super::*;
fn calculate_hash<T: Hash>(t: &T) -> u64 {
calculate_hash_with_hasher::<T, DefaultHasher>(t)
}
fn calculate_hash_with_hasher<T: Hash, H: Hasher + Default>(t: &T) -> u64 {
let mut s = H::default();
t.hash(&mut s);
s.finish()
}
#[test]
fn hash_is_stable_after_clone() {
let foo = HashMemo::new("foo".to_string());
let hash = calculate_hash(&foo);
let foo2 = foo.clone();
let hash2 = calculate_hash(&foo2);
assert_eq!(hash, hash2, "Hash should remain the same after cloning");
}
#[test]
fn hash_is_consistent_on_reuse() {
let foo = HashMemo::new("foo".to_string());
let hash1 = calculate_hash(&foo);
let hash2 = calculate_hash(&foo);
let hash3 = calculate_hash(&foo);
assert_eq!(hash1, hash2);
assert_eq!(hash2, hash3);
}
#[test]
fn hash_is_cached_and_only_calculated_once() {
struct HashOnce {
hashed_once: Arc<AtomicBool>,
}
impl Eq for HashOnce {}
impl PartialEq for HashOnce {
fn eq(&self, _: &Self) -> bool {
true
}
}
impl Hash for HashOnce {
fn hash<H: Hasher>(&self, _: &mut H) {
if self.hashed_once.swap(true, Ordering::SeqCst) {
panic!("Hashing should only happen once");
}
}
}
let foo = HashMemo::new(HashOnce {
hashed_once: Arc::new(AtomicBool::new(false)),
});
for _ in 0..10 {
calculate_hash(&foo);
}
}
#[test]
fn into_inner_returns_original_value() {
let foo = HashMemo::new("foo".to_string());
let inner = HashMemo::into_inner(foo);
assert_eq!(inner, "foo".to_string());
}
#[test]
fn struct_is_not_significantly_larger_than_wrapped_value() {
assert!(
std::mem::size_of::<HashMemo<String>>()
<= std::mem::size_of::<String>() + std::mem::size_of::<u64>(),
"HashMemo should have minimal overhead"
);
}
#[test]
fn zero_hash_is_remapped_to_nonzero_in_cache() {
use nohash_hasher::NoHashHasher;
struct PinHash<const H: u64>();
impl<const H: u64> Eq for PinHash<H> {}
impl<const H: u64> PartialEq for PinHash<H> {
fn eq(&self, _: &Self) -> bool {
true
}
}
impl<const H: u64> Hash for PinHash<H> {
fn hash<HS: Hasher>(&self, state: &mut HS) {
state.write_u64(H);
}
}
// Sanity check: hash value of FixedHash<0> using dummy hasher is 0
assert_eq!(
calculate_hash_with_hasher::<PinHash<0>, NoHashHasher<u64>>(&PinHash::<0>()),
0
);
// Wrap in HashMemo and ensure it's not stored as zero
let memo: HashMemo<_, BuildHasherDefault<NoHashHasher<u64>>> = HashMemo::with_hasher(
PinHash::<0>(),
BuildHasherDefault::<NoHashHasher<u64>>::default(),
);
let _ = calculate_hash(&memo);
let cached = memo.hash.load(Ordering::Relaxed);
assert_ne!(cached, 0, "Cached hash must not be zero");
}
}
|
0x676e67/hashmemo
| 0
|
Hash value memoization
|
Rust
|
0x676e67
| ||
.github/build.sh
|
Shell
|
#!/bin/bash
: ${root=$(pwd)}
: ${tag=latest}
: ${os=linux}
: ${name=pingly}
# Function to print colored text based on log level
log() {
local level=$1
local message=$2
local NC='\033[0m' # Reset to default color
case "$level" in
"info")
echo -e "\033[0;32m[INFO] $message${NC}" # Green for INFO
;;
"warning")
echo -e "\033[0;33m[WARNING] $message${NC}" # Yellow for WARNING
;;
"error")
echo -e "\033[0;31m[ERROR] $message${NC}" # Red for ERROR
;;
*)
echo "$message" # Default to printing message without color for other levels
;;
esac
}
[ ! -d bin ] && mkdir bin
# Build support paltform target
# 1. Linux (force musl)
linux_target=(
"x86_64-unknown-linux-musl:mimalloc"
"aarch64-unknown-linux-musl:mimalloc"
"armv7-unknown-linux-musleabihf:jemalloc"
"arm-unknown-linux-musleabihf:jemalloc"
"i686-unknown-linux-musl:jemalloc"
)
# 2. MacOS
macos_target=(
"x86_64-apple-darwin"
"aarch64-apple-darwin"
)
# 3. Windows
windows_target=(
"x86_64-pc-windows-gnu"
"i686-pc-windows-gnu"
)
# Check linux rustup target installed
check_linux_rustup_target_installed() {
for target in ${linux_target[@]}; do
target=$(echo $target | cut -d':' -f1)
installed=$(rustup target list | grep "${target} (installed)")
if [ -z "$installed" ]; then
log "info" "Installing ${target}..."
rustup target add ${target}
fi
done
}
# Check macos rustup target installed
check_macos_rustup_target_installed() {
for target in ${macos_target[@]}; do
installed=$(rustup target list | grep "${target} (installed)")
if [ -z "$installed" ]; then
log "info" "Installing ${target}..."
rustup target add ${target}
fi
done
}
# Check windows rustup target installed
check_windows_rustup_target_installed() {
for target in ${windows_target[@]}; do
installed=$(rustup target list | grep "${target} (installed)")
if [ -z "$installed" ]; then
log "info" "Installing ${target}..."
rustup target add ${target}
fi
done
}
# Build linux target
build_linux_target() {
for target in "${linux_target[@]}"; do
build_target=$(echo $target | cut -d':' -f1)
feature=$(echo $target | cut -d':' -f2)
log "info" "Building ${target}..."
if cargo zigbuild --release --no-default-features --target "${build_target}" --features "${feature}"; then
compress_and_move $build_target
log "info" "Build ${target} done"
else
log "error" "Build ${target} failed"
exit 1
fi
done
}
# Build macos target
build_macos_target() {
for target in "${macos_target[@]}"; do
log "info" "Building ${target}..."
if CARGO_PROFILE_RELEASE_STRIP=none cargo zigbuild --release --no-default-features --target "${target}"; then
compress_and_move $target
log "info" "Build ${target} done"
else
log "error" "Build ${target} failed"
exit 1
fi
done
}
# Build windows target
build_windows_target() {
for target in "${windows_target[@]}"; do
log "info" "Building ${target}..."
if cargo build --release --no-default-features --target "${target}"; then
compress_and_move $target
log "info" "Build ${target} done"
else
log "error" "Build ${target} failed"
exit 1
fi
done
}
# upx and move target
compress_and_move() {
build_target=$1
target_dir="target/${build_target}/release"
bin_name=$name
if [[ $build_target == *windows* ]]; then
bin_name="${name}.exe"
fi
upx "${target_dir}/${bin_name}"
chmod +x "${target_dir}/${bin_name}"
cd "${target_dir}"
tar czvf $name-$tag-${build_target}.tar.gz $bin_name
shasum -a 256 $name-$tag-${build_target}.tar.gz >$name-$tag-${build_target}.tar.gz.sha256
mv $name-$tag-${build_target}.tar.gz $root/bin/
mv $name-$tag-${build_target}.tar.gz.sha256 $root/bin/
cd -
}
# Execute
if [ "$os" == "linux" ]; then
log "info" "Building linux target..."
check_linux_rustup_target_installed
build_linux_target
elif [ "$os" == "macos" ]; then
log "info" "Building macos target..."
check_macos_rustup_target_installed
build_macos_target
elif [ "$os" == "windows" ]; then
log "info" "Building windows target..."
check_windows_rustup_target_installed
build_windows_target
else
log "error" "Unsupported os: ${os}"
exit 1
fi
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/alloc.rs
|
Rust
|
//! Memory allocator
#[cfg(feature = "jemalloc")]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
#[cfg(feature = "tcmalloc")]
#[global_allocator]
static ALLOC: tcmalloc::TCMalloc = tcmalloc::TCMalloc;
#[cfg(feature = "mimalloc")]
#[global_allocator]
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
#[cfg(feature = "snmalloc")]
#[global_allocator]
static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
#[cfg(feature = "rpmalloc")]
#[global_allocator]
static ALLOC: rpmalloc::RpMalloc = rpmalloc::RpMalloc;
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/daemon.rs
|
Rust
|
use std::{
fs::{File, Permissions},
os::unix::fs::PermissionsExt,
path::{Path, PathBuf},
};
use daemonize::Daemonize;
use crate::{server, Args};
const DEFAULT_PID_PATH: &str = "/var/run/pingly.pid";
const DEFAULT_STDOUT_PATH: &str = "/var/run/pingly.out";
const DEFAULT_STDERR_PATH: &str = "/var/run/pingly.err";
pub struct Daemon {
pid_file: PathBuf,
stdout_file: PathBuf,
stderr_file: PathBuf,
}
impl Default for Daemon {
fn default() -> Self {
Daemon {
pid_file: PathBuf::from(DEFAULT_PID_PATH),
stdout_file: PathBuf::from(DEFAULT_STDOUT_PATH),
stderr_file: PathBuf::from(DEFAULT_STDERR_PATH),
}
}
}
impl Daemon {
/// Get the pid of the daemon
fn get_pid(&self) -> crate::Result<Option<String>> {
if let Ok(data) = std::fs::read(&self.pid_file) {
let binding = String::from_utf8(data)?;
return Ok(Some(binding.trim().to_string()));
}
Ok(None)
}
/// Check if the current user is root
fn check_root(&self) {
if !nix::unistd::Uid::effective().is_root() {
println!("You must run this executable with root permissions");
std::process::exit(-1)
}
}
/// Start the daemon
pub fn start(&self, config: Args) -> crate::Result<()> {
if let Some(pid) = self.get_pid()? {
println!("pingly is already running with pid: {pid}");
return Ok(());
}
self.check_root();
let pid_file = File::create(&self.pid_file)?;
pid_file.set_permissions(Permissions::from_mode(0o755))?;
let stdout = File::create(&self.stdout_file)?;
stdout.set_permissions(Permissions::from_mode(0o755))?;
let stderr = File::create(&self.stderr_file)?;
stderr.set_permissions(Permissions::from_mode(0o755))?;
let mut daemonize = Daemonize::new()
.pid_file(&self.pid_file)
.chown_pid_file(true)
.umask(0o777)
.stdout(stdout)
.stderr(stderr)
.privileged_action(|| "Executed before drop privileges");
if let Ok(user) = std::env::var("SUDO_USER") {
if let Ok(Some(real_user)) = nix::unistd::User::from_name(&user) {
daemonize = daemonize
.user(real_user.name.as_str())
.group(real_user.gid.as_raw());
}
}
if let Some(err) = daemonize.start().err() {
eprintln!("Error: {err}");
std::process::exit(-1)
}
server::run(config)
}
/// Stop the daemon
pub fn stop(&self) -> crate::Result<()> {
use nix::{sys::signal, unistd::Pid};
self.check_root();
if let Some(pid) = self.get_pid()? {
let pid = pid.parse::<i32>()?;
for _ in 0..360 {
if signal::kill(Pid::from_raw(pid), signal::SIGINT).is_err() {
break;
}
std::thread::sleep(std::time::Duration::from_secs(1))
}
}
std::fs::remove_file(&self.pid_file)?;
Ok(())
}
/// Restart the daemon
pub fn restart(&self, config: Args) -> crate::Result<()> {
self.stop()?;
self.start(config)
}
/// Show the status of the daemon
pub fn status(&self) -> crate::Result<()> {
match self.get_pid()? {
None => println!("pingly is not running"),
Some(pid) => {
let mut sys = sysinfo::System::new();
sys.refresh_all();
for (raw_pid, process) in sys.processes().iter() {
if raw_pid.as_u32().eq(&(pid.parse::<u32>()?)) {
println!("{:<6} {:<6} {:<6}", "PID", "CPU(%)", "MEM(MB)");
println!(
"{:<6} {:<6.1} {:<6.1}",
raw_pid,
process.cpu_usage(),
(process.memory() as f64) / 1024.0 / 1024.0
);
}
}
}
}
Ok(())
}
/// Show the log of the daemon
pub fn log(&self) -> crate::Result<()> {
fn read_and_print_file(file_path: &Path, placeholder: &str) -> crate::Result<()> {
if !file_path.exists() {
return Ok(());
}
let metadata = std::fs::metadata(file_path)?;
if metadata.len() == 0 {
return Ok(());
}
let file = File::open(file_path)?;
let reader = std::io::BufReader::new(file);
let mut start = true;
use std::io::BufRead;
for line in reader.lines() {
if let Ok(content) = line {
if start {
start = false;
println!("{placeholder}");
}
println!("{content}");
} else if let Err(err) = line {
eprintln!("Error reading line: {err}");
}
}
Ok(())
}
read_and_print_file(&self.stdout_file, "STDOUT>")?;
read_and_print_file(&self.stderr_file, "STDERR>")?;
Ok(())
}
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/error.rs
|
Rust
|
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
IO(#[from] std::io::Error),
#[error(transparent)]
ParseInt(#[from] std::num::ParseIntError),
#[error(transparent)]
AddressParse(#[from] std::net::AddrParseError),
#[cfg(target_family = "unix")]
#[error(transparent)]
Nix(#[from] nix::Error),
#[error(transparent)]
LogParse(#[from] tracing_subscriber::filter::ParseError),
#[error(transparent)]
LogSetGlobalDefault(#[from] tracing::subscriber::SetGlobalDefaultError),
#[error(transparent)]
JsonExtractorRejection(#[from] axum::extract::rejection::JsonRejection),
#[error(transparent)]
Http(#[from] axum::http::Error),
#[error(transparent)]
Rcgen(#[from] rcgen::Error),
#[error(transparent)]
Join(#[from] tokio::task::JoinError),
#[error(transparent)]
Utf8(#[from] std::string::FromUtf8Error),
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/main.rs
|
Rust
|
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
mod alloc;
#[cfg(target_family = "unix")]
mod daemon;
mod error;
mod server;
use std::{net::SocketAddr, path::PathBuf};
use clap::{Parser, Subcommand};
use error::Result;
#[derive(Parser)]
#[clap(author, version, about, arg_required_else_help = true)]
#[command(args_conflicts_with_subcommands = true)]
pub struct Opt {
#[clap(subcommand)]
pub commands: Commands,
}
#[derive(clap::Args, Clone)]
pub struct Args {
/// Debug mode
#[arg(long, default_value = "info", env = "PINGLY_LOG")]
pub log: String,
/// Bind address
#[arg(short, long, default_value = "0.0.0.0:8181")]
pub bind: SocketAddr,
/// Concurrent connections
#[arg(short, long, default_value = "1024")]
pub concurrent: usize,
/// Keep alive timeout (seconds)
#[arg(short, long, default_value = "60")]
pub keep_alive_timeout: u64,
/// TLS certificate file path
#[arg(short = 'C', long)]
pub tls_cert: Option<PathBuf>,
/// TLS private key file path (EC/PKCS8/RSA)
#[arg(short = 'K', long)]
pub tls_key: Option<PathBuf>,
/// Enable packet capture for TCP/IP analysis (requires root privileges)
#[cfg(target_os = "linux")]
#[arg(long, short = 'T')]
pub tcp_capture_packet: bool,
/// Network interface to capture packets from (default: auto-detect)
#[cfg(target_os = "linux")]
#[arg(long, short = 'I')]
pub tcp_capture_interface: Option<String>,
}
#[derive(Subcommand)]
pub enum Commands {
/// Run tracking server
Run(Args),
/// Start tracking server daemon
#[cfg(target_family = "unix")]
Start(Args),
/// Restart tracking server daemon
#[cfg(target_family = "unix")]
Restart(Args),
/// Stop tracking server daemon
#[cfg(target_family = "unix")]
Stop,
/// Show tracking server daemon log
#[cfg(target_family = "unix")]
Log,
/// Show tracking server daemon process
#[cfg(target_family = "unix")]
PS,
}
fn main() -> Result<()> {
let opt = Opt::parse();
#[cfg(target_family = "unix")]
let daemon = daemon::Daemon::default();
match opt.commands {
Commands::Run(config) => server::run(config),
#[cfg(target_family = "unix")]
Commands::Start(config) => daemon.start(config),
#[cfg(target_family = "unix")]
Commands::Restart(config) => daemon.restart(config),
#[cfg(target_family = "unix")]
Commands::Stop => daemon.stop(),
#[cfg(target_family = "unix")]
Commands::PS => daemon.status(),
#[cfg(target_family = "unix")]
Commands::Log => daemon.log(),
}
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/certificate.rs
|
Rust
|
use std::{io, path::Path, sync::Arc};
use axum_server::tls_rustls::RustlsConfig;
use rcgen::{
date_time_ymd, BasicConstraints, CertificateParams, DistinguishedName, DnType, IsCa, KeyPair,
KeyUsagePurpose, SanType,
};
use rustls_pemfile::Item;
use tokio_rustls::rustls::{
pki_types::{CertificateDer, PrivateKeyDer},
ServerConfig,
};
// Load TLS configuration from self-signed PEM files
pub async fn config_self_signed() -> crate::Result<RustlsConfig> {
let (cert, key) = get_self_signed_cert()?;
let cert = rustls_pemfile::certs(&mut cert.as_ref())
.map(|it| it.map(|it| it.to_vec()))
.collect::<Result<Vec<_>, _>>()?;
// Check the entire PEM file for the key in case it is not first section
let mut key_vec: Vec<Vec<u8>> = rustls_pemfile::read_all(&mut key.as_ref())
.filter_map(|i| match i.ok()? {
Item::Sec1Key(key) => Some(key.secret_sec1_der().to_vec()),
Item::Pkcs1Key(key) => Some(key.secret_pkcs1_der().to_vec()),
Item::Pkcs8Key(key) => Some(key.secret_pkcs8_der().to_vec()),
_ => None,
})
.collect();
// Make sure file contains only one key
if key_vec.len() != 1 {
return Err(io::Error::other("private key format not supported").into());
}
let cert = cert.into_iter().map(CertificateDer::from).collect();
let key = PrivateKeyDer::try_from(
key_vec
.pop()
.expect("private key should be present in the file"),
)
.map_err(io::Error::other)?;
Ok(config_from_der(cert, key)?)
}
/// Load TLS configuration from PEM files
pub async fn config_from_pem_chain_file(
cert: impl AsRef<Path>,
chain: impl AsRef<Path>,
) -> crate::Result<RustlsConfig> {
let cert = tokio::fs::read(cert.as_ref()).await?;
let cert = rustls_pemfile::certs(&mut cert.as_ref())
.map(|it| it.map(|it| CertificateDer::from(it.to_vec())))
.collect::<Result<Vec<_>, _>>()?;
let key = tokio::fs::read(chain.as_ref()).await?;
let key_cert: PrivateKeyDer = match rustls_pemfile::read_one(&mut key.as_ref())?
.ok_or_else(|| io::Error::other("could not parse pem file"))?
{
Item::Pkcs8Key(key) => Ok(key.into()),
Item::Sec1Key(key) => Ok(key.into()),
Item::Pkcs1Key(key) => Ok(key.into()),
x => Err(io::Error::other(format!(
"invalid certificate format, received: {x:?}"
))),
}?;
Ok(config_from_der(cert, key_cert)?)
}
fn config_from_der(
cert_chain: Vec<CertificateDer<'static>>,
key_der: PrivateKeyDer<'static>,
) -> io::Result<RustlsConfig> {
let mut config = ServerConfig::builder()
.with_no_client_auth()
.with_single_cert(cert_chain, key_der)
.map_err(io::Error::other)?;
config.alpn_protocols = vec![
b"h2".to_vec(),
b"http/1.1".to_vec(),
b"http/1.0".to_vec(),
b"http/0.9".to_vec(),
];
Ok(RustlsConfig::from_config(Arc::new(config)))
}
fn get_self_signed_cert() -> crate::Result<(Vec<u8>, Vec<u8>)> {
let temp_dir = std::env::temp_dir().join(env!("CARGO_PKG_NAME"));
if !temp_dir.exists() {
tracing::info!("Creating temp cert directory: {}", temp_dir.display());
std::fs::create_dir_all(&temp_dir)?;
}
let cert_path = temp_dir.join("cert.pem");
let key_path = temp_dir.join("key.pem");
if cert_path.exists() && key_path.exists() {
let cert = std::fs::read(cert_path)?;
let key = std::fs::read(key_path)?;
return Ok((cert, key));
}
let (cert, key) = generate_self_signed()?;
std::fs::write(cert_path, &cert)?;
std::fs::write(key_path, &key)?;
Ok((cert, key))
}
fn generate_self_signed() -> crate::Result<(Vec<u8>, Vec<u8>)> {
let mut params = CertificateParams::default();
params.not_before = date_time_ymd(1975, 1, 1);
params.not_after = date_time_ymd(4096, 1, 1);
let mut distinguished_name = DistinguishedName::new();
distinguished_name.push(DnType::CommonName, "penumbra-x");
distinguished_name.push(DnType::OrganizationName, "penumbra-x");
params.distinguished_name = distinguished_name;
params.key_usages = vec![
KeyUsagePurpose::DigitalSignature,
KeyUsagePurpose::KeyCertSign,
KeyUsagePurpose::CrlSign,
KeyUsagePurpose::KeyEncipherment,
];
params.is_ca = IsCa::Ca(BasicConstraints::Unconstrained);
params.subject_alt_names = vec![SanType::DnsName("localhost".try_into()?)];
let key_pair = KeyPair::generate()?;
let cert = params.self_signed(&key_pair)?;
let cert = cert.pem();
tracing::info!("Generating self-signed certificate:\n{}", cert);
Ok((cert.into_bytes(), key_pair.serialize_pem().into_bytes()))
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/mod.rs
|
Rust
|
mod certificate;
mod signal;
mod tracker;
use std::{net::SocketAddr, str::FromStr, time::Duration};
use axum::{
body::Body,
extract::ConnectInfo,
http::{Request, StatusCode},
response::IntoResponse,
routing::any,
Extension, Router,
};
use axum_extra::response::ErasedJson;
use axum_server::Handle;
use hyper_util::rt::TokioTimer;
use tower::{limit::ConcurrencyLimitLayer, ServiceBuilder};
use tower_http::{
cors::{AllowHeaders, AllowMethods, AllowOrigin, CorsLayer},
trace::{DefaultMakeSpan, DefaultOnFailure, DefaultOnResponse, TraceLayer},
};
use tracing::Level;
use tracing_subscriber::{EnvFilter, FmtSubscriber};
use tracker::{
accept::TrackAcceptor,
info::{ConnectionTrack, Track, TrackInfo},
};
#[cfg(target_os = "linux")]
use tracker::capture::TcpCaptureTrack;
use crate::{error::Error, Args, Result};
#[tokio::main]
pub async fn run(args: Args) -> Result<()> {
tracing::subscriber::set_global_default(
FmtSubscriber::builder()
.with_env_filter(EnvFilter::from_default_env())
.with_max_level(Level::from_str(&args.log).unwrap_or(Level::INFO))
.finish(),
)?;
tracing::info!("OS: {}", std::env::consts::OS);
tracing::info!("Arch: {}", std::env::consts::ARCH);
tracing::info!("Version: {}", env!("CARGO_PKG_VERSION"));
tracing::info!("Concurrent limit: {}", args.concurrent);
tracing::info!("Bind address: {}", args.bind);
// Init global layer
let global_layer = ServiceBuilder::new()
.layer(
TraceLayer::new_for_http()
.make_span_with(DefaultMakeSpan::new().level(Level::INFO))
.on_response(DefaultOnResponse::new().level(Level::INFO))
.on_failure(DefaultOnFailure::new().level(Level::WARN)),
)
.layer(
CorsLayer::new()
.allow_credentials(true)
.allow_headers(AllowHeaders::mirror_request())
.allow_methods(AllowMethods::mirror_request())
.allow_origin(AllowOrigin::mirror_request()),
)
.layer(ConcurrencyLimitLayer::new(args.concurrent));
// Create the router with the tracking endpoints
#[cfg_attr(not(target_os = "linux"), allow(unused_mut))]
let mut router = Router::new()
.route("/api/all", any(track))
.route("/api/tls", any(tls_track))
.route("/api/http1", any(http1_track))
.route("/api/http2", any(http2_track));
// Signal the server to shutdown using Handle.
let handle = Handle::new();
// Add TCP tracking layer
#[cfg(target_os = "linux")]
{
let mut tcp_capture_track: Option<TcpCaptureTrack> = None;
if args.tcp_capture_packet {
tracing::info!("Enabling TCP/IP packet capture (requires root)");
let capture = TcpCaptureTrack::new(128, args.bind.port());
if let Err(err) = capture.start_capture(args.tcp_capture_interface.clone()) {
tracing::error!("Failed to start TCP/IP packet capture: {err}");
} else {
if let Some(iface) = args.tcp_capture_interface {
tracing::info!(
"TCP/IP packet capture started successfully on interface {iface}"
);
}
tcp_capture_track = Some(capture);
}
}
if let Some(capture) = tcp_capture_track.clone() {
router = router
.route("/api/tcp", any(tcp_track))
.layer(Extension(capture));
}
tokio::spawn(signal::graceful_shutdown(
handle.clone(),
tcp_capture_track.clone(),
));
}
// Spawn a task to gracefully shutdown server.
#[cfg(not(target_os = "linux"))]
tokio::spawn(signal::graceful_shutdown(handle.clone()));
// Load TLS configuration with HTTP/2 ALPN preference
let config = match (args.tls_cert.as_ref(), args.tls_key.as_ref()) {
(Some(cert_path), Some(key_path)) => {
// Load TLS configuration from PEM files
certificate::config_from_pem_chain_file(cert_path, key_path).await?
}
_ => {
// Generate self-signed certificate configuration
certificate::config_self_signed().await?
}
};
// Use TLS configuration to create a secure server
let mut server = axum_server::bind_rustls(args.bind, config);
server
.http_builder()
.http2()
.timer(TokioTimer::new())
.auto_date_header(true)
.keep_alive_interval(Duration::from_secs(0))
.keep_alive_timeout(Duration::from_secs(0));
server
.handle(handle)
.map(TrackAcceptor::new)
.serve(
router
.layer(global_layer)
.into_make_service_with_connect_info::<SocketAddr>(),
)
.await
.map_err(Into::into)
}
impl IntoResponse for Error {
fn into_response(self) -> axum::response::Response {
tracing::warn!("server track error: {}", self);
(StatusCode::INTERNAL_SERVER_ERROR).into_response()
}
}
#[inline]
pub async fn track(
Extension(ConnectInfo(addr)): Extension<ConnectInfo<SocketAddr>>,
Extension(track): Extension<ConnectionTrack>,
#[cfg(target_os = "linux")] tcp_capture: Option<Extension<TcpCaptureTrack>>,
req: Request<Body>,
) -> Result<ErasedJson> {
// get TCP packets if capture is available
#[cfg(target_os = "linux")]
let tcp_packets = if let Some(Extension(capture)) = tcp_capture {
// small delay to capture packets
tokio::time::sleep(Duration::from_millis(100)).await;
let client_ip = addr.ip().to_string();
let client_port = addr.port();
let packets = capture.get_packets_for_client(&client_ip, client_port);
capture.clear_packets_for_client(&client_ip, client_port);
packets
} else {
Vec::new()
};
#[cfg(target_os = "linux")]
{
tokio::task::spawn_blocking(move || {
TrackInfo::new_with_tcp(Track::All, addr, req, track, tcp_packets)
})
.await
.map(ErasedJson::pretty)
.map_err(Error::from)
}
#[cfg(not(target_os = "linux"))]
{
tokio::task::spawn_blocking(move || TrackInfo::new(Track::All, addr, req, track))
.await
.map(ErasedJson::pretty)
.map_err(Error::from)
}
}
#[inline]
pub async fn tls_track(
Extension(ConnectInfo(addr)): Extension<ConnectInfo<SocketAddr>>,
Extension(track): Extension<ConnectionTrack>,
req: Request<Body>,
) -> Result<ErasedJson> {
tokio::task::spawn_blocking(move || TrackInfo::new(Track::Tls, addr, req, track))
.await
.map(ErasedJson::pretty)
.map_err(Error::from)
}
#[inline]
pub async fn http1_track(
Extension(ConnectInfo(addr)): Extension<ConnectInfo<SocketAddr>>,
Extension(track): Extension<ConnectionTrack>,
req: Request<Body>,
) -> Result<ErasedJson> {
tokio::task::spawn_blocking(move || TrackInfo::new(Track::HTTP1, addr, req, track))
.await
.map(ErasedJson::pretty)
.map_err(Error::from)
}
#[inline]
pub async fn http2_track(
Extension(ConnectInfo(addr)): Extension<ConnectInfo<SocketAddr>>,
Extension(track): Extension<ConnectionTrack>,
req: Request<Body>,
) -> Result<ErasedJson> {
tokio::task::spawn_blocking(move || TrackInfo::new(Track::HTTP2, addr, req, track))
.await
.map(ErasedJson::pretty)
.map_err(Error::from)
}
#[inline]
#[cfg(target_os = "linux")]
pub async fn tcp_track(
Extension(ConnectInfo(addr)): Extension<ConnectInfo<SocketAddr>>,
Extension(capture): Extension<TcpCaptureTrack>,
) -> Result<ErasedJson> {
tokio::time::sleep(Duration::from_millis(100)).await;
let client_ip = addr.ip().to_string();
let client_port = addr.port();
let packets = capture.get_packets_for_client(&client_ip, client_port);
capture.clear_packets_for_client(&client_ip, client_port);
Ok(ErasedJson::pretty(&packets))
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/signal.rs
|
Rust
|
use std::time::Duration;
use axum_server::Handle;
use tokio::time::sleep;
use tracing::info;
#[cfg(target_os = "linux")]
use super::tracker::capture::TcpCaptureTrack;
pub(super) async fn graceful_shutdown(
handle: Handle,
#[cfg(target_os = "linux")] capture: Option<TcpCaptureTrack>,
) {
tokio::signal::ctrl_c()
.await
.expect("Ctrl+C signal hanlde error");
info!("Ctrl+C signal received: starting graceful shutdown");
#[cfg(target_os = "linux")]
if let Some(capture) = capture {
capture.shutdown();
}
// Signal the server to shutdown using Handle.
handle.graceful_shutdown(Some(Duration::from_secs(1)));
// Print alive connection count every second.
loop {
sleep(Duration::from_secs(1)).await;
let connections = handle.connection_count();
info!("Alive connections: {}", connections);
// Exit the loop when all connections are closed
if connections == 0 {
info!("All connections closed, exiting gracefully");
break;
}
}
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/accept.rs
|
Rust
|
use std::io;
use axum::{middleware::AddExtension, Extension};
use axum_server::{accept::Accept, tls_rustls::RustlsAcceptor};
use futures_util::future::BoxFuture;
use tokio::io::{AsyncRead, AsyncWrite};
use tower::Layer;
use super::{
info::ConnectionTrack,
inspector::{Http1Inspector, Http2Inspector, Inspector, TlsInspector},
};
/// TrackAcceptor is a wrapper around RustlsAcceptor that inspects incoming TLS connections,
/// automatically detects the negotiated ALPN protocol (such as HTTP/1.1 or HTTP/2),
/// and wraps the stream with the appropriate Inspector type (Http1Inspector or Http2Inspector).
#[derive(Clone)]
pub struct TrackAcceptor(RustlsAcceptor);
impl TrackAcceptor {
/// Create a new [`TrackAcceptor`] with the provided RustlsAcceptor.
pub fn new(acceptor: RustlsAcceptor) -> Self {
Self(acceptor)
}
}
impl<I, S> Accept<I, S> for TrackAcceptor
where
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
S: Send + 'static,
{
type Stream = Inspector<I>;
type Service = AddExtension<S, ConnectionTrack>;
type Future = BoxFuture<'static, io::Result<(Self::Stream, Self::Service)>>;
#[inline]
fn accept(&self, stream: I, service: S) -> Self::Future {
let acceptor = self.0.clone();
Box::pin(async move {
let (mut stream, service) = acceptor.accept(TlsInspector::new(stream), service).await?;
let mut connect_track = ConnectionTrack::default();
connect_track.set_client_hello(stream.get_mut().0.client_hello());
connect_track.set_tls_version_negotiated(stream.get_ref().1.protocol_version());
let stream = match stream.get_ref().1.alpn_protocol() {
// If ALPN is set to HTTP/2, use Http2Inspector
Some(b"h2") => {
tracing::debug!("negotiated ALPN protocol: HTTP/2");
let inspector = Http2Inspector::new(stream);
connect_track.set_http2_frames(inspector.frames());
Inspector::Http2(inspector)
}
// If ALPN is not set, default to HTTP/1.1
_ => {
tracing::debug!("negotiated ALPN protocol: HTTP/1.1 or not set");
let inspector = Http1Inspector::new(stream);
connect_track.set_http1_headers(inspector.headers());
Inspector::Http1(inspector)
}
};
Ok((stream, Extension(connect_track).layer(service)))
})
}
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/capture/mod.rs
|
Rust
|
mod parser;
use std::{
collections::VecDeque,
sync::{
atomic::{AtomicBool, Ordering},
Arc, Mutex,
},
time::{SystemTime, UNIX_EPOCH},
};
use pcap::{Capture, Device};
use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CapturedPacket {
pub timestamp: u64,
pub direction: String,
pub src_ip: String,
pub dst_ip: String,
pub src_port: u16,
pub dst_port: u16,
pub protocol: String,
pub packet_size: usize,
pub parsed_info: Option<JsonValue>,
}
#[derive(Debug, Clone)]
pub struct TcpCaptureTrack {
packets: Arc<Mutex<VecDeque<CapturedPacket>>>,
max_packets: usize,
server_port: u16,
shutdown_flag: Arc<AtomicBool>,
}
impl TcpCaptureTrack {
pub fn new(max_packets: usize, server_port: u16) -> Self {
Self {
packets: Arc::new(Mutex::new(VecDeque::new())),
max_packets,
server_port,
shutdown_flag: Arc::new(AtomicBool::new(false)),
}
}
pub fn start_capture(
&self,
interface: Option<String>,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let packets = self.packets.clone();
let max_packets = self.max_packets;
let server_port = self.server_port;
let shutdown_flag = self.shutdown_flag.clone();
tracing::info!("Attempting to start packet capture on port {}", server_port);
// Test basic pcap functionality first
match self.test_pcap_basic(interface.clone()) {
Ok(device_name) => {
tracing::info!("Packet capture test passed, using device: {}", device_name);
// Spawn the actual capture task
let _ = tokio::task::spawn_blocking(move || {
if let Err(e) = run_capture_blocking(
packets,
max_packets,
server_port,
interface,
shutdown_flag,
) {
tracing::error!("Packet capture task error: {}", e);
}
});
// Give the capture task a moment to initialize before returning
std::thread::sleep(std::time::Duration::from_millis(500));
tracing::info!("Packet capture background task started");
Ok(())
}
Err(e) => {
tracing::error!("Packet capture initialization failed: {}", e);
Err(e)
}
}
}
fn test_pcap_basic(
&self,
interface: Option<String>,
) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
use pcap::{Capture, Device};
let devices = Device::list()?;
tracing::info!("Available network devices:");
for (i, device) in devices.iter().enumerate() {
tracing::info!(
" {}: {} ({})",
i,
device.name,
device
.desc
.as_ref()
.unwrap_or(&"No description".to_string())
);
}
let device = if let Some(iface) = interface {
devices
.into_iter()
.find(|d| d.name == iface)
.ok_or(format!("Interface {} not found", iface))?
} else {
// For localhost testing, prefer loopback interface over 'any'
devices
.iter()
.find(|d| d.name == "lo")
.cloned()
.or_else(|| devices.iter().find(|d| d.name == "any").cloned())
.unwrap_or_else(|| devices.into_iter().next().unwrap())
};
let use_promisc = device.name != "any";
let _test_cap = Capture::from_device(device.clone())?
.promisc(use_promisc)
.snaplen(1500)
.timeout(100)
.open()?;
Ok(device.name)
}
pub fn get_packets_for_client(&self, client_ip: &str, client_port: u16) -> Vec<CapturedPacket> {
let packets_guard = self.packets.lock().unwrap();
packets_guard
.iter()
.filter(|packet| packet.src_ip == client_ip && packet.src_port == client_port)
.cloned()
.collect()
}
pub fn clear_packets_for_client(&self, client_ip: &str, client_port: u16) {
let mut packets_guard = self.packets.lock().unwrap();
packets_guard
.retain(|packet| !(packet.src_ip == client_ip && packet.src_port == client_port));
}
pub fn shutdown(&self) {
tracing::info!("Signaling packet capture to shutdown");
self.shutdown_flag.store(true, Ordering::SeqCst);
}
}
fn run_capture_blocking(
packets: Arc<Mutex<VecDeque<CapturedPacket>>>,
max_packets: usize,
server_port: u16,
interface: Option<String>,
shutdown_flag: Arc<AtomicBool>,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let devices = Device::list()?;
let device = if let Some(iface) = interface {
devices
.into_iter()
.find(|d| d.name == iface)
.ok_or(format!("Interface {} not found", iface))?
} else {
devices
.iter()
.find(|d| d.name == "lo")
.cloned()
.or_else(|| devices.iter().find(|d| d.name == "any").cloned())
.unwrap_or_else(|| devices.into_iter().next().unwrap())
};
tracing::info!("Starting packet capture on interface: {}", device.name);
let use_promisc = device.name != "any";
let mut cap = Capture::from_device(device)?
.promisc(use_promisc)
.snaplen(65535)
.timeout(100)
.open()?;
let filter = format!("tcp and dst port {}", server_port);
tracing::info!("Setting packet filter: {}", filter);
cap.filter(&filter, true)?;
tracing::info!("Packet capture loop started, waiting for packets...");
let mut packet_count = 0;
loop {
if shutdown_flag.load(Ordering::SeqCst) {
tracing::info!("Shutdown flag is set, terminating packet capture loop");
break;
}
match cap.next_packet() {
Ok(packet) => {
packet_count += 1;
tracing::info!(
"Raw packet #{} captured, size: {} bytes",
packet_count,
packet.data.len()
);
if let Some(captured_packet) = parser::parse_packet(&packet.data, server_port) {
let mut packets_guard = packets.lock().unwrap();
if packets_guard.len() >= max_packets {
packets_guard.pop_front();
}
packets_guard.push_back(captured_packet.clone());
tracing::info!(
"Captured packet #{}: {} -> {} ({})",
packet_count,
captured_packet.src_ip,
captured_packet.dst_ip,
captured_packet.direction
);
} else {
let parsed_info = parser::parse_packet_with_pktparse(&packet.data);
let raw_packet = CapturedPacket {
timestamp: SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as u64,
direction: "unknown".to_string(),
src_ip: "unknown".to_string(),
dst_ip: "unknown".to_string(),
src_port: 0,
dst_port: server_port,
protocol: "RAW".to_string(),
packet_size: packet.data.len(),
parsed_info,
};
let mut packets_guard = packets.lock().unwrap();
if packets_guard.len() >= max_packets {
packets_guard.pop_front();
}
packets_guard.push_back(raw_packet);
tracing::warn!("Stored raw packet #{} (parsing failed)", packet_count);
}
}
Err(pcap::Error::TimeoutExpired) => {
// Timeout is normal, continue
continue;
}
Err(e) => {
tracing::error!("Packet capture error: {}", e);
std::thread::sleep(std::time::Duration::from_millis(100));
}
}
}
tracing::info!(
"Packet capture thread exiting, processed {} packets",
packet_count
);
Ok(())
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/capture/parser.rs
|
Rust
|
use std::time::{SystemTime, UNIX_EPOCH};
use serde_json::Value as JsonValue;
use super::CapturedPacket;
pub fn parse_packet_with_pktparse(data: &[u8]) -> Option<JsonValue> {
use pktparse::{ethernet, ip::IPProtocol, ipv4, ipv6, tcp};
use serde_json::{json, to_value};
// Try to parse the ethernet frame
match ethernet::parse_ethernet_frame(data) {
Ok((remaining, eth_frame)) => {
let mut parsed = json!({
"ethernet": {
"ethertype": to_value(ð_frame.ethertype).unwrap_or_else(|_| json!("unknown"))
}
});
// Parse IP layer
match eth_frame.ethertype {
ethernet::EtherType::IPv4 => {
if let Ok((tcp_udp_data, ipv4_hdr)) = ipv4::parse_ipv4_header(remaining) {
parsed["ipv4"] = to_value(&ipv4_hdr).unwrap_or_else(
|_| json!({"error": "Failed to serialize IPv4 header"}),
);
// Parse transport layer
match ipv4_hdr.protocol {
IPProtocol::TCP => {
if let Ok((payload, tcp_hdr)) = tcp::parse_tcp_header(tcp_udp_data)
{
parsed["tcp"] = to_value(&tcp_hdr).unwrap_or_else(
|_| json!({"error": "Failed to serialize TCP header"}),
);
// If there's application data, include a preview
if !payload.is_empty() {
let preview_len = std::cmp::min(payload.len(), 64);
parsed["application_data"] = json!({
"length": payload.len(),
"preview_hex": hex::encode(&payload[..preview_len]),
"preview_ascii": payload[..preview_len].iter()
.map(|&b| if b.is_ascii_graphic() || b == b' ' { b as char } else { '.' })
.collect::<String>()
});
}
}
}
_ => {
parsed["unknown_transport"] = json!({
"protocol": to_value(&ipv4_hdr.protocol).unwrap_or_else(|_| json!("unknown")),
"data_length": tcp_udp_data.len()
});
}
}
}
}
ethernet::EtherType::IPv6 => {
if let Ok((tcp_udp_data, ipv6_hdr)) = ipv6::parse_ipv6_header(remaining) {
parsed["ipv6"] = to_value(&ipv6_hdr).unwrap_or_else(
|_| json!({"error": "Failed to serialize IPv6 header"}),
);
// Parse transport layer for IPv6
match ipv6_hdr.next_header {
IPProtocol::TCP => {
if let Ok((payload, tcp_hdr)) = tcp::parse_tcp_header(tcp_udp_data)
{
parsed["tcp"] = to_value(&tcp_hdr).unwrap_or_else(
|_| json!({"error": "Failed to serialize TCP header"}),
);
// If there's application data, include a preview
if !payload.is_empty() {
let preview_len = std::cmp::min(payload.len(), 64);
parsed["application_data"] = json!({
"length": payload.len(),
"preview_hex": hex::encode(&payload[..preview_len]),
"preview_ascii": payload[..preview_len].iter()
.map(|&b| if b.is_ascii_graphic() || b == b' ' { b as char } else { '.' })
.collect::<String>()
});
}
}
}
_ => {
parsed["unknown_transport"] = json!({
"protocol": to_value(&ipv6_hdr.next_header).unwrap_or_else(|_| json!("unknown")),
"data_length": tcp_udp_data.len()
});
}
}
}
}
_ => {
parsed["unknown_protocol"] = json!({
"ethertype": to_value(ð_frame.ethertype).unwrap_or_else(|_| json!("unknown")),
"data_length": remaining.len()
});
}
}
Some(parsed)
}
Err(_) => Some(json!({
"parse_error": "Failed to parse ethernet frame",
"raw_data_length": data.len(),
"raw_data_preview": hex::encode(&data[..std::cmp::min(data.len(), 32)])
})),
}
}
pub fn parse_packet(data: &[u8], server_port: u16) -> Option<CapturedPacket> {
use pnet::packet::{
ethernet::{EtherTypes, EthernetPacket},
ip::IpNextHeaderProtocols,
ipv4::Ipv4Packet,
ipv6::Ipv6Packet,
tcp::TcpPacket,
Packet,
};
let ethernet = EthernetPacket::new(data)?;
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as u64;
let parsed_info = parse_packet_with_pktparse(data);
match ethernet.get_ethertype() {
EtherTypes::Ipv4 => {
let ipv4 = Ipv4Packet::new(ethernet.payload())?;
if ipv4.get_next_level_protocol() == IpNextHeaderProtocols::Tcp {
let tcp = TcpPacket::new(ipv4.payload())?;
let src_port = tcp.get_source();
let dst_port = tcp.get_destination();
if dst_port == server_port {
return Some(CapturedPacket {
timestamp,
direction: "inbound".to_string(),
src_ip: ipv4.get_source().to_string(),
dst_ip: ipv4.get_destination().to_string(),
src_port,
dst_port,
protocol: "TCP".to_string(),
packet_size: data.len(),
parsed_info,
});
}
}
}
EtherTypes::Ipv6 => {
let ipv6 = Ipv6Packet::new(ethernet.payload())?;
if ipv6.get_next_header() == IpNextHeaderProtocols::Tcp {
let tcp = TcpPacket::new(ipv6.payload())?;
let src_port = tcp.get_source();
let dst_port = tcp.get_destination();
if dst_port == server_port {
return Some(CapturedPacket {
timestamp,
direction: "inbound".to_string(),
src_ip: ipv6.get_source().to_string(),
dst_ip: ipv6.get_destination().to_string(),
src_port,
dst_port,
protocol: "TCP".to_string(),
packet_size: data.len(),
parsed_info,
});
}
}
}
_ => {}
}
None
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/info.rs
|
Rust
|
use std::net::SocketAddr;
use axum::{
body::Body,
http::{header::USER_AGENT, HeaderValue, Method, Request},
};
use serde::{Serialize, Serializer};
use tokio_rustls::rustls::ProtocolVersion;
use super::inspector::{ClientHello, Frame, Http1Headers, Http2Frame, LazyClientHello};
#[cfg(target_os = "linux")]
use super::capture::CapturedPacket;
/// TLS handshake tracking information, which includes the client hello payload.
#[derive(Serialize)]
pub struct TlsTrackInfo(ClientHello);
/// HTTP/1.x request header tracking information.
pub struct Http1TrackInfo(Http1Headers);
/// HTTP/2 tracking information, including Akamai fingerprint and sent frames.
#[derive(Serialize)]
pub struct Http2TrackInfo {
akamai_fingerprint: String,
akamai_fingerprint_hash: String,
#[serde(serialize_with = "serialize_sent_frames")]
sent_frames: Http2Frame,
}
/// Collects TLS, HTTP/1, and HTTP/2 handshake info for tracking.
#[derive(Clone, Default)]
pub struct ConnectionTrack {
/// The TLS protocol version that was negotiated for this connection, if any.
tls_version_negotiated: Option<ProtocolVersion>,
client_hello: Option<LazyClientHello>,
http1_headers: Option<Http1Headers>,
http2_frames: Option<Http2Frame>,
}
/// TrackInfo aggregates tracking details for a single connection,
/// including TLS handshake info, HTTP/1 headers, and HTTP/2 frames.
/// Useful for logging, analysis, or debugging connection
#[derive(Serialize)]
pub struct TrackInfo {
donate: &'static str,
address: SocketAddr,
http_version: String,
#[serde(serialize_with = "serialize_method")]
method: Method,
#[serde(serialize_with = "serialize_user_agent")]
user_agent: Option<HeaderValue>,
#[serde(skip_serializing_if = "Option::is_none")]
tls: Option<TlsTrackInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
http1: Option<Http1TrackInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
http2: Option<Http2TrackInfo>,
#[cfg(target_os = "linux")]
#[serde(skip_serializing_if = "Vec::is_empty")]
tcp: Vec<CapturedPacket>,
}
/// Track enum to specify which tracking information to collect.
#[repr(u8)]
pub enum Track {
All,
Tls,
HTTP1,
HTTP2,
}
// ==== impl Http1TrackInfo ====
impl TlsTrackInfo {
/// Create a new [`TlsTrackInfo`] instance.
pub fn new(client_hello: ClientHello) -> TlsTrackInfo {
TlsTrackInfo(client_hello)
}
}
// ==== impl Http1TrackInfo ====
impl Http1TrackInfo {
/// Create a new [`Http1TrackInfo`] instance.
pub fn new(headers: Http1Headers) -> Http1TrackInfo {
Http1TrackInfo(headers)
}
}
impl Serialize for Http1TrackInfo {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
use serde::ser::SerializeSeq;
let mut seq = serializer.serialize_seq(Some(self.0.count()))?;
for (_, (name, value)) in self.0.iter() {
let s = format!(
"{}: {}",
String::from_utf8_lossy(name),
String::from_utf8_lossy(value)
);
seq.serialize_element(&s)?;
}
seq.end()
}
}
// ==== impl Http2TrackInfo ====
impl Http2TrackInfo {
/// Create a new [`Http2TrackInfo`] instance.
pub fn new(sent_frames: Http2Frame) -> Option<Http2TrackInfo> {
if sent_frames.is_empty() {
return None;
}
let akamai_fingerprint = compute_akamai_fingerprint(&sent_frames);
let akamai_fingerprint_hash = compute_akamai_fingerprint_hash(&akamai_fingerprint);
Some(Self {
akamai_fingerprint,
akamai_fingerprint_hash,
sent_frames,
})
}
}
/// Compute the Akamai fingerprint hash from the Akamai fingerprint
fn compute_akamai_fingerprint_hash(akamai_fingerprint: &str) -> String {
let hash = md5::compute(akamai_fingerprint);
hex::encode(hash.as_slice())
}
/// Compute the Akamai fingerprint from the sent frames
///
/// The Akamai fingerprint is a string of 16 bytes that is computed from the sent frames.
/// It is used to identify the client and the server.
fn compute_akamai_fingerprint(sent_frames: &Http2Frame) -> String {
let mut setting_group = Vec::new();
let mut window_update_group = None;
let mut priority_group = None;
let mut headers_group = Vec::with_capacity(4);
for (_, frame) in sent_frames.iter() {
match frame {
Frame::Settings(frame) => {
for setting in &frame.settings {
let (id, value) = setting.value();
setting_group.push(format!("{id}:{value}"));
}
}
Frame::WindowUpdate(frame) => {
window_update_group = Some(frame.increment);
}
Frame::Priority(frame) => {
let priority_group = priority_group.get_or_insert_with(Vec::new);
priority_group.push(format!(
"{}:{}:{}:{}",
frame.stream_id,
frame.priority.exclusive,
frame.priority.depends_on,
frame.priority.weight + 1
));
}
Frame::Headers(frame) => {
headers_group.push(format!("{}", frame.stream_id));
headers_group.push(
frame
.pseudo_headers
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(","),
);
headers_group.push(format!("{}", frame.flags.0));
if let Some(ref priority) = frame.priority {
headers_group.push(format!(
"{}:{}:{}",
priority.exclusive, priority.depends_on, priority.weight
));
}
}
Frame::Unknown(v) => {
tracing::trace!("Unknown http2 frame: {:?}", v);
}
}
}
let mut akamai_fingerprint = Vec::with_capacity(3);
akamai_fingerprint.push(setting_group.join(";"));
if let Some(window_update_group) = window_update_group {
akamai_fingerprint.push(window_update_group.to_string());
}
if let Some(priority_group) = priority_group {
akamai_fingerprint.push(priority_group.join(","));
}
akamai_fingerprint.push(headers_group.join(";"));
akamai_fingerprint.join("|")
}
fn serialize_sent_frames<S>(sent_frames: &Http2Frame, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let vec = sent_frames
.iter()
.map(|(_, value)| value)
.collect::<Vec<_>>();
vec.serialize(serializer)
}
// ==== impl ConnectionTrack ====
impl ConnectionTrack {
/// Set TLS version negotiated during the handshake.
#[inline]
pub fn set_tls_version_negotiated(&mut self, version: Option<ProtocolVersion>) {
self.tls_version_negotiated = version;
}
/// Set TLS client hello
#[inline]
pub fn set_client_hello(&mut self, client_hello: Option<LazyClientHello>) {
self.client_hello = client_hello;
}
/// Set HTTP/1 headers
#[inline]
pub fn set_http1_headers(&mut self, headers: Http1Headers) {
self.http1_headers = Some(headers);
}
/// Set HTTP/2 frames
#[inline]
pub fn set_http2_frames(&mut self, frames: Http2Frame) {
self.http2_frames = Some(frames);
}
}
// ==== impl TrackInfo ====
impl TrackInfo {
const DONATE_URL: &'static str = "Analysis server for TLS and HTTP/1/2/3, developed by 0x676e67: https://github.com/0x676e67/pingly";
/// Create a new [`TrackInfo`] instance.
#[inline]
pub fn new(
track: Track,
addr: SocketAddr,
req: Request<Body>,
connection_track: ConnectionTrack,
) -> TrackInfo {
#[cfg(target_os = "linux")]
return Self::new_with_tcp(track, addr, req, connection_track, Vec::new());
#[cfg(not(target_os = "linux"))]
{
let mut tls = connection_track
.client_hello
.and_then(LazyClientHello::parse)
.map(TlsTrackInfo::new);
if let Some(tls) = tls.as_mut() {
tls.0
.set_tls_version_negotiated(connection_track.tls_version_negotiated);
}
let track_info = TrackInfo {
donate: Self::DONATE_URL,
address: addr,
http_version: format!("{:?}", req.version()),
method: req.method().clone(),
user_agent: req.headers().get(USER_AGENT).cloned(),
tls,
http1: connection_track.http1_headers.map(Http1TrackInfo::new),
http2: connection_track.http2_frames.and_then(Http2TrackInfo::new),
};
match track {
Track::All => track_info,
Track::Tls => TrackInfo {
http1: None,
http2: None,
..track_info
},
Track::HTTP1 => TrackInfo {
tls: None,
http2: None,
..track_info
},
Track::HTTP2 => TrackInfo {
tls: None,
http1: None,
..track_info
},
}
}
}
/// Create a new [`TrackInfo`] instance with TCP data.
#[inline]
#[cfg(target_os = "linux")]
pub fn new_with_tcp(
track: Track,
addr: SocketAddr,
req: Request<Body>,
connection_track: ConnectionTrack,
tcp_packets: Vec<CapturedPacket>,
) -> TrackInfo {
let mut tls = connection_track
.client_hello
.and_then(LazyClientHello::parse)
.map(TlsTrackInfo::new);
if let Some(tls) = tls.as_mut() {
tls.0
.set_tls_version_negotiated(connection_track.tls_version_negotiated);
}
let track_info = TrackInfo {
donate: Self::DONATE_URL,
address: addr,
http_version: format!("{:?}", req.version()),
method: req.method().clone(),
user_agent: req.headers().get(USER_AGENT).cloned(),
tls,
http1: connection_track.http1_headers.map(Http1TrackInfo::new),
http2: connection_track.http2_frames.and_then(Http2TrackInfo::new),
#[cfg(target_os = "linux")]
tcp: tcp_packets,
};
match track {
Track::All => track_info,
Track::Tls => TrackInfo {
http1: None,
http2: None,
#[cfg(target_os = "linux")]
tcp: Vec::new(),
..track_info
},
Track::HTTP1 => TrackInfo {
tls: None,
http2: None,
#[cfg(target_os = "linux")]
tcp: Vec::new(),
..track_info
},
Track::HTTP2 => TrackInfo {
tls: None,
http1: None,
#[cfg(target_os = "linux")]
tcp: Vec::new(),
..track_info
},
}
}
}
fn serialize_user_agent<S>(value: &Option<HeaderValue>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match value {
Some(value) => value
.to_str()
.map_err(serde::ser::Error::custom)
.and_then(|s| serializer.serialize_str(s)),
None => serializer.serialize_none(),
}
}
fn serialize_method<S>(method: &Method, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(method.as_str())
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/inspector/http1.rs
|
Rust
|
use std::{ops::Deref, pin::Pin, sync::Arc, task, task::Poll};
use bytes::Bytes;
use pin_project_lite::pin_project;
use tokio::io::{self, AsyncRead, AsyncWrite, ReadBuf};
use tokio_rustls::server::TlsStream;
use super::tls::TlsInspector;
pub type Http1Headers = Arc<boxcar::Vec<(Bytes, Bytes)>>;
pin_project! {
/// A wrapper over a TLS stream that inspects HTTP/1.x traffic.
/// It buffers incoming data, parses HTTP/1 request headers,
/// and records parsed headers for later inspection or analysis.
/// Does not interfere with normal stream reading or writing.
pub struct Http1Inspector<I> {
#[pin]
inner: TlsStream<TlsInspector<I>>,
buf: Vec<u8>,
headers: Http1Headers,
}
}
impl<I> Http1Inspector<I>
where
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
/// Create a new [`Http1Inspector`] instance.
#[inline]
pub fn new(inner: TlsStream<TlsInspector<I>>) -> Self {
Self {
inner,
buf: Vec::new(),
headers: Arc::new(boxcar::Vec::new()),
}
}
/// Get previously parsed HTTP/1 headers
#[inline]
pub fn headers(&self) -> Http1Headers {
self.headers.clone()
}
}
impl<I> AsyncRead for Http1Inspector<I>
where
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
fn poll_read(
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
let this = self.project();
let prev_len = buf.filled().len();
let poll = this.inner.poll_read(cx, buf);
// Only process new data
let new_data = &buf.filled()[prev_len..];
if !new_data.is_empty() {
this.buf.extend_from_slice(new_data);
// Try to parse headers
let mut headers = [httparse::EMPTY_HEADER; 64];
let mut req = httparse::Request::new(&mut headers);
if let Ok(httparse::Status::Complete(_header_len)) = req.parse(this.buf) {
let headers = this.headers.deref();
for h in req.headers.iter() {
headers.push((
Bytes::from(h.name.to_owned()),
Bytes::copy_from_slice(h.value),
));
}
}
}
poll
}
}
impl<I> AsyncWrite for Http1Inspector<I>
where
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
#[inline]
fn poll_write(
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
self.project().inner.poll_write(cx, buf)
}
#[inline]
fn poll_flush(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
self.project().inner.poll_flush(cx)
}
#[inline]
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
self.project().inner.poll_shutdown(cx)
}
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/inspector/http2/frame/error.rs
|
Rust
|
/// Errors that can occur during parsing an HTTP/2 frame.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
/// A length value other than 8 was set on a PING message.
BadFrameSize,
/// The padding length was larger than the frame-header-specified
/// length of the payload.
TooMuchPadding,
/// An invalid stream identifier was provided.
///
/// This is returned if a SETTINGS or PING frame is received with a stream
/// identifier other than zero.
InvalidStreamId,
/// A request is malformed.
MalformedMessage,
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/inspector/http2/frame/headers.rs
|
Rust
|
use std::fmt::Write;
use httlib_hpack::Decoder;
use serde::{Serialize, Serializer};
use super::{error::Error, priority::StreamDependency, FrameType};
/// Header frame
#[derive(Debug, Serialize)]
pub struct HeadersFrame {
/// The type of the frame
pub frame_type: FrameType,
/// The ID of the stream with which this frame is associated.
pub stream_id: u32,
/// The length of the frame payload
pub length: usize,
/// The short pseudo-header names
#[serde(skip)]
pub pseudo_headers: Vec<char>,
/// The headers in the frame
pub headers: Vec<String>,
/// The associated flags
pub flags: HeadersFlag,
/// The stream dependency information
#[serde(skip_serializing_if = "Option::is_none")]
pub priority: Option<StreamDependency>,
}
/// Headers flags
#[derive(Debug)]
pub struct HeadersFlag(pub u8);
// ==== impl HeadersFlag ====
impl Serialize for HeadersFlag {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
const END_STREAM: u8 = 0x1;
const END_HEADERS: u8 = 0x4;
const PADDED: u8 = 0x8;
const PRIORITY: u8 = 0x20;
let mut flags = Vec::new();
if self.0 & END_STREAM != 0 {
flags.push("EndStream (0x1)");
}
if self.0 & END_HEADERS != 0 {
flags.push("EndHeaders (0x4)");
}
if self.0 & PADDED != 0 {
flags.push("Padded (0x8)");
}
if self.0 & PRIORITY != 0 {
flags.push("Priority (0x20)");
}
flags.serialize(serializer)
}
}
// ==== impl HeadersFrame ====
impl TryFrom<(u8, u32, &[u8])> for HeadersFrame {
type Error = Error;
fn try_from((flags, stream_id, payload): (u8, u32, &[u8])) -> Result<Self, Self::Error> {
let mut fragment_offset = 0;
let padded = flags & 0x8 != 0;
if flags & 0x20 != 0 {
fragment_offset += 5;
}
if padded {
fragment_offset += 1;
}
if payload.len() < fragment_offset {
return Err(Error::TooMuchPadding);
}
let padding_len = if padded { payload[0] as usize } else { 0 };
let data = &payload[fragment_offset..];
if data.len() < padding_len {
return Err(Error::TooMuchPadding);
}
let mut decoder = Decoder::default();
let mut buf = data[..data.len() - padding_len].to_vec();
let mut dst = Vec::new();
if decoder.decode(&mut buf, &mut dst).is_err() {
return Err(Error::MalformedMessage);
}
let mut headers = Vec::with_capacity(dst.len());
let mut pseudo_headers = Vec::with_capacity(4);
for (name, value, _) in dst {
if name.starts_with(b":") {
if let Some(first_char) = name.get(1).copied() {
pseudo_headers.push(first_char as char);
} else {
tracing::warn!("Invalid pseudo-header: {:?}", name);
return Err(Error::MalformedMessage);
}
}
let mut kv = String::with_capacity(name.len() + value.len() + 2);
write!(
&mut kv,
"{}: {}",
String::from_utf8_lossy(&name),
String::from_utf8_lossy(&value)
)
.map_err(|_| Error::MalformedMessage)?;
headers.push(kv);
}
let priority = if flags & 0x20 != 0 {
let buf = &payload[fragment_offset - 5..fragment_offset];
let priority = StreamDependency::try_from(buf)?;
Some(priority)
} else {
None
};
Ok(HeadersFrame {
frame_type: FrameType::Headers,
stream_id,
length: payload.len(),
pseudo_headers,
headers,
flags: HeadersFlag(flags),
priority,
})
}
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/inspector/http2/frame/mod.rs
|
Rust
|
mod error;
mod headers;
mod priority;
mod settings;
mod window_update;
use headers::HeadersFrame;
use priority::PriorityFrame;
use serde::Serialize;
use settings::SettingsFrame;
use window_update::WindowUpdateFrame;
pub fn parse(data: &[u8]) -> (usize, Option<Frame>) {
const FRAME_HEADER_LEN: usize = 9;
if data.len() < FRAME_HEADER_LEN {
return (0, None);
}
let header = &data[..FRAME_HEADER_LEN];
let length = u32::from_be_bytes([0, header[0], header[1], header[2]]) as usize;
let ty = header[3];
let flags = header[4];
let stream_id = u32::from_be_bytes([header[5] & 0x7f, header[6], header[7], header[8]]);
let payload = &data[FRAME_HEADER_LEN..];
if payload.len() < length {
return (0, None);
}
match Frame::try_from((ty, flags, stream_id, &payload[..length])) {
Ok(frame) => (FRAME_HEADER_LEN + length, Some(frame)),
Err(err) => {
tracing::debug!("Failed to parse frame: {:?}", err);
(FRAME_HEADER_LEN + length, None)
}
}
}
/// Represents HTTP/2 frame.
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub enum Frame {
Settings(SettingsFrame),
WindowUpdate(WindowUpdateFrame),
Priority(PriorityFrame),
Headers(HeadersFrame),
Unknown(UnknownFrame),
}
/// Represents frame types for serialization.
#[derive(Debug, Serialize)]
pub enum FrameType {
Settings,
WindowUpdate,
Headers,
Priority,
Unknown,
}
/// Represents an unknown frame.
#[derive(Debug, Serialize)]
pub struct UnknownFrame {
pub frame_type: FrameType,
pub length: usize,
pub payload: Vec<u8>,
}
impl TryFrom<(u8, u8, u32, &[u8])> for Frame {
type Error = error::Error;
fn try_from(
(ty, flags, stream_id, payload): (u8, u8, u32, &[u8]),
) -> Result<Self, Self::Error> {
match ty {
0x1 => HeadersFrame::try_from((flags, stream_id, payload)).map(Frame::Headers),
0x2 => PriorityFrame::try_from((stream_id, payload)).map(Frame::Priority),
0x4 => SettingsFrame::try_from(payload).map(Frame::Settings),
0x8 => WindowUpdateFrame::try_from(payload).map(Frame::WindowUpdate),
_ => {
// If the frame type is unknown, we create an UnknownFrame
let frame = UnknownFrame {
frame_type: FrameType::Unknown,
length: payload.len(),
payload: payload.to_vec(),
};
Ok(Frame::Unknown(frame))
}
}
}
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/inspector/http2/frame/priority.rs
|
Rust
|
use serde::Serialize;
use super::{error::Error, FrameType};
/// The PRIORITY frame (type=0x2) specifies the sender-advised priority
/// of a stream [Section 5.3]. It can be sent in any stream state,
/// including idle or closed streams.
/// [Section 5.3]: <https://tools.ietf.org/html/rfc7540#section-5.3>
#[derive(Debug, Serialize)]
pub struct PriorityFrame {
/// The type of the frame, which is always `FrameType::Priority`.
pub frame_type: FrameType,
/// The stream identifier this frame applies to.
pub stream_id: u32,
/// The length of the frame payload, excluding the 9-byte header.
pub length: usize,
/// The priority information contained in this frames.
pub priority: StreamDependency,
}
/// Represents a stream dependency in HTTP/2 priority frames.
#[derive(Debug, Serialize)]
pub struct StreamDependency {
/// The stream weight as received in the PRIORITY frame (0~255).
/// According to RFC 7540 5.3.2, the actual weight is always `weight + 1` (range 1~256).
/// That is, a value of 0 means weight 1, 255 means weight 256.
pub weight: u16,
/// The stream identifier this stream depends on.
pub depends_on: u32,
/// Whether this dependency is exclusive (1 for exclusive, 0 for non-exclusive).
pub exclusive: u8,
}
// ==== impl PriorityFrame ====
impl TryFrom<(u32, &[u8])> for PriorityFrame {
type Error = Error;
fn try_from((stream_id, buf): (u32, &[u8])) -> Result<Self, Self::Error> {
let priority = StreamDependency::try_from(buf)?;
if stream_id == priority.depends_on {
return Err(Error::InvalidStreamId);
}
Ok(PriorityFrame {
frame_type: FrameType::Priority,
stream_id,
length: buf.len(),
priority,
})
}
}
// ==== impl StreamDependency ====
impl TryFrom<&[u8]> for StreamDependency {
type Error = Error;
fn try_from(buf: &[u8]) -> Result<Self, Self::Error> {
if buf.len() != 5 {
tracing::debug!("Invalid PRIORITY frame size: {}", buf.len());
return Err(Error::BadFrameSize);
}
let (weight, depends_on, exclusive) = {
const STREAM_ID_MASK: u32 = 1 << 31;
let mut ubuf = [0; 4];
ubuf.copy_from_slice(&buf[0..4]);
let unpacked = u32::from_be_bytes(ubuf);
let exclusive = unpacked & STREAM_ID_MASK == STREAM_ID_MASK;
// Now clear the most significant bit, as that is reserved and MUST be
// ignored when received.
(buf[4], unpacked & !STREAM_ID_MASK, exclusive)
};
Ok(StreamDependency {
weight: weight as u16 + 1,
depends_on,
exclusive: exclusive as u8,
})
}
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/inspector/http2/frame/settings.rs
|
Rust
|
use serde::Serialize;
use super::{error::Error, FrameType};
/// An enum that lists all valid settings that can be sent in a SETTINGS
/// frame.
///
/// Each setting has a value that is a 32 bit unsigned integer (6.5.1.).
#[derive(Debug, Serialize)]
pub enum Setting {
HeaderTableSize { id: u16, value: u32 },
EnablePush { id: u16, value: u32 },
MaxConcurrentStreams { id: u16, value: u32 },
InitialWindowSize { id: u16, value: u32 },
MaxFrameSize { id: u16, value: u32 },
MaxHeaderListSize { id: u16, value: u32 },
EnableConnectProtocol { id: u16, value: u32 },
NoRfc7540Priorities { id: u16, value: u32 },
Unknown { id: u16, value: u32 },
}
/// Representing a SETTINGS frame in HTTP/2.
#[derive(Debug, Serialize)]
pub struct SettingsFrame {
pub frame_type: FrameType,
pub length: usize,
pub settings: Vec<Setting>,
}
// ==== impl Setting ====
impl From<(u16, u32)> for Setting {
fn from((id, value): (u16, u32)) -> Self {
match id {
1 => Setting::HeaderTableSize { id, value },
2 => Setting::EnablePush { id, value },
3 => Setting::MaxConcurrentStreams { id, value },
4 => Setting::InitialWindowSize { id, value },
5 => Setting::MaxFrameSize { id, value },
6 => Setting::MaxHeaderListSize { id, value },
8 => Setting::EnableConnectProtocol { id, value },
9 => Setting::NoRfc7540Priorities { id, value },
_ => Setting::Unknown { id, value },
}
}
}
impl Setting {
pub fn value(&self) -> (u16, u32) {
match self {
Setting::HeaderTableSize { id, value } => (*id, *value),
Setting::EnablePush { id, value } => (*id, *value),
Setting::MaxConcurrentStreams { id, value } => (*id, *value),
Setting::InitialWindowSize { id, value } => (*id, *value),
Setting::MaxFrameSize { id, value } => (*id, *value),
Setting::MaxHeaderListSize { id, value } => (*id, *value),
Setting::EnableConnectProtocol { id, value } => (*id, *value),
Setting::NoRfc7540Priorities { id, value } => (*id, *value),
Setting::Unknown { id, value } => (*id, *value),
}
}
}
// ==== impl SettingsFrame ====
impl TryFrom<&[u8]> for SettingsFrame {
type Error = Error;
fn try_from(payload: &[u8]) -> Result<Self, Self::Error> {
if payload.is_empty() {
tracing::debug!("Invalid SETTINGS frame size: {}", payload.len());
return Err(Error::BadFrameSize);
}
let settings = payload
.chunks_exact(6)
.map(|data| {
let id = u16::from_be_bytes([data[0], data[1]]);
let value = u32::from_be_bytes([data[2], data[3], data[4], data[5]]);
Setting::from((id, value))
})
.collect();
Ok(SettingsFrame {
frame_type: FrameType::Settings,
length: payload.len(),
settings,
})
}
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/inspector/http2/frame/window_update.rs
|
Rust
|
use serde::Serialize;
use super::{error::Error, FrameType};
/// Represents an HTTP/2 WINDOW_UPDATE frame.
///
/// See RFC 7540, Section 6.9: <https://datatracker.ietf.org/doc/html/rfc7540#section-6.9>
/// This frame is used for flow control, indicating how many additional bytes the sender is
/// permitted to transmit.
#[derive(Debug, Serialize)]
pub struct WindowUpdateFrame {
/// The type of this frame (should always be `FrameType::WindowUpdate`)
pub frame_type: FrameType,
/// The length of the frame payload (should always be 4 for WINDOW_UPDATE)
pub length: usize,
/// The window size increment (31 bits, most significant bit is reserved and must be zero).
/// This value specifies the number of bytes that can be sent.
pub increment: u32,
}
impl TryFrom<&[u8]> for WindowUpdateFrame {
type Error = Error;
fn try_from(payload: &[u8]) -> Result<Self, Self::Error> {
if payload.len() != 4 {
tracing::debug!("Invalid WINDOW_UPDATE frame size: {}", payload.len());
return Err(Error::BadFrameSize);
}
let window_size_increment =
u32::from_be_bytes([payload[0] & 0x7f, payload[1], payload[2], payload[3]]);
Ok(WindowUpdateFrame {
frame_type: FrameType::WindowUpdate,
length: payload.len(),
increment: window_size_increment,
})
}
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/inspector/http2/mod.rs
|
Rust
|
pub mod frame;
use std::{ops::Deref, pin::Pin, sync::Arc, task, task::Poll};
use frame::Frame;
use pin_project_lite::pin_project;
use tokio::io::{self, AsyncRead, AsyncWrite, ReadBuf};
use tokio_rustls::server::TlsStream;
use super::tls::TlsInspector;
pub type Http2Frame = Arc<boxcar::Vec<Frame>>;
pin_project! {
/// A wrapper over a TLS stream that inspects HTTP/2 traffic.
/// It buffers incoming data, parses HTTP/2 frames (including the connection preface),
/// and records parsed frames for later inspection or analysis.
/// Does not interfere with normal stream reading
pub struct Http2Inspector<I> {
#[pin]
inner: TlsStream<TlsInspector<I>>,
buf: Vec<u8>,
frames: Http2Frame,
}
}
impl<I> Http2Inspector<I>
where
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
/// Create a new [`Http2Inspector`] instance.
#[inline]
pub fn new(inner: TlsStream<TlsInspector<I>>) -> Self {
Self {
inner,
buf: Vec::new(),
frames: Arc::new(boxcar::Vec::new()),
}
}
/// Get previously parsed HTTP/2 frames.
#[inline]
pub fn frames(&self) -> Http2Frame {
self.frames.clone()
}
}
impl<I> AsyncRead for Http2Inspector<I>
where
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
#[inline]
fn poll_read(
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
const HTTP2_PREFACE: &[u8] = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";
let len = buf.filled().len();
let this = self.project();
let poll = this.inner.poll_read(cx, buf);
let plen = HTTP2_PREFACE.len();
let not_http2 = this.buf.len() >= plen && !this.buf.starts_with(HTTP2_PREFACE);
if !not_http2 {
this.buf.extend(&buf.filled()[len..]);
let frames = this.frames.deref();
while this.buf.len() > plen {
let last = frames.iter().last().map(|f| f.1);
if matches!(last, Some(Frame::Headers(_))) {
break;
}
let (frame_len, frame) = frame::parse(&this.buf[plen..]);
if frame_len > 0 {
this.buf.drain(plen..plen + frame_len);
if let Some(frame) = frame {
frames.push(frame);
}
} else {
break;
}
}
}
poll
}
}
impl<I> AsyncWrite for Http2Inspector<I>
where
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
#[inline]
fn poll_write(
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
self.project().inner.poll_write(cx, buf)
}
#[inline]
fn poll_flush(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
self.project().inner.poll_flush(cx)
}
#[inline]
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
self.project().inner.poll_shutdown(cx)
}
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/inspector/mod.rs
|
Rust
|
mod http1;
mod http2;
mod tls;
use std::{pin::Pin, task, task::Poll};
pub use http1::{Http1Headers, Http1Inspector};
pub use http2::{frame::Frame, Http2Frame, Http2Inspector};
pub use tls::{ClientHello, LazyClientHello, TlsInspector};
use tokio::io::{self, AsyncRead, AsyncWrite, ReadBuf};
/// `Inspector` is an enum that wraps protocol-specific inspectors (such as `Http1Inspector` and
/// `Http2Inspector`) to provide a unified interface for inspecting and tracking different protocol
/// streams. Implements `AsyncRead` and `AsyncWrite` by delegating to the underlying
pub enum Inspector<S> {
Http1(Http1Inspector<S>),
Http2(Http2Inspector<S>),
}
impl<I> AsyncRead for Inspector<I>
where
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
#[inline]
fn poll_read(
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
match self.get_mut() {
Inspector::Http1(inspector) => Pin::new(inspector).poll_read(cx, buf),
Inspector::Http2(inspector) => Pin::new(inspector).poll_read(cx, buf),
}
}
}
impl<I> AsyncWrite for Inspector<I>
where
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
#[inline]
fn poll_write(
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
match self.get_mut() {
Inspector::Http1(inspector) => Pin::new(inspector).poll_write(cx, buf),
Inspector::Http2(inspector) => Pin::new(inspector).poll_write(cx, buf),
}
}
#[inline]
fn poll_flush(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
match self.get_mut() {
Inspector::Http1(inspector) => Pin::new(inspector).poll_flush(cx),
Inspector::Http2(inspector) => Pin::new(inspector).poll_flush(cx),
}
}
#[inline]
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
match self.get_mut() {
Inspector::Http1(inspector) => Pin::new(inspector).poll_shutdown(cx),
Inspector::Http2(inspector) => Pin::new(inspector).poll_shutdown(cx),
}
}
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/inspector/tls/enums.rs
|
Rust
|
#![allow(non_camel_case_types)]
enum_builder! {
/// The `TlsVersion` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U16
pub enum TlsVersion {
SSLv2 => 0x0200,
SSLv3 => 0x0300,
TLSv1_0 => 0x0301,
TLSv1_1 => 0x0302,
TLSv1_2 => 0x0303,
TLSv1_3 => 0x0304,
DTLSv1_0 => 0xFEFF,
DTLSv1_2 => 0xFEFD,
DTLSv1_3 => 0xFEFC,
}
}
enum_builder! {
/// The `SignatureAlgorithm` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U16
pub enum SignatureAlgorithm {
rsa_pkcs1_sha1 => 513,
ecdsa_sha1 => 515,
rsa_pkcs1_sha256 => 1025,
ecdsa_secp256r1_sha256 => 1027,
rsa_pkcs1_sha256_legacy => 1056,
rsa_pkcs1_sha384 => 1281,
ecdsa_secp384r1_sha384 => 1283,
rsa_pkcs1_sha384_legacy => 1312,
rsa_pkcs1_sha512 => 1537,
ecdsa_secp521r1_sha512 => 1539,
rsa_pkcs1_sha512_legacy => 1568,
eccsi_sha256 => 1796,
iso_ibs1 => 1797,
iso_ibs2 => 1798,
iso_chinese_ibs => 1799,
sm2sig_sm3 => 1800,
gostr34102012_256a => 1801,
gostr34102012_256b => 1802,
gostr34102012_256c => 1803,
gostr34102012_256d => 1804,
gostr34102012_512a => 1805,
gostr34102012_512b => 1806,
gostr34102012_512c => 1807,
rsa_pss_rsae_sha256 => 2052,
rsa_pss_rsae_sha384 => 2053,
rsa_pss_rsae_sha512 => 2054,
ed25519 => 2055,
ed448 => 2056,
rsa_pss_pss_sha256 => 2057,
rsa_pss_pss_sha384 => 2058,
rsa_pss_pss_sha512 => 2059,
ecdsa_brainpoolp256r1tls13_sha256 => 2074,
ecdsa_brainpoolp384r1tls13_sha384 => 2075,
ecdsa_brainpoolp512r1tls13_sha512 => 2076,
}
}
enum_builder! {
/// The `CompressionAlgorithm` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
pub enum CompressionAlgorithm {
Null => 0x00,
Deflate => 0x01,
}
}
enum_builder! {
/// The `ECPointFormat` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
pub enum ECPointFormat {
Uncompressed => 0x00,
ANSIX962CompressedPrime => 0x01,
ANSIX962CompressedChar2 => 0x02,
}
}
enum_builder! {
/// Key derivation function used in hybrid public key encryption
@U16
pub enum KeyDerivationFunction {
HKDF_SHA256 => 0x0001,
HKDF_SHA384 => 0x0002,
HKDF_SHA512 => 0x0003,
}
}
enum_builder! {
/// Authenticated encryption with associated data (AEAD) used in hybrid public key encryption
@U16
pub enum AuthenticatedEncryptionWithAssociatedData {
AES_128_GCM => 0x0001,
AES_256_GCM => 0x0002,
ChaCha20Poly1305 => 0x0003,
ExportOnly => 0xffff,
}
}
enum_builder! {
/// The `CertificateCompressionAlgorithm` TLS protocol enum, the algorithm used to compress the certificate.
/// The algorithm MUST be one of the algorithms listed in the peer's compress_certificate extension.
@U16
pub enum CertificateCompressionAlgorithm {
Zlib => 0x0001,
Brotli => 0x0002,
Zstd => 0x0003,
}
}
enum_builder! {
/// The `CertificateStatusType` TLS protocol enum, used in the status_request extension.
/// Values in this enum are taken from the various RFCs covering TLS, and are listed
/// by IANA. The `Unknown` item is used when processing unrecognised ordinals.
/// The `OCSP` value is used to indicate that the certificate status is provided
/// using the Online Certificate Status Protocol (OCSP).
#[allow(clippy::upper_case_acronyms)]
@U8
pub enum CertificateStatusType {
OCSP => 0x01,
}
}
enum_builder! {
@U8
pub enum PskKeyExchangeMode {
/// See https://www.rfc-editor.org/rfc/rfc8446#section-4.2.9
psk_ke => 0,
psk_dhe_ke => 1
}
}
enum_builder2! {
/// The `NamesGroup` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U16
pub enum NamesGroup {
sect163k1 => 1,
sect163k1_2 => 2,
sect163r2 => 3,
sect193r1 => 4,
sect193r2 => 5,
sect233k1 => 6,
sect233r1 => 7,
sect239k1 => 8,
sect283k1 => 9,
sect283r1 => 10,
sect409k1 => 11,
sect409r1 => 12,
sect571k1 => 13,
sect571r1 => 14,
secp160k1 => 15,
secp160r1 => 16,
secp160r2 => 17,
secp192k1 => 18,
secp192r1 => 19,
secp224k1 => 20,
P_224 => 21,
P_256 => 23,
P_384 => 24,
P_521 => 25,
X25519 => 29,
X448 => 30,
P256r1tls13 => 31,
P384r1tls13 => 32,
P521r1tls13 => 33,
GC256A => 34,
GC256B => 35,
GC256C => 36,
GC256D => 37,
GC512A => 38,
GC512B => 39,
GC512C => 40,
SM2 => 41,
ffdhe2048 => 256,
ffdhe3072 => 257,
ffdhe4096 => 258,
ffdhe6144 => 259,
ffdhe8192 => 260,
MLKEM1024 => 514,
X25519MLKEM768 => 4588,
CECPQ2 => 16696,
X25519Kyber768Draft00 => 25497,
X25519Kyber512Draft00 => 65072,
X25519Kyber768Draft00Old => 65073,
P256Kyber768Draft00 => 65074,
}
}
impl ::std::fmt::Display for NamesGroup {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match self {
NamesGroup::P_224 => f.write_str("P-224"),
NamesGroup::P_256 => f.write_str("P-256"),
NamesGroup::P_384 => f.write_str("P-384"),
NamesGroup::P_521 => f.write_str("P-521"),
NamesGroup::Unknown(x) => {
if x & 0x0f0f == 0x0a0a {
write!(f, "GREASE ({x:#06x})")
} else {
write!(f, "Unknown ({x:#06x})")
}
}
other => write!(f, "{other:?}"),
}
}
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/inspector/tls/hello.rs
|
Rust
|
//! See: <https://www.rfc-editor.org/rfc/rfc8446#section-4.2>
use serde::Serialize;
use tls_parser::{TlsCipherSuite, TlsExtensionType, TlsMessage, TlsMessageHandshake};
use tokio_rustls::rustls::ProtocolVersion;
use super::{
enums::{
AuthenticatedEncryptionWithAssociatedData, CertificateCompressionAlgorithm,
CertificateStatusType, CompressionAlgorithm, ECPointFormat, KeyDerivationFunction,
NamesGroup, PskKeyExchangeMode, SignatureAlgorithm, TlsVersion,
},
parser,
};
/// `LazyClientHello` is a buffer for accumulating raw TLS ClientHello data during the handshake
/// phase. It allows incremental appending of data and supports deferred (lazy) parsing into a
/// structured `ClientHello` only when needed, without interfering with the TLS handshake process.
#[derive(Clone)]
pub struct LazyClientHello {
buf: Vec<u8>,
}
impl LazyClientHello {
/// Creates a new, empty buffer for accumulating ClientHello data.
pub fn new() -> LazyClientHello {
LazyClientHello {
// Buffer size is set to match typical ClientHello message sizes sent by most browsers.
// This helps minimize memory reallocations and is sufficient for almost all real-world
// cases. Adjust this value if larger ClientHello payloads are encountered.
buf: Vec::with_capacity(2048),
}
}
/// Attempts to parse a TLS ClientHello message from the buffered data.
/// Returns `Some(ClientHello)` if parsing succeeds, otherwise `None`.
pub fn parse(self) -> Option<ClientHello> {
ClientHello::parse(&self.buf)
}
/// Returns `true` if the buffered data has reached the maximum TLS record length.
/// This can be used to determine if further buffering is unnecessary.
pub fn is_max_record_len(&self) -> bool {
self.buf.len() >= tls_parser::MAX_RECORD_LEN.into()
}
/// Appends additional data to the internal buffer.
pub fn extend(&mut self, data: &[u8]) {
self.buf.extend(data);
}
}
/// Represents a TLS Client Hello message.
#[derive(Clone, Serialize)]
pub struct ClientHello {
/// TLS version of message
tls_version: TlsVersion,
/// The final TLS version negotiated during the handshake
tls_version_negotiated: Option<TlsVersion>,
client_random: String,
session_id: Option<String>,
/// A list of compression methods supported by client
compression_algorithms: Vec<CompressionAlgorithm>,
/// A list of ciphers supported by client
ciphers: Vec<&'static str>,
/// A list of extensions supported by client
extensions: Vec<TlsExtension>,
}
/// Extensions that can be set in a [`ClientHello`] message by a TLS client.
#[derive(Clone, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum TlsExtension {
/// Server Name Indication (SNI), used for virtual hosting.
ServerName { value: u16, data: Vec<String> },
/// Supported elliptic curve groups for key exchange.
SupportedGroups { value: u16, data: Vec<NamesGroup> },
/// Supported EC point formats for key exchange.
EcPointFormats {
value: u16,
data: Vec<ECPointFormat>,
},
/// Supported signature algorithms for authentication.
SignatureAlgorithms {
value: u16,
data: Vec<SignatureAlgorithm>,
},
/// OCSP stapling support (status request).
StatusRequest { value: u16, data: StatusRequest },
/// Application-Layer Protocol Negotiation (ALPN), e.g., for HTTP/2.
ApplicationLayerProtocolNegotiation { value: u16, data: Vec<String> },
/// Old Application Settings extension (non-standard).
ApplicationSettingsOld { value: u16, data: Vec<String> },
/// Application Settings extension (used for ALPS in HTTP/2/3).
ApplicationSettings { value: u16, data: Vec<String> },
/// Supported TLS protocol versions.
SupportedVersions { value: u16, data: Vec<TlsVersion> },
/// Session ticket for session resumption.
SessionTicket { value: u16, data: String },
/// Supported certificate compression algorithms.
CertificateCompression {
value: u16,
data: Vec<CertificateCompressionAlgorithm>,
},
/// Record size limit for TLS records.
RecordSizeLimit { value: u16, data: u16 },
/// Delegated credentials for authentication.
DelegatedCredentials {
value: u16,
data: Vec<SignatureAlgorithm>,
},
/// Encrypted ClientHello (ECH) extension.
EncryptedClientHello { value: u16, data: ECHClientHello },
/// Signed Certificate Timestamp (SCT) for certificate transparency.
SignedCertificateTimestamp {
value: u16,
#[serde(skip_serializing_if = "Option::is_none")]
data: Option<String>,
},
/// Renegotiation info for secure renegotiation.
RenegotiationInfo { value: u16 },
/// Extended Master Secret extension for improved security.
ExtendedMasterSecret { value: u16 },
/// Padding extension to obscure ClientHello length.
Padding { value: u16, data: String },
/// Key share entries for key exchange (TLS 1.3).
KeyShare { value: u16, data: Vec<KeyShare> },
/// PSK key exchange modes (TLS 1.3).
PskKeyExchangeModes {
value: u16,
data: PskKeyExchangeModes,
},
/// Pre-shared key for session resumption or 0-RTT.
PreSharedKey { value: u16, data: String },
/// Encrypted Server Name Indication (ESNI) extension.
EncryptedServerName {
value: u16,
ciphersuite: &'static str,
group: NamesGroup,
key_share: String,
record_digest: String,
encrypted_sni: String,
},
/// Oid filters for certificate extensions.
OidFilters { value: u16, data: Vec<OidFilter> },
/// GREASE value for protocol extensibility testing.
Grease { value: u16 },
/// Any unknown or unsupported extension.
Opaque { value: u16, data: Option<String> },
}
/// StatusRequest extension data
///
/// See: <https://www.rfc-editor.org/rfc/rfc6066#section-8>
#[derive(Clone, Serialize, Hash)]
pub struct StatusRequest {
certificate_status_type: CertificateStatusType,
responder_id_list: u16,
request_extensions: u16,
}
/// Client Hello contents send by ECH
#[derive(Clone, Serialize, Hash)]
pub enum ECHClientHello {
/// Send when message is in the outer (unencrypted) part of client hello. It contains
/// encryption data and the encrypted client hello.
Outer(ECHClientHelloOuter),
/// The inner extension has an empty payload, which is included because TLS servers are
/// not allowed to provide extensions in ServerHello which were not included in ClientHello.
/// And when using encrypted client hello the server will discard the outer unencrypted one,
/// and only look at the encrypted client hello. So we have to add this extension again there
/// so the server knows ECH is supported by the client.
Inner,
}
/// Data send by ech hello message when it is in the outer part
#[derive(Clone, Serialize, Hash)]
pub struct ECHClientHelloOuter {
pub cipher_suite: HpkeSymmetricCipherSuite,
pub config_id: u8,
pub enc: String,
pub payload: String,
}
/// HPKE KDF and AEAD pair used to encrypt ClientHello
#[derive(Clone, Serialize, Hash)]
pub struct HpkeSymmetricCipherSuite {
pub kdf_id: KeyDerivationFunction,
pub aead_id: AuthenticatedEncryptionWithAssociatedData,
}
/// Key shares used in ClientHello
///
/// See: <https://www.rfc-editor.org/rfc/rfc8446#section-4.2.8>
#[derive(Clone, Serialize, Hash)]
pub struct KeyShare {
pub name: NamesGroup,
pub value: String,
}
/// PSK Key Exchange Modes
#[derive(Clone, Serialize, Hash)]
pub struct PskKeyExchangeModes {
pub ke_modes: Vec<PskKeyExchangeMode>,
}
/// Represents a filter for OID extensions in certificates.
#[derive(Clone, Debug, PartialEq, Serialize, Hash)]
pub struct OidFilter {
pub cert_ext_oid: String,
pub cert_ext_val: String,
}
impl ClientHello {
/// Sets the negotiated TLS version for this `ClientHello`.
///
/// # Parameters
/// - `version`: An `Option<ProtocolVersion>` representing the negotiated TLS version. If
/// `Some`, the version is set; if `None`, no version was negotiated.
pub fn set_tls_version_negotiated(&mut self, version: Option<ProtocolVersion>) {
self.tls_version_negotiated = version.map(u16::from).map(TlsVersion::from);
}
pub fn parse(buf: &[u8]) -> Option<Self> {
let (_, r) = tls_parser::parse_tls_raw_record(buf).ok()?;
let (_, msg_list) = tls_parser::parse_tls_record_with_header(r.data, &r.hdr).ok()?;
let payload = msg_list.into_iter().find_map(|msg| {
if let TlsMessage::Handshake(TlsMessageHandshake::ClientHello(payload)) = msg {
Some(payload)
} else {
None
}
})?;
let mut client_hello = ClientHello {
tls_version: TlsVersion::from(payload.version.0),
tls_version_negotiated: None,
client_random: hex::encode(payload.random),
session_id: payload.session_id.map(hex::encode),
compression_algorithms: payload
.comp
.iter()
.map(|c| CompressionAlgorithm::from(c.0))
.collect(),
ciphers: payload
.ciphers
.iter()
.flat_map(|v| TlsCipherSuite::from_id(v.0).map(|v| v.name))
.collect(),
extensions: Vec::with_capacity(5),
};
let ext = payload.ext?;
let (_, ext_list) = tls_parser::parse_tls_client_hello_extensions(ext).ok()?;
for ext in ext_list {
let extension_id = TlsExtensionType::from(&ext).0;
match ext {
tls_parser::TlsExtension::SNI(name) => {
tracing::debug!("ClientHello: SNI extension: {name:?}");
client_hello.extensions.push(TlsExtension::ServerName {
value: extension_id,
data: name
.into_iter()
.map(|n| n.1)
.map(|n| String::from_utf8_lossy(n).to_string())
.collect(),
});
}
tls_parser::TlsExtension::EllipticCurves(groups) => {
tracing::debug!("ClientHello: EllipticCurves extension: {groups:?}");
client_hello.extensions.push(TlsExtension::SupportedGroups {
value: extension_id,
data: groups.into_iter().map(|g| NamesGroup::from(g.0)).collect(),
});
}
tls_parser::TlsExtension::SupportedVersions(versions) => {
tracing::debug!("ClientHello: SupportedVersions extension: {versions:?}");
client_hello
.extensions
.push(TlsExtension::SupportedVersions {
value: extension_id,
data: versions
.into_iter()
.map(|v| TlsVersion::from(v.0))
.collect(),
});
}
tls_parser::TlsExtension::SessionTicket(data) => {
tracing::debug!("ClientHello: SessionTicket extension: {data:?}");
client_hello.extensions.push(TlsExtension::SessionTicket {
value: extension_id,
data: hex::encode(data),
});
}
tls_parser::TlsExtension::SignatureAlgorithms(algorithms) => {
tracing::debug!("ClientHello: SignatureAlgorithms extension: {algorithms:?}");
client_hello
.extensions
.push(TlsExtension::SignatureAlgorithms {
value: extension_id,
data: algorithms
.into_iter()
.map(SignatureAlgorithm::from)
.collect(),
});
}
tls_parser::TlsExtension::StatusRequest(data) => {
tracing::debug!("ClientHello: StatusRequest extension: {data:?}");
if let Some((status, data)) = data {
let (_, (responder_id_list, request_extensions)) =
parser::parse_ocsp_status_request_lengths(data).ok()?;
client_hello.extensions.push(TlsExtension::StatusRequest {
value: extension_id,
data: StatusRequest {
certificate_status_type: CertificateStatusType::from(status.0),
responder_id_list,
request_extensions,
},
});
}
}
tls_parser::TlsExtension::EcPointFormats(formats) => {
tracing::debug!("ClientHello: ECPointFormats extension: {formats:?}");
client_hello.extensions.push(TlsExtension::EcPointFormats {
value: extension_id,
data: formats.iter().map(|f| ECPointFormat::from(*f)).collect(),
});
}
tls_parser::TlsExtension::ALPN(protocols) => {
tracing::debug!("ClientHello: ALPN extension: {protocols:?}");
client_hello.extensions.push(
TlsExtension::ApplicationLayerProtocolNegotiation {
value: extension_id,
data: protocols
.into_iter()
.map(|p| String::from_utf8_lossy(p).to_string())
.collect(),
},
);
}
tls_parser::TlsExtension::SignedCertificateTimestamp(timestamps) => {
tracing::debug!("ClientHello: SCT extension: {timestamps:?}");
client_hello
.extensions
.push(TlsExtension::SignedCertificateTimestamp {
value: extension_id,
data: timestamps.map(hex::encode),
});
}
tls_parser::TlsExtension::RenegotiationInfo(data) => {
tracing::debug!("ClientHello: RenegotiationInfo extension: {data:?}");
client_hello
.extensions
.push(TlsExtension::RenegotiationInfo {
value: extension_id,
});
}
tls_parser::TlsExtension::Unknown(TlsExtensionType(34), algorithms) => {
tracing::debug!("ClientHello: DelegatedCredentials extension: {algorithms:?}");
let extension =
parser::parse_tls_extension_delegated_credentials(extension_id, algorithms)
.ok()?
.1;
client_hello.extensions.push(extension);
}
tls_parser::TlsExtension::RecordSizeLimit(limit) => {
tracing::debug!("ClientHello: RecordSizeLimit extension: {limit:?}");
client_hello.extensions.push(TlsExtension::RecordSizeLimit {
value: extension_id,
data: limit,
});
}
tls_parser::TlsExtension::Unknown(TlsExtensionType(27), data) => {
tracing::debug!("ClientHello: CertificateCompression extension: {data:?}");
let extension =
parser::parse_tls_extension_certificate_compression(extension_id, data)
.ok()?
.1;
client_hello.extensions.push(extension);
}
tls_parser::TlsExtension::Unknown(TlsExtensionType(65037), data) => {
tracing::debug!("ClientHello: EncryptedClientHello extension: {data:?}");
let extension = parser::parse_tls_extension_ech(extension_id, data).ok()?.1;
client_hello.extensions.push(extension);
}
tls_parser::TlsExtension::Padding(padding) => {
tracing::debug!("ClientHello: Padding extension");
client_hello.extensions.push(TlsExtension::Padding {
value: extension_id,
data: hex::encode(padding),
});
}
tls_parser::TlsExtension::KeyShare(data) => {
tracing::debug!("ClientHello: KeyShare extension: {data:?}");
client_hello.extensions.push(TlsExtension::KeyShare {
value: extension_id,
data: parser::parse_key_share(data)?
.into_iter()
.map(|data| KeyShare {
name: NamesGroup::from(data.0),
value: hex::encode(data.1),
})
.collect(),
});
}
tls_parser::TlsExtension::PskExchangeModes(data) => {
tracing::debug!("ClientHello: PskExchangeModes extension: {data:?}");
client_hello
.extensions
.push(TlsExtension::PskKeyExchangeModes {
value: extension_id,
data: PskKeyExchangeModes {
ke_modes: data.into_iter().map(PskKeyExchangeMode::from).collect(),
},
});
}
tls_parser::TlsExtension::PreSharedKey(data) => {
tracing::debug!("ClientHello: PreSharedKey extension: {data:?}");
client_hello.extensions.push(TlsExtension::PreSharedKey {
value: extension_id,
data: hex::encode(data),
});
}
tls_parser::TlsExtension::Unknown(TlsExtensionType(17513), protocols) => {
tracing::debug!(
"ClientHello: Old Application Settings extension: {protocols:?}"
);
client_hello
.extensions
.push(TlsExtension::ApplicationSettingsOld {
value: extension_id,
data: parser::parse_alps_packet(protocols),
});
}
tls_parser::TlsExtension::Unknown(TlsExtensionType(17613), protocols) => {
tracing::debug!("ClientHello: Application Settings extension: {protocols:?}");
client_hello
.extensions
.push(TlsExtension::ApplicationSettings {
value: extension_id,
data: parser::parse_alps_packet(protocols),
});
}
tls_parser::TlsExtension::ExtendedMasterSecret => {
tracing::debug!("ClientHello: ExtendedMasterSecret extension");
client_hello
.extensions
.push(TlsExtension::ExtendedMasterSecret {
value: extension_id,
});
}
tls_parser::TlsExtension::Grease(id, data) => {
tracing::debug!("ClientHello: Grease extension: {id:?}, {data:?}");
client_hello.extensions.push(TlsExtension::Grease {
value: extension_id,
});
}
tls_parser::TlsExtension::MaxFragmentLength(data) => {
tracing::debug!("ClientHello: MaxFragmentLength extension");
client_hello.extensions.push(TlsExtension::Opaque {
value: extension_id,
data: Some(hex::encode(data.to_be_bytes())),
});
}
tls_parser::TlsExtension::KeyShareOld(items) => {
tracing::debug!("ClientHello: KeyShareOld extension: {items:?}");
client_hello.extensions.push(TlsExtension::Opaque {
value: extension_id,
data: Some(hex::encode(items)),
});
}
tls_parser::TlsExtension::EarlyData(data) => {
tracing::debug!("ClientHello: EarlyData extension: {data:?}");
client_hello.extensions.push(TlsExtension::Opaque {
value: extension_id,
data: data.map(|d| hex::encode(d.to_be_bytes())),
});
}
tls_parser::TlsExtension::Cookie(items) => {
tracing::debug!("ClientHello: Cookie extension: {items:?}");
client_hello.extensions.push(TlsExtension::Opaque {
value: extension_id,
data: Some(hex::encode(items)),
});
}
tls_parser::TlsExtension::Heartbeat(data) => {
tracing::debug!("ClientHello: Heartbeat extension: {data:?}");
client_hello.extensions.push(TlsExtension::Opaque {
value: extension_id,
data: Some(hex::encode(data.to_be_bytes())),
});
}
tls_parser::TlsExtension::EncryptThenMac => {
tracing::debug!("ClientHello: EncryptThenMac extension");
client_hello.extensions.push(TlsExtension::Opaque {
value: extension_id,
data: None,
});
}
tls_parser::TlsExtension::OidFilters(oid_filters) => {
tracing::debug!("ClientHello: OidFilters extension: {oid_filters:?}");
client_hello.extensions.push(TlsExtension::OidFilters {
value: extension_id,
data: oid_filters
.into_iter()
.map(|f| OidFilter {
cert_ext_oid: hex::encode(f.cert_ext_oid),
cert_ext_val: hex::encode(f.cert_ext_val),
})
.collect(),
});
}
tls_parser::TlsExtension::PostHandshakeAuth => {
tracing::debug!("ClientHello: PostHandshakeAuth extension");
client_hello.extensions.push(TlsExtension::Opaque {
value: extension_id,
data: None,
});
}
tls_parser::TlsExtension::NextProtocolNegotiation => {
tracing::debug!("ClientHello: NextProtocolNegotiation extension");
client_hello.extensions.push(TlsExtension::Opaque {
value: extension_id,
data: None,
});
}
tls_parser::TlsExtension::EncryptedServerName {
ciphersuite,
group,
key_share,
record_digest,
encrypted_sni,
} => {
tracing::debug!("ClientHello: EncryptedServerName extension");
client_hello
.extensions
.push(TlsExtension::EncryptedServerName {
value: extension_id,
ciphersuite: tls_parser::TlsCipherSuite::from_id(ciphersuite.0)
.map(|c| c.name)
.unwrap_or("Unknown"),
group: NamesGroup::from(group.0),
key_share: hex::encode(key_share),
record_digest: hex::encode(record_digest),
encrypted_sni: hex::encode(encrypted_sni),
});
}
tls_parser::TlsExtension::Unknown(id, data) => {
tracing::debug!("ClientHello: Unknown extension: {id:?}, {data:?}");
client_hello.extensions.push(TlsExtension::Opaque {
value: extension_id,
data: Some(hex::encode(data)),
});
}
}
}
Some(client_hello)
}
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/inspector/tls/macros.rs
|
Rust
|
macro_rules! enum_builder {
(
$(#[$m:meta])*
@U8
$enum_vis:vis enum $enum_name:ident
{ $( $(#[$enum_meta:meta])* $enum_var: ident => $enum_val: expr ),* $(,)? }
) => {
$(#[$m])*
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
$enum_vis enum $enum_name {
$(
$(#[$enum_meta])*
$enum_var
),*
,Unknown(u8)
}
impl From<u8> for $enum_name {
fn from(x: u8) -> Self {
match x {
$($enum_val => $enum_name::$enum_var),*
, x => $enum_name::Unknown(x),
}
}
}
impl ::std::fmt::Display for $enum_name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
$( $enum_name::$enum_var => write!(f, stringify!($enum_var))),*
,$enum_name::Unknown(x) => write!(f, "Unknown ({x:#06x})"),
}
}
}
impl ::serde::Serialize for $enum_name {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::Serializer,
{
serializer.collect_str(self)
}
}
};
(
$(#[$m:meta])*
@U16
$enum_vis:vis enum $enum_name:ident
{ $( $(#[$enum_meta:meta])* $enum_var: ident => $enum_val: expr ),* $(,)? }
) => {
$(#[$m])*
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
$enum_vis enum $enum_name {
$(
$(#[$enum_meta])*
$enum_var
),*
,Unknown(u16)
}
impl From<u16> for $enum_name {
fn from(x: u16) -> Self {
match x {
$($enum_val => $enum_name::$enum_var),*
, x => $enum_name::Unknown(x),
}
}
}
impl ::std::fmt::Display for $enum_name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match self {
$( $enum_name::$enum_var => write!(f, stringify!($enum_var))),*
,$enum_name::Unknown(x) => if x & 0x0f0f == 0x0a0a {
write!(f, "GREASE ({x:#06x})")
} else {
write!(f, "Unknown ({x:#06x})")
}
}
}
}
impl ::serde::Serialize for $enum_name {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::Serializer,
{
serializer.collect_str(self)
}
}
};
}
macro_rules! enum_builder2 {
(
$(#[$m:meta])*
@U16
$enum_vis:vis enum $enum_name:ident
{ $( $(#[$enum_meta:meta])* $enum_var: ident => $enum_val: expr ),* $(,)? }
) => {
$(#[$m])*
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
$enum_vis enum $enum_name {
$(
$(#[$enum_meta])*
$enum_var
),*
,Unknown(u16)
}
impl From<u16> for $enum_name {
fn from(x: u16) -> Self {
match x {
$($enum_val => $enum_name::$enum_var),*
, x => $enum_name::Unknown(x),
}
}
}
impl ::serde::Serialize for $enum_name {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::Serializer,
{
serializer.collect_str(self)
}
}
};
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/inspector/tls/mod.rs
|
Rust
|
#[macro_use]
mod macros;
mod enums;
mod hello;
mod parser;
use std::{pin::Pin, task, task::Poll};
pub use hello::{ClientHello, LazyClientHello};
use tokio::io::{self, AsyncRead, AsyncWrite, ReadBuf};
pin_project_lite::pin_project! {
/// A wrapper over a TLS stream that inspects TLS client hello messages.
/// It buffers incoming data, parses the client hello message,
/// and records the parsed client hello for later inspection or analysis.
/// Does not interfere with normal stream reading or writing.
pub struct TlsInspector<I> {
#[pin]
inner: I,
client_hello: Option<LazyClientHello>,
}
}
impl<I> TlsInspector<I>
where
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
/// Create a new [`TlsInspector`] instance.
pub fn new(inner: I) -> Self {
Self {
inner,
client_hello: Some(LazyClientHello::new()),
}
}
/// Extracts and takes ownership of the buffered ClientHello payload,
/// leaving `None` in its place.
#[inline]
#[must_use]
pub fn client_hello(&mut self) -> Option<LazyClientHello> {
self.client_hello.take()
}
}
impl<I> AsyncRead for TlsInspector<I>
where
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
#[inline]
fn poll_read(
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
let len = buf.filled().len();
let this = self.project();
let poll = this.inner.poll_read(cx, buf);
if let Some(client_hello) = this.client_hello {
if !client_hello.is_max_record_len() {
client_hello.extend(&buf.filled()[len..]);
}
}
poll
}
}
impl<I> AsyncWrite for TlsInspector<I>
where
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
#[inline]
fn poll_write(
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
self.project().inner.poll_write(cx, buf)
}
#[inline]
fn poll_flush(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
self.project().inner.poll_flush(cx)
}
#[inline]
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
self.project().inner.poll_shutdown(cx)
}
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/inspector/tls/parser.rs
|
Rust
|
use nom::{
combinator::{map, map_opt, map_parser},
error::{make_error, ErrorKind},
multi::length_data,
number::streaming::{be_u16, be_u8},
IResult, Parser,
};
use super::hello::{ECHClientHello, ECHClientHelloOuter, HpkeSymmetricCipherSuite, TlsExtension};
/// Parse KeyShare extension in TLS 1.3 (RFC 8446) with 4-byte length and 4-byte fields.
pub fn parse_key_share(data: &[u8]) -> Option<Vec<(u16, Vec<u8>)>> {
if data.len() < 2 {
return None;
}
let total_len = u16::from_be_bytes([data[0], data[1]]) as usize;
if data.len() < 2 + total_len {
return None;
}
let mut res = Vec::new();
let mut i = 2;
while i + 4 <= 2 + total_len {
let group = u16::from_be_bytes([data[i], data[i + 1]]);
let key_len = u16::from_be_bytes([data[i + 2], data[i + 3]]) as usize;
i += 4;
if i + key_len > data.len() {
break;
}
let key = data[i..i + key_len].to_vec();
res.push((group, key));
i += key_len;
}
Some(res)
}
/// Parse the OCSP status request extension from the ClientHello.
pub fn parse_ocsp_status_request_lengths(data: &[u8]) -> IResult<&[u8], (u16, u16)> {
(be_u16, be_u16).parse(data)
}
/// Parse extension for delegated credentials.
pub fn parse_tls_extension_delegated_credentials(
id: u16,
data: &[u8],
) -> IResult<&[u8], TlsExtension> {
map_parser(
length_data(be_u16),
map(parse_u16_type, |x| TlsExtension::DelegatedCredentials {
value: id,
data: x,
}),
)
.parse(data)
}
/// Parses extension for certificate compression
pub fn parse_tls_extension_certificate_compression(
id: u16,
data: &[u8],
) -> IResult<&[u8], TlsExtension> {
map_parser(
length_data(be_u8),
map(parse_u16_type, |args| {
TlsExtension::CertificateCompression {
value: id,
data: args,
}
}),
)
.parse(data)
}
/// Parses extension for encrypted client hello (ECH).
pub fn parse_tls_extension_ech(id: u16, data: &[u8]) -> IResult<&[u8], TlsExtension> {
let (input, is_outer) = map_opt(be_u8, |v| match v {
0 => Some(true),
1 => Some(false),
_ => None,
})
.parse(data)?;
match is_outer {
true => {
let (input, (kdf_id, aead_id, config_id)) = (be_u16, be_u16, be_u8).parse(input)?;
let (input, enc) = length_data(be_u16).parse(input)?;
let (input, payload) = length_data(be_u16).parse(input)?;
Ok((
input,
TlsExtension::EncryptedClientHello {
value: id,
data: ECHClientHello::Outer(ECHClientHelloOuter {
cipher_suite: HpkeSymmetricCipherSuite {
aead_id: aead_id.into(),
kdf_id: kdf_id.into(),
},
config_id,
enc: hex::encode(enc),
payload: hex::encode(payload),
}),
},
))
}
false => Ok((
input,
TlsExtension::EncryptedClientHello {
value: id,
data: ECHClientHello::Inner,
},
)),
}
}
/// The alpn_protocol_name field MUST match the protocol negotiated by ALPN.
/// The extension is only sent by the server, and only for the selected protocol.
/// See <https://datatracker.ietf.org/doc/html/draft-vvv-tls-alps>
pub fn parse_alps_packet(d: &[u8]) -> Vec<String> {
let mut protocols = Vec::new();
if d.len() < 3 {
return protocols;
}
let mut cursor = 0;
if d[0] == 0 {
cursor += 1;
}
if cursor >= d.len() {
return protocols;
}
cursor += 1;
while cursor < d.len() {
let len = d[cursor] as usize;
cursor += 1;
if cursor + len > d.len() {
break;
}
let proto_bytes = &d[cursor..cursor + len];
let proto_str = match std::str::from_utf8(proto_bytes) {
Ok(s) => s.to_string(),
Err(_) => return protocols,
};
protocols.push(proto_str);
cursor += len;
}
protocols
}
fn parse_u16_type<T: From<u16>>(i: &[u8]) -> IResult<&[u8], Vec<T>> {
let len = i.len();
if len == 0 {
return Ok((i, Vec::new()));
}
if len % 2 == 1 || len > i.len() {
return Err(nom::Err::Error(make_error(i, ErrorKind::LengthValue)));
}
let v = (i[..len])
.chunks(2)
.map(|chunk| T::from(((chunk[0] as u16) << 8) | chunk[1] as u16))
.collect();
Ok((&i[len..], v))
}
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
src/server/tracker/mod.rs
|
Rust
|
pub mod accept;
#[cfg(target_os = "linux")]
pub mod capture;
pub mod info;
mod inspector;
|
0x676e67/pingly
| 26
|
Analysis server for TLS and HTTP/1/2/3
|
Rust
|
0x676e67
| ||
examples/client.rs
|
Rust
|
//! This example demonstrates an HTTP client that requests files from a server.
//!
//! Checkout the `README.md` for guidance.
use std::{
fs,
io::{self, Write},
net::{SocketAddr, ToSocketAddrs},
path::PathBuf,
sync::Arc,
time::{Duration, Instant},
};
use anyhow::{anyhow, Result};
use boring::x509::X509;
use clap::Parser;
use quinn_boring2::QuicSslContext;
use tracing::{error, info};
use url::Url;
/// HTTP/0.9 over QUIC client
#[derive(Parser, Debug)]
#[clap(name = "client")]
struct Opt {
/// Perform NSS-compatible TLS key logging to the file specified in `SSLKEYLOGFILE`.
#[clap(long = "keylog")]
keylog: bool,
url: Url,
/// Override hostname used for certificate verification
#[clap(long = "host")]
host: Option<String>,
/// Custom certificate authority to trust, in DER format
#[clap(long = "ca")]
ca: Option<PathBuf>,
/// Simulate NAT rebinding after connecting
#[clap(long = "rebind")]
rebind: bool,
/// Address to bind on
#[clap(long = "bind", default_value = "[::]:0")]
bind: SocketAddr,
}
fn main() {
tracing::subscriber::set_global_default(
tracing_subscriber::FmtSubscriber::builder()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.finish(),
)
.unwrap();
let opt = Opt::parse();
let code = {
if let Err(e) = run(opt) {
eprintln!("ERROR: {e}");
1
} else {
0
}
};
::std::process::exit(code);
}
#[tokio::main]
async fn run(options: Opt) -> Result<()> {
let url = options.url;
let url_host = strip_ipv6_brackets(url.host_str().unwrap());
let remote = (url_host, url.port().unwrap_or(4433))
.to_socket_addrs()?
.next()
.ok_or_else(|| anyhow!("couldn't resolve to an address"))?;
let mut client_crypto = quinn_boring2::ClientConfig::new()?;
if let Some(ca_path) = options.ca {
client_crypto
.ctx_mut()
.cert_store_mut()
.add_cert(X509::from_der(&fs::read(ca_path)?)?)?;
} else {
let dirs = directories_next::ProjectDirs::from("org", "quinn", "quinn-examples").unwrap();
let path = dirs.data_local_dir();
info!("using cert directory: {:?}", path);
match fs::read(path.join("cert.der")) {
Ok(cert) => {
client_crypto
.ctx_mut()
.cert_store_mut()
.add_cert(X509::from_der(&cert)?)?;
}
Err(ref e) if e.kind() == io::ErrorKind::NotFound => {
info!("local server certificate not found");
}
Err(e) => {
error!("failed to open local server certificate: {}", e);
}
}
}
let mut endpoint = quinn_boring2::helpers::client_endpoint(options.bind)?;
endpoint.set_default_client_config(quinn::ClientConfig::new(Arc::new(client_crypto)));
let request = format!("GET {}\r\n", url.path());
let start = Instant::now();
let rebind = options.rebind;
let host = options.host.as_deref().unwrap_or(url_host);
eprintln!("connecting to {host} at {remote}");
let conn = endpoint
.connect(remote, host)?
.await
.map_err(|e| anyhow!("failed to connect: {}", e))?;
eprintln!("connected at {:?}", start.elapsed());
let (mut send, mut recv) = conn
.open_bi()
.await
.map_err(|e| anyhow!("failed to open stream: {}", e))?;
if rebind {
let socket = std::net::UdpSocket::bind("[::]:0").unwrap();
let addr = socket.local_addr().unwrap();
eprintln!("rebinding to {addr}");
endpoint.rebind(socket).expect("rebind failed");
}
send.write_all(request.as_bytes())
.await
.map_err(|e| anyhow!("failed to send request: {}", e))?;
send.finish().unwrap();
let response_start = Instant::now();
eprintln!("request sent at {:?}", response_start - start);
let resp = recv
.read_to_end(usize::MAX)
.await
.map_err(|e| anyhow!("failed to read response: {}", e))?;
let duration = response_start.elapsed();
eprintln!(
"response received in {:?} - {} KiB/s",
duration,
resp.len() as f32 / (duration_secs(&duration) * 1024.0)
);
io::stdout().write_all(&resp).unwrap();
io::stdout().flush().unwrap();
conn.close(0u32.into(), b"done");
// Give the server a fair chance to receive the close packet
endpoint.wait_idle().await;
Ok(())
}
fn strip_ipv6_brackets(host: &str) -> &str {
// An ipv6 url looks like eg https://[::1]:4433/Cargo.toml, wherein the host [::1] is the
// ipv6 address ::1 wrapped in brackets, per RFC 2732. This strips those.
if host.starts_with('[') && host.ends_with(']') {
&host[1..host.len() - 1]
} else {
host
}
}
fn duration_secs(x: &Duration) -> f32 {
x.as_secs() as f32 + x.subsec_nanos() as f32 * 1e-9
}
|
0x676e67/quinn-boring2
| 0
|
A crypto provider for quinn based on BoringSSL
|
Rust
|
0x676e67
| ||
examples/server.rs
|
Rust
|
//! This example demonstrates an HTTP server that serves files from a directory.
//!
//! Checkout the `README.md` for guidance.
use std::{
ascii, fs, io,
net::SocketAddr,
path::{self, Path, PathBuf},
str,
sync::Arc,
};
use anyhow::{anyhow, bail, Context, Result};
use boring::pkey::PKey;
use boring::x509::X509;
use clap::Parser;
use quinn_boring2::QuicSslContext;
use tracing::{error, info, info_span, Instrument as _};
#[derive(Parser, Debug)]
#[clap(name = "server")]
struct Opt {
/// file to log TLS keys to for debugging
#[clap(long = "keylog")]
keylog: bool,
/// directory to serve files from
root: PathBuf,
/// TLS private key in PEM format
#[clap(short = 'k', long = "key", requires = "cert")]
key: Option<PathBuf>,
/// TLS certificate in PEM format
#[clap(short = 'c', long = "cert", requires = "key")]
cert: Option<PathBuf>,
/// Enable stateless retries
#[clap(long = "stateless-retry")]
stateless_retry: bool,
/// Address to listen on
#[clap(long = "listen", default_value = "[::1]:4433")]
listen: SocketAddr,
/// Client address to block
#[clap(long = "block")]
block: Option<SocketAddr>,
/// Maximum number of concurrent connections to allow
#[clap(long = "connection-limit")]
connection_limit: Option<usize>,
}
fn main() {
tracing::subscriber::set_global_default(
tracing_subscriber::FmtSubscriber::builder()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.finish(),
)
.unwrap();
let opt = Opt::parse();
let code = {
if let Err(e) = run(opt) {
eprintln!("ERROR: {e}");
1
} else {
0
}
};
std::process::exit(code);
}
#[tokio::main]
async fn run(options: Opt) -> Result<()> {
let (certs, key) = if let (Some(key_path), Some(cert_path)) = (&options.key, &options.cert) {
let key = fs::read(key_path).context("failed to read private key")?;
let key = if key_path.extension().map_or(false, |x| x == "der") {
PKey::private_key_from_der(&key)?
} else {
let key = rustls_pemfile::private_key(&mut &*key)
.context("malformed PKCS #1 private key")?
.ok_or_else(|| anyhow::Error::msg("no private keys found"))?;
PKey::private_key_from_der(key.secret_der())?
};
let cert_chain = fs::read(cert_path).context("failed to read certificate chain")?;
let cert_chain = if cert_path.extension().map_or(false, |x| x == "der") {
vec![X509::from_der(&cert_chain)?]
} else {
let mut certs = Vec::new();
for cert in rustls_pemfile::certs(&mut &*cert_chain) {
let cert = cert.context("invalid PEM-encoded certificate")?;
let x509 = X509::from_der(&cert).context("invalid X509 cert")?;
certs.push(x509);
}
certs
};
(cert_chain, key)
} else {
let dirs = directories_next::ProjectDirs::from("org", "quinn", "quinn-examples").unwrap();
let path = dirs.data_local_dir();
info!("using cert directory: {:?}", path);
let cert_path = path.join("cert.der");
let key_path = path.join("key.der");
let (cert, key) = match fs::read(&cert_path).and_then(|x| Ok((x, fs::read(&key_path)?))) {
Ok((cert, key)) => (cert, key),
Err(ref e) if e.kind() == io::ErrorKind::NotFound => {
info!("generating self-signed certificate");
let cert = rcgen::generate_simple_self_signed(vec!["localhost".into()]).unwrap();
let key = cert.key_pair.serialize_der();
let cert = cert.cert.der().to_vec();
fs::create_dir_all(path).context("failed to create certificate directory")?;
fs::write(&cert_path, &cert).context("failed to write certificate")?;
fs::write(&key_path, &key).context("failed to write private key")?;
(cert, key)
}
Err(e) => {
bail!("failed to read certificate: {}", e);
}
};
let key = PKey::private_key_from_der(&key)?;
let cert = X509::from_der(&cert)?;
(vec![cert], key)
};
let mut server_crypto = quinn_boring2::ServerConfig::new()?;
let ctx = server_crypto.ctx_mut();
for (i, cert) in certs.iter().enumerate() {
if i == 0 {
ctx.set_certificate(cert.clone())?;
} else {
if i < certs.len() - 1 {
ctx.add_to_cert_chain(cert.clone())?;
}
ctx.cert_store_mut().add_cert(cert.clone())?;
}
}
ctx.set_private_key(key)?;
ctx.check_private_key()?;
let mut server_config = quinn_boring2::helpers::server_config(Arc::new(server_crypto))?;
let transport_config = Arc::get_mut(&mut server_config.transport).unwrap();
transport_config.max_concurrent_uni_streams(0_u8.into());
let root = Arc::<Path>::from(options.root.clone());
if !root.exists() {
bail!("root path does not exist");
}
let endpoint = quinn_boring2::helpers::server_endpoint(server_config, options.listen)?;
eprintln!("listening on {}", endpoint.local_addr()?);
while let Some(conn) = endpoint.accept().await {
if options
.connection_limit
.map_or(false, |n| endpoint.open_connections() >= n)
{
info!("refusing due to open connection limit");
conn.refuse();
} else if Some(conn.remote_address()) == options.block {
info!("refusing blocked client IP address");
conn.refuse();
} else if options.stateless_retry && !conn.remote_address_validated() {
info!("requiring connection to validate its address");
conn.retry().unwrap();
} else {
info!("accepting connection");
let fut = handle_connection(root.clone(), conn);
tokio::spawn(async move {
if let Err(e) = fut.await {
error!("connection failed: {reason}", reason = e.to_string())
}
});
}
}
Ok(())
}
async fn handle_connection(root: Arc<Path>, conn: quinn::Incoming) -> Result<()> {
let connection = conn.await?;
let span = info_span!(
"connection",
remote = %connection.remote_address(),
protocol = %connection
.handshake_data()
.unwrap()
.downcast::<quinn_boring2::HandshakeData>().unwrap()
.protocol
.map_or_else(|| "<none>".into(), |x| String::from_utf8_lossy(&x).into_owned())
);
async {
info!("established");
// Each stream initiated by the client constitutes a new request.
loop {
let stream = connection.accept_bi().await;
let stream = match stream {
Err(quinn::ConnectionError::ApplicationClosed { .. }) => {
info!("connection closed");
return Ok(());
}
Err(e) => {
return Err(e);
}
Ok(s) => s,
};
let fut = handle_request(root.clone(), stream);
tokio::spawn(
async move {
if let Err(e) = fut.await {
error!("failed: {reason}", reason = e.to_string());
}
}
.instrument(info_span!("request")),
);
}
}
.instrument(span)
.await?;
Ok(())
}
async fn handle_request(
root: Arc<Path>,
(mut send, mut recv): (quinn::SendStream, quinn::RecvStream),
) -> Result<()> {
let req = recv
.read_to_end(64 * 1024)
.await
.map_err(|e| anyhow!("failed reading request: {}", e))?;
let mut escaped = String::new();
for &x in &req[..] {
let part = ascii::escape_default(x).collect::<Vec<_>>();
escaped.push_str(str::from_utf8(&part).unwrap());
}
info!(content = %escaped);
// Execute the request
let resp = process_get(&root, &req).unwrap_or_else(|e| {
error!("failed: {}", e);
format!("failed to process request: {e}\n").into_bytes()
});
// Write the response
send.write_all(&resp)
.await
.map_err(|e| anyhow!("failed to send response: {}", e))?;
// Gracefully terminate the stream
send.finish().unwrap();
info!("complete");
Ok(())
}
fn process_get(root: &Path, x: &[u8]) -> Result<Vec<u8>> {
if x.len() < 4 || &x[0..4] != b"GET " {
bail!("missing GET");
}
if x[4..].len() < 2 || &x[x.len() - 2..] != b"\r\n" {
bail!("missing \\r\\n");
}
let x = &x[4..x.len() - 2];
let end = x.iter().position(|&c| c == b' ').unwrap_or(x.len());
let path = str::from_utf8(&x[..end]).context("path is malformed UTF-8")?;
let path = Path::new(&path);
let mut real_path = PathBuf::from(root);
let mut components = path.components();
match components.next() {
Some(path::Component::RootDir) => {}
_ => {
bail!("path must be absolute");
}
}
for c in components {
match c {
path::Component::Normal(x) => {
real_path.push(x);
}
x => {
bail!("illegal component in path: {:?}", x);
}
}
}
let data = fs::read(&real_path).context("failed reading file")?;
Ok(data)
}
|
0x676e67/quinn-boring2
| 0
|
A crypto provider for quinn based on BoringSSL
|
Rust
|
0x676e67
| ||
src/aead.rs
|
Rust
|
use crate::error::{map_result, Error, Result};
use crate::key::{Key, Nonce, Tag};
use boring_sys as bffi;
use once_cell::sync::Lazy;
use std::mem::MaybeUninit;
const AES_128_GCM_KEY_LEN: usize = 16;
const AES_256_GCM_KEY_LEN: usize = 32;
const CHACHA20_POLY1305_KEY_LEN: usize = 32;
const AES_GCM_NONCE_LEN: usize = 12;
const POLY1305_NONCE_LEN: usize = 12;
pub(crate) const AES_GCM_TAG_LEN: usize = 16;
const POLY1305_TAG_LEN: usize = 16;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub(crate) enum ID {
Aes128Gcm,
Aes256Gcm,
Chacha20Poly1305,
}
/// Wrapper around a raw BoringSSL EVP_AEAD.
#[derive(Copy, Clone, PartialEq, Eq)]
struct AeadPtr(*const bffi::EVP_AEAD);
unsafe impl Send for AeadPtr {}
unsafe impl Sync for AeadPtr {}
impl AeadPtr {
fn aes128_gcm() -> Self {
unsafe { Self(bffi::EVP_aead_aes_128_gcm()) }
}
fn aes256_gcm() -> Self {
unsafe { Self(bffi::EVP_aead_aes_256_gcm()) }
}
fn chacha20_poly1305() -> Self {
unsafe { Self(bffi::EVP_aead_chacha20_poly1305()) }
}
}
/// Wrapper around an BoringSSL EVP_AEAD.
pub(crate) struct Aead {
ptr: AeadPtr,
pub(crate) id: ID,
pub(crate) key_len: usize,
pub(crate) tag_len: usize,
pub(crate) nonce_len: usize,
}
impl PartialEq for Aead {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}
impl Eq for Aead {}
static AES128_GCM: Lazy<Aead> = Lazy::new(|| Aead {
ptr: AeadPtr::aes128_gcm(),
id: ID::Aes128Gcm,
key_len: AES_128_GCM_KEY_LEN,
tag_len: AES_GCM_TAG_LEN,
nonce_len: AES_GCM_NONCE_LEN,
});
static AES256_GCM: Lazy<Aead> = Lazy::new(|| Aead {
ptr: AeadPtr::aes256_gcm(),
id: ID::Aes256Gcm,
key_len: AES_256_GCM_KEY_LEN,
tag_len: AES_GCM_TAG_LEN,
nonce_len: AES_GCM_NONCE_LEN,
});
static CHACHA20_POLY1305: Lazy<Aead> = Lazy::new(|| Aead {
ptr: AeadPtr::chacha20_poly1305(),
id: ID::Chacha20Poly1305,
key_len: CHACHA20_POLY1305_KEY_LEN,
tag_len: POLY1305_TAG_LEN,
nonce_len: POLY1305_NONCE_LEN,
});
impl Aead {
#[inline]
pub(crate) fn aes128_gcm() -> &'static Self {
&AES128_GCM
}
#[inline]
pub(crate) fn aes256_gcm() -> &'static Self {
&AES256_GCM
}
#[inline]
pub(crate) fn chacha20_poly1305() -> &'static Self {
&CHACHA20_POLY1305
}
/// Creates a new zeroed key of the appropriate length for the AEAD algorithm.
#[inline]
pub(crate) fn zero_key(&self) -> Key {
Key::with_len(self.key_len)
}
/// Creates a new zeroed nonce of the appropriate length for the AEAD algorithm.
#[inline]
pub(crate) fn zero_nonce(&self) -> Nonce {
Nonce::with_len(self.nonce_len)
}
/// Creates a new zeroed tag of the appropriate length for the AEAD algorithm.
#[inline]
pub(crate) fn zero_tag(&self) -> Tag {
Tag::with_len(self.tag_len)
}
#[inline]
pub(crate) fn as_ptr(&self) -> *const bffi::EVP_AEAD {
self.ptr.0
}
#[inline]
pub(crate) fn new_aead_ctx(&self, key: &Key) -> Result<bffi::EVP_AEAD_CTX> {
if key.len() != self.key_len {
return Err(Error::invalid_input(format!(
"key length invalid for AEAD_CTX: {}",
key.len()
)));
}
let ctx = unsafe {
let mut ctx = MaybeUninit::uninit();
map_result(bffi::EVP_AEAD_CTX_init(
ctx.as_mut_ptr(),
self.as_ptr(),
key.as_ptr(),
key.len(),
self.tag_len,
std::ptr::null_mut(),
))?;
ctx.assume_init()
};
Ok(ctx)
}
}
|
0x676e67/quinn-boring2
| 0
|
A crypto provider for quinn based on BoringSSL
|
Rust
|
0x676e67
| ||
src/alert.rs
|
Rust
|
use boring_sys as bffi;
use quinn_proto::{TransportError, TransportErrorCode};
use std::ffi::{c_int, CStr};
use std::fmt;
use std::fmt::{Display, Formatter};
use std::str::FromStr;
pub(crate) enum AlertType {
Warning,
Fatal,
Unknown,
}
impl AlertType {
const ALERT_TYPE_WARNING: &'static str = "warning";
const ALERT_TYPE_FATAL: &'static str = "fatal";
const ALERT_TYPE_UNKNOWN: &'static str = "unknown";
}
impl Display for AlertType {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::Warning => f.write_str(Self::ALERT_TYPE_WARNING),
Self::Fatal => f.write_str(Self::ALERT_TYPE_FATAL),
_ => f.write_str(Self::ALERT_TYPE_UNKNOWN),
}
}
}
impl FromStr for AlertType {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
Self::ALERT_TYPE_WARNING => Ok(Self::Warning),
Self::ALERT_TYPE_FATAL => Ok(Self::Fatal),
_ => Ok(Self::Unknown),
}
}
}
#[derive(Copy, Clone)]
pub(crate) struct Alert(u8);
impl Alert {
pub(crate) fn from(value: u8) -> Self {
Alert(value)
}
pub(crate) fn handshake_failure() -> Self {
Alert(bffi::SSL_AD_HANDSHAKE_FAILURE as u8)
}
pub(crate) fn get_description(&self) -> &'static str {
unsafe {
CStr::from_ptr(bffi::SSL_alert_desc_string_long(self.0 as c_int))
.to_str()
.unwrap()
}
}
}
impl Display for Alert {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "SSL alert [{}]: {}", self.0, self.get_description())
}
}
impl From<Alert> for TransportErrorCode {
fn from(alert: Alert) -> Self {
TransportErrorCode::crypto(alert.0)
}
}
impl From<Alert> for TransportError {
fn from(alert: Alert) -> Self {
TransportError {
code: alert.into(),
frame: None,
reason: alert.get_description().to_string(),
}
}
}
|
0x676e67/quinn-boring2
| 0
|
A crypto provider for quinn based on BoringSSL
|
Rust
|
0x676e67
| ||
src/alpn.rs
|
Rust
|
use crate::error::{Error, Result};
#[derive(Clone, Debug)]
pub(crate) struct AlpnProtocol(Vec<u8>);
impl AlpnProtocol {
#[inline]
pub(crate) fn encode(&self, encoded: &mut Vec<u8>) {
encoded.push(self.0.len() as u8);
encoded.extend_from_slice(&self.0);
}
}
impl From<Vec<u8>> for AlpnProtocol {
fn from(value: Vec<u8>) -> Self {
Self(value)
}
}
#[derive(Clone, Debug)]
pub(crate) struct AlpnProtocols(Vec<AlpnProtocol>);
impl AlpnProtocols {
pub(crate) const H3: &'static [u8; 2] = b"h3";
/// Performs the server-side ALPN protocol selection.
pub(crate) fn select<'a>(&self, offered: &'a [u8]) -> Result<&'a [u8]> {
for server_proto in &self.0 {
let mut i = 0;
while i < offered.len() {
let len = offered[i] as usize;
i += 1;
let client_proto = &offered[i..i + len];
if server_proto.0 == client_proto {
return Ok(client_proto);
}
i += len;
}
}
Err(Error::other("ALPN selection failed".into()))
}
pub(crate) fn encode(&self) -> Vec<u8> {
let mut out: Vec<u8> = Vec::new();
for proto in &self.0 {
proto.encode(&mut out);
}
out
}
}
impl Default for AlpnProtocols {
fn default() -> Self {
Self::from(&[Self::H3.to_vec()][..])
}
}
impl From<&[Vec<u8>]> for AlpnProtocols {
fn from(protos: &[Vec<u8>]) -> Self {
let mut out = Vec::with_capacity(protos.len());
for proto in protos {
out.push(AlpnProtocol(proto.clone()))
}
Self(out)
}
}
impl From<&Vec<Vec<u8>>> for AlpnProtocols {
fn from(protos: &Vec<Vec<u8>>) -> Self {
Self::from(protos.as_slice())
}
}
|
0x676e67/quinn-boring2
| 0
|
A crypto provider for quinn based on BoringSSL
|
Rust
|
0x676e67
| ||
src/bffi_ext.rs
|
Rust
|
use crate::error::{br, br_zero_is_success, BoringResult};
use boring::error::ErrorStack;
use boring::pkey::{HasPrivate, PKey};
use boring::ssl::{Ssl, SslContext, SslContextRef, SslSession};
use boring::x509::store::X509StoreBuilderRef;
use boring::x509::X509;
use boring_sys as bffi;
use bytes::{Buf, BufMut};
use foreign_types_shared::{ForeignType, ForeignTypeRef};
use std::ffi::{c_char, c_int, c_uint, c_void, CStr};
use std::fmt::{Display, Formatter};
use std::result::Result as StdResult;
use std::{ffi, fmt, mem, ptr, slice};
/// Provides additional methods to [SslContext] needed for QUIC.
pub trait QuicSslContext {
fn set_options(&mut self, options: u32) -> u32;
fn verify_peer(&mut self, verify: bool);
fn set_quic_method(&mut self, method: &bffi::SSL_QUIC_METHOD) -> BoringResult;
fn set_session_cache_mode(&mut self, mode: c_int) -> c_int;
fn set_new_session_callback(
&mut self,
cb: Option<
unsafe extern "C" fn(ssl: *mut bffi::SSL, session: *mut bffi::SSL_SESSION) -> c_int,
>,
);
fn set_info_callback(
&mut self,
cb: Option<unsafe extern "C" fn(ssl: *const bffi::SSL, type_: c_int, value: c_int)>,
);
fn set_keylog_callback(
&mut self,
cb: Option<unsafe extern "C" fn(ssl: *const bffi::SSL, line: *const c_char)>,
);
fn set_certificate(&mut self, cert: X509) -> BoringResult;
fn load_certificate_from_pem_file(&mut self, path: &str) -> BoringResult;
fn add_to_cert_chain(&mut self, cert: X509) -> BoringResult;
fn load_cert_chain_from_pem_file(&mut self, path: &str) -> BoringResult;
fn set_private_key<T: HasPrivate>(&mut self, key: PKey<T>) -> BoringResult;
fn load_private_key_from_pem_file(&mut self, path: &str) -> BoringResult;
fn check_private_key(&self) -> BoringResult;
fn cert_store_mut(&mut self) -> &mut X509StoreBuilderRef;
fn enable_early_data(&mut self, enable: bool);
fn set_alpn_protos(&mut self, protos: &[u8]) -> BoringResult;
fn set_alpn_select_cb(
&mut self,
cb: Option<
unsafe extern "C" fn(
ssl: *mut bffi::SSL,
out: *mut *const u8,
out_len: *mut u8,
in_: *const u8,
in_len: c_uint,
arg: *mut c_void,
) -> c_int,
>,
);
fn set_server_name_cb(
&mut self,
cb: Option<
unsafe extern "C" fn(
ssl: *mut bffi::SSL,
out_alert: *mut c_int,
arg: *mut c_void,
) -> c_int,
>,
);
fn set_select_certificate_cb(
&mut self,
cb: Option<
unsafe extern "C" fn(
arg1: *const bffi::SSL_CLIENT_HELLO,
) -> bffi::ssl_select_cert_result_t,
>,
);
}
impl QuicSslContext for SslContext {
fn set_options(&mut self, options: u32) -> u32 {
unsafe { bffi::SSL_CTX_set_options(self.as_ptr(), options) }
}
fn verify_peer(&mut self, verify: bool) {
let mode = if verify {
bffi::SSL_VERIFY_PEER | bffi::SSL_VERIFY_FAIL_IF_NO_PEER_CERT
} else {
bffi::SSL_VERIFY_NONE
};
unsafe { bffi::SSL_CTX_set_verify(self.as_ptr(), mode, None) }
}
fn set_quic_method(&mut self, method: &bffi::SSL_QUIC_METHOD) -> BoringResult {
unsafe { br(bffi::SSL_CTX_set_quic_method(self.as_ptr(), method)) }
}
fn set_session_cache_mode(&mut self, mode: c_int) -> c_int {
unsafe { bffi::SSL_CTX_set_session_cache_mode(self.as_ptr(), mode) }
}
fn set_new_session_callback(
&mut self,
cb: Option<
unsafe extern "C" fn(ssl: *mut bffi::SSL, session: *mut bffi::SSL_SESSION) -> c_int,
>,
) {
unsafe {
bffi::SSL_CTX_sess_set_new_cb(self.as_ptr(), cb);
}
}
fn set_info_callback(
&mut self,
cb: Option<unsafe extern "C" fn(ssl: *const bffi::SSL, type_: c_int, value: c_int)>,
) {
unsafe { bffi::SSL_CTX_set_info_callback(self.as_ptr(), cb) }
}
fn set_keylog_callback(
&mut self,
cb: Option<unsafe extern "C" fn(ssl: *const bffi::SSL, line: *const c_char)>,
) {
unsafe { bffi::SSL_CTX_set_keylog_callback(self.as_ptr(), cb) }
}
fn set_certificate(&mut self, cert: X509) -> BoringResult {
unsafe {
br(bffi::SSL_CTX_use_certificate(self.as_ptr(), cert.as_ptr()))?;
mem::forget(cert);
Ok(())
}
}
fn load_certificate_from_pem_file(&mut self, path: &str) -> BoringResult {
let path = ffi::CString::new(path).unwrap();
unsafe {
br(bffi::SSL_CTX_use_certificate_file(
self.as_ptr(),
path.as_ptr(),
bffi::SSL_FILETYPE_PEM,
))
}
}
fn add_to_cert_chain(&mut self, cert: X509) -> BoringResult {
unsafe {
br(bffi::SSL_CTX_add_extra_chain_cert(self.as_ptr(), cert.as_ptr()) as c_int)?;
mem::forget(cert);
Ok(())
}
}
fn load_cert_chain_from_pem_file(&mut self, path: &str) -> BoringResult {
let path = ffi::CString::new(path).unwrap();
unsafe {
br(bffi::SSL_CTX_use_certificate_chain_file(
self.as_ptr(),
path.as_ptr(),
))
}
}
fn set_private_key<T: HasPrivate>(&mut self, key: PKey<T>) -> BoringResult {
unsafe {
br(bffi::SSL_CTX_use_PrivateKey(self.as_ptr(), key.as_ptr()))?;
mem::forget(key);
Ok(())
}
}
fn load_private_key_from_pem_file(&mut self, path: &str) -> BoringResult {
let path = ffi::CString::new(path).unwrap();
unsafe {
br(bffi::SSL_CTX_use_PrivateKey_file(
self.as_ptr(),
path.as_ptr(),
bffi::SSL_FILETYPE_PEM,
))
}
}
fn check_private_key(&self) -> BoringResult {
unsafe { br(bffi::SSL_CTX_check_private_key(self.as_ptr())) }
}
fn cert_store_mut(&mut self) -> &mut X509StoreBuilderRef {
unsafe { X509StoreBuilderRef::from_ptr_mut(bffi::SSL_CTX_get_cert_store(self.as_ptr())) }
}
fn enable_early_data(&mut self, enable: bool) {
unsafe { bffi::SSL_CTX_set_early_data_enabled(self.as_ptr(), enable.into()) }
}
fn set_alpn_protos(&mut self, protos: &[u8]) -> BoringResult {
unsafe {
br_zero_is_success(bffi::SSL_CTX_set_alpn_protos(
self.as_ptr(),
protos.as_ptr(),
protos.len() as _,
))
}
}
fn set_alpn_select_cb(
&mut self,
cb: Option<
unsafe extern "C" fn(
*mut bffi::SSL,
*mut *const u8,
*mut u8,
*const u8,
c_uint,
*mut c_void,
) -> c_int,
>,
) {
unsafe { bffi::SSL_CTX_set_alpn_select_cb(self.as_ptr(), cb, ptr::null_mut()) }
}
fn set_server_name_cb(
&mut self,
cb: Option<
unsafe extern "C" fn(
ssl: *mut bffi::SSL,
out_alert: *mut c_int,
arg: *mut c_void,
) -> c_int,
>,
) {
// The function always returns 1.
unsafe {
let _ = bffi::SSL_CTX_set_tlsext_servername_callback(self.as_ptr(), cb);
}
}
fn set_select_certificate_cb(
&mut self,
cb: Option<
unsafe extern "C" fn(
arg1: *const bffi::SSL_CLIENT_HELLO,
) -> bffi::ssl_select_cert_result_t,
>,
) {
unsafe { bffi::SSL_CTX_set_select_certificate_cb(self.as_ptr(), cb) }
}
}
/// Provides additional methods to [Ssl] needed for QUIC.
pub trait QuicSsl {
fn set_connect_state(&mut self);
fn set_accept_state(&mut self);
fn state_string(&self) -> &'static str;
fn set_quic_transport_params(&mut self, params: &[u8]) -> BoringResult;
fn get_peer_quic_transport_params(&self) -> Option<&[u8]>;
fn get_error(&self, raw: c_int) -> SslError;
fn is_handshaking(&self) -> bool;
fn do_handshake(&mut self) -> SslError;
fn provide_quic_data(&mut self, level: Level, data: &[u8]) -> SslError;
fn quic_max_handshake_flight_len(&self, level: Level) -> usize;
fn quic_read_level(&self) -> Level;
fn quic_write_level(&self) -> Level;
fn process_post_handshake(&mut self) -> SslError;
fn set_verify_hostname(&mut self, domain: &str) -> BoringResult;
fn export_keyring_material(
&self,
output: &mut [u8],
label: &[u8],
context: &[u8],
) -> BoringResult;
fn in_early_data(&self) -> bool;
fn early_data_accepted(&self) -> bool;
fn set_quic_method(&mut self, method: &bffi::SSL_QUIC_METHOD) -> BoringResult;
fn set_quic_early_data_context(&mut self, value: &[u8]) -> BoringResult;
fn get_early_data_reason(&self) -> bffi::ssl_early_data_reason_t;
fn early_data_reason_string(reason: bffi::ssl_early_data_reason_t) -> &'static str;
fn reset_early_rejected_data(&mut self);
fn set_quic_use_legacy_codepoint(&mut self, use_legacy: bool);
}
impl QuicSsl for Ssl {
fn set_connect_state(&mut self) {
unsafe { bffi::SSL_set_connect_state(self.as_ptr()) }
}
fn set_accept_state(&mut self) {
unsafe { bffi::SSL_set_accept_state(self.as_ptr()) }
}
fn state_string(&self) -> &'static str {
unsafe {
CStr::from_ptr(bffi::SSL_state_string_long(self.as_ptr()))
.to_str()
.unwrap()
}
}
fn set_quic_transport_params(&mut self, params: &[u8]) -> BoringResult {
unsafe {
br(bffi::SSL_set_quic_transport_params(
self.as_ptr(),
params.as_ptr(),
params.len(),
))
}
}
fn get_peer_quic_transport_params(&self) -> Option<&[u8]> {
let mut ptr: *const u8 = ptr::null();
let mut len: usize = 0;
unsafe {
bffi::SSL_get_peer_quic_transport_params(self.as_ptr(), &mut ptr, &mut len);
if len == 0 {
None
} else {
Some(slice::from_raw_parts(ptr, len))
}
}
}
#[inline]
fn get_error(&self, raw: c_int) -> SslError {
unsafe { SslError(bffi::SSL_get_error(self.as_ptr(), raw)) }
}
#[inline]
fn is_handshaking(&self) -> bool {
unsafe { bffi::SSL_in_init(self.as_ptr()) == 1 }
}
#[inline]
fn do_handshake(&mut self) -> SslError {
self.get_error(unsafe { bffi::SSL_do_handshake(self.as_ptr()) })
}
#[inline]
fn provide_quic_data(&mut self, level: Level, plaintext: &[u8]) -> SslError {
unsafe {
self.get_error(bffi::SSL_provide_quic_data(
self.as_ptr(),
level.into(),
plaintext.as_ptr(),
plaintext.len(),
))
}
}
#[inline]
fn quic_max_handshake_flight_len(&self, level: Level) -> usize {
unsafe { bffi::SSL_quic_max_handshake_flight_len(self.as_ptr(), level.into()) }
}
#[inline]
fn quic_read_level(&self) -> Level {
unsafe { bffi::SSL_quic_read_level(self.as_ptr()).into() }
}
#[inline]
fn quic_write_level(&self) -> Level {
unsafe { bffi::SSL_quic_write_level(self.as_ptr()).into() }
}
#[inline]
fn process_post_handshake(&mut self) -> SslError {
self.get_error(unsafe { bffi::SSL_process_quic_post_handshake(self.as_ptr()) })
}
fn set_verify_hostname(&mut self, domain: &str) -> BoringResult {
let param = self.param_mut();
param.set_hostflags(boring::x509::verify::X509CheckFlags::NO_PARTIAL_WILDCARDS);
match domain.parse() {
Ok(ip) => param.set_ip(ip)?,
Err(_) => param.set_host(domain)?,
}
Ok(())
}
#[inline]
fn export_keyring_material(
&self,
output: &mut [u8],
label: &[u8],
context: &[u8],
) -> BoringResult {
unsafe {
br(bffi::SSL_export_keying_material(
self.as_ptr(),
output.as_mut_ptr(),
output.len(),
label.as_ptr() as *const c_char,
label.len(),
context.as_ptr(),
context.len(),
context.is_empty() as _,
))
}
}
#[inline]
fn in_early_data(&self) -> bool {
unsafe { bffi::SSL_in_early_data(self.as_ptr()) == 1 }
}
#[inline]
fn early_data_accepted(&self) -> bool {
unsafe { bffi::SSL_early_data_accepted(self.as_ptr()) == 1 }
}
fn set_quic_method(&mut self, method: &bffi::SSL_QUIC_METHOD) -> BoringResult {
unsafe { br(bffi::SSL_set_quic_method(self.as_ptr(), method)) }
}
fn set_quic_early_data_context(&mut self, value: &[u8]) -> BoringResult {
unsafe {
br(bffi::SSL_set_quic_early_data_context(
self.as_ptr(),
value.as_ptr(),
value.len(),
))
}
}
fn get_early_data_reason(&self) -> bffi::ssl_early_data_reason_t {
unsafe { bffi::SSL_get_early_data_reason(self.as_ptr()) }
}
fn early_data_reason_string(reason: bffi::ssl_early_data_reason_t) -> &'static str {
unsafe {
bffi::SSL_early_data_reason_string(reason)
.as_ref()
.map_or("unknown", |reason| CStr::from_ptr(reason).to_str().unwrap())
}
}
#[inline]
fn reset_early_rejected_data(&mut self) {
unsafe { bffi::SSL_reset_early_data_reject(self.as_ptr()) }
}
fn set_quic_use_legacy_codepoint(&mut self, use_legacy: bool) {
unsafe { bffi::SSL_set_quic_use_legacy_codepoint(self.as_ptr(), use_legacy as _) }
}
}
pub trait QuicSslSession {
fn early_data_capable(&self) -> bool;
fn copy_without_early_data(&mut self) -> SslSession;
fn encode<W: BufMut>(&self, out: &mut W) -> BoringResult;
fn decode<R: Buf>(ctx: &SslContextRef, r: &mut R) -> StdResult<SslSession, ErrorStack>;
}
impl QuicSslSession for SslSession {
fn early_data_capable(&self) -> bool {
unsafe { bffi::SSL_SESSION_early_data_capable(self.as_ptr()) == 1 }
}
fn copy_without_early_data(&mut self) -> SslSession {
unsafe { SslSession::from_ptr(bffi::SSL_SESSION_copy_without_early_data(self.as_ptr())) }
}
fn encode<W: BufMut>(&self, out: &mut W) -> BoringResult {
unsafe {
let mut buf: *mut u8 = ptr::null_mut();
let mut len = 0usize;
br(bffi::SSL_SESSION_to_bytes(
self.as_ptr(),
&mut buf,
&mut len,
))?;
out.put_slice(slice::from_raw_parts(buf, len));
bffi::OPENSSL_free(buf as _);
Ok(())
}
}
fn decode<R: Buf>(ctx: &SslContextRef, r: &mut R) -> StdResult<SslSession, ErrorStack> {
unsafe {
let in_len = r.remaining();
let in_ = r.chunk();
bffi::SSL_SESSION_from_bytes(in_.as_ptr(), in_len, ctx.as_ptr())
.as_mut()
.map_or_else(
|| Err(ErrorStack::get()),
|session| Ok(SslSession::from_ptr(session)),
)
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub enum Level {
Initial = 0,
EarlyData = 1,
Handshake = 2,
Application = 3,
}
impl Level {
pub const NUM_LEVELS: usize = 4;
pub fn next(&self) -> Self {
match self {
Level::Initial => Level::Handshake,
Level::EarlyData => Level::Handshake,
_ => Level::Application,
}
}
}
impl From<bffi::ssl_encryption_level_t> for Level {
fn from(value: bffi::ssl_encryption_level_t) -> Self {
match value {
bffi::ssl_encryption_level_t::ssl_encryption_initial => Self::Initial,
bffi::ssl_encryption_level_t::ssl_encryption_early_data => Self::EarlyData,
bffi::ssl_encryption_level_t::ssl_encryption_handshake => Self::Handshake,
bffi::ssl_encryption_level_t::ssl_encryption_application => Self::Application,
_ => unreachable!(),
}
}
}
impl From<Level> for bffi::ssl_encryption_level_t {
fn from(value: Level) -> Self {
match value {
Level::Initial => bffi::ssl_encryption_level_t::ssl_encryption_initial,
Level::EarlyData => bffi::ssl_encryption_level_t::ssl_encryption_early_data,
Level::Handshake => bffi::ssl_encryption_level_t::ssl_encryption_handshake,
Level::Application => bffi::ssl_encryption_level_t::ssl_encryption_application,
}
}
}
#[derive(Copy, Clone)]
pub struct SslError(c_int);
impl SslError {
#[inline]
pub fn value(&self) -> c_int {
self.0
}
#[inline]
pub fn is_none(&self) -> bool {
self.0 == bffi::SSL_ERROR_NONE
}
#[inline]
pub fn get_description(&self) -> &'static str {
unsafe {
CStr::from_ptr(bffi::SSL_error_description(self.0))
.to_str()
.unwrap()
}
}
}
impl Display for SslError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "SSL_ERROR[{}]: {}", self.0, self.get_description())
}
}
|
0x676e67/quinn-boring2
| 0
|
A crypto provider for quinn based on BoringSSL
|
Rust
|
0x676e67
| ||
src/client.rs
|
Rust
|
use crate::alpn::AlpnProtocols;
use crate::bffi_ext::QuicSslContext;
use crate::error::{map_result, Result};
use crate::session_state::{SessionState, QUIC_METHOD};
use crate::version::QuicVersion;
use crate::{Entry, KeyLog, NoKeyLog, QuicSsl, QuicSslSession, SessionCache, SimpleCache};
use boring::ssl::{Ssl, SslContext, SslContextBuilder, SslMethod, SslSession, SslVersion};
use boring_sys as bffi;
use bytes::{Bytes, BytesMut};
use foreign_types_shared::ForeignType;
use once_cell::sync::Lazy;
use quinn_proto::{
crypto, transport_parameters::TransportParameters, ConnectError, ConnectionId, Side,
TransportError,
};
use std::any::Any;
use std::ffi::c_int;
use std::io::Cursor;
use std::result::Result as StdResult;
use std::sync::Arc;
use tracing::{trace, warn};
/// Configuration for a client-side QUIC. Wraps around a BoringSSL [SslContext].
pub struct Config {
ctx: SslContext,
session_cache: Arc<dyn SessionCache>,
key_log: Option<Arc<dyn KeyLog>>,
}
impl Config {
pub fn new() -> Result<Self> {
let mut builder = SslContextBuilder::new(SslMethod::tls())?;
// QUIC requires TLS 1.3.
builder.set_min_proto_version(Some(SslVersion::TLS1_3))?;
builder.set_max_proto_version(Some(SslVersion::TLS1_3))?;
builder.set_default_verify_paths()?;
// We build the context early, since we are not allowed to further mutate the context
// in start_session.
let mut ctx = builder.build();
// By default, enable early data (used for 0-RTT).
ctx.enable_early_data(true);
// Set the default ALPN protocols offered by the client. QUIC requires ALPN be configured
// (see <https://www.rfc-editor.org/rfc/rfc9001.html#section-8.1>).
ctx.set_alpn_protos(&AlpnProtocols::default().encode())?;
// Configure session caching.
ctx.set_session_cache_mode(bffi::SSL_SESS_CACHE_CLIENT | bffi::SSL_SESS_CACHE_NO_INTERNAL);
ctx.set_new_session_callback(Some(Session::new_session_callback));
// Set callbacks for the SessionState.
ctx.set_quic_method(&QUIC_METHOD)?;
ctx.set_info_callback(Some(SessionState::info_callback));
// For clients, verification of the server is on by default.
ctx.verify_peer(true);
Ok(Self {
ctx,
session_cache: Arc::new(SimpleCache::new(256)),
key_log: None,
})
}
/// Returns the underlying [SslContext] backing all created sessions.
pub fn ctx(&self) -> &SslContext {
&self.ctx
}
/// Returns the underlying [SslContext] backing all created sessions. Wherever possible use
/// the provided methods to modify settings rather than accessing this directly.
///
/// Care should be taken to avoid overriding required behavior. In particular, this
/// configuration will set callbacks for QUIC events, alpn selection, server name,
/// as well as info and key logging.
pub fn ctx_mut(&mut self) -> &mut SslContext {
&mut self.ctx
}
/// Sets whether or not the peer certificate should be verified. If `true`, any error
/// during verification will be fatal. If not called, verification of the server is
/// enabled by default.
pub fn verify_peer(&mut self, verify: bool) {
self.ctx.verify_peer(verify)
}
/// Gets the [SessionCache] used to cache all client sessions.
pub fn get_session_cache(&self) -> Arc<dyn SessionCache> {
self.session_cache.clone()
}
/// Sets the [SessionCache] to be shared by all created client sessions.
pub fn set_session_cache(&mut self, session_cache: Arc<dyn SessionCache>) {
self.session_cache = session_cache;
}
/// Sets the ALPN protocols supported by the client. QUIC requires that
/// ALPN be used (see <https://www.rfc-editor.org/rfc/rfc9001.html#section-8.1>).
/// By default, the client will offer "h3".
pub fn set_alpn(&mut self, alpn_protocols: &[Vec<u8>]) -> Result<()> {
self.ctx
.set_alpn_protos(&AlpnProtocols::from(alpn_protocols).encode())?;
Ok(())
}
/// Sets the [KeyLog] for the client. By default, no key logging will occur.
pub fn set_key_log(&mut self, key_log: Option<Arc<dyn KeyLog>>) {
self.key_log = key_log;
// Optimization for key logging. Only set the callback if a logger was supplied,
// since the BoringSSL processing isn't free.
match &self.key_log {
Some(_) => {
self.ctx
.set_keylog_callback(Some(SessionState::keylog_callback));
}
None => {
self.ctx.set_keylog_callback(None);
}
}
}
}
impl crypto::ClientConfig for Config {
fn start_session(
self: Arc<Self>,
version: u32,
server_name: &str,
params: &TransportParameters,
) -> StdResult<Box<dyn crypto::Session>, ConnectError> {
let version = QuicVersion::parse(version).unwrap();
Ok(Session::new(self, version, server_name, params)
.map_err(|_| ConnectError::EndpointStopping)?)
}
}
static SESSION_INDEX: Lazy<c_int> = Lazy::new(|| unsafe {
bffi::SSL_get_ex_new_index(0, std::ptr::null_mut(), std::ptr::null_mut(), None, None)
});
/// The [crypto::Session] implementation for BoringSSL.
struct Session {
state: Box<SessionState>,
server_name: Bytes,
session_cache: Arc<dyn SessionCache>,
zero_rtt_peer_params: Option<TransportParameters>,
handshake_data_available: bool,
handshake_data_sent: bool,
}
impl Session {
fn new(
cfg: Arc<Config>,
version: QuicVersion,
server_name: &str,
params: &TransportParameters,
) -> Result<Box<Self>> {
let session_cache = cfg.session_cache.clone();
let mut ssl = Ssl::new(&cfg.ctx).unwrap();
// Configure the TLS extension based on the QUIC version used.
ssl.set_quic_use_legacy_codepoint(version.uses_legacy_extension());
// Configure the SSL to be a client.
ssl.set_connect_state();
// Configure verification for the server hostname.
ssl.set_verify_hostname(server_name)
.map_err(|_| ConnectError::InvalidServerName(server_name.into()))?;
// Set the SNI hostname.
// TODO: should we validate the hostname?
ssl.set_hostname(server_name)
.map_err(|_| ConnectError::InvalidServerName(server_name.into()))?;
// Set the transport parameters.
ssl.set_quic_transport_params(&encode_params(params))
.map_err(|_| ConnectError::EndpointStopping)?;
let server_name_bytes = Bytes::copy_from_slice(server_name.as_bytes());
// If we have a cached session, use it.
let mut zero_rtt_peer_params = None;
if let Some(entry) = session_cache.get(server_name_bytes.clone()) {
match Entry::decode(ssl.ssl_context(), entry) {
Ok(entry) => {
zero_rtt_peer_params = Some(entry.params);
match unsafe { ssl.set_session(entry.session.as_ref()) } {
Ok(()) => {
trace!("attempting resumption (0-RTT) for server: {}.", server_name);
}
Err(e) => {
warn!(
"failed setting cached session for server {}: {:?}",
server_name, e
)
}
}
}
Err(e) => {
warn!(
"failed decoding session entry for server {}: {:?}",
server_name, e
)
}
}
} else {
trace!(
"no cached session found for server: {}. Will continue with 1-RTT.",
server_name
);
}
let mut session = Box::new(Self {
state: SessionState::new(
ssl,
Side::Client,
version,
cfg.key_log
.as_ref()
.map_or(Arc::new(NoKeyLog), |key_log| key_log.clone()),
)?,
server_name: server_name_bytes,
session_cache,
zero_rtt_peer_params,
handshake_data_available: false,
handshake_data_sent: false,
});
// Register the instance in SSL ex_data. This allows the static callbacks to
// reference the instance.
unsafe {
map_result(bffi::SSL_set_ex_data(
session.state.ssl.as_ptr(),
*SESSION_INDEX,
&mut *session as *mut Self as *mut _,
))?;
}
// Start the handshake in order to emit the Client Hello on the first
// call to write_handshake.
session.state.advance_handshake()?;
Ok(session)
}
/// Handler for the rejection of a 0-RTT attempt. Will continue with 1-RTT.
fn on_zero_rtt_rejected(&mut self) {
trace!(
"0-RTT handshake attempted but was rejected by the server: {}",
Ssl::early_data_reason_string(self.state.ssl.get_early_data_reason())
);
self.zero_rtt_peer_params = None;
// Removed the failed cache entry.
self.session_cache.remove(self.server_name.clone());
// Now retry advancing the handshake, this time in 1-RTT mode.
if let Err(e) = self.state.advance_handshake() {
warn!("failed advancing 1-RTT handshake: {:?}", e)
}
}
/// Client-side only callback from BoringSSL to allow caching of a new session.
fn on_new_session(&mut self, session: SslSession) {
if !session.early_data_capable() {
warn!("failed caching session: not early data capable");
return;
}
// Get the server transport parameters.
let params = match self.state.ssl.get_peer_quic_transport_params() {
Some(params) => {
match TransportParameters::read(Side::Client, &mut Cursor::new(¶ms)) {
Ok(params) => params,
Err(e) => {
warn!("failed parsing server transport parameters: {:?}", e);
return;
}
}
}
None => {
warn!("failed caching session: server transport parameters are not available");
return;
}
};
// Encode the session cache entry, including both the session and the server params.
let entry = Entry { session, params };
match entry.encode() {
Ok(value) => {
// Cache the session.
self.session_cache.put(self.server_name.clone(), value)
}
Err(e) => {
warn!("failed caching session: unable to encode entry: {:?}", e);
}
}
}
/// Called by the static callbacks to retrieve the instance pointer.
#[inline]
fn get_instance(ssl: *const bffi::SSL) -> &'static mut Session {
unsafe {
let data = bffi::SSL_get_ex_data(ssl, *SESSION_INDEX);
if data.is_null() {
panic!("BUG: Session instance missing")
}
&mut *(data as *mut Session)
}
}
/// Raw callback from BoringSSL.
extern "C" fn new_session_callback(
ssl: *mut bffi::SSL,
session: *mut bffi::SSL_SESSION,
) -> c_int {
let inst = Self::get_instance(ssl);
let session = unsafe { SslSession::from_ptr(session) };
inst.on_new_session(session);
// Return 1 to indicate we've taken ownership of the session.
1
}
}
impl crypto::Session for Session {
fn initial_keys(&self, dcid: &ConnectionId, side: Side) -> crypto::Keys {
self.state.initial_keys(dcid, side)
}
fn handshake_data(&self) -> Option<Box<dyn Any>> {
self.state.handshake_data()
}
fn peer_identity(&self) -> Option<Box<dyn Any>> {
self.state.peer_identity()
}
fn early_crypto(&self) -> Option<(Box<dyn crypto::HeaderKey>, Box<dyn crypto::PacketKey>)> {
self.state.early_crypto()
}
fn early_data_accepted(&self) -> Option<bool> {
Some(self.state.ssl.early_data_accepted())
}
fn is_handshaking(&self) -> bool {
self.state.is_handshaking()
}
fn read_handshake(&mut self, plaintext: &[u8]) -> StdResult<bool, TransportError> {
self.state.read_handshake(plaintext)?;
if self.state.early_data_rejected {
self.on_zero_rtt_rejected();
}
// Only indicate that handshake data is available once.
// On the client side there is no ALPN callback, so we need to manually check
// if the ALPN protocol has been selected.
if !self.handshake_data_sent {
if self.state.ssl.selected_alpn_protocol().is_some() {
self.handshake_data_available = true;
}
if self.handshake_data_available {
self.handshake_data_sent = true;
return Ok(true);
}
}
Ok(false)
}
fn transport_parameters(&self) -> StdResult<Option<TransportParameters>, TransportError> {
match self.state.transport_parameters()? {
Some(params) => Ok(Some(params)),
None => {
if self.state.ssl.in_early_data() {
Ok(self.zero_rtt_peer_params)
} else {
Ok(None)
}
}
}
}
fn write_handshake(&mut self, buf: &mut Vec<u8>) -> Option<crypto::Keys> {
self.state.write_handshake(buf)
}
fn next_1rtt_keys(&mut self) -> Option<crypto::KeyPair<Box<dyn crypto::PacketKey>>> {
self.state.next_1rtt_keys()
}
fn is_valid_retry(&self, orig_dst_cid: &ConnectionId, header: &[u8], payload: &[u8]) -> bool {
self.state.is_valid_retry(orig_dst_cid, header, payload)
}
fn export_keying_material(
&self,
output: &mut [u8],
label: &[u8],
context: &[u8],
) -> StdResult<(), crypto::ExportKeyingMaterialError> {
self.state.export_keying_material(output, label, context)
}
}
fn encode_params(params: &TransportParameters) -> Bytes {
let mut out = BytesMut::with_capacity(128);
params.write(&mut out);
out.freeze()
}
|
0x676e67/quinn-boring2
| 0
|
A crypto provider for quinn based on BoringSSL
|
Rust
|
0x676e67
| ||
src/error.rs
|
Rust
|
use boring::error::ErrorStack;
use quinn_proto::{crypto, ConnectError, TransportError};
use std::ffi::c_int;
use std::fmt::{Debug, Display, Formatter};
use std::io::ErrorKind;
use std::result::Result as StdResult;
use std::{fmt, io};
// Error conversion:
pub enum Error {
SslError(ErrorStack),
IoError(io::Error),
ConnectError(ConnectError),
TransportError(TransportError),
}
impl Debug for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::SslError(e) => Debug::fmt(&e, f),
Self::IoError(e) => Debug::fmt(&e, f),
Self::ConnectError(e) => Debug::fmt(&e, f),
Self::TransportError(e) => Debug::fmt(&e, f),
}
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::SslError(e) => Display::fmt(&e, f),
Self::IoError(e) => Display::fmt(&e, f),
Self::ConnectError(e) => Display::fmt(&e, f),
Self::TransportError(e) => Display::fmt(&e, f),
}
}
}
impl std::error::Error for Error {}
impl Error {
pub(crate) fn ssl() -> Self {
Error::SslError(ErrorStack::get())
}
pub(crate) fn invalid_input(msg: String) -> Self {
Error::IoError(io::Error::new(ErrorKind::InvalidInput, msg))
}
pub(crate) fn other(msg: String) -> Self {
Error::IoError(io::Error::new(ErrorKind::Other, msg))
}
}
/// Support conversion to CryptoError.
impl From<Error> for crypto::CryptoError {
fn from(_: Error) -> Self {
crypto::CryptoError
}
}
/// Support conversion to ConnectError.
impl From<Error> for ConnectError {
fn from(e: Error) -> Self {
match e {
Error::SslError(_) => Self::EndpointStopping,
Error::IoError(_) => Self::EndpointStopping,
Error::ConnectError(e) => e,
Error::TransportError(_) => Self::EndpointStopping,
}
}
}
impl From<ErrorStack> for Error {
fn from(e: ErrorStack) -> Self {
Error::SslError(e)
}
}
impl From<io::Error> for Error {
fn from(e: io::Error) -> Self {
Error::IoError(e)
}
}
impl From<ConnectError> for Error {
fn from(e: ConnectError) -> Self {
Error::ConnectError(e)
}
}
impl From<TransportError> for Error {
fn from(e: TransportError) -> Self {
Error::TransportError(e)
}
}
/// The main result type for this (crypto boring) module.
pub type Result<T> = StdResult<T, Error>;
/// The result returned by the Cloudflare Boring library API functions.
pub(crate) type BoringResult = StdResult<(), ErrorStack>;
/// Maps BoringSSL ffi return values to the Result type consistent with the Boring APIs.
pub(crate) fn br(bssl_result: c_int) -> BoringResult {
match bssl_result {
1 => Ok(()),
_ => Err(ErrorStack::get()),
}
}
pub(crate) fn br_zero_is_success(bssl_result: c_int) -> BoringResult {
match bssl_result {
0 => Ok(()),
_ => Err(ErrorStack::get()),
}
}
/// Maps BoringSSL ffi return values to a Result.
pub(crate) fn map_result(bssl_result: c_int) -> Result<()> {
match bssl_result {
1 => Ok(()),
_ => Err(Error::SslError(ErrorStack::get())),
}
}
/// Maps a result from a Rust callback to a BoringSSL result error code.
pub(crate) fn map_cb_result<T>(result: Result<T>) -> c_int {
match result {
Ok(_) => 1,
_ => 0,
}
}
/// Like map_result, but for BoringSSL method that break the standard return value convention.
pub(crate) fn map_result_zero_is_success(bssl_result: c_int) -> Result<()> {
match bssl_result {
0 => Ok(()),
_ => Err(Error::SslError(ErrorStack::get())),
}
}
/// Like map_result, but ensures that the resulting pointer is non-null.
pub(crate) fn map_ptr_result<T>(r: *mut T) -> Result<*mut T> {
if r.is_null() {
Err(Error::ssl())
} else {
Ok(r)
}
}
|
0x676e67/quinn-boring2
| 0
|
A crypto provider for quinn based on BoringSSL
|
Rust
|
0x676e67
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.