1
0

add initial marp implementation with sample content and build configuration

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

219
node_modules/mathjax-full/ts/core/MmlTree/Attributes.ts generated vendored Normal file
View File

@@ -0,0 +1,219 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements Attribute class for MmlNodes
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList, Property} from '../Tree/Node.js';
/**
* A constant for when a property should be inherited from the global defaults lists
*/
export const INHERIT = '_inherit_';
/******************************************************************/
/**
* Implements the Attributes class for MmlNodes
* (These can be set explicitly, inherited from parent nodes,
* taken from a default list of values, or taken from global
* defaults.)
*/
export class Attributes {
/**
* The attributes explicitly set on a node
*/
protected attributes: PropertyList;
/**
* The attributes inherited from parent nodes
*/
protected inherited: PropertyList;
/**
* The default attributes for the node type
*/
protected defaults: PropertyList;
/**
* Global attributes from the math node itself
*/
protected global: PropertyList;
/**
* @param {PropertyList} defaults The defaults for this node type
* @param {PropertyList} global The global properties (from the math node)
*
* @constructor
*/
constructor(defaults: PropertyList, global: PropertyList) {
this.global = global;
this.defaults = Object.create(global);
this.inherited = Object.create(this.defaults);
this.attributes = Object.create(this.inherited);
Object.assign(this.defaults, defaults);
}
/**
* @param {string} name The name of the attribute to set
* @param {Property} value The value to give the named attribute
*/
public set(name: string, value: Property) {
this.attributes[name] = value;
}
/**
* @param {PropertyList} list An object containing the properties to set
*/
public setList(list: PropertyList) {
Object.assign(this.attributes, list);
}
/**
* @param {string} name The name of the attribute whose value is to be returned
* @return {Property} The value of the named attribute (including inheritance and defaults)
*/
public get(name: string): Property {
let value = this.attributes[name];
if (value === INHERIT) {
value = this.global[name];
}
return value;
}
/**
* @param {string} name The value of the attribute whose value is to be returned
* @return {Property} The attribute whose name was given if it is explicit on the
* node (not inherited or defaulted), null otherwise
*/
public getExplicit(name: string): Property {
if (!this.attributes.hasOwnProperty(name)) {
return undefined;
}
return this.attributes[name];
}
/**
* @param {string[]} names The names of attributes whose values are to be returned
* @return {PropertyList} An object containing the attributes and their values
*/
public getList(...names: string[]): PropertyList {
let values: PropertyList = {};
for (const name of names) {
values[name] = this.get(name);
}
return values;
}
/**
* @param {string} name The name of an inherited attribute to be set
* @param {Property} value The value to assign to the named attribute
*/
public setInherited(name: string, value: Property) {
this.inherited[name] = value;
}
/**
* @param {string} name The name of an inherited attribute whose value is to be returned
* @return {Property} The value of the named attribute if it is inherited, null otherwise
*/
public getInherited(name: string): Property {
return this.inherited[name];
}
/**
* @param {string} name The name of a default attribute whose value is to be returned
* @return {Property} The value of the named attribute if a default exists for it, null otherwise
*/
public getDefault(name: string): Property {
return this.defaults[name];
}
/**
* @param {string} name The name of a attribute to check
* @return {boolean} True if attribute is set explicitly or inherited
* from an explicit mstyle or math attribute
*/
public isSet(name: string): boolean {
return this.attributes.hasOwnProperty(name) || this.inherited.hasOwnProperty(name);
}
/**
* @param {string} name The name of an attribute to test for the existence of a default
* @return {boolean} True of there is a default for the named attribute, false otherwise
*/
public hasDefault(name: string): boolean {
return (name in this.defaults);
}
/**
* @return {string[]} The names of all the attributes explicitly set on the node
*/
public getExplicitNames(): string[] {
return Object.keys(this.attributes);
}
/**
* @return {string[]} The names of all the inherited attributes for the node
*/
public getInheritedNames(): string[] {
return Object.keys(this.inherited);
}
/**
* @return {string[]} The names of all the default attributes for the node
*/
public getDefaultNames(): string[] {
return Object.keys(this.defaults);
}
/**
* @return {string[]} The names of all the global attributes
*/
public getGlobalNames(): string[] {
return Object.keys(this.global);
}
/**
* @return {PropertyList} The attribute object
*/
public getAllAttributes(): PropertyList {
return this.attributes;
}
/**
* @return {PropertyList} The inherited object
*/
public getAllInherited(): PropertyList {
return this.inherited;
}
/**
* @return {PropertyList} The defaults object
*/
public getAllDefaults(): PropertyList {
return this.defaults;
}
/**
* @return {PropertyList} The global object
*/
public getAllGlobals(): PropertyList {
return this.global;
}
}

View File

@@ -0,0 +1,151 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview A visitor that produces a JSON version of an MmlNode tree
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../Tree/Node.js';
import {MmlVisitor} from './MmlVisitor.js';
import {MmlNode, TextNode, XMLNode} from './MmlNode.js';
export type MmlNodeJSON = {
kind: string,
texClass: number
isEmbellished?: boolean,
isSpacelike?: boolean,
isInferred?: boolean,
childNodes: MmlJSON[],
attributes: PropertyList,
inherited: PropertyList,
properties: PropertyList
};
export type MmlTextJSON = {
kind: string,
text: string
};
export type MmlXmlJSON = {
kind: string,
xml: any
};
export type MmlJSON = MmlNodeJSON | MmlTextJSON | MmlXmlJSON;
/*****************************************************************/
/**
* Implements the JsonMmlVisitor (subclass of MmlVisitor)
*/
export class JsonMmlVisitor extends MmlVisitor {
/**
* Convert the tree rooted at a particular node into a JSON structure
*
* @param {MmlNode} node The node to use as the root of the tree to traverse
* @return {MmlJSON} The JSON object representing the internal tree
*/
public visitTree(node: MmlNode): MmlJSON {
return this.visitNode(node);
}
/**
* @param {TextNode} node The text node to visit
* @return {MmlJSON} The JSON for the text element
*/
public visitTextNode(node: TextNode): MmlTextJSON {
return {kind: node.kind, text: node.getText()};
}
/**
* @param {XMLNode} node The XML node to visit
* @return {MmlJSON} The JSON for the XML node
*/
public visitXMLNode(node: XMLNode): MmlXmlJSON {
return {kind: node.kind, xml: node.getXML()};
}
/**
* The generic visiting function:
* Create a DOM node of the correct type.
* Add its explicit attributes.
* Append its children nodes.
* Append the new node to the DOM parent.
*
* @param {MmlNode} node The node to visit
* @return {MmlJSON} The JSON object representing it
*/
public visitDefault(node: MmlNode): MmlJSON {
let json: MmlJSON = {
kind: node.kind.replace(/inferredM/, 'm'),
texClass: node.texClass,
attributes: this.getAttributes(node),
inherited: this.getInherited(node),
properties: this.getProperties(node),
childNodes: this.getChildren(node)
};
if (node.isInferred) {
json.isInferred = true;
}
if (node.isEmbellished) {
json.isEmbellished = true;
}
if (node.isSpacelike) {
json.isSpacelike = true;
}
return json;
}
/**
* @param {MmlNode} node The node whose children are to be copied
* @return {MmlJSON[]} The array of child JSON objects
*/
public getChildren(node: MmlNode): MmlJSON[] {
let children = [];
for (const child of node.childNodes) {
children.push(this.visitNode(child));
}
return children;
}
/**
* @param {MmlNode} node The node whose attributes are to be copied
* @return {PropertyList} The object containing the attributes;
*/
public getAttributes(node: MmlNode): PropertyList {
return Object.assign({}, node.attributes.getAllAttributes());
}
/**
* @param {MmlNode} node The node whose inherited attributes are to be copied
* @return {PropertyList} The object containing the inherited attributes;
*/
public getInherited(node: MmlNode): PropertyList {
return Object.assign({}, node.attributes.getAllInherited());
}
/**
* @param {MmlNode} node The node whose properties are to be copied
* @return {PropertyList} The object containing the properties;
*/
public getProperties(node: MmlNode): PropertyList {
return Object.assign({}, node.getAllProperties());
}
}

View File

@@ -0,0 +1,128 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview A visitor to convert the new to the old internal format.
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {MmlVisitor} from './MmlVisitor.js';
import {MmlNode, TextNode, XMLNode} from './MmlNode.js';
/**
* Get access to legacy MML Element Jax
*/
declare var MathJax: any;
let MML = MathJax.ElementJax.mml;
/*****************************************************************/
/**
* Implements the LegacyMmlVisitor (subclass of MmlVisitor)
*/
export class LegacyMmlVisitor extends MmlVisitor {
/**
* Convert the tree rooted at a particular node into the old-style
* internal format used by MathJax v2.
*
* @param {MmlNode} node The node to use as the root of the tree to traverse
* @return {any} The old-style internal format equivalent of the tree
*/
public visitTree(node: MmlNode): any {
let root = MML.mrow();
this.visitNode(node, root);
root = root.data[0];
root.parent = null;
return root;
}
/**
* @param {TextNode} node The text node to visit
* @param {any} parent The old-style parent to which this node should be added
*/
public visitTextNode(node: TextNode, parent: any) {
parent.Append(MML.chars(node.getText()));
}
/**
* @param {XMLNode} node The XML node to visit
* @param {any} parent The old-style parent to which this node should be added
*/
public visitXMLNode(node: XMLNode, parent: any) {
parent.Append(MML.xml(node.getXML()));
}
/**
* Visit an inferred mrow, but don't add the inferred row itself (the old-style
* nodes will add one automatically).
*
* @param {MmlNode} node The inferred mrow to visit
* @param {any} parent The old-style parent to which this node's children should be added
*/
public visitInferredMrowNode(node: MmlNode, parent: any) {
for (const child of node.childNodes) {
this.visitNode(child, parent);
}
}
/**
* The generic visiting function:
* Create a node of the correct type.
* Add its explicit attributes.
* Add its non-attribute properties.
* Append its children nodes.
* Append the new node to the old-style parent.
*
* @param {MmlNode} node The node to visit
* @param {any} parent The old-style parent to which this node should be added
*/
public visitDefault(node: MmlNode, parent: any) {
let mml = MML[node.kind]();
this.addAttributes(node, mml);
this.addProperties(node, mml);
for (const child of node.childNodes) {
this.visitNode(child, mml);
}
parent.Append(mml);
}
/**
* @param {MmlNode} node The node who attributes are to be copied
* @param {any} mml The old-style node to which attributes are being added
*/
public addAttributes(node: MmlNode, mml: any) {
let attributes = node.attributes;
let names = attributes.getExplicitNames();
for (const name of names) {
mml[name] = attributes.getExplicit(name);
}
}
/**
* @param {MmlNode} node The node whose properties are to be copied
* @param {any} mml The old-stype node to which the properties are being copied
*/
public addProperties(node: MmlNode, mml: any) {
let names = node.getPropertyNames();
for (const name of names) {
mml[name] = node.getProperty(name);
}
}
}

125
node_modules/mathjax-full/ts/core/MmlTree/MML.ts generated vendored Normal file
View File

