diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9029ac5eb..4b61fe351 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,7 +35,7 @@ importers: version: 5.7.5 terser-webpack-plugin: specifier: ^5.3.10 - version: 5.3.10(webpack@5.91.0(webpack-cli@5.1.4)) + version: 5.3.10(webpack@5.91.0) tslint: specifier: ^6.1.3 version: 6.1.3(typescript@5.4.5) @@ -1397,17 +1397,17 @@ snapshots: '@webassemblyjs/ast': 1.12.1 '@xtuc/long': 4.2.2 - '@webpack-cli/configtest@2.1.1(webpack-cli@5.1.4(webpack@5.91.0))(webpack@5.91.0(webpack-cli@5.1.4))': + '@webpack-cli/configtest@2.1.1(webpack-cli@5.1.4)(webpack@5.91.0)': dependencies: webpack: 5.91.0(webpack-cli@5.1.4) webpack-cli: 5.1.4(webpack@5.91.0) - '@webpack-cli/info@2.0.2(webpack-cli@5.1.4(webpack@5.91.0))(webpack@5.91.0(webpack-cli@5.1.4))': + '@webpack-cli/info@2.0.2(webpack-cli@5.1.4)(webpack@5.91.0)': dependencies: webpack: 5.91.0(webpack-cli@5.1.4) webpack-cli: 5.1.4(webpack@5.91.0) - '@webpack-cli/serve@2.0.5(webpack-cli@5.1.4(webpack@5.91.0))(webpack@5.91.0(webpack-cli@5.1.4))': + '@webpack-cli/serve@2.0.5(webpack-cli@5.1.4)(webpack@5.91.0)': dependencies: webpack: 5.91.0(webpack-cli@5.1.4) webpack-cli: 5.1.4(webpack@5.91.0) @@ -1897,7 +1897,7 @@ snapshots: internal-slot@1.0.5: dependencies: - get-intrinsic: 1.2.1 + get-intrinsic: 1.2.4 has: 1.0.3 side-channel: 1.0.4 @@ -1968,7 +1968,7 @@ snapshots: is-typed-array@1.1.12: dependencies: - which-typed-array: 1.1.11 + which-typed-array: 1.1.15 is-weakmap@2.0.1: {} @@ -2354,7 +2354,7 @@ snapshots: resolve: 2.0.0-next.5 string.prototype.trim: 1.2.8 - terser-webpack-plugin@5.3.10(webpack@5.91.0(webpack-cli@5.1.4)): + terser-webpack-plugin@5.3.10(webpack@5.91.0): dependencies: '@jridgewell/trace-mapping': 0.3.25 jest-worker: 27.5.1 @@ -2488,9 +2488,9 @@ snapshots: webpack-cli@5.1.4(webpack@5.91.0): dependencies: '@discoveryjs/json-ext': 0.5.7 - '@webpack-cli/configtest': 2.1.1(webpack-cli@5.1.4(webpack@5.91.0))(webpack@5.91.0(webpack-cli@5.1.4)) - '@webpack-cli/info': 2.0.2(webpack-cli@5.1.4(webpack@5.91.0))(webpack@5.91.0(webpack-cli@5.1.4)) - '@webpack-cli/serve': 2.0.5(webpack-cli@5.1.4(webpack@5.91.0))(webpack@5.91.0(webpack-cli@5.1.4)) + '@webpack-cli/configtest': 2.1.1(webpack-cli@5.1.4)(webpack@5.91.0) + '@webpack-cli/info': 2.0.2(webpack-cli@5.1.4)(webpack@5.91.0) + '@webpack-cli/serve': 2.0.5(webpack-cli@5.1.4)(webpack@5.91.0) colorette: 2.0.20 commander: 10.0.1 cross-spawn: 7.0.3 @@ -2532,11 +2532,10 @@ snapshots: neo-async: 2.6.2 schema-utils: 3.3.0 tapable: 2.2.1 - terser-webpack-plugin: 5.3.10(webpack@5.91.0(webpack-cli@5.1.4)) + terser-webpack-plugin: 5.3.10(webpack@5.91.0) watchpack: 2.4.1 - webpack-sources: 3.2.3 - optionalDependencies: webpack-cli: 5.1.4(webpack@5.91.0) + webpack-sources: 3.2.3 transitivePeerDependencies: - '@swc/core' - esbuild diff --git a/tests/length.test.js b/tests/length.test.js index 938de044e..fa06bbab9 100644 --- a/tests/length.test.js +++ b/tests/length.test.js @@ -1,18 +1,18 @@ import {jest} from '@jest/globals'; -import {ParseUtil} from '../mjs/input/tex/ParseUtil.js'; +import {UnitUtil} from '../mjs/input/tex/UnitUtil.js'; import * as Length from '../mjs/util/lengths.js'; // These methods will be rewritten into non-ParseUtil ones. function convertLength(unit, num) { - return ParseUtil.UNIT_CASES.get(unit) * (num); + return UnitUtil.UNIT_CASES.get(unit) * (num); } function matchDimension(str) { - return ParseUtil.matchDimen(str); + return UnitUtil.matchDimen(str); } function convertDimension(str) { - return ParseUtil.dimen2em(str); + return UnitUtil.dimen2em(str); } function convertLengthDim(str) { @@ -20,7 +20,7 @@ function convertLengthDim(str) { } function convertEm(num) { - return ParseUtil.em(num); + return UnitUtil.em(num); } describe('Length conversion', () => { @@ -125,7 +125,7 @@ describe.skip('Dimension conversion comparison', () => { // Useful for the IEEE case. describe('Adds pi unit', () => { - beforeAll(() => ParseUtil.UNIT_CASES.set('pi', 1 / 10)); + beforeAll(() => UnitUtil.UNIT_CASES.set('pi', 1 / 10)); it('pi', () => expect(convertLength('pi', 9)).toBe(0.9)); it('9pi', () => expect(matchDimension('9pi')).toEqual(['9', 'pi', 3])); it('10pi', () => expect(matchDimension('10pi')).toEqual(['10', 'pi', 4])); diff --git a/ts/input/tex/ColumnParser.ts b/ts/input/tex/ColumnParser.ts index 4547972ff..f7f85fd20 100644 --- a/ts/input/tex/ColumnParser.ts +++ b/ts/input/tex/ColumnParser.ts @@ -26,6 +26,7 @@ import TexParser from './TexParser.js'; import TexError from './TexError.js'; import {lookup} from '../../util/Options.js'; import {ParseUtil} from './ParseUtil.js'; +import { UnitUtil } from './UnitUtil.js'; /***********************************************************************/ @@ -233,7 +234,7 @@ export class ColumnParser { */ public getDimen(state: ColumnState) { const dim = this.getBraces(state) || ''; - if (!ParseUtil.matchDimen(dim)[0]) { + if (!UnitUtil.matchDimen(dim)[0]) { throw new TexError('MissingColumnDimOrUnits', 'Missing dimension or its units for %1 column declaration', state.c); } diff --git a/ts/input/tex/ParseUtil.ts b/ts/input/tex/ParseUtil.ts index 19c404f83..15aeab854 100644 --- a/ts/input/tex/ParseUtil.ts +++ b/ts/input/tex/ParseUtil.ts @@ -31,79 +31,7 @@ import TexParser from './TexParser.js'; import TexError from './TexError.js'; import {entities} from '../../util/Entities.js'; import {MmlMunderover} from '../../core/MmlTree/MmlNodes/munderover.js'; - - -class UnitMap extends Map { - - public num = '([-+]?([.,]\\d+|\\d+([.,]\\d*)?))'; - public unit = ''; - public dimenEnd = /./; - public dimenRest = /./; - - /** - * @override - */ - constructor(map: [string, number][]) { - super(map); - this.updateDimen(); - } - - /** - * Updates the regular expressions for the unit. - */ - private updateDimen() { - this.unit = `(${Array.from(this.keys()).join('|')})`; - this.dimenEnd = RegExp('^\\s*' + this.num + '\\s*' + this.unit + '\\s*$'); - this.dimenRest = RegExp('^\\s*' + this.num + '\\s*' + this.unit + ' ?'); - } - - /** - * @override - */ - public set(name: string, ems: number) { - super.set(name, ems); - this.updateDimen(); - return this; - } - - /** - * Retrieves conversion value for an existing dimension. If the dimension does - * not exist, `pt` is used, similar to TeX behaviour. However, no error is thrown. - * - * @override - */ - public get(name: string) { - return super.get(name) || super.get('pt'); - } - - /** - * @override - */ - public delete(name: string) { - if (super.delete(name)) { - this.updateDimen(); - return true; - } - return false; - } - -} - -const emPerInch = 7.2; -const pxPerInch = 72; - -/** - * Transforms mu dimension to em if necessary. - * @param {[string, string, number]} [value, unit, length] The dimension triple. - * @return {[string, string, number]} [value, unit, length] The transformed triple. - */ -function muReplace([value, unit, length]: [string, string, number]): [string, string, number] { - if (unit !== 'mu') { - return [value, unit, length]; - } - let em = ParseUtil.em(ParseUtil.UNIT_CASES.get(unit) * (parseFloat(value || '1'))); - return [em.slice(0, -2), 'em', length]; -} +import { UnitUtil } from './UnitUtil.js'; /** @@ -157,7 +85,7 @@ export const KeyValueTypes: {[name: string]: KeyValueType | ((data: any) => ), dimen: new KeyValueType( 'dimen', - (value) => ParseUtil.matchDimen(value)[0] !== null, + (value) => UnitUtil.matchDimen(value)[0] !== null, (value) => value ) }; @@ -271,62 +199,6 @@ function readValue(text: string, end: string[], export const ParseUtil = { - // Note, the following are TeX CM font values. - UNIT_CASES: new UnitMap([ - ['em', 1], - ['ex', .43], - ['pt', 1 / 10], // 10 pt to an em - ['pc', 1.2], // 12 pt to a pc - ['px', emPerInch / pxPerInch], - ['in', emPerInch], - ['cm', emPerInch / 2.54], // 2.54 cm to an inch - ['mm', emPerInch / 25.4], // 10 mm to a cm - ['mu', 1 / 18], - ]), - - - /** - * Matches for a dimension argument. - * @param {string} dim The argument. - * @param {boolean} rest Allow for trailing garbage in the dimension string. - * @return {[string, string, number]} The match result as (Anglosaxon) value, - * unit name, length of matched string. The latter is interesting in the - * case of trailing garbage. - */ - matchDimen( - dim: string, rest: boolean = false): [string, string, number] { - let match = dim.match(rest ? ParseUtil.UNIT_CASES.dimenRest : ParseUtil.UNIT_CASES.dimenEnd); - return match ? - muReplace([match[1].replace(/,/, '.'), match[4], match[0].length]) : - [null, null, 0]; - }, - - - /** - * Convert a dimension string into standard em dimension. - * @param {string} dim The attribute string. - * @return {number} The numerical value. - */ - dimen2em(dim: string): number { - let [value, unit] = ParseUtil.matchDimen(dim); - let m = parseFloat(value || '1'); - let factor = ParseUtil.UNIT_CASES.get(unit); - return factor ? factor * (m) : 0; - }, - - - /** - * Turns a number into an em value. - * @param {number} m The number. - * @return {string} The em dimension string. - */ - em(m: number): string { - if (Math.abs(m) < .0006) { - return '0em'; - } - return m.toFixed(3).replace(/\.?0+$/, '') + 'em'; - }, - // Above will move into lenghts // // Remainder: Parse Utililities @@ -337,7 +209,7 @@ export const ParseUtil = { * @return {string} The numbers with em units, separated by spaces. */ cols(...W: number[]): string { - return W.map(n => ParseUtil.em(n)).join(' '); + return W.map(n => UnitUtil.em(n)).join(' '); }, @@ -638,23 +510,6 @@ export const ParseUtil = { } }, - /** - * Trim spaces from a string. - * @param {string} text The string to clean. - * @return {string} The string with leading and trailing whitespace removed. - */ - trimSpaces(text: string): string { - if (typeof(text) !== 'string') { - return text; - } - let TEXT = text.trim(); - if (TEXT.match(/\\$/) && text.match(/ $/)) { - TEXT += ' '; - } - return TEXT; - }, - - /** * Sets alignment in array definitions. * @param {ArrayItem} array The array item. @@ -665,7 +520,7 @@ export const ParseUtil = { setArrayAlign(array: ArrayItem, align: string, parser?: TexParser): ArrayItem { // @test Array1, Array2, Array Test if (!parser) { - align = ParseUtil.trimSpaces(align || ''); + align = UnitUtil.trimSpaces(align || ''); } if (align === 't') { array.arraydef.align = 'baseline 1'; diff --git a/ts/input/tex/TexParser.ts b/ts/input/tex/TexParser.ts index 06fce8a2f..c019965e5 100644 --- a/ts/input/tex/TexParser.ts +++ b/ts/input/tex/TexParser.ts @@ -23,7 +23,7 @@ * @author v.sorge@mathjax.org (Volker Sorge) */ -import {ParseUtil} from './ParseUtil.js'; +import {UnitUtil} from './UnitUtil.js'; import {HandlerType} from './MapHandler.js'; import Stack from './Stack.js'; import StackItemFactory from './StackItemFactory.js'; @@ -415,7 +415,7 @@ export default class TexParser { public GetDimen(name: string): string { if (this.GetNext() === '{') { let dimen = this.GetArgument(name); - let [value, unit] = ParseUtil.matchDimen(dimen); + let [value, unit] = UnitUtil.matchDimen(dimen); if (value) { // @test Raise In Line, Lower 2, (Raise|Lower) Negative return value + unit; @@ -423,7 +423,7 @@ export default class TexParser { } else { // @test Above, Raise, Lower, Modulo, Above With Delims let dimen = this.string.slice(this.i); - let [value, unit, length] = ParseUtil.matchDimen(dimen, true); + let [value, unit, length] = UnitUtil.matchDimen(dimen, true); if (value) { this.i += length; return value + unit; @@ -498,7 +498,7 @@ export default class TexParser { * @return {string} The delimiter. */ public GetDelimiterArg(name: string): string { - let c = ParseUtil.trimSpaces(this.GetArgument(name)); + let c = UnitUtil.trimSpaces(this.GetArgument(name)); if (c === '') { return null; } diff --git a/ts/input/tex/UnitUtil.ts b/ts/input/tex/UnitUtil.ts new file mode 100644 index 000000000..1aff2ef77 --- /dev/null +++ b/ts/input/tex/UnitUtil.ts @@ -0,0 +1,174 @@ +/************************************************************* + * + * Copyright (c) 2009-2024 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 Utilities for units. + * + * @author v.sorge@mathjax.org (Volker Sorge) + */ + +class UnitMap { + + public num = '([-+]?([.,]\\d+|\\d+([.,]\\d*)?))'; + public unit = ''; + public dimenEnd = /./; + public dimenRest = /./; + + private map:Map; + + /** + * @override + */ + constructor(map: [string, number][]) { + this.map = new Map(map); + this.updateDimen(); + } + + /** + * Updates the regular expressions for the unit. + */ + private updateDimen() { + this.unit = `(${Array.from(this.map.keys()).join('|')})`; + this.dimenEnd = RegExp('^\\s*' + this.num + '\\s*' + this.unit + '\\s*$'); + this.dimenRest = RegExp('^\\s*' + this.num + '\\s*' + this.unit + ' ?'); + } + + /** + * @override + */ + public set(name: string, ems: number) { + this.map.set(name, ems); + this.updateDimen(); + return this; + } + + /** + * Retrieves conversion value for an existing dimension. If the dimension does + * not exist, `pt` is used, similar to TeX behaviour. However, no error is thrown. + * + * @override + */ + public get(name: string) { + return this.map.get(name) || this.map.get('pt'); + } + + /** + * @override + */ + public delete(name: string) { + if (this.map.delete(name)) { + this.updateDimen(); + return true; + } + return false; + } + +} + +const emPerInch = 7.2; +const pxPerInch = 72; + +/** + * Transforms mu dimension to em if necessary. + * @param {[string, string, number]} [value, unit, length] The dimension triple. + * @return {[string, string, number]} [value, unit, length] The transformed triple. + */ +function muReplace([value, unit, length]: [string, string, number]): [string, string, number] { + if (unit !== 'mu') { + return [value, unit, length]; + } + let em = UnitUtil.em(UnitUtil.UNIT_CASES.get(unit) * (parseFloat(value || '1'))); + return [em.slice(0, -2), 'em', length]; +} + + +export const UnitUtil = { + + // Note, the following are TeX CM font values. + UNIT_CASES: new UnitMap([ + ['em', 1], + ['ex', .43], + ['pt', 1 / 10], // 10 pt to an em + ['pc', 1.2], // 12 pt to a pc + ['px', emPerInch / pxPerInch], + ['in', emPerInch], + ['cm', emPerInch / 2.54], // 2.54 cm to an inch + ['mm', emPerInch / 25.4], // 10 mm to a cm + ['mu', 1 / 18], + ]), + + + /** + * Matches for a dimension argument. + * @param {string} dim The argument. + * @param {boolean} rest Allow for trailing garbage in the dimension string. + * @return {[string, string, number]} The match result as (Anglosaxon) value, + * unit name, length of matched string. The latter is interesting in the + * case of trailing garbage. + */ + matchDimen( + dim: string, rest: boolean = false): [string, string, number] { + let match = dim.match(rest ? UnitUtil.UNIT_CASES.dimenRest : UnitUtil.UNIT_CASES.dimenEnd); + return match ? + muReplace([match[1].replace(/,/, '.'), match[4], match[0].length]) : + [null, null, 0]; + }, + + + /** + * Convert a dimension string into standard em dimension. + * @param {string} dim The attribute string. + * @return {number} The numerical value. + */ + dimen2em(dim: string): number { + let [value, unit] = UnitUtil.matchDimen(dim); + let m = parseFloat(value || '1'); + let factor = UnitUtil.UNIT_CASES.get(unit); + return factor ? factor * (m) : 0; + }, + + + /** + * Turns a number into an em value. + * @param {number} m The number. + * @return {string} The em dimension string. + */ + em(m: number): string { + if (Math.abs(m) < .0006) { + return '0em'; + } + return m.toFixed(3).replace(/\.?0+$/, '') + 'em'; + }, + + /** + * Trim spaces from a string. + * @param {string} text The string to clean. + * @return {string} The string with leading and trailing whitespace removed. + */ + trimSpaces(text: string): string { + if (typeof(text) !== 'string') { + return text; + } + let TEXT = text.trim(); + if (TEXT.match(/\\$/) && text.match(/ $/)) { + TEXT += ' '; + } + return TEXT; + } + +} diff --git a/ts/input/tex/ams/AmsMethods.ts b/ts/input/tex/ams/AmsMethods.ts index 4caa82079..068197e40 100644 --- a/ts/input/tex/ams/AmsMethods.ts +++ b/ts/input/tex/ams/AmsMethods.ts @@ -26,6 +26,7 @@ import {StackItem} from '../StackItem.js'; import {ParseMethod} from '../Types.js'; import {ParseUtil} from '../ParseUtil.js'; +import { UnitUtil } from '../UnitUtil.js'; import ParseMethods from '../ParseMethods.js'; import NodeUtil from '../NodeUtil.js'; import {TexConstant} from '../TexConstants.js'; @@ -213,7 +214,7 @@ export const NEW_OPS = 'ams-declare-ops'; */ AmsMethods.HandleDeclareOp = function (parser: TexParser, name: string) { let star = (parser.GetStar() ? '*' : ''); - let cs = ParseUtil.trimSpaces(parser.GetArgument(name)); + let cs = UnitUtil.trimSpaces(parser.GetArgument(name)); if (cs.charAt(0) === '\\') { cs = cs.substring(1); } @@ -235,7 +236,7 @@ AmsMethods.HandleOperatorName = function(parser: TexParser, name: string) { // // Parse the argument using operator letters and grouping multiple letters. // - let op = ParseUtil.trimSpaces(parser.GetArgument(name)); + let op = UnitUtil.trimSpaces(parser.GetArgument(name)); let mml = new TexParser(op, { ...parser.stack.env, font: TexConstant.Variant.NORMAL, @@ -424,7 +425,7 @@ AmsMethods.MultiIntegral = function(parser: TexParser, name: string, */ AmsMethods.xArrow = function(parser: TexParser, name: string, chr: number, l: number, r: number) { - let def = {width: '+' + ParseUtil.em((l + r) / 18), lspace: ParseUtil.em(l / 18)}; + let def = {width: '+' + UnitUtil.em((l + r) / 18), lspace: UnitUtil.em(l / 18)}; let bot = parser.GetBrackets(name); let first = parser.ParseArg(name); let dstrut = parser.create('node', 'mspace', [], {depth: '.2em'}); @@ -483,7 +484,7 @@ AmsMethods.HandleShove = function(parser: TexParser, _name: string, * @param {string} name The macro name. */ AmsMethods.CFrac = function(parser: TexParser, name: string) { - let lr = ParseUtil.trimSpaces(parser.GetBrackets(name, '')); + let lr = UnitUtil.trimSpaces(parser.GetBrackets(name, '')); let num = parser.GetArgument(name); let den = parser.GetArgument(name); let lrMap: {[key: string]: string} = { @@ -528,7 +529,7 @@ AmsMethods.Genfrac = function(parser: TexParser, name: string, left: string, thick = parser.GetArgument(name); } if (style == null) { // @test Genfrac - style = ParseUtil.trimSpaces(parser.GetArgument(name)); + style = UnitUtil.trimSpaces(parser.GetArgument(name)); } let num = parser.ParseArg(name); let den = parser.ParseArg(name); @@ -585,7 +586,7 @@ AmsMethods.HandleTag = function(parser: TexParser, name: string) { throw new TexError('MultipleCommand', 'Multiple %1', parser.currentCS); } let star = parser.GetStar(); - let tagId = ParseUtil.trimSpaces(parser.GetArgument(name)); + let tagId = UnitUtil.trimSpaces(parser.GetArgument(name)); parser.tags.tag(tagId, star); parser.Push(parser.itemFactory.create('null')); }; diff --git a/ts/input/tex/base/BaseItems.ts b/ts/input/tex/base/BaseItems.ts index add187a29..7932c78b0 100644 --- a/ts/input/tex/base/BaseItems.ts +++ b/ts/input/tex/base/BaseItems.ts @@ -33,6 +33,7 @@ import {MmlMunderover} from '../../../core/MmlTree/MmlNodes/munderover.js'; import TexParser from '../TexParser.js'; import TexError from '../TexError.js'; import {ParseUtil} from '../ParseUtil.js'; +import { UnitUtil } from '../UnitUtil.js'; import NodeUtil from '../NodeUtil.js'; import {Property, PropertyList} from '../../../core/Tree/Node.js'; import StackItemFactory from '../StackItemFactory.js'; @@ -1376,15 +1377,15 @@ export class ArrayItem extends BaseItem { const rows = (this.arraydef['rowspacing'] as string).split(/ /); if (!this.getProperty('rowspacing')) { // @test Array Custom Linebreak - let dimem = ParseUtil.dimen2em(rows[0]); + let dimem = UnitUtil.dimen2em(rows[0]); this.setProperty('rowspacing', dimem); } const rowspacing = this.getProperty('rowspacing') as number; while (rows.length < this.table.length) { - rows.push(ParseUtil.em(rowspacing)); + rows.push(UnitUtil.em(rowspacing)); } - rows[this.table.length - 1] = ParseUtil.em( - Math.max(0, rowspacing + ParseUtil.dimen2em(spacing))); + rows[this.table.length - 1] = UnitUtil.em( + Math.max(0, rowspacing + UnitUtil.dimen2em(spacing))); this.arraydef['rowspacing'] = rows.join(' '); } } diff --git a/ts/input/tex/base/BaseMethods.ts b/ts/input/tex/base/BaseMethods.ts index 034aa8d5c..83f60dcaa 100644 --- a/ts/input/tex/base/BaseMethods.ts +++ b/ts/input/tex/base/BaseMethods.ts @@ -31,6 +31,7 @@ import TexError from '../TexError.js'; import TexParser from '../TexParser.js'; import {TexConstant} from '../TexConstants.js'; import {ParseUtil} from '../ParseUtil.js'; +import {UnitUtil} from '../UnitUtil.js'; import {PropertyList} from '../../../core/Tree/Node.js'; import {MmlNode, TEXCLASS} from '../../../core/MmlTree/MmlNode.js'; import {MmlMo} from '../../../core/MmlTree/MmlNodes/mo.js'; @@ -980,7 +981,7 @@ BaseMethods.Phantom = function(parser: TexParser, name: string, v: string, h: st */ BaseMethods.Smash = function(parser: TexParser, name: string) { // @test Smash, Smash Top, Smash Bottom - const bt = ParseUtil.trimSpaces(parser.GetBrackets(name, '')); + const bt = UnitUtil.trimSpaces(parser.GetBrackets(name, '')); const smash = parser.create('node', 'mpadded', [parser.ParseArg(name)]); // TEMP: Changes here: switch (bt) { @@ -1416,7 +1417,7 @@ BaseMethods.Entry = function(parser: TexParser, name: string) { // i >= parser.i const text = str.substring(parser.i, i); if (!text.match(/^\s*\\text[^a-zA-Z]/) || close !== text.replace(/\s+$/, '').length - 1) { - const internal = ParseUtil.internalMath(parser, ParseUtil.trimSpaces(text), 0); + const internal = ParseUtil.internalMath(parser, UnitUtil.trimSpaces(text), 0); parser.PushAll(internal); parser.i = i; } @@ -1451,7 +1452,7 @@ BaseMethods.CrLaTeX = function(parser: TexParser, name: string, nobrackets: bool } if (parser.string.charAt(parser.i) === '[') { let dim = parser.GetBrackets(name, ''); - let [value, unit, ] = ParseUtil.matchDimen(dim); + let [value, unit, ] = UnitUtil.matchDimen(dim); // @test Custom Linebreak if (dim && !value) { // @test Dimension Error @@ -1672,9 +1673,9 @@ BaseMethods.IndentAlign = function (parser: TexParser, begin: StackItem) { const first = parser.GetBrackets(name, ''); let shift = parser.GetBrackets(name, ''); const last = parser.GetBrackets(name, ''); - if ((first && !ParseUtil.matchDimen(first)[0]) || - (shift && !ParseUtil.matchDimen(shift)[0]) || - (last && !ParseUtil.matchDimen(last)[0])) { + if ((first && !UnitUtil.matchDimen(first)[0]) || + (shift && !UnitUtil.matchDimen(shift)[0]) || + (last && !UnitUtil.matchDimen(last)[0])) { throw new TexError('BracketMustBeDimension', 'Bracket argument to %1 must be a dimension', name); } // diff --git a/ts/input/tex/bussproofs/BussproofsMethods.ts b/ts/input/tex/bussproofs/BussproofsMethods.ts index d60438409..603c3bb87 100644 --- a/ts/input/tex/bussproofs/BussproofsMethods.ts +++ b/ts/input/tex/bussproofs/BussproofsMethods.ts @@ -27,6 +27,7 @@ import {ParseMethod} from '../Types.js'; import TexError from '../TexError.js'; import TexParser from '../TexParser.js'; import {ParseUtil} from '../ParseUtil.js'; +import {UnitUtil} from '../UnitUtil.js'; import {StackItem} from '../StackItem.js'; import {MmlNode} from '../../../core/MmlTree/MmlNode.js'; import * as BussproofsUtil from './BussproofsUtil.js'; @@ -80,7 +81,7 @@ BussproofsMethods.Axiom = function(parser: TexParser, name: string) { */ const paddedContent = function(parser: TexParser, content: string): MmlNode { // Add padding on either site. - let nodes = ParseUtil.internalMath(parser, ParseUtil.trimSpaces(content), 0); + let nodes = ParseUtil.internalMath(parser, UnitUtil.trimSpaces(content), 0); if (!nodes[0].childNodes[0].childNodes.length) { return parser.create('node', 'mrow', []); } diff --git a/ts/input/tex/bussproofs/BussproofsUtil.ts b/ts/input/tex/bussproofs/BussproofsUtil.ts index f49a41faf..e238e1647 100644 --- a/ts/input/tex/bussproofs/BussproofsUtil.ts +++ b/ts/input/tex/bussproofs/BussproofsUtil.ts @@ -25,7 +25,7 @@ import ParseOptions from '../ParseOptions.js'; import NodeUtil from '../NodeUtil.js'; -import {ParseUtil} from '../ParseUtil.js'; +import {UnitUtil} from '../UnitUtil.js'; import {MmlNode} from '../../../core/MmlTree/MmlNode.js'; import {Property} from '../../../core/Tree/Node.js'; @@ -270,12 +270,12 @@ let addSpace = function(config: ParseOptions, inf: MmlNode, if (NodeUtil.isType(mspace, 'mspace')) { NodeUtil.setAttribute( mspace, 'width', - ParseUtil.em(ParseUtil.dimen2em( + UnitUtil.em(UnitUtil.dimen2em( NodeUtil.getAttribute(mspace, 'width') as string) + space)); return; } mspace = config.nodeFactory.create('node', 'mspace', [], - {width: ParseUtil.em(space)}); + {width: UnitUtil.em(space)}); if (right) { inf.appendChild(mspace); return; @@ -362,7 +362,7 @@ let adjustSequents = function(config: ParseOptions) { const addSequentSpace = function(config: ParseOptions, sequent: MmlNode, position: number, direction: string, width: number) { let mspace = config.nodeFactory.create('node', 'mspace', [], - {width: ParseUtil.em(width)}); + {width: UnitUtil.em(width)}); if (direction === 'left') { let row = sequent.childNodes[position].childNodes[0]; mspace.parent = row; diff --git a/ts/input/tex/mathtools/MathtoolsMethods.ts b/ts/input/tex/mathtools/MathtoolsMethods.ts index 856130ba1..f2b90e1ad 100644 --- a/ts/input/tex/mathtools/MathtoolsMethods.ts +++ b/ts/input/tex/mathtools/MathtoolsMethods.ts @@ -25,6 +25,7 @@ import {ArrayItem, EqnArrayItem} from '../base/BaseItems.js'; import {StackItem} from '../StackItem.js'; import {ParseUtil} from '../ParseUtil.js'; +import {UnitUtil} from '../UnitUtil.js'; import {ParseMethod, ParseResult} from '../Types.js'; import {AmsMethods} from '../ams/AmsMethods.js'; import BaseMethods from '../base/BaseMethods.js'; @@ -74,7 +75,7 @@ export const MathtoolsMethods: Record = { align = parser.GetBrackets(`\\begin{${begin.getName()}}`, parser.options.mathtools['smallmatrix-align']); } return MathtoolsMethods.Array( - parser, begin, open, close, align, ParseUtil.em(1 / 3), '.2em', 'S', 1 + parser, begin, open, close, align, UnitUtil.em(1 / 3), '.2em', 'S', 1 ); }, @@ -100,7 +101,7 @@ export const MathtoolsMethods: Record = { } else { width = arg; } - if (width && !ParseUtil.matchDimen(width)[0]) { + if (width && !UnitUtil.matchDimen(width)[0]) { throw new TexError('BadWidth', 'Width for %1 must be a dimension', name); } } diff --git a/ts/input/tex/mathtools/MathtoolsUtil.ts b/ts/input/tex/mathtools/MathtoolsUtil.ts index 790a3d775..e0ce800c0 100644 --- a/ts/input/tex/mathtools/MathtoolsUtil.ts +++ b/ts/input/tex/mathtools/MathtoolsUtil.ts @@ -21,7 +21,7 @@ */ import {EqnArrayItem} from '../base/BaseItems.js'; -import {ParseUtil} from '../ParseUtil.js'; +import {UnitUtil} from '../UnitUtil.js'; import TexParser from '../TexParser.js'; import TexError from '../TexError.js'; import {CommandMap} from '../TokenMap.js'; @@ -98,10 +98,10 @@ export const MathtoolsUtil = { if (!mtable.isKind('mtable')) return; let rowspacing = mtable.attributes.get('rowspacing') as string; if (rowspacing) { - const add = ParseUtil.dimen2em(spread); + const add = UnitUtil.dimen2em(spread); rowspacing = rowspacing .split(/ /) - .map(s => ParseUtil.em(Math.max(0, ParseUtil.dimen2em(s) + add))) + .map(s => UnitUtil.em(Math.max(0, UnitUtil.dimen2em(s) + add))) .join(' '); } else { rowspacing = spread; @@ -133,7 +133,7 @@ export const MathtoolsUtil = { * @return {MmlNode} The parsed MML version of the argument. */ getScript(parser: TexParser, name: string, pos: string): MmlNode { - let arg = ParseUtil.trimSpaces(parser.GetArgument(name)); + let arg = UnitUtil.trimSpaces(parser.GetArgument(name)); if (arg === '') { return parser.create('node', 'none'); } diff --git a/ts/input/tex/newcommand/NewcommandMethods.ts b/ts/input/tex/newcommand/NewcommandMethods.ts index 82736655b..b05a2275f 100644 --- a/ts/input/tex/newcommand/NewcommandMethods.ts +++ b/ts/input/tex/newcommand/NewcommandMethods.ts @@ -30,6 +30,7 @@ import * as sm from '../TokenMap.js'; import {Token, Macro} from '../Token.js'; import BaseMethods from '../base/BaseMethods.js'; import {ParseUtil} from '../ParseUtil.js'; +import {UnitUtil} from '../UnitUtil.js'; import {StackItem} from '../StackItem.js'; import NewcommandUtil from './NewcommandUtil.js'; @@ -60,7 +61,7 @@ NewcommandMethods.NewCommand = function(parser: TexParser, name: string) { */ NewcommandMethods.NewEnvironment = function(parser: TexParser, name: string) { // @test Newenvironment Empty, Newenvironment Content - let env = ParseUtil.trimSpaces(parser.GetArgument(name)); + let env = UnitUtil.trimSpaces(parser.GetArgument(name)); let n = NewcommandUtil.GetArgCount(parser, name); let opt = parser.GetBrackets(name); let bdef = parser.GetArgument(name); diff --git a/ts/input/tex/newcommand/NewcommandUtil.ts b/ts/input/tex/newcommand/NewcommandUtil.ts index b53125913..36bc39690 100644 --- a/ts/input/tex/newcommand/NewcommandUtil.ts +++ b/ts/input/tex/newcommand/NewcommandUtil.ts @@ -23,7 +23,7 @@ */ -import {ParseUtil} from '../ParseUtil.js'; +import {UnitUtil} from '../UnitUtil.js'; import TexError from '../TexError.js'; import TexParser from '../TexParser.js'; import {Macro, Token} from '../Token.js'; @@ -47,7 +47,7 @@ namespace NewcommandUtil { throw new TexError('MissingCS', '%1 must be followed by a control sequence', cmd); } - let cs = ParseUtil.trimSpaces(parser.GetArgument(cmd)); + let cs = UnitUtil.trimSpaces(parser.GetArgument(cmd)); return cs.substring(1); } @@ -58,7 +58,7 @@ namespace NewcommandUtil { * @return {string} The control sequence. */ export function GetCsNameArgument(parser: TexParser, name: string): string { - let cs = ParseUtil.trimSpaces(parser.GetArgument(name)); + let cs = UnitUtil.trimSpaces(parser.GetArgument(name)); if (cs.charAt(0) === '\\') { // @test Newcommand Simple cs = cs.substring(1); @@ -82,7 +82,7 @@ namespace NewcommandUtil { if (n) { // @test Newcommand Optional, Newcommand Arg, Newcommand Arg Optional // @test Newenvironment Optional, Newenvironment Arg Optional - n = ParseUtil.trimSpaces(n); + n = UnitUtil.trimSpaces(n); if (!n.match(/^[0-9]+$/)) { // @test Illegal Argument Number throw new TexError('IllegalParamNumber', diff --git a/ts/input/tex/unicode/UnicodeConfiguration.ts b/ts/input/tex/unicode/UnicodeConfiguration.ts index c7d959c9f..9f753b71c 100644 --- a/ts/input/tex/unicode/UnicodeConfiguration.ts +++ b/ts/input/tex/unicode/UnicodeConfiguration.ts @@ -28,7 +28,7 @@ import TexParser from '../TexParser.js'; import TexError from '../TexError.js'; import {CommandMap} from '../TokenMap.js'; import {ParseMethod} from '../Types.js'; -import {ParseUtil} from '../ParseUtil.js'; +import {UnitUtil} from '../UnitUtil.js'; import NodeUtil from '../NodeUtil.js'; import {numeric} from '../../../util/Entities.js'; import {Other} from '../base/BaseConfiguration.js'; @@ -59,7 +59,7 @@ UnicodeMethods.Unicode = function(parser: TexParser, name: string) { if (font.match(/;/)) { throw new TexError('BadFont', 'Font name for %1 can\'t contain semicolons', parser.currentCS); } - let n = ParseUtil.trimSpaces(parser.GetArgument(name)).replace(/^0x/, 'x'); + let n = UnitUtil.trimSpaces(parser.GetArgument(name)).replace(/^0x/, 'x'); if (!n.match(/^(x[0-9A-Fa-f]+|[0-9]+)$/)) { throw new TexError('BadUnicode', 'Argument to %1 must be a number', parser.currentCS); }