Skip to content

Commit

Permalink
Merge branch 'develop' into issue3098b
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvc authored Sep 17, 2023
2 parents bbdbc31 + 55699fb commit de08ad6
Show file tree
Hide file tree
Showing 26 changed files with 158 additions and 153 deletions.
2 changes: 1 addition & 1 deletion components/bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const EXCLUDE = new Map((config.exclude || []).map(name => [name, true])); // f
const EXCLUDESUBDIRS = !!config.excludeSubdirs; // exclude subdirectories or not
const JS = config.js || config.mathjax || mjPath; // path to the compiled .js files
const LIB = config.lib || './lib'; // path to the lib directory to create
const TS = config.ts || JS.replace(/[cm]js$/, 'ts'); // path to the .ts files
const TS = config.ts || path.join(JS, '..', 'ts'); // path to the .ts files
const GLOBAL = config.global || mjGlobal; // path to the global.js file
const VERSION = config.version || mjGlobal.replace(/global/, 'version'); // path to the version.js file
const TYPE = config.type || getType(); // the module type
Expand Down
4 changes: 3 additions & 1 deletion components/bin/pack
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ async function webpackLib(dir) {
if (!config) return;
const jsdir = (config.js ? path.resolve(dir, config.js).replace(/js$/, target) : jsPath);
const jsRE = fileRegExp(jsdir);
const jsRE2 = (config.js ? fileRegExp(path.resolve(dir, config.js)) : /^$/);
const libRE = fileRegExp(path.resolve(jsdir, '..', 'components'));

//
Expand Down Expand Up @@ -131,7 +132,8 @@ async function webpackLib(dir) {
.replace(rootRE, '[mathjax]')
.replace(fontRE, '[$1]/$2')
.replace(jsRE, '[js]')
.replace(libRE, '[lib]');
.replace(jsRE2, '[js]')
.replace(libRE, '[build]');
if (name.charAt(0) !== '.' && name.charAt(0) !== '[') {
name = path.relative(dir, name);
}
Expand Down
1 change: 0 additions & 1 deletion components/bin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"#js/*": "mathjax-full/cjs/*",
"#source/*": "mathjax-full/components/cjs/*",
"#root/*": "mathjax-full/cjs/components/cjs/*",
"#mml3/*": "mathjax-full/cjs/input/mathml/mml3/cjs/*",
"#menu/*": "mj-context-menu/cjs/*",
"#sre/*": "speech-rule-engine/cjs/*",
"#mhchem/*": "mhchemparser/dist/*",
Expand Down
2 changes: 2 additions & 0 deletions components/mjs/node-main/node-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ const dir = global.MathJax.config.__dirname; // set up by node-main.mjs or nod
* Set up the initial configuration
*/
combineDefaults(MathJax.config, 'loader', {
paths: {'mathjax-modern': 'mathjax-modern-font'},
require: eval("(file) => import(file)"), // use dynamic imports
failed: (err) => {throw err} // pass on error message to init()'s catch function
});
combineDefaults(MathJax.config, 'output', {font: 'mathjax-modern'});

/*
* Mark the preloaded components
Expand Down
6 changes: 4 additions & 2 deletions components/root-pack.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//
// Do what __dirname does in webpack
// Replacement for __dirname for root directory
//
export const esRoot = () => '/';

const config = global.MathJax?.config || {};
export const mjxRoot = () => config?.loader?.paths?.mathjax || config?.__dirname || '/';
7 changes: 7 additions & 0 deletions components/webpack.common.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function fullPath(resource) {
const PLUGINS = function (js, dir, target, font, jax, name) {
//
// Replace a11y/util and components/mjs/root with the webpack versions
// and map mathjax-full/js to mathjax-full/${target}
//
const plugins = [
new webpack.NormalModuleReplacementPlugin(
Expand All @@ -76,6 +77,12 @@ const PLUGINS = function (js, dir, target, font, jax, name) {
new webpack.NormalModuleReplacementPlugin(
/mjs\/components\/mjs\/root\.js/,
'../../../components/root-pack.js'
),
new webpack.NormalModuleReplacementPlugin(
/mathjax-full\/js\//,
function (resource) {
resource.request = resource.request.replace(/mathjax-full\/js\//, `mathjax-full/${target}/`);
}
)
];

Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"#js/*": "mathjax-full/mjs/*",
"#source/*": "mathjax-full/components/mjs/*",
"#root/*": "mathjax-full/mjs/components/mjs/*",
"#mml3/*": "mathjax-full/mjs/input/mathml/mml3/mjs/*",
"#menu/*": "mj-context-menu/js/*",
"#sre/*": "speech-rule-engine/js/*",
"#mhchem/*": "mhchemparser/esm/*",
Expand Down Expand Up @@ -110,9 +109,9 @@
"build": "npm run -s build-mjs",
"build-all": "npm run -s build-mjs ; echo ; npm run -s build-cjs",
"=============================================================================== mml3": "",
"premake-mml3-xslt": "cd ts/input/mathml/mml3 && grep '^\\s*\\(<\\|or\\|xmlns\\|excl\\|\">\\)' mml3.ts > mml3.xsl",
"make-mml3-xslt": "cd ts/input/mathml/mml3 && npx xslt3 -t -xsl:mml3.xsl -export:mml3.sef.json -nogo",
"postmake-mml3-xslt": "npx rimraf ts/input/mathml/mml3/mml3.xsl",
"premake-mml3-xslt": "grep '^\\s*\\(<\\|or\\|xmlns\\|excl\\|\">\\)' ts/input/mathml/mml3/mml3.ts > /tmp/mml3.xsl",
"make-mml3-xslt": "npx xslt3 -t -xsl:/tmp/mml3.xsl -export:ts/input/mathml/mml3/mml3.sef.json -nogo",
"postmake-mml3-xslt": "npx rimraf /tmp/mml3.xsl",
"=============================================================================== install": "",
"link:full": "node components/bin/link-full",
"install": "npm run -s link:full",
Expand Down
2 changes: 1 addition & 1 deletion ts/components/cjs/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ declare const __dirname: string;
/**
* @return {string} The MathJax component root directory
*/
export function esRoot(): string {
export function mjxRoot(): string {
return __dirname.replace(/[cm]js\/components\/[cm]js$/, (_) => 'bundle');
}
25 changes: 15 additions & 10 deletions ts/components/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,22 @@ export function isObject(x: any): boolean {
* Combine user-produced configuration with existing defaults. Values
* from src will replace those in dst.
*
* @param {any} dst The destination config object (to be merged into)
* @param {any} src The source configuration object (to replace defaul values in dst}
* @return {any} The resulting (modified) config object
* @param {any} dst The destination config object (to be merged into)
* @param {any} src The source configuration object (to replace default values in dst}
* @param {boolean} check True when combining into MathJax._ to avoid setting a property with a getter
* @return {any} The resulting (modified) config object
*/
export function combineConfig(dst: any, src: any): any {
export function combineConfig(dst: any, src: any, check: boolean = false): any {
for (const id of Object.keys(src)) {
if (id === '__esModule') continue;
if (isObject(dst[id]) && isObject(src[id]) &&
!(src[id] instanceof Promise) /* needed for IE polyfill */) {
combineConfig(dst[id], src[id]);
} else if (src[id] !== null && src[id] !== undefined && dst[id] !== src[id]) {
if (id === '__esModule' ||
dst[id] === src[id] ||
src[id] === null ||
src[id] === undefined) {
continue;
}
if (isObject(dst[id]) && isObject(src[id])) {
combineConfig(dst[id], src[id], check || id === '_');
} else if (!check || !Object.getOwnPropertyDescriptor(dst, id)?.get) {
dst[id] = src[id];
}
}
Expand All @@ -102,7 +107,7 @@ export function combineConfig(dst: any, src: any): any {
*
* @param {any} dst The destination config object (to be merged into)
* @param {string} name The id of the configuration block to modify (created if doesn't exist)
* @param {any} src The source configuration object (to replace defaul values in dst}
* @param {any} src The source configuration object (to replace default values in dst}
* @return {any} The resulting (modified) config object
*/
export function combineDefaults(dst: any, name: string, src: any): any {
Expand Down
4 changes: 2 additions & 2 deletions ts/components/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {MathJax as MJGlobal, MathJaxObject as MJObject, MathJaxLibrary,
MathJaxConfig as MJConfig, combineWithMathJax, combineDefaults} from './global.js';
import {Package, PackageError, PackageReady, PackageFailed} from './package.js';
import {FunctionList} from '../util/FunctionList.js';
import {esRoot} from '#root/root.js';
import {mjxRoot} from '#root/root.js';

/*
* The browser document (if any)
Expand Down Expand Up @@ -220,7 +220,7 @@ export namespace Loader {
return (script as HTMLScriptElement).src.replace(/\/[^\/]*$/, '');
}
}
return esRoot();
return mjxRoot();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion ts/components/mjs/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* @return {string} The MathJax component root directory
*/
export function esRoot(): string {
export function mjxRoot(): string {
return new URL(import.meta.url).pathname
.replace(/[cm]js\/components\/[cm]js\/root.js$/, (_) => 'bundle');
}
Expand Down
70 changes: 40 additions & 30 deletions ts/core/MmlTree/MmlNodes/mo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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 {OperatorList, OPTABLE, OPDEF, getRange, MMLSPACING} from '../OperatorDictionary.js';
import {unicodeChars, unicodeString} from '../../../util/string.js';

/*****************************************************************/
Expand Down Expand Up @@ -101,6 +101,11 @@ export class MmlMo extends AbstractMmlTokenNode {
']+$'
].join(''));

/**
* Pattern to use to identify a multiletter operator
*/
protected static opPattern = /^[a-zA-Z]{2,}$/;

/**
* Default map for remapping prime characters
*/
Expand Down Expand Up @@ -150,11 +155,7 @@ export class MmlMo extends AbstractMmlTokenNode {
*/
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.getOperatorDef(this.getText())[2];
}
return this._texClass;
}
Expand Down Expand Up @@ -348,35 +349,44 @@ export class MmlMo extends AbstractMmlTokenNode {
}

/**
* Set the attributes from the operator table
* get the operator definition from the operator table
*
* @param {string} mo The test of the mo element
* @param {string} mo The text of the mo element
*/
protected checkOperatorTable(mo: string) {
let [form1, form2, form3] = this.handleExplicitForm(this.getForms());
protected getOperatorDef(mo: string) {
const [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];
const CLASS = this.constructor as typeof MmlMo
const OPTABLE = CLASS.OPTABLE;
const 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 def;
}
const limits = this.attributes.get('movablelimits');
const isOP = !!mo.match(CLASS.opPattern);
if ((isOP || limits) && this.getProperty('texClass') === undefined) {
return OPDEF(1, 2, TEXCLASS.OP);
}
const range = getRange(mo);
const [l, r] = CLASS.MMLSPACING[range[2]];
return OPDEF(l, r, range[2]);
}

/**
* Set the attributes from the operator table
*
* @param {string} mo The text of the mo element
*/
protected checkOperatorTable(mo: string) {
const def = this.getOperatorDef(mo);
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;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions ts/core/MmlTree/OperatorDictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ export const RANGES: RangeDef[] = [
/**
* Get the Unicode range for the first character of a string
*
* @param {string} text The character to check
* @return {RangeDef|null} The range containing that character, or null
* @param {string} text The character to check
* @return {RangeDef} The range containing that character, or null
*/
export function getRange(text: string): RangeDef | null {
export function getRange(text: string): RangeDef {
const n = text.codePointAt(0);
for (const range of RANGES) {
if (n <= range[1]) {
Expand All @@ -149,7 +149,7 @@ export function getRange(text: string): RangeDef | null {
break;
}
}
return null;
return [0, 0, TEXCLASS.REL, 'mo'];
}

/**
Expand Down
32 changes: 0 additions & 32 deletions ts/input/mathml/mml3/cjs/xsltFilename.ts

This file was deleted.

32 changes: 0 additions & 32 deletions ts/input/mathml/mml3/mjs/xsltFilename.ts

This file was deleted.

7 changes: 5 additions & 2 deletions ts/input/mathml/mml3/mml3-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

import {MathDocument} from '../../../core/MathDocument.js';
import {xsltFilename} from '#mml3/xsltFilename.js';
import {mjxRoot} from '#root/root.js';

/**
* Create the transform function that uses Saxon-js to perform the
Expand All @@ -44,7 +44,10 @@ export function createTransform<N, T, D>(): (node: N, doc: MathDocument<N, T, D>
}
const Saxon = nodeRequire('saxon-js'); // dynamically load Saxon-JS.
const path = nodeRequire('path'); // use the real version from node.
const xslt = nodeRequire(xsltFilename(path)); // load the preprocessed stylesheet.
//
// Load the XSLT stylesheet
//
const xslt = nodeRequire(path.resolve(mjxRoot(), 'input', 'mml', 'extensions', 'mml3.sef.json'));
return (node: N, doc: MathDocument<N, T, D>) => {
const adaptor = doc.adaptor;
let mml = adaptor.outerHTML(node);
Expand Down
2 changes: 1 addition & 1 deletion ts/input/mathml/mml3/mml3.sef.json

Large diffs are not rendered by default.

Loading

0 comments on commit de08ad6

Please sign in to comment.