@@ -0,0 +1,125 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview An object listing all the MathML node types
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {MmlNodeClass, TextNode, XMLNode} from './MmlNode.js';
import {MmlMath} from './MmlNodes/math.js';
import {MmlMi} from './MmlNodes/mi.js';
import {MmlMn} from './MmlNodes/mn.js';
import {MmlMo} from './MmlNodes/mo.js';
import {MmlMtext} from './MmlNodes/mtext.js';
import {MmlMspace} from './MmlNodes/mspace.js';
import {MmlMs} from './MmlNodes/ms.js';
import {MmlMrow, MmlInferredMrow} from './MmlNodes/mrow.js';
import {MmlMfrac} from './MmlNodes/mfrac.js';
import {MmlMsqrt} from './MmlNodes/msqrt.js';
import {MmlMroot} from './MmlNodes/mroot.js';
import {MmlMstyle} from './MmlNodes/mstyle.js';
import {MmlMerror} from './MmlNodes/merror.js';
import {MmlMpadded} from './MmlNodes/mpadded.js';
import {MmlMphantom} from './MmlNodes/mphantom.js';
import {MmlMfenced} from './MmlNodes/mfenced.js';
import {MmlMenclose} from './MmlNodes/menclose.js';
import {MmlMaction} from './MmlNodes/maction.js';
import {MmlMsubsup, MmlMsub, MmlMsup} from './MmlNodes/msubsup.js';
import {MmlMunderover, MmlMunder, MmlMover} from './MmlNodes/munderover.js';
import {MmlMmultiscripts, MmlMprescripts, MmlNone} from './MmlNodes/mmultiscripts.js';
import {MmlMtable} from './MmlNodes/mtable.js';
import {MmlMtr, MmlMlabeledtr} from './MmlNodes/mtr.js';
import {MmlMtd} from './MmlNodes/mtd.js';
import {MmlMaligngroup} from './MmlNodes/maligngroup.js';
import {MmlMalignmark} from './MmlNodes/malignmark.js';
import {MmlMglyph} from './MmlNodes/mglyph.js';
import {MmlSemantics, MmlAnnotation, MmlAnnotationXML} from './MmlNodes/semantics.js';
import {TeXAtom} from './MmlNodes/TeXAtom.js';
import {MathChoice} from './MmlNodes/mathchoice.js';
/************************************************************************/
/**
* This object collects all the MathML node types together so that
* they can be used to seed an MmlNodeFactory. One could copy this
* object to override existing classes with subclasses, or to add new
* classes as necessary.
*/
export let MML: {[kind: string]: MmlNodeClass} = {
[MmlMath.prototype.kind]: MmlMath,
[MmlMi.prototype.kind]: MmlMi,
[MmlMn.prototype.kind]: MmlMn,
[MmlMo.prototype.kind]: MmlMo,
[MmlMtext.prototype.kind]: MmlMtext,
[MmlMspace.prototype.kind]: MmlMspace,
[MmlMs.prototype.kind]: MmlMs,
[MmlMrow.prototype.kind]: MmlMrow,
[MmlInferredMrow.prototype.kind]: MmlInferredMrow,
[MmlMfrac.prototype.kind]: MmlMfrac,
[MmlMsqrt.prototype.kind]: MmlMsqrt,
[MmlMroot.prototype.kind]: MmlMroot,
[MmlMstyle.prototype.kind]: MmlMstyle,
[MmlMerror.prototype.kind]: MmlMerror,
[MmlMpadded.prototype.kind]: MmlMpadded,
[MmlMphantom.prototype.kind]: MmlMphantom,
[MmlMfenced.prototype.kind]: MmlMfenced,
[MmlMenclose.prototype.kind]: MmlMenclose,
[MmlMaction.prototype.kind]: MmlMaction,
[MmlMsub.prototype.kind]: MmlMsub,
[MmlMsup.prototype.kind]: MmlMsup,
[MmlMsubsup.prototype.kind]: MmlMsubsup,
[MmlMunder.prototype.kind]: MmlMunder,
[MmlMover.prototype.kind]: MmlMover,
[MmlMunderover.prototype.kind]: MmlMunderover,
[MmlMmultiscripts.prototype.kind]: MmlMmultiscripts,
[MmlMprescripts.prototype.kind]: MmlMprescripts,
[MmlNone.prototype.kind]: MmlNone,
[MmlMtable.prototype.kind]: MmlMtable,
[MmlMlabeledtr.prototype.kind]: MmlMlabeledtr,
[MmlMtr.prototype.kind]: MmlMtr,
[MmlMtd.prototype.kind]: MmlMtd,
[MmlMaligngroup.prototype.kind]: MmlMaligngroup,
[MmlMalignmark.prototype.kind]: MmlMalignmark,
[MmlMglyph.prototype.kind]: MmlMglyph,
[MmlSemantics.prototype.kind]: MmlSemantics,
[MmlAnnotation.prototype.kind]: MmlAnnotation,
[MmlAnnotationXML.prototype.kind]: MmlAnnotationXML,
[TeXAtom.prototype.kind]: TeXAtom,
[MathChoice.prototype.kind]: MathChoice,
[TextNode.prototype.kind]: TextNode,
[XMLNode.prototype.kind]: XMLNode
};

View File

@@ -0,0 +1,112 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview A visitor that produces MathML DOM nodes from the iternal nodes
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {MmlVisitor} from './MmlVisitor.js';
import {MmlNode, TextNode, XMLNode} from './MmlNode.js';
/*****************************************************************/
/**
* Implements the MathMLVisitor (subclass of MmlVisitor)
*/
export class MathMLVisitor extends MmlVisitor {
/**
* The document in which the nodes are being made
*/
protected document: Document = null;
/**
* Convert the tree rooted at a particular node into DOM nodes.
*
* @param {MmlNode} node The node to use as the root of the tree to traverse
* @param {Document} document The document in which the nodes are created
* @return {Node} The MathML DOM nodes representing the internal tree
*/
public visitTree(node: MmlNode, document: Document): Node {
this.document = document;
let root = document.createElement('top');
this.visitNode(node, root);
this.document = null;
return root.firstChild;
}
/**
* @param {TextNode} node The text node to visit
* @param {Element} parent The DOM parent to which this node should be added
*/
public visitTextNode(node: TextNode, parent: Element) {
parent.appendChild(this.document.createTextNode(node.getText()));
}
/**
* @param {XMLNode} node The XML node to visit
* @param {Element} parent The DOM parent to which this node should be added
*/
public visitXMLNode(node: XMLNode, parent: Element) {
parent.appendChild((node.getXML() as Element).cloneNode(true));
}
/**
* Visit an inferred mrow, but don't add the inferred row itself (since
* it is supposed to be inferred).
*
* @param {MmlNode} node The inferred mrow to visit
* @param {Element} parent The DOM parent to which this node's children should be added
*/
public visitInferredMrowNode(node: MmlNode, parent: Element) {
for (const child of node.childNodes) {
this.visitNode(child, parent);
}
}
/**
* The generic visiting function:
* Create a DOM node of the correct type.
* Add its explicit attributes.
* Append its children nodes.
* Append the new node to the DOM parent.
*
* @param {MmlNode} node The node to visit
* @param {Element} parent The DOM parent to which this node should be added
*/
public visitDefault(node: MmlNode, parent: Element) {
let mml = this.document.createElement(node.kind);
this.addAttributes(node, mml);
for (const child of node.childNodes) {
this.visitNode(child, mml);
}
parent.appendChild(mml);
}
/**
* @param {MmlNode} node The node who attributes are to be copied
* @param {Element} mml The MathML DOM node to which attributes are being added
*/
public addAttributes(node: MmlNode, mml: Element) {
let attributes = node.attributes;
let names = attributes.getExplicitNames();
for (const name of names) {
mml.setAttribute(name, attributes.getExplicit(name).toString());
}
}
}

View File

@@ -0,0 +1,48 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlFactory to create Mml Nodes
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {AbstractNodeFactory} from '../Tree/NodeFactory.js';
import {MmlNode, MmlNodeClass} from './MmlNode.js';
import {MML} from './MML.js';
/*****************************************************************/
/**
* Implements the MmlFactory (subclass of NodeFactory)
*/
export class MmlFactory extends AbstractNodeFactory<MmlNode, MmlNodeClass> {
/**
* The default node-creation functions
*/
public static defaultNodes = MML;
/**
* @return {Object} The list of node-creation functions (similar to the
* MML object from MathJax v2).
*/
get MML(): Object {
return this.node;
}
}

1314
node_modules/mathjax-full/ts/core/MmlTree/MmlNode.ts generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,100 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the TeXAtom node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {MmlFactory} from '../MmlFactory.js';
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlBaseNode, MmlNode, TEXCLASS} from '../MmlNode.js';
import {MmlMo} from './mo.js';
/*****************************************************************/
/**
* Implements the TeXAtom node class (subclass of AbstractMmlBaseNode)
*/
export class TeXAtom extends AbstractMmlBaseNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlBaseNode.defaults
};
/**
* TeX class is ORD
*/
protected texclass = TEXCLASS.ORD;
/**
* @override
*/
public get kind() {
return 'TeXAtom';
}
/**
* Inferred mrow with any number of children
* @override
*/
public get arity() {
return -1;
}
/**
* This element is not considered a MathML container
* @override
*/
public get notParent() {
return this.childNodes[0] && this.childNodes[0].childNodes.length === 1;
}
/**
* @override
*/
constructor(factory: MmlFactory, attributes: PropertyList, children: MmlNode[]) {
super(factory, attributes, children);
this.setProperty('texClass', this.texClass); // needed for serialization to include the texClass
}
/**
* @override
*/
public setTeXclass(prev: MmlNode) {
this.childNodes[0].setTeXclass(null);
return this.adjustTeXclass(prev);
}
/**
* (Replaced below by the version from the MmlMo node)
*
* @override
*/
public adjustTeXclass(prev: MmlNode) {
return prev;
}
}
/**
* Use the method from the MmlMo class
*/
TeXAtom.prototype.adjustTeXclass = MmlMo.prototype.adjustTeXclass;

View File

@@ -0,0 +1,134 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMaction node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {MmlNode, AbstractMmlNode} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMaction node class (subclass of AbstractMmlNode)
*/
export class MmlMaction extends AbstractMmlNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlNode.defaults,
actiontype: 'toggle',
selection: 1
};
/**
* @override
*/
public get kind() {
return 'maction';
}
/**
* At least one child
* @override
*/
public get arity() {
return 1;
}
/**
* @return {MmlNode} The selected child node (or an mrow if none selected)
*/
public get selected(): MmlNode {
const selection = this.attributes.get('selection') as number;
const i = Math.max(1, Math.min(this.childNodes.length, selection)) - 1;
return this.childNodes[i] || this.factory.create('mrow');
}
/**
* @override
*/
public get isEmbellished() {
return this.selected.isEmbellished;
}
/**
* @override
*/
public get isSpacelike() {
return this.selected.isSpacelike;
}
/**
* @override
*/
public core(): MmlNode {
return this.selected.core();
}
/**
* @override
*/
public coreMO(): MmlNode {
return this.selected.coreMO();
}
/**
* @override
*/
protected verifyAttributes(options: PropertyList) {
super.verifyAttributes(options);
if (this.attributes.get('actiontype') !== 'toggle' &&
this.attributes.getExplicit('selection') !== undefined) {
const attributes = this.attributes.getAllAttributes();
delete attributes.selection;
}
}
/**
* Get the TeX class from the selceted node
* For tooltips, set TeX classes within the tip as a separate math list
*
* @override
*/
public setTeXclass(prev: MmlNode) {
if (this.attributes.get('actiontype') === 'tooltip' && this.childNodes[1]) {
this.childNodes[1].setTeXclass(null);
}
let selected = this.selected;
prev = selected.setTeXclass(prev);
this.updateTeXclass(selected);
return prev;
}
/**
* Select the next child for a toggle action
*/
public nextToggleSelection() {
let selection = Math.max(1, (this.attributes.get('selection') as number) + 1);
if (selection > this.childNodes.length) {
selection = 1;
}
this.attributes.set('selection', selection);
}
}

View File

@@ -0,0 +1,67 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMaligngroup node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlLayoutNode, AttributeList} from '../MmlNode.js';
import {INHERIT} from '../Attributes.js';
/*****************************************************************/
/**
* Implements the MmlMaligngroup node class (subclass of AbstractMmlNode)
*/
export class MmlMaligngroup extends AbstractMmlLayoutNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlLayoutNode.defaults,
groupalign: INHERIT
};
/**
* @override
*/
public get kind() {
return 'maligngroup';
}
/**
* <maligngroup> is space-like
* @override
*/
public get isSpacelike() {
return true;
}
/**
* Children can inherit from <maligngroup>
* @override
*/
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean) {
attributes = this.addInheritedAttributes(attributes, this.attributes.getAllAttributes());
super.setChildInheritedAttributes(attributes, display, level, prime);
}
}

View File

@@ -0,0 +1,65 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMalignmark node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlNode} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMalignmark node class (subclass of AbstractMmlNode)
*/
export class MmlMalignmark extends AbstractMmlNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlNode.defaults,
edge: 'left'
};
/**
* @override
*/
public get kind() {
return 'malignmark';
}
/**
* No children allowed
* @override
*/
public get arity() {
return 0;
}
/**
* <malignmark> is space-like
* @override
*/
public get isSpacelike() {
return true;
}
}

View File

@@ -0,0 +1,104 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMath node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlLayoutNode, AttributeList} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMath node class (subclass of AbstractMmlLayoutNode)
*/
export class MmlMath extends AbstractMmlLayoutNode {
/**
* These are used as the defaults for any attributes marked INHERIT in other classes
*/
public static defaults: PropertyList = {
...AbstractMmlLayoutNode.defaults,
mathvariant: 'normal',
mathsize: 'normal',
mathcolor: '', // Should be 'black', but allow it to inherit from surrounding text
mathbackground: 'transparent',
dir: 'ltr',
scriptlevel: 0,
displaystyle: false,
display: 'inline',
maxwidth: '',
overflow: 'linebreak',
altimg: '',
'altimg-width': '',
'altimg-height': '',
'altimg-valign': '',
alttext: '',
cdgroup: '',
scriptsizemultiplier: 1 / Math.sqrt(2),
scriptminsize: '8px', // Should be 8pt, but that's too big
infixlinebreakstyle: 'before',
lineleading: '1ex',
linebreakmultchar: '\u2062', // Invisible times
indentshift: 'auto', // Use user configuration
indentalign: 'auto',
indenttarget: '',
indentalignfirst: 'indentalign',
indentshiftfirst: 'indentshift',
indentalignlast: 'indentalign',
indentshiftlast: 'indentshift'
};
/**
* @override
*/
public get kind() {
return 'math';
}
/**
* Linebreaking can occur in math nodes
* @override
*/
public get linebreakContainer() {
return true;
}
/**
* The attributes of math nodes are inherited, so add them into the list.
* The displaystyle attribute comes from the display attribute if not given explicitly
* The scriptlevel comes from the scriptlevel attribute or default
*
* @override
*/
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean) {
if (this.attributes.get('mode') === 'display') {
this.attributes.setInherited('display', 'block');
}
attributes = this.addInheritedAttributes(attributes, this.attributes.getAllAttributes());
display = (!!this.attributes.get('displaystyle') ||
(!this.attributes.get('displaystyle') && this.attributes.get('display') === 'block'));
this.attributes.setInherited('displaystyle', display);
level = (this.attributes.get('scriptlevel') ||
(this.constructor as typeof MmlMath).defaults['scriptlevel']) as number;
super.setChildInheritedAttributes(attributes, display, level, prime);
}
}

View File

@@ -0,0 +1,80 @@
/*************************************************************
*
* Copyright (c) 2018-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MathChoice node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlBaseNode, AttributeList} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MathChoice node class (subclass of AbstractMmlBaseNode)
*
* This is used by TeX's \mathchoice macro, but removes itself
* during the setInheritedAttributes process
*/
export class MathChoice extends AbstractMmlBaseNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlBaseNode.defaults
};
/**
* @override
*/
public get kind() {
return 'MathChoice';
}
/**
* 4 children (display, text, script, and scriptscript styles)
* @override
*/
public get arity() {
return 4;
}
/**
* This element is not considered a MathML container
* @override
*/
public get notParent() {
return true;
}
/**
* Replace the MathChoice node with the selected on based on the displaystyle and scriptlevel settings
* (so the MathChoice never ends up in a finished MmlNode tree)
*
* @override
*/
public setInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean) {
const selection = (display ? 0 : Math.max(0, Math.min(level, 2)) + 1);
const child = this.childNodes[selection] || this.factory.create('mrow');
this.parent.replaceChild(child, this);
child.setInheritedAttributes(attributes, display, level, prime);
}
}

View File

@@ -0,0 +1,80 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMenclose node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {MmlNode, AbstractMmlNode, TEXCLASS} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlEnclose node class (subclass of AbstractMmlNode)
*/
export class MmlMenclose extends AbstractMmlNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlNode.defaults,
notation: 'longdiv'
};
/**
* TeX class is ORD
*/
protected texclass = TEXCLASS.ORD;
/**
* The menclose kind
* @override
*/
public get kind() {
return 'menclose';
}
/**
* <menclose> has an inferred mrow
* @override
*/
public get arity() {
return -1;
}
/**
* <menclose> is a linebreak container
* @override
*/
public get linebreakContininer() {
return true;
}
/**
* @override
*/
public setTeXclass(prev: MmlNode) {
prev = this.childNodes[0].setTeXclass(prev);
this.updateTeXclass(this.childNodes[0]);
return prev;
}
}

View File

@@ -0,0 +1,69 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMerror node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlNode, TEXCLASS} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMerror node class (subclass of AbstractMmlNode)
*/
export class MmlMerror extends AbstractMmlNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlNode.defaults
};
/**
* TeX class is ORD
*/
protected texclass = TEXCLASS.ORD;
/**
* @override
*/
public get kind() {
return 'merror';
}
/**
* <merror> gets an inferred mrow
* @override
*/
public get arity() {
return -1;
}
/**
* <merror> can contain line breaks
* @override
*/
public get linebreakContainer() {
return true;
}
}

View File

@@ -0,0 +1,165 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMfenced node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {MmlNode, TextNode, AbstractMmlNode, AttributeList, TEXCLASS} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMfenced node class (subclass of AbstractMmlNode)
*/
export class MmlMfenced extends AbstractMmlNode {
/**
* @overeride
*/
public static defaults: PropertyList = {
...AbstractMmlNode.defaults,
open: '(',
close: ')',
separators: ','
};
/**
* TeX class is INNER
*/
protected texclass = TEXCLASS.INNER;
/**
* Storage for "fake" nodes for the separators
*/
public separators: MmlNode[] = [];
/**
* Storage for "fake" open node
*/
public open: MmlNode = null;
/**
* Storage for "fake" close node
*/
public close: MmlNode = null;
/**
* @override
*/
public get kind() {
return 'mfenced';
}
/**
* Include the fake nodes in the process, since they will be used
* to produce the output.
*
* @override
*/
public setTeXclass(prev: MmlNode) {
this.getPrevClass(prev);
if (this.open) {
prev = this.open.setTeXclass(prev);
}
if (this.childNodes[0]) {
prev = this.childNodes[0].setTeXclass(prev);
}
for (let i = 1, m = this.childNodes.length; i < m; i++) {
if (this.separators[i - 1]) {
prev = this.separators[i - 1].setTeXclass(prev);
}
if (this.childNodes[i]) {
prev = this.childNodes[i].setTeXclass(prev);
}
}
if (this.close) {
prev = this.close.setTeXclass(prev);
}
this.updateTeXclass(this.open);
return prev;
}
/**
* Create the fake nodes and do their inheritance
* Then do inheridence of usual children
*
* @override
*/
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean) {
this.addFakeNodes();
for (const child of [this.open, this.close].concat(this.separators)) {
if (child) {
child.setInheritedAttributes(attributes, display, level, prime);
}
}
super.setChildInheritedAttributes(attributes, display, level, prime);
}
/**
* Create <mo> elements for the open and close delimiters, and for the separators (if any)
*/
protected addFakeNodes() {
let {open, close, separators} = this.attributes.getList('open', 'close', 'separators') as
{open: string, close: string, separators: string};
open = open.replace(/[ \t\n\r]/g, '');
close = close.replace(/[ \t\n\r]/g, '');
separators = separators.replace(/[ \t\n\r]/g, '');
//
// Create open node
//
if (open) {
this.open = this.fakeNode(open, {fence: true, form: 'prefix'}, TEXCLASS.OPEN);
}
//
// Create nodes for the separators
//
if (separators) {
while (separators.length < this.childNodes.length - 1) {
separators += separators.charAt(separators.length - 1);
}
let i = 0;
for (const child of this.childNodes.slice(1)) {
if (child) {
this.separators.push(this.fakeNode(separators.charAt(i++)));
}
}
}
//
// Create close node
//
if (close) {
this.close = this.fakeNode(close, {fence: true, form: 'postfix'}, TEXCLASS.CLOSE);
}
}
/**
* @param {string} c The character for the text of the node
* @param {PropertyList} properties The attributes for the node
* @param {number} texClass The TeX class for the node
* @return {MmlNode} The generated <mo> node
*/
protected fakeNode(c: string, properties: PropertyList = {}, texClass: number = null): MmlNode {
let text = (this.factory.create('text') as TextNode).setText(c);
let node = this.factory.create('mo', properties, [text]);
node.texClass = texClass;
node.parent = this;
return node;
}
}

View File

@@ -0,0 +1,92 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMfrac node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {MmlNode, AbstractMmlBaseNode, AttributeList} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMfrac node class (subclass of AbstractMmlBaseNode)
*/
export class MmlMfrac extends AbstractMmlBaseNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlBaseNode.defaults,
linethickness: 'medium',
numalign: 'center',
denomalign: 'center',
bevelled: false
};
/**
* @override
*/
public get kind() {
return 'mfrac';
}
/**
* <mfrac> requires two children
* @override
*/
public get arity() {
return 2;
}
/**
* The children of <mfrac> can include line breaks
* @override
*/
public get linebreakContainer() {
return true;
}
/**
* Update the children separately
* @override
*/
public setTeXclass(prev: MmlNode) {
this.getPrevClass(prev);
for (const child of this.childNodes) {
child.setTeXclass(null);
}
return this;
}
/**
* Adjust the display level, and use prime style in denominator
* @override
*/
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean) {
if (!display || level > 0) {
level++;
}
this.childNodes[0].setInheritedAttributes(attributes, false, level, prime);
this.childNodes[1].setInheritedAttributes(attributes, false, level, true);
}
}

View File

@@ -0,0 +1,71 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMglyph node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlTokenNode, TEXCLASS} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMglyph node class (subclass of AbstractMmlTokenNode)
*/
export class MmlMglyph extends AbstractMmlTokenNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlTokenNode.defaults,
alt: '',
src: '',
index: '',
width: 'auto',
height: 'auto',
valign: '0em'
};
/**
* TeX class is ORD
*/
protected texclass = TEXCLASS.ORD;
/**
* @override
*/
public get kind() {
return 'mglyph';
}
/**
* @override
*/
public verifyAttributes(options: PropertyList) {
const {src, fontfamily, index} = this.attributes.getList('src', 'fontfamily', 'index');
if (src === '' && (fontfamily === '' || index === '')) {
this.mError('mglyph must have either src or fontfamily and index attributes', options, true);
} else {
super.verifyAttributes(options);
}
}
}

View File

@@ -0,0 +1,96 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMi node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlTokenNode, AbstractMmlNode, AttributeList, TEXCLASS} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMi node class (subclass of AbstractMmlTokenNode)
*/
export class MmlMi extends AbstractMmlTokenNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlTokenNode.defaults
};
/**
* Pattern for operator names
*/
public static operatorName: RegExp = /^[a-z][a-z0-9]*$/i;
/**
* Pattern for single-character texts
*/
public static singleCharacter: RegExp =
/^[\uD800-\uDBFF]?.[\u0300-\u036F\u1AB0-\u1ABE\u1DC0-\u1DFF\u20D0-\u20EF]*$/;
/**
* TeX class is ORD
*/
protected texclass = TEXCLASS.ORD;
/**
* @override
*/
public get kind() {
return 'mi';
}
/**
* Do the usual inheritance, then check the text length to see
* if mathvariant should be normal or italic.
*
* @override
*/
public setInheritedAttributes(attributes: AttributeList = {},
display: boolean = false, level: number = 0, prime: boolean = false) {
super.setInheritedAttributes(attributes, display, level, prime);
let text = this.getText();
if (text.match(MmlMi.singleCharacter) && !attributes.mathvariant) {
this.attributes.setInherited('mathvariant', 'italic');
}
}
/**
* Mark multi-character texts as OP rather than ORD for spacing purposes
*
* @override
*/
public setTeXclass(prev: AbstractMmlNode) {
this.getPrevClass(prev);
let name = this.getText();
if (name.length > 1 && name.match(MmlMi.operatorName) &&
this.attributes.get('mathvariant') === 'normal' &&
this.getProperty('autoOP') === undefined &&
this.getProperty('texClass') === undefined) {
this.texClass = TEXCLASS.OP;
this.setProperty('autoOP', true);
}
return this;
}
}

View File

@@ -0,0 +1,203 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMmultiscripts node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlNode, AttributeList} from '../MmlNode.js';
import {MmlMsubsup} from './msubsup.js';
/*****************************************************************/
/**
* Implements the MmlMmultiscripts node class (subclass of MmlMsubsup)
*/
export class MmlMmultiscripts extends MmlMsubsup {
/**
* @override
*/
public static defaults: PropertyList = {
...MmlMsubsup.defaults
};
/**
* @override
*/
public get kind() {
return 'mmultiscripts';
}
/**
* <mmultiscripts> requires at least one child (the base)
* @override
*/
public get arity() {
return 1;
}
/**
* Push the inherited values to the base
* Make sure the number of pre- and post-scripts are even by adding mrows, if needed.
* For the scripts, use displaystyle = false, scriptlevel + 1, and
* set the primestyle in the subscripts.
*
* @override
*/
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean) {
this.childNodes[0].setInheritedAttributes(attributes, display, level, prime);
let prescripts = false;
for (let i = 1, n = 0; i < this.childNodes.length; i++) {
let child = this.childNodes[i];
if (child.isKind('mprescripts')) {
if (!prescripts) {
prescripts = true;
if (i % 2 === 0) {
let mrow = this.factory.create('mrow');
this.childNodes.splice(i, 0, mrow);
mrow.parent = this;
i++;
}
}
} else {
let primestyle = prime || (n % 2 === 0);
child.setInheritedAttributes(attributes, false, level + 1, primestyle);
n++;
}
}
if (this.childNodes.length % 2 === (prescripts ? 1 : 0)) {
this.appendChild(this.factory.create('mrow'));
this.childNodes[this.childNodes.length - 1].setInheritedAttributes(attributes, false, level + 1, prime);
}
}
/**
* Check that mprescripts only occurs once, and that the number of pre- and post-scripts are even.
*
* @override
*/
protected verifyChildren(options: PropertyList) {
let prescripts = false;
let fix = options['fixMmultiscripts'];
for (let i = 0; i < this.childNodes.length; i++) {
let child = this.childNodes[i];
if (child.isKind('mprescripts')) {
if (prescripts) {
child.mError(child.kind + ' can only appear once in ' + this.kind, options, true);
} else {
prescripts = true;
if (i % 2 === 0 && !fix) {
this.mError('There must be an equal number of prescripts of each type', options);
}
}
}
}
if (this.childNodes.length % 2 === (prescripts ? 1 : 0) && !fix) {
this.mError('There must be an equal number of scripts of each type', options);
}
super.verifyChildren(options);
}
}
/*****************************************************************/
/**
* Implements the MmlMprescripts node class (subclass of AbstractMmlNode)
*/
export class MmlMprescripts extends AbstractMmlNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlNode.defaults
};
/**
* @return {string} The mprescripts kind
*/
public get kind(): string {
return 'mprescripts';
}
/**
* @return {number} <mprescripts> can have no children
*/
public get arity(): number {
return 0;
}
/**
* Check that parent is mmultiscripts
*
* @override
*/
public verifyTree(options: PropertyList) {
super.verifyTree(options);
if (this.parent && !this.parent.isKind('mmultiscripts')) {
this.mError(this.kind + ' must be a child of mmultiscripts', options, true);
}
}
}
/*****************************************************************/
/**
* Implements the MmlNone node class (subclass of AbstractMmlNode)
*/
export class MmlNone extends AbstractMmlNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlNode.defaults
};
/**
* @return {string} The none kind
*/
public get kind(): string {
return 'none';
}
/**
* @return {number} <none> can have no children
*/
public get arity(): number {
return 0;
}
/**
* Check that parent is mmultiscripts
*
* @override
*/
public verifyTree(options: PropertyList) {
super.verifyTree(options);
if (this.parent && !this.parent.isKind('mmultiscripts')) {
this.mError(this.kind + ' must be a child of mmultiscripts', options, true);
}
}
}

View File

@@ -0,0 +1,53 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMn node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlTokenNode, TEXCLASS} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMn node class (subclass of AbstractMmlTokenNode)
*/
export class MmlMn extends AbstractMmlTokenNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlTokenNode.defaults
};
/**
* TeX class is ORD
*/
protected texclass = TEXCLASS.ORD;
/**
* @override
*/
public get kind() {
return 'mn';
}
}

View File

@@ -0,0 +1,476 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMo node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlTokenNode, MmlNode, AttributeList, TEXCLASS} from '../MmlNode.js';
import {MmlMrow} from './mrow.js';
import {MmlMover, MmlMunder, MmlMunderover} from './munderover.js';
import {OperatorList, OPTABLE, getRange, MMLSPACING} from '../OperatorDictionary.js';
import {unicodeChars, unicodeString} from '../../../util/string.js';
/*****************************************************************/
/**
* Implements the MmlMo node class (subclass of AbstractMmlTokenNode)
*/
export class MmlMo extends AbstractMmlTokenNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlTokenNode.defaults,
form: 'infix',
fence: false,
separator: false,
lspace: 'thickmathspace',
rspace: 'thickmathspace',
stretchy: false,
symmetric: false,
maxsize: 'infinity',
minsize: '0em', // MathML says '1em', but that is larger than some natural sizes
largeop: false,
movablelimits: false,
accent: false,
linebreak: 'auto',
lineleading: '1ex',
linebreakstyle: 'before',
indentalign: 'auto',
indentshift: '0',
indenttarget: '',
indentalignfirst: 'indentalign',
indentshiftfirst: 'indentshift',
indentalignlast: 'indentalign',
indentshiftlast: 'indentshift'
};
/**
* The MathML spacing values for the TeX classes
*/
public static MMLSPACING = MMLSPACING;
/**
* The Operator Dictionary
*/
public static OPTABLE: {[form: string]: OperatorList} = OPTABLE;
/**
* Pattern for matching when the contents is one ore more pseudoscripts
*/
public static pseudoScripts = new RegExp([
'^["\'*`',
'\u00AA', // FEMININE ORDINAL INDICATOR
'\u00B0', // DEGREE SIGN
'\u00B2-\u00B4', // SUPERSCRIPT 2 and 3, ACUTE ACCENT
'\u00B9', // SUPERSCRIPT ONE
'\u00BA', // MASCULINE ORDINAL INDICATOR
'\u2018-\u201F', // Various double and single quotation marks (up and down)
'\u2032-\u2037\u2057', // Primes and reversed primes (forward and reversed)
'\u2070\u2071', // SUPERSCRIPT 0 and i
'\u2074-\u207F', // SUPERCRIPT 4 through 9, -, =, (, ), and n
'\u2080-\u208E', // SUBSCRIPT 0 through 9, -, =, (, ).
']+$'
].join(''));
/**
* Pattern for when contents is a collection of primes
*/
protected static primes = new RegExp([
'^["\'`',
'\u2018-\u201F', // Various double and single quotation marks (up and down)
']+$'
].join(''));
/**
* Default map for remapping prime characters
*/
protected static remapPrimes: {[n: number]: number} = {
0x0022: 0x2033, // double quotes
0x0027: 0x2032, // single quote
0x0060: 0x2035, // back quote
0x2018: 0x2035, // open single quote
0x2019: 0x2032, // close single quote
0x201A: 0x2032, // low open single quote
0x201B: 0x2035, // reversed open single quote
0x201C: 0x2036, // open double quote
0x201D: 0x2033, // close double quote
0x201E: 0x2033, // low open double quote
0x201F: 0x2036, // reversed open double quote
};
/**
* Regular expression matching characters that are marked as math accents
*/
protected static mathaccents = new RegExp([
'^[',
'\u00B4\u0301\u02CA', // acute
'\u0060\u0300\u02CB', // grave
'\u00A8\u0308', // ddot
'\u007E\u0303\u02DC', // tilde
'\u00AF\u0304\u02C9', // bar
'\u02D8\u0306', // breve
'\u02C7\u030C', // check
'\u005E\u0302\u02C6', // hat
'\u2192\u20D7', // vec
'\u02D9\u0307', // dot
'\u02DA\u030A', // mathring
'\u20DB', // dddot
'\u20DC', // ddddot
']$'
].join(''));
/**
* The internal TeX class of the node (for use with getter/setter below)
*/
public _texClass: number = null;
/**
* Use a getter to look up the TeX class from the operator table if it hasn't
* been set yet (but don't save it in case the form changes when it is in its
* location).
*/
public get texClass() {
if (this._texClass === null) {
let mo = this.getText();
let [form1, form2, form3] = this.handleExplicitForm(this.getForms());
let OPTABLE = (this.constructor as typeof MmlMo).OPTABLE;
let def = OPTABLE[form1][mo] || OPTABLE[form2][mo] || OPTABLE[form3][mo];
return def ? def[2] : TEXCLASS.REL;
}
return this._texClass;
}
/**
* Use a setter to store the actual value in _texClass;
*/
public set texClass(value: number) {
this._texClass = value;
}
/**
* The default MathML spacing on the left
*/
/* tslint:disable-next-line:whitespace */
public lspace = 5/18;
/**
* The default MathML spacing on the right
*/
/* tslint:disable-next-line:whitespace */
public rspace = 5/18;
/**
* @override
*/
public get kind() {
return 'mo';
}
/**
* All <mo> are considered embellished
* @override
*/
public get isEmbellished() {
return true;
}
/**
* @return {boolean} Is <mo> marked as an explicit linebreak?
*/
public get hasNewLine(): boolean {
return this.attributes.get('linebreak') === 'newline';
}
/**
* @return {MmlNode} The node that is the outermost embellished operator
* with this node as its core
*/
public coreParent(): MmlNode {
let embellished = this as MmlNode;
let parent = this as MmlNode;
let math = this.factory.getNodeClass('math');
while (parent && parent.isEmbellished && parent.coreMO() === this && !(parent instanceof math)) {
embellished = parent;
parent = (parent as MmlNode).parent;
}
return embellished;
}
/**
* @param {MmlNode} parent The node whose core text is to be obtained
* @return {string} The text of the core MO of the given parent element
*/
public coreText(parent: MmlNode): string {
if (!parent) {
return '';
}
if (parent.isEmbellished) {
return (parent.coreMO() as MmlMo).getText();
}
while ((((parent.isKind('mrow') ||
(parent.isKind('TeXAtom') && parent.texClass !== TEXCLASS.VCENTER) ||
parent.isKind('mstyle') ||
parent.isKind('mphantom')) && parent.childNodes.length === 1) ||
parent.isKind('munderover')) && parent.childNodes[0]) {
parent = parent.childNodes[0] as MmlNode;
}
return (parent.isToken ? (parent as AbstractMmlTokenNode).getText() : '');
}
/**
* @override
*/
public hasSpacingAttributes() {
return this.attributes.isSet('lspace') ||
this.attributes.isSet('rspace');
}
/**
* @return {boolean} True is this mo is an accent in an munderover construction
*/
get isAccent(): boolean {
let accent = false;
const node = this.coreParent().parent;
if (node) {
const key = (node.isKind('mover') ?
((node.childNodes[(node as MmlMover).over] as MmlNode).coreMO() ?
'accent' : '') :
node.isKind('munder') ?
((node.childNodes[(node as MmlMunder).under] as MmlNode).coreMO() ?
'accentunder' : '') :
node.isKind('munderover') ?
(this === (node.childNodes[(node as MmlMunderover).over] as MmlNode).coreMO() ?
'accent' :
this === (node.childNodes[(node as MmlMunderover).under] as MmlNode).coreMO() ?
'accentunder' : '') :
'');
if (key) {
const value = node.attributes.getExplicit(key);
accent = (value !== undefined ? accent : this.attributes.get('accent')) as boolean;
}
}
return accent;
}
/**
* Produce the texClass based on the operator dictionary values
*
* @override
*/
public setTeXclass(prev: MmlNode): MmlNode {
let {form, fence} = this.attributes.getList('form', 'fence') as {form: string, fence: string};
if (this.getProperty('texClass') === undefined &&
(this.attributes.isSet('lspace') || this.attributes.isSet('rspace'))) {
return null;
}
if (fence && this.texClass === TEXCLASS.REL) {
if (form === 'prefix') {
this.texClass = TEXCLASS.OPEN;
}
if (form === 'postfix') {
this.texClass = TEXCLASS.CLOSE;
}
}
return this.adjustTeXclass(prev);
}
/**
* Follow the TeXBook rules for adjusting the TeX class once its neighbors are known
*
* @param {MmlNode} prev The node appearing before this one in the output
* @return {MmlNode} The last node displayed (this node)
*/
public adjustTeXclass(prev: MmlNode): MmlNode {
let texClass = this.texClass;
let prevClass = this.prevClass;
if (texClass === TEXCLASS.NONE) {
return prev;
}
if (prev) {
if (prev.getProperty('autoOP') && (texClass === TEXCLASS.BIN || texClass === TEXCLASS.REL)) {
prevClass = prev.texClass = TEXCLASS.ORD;
}
prevClass = this.prevClass = (prev.texClass || TEXCLASS.ORD);
this.prevLevel = this.attributes.getInherited('scriptlevel') as number;
} else {
prevClass = this.prevClass = TEXCLASS.NONE;
}
if (texClass === TEXCLASS.BIN &&
(prevClass === TEXCLASS.NONE || prevClass === TEXCLASS.BIN || prevClass === TEXCLASS.OP ||
prevClass === TEXCLASS.REL || prevClass === TEXCLASS.OPEN || prevClass === TEXCLASS.PUNCT)) {
this.texClass = TEXCLASS.ORD;
} else if (prevClass === TEXCLASS.BIN &&
(texClass === TEXCLASS.REL || texClass === TEXCLASS.CLOSE || texClass === TEXCLASS.PUNCT)) {
prev.texClass = this.prevClass = TEXCLASS.ORD;
} else if (texClass === TEXCLASS.BIN) {
//
// Check if node is the last one in its container since the rule
// above only takes effect if there is a node that follows.
//
let child: MmlNode = this;
let parent = this.parent;
while (parent && parent.parent && parent.isEmbellished &&
(parent.childNodes.length === 1 ||
(!parent.isKind('mrow') && parent.core() === child))) {
child = parent;
parent = parent.parent;
}
if (parent.childNodes[parent.childNodes.length - 1] === child) {
this.texClass = TEXCLASS.ORD;
}
}
return this;
}
/**
* Do the normal inheritance, then look up the attributes from the operator dictionary.
* If there is no dictionary entry, get the TeX class from the Unicode range list.
*
* @override
*/
public setInheritedAttributes(attributes: AttributeList = {},
display: boolean = false, level: number = 0, prime: boolean = false) {
super.setInheritedAttributes(attributes, display, level, prime);
let mo = this.getText();
this.checkOperatorTable(mo);
this.checkPseudoScripts(mo);
this.checkPrimes(mo);
this.checkMathAccent(mo);
}
/**
* Set the attributes from the operator table
*
* @param {string} mo The test of the mo element
*/
protected checkOperatorTable(mo: string) {
let [form1, form2, form3] = this.handleExplicitForm(this.getForms());
this.attributes.setInherited('form', form1);
let OPTABLE = (this.constructor as typeof MmlMo).OPTABLE;
let def = OPTABLE[form1][mo] || OPTABLE[form2][mo] || OPTABLE[form3][mo];
if (def) {
if (this.getProperty('texClass') === undefined) {
this.texClass = def[2];
}
for (const name of Object.keys(def[3] || {})) {
this.attributes.setInherited(name, def[3][name]);
}
this.lspace = (def[0] + 1) / 18;
this.rspace = (def[1] + 1) / 18;
} else {
let range = getRange(mo);
if (range) {
if (this.getProperty('texClass') === undefined) {
this.texClass = range[2];
}
const spacing = (this.constructor as typeof MmlMo).MMLSPACING[range[2]];
this.lspace = (spacing[0] + 1) / 18;
this.rspace = (spacing[1] + 1) / 18;
}
}
}
/**
* @return {[string, string, string]} The list of form attribute values in the
* order they should be tested, based on the
* position of the element in its parent.
*/
public getForms(): [string, string, string] {
let core: MmlNode = this;
let parent = this.parent;
let Parent = this.Parent;
while (Parent && Parent.isEmbellished) {
core = parent;
parent = Parent.parent;
Parent = Parent.Parent;
}
if (parent && parent.isKind('mrow') && (parent as MmlMrow).nonSpaceLength() !== 1) {
if ((parent as MmlMrow).firstNonSpace() === core) {
return ['prefix', 'infix', 'postfix'];
}
if ((parent as MmlMrow).lastNonSpace() === core) {
return ['postfix', 'infix', 'prefix'];
}
}
return ['infix', 'prefix', 'postfix'];
}
/**
* @param {string[]} forms The three forms in the default order they are to be tested
* @return {string[]} The forms in the new order, if there is an explicit form attribute
*/
protected handleExplicitForm(forms: string[]): string[] {
if (this.attributes.isSet('form')) {
const form = this.attributes.get('form') as string;
forms = [form].concat(forms.filter(name => (name !== form)));
}
return forms;
}
/**
* Mark the mo as a pseudoscript if it is one. True means it is,
* false means it is a pseudo-script character, but in an msup (so needs a variant form)
*
* @param {string} mo The test of the mo element
*/
protected checkPseudoScripts(mo: string) {
const PSEUDOSCRIPTS = (this.constructor as typeof MmlMo).pseudoScripts;
if (!mo.match(PSEUDOSCRIPTS)) return;
const parent = this.coreParent().Parent;
const isPseudo = !parent || !(parent.isKind('msubsup') && !parent.isKind('msub'));
this.setProperty('pseudoscript', isPseudo);
if (isPseudo) {
this.attributes.setInherited('lspace', 0);
this.attributes.setInherited('rspace', 0);
}
}
/**
* Determine whether the mo consists of primes, and remap them if so.
*
* @param {string} mo The test of the mo element
*/
protected checkPrimes(mo: string) {
const PRIMES = (this.constructor as typeof MmlMo).primes;
if (!mo.match(PRIMES)) return;
const REMAP = (this.constructor as typeof MmlMo).remapPrimes;
const primes = unicodeString(unicodeChars(mo).map(c => REMAP[c]));
this.setProperty('primes', primes);
}
/**
* Determine whether the mo is a mathaccent character
*
* @param {string} mo The test of the mo element
*/
protected checkMathAccent(mo: string) {
const parent = this.Parent;
if (this.getProperty('mathaccent') !== undefined || !parent || !parent.isKind('munderover')) return;
const base = parent.childNodes[0] as MmlNode;
if (base.isEmbellished && base.coreMO() === this) return;
const MATHACCENT = (this.constructor as typeof MmlMo).mathaccents;
if (mo.match(MATHACCENT)) {
this.setProperty('mathaccent', true);
}
}
}

View File

@@ -0,0 +1,53 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMpadded node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlLayoutNode} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMpadded node class (subclass of AbstractMmlLayoutNode)
*/
export class MmlMpadded extends AbstractMmlLayoutNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlLayoutNode.defaults,
width: '',
height: '',
depth: '',
lspace: 0,
voffset: 0
};
/**
* @override
*/
public get kind() {
return 'mpadded';
}
}

View File

@@ -0,0 +1,53 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMphantom node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlLayoutNode, TEXCLASS} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMphantom node class (subclass of AbstractMmlLayoutNode)
*/
export class MmlMphantom extends AbstractMmlLayoutNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlLayoutNode.defaults
};
/**
* TeX class is ORD
*/
protected texclass = TEXCLASS.ORD;
/**
* @override
*/
public get kind() {
return 'mphantom';
}
}

View File

@@ -0,0 +1,84 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMroot node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {MmlNode, AbstractMmlNode, AttributeList, TEXCLASS} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMroot node class (subclass of AbstractMmlNode)
*/
export class MmlMroot extends AbstractMmlNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlNode.defaults
};
/**
* TeX class is ORD
*/
protected texclass = TEXCLASS.ORD;
/**
* @override
*/
public get kind() {
return 'mroot';
}
/**
* <mroot> requires two children
* @override
*/
public get arity() {
return 2;
}
/**
* Set the TeX class for the content of the root and the root separately.
* Return ourself as the previous item.
*
* @override
*/
public setTeXclass(prev: MmlNode) {
this.getPrevClass(prev);
this.childNodes[0].setTeXclass(null);
this.childNodes[1].setTeXclass(null);
return this;
}
/**
* Set the children display/level/prime for the base and root.
*
* @override
*/
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean) {
this.childNodes[0].setInheritedAttributes(attributes, display, level, true);
this.childNodes[1].setInheritedAttributes(attributes, false, level + 2, prime);
}
}

View File

@@ -0,0 +1,229 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMrow node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {MmlNode, AbstractMmlNode, TEXCLASS} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMrow node class (subclass of AbstractMmlNode)
*/
export class MmlMrow extends AbstractMmlNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlNode.defaults
};
/**
* The index of the core child, when acting as an embellish mrow
*/
protected _core: number = null;
/**
* @override
*/
public get kind() {
return 'mrow';
}
/**
* An mrow is space-like if all its children are.
*
* @override
*/
public get isSpacelike() {
for (const child of this.childNodes) {
if (!child.isSpacelike) {
return false;
}
}
return true;
}
/**
* An mrow is embellished if it contains one embellished operator
* and any number of space-like nodes
*
* @override
*/
public get isEmbellished() {
let embellished = false;
let i = 0;
for (const child of this.childNodes) {
if (child) {
if (child.isEmbellished) {
if (embellished) {
return false;
}
embellished = true;
this._core = i;
} else if (!child.isSpacelike) {
return false;
}
}
i++;
}
return embellished;
}
/**
* @override
*/
public core(): MmlNode {
if (!this.isEmbellished || this._core == null) {
return this;
}
return this.childNodes[this._core];
}
/**
* @override
*/
public coreMO(): MmlNode {
if (!this.isEmbellished || this._core == null) {
return this;
}
return this.childNodes[this._core].coreMO();
}
/**
* @return {number} The number of non-spacelike child nodes
*/
public nonSpaceLength(): number {
let n = 0;
for (const child of this.childNodes) {
if (child && !child.isSpacelike) {
n++;
}
}
return n;
}
/**
* @return {MmlNode|null} The first non-space-like child node
*/
public firstNonSpace(): MmlNode | null {
for (const child of this.childNodes) {
if (child && !child.isSpacelike) {
return child;
}
}
return null;
}
/**
* @return {MmlNode|null} The last non-space-like child node
*/
public lastNonSpace(): MmlNode | null {
let i = this.childNodes.length;
while (--i >= 0) {
let child = this.childNodes[i];
if (child && !child.isSpacelike) {
return child;
}
}
return null;
}
/**
* @override
*/
public setTeXclass(prev: MmlNode) {
if (this.getProperty('open') != null || this.getProperty('close') != null) {
//
// <mrow> looks like it came from \left...\right
// so treat as subexpression (TeX class INNER).
// Use prev = null for the initial element in the
// delimiters, since there is nothing previous to
// it in what would be the TeX math list.
//
this.getPrevClass(prev);
prev = null;
for (const child of this.childNodes) {
prev = child.setTeXclass(prev);
}
if (this.texClass == null) {
this.texClass = TEXCLASS.INNER;
}
} else {
//
// Normal <mrow>, so treat as though mrow is not there
//
for (const child of this.childNodes) {
prev = child.setTeXclass(prev);
}
if (this.childNodes[0]) {
this.updateTeXclass(this.childNodes[0]);
}
}
return prev;
}
}
/*****************************************************************/
/**
* Implements the MmlInferredMrow node class (subclass of MmlMrow)
*/
export class MmlInferredMrow extends MmlMrow {
/**
* @override
*/
public static defaults: PropertyList = MmlMrow.defaults;
/**
* @return {string} The inferred-mrow kind
*/
public get kind(): string {
return 'inferredMrow';
}
/**
* @return {boolean} This is inferred
*/
public get isInferred(): boolean {
return true;
}
/**
* @override
*/
public get notParent() {
return true;
}
/**
* Show the child nodes in brackets
*/
public toString() {
return '[' + this.childNodes.join(',') + ']';
}
}

View File

@@ -0,0 +1,55 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMs node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlTokenNode, TEXCLASS} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMs node class (subclass of AbstractMmlTokenNode)
*/
export class MmlMs extends AbstractMmlTokenNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlTokenNode.defaults,
lquote: '"',
rquote: '"'
};
/**
* TeX class is ORD
*/
protected texclass = TEXCLASS.ORD;
/**
* @override
*/
public get kind() {
return 'ms';
}
}

View File

@@ -0,0 +1,90 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMspace node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {MmlNode, AbstractMmlTokenNode, TEXCLASS} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMspace node class (subclass of AbstractMmlTokenNode)
*/
export class MmlMspace extends AbstractMmlTokenNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlTokenNode.defaults,
width: '0em',
height: '0ex',
depth: '0ex',
linebreak: 'auto'
};
/**
* TeX class is ORD
*/
protected texclass = TEXCLASS.NONE;
/**
* @override
*/
public setTeXclass(prev: MmlNode): MmlNode {
return prev;
}
/**
* @override
*/
public get kind() {
return 'mspace';
}
/**
* mspace can't have children
* @override
*/
public get arity() {
return 0;
}
/**
* @override
*/
public get isSpacelike() {
return true;
}
/**
* Only process linebreak if the space has no explicit dimensions (according to spec)
*
* @override
*/
public get hasNewline() {
let attributes = this.attributes;
return (attributes.getExplicit('width') == null && attributes.getExplicit('height') == null &&
attributes.getExplicit('depth') == null && attributes.get('linebreak') === 'newline');
}
}

View File

@@ -0,0 +1,87 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMsqrt node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {MmlNode, AbstractMmlNode, AttributeList, TEXCLASS} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMsqrt node class (subclass of AbstractMmlNode)
*/
export class MmlMsqrt extends AbstractMmlNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlNode.defaults
};
/**
* TeX class is ORD
*/
protected texclass = TEXCLASS.ORD;
/**
* @override
*/
public get kind() {
return 'msqrt';
}
/**
* <msqrt> has an inferred mrow
* @override
*/
public get arity() {
return -1;
}
/**
* <msqrt> can contain line breaks
* @override
*/
public get linebreakContainer() {
return true;
}
/**
* @override
*/
public setTeXclass(prev: MmlNode) {
this.getPrevClass(prev);
this.childNodes[0].setTeXclass(null);
return this;
}
/**
* The contents of sqrt are in TeX prime style.
*
* @override
*/
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, _prime: boolean) {
this.childNodes[0].setInheritedAttributes(attributes, display, level, true);
}
}

View File

@@ -0,0 +1,93 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMstyle node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlLayoutNode, AttributeList} from '../MmlNode.js';
import {INHERIT} from '../Attributes.js';
/*****************************************************************/
/**
* Implements the MmlMstyle node class (subclass of AbstractMmlLayoutNode)
*/
export class MmlMstyle extends AbstractMmlLayoutNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlLayoutNode.defaults,
scriptlevel: INHERIT,
displaystyle: INHERIT,
scriptsizemultiplier: 1 / Math.sqrt(2),
scriptminsize: '8px', // should be 8pt, but that is too large
mathbackground: INHERIT,
mathcolor: INHERIT,
dir: INHERIT,
infixlinebreakstyle: 'before'
};
/**
* @override
*/
public get kind() {
return 'mstyle';
}
/**
* @override
*/
public get notParent() {
return this.childNodes[0] && this.childNodes[0].childNodes.length === 1;
}
/**
* Handle scriptlevel changes, and add mstyle attributes to the ones being inherited.
*
* @override
*/
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean) {
let scriptlevel = this.attributes.getExplicit('scriptlevel');
if (scriptlevel != null) {
scriptlevel = scriptlevel.toString();
if (scriptlevel.match(/^\s*[-+]/)) {
level += parseInt(scriptlevel);
} else {
level = parseInt(scriptlevel);
}
prime = false; // style change resets tex prime style
}
let displaystyle = this.attributes.getExplicit('displaystyle') as boolean;
if (displaystyle != null) {
display = (displaystyle === true);
prime = false; // style change resets tex prime style
}
const cramped = this.attributes.getExplicit('data-cramped') as boolean; // manual control of tex prime style
if (cramped != null) {
prime = cramped;
}
attributes = this.addInheritedAttributes(attributes, this.attributes.getAllAttributes());
this.childNodes[0].setInheritedAttributes(attributes, display, level, prime);
}
}

View File

@@ -0,0 +1,173 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMsubsup, MmlMsub, and MmlMsup nodes
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlBaseNode, AttributeList} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMsubsup node class (subclass of AbstractMmlBaseNode)
*/
export class MmlMsubsup extends AbstractMmlBaseNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlBaseNode.defaults,
subscriptshift: '',
superscriptshift: ''
};
/**
* @override
*/
public get kind() {
return 'msubsup';
}
/**
* <msubsup> requires three children
* @override
*/
public get arity() {
return 3;
}
/**
* @return {number} The position of the base element
*/
public get base(): number {
return 0;
}
/**
* @return {number} The position of the subscript (overridden in msup below)
*/
public get sub(): number {
return 1;
}
/**
* @return {number} The position of the superscript (overridden in msup below)
*/
public get sup(): number {
return 2;
}
/**
* Super- and subscripts are not in displaymode, have scriptlevel increased, and prime style in subscripts.
*
* @override
*/
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean) {
let nodes = this.childNodes;
nodes[0].setInheritedAttributes(attributes, display, level, prime);
nodes[1].setInheritedAttributes(attributes, false, level + 1, prime || this.sub === 1);
if (!nodes[2]) {
return;
}
nodes[2].setInheritedAttributes(attributes, false, level + 1, prime || this.sub === 2);
}
}
/*****************************************************************/
/**
* Implements the MmlMsub node class (subclass of MmlMsubsup)
*/
export class MmlMsub extends MmlMsubsup {
/**
* @override
*/
public static defaults: PropertyList = {
...MmlMsubsup.defaults
};
/**
* @override
*/
public get kind() {
return 'msub';
}
/**
* <msub> only gets two children
* @override
*/
public get arity() {
return 2;
}
}
/*****************************************************************/
/**
* Implements the MmlMsup node class (subclass of MmlMsubsup)
*/
export class MmlMsup extends MmlMsubsup {
/**
* @override
*/
public static defaults: PropertyList = {
...MmlMsubsup.defaults
};
/**
* @override
*/
public get kind() {
return 'msup';
}
/**
* <msup> only gets two children
* @override
*/
get arity() {
return 2;
}
/**
* child 1 is superscript
* @override
*/
get sup() {
return 1;
}
/**
* child 2 is null (no subscript)
* @override
*/
get sub() {
return 2;
}
}

View File

@@ -0,0 +1,182 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMtable node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {MmlNode, AbstractMmlNode, AttributeList, TEXCLASS, indentAttributes} from '../MmlNode.js';
import {split} from '../../../util/string.js';
/*****************************************************************/
/**
* Implements the MmlMtable node class (subclass of AbstractMmlNode)
*/
export class MmlMtable extends AbstractMmlNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlNode.defaults,
align: 'axis',
rowalign: 'baseline',
columnalign: 'center',
groupalign: '{left}',
alignmentscope: true,
columnwidth: 'auto',
width: 'auto',
rowspacing: '1ex',
columnspacing: '.8em',
rowlines: 'none',
columnlines: 'none',
frame: 'none',
framespacing: '0.4em 0.5ex',
equalrows: false,
equalcolumns: false,
displaystyle: false,
side: 'right',
minlabelspacing: '0.8em'
};
/**
* Extra properties for this node
*/
public properties = {
useHeight: true
};
/**
* TeX class is ORD
*/
protected texclass = TEXCLASS.ORD;
/**
* @override
*/
public get kind() {
return 'mtable';
}
/**
* Linebreaks are allowed in tables
* @override
*/
public get linebreakContainer() {
return true;
}
/**
* @override
*/
public setInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean) {
//
// Force inheritance of shift and align values (since they are needed to output tables with labels)
// but make sure they are not given explicitly on the <mtable> tag.
//
for (const name of indentAttributes) {
if (attributes[name]) {
this.attributes.setInherited(name, attributes[name][1]);
}
if (this.attributes.getExplicit(name) !== undefined) {
delete (this.attributes.getAllAttributes())[name];
}
}
super.setInheritedAttributes(attributes, display, level, prime);
}
/**
* Make sure all children are mtr or mlabeledtr nodes
* Inherit the table attributes, and set the display attribute based on the table's displaystyle attribute
* Reset the prime value to false
*
* @override
*/
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, _prime: boolean) {
for (const child of this.childNodes) {
if (!child.isKind('mtr')) {
this.replaceChild(this.factory.create('mtr'), child)
.appendChild(child);
}
}
level = this.getProperty('scriptlevel') as number || level;
display = !!(this.attributes.getExplicit('displaystyle') || this.attributes.getDefault('displaystyle'));
attributes = this.addInheritedAttributes(attributes, {
columnalign: this.attributes.get('columnalign'),
rowalign: 'center'
});
const cramped = this.attributes.getExplicit('data-cramped') as boolean;
const ralign = split(this.attributes.get('rowalign') as string);
for (const child of this.childNodes) {
attributes.rowalign[1] = ralign.shift() || attributes.rowalign[1];
child.setInheritedAttributes(attributes, display, level, !!cramped);
}
}
/**
* Check that children are mtr or mlabeledtr
*
* @override
*/
protected verifyChildren(options: PropertyList) {
let mtr: MmlNode = null; // all consecutive non-mtr elements are collected into one mtr
const factory = this.factory;
for (let i = 0; i < this.childNodes.length; i++) {
const child = this.childNodes[i];
if (child.isKind('mtr')) {
mtr = null; // start a new row if there are non-mtr children
} else {
const isMtd = child.isKind('mtd');
//
// If there is already an mtr for previous children, just remove the child
// otherwise replace the child with a new mtr
//
if (mtr) {
this.removeChild(child);
i--; // there is one fewer child now
} else {
mtr = this.replaceChild(factory.create('mtr'), child) as MmlNode;
}
mtr.appendChild(isMtd ? child : factory.create('mtd', {}, [child])); // Move the child into the mtr
if (!options['fixMtables']) {
child.parent.removeChild(child); // remove the child from its mtd or mtr
child.parent = this; // ... and make it think it is a child of the table again
isMtd && mtr.appendChild(factory.create('mtd')); // child will be replaced, so make sure there is an mtd
const merror = child.mError('Children of ' + this.kind + ' must be mtr or mlabeledtr', options, isMtd);
mtr.childNodes[mtr.childNodes.length - 1].appendChild(merror); // append the error to the mtd in the mtr
}
}
}
super.verifyChildren(options);
}
/**
* @override
*/
public setTeXclass(prev: MmlNode) {
this.getPrevClass(prev);
for (const child of this.childNodes) {
child.setTeXclass(null);
}
return this;
}
}

View File

@@ -0,0 +1,92 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMtd node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlBaseNode, MmlNode} from '../MmlNode.js';
import {INHERIT} from '../Attributes.js';
/*****************************************************************/
/**
* Implements the MmlMtd node class (subclass of AbstractMmlBaseNode)
*/
export class MmlMtd extends AbstractMmlBaseNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlBaseNode.defaults,
rowspan: 1,
columnspan: 1,
rowalign: INHERIT,
columnalign: INHERIT,
groupalign: INHERIT
};
/**
* @override
*/
public get kind() {
return 'mtd';
}
/**
* <mtd> has an inferred mrow
* @overrride
*/
public get arity() {
return -1;
}
/**
* <mtd> can contain line breaks
* @override
*/
public get linebreakContainer() {
return true;
}
/**
* Check that parent is mtr
*
* @override
*/
protected verifyChildren(options: PropertyList) {
if (this.parent && !this.parent.isKind('mtr')) {
this.mError(this.kind + ' can only be a child of an mtr or mlabeledtr', options, true);
return;
}
super.verifyChildren(options);
}
/**
* @override
*/
public setTeXclass(prev: MmlNode) {
this.getPrevClass(prev);
this.childNodes[0].setTeXclass(null);
return this;
}
}

View File

@@ -0,0 +1,61 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMtext node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlTokenNode, TEXCLASS} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMtext node class (subclass of AbstractMmlTokenNode)
*/
export class MmlMtext extends AbstractMmlTokenNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlTokenNode.defaults
};
/**
* TeX class is ORD
*/
protected texclass = TEXCLASS.ORD;
/**
* @override
*/
public get kind() {
return 'mtext';
}
/**
* <mtext> is always space-like according to the spec
* @override
*/
public get isSpacelike() {
return true;
}
}

View File

@@ -0,0 +1,144 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMtr and MmlMlabeledtr nodes
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {MmlNode, AbstractMmlNode, AttributeList} from '../MmlNode.js';
import {INHERIT} from '../Attributes.js';
import {split} from '../../../util/string.js';
/*****************************************************************/
/**
* Implements the MmlMtr node class (subclass of AbstractMmlNode)
*/
export class MmlMtr extends AbstractMmlNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlNode.defaults,
rowalign: INHERIT,
columnalign: INHERIT,
groupalign: INHERIT
};
/**
* @override
*/
public get kind() {
return 'mtr';
}
/**
* <mtr> can contain linebreaks
* @override
*/
public get linebreakContainer() {
return true;
}
/**
* Inherit the mtr attributes
*
* @override
*/
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean) {
for (const child of this.childNodes) {
if (!child.isKind('mtd')) {
this.replaceChild(this.factory.create('mtd'), child)
.appendChild(child);
}
}
const calign = split(this.attributes.get('columnalign') as string);
if (this.arity === 1) {
calign.unshift(this.parent.attributes.get('side') as string);
}
attributes = this.addInheritedAttributes(attributes, {
rowalign: this.attributes.get('rowalign'),
columnalign: 'center'
});
for (const child of this.childNodes) {
attributes.columnalign[1] = calign.shift() || attributes.columnalign[1];
child.setInheritedAttributes(attributes, display, level, prime);
}
}
/**
* Check that parent is mtable and children are mtd
*
* @override
*/
protected verifyChildren(options: PropertyList) {
if (this.parent && !this.parent.isKind('mtable')) {
this.mError(this.kind + ' can only be a child of an mtable', options, true);
return;
}
for (const child of this.childNodes) {
if (!child.isKind('mtd')) {
let mtd = this.replaceChild(this.factory.create('mtd'), child) as MmlNode;
mtd.appendChild(child);
if (!options['fixMtables']) {
child.mError('Children of ' + this.kind + ' must be mtd', options);
}
}
}
super.verifyChildren(options);
}
/**
* @override
*/
public setTeXclass(prev: MmlNode) {
this.getPrevClass(prev);
for (const child of this.childNodes) {
child.setTeXclass(null);
}
return this;
}
}
/*****************************************************************/
/**
* Implements the MmlMlabeledtr node class (subclass of MmlMtr)
*/
export class MmlMlabeledtr extends MmlMtr {
/**
* @override
*/
public get kind() {
return 'mlabeledtr';
}
/**
* <mlabeledtr> requires at least one child (the label)
* @override
*/
get arity() {
return 1;
}
}

View File

@@ -0,0 +1,238 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlMunderover node
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlBaseNode, AttributeList} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMunderover node class (subclass of AbstractMmlNode)
*/
export class MmlMunderover extends AbstractMmlBaseNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlBaseNode.defaults,
accent: false,
accentunder: false,
align: 'center'
};
/**
* The names of attributes controling accents for each child node (reversed for mover below)
*/
protected static ACCENTS = ['', 'accentunder', 'accent'];
/**
* @override
*/
public get kind() {
return 'munderover';
}
/**
* <munderover> requires three children
* @override
*/
public get arity() {
return 3;
}
/**
* @return {number} The base is child 0
*/
public get base(): number {
return 0;
}
/**
* @return {number} Child 1 goes under (overridden by mover below)
*/
public get under(): number {
return 1;
}
/**
* @return {number} Child 2 goes over (overridden by mover below)
*/
public get over(): number {
return 2;
}
/**
* <munderover> can contain line breaks
* @override
*/
public get linebreakContainer() {
return true;
}
/**
* Base is in prime style if there is an over node
* Force scriptlevel change if converted to sub-sup by movablelimits on the base in non-display mode
* Adjust displaystyle, scriptlevel, and primestyle for the under/over nodes and check if accent
* values have changed due to the inheritance (e.g., settings in operator dictionary)
*
* @override
*/
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean) {
let nodes = this.childNodes;
nodes[0].setInheritedAttributes(attributes, display, level, prime || !!nodes[this.over]);
let force = !!(!display && nodes[0].coreMO().attributes.get('movablelimits'));
let ACCENTS = (this.constructor as typeof MmlMunderover).ACCENTS;
nodes[1].setInheritedAttributes(attributes, false,
this.getScriptlevel(ACCENTS[1], force, level),
prime || this.under === 1);
this.setInheritedAccent(1, ACCENTS[1], display, level, prime, force);
if (!nodes[2]) {
return;
}
nodes[2].setInheritedAttributes(attributes, false,
this.getScriptlevel(ACCENTS[2], force, level),
prime || this.under === 2);
this.setInheritedAccent(2, ACCENTS[2], display, level, prime, force);
}
/**
* @param {string} accent The name of the accent attribute to check ("accent" or "accentunder")
* @param {boolean} force True if the scriptlevel change is to be forced to occur
* @param {number} level The current scriptlevel
* @return {number} The new script level based on the accent attribute
*/
protected getScriptlevel(accent: string, force: boolean, level: number): number {
if (force || !this.attributes.get(accent)) {
level++;
}
return level;
}
/**
* Check if an under or over accent should cause the appropriate accent attribute to be inherited
* on the munderover node, and if it is not the default, re-inherit the scriptlevel, since that
* is affected by the accent attribute
*
* @param {number} n The index of the node to check
* @param {string} accent The name of the accent attribute to check ("accent" or "accentunder")
* @param {boolean} display The displaystyle
* @param {number} level The scriptlevel
* @param {number} prime The TeX prime style
* @param {boolean} force Whether to force the scriptlevel change
*/
protected setInheritedAccent(n: number, accent: string, display: boolean, level: number,
prime: boolean, force: boolean) {
let node = this.childNodes[n];
if (this.attributes.getExplicit(accent) == null && node.isEmbellished) {
let value = node.coreMO().attributes.get('accent');
this.attributes.setInherited(accent, value);
if (value !== this.attributes.getDefault(accent)) {
node.setInheritedAttributes({}, display, this.getScriptlevel(accent, force, level), prime);
}
}
}
}
/*****************************************************************/
/**
* Implements the MmlMunder node class (subclass of MmlMunderover)
*/
export class MmlMunder extends MmlMunderover {
/**
* @override
*/
public static defaults: PropertyList = {
...MmlMunderover.defaults
};
/**
* @override
*/
public get kind() {
return 'munder';
}
/**
* <munder> has only two children
* @override
*/
public get arity() {
return 2;
}
}
/*****************************************************************/
/**
* Implements the MmlMover node class (subclass of MmlMunderover)
*/
export class MmlMover extends MmlMunderover {
/**
* @override
*/
public static defaults: PropertyList = {
...MmlMunderover.defaults
};
/**
* The first child is the over accent (second never occurs)
*/
protected static ACCENTS = ['', 'accent', 'accentunder'];
/**
* @override
*/
public get kind() {
return 'mover';
}
/**
* <mover> has only two children
* @override
*/
get arity() {
return 2;
}
/**
* Child 1 is the over node
* @override
*/
public get over() {
return 1;
}
/**
* Child 2 is the null (the under node)
* @override
*/
public get under() {
return 2;
}
}

View File

@@ -0,0 +1,130 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Implements the MmlSemantics, MmlAnnotation, and MmlAnnotationXML nodes
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {PropertyList} from '../../Tree/Node.js';
import {AbstractMmlNode, AbstractMmlBaseNode} from '../MmlNode.js';
/*****************************************************************/
/**
* Implements the MmlMroot node class (subclass of AbstractMmlBaseNode)
*/
export class MmlSemantics extends AbstractMmlBaseNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlBaseNode.defaults,
definitionUrl: null,
encoding: null
};
/**
* @override
*/
public get kind() {
return 'semantics';
}
/**
* <semantics> requires at least one node
* @override
*/
public get arity() {
return 1;
}
/**
* Ignore <semantics> when looking for partent node
* @override
*/
public get notParent() {
return true;
}
}
/*****************************************************************/
/**
* Implements the MmlMroot node class (subclass of AbstractMmlNode)
*/
export class MmlAnnotationXML extends AbstractMmlNode {
/**
* @override
*/
public static defaults: PropertyList = {
...AbstractMmlNode.defaults,
definitionUrl: null,
encoding: null,
cd: 'mathmlkeys',
name: '',
src: null
};
/**
* @override
*/
public get kind() {
return 'annotation-xml';
}
/**
* Children are XMLNodes, so don't bother inheritting to them
* @override
*/
protected setChildInheritedAttributes() {}
}
/*****************************************************************/
/**
* Implements the MmlMroot node class (subclass of MmlAnnotationXML)
*/
export class MmlAnnotation extends MmlAnnotationXML {
/**
* @override
*/
public static defaults = {
...MmlAnnotationXML.defaults
};
/**
* Extra properties for this node
*/
public properties = {
isChars: true
};
/**
* @override
*/
public get kind() {
return 'annotation';
}
}

View File

@@ -0,0 +1,67 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview A visitor class that visits MmlNode trees
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {TextNode, XMLNode} from './MmlNode.js';
import {MmlFactory} from './MmlFactory.js';
import {AbstractVisitor} from '../Tree/Visitor.js';
/*****************************************************************/
/**
* Implements the MmlVisitor (subclass of Visitor, and base class
* for visitors that accept MmlNode trees)
*/
export class MmlVisitor extends AbstractVisitor {
/**
* @param {MmlFactory} factory The MmlNode factory (defaults to MmlFactory if not given)
*
* @constructor
* @extends {AbstractVisitor}
*/
constructor(factory: MmlFactory = null) {
if (!factory) {
factory = new MmlFactory();
}
super(factory);
}
/***********************************************/
/**
* Stubs for overriding in subclasses
*/
/**
* @param {TextNode} node The TextNode to visit
* @param {any[]} args Any arguments needed by the visitor
* @return {any} Any return value needed for the visitor
*/
public visitTextNode(_node: TextNode, ..._args: any[]): any {}
/**
* @param {XMLNode} node The XMLNode to visit
* @param {any[]} args Any arguments needed by the visitor
* @return {any} Any return value needed for the visitor
*/
public visitXMLNode(_node: XMLNode, ..._args: any[]): any {}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,248 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview A visitor that produces a serilaied MathML string
* (replacement for toMathML() output from v2)
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {MmlVisitor} from './MmlVisitor.js';
import {MmlNode, TextNode, XMLNode, TEXCLASS, TEXCLASSNAMES} from './MmlNode.js';
import {MmlMi} from './MmlNodes/mi.js';
export const DATAMJX = 'data-mjx-';
export const toEntity = (c: string) => '&#x' + c.codePointAt(0).toString(16).toUpperCase() + ';';
type PropertyList = {[name: string]: string};
/*****************************************************************/
/**
* Implements the SerializedMmlVisitor (subclass of MmlVisitor)
*/
export class SerializedMmlVisitor extends MmlVisitor {
/**
* Translations for the internal mathvariants
*/
public static variants: PropertyList = {
'-tex-calligraphic': 'script',
'-tex-bold-calligraphic': 'bold-script',
'-tex-oldstyle': 'normal',
'-tex-bold-oldstyle': 'bold',
'-tex-mathit': 'italic'
};
/**
* Attributes to include on every element of a given kind
*/
public static defaultAttributes: {[kind: string]: PropertyList} = {
math: {
xmlns: 'http://www.w3.org/1998/Math/MathML'
}
};
/**
* Convert the tree rooted at a particular node into a serialized MathML string
*
* @param {MmlNode} node The node to use as the root of the tree to traverse
* @return {string} The MathML string representing the internal tree
*/
public visitTree(node: MmlNode): string {
return this.visitNode(node, '');
}
/**
* @param {TextNode} node The text node to visit
* @param {string} space The amount of indenting for this node
* @return {string} The (HTML-quoted) text of the node
*/
public visitTextNode(node: TextNode, _space: string): string {
return this.quoteHTML(node.getText());
}
/**
* @param {XMLNode} node The XML node to visit
* @param {string} space The amount of indenting for this node
* @return {string} The serialization of the XML node
*/
public visitXMLNode(node: XMLNode, space: string): string {
return space + node.getSerializedXML();
}
/**
* Visit an inferred mrow, but don't add the inferred row itself (since
* it is supposed to be inferred).
*
* @param {MmlNode} node The inferred mrow to visit
* @param {string} space The amount of indenting for this node
* @return {string} The serialized contents of the mrow, properly indented
*/
public visitInferredMrowNode(node: MmlNode, space: string): string {
let mml = [];
for (const child of node.childNodes) {
mml.push(this.visitNode(child, space));
}
return mml.join('\n');
}
/**
* Visit a TeXAtom node. It is turned into a mrow with the appropriate TeX class
* indicator.
*
* @param {MmlNode} node The TeXAtom to visit.
* @param {string} space The amount of indenting for this node.
* @return {string} The serialized contents of the mrow, properly indented.
*/
public visitTeXAtomNode(node: MmlNode, space: string): string {
let children = this.childNodeMml(node, space + ' ', '\n');
let mml = space + '<mrow' + this.getAttributes(node) + '>' +
(children.match(/\S/) ? '\n' + children + space : '') + '</mrow>';
return mml;
}
/**
* @param {MmlNode} node The annotation node to visit
* @param {string} space The number of spaces to use for indentation
* @return {string} The serializied annotation element
*/
public visitAnnotationNode(node: MmlNode, space: string): string {
return space + '<annotation' + this.getAttributes(node) + '>'
+ this.childNodeMml(node, '', '')
+ '</annotation>';
}
/**
* The generic visiting function:
* Make the string version of the open tag, properly indented, with it attributes
* Increate the indentation level
* Add the childnodes
* Add the end tag with proper spacing (empty tags have the close tag following directly)
*
* @param {MmlNode} node The node to visit
* @param {string} space The number of spaces to use for indentation
* @return {string} The serialization of the given node
*/
public visitDefault(node: MmlNode, space: string): string {
let kind = node.kind;
let [nl, endspace] = (node.isToken || node.childNodes.length === 0 ? ['', ''] : ['\n', space]);
const children = this.childNodeMml(node, space + ' ', nl);
return space + '<' + kind + this.getAttributes(node) + '>'
+ (children.match(/\S/) ? nl + children + endspace : '')
+ '</' + kind + '>';
}
/**
* @param {MmlNode} node The node whose children are to be added
* @param {string} space The spaces to use for indentation
* @param {string} nl The newline character (or empty)
* @return {string} The serializied children
*/
protected childNodeMml(node: MmlNode, space: string, nl: string): string {
let mml = '';
for (const child of node.childNodes) {
mml += this.visitNode(child, space) + nl;
}
return mml;
}
/**
* @param {MmlNode} node The node whose attributes are to be produced
* @return {string} The attribute list as a string
*/
protected getAttributes(node: MmlNode): string {
const attr = [];
const defaults = (this.constructor as typeof SerializedMmlVisitor).defaultAttributes[node.kind] || {};
const attributes = Object.assign({},
defaults,
this.getDataAttributes(node),
node.attributes.getAllAttributes()
);
const variants = (this.constructor as typeof SerializedMmlVisitor).variants;
if (attributes.hasOwnProperty('mathvariant') && variants.hasOwnProperty(attributes.mathvariant)) {
attributes.mathvariant = variants[attributes.mathvariant];
}
for (const name of Object.keys(attributes)) {
const value = String(attributes[name]);
if (value === undefined) continue;
attr.push(name + '="' + this.quoteHTML(value) + '"');
}
return attr.length ? ' ' + attr.join(' ') : '';
}
/**
* Create the list of data-mjx-* attributes
*
* @param {MmlNode} node The node whose data list is to be generated
* @return {PropertyList} The final class attribute list
*/
protected getDataAttributes(node: MmlNode): PropertyList {
const data = {} as PropertyList;
const variant = node.attributes.getExplicit('mathvariant') as string;
const variants = (this.constructor as typeof SerializedMmlVisitor).variants;
variant && variants.hasOwnProperty(variant) && this.setDataAttribute(data, 'variant', variant);
node.getProperty('variantForm') && this.setDataAttribute(data, 'alternate', '1');
node.getProperty('pseudoscript') && this.setDataAttribute(data, 'pseudoscript', 'true');
node.getProperty('autoOP') === false && this.setDataAttribute(data, 'auto-op', 'false');
const scriptalign = node.getProperty('scriptalign') as string;
scriptalign && this.setDataAttribute(data, 'script-align', scriptalign);
const texclass = node.getProperty('texClass') as number;
if (texclass !== undefined) {
let setclass = true;
if (texclass === TEXCLASS.OP && node.isKind('mi')) {
const name = (node as MmlMi).getText();
setclass = !(name.length > 1 && name.match(MmlMi.operatorName));
}
setclass && this.setDataAttribute(data, 'texclass', texclass < 0 ? 'NONE' : TEXCLASSNAMES[texclass]);
}
node.getProperty('scriptlevel') && node.getProperty('useHeight') === false &&
this.setDataAttribute(data, 'smallmatrix', 'true');
return data;
}
/**
* @param {PropertyList} data The class attribute list
* @param {string} name The name for the data-mjx-name attribute
* @param {string} value The value of the attribute
*/
protected setDataAttribute(data: PropertyList, name: string, value: string) {
data[DATAMJX + name] = value;
}
/**
* Convert HTML special characters to entities (&amp;, &lt;, &gt;, &quot;)
* Convert multi-character Unicode characters to entities
* Convert non-ASCII characters to entities.
*
* @param {string} value The string to be made HTML escaped
* @return {string} The string with escaping performed
*/
protected quoteHTML(value: string): string {
return value
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;').replace(/>/g, '&gt;')
.replace(/\"/g, '&quot;')
.replace(/[\uD800-\uDBFF]./g, toEntity)
.replace(/[\u0080-\uD7FF\uE000-\uFFFF]/g, toEntity);
}
}

View File

@@ -0,0 +1,106 @@
/*************************************************************
*
* Copyright (c) 2017-2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview A visitor that produces a serilaied MathML string
* that contains addition information about inherited
* attributes and internal properties.
* (For testing purposes only.)
*
* @author dpvc@mathjax.org (Davide Cervone)
*/
import {SerializedMmlVisitor} from './SerializedMmlVisitor.js';
import {MmlNode} from './MmlNode.js';
import {PropertyList} from '../Tree/Node.js';
/*****************************************************************/
/**
* Implements the TestMmlVisitor (subclass of SerializedMmlVisitor)
*/
export class TestMmlVisitor extends SerializedMmlVisitor {
/**
* The generic visiting function:
* Make the string versino of the open tag with it attributes (explicit and
* inherited) and properties
* Increate the indentation level
* Add the childnodes
* Add the end tag with proper spacing (empty tags have the close tag following directly)
*
* @param {MmlNode} node The node to visit
* @param {string} space The number of spaces to use for indentation
*/
public visitDefault(node: MmlNode, space: string) {
let kind = node.kind;
let [nl, endspace] = (node.isToken || node.childNodes.length === 0 ? ['', ''] : ['\n', space]);
let mml = space + '<' + kind + this.getAttributes(node) +
this.getInherited(node) + this.getProperties(node) + '\n' + space + ' ' +
this.attributeString({
isEmbellished: node.isEmbellished,
isSpacelike: node.isSpacelike,
texClass: node.texClass
}, '{', '}') +
'>' + nl;
space += ' ';
for (const child of node.childNodes) {
mml += this.visitNode(child, space) + nl;
}
mml += endspace + '</' + kind + '>';
return mml;
}
/**
* @param {MmlNode} node The node whose attributes are to be produced
* @return {string} The attribute list as a string
*/
protected getAttributes(node: MmlNode): string {
return this.attributeString(node.attributes.getAllAttributes(), '', '');
}
/**
* @param {MmlNode} node The node whose inherited attributes are to be produced
* @return {string} The inhertited attribute list as a string (with each in [...])
*/
protected getInherited(node: MmlNode): string {
return this.attributeString(node.attributes.getAllInherited(), '[', ']');
}
/**
* @param {MmlNode} node The node whose properties are to be produced
* @return {string} The property list as a string (with each in [[...]])
*/
protected getProperties(node: MmlNode): string {
return this.attributeString(node.getAllProperties(), '[[', ']]');
}
/**
* @param {PropertyList} attributes The attributes to be made into a list
* @param {string} open The opening delimiter to add before each attribute
* @param {string} close The closing delimiter to add after each attribute
* @return {string} The attribute list as a string
*/
protected attributeString(attributes: PropertyList, open: string, close: string): string {
let ATTR = '';
for (const name of Object.keys(attributes)) {
ATTR += ' ' + open + name + '="' + this.quoteHTML(String(attributes[name])) + '"' + close;
}
return ATTR;
}
}