Skip to content

Commit 2e5d6a1

Browse files
committed
Merge branch 'origin/cancel_package' into beta.2
2 parents 9e25637 + 9138604 commit 2e5d6a1

File tree

4 files changed

+201
-0
lines changed

4 files changed

+201
-0
lines changed

lib/TeX-lab.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import '../mathjax3/input/tex/braket/BraketConfiguration.js';
1818
import '../mathjax3/input/tex/mhchem/MhchemConfiguration.js';
1919
import '../mathjax3/input/tex/physics/PhysicsConfiguration.js';
2020
import '../mathjax3/input/tex/verb/VerbConfiguration.js';
21+
import '../mathjax3/input/tex/cancel/CancelConfiguration.js';
22+
import '../mathjax3/input/tex/enclose/EncloseConfiguration.js';
2123

2224
const jax = {
2325
TeX: new TeX(),

mathjax3-ts/input/tex/ParseUtil.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,30 @@ namespace ParseUtil {
470470
return (font ? {mathvariant: font} : {});
471471
};
472472

473+
474+
/**
475+
* Splits a package option list of the form [x=y,z=1] into an attribute list
476+
* of the form {x: y, z: 1}.
477+
* @param {string} attrib The attributes of the package.
478+
* @param {{[key: string]: number}?} allowed A list of allowed options.
479+
* @return {EnvList} The attribute list.
480+
*/
481+
export function splitPackageOptions(attrib: string, allowed: {[key: string]: number} = {}): EnvList {
482+
let def: EnvList = {};
483+
if (attrib !== '') {
484+
const attr = attrib.replace(/ /g, '').split(/,/);
485+
for (let i = 0, m = attr.length; i < m; i++) {
486+
const keyvalue = attr[i].split(/[:=]/);
487+
if (allowed[keyvalue[0]]) {
488+
let value = keyvalue[1];
489+
def[keyvalue[0]] = (value === 'true') ? true :
490+
(value === 'false') ? false : value;
491+
}
492+
}
493+
}
494+
return def;
495+
}
496+
473497
}
474498

475499
export default ParseUtil;
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*************************************************************
2+
*
3+
* Copyright (c) 2018 The MathJax Consortium
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
/**
20+
* @fileoverview Configuration file for the cancel package.
21+
*
22+
* @author [email protected] (Volker Sorge)
23+
*/
24+
25+
import {Configuration} from '../Configuration.js';
26+
import TexParser from '../TexParser.js';
27+
import {TexConstant} from '../TexConstants.js';
28+
import {CommandMap} from '../SymbolMap.js';
29+
import {ParseMethod} from '../Types.js';
30+
import ParseUtil from '../ParseUtil.js';
31+
32+
33+
/**
34+
* The attributes allowed in \enclose{notation}[attributes]{math}
35+
* @type {{[key: string]: number}}
36+
*/
37+
const ALLOWED: {[key: string]: number} = {
38+
color: 1, mathcolor: 1,
39+
background: 1, mathbackground: 1,
40+
padding: 1,
41+
thickness: 1
42+
};
43+
44+
45+
// Namespace
46+
export let CancelMethods: Record<string, ParseMethod> = {};
47+
48+
49+
/**
50+
* Parse function for cancel macros of the form \(b|x)cancel[attributes]{math}
51+
* @param {TexParser} parser The current tex parser.
52+
* @param {string} name The name of the calling macro.
53+
* @param {string} notation The type of cancel notation to use.
54+
*/
55+
CancelMethods.Cancel = function(parser: TexParser, name: string, notation: string) {
56+
const attr = parser.GetBrackets(name, '');
57+
const math = parser.ParseArg(name);
58+
const def = ParseUtil.splitPackageOptions(attr, ALLOWED);
59+
def['notation'] = notation;
60+
parser.Push(parser.create('node', 'menclose', [math], def));
61+
};
62+
63+
64+
/**
65+
* Parse function implementing \cancelto{value}[attributes]{math}
66+
* @param {TexParser} parser The current tex parser.
67+
* @param {string} name The name of the calling macro.
68+
* @param {string} notation The type of cancel notation to use.
69+
*/
70+
71+
CancelMethods.CancelTo = function(parser: TexParser, name: string) {
72+
const attr = parser.GetBrackets(name, '');
73+
let value = parser.ParseArg(name);
74+
const math = parser.ParseArg(name);
75+
const def = ParseUtil.splitPackageOptions(attr, ALLOWED);
76+
def ['notation'] = TexConstant.Notation.UPDIAGONALSTRIKE + ' ' +
77+
TexConstant.Notation.UPDIAGONALARROW;
78+
value = parser.create('node', 'mpadded', [value],
79+
{depth: '-.1em', height: ' + .1em', voffset: '.1em'});
80+
parser.Push(parser.create('node', 'msup',
81+
[parser.create('node', 'menclose', [math], def), value]));
82+
};
83+
84+
85+
new CommandMap('cancel', {
86+
cancel: ['Cancel', TexConstant.Notation.UPDIAGONALSTRIKE],
87+
bcancel: ['Cancel', TexConstant.Notation.DOWNDIAGONALSTRIKE],
88+
xcancel: ['Cancel', TexConstant.Notation.UPDIAGONALSTRIKE + ' ' +
89+
TexConstant.Notation.DOWNDIAGONALSTRIKE],
90+
cancelto: 'CancelTo'
91+
}, CancelMethods);
92+
93+
94+
export const CancelConfiguration = Configuration.create(
95+
'cancel', {handler: {macro: ['cancel']}}
96+
);
97+
98+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*************************************************************
2+
*
3+
* Copyright (c) 2018 The MathJax Consortium
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
/**
20+
* @fileoverview Configuration file for the enclose package.
21+
*
22+
* @author [email protected] (Volker Sorge)
23+
*/
24+
25+
import {Configuration} from '../Configuration.js';
26+
import TexParser from '../TexParser.js';
27+
import {TexConstant} from '../TexConstants.js';
28+
import {CommandMap} from '../SymbolMap.js';
29+
import {ParseMethod} from '../Types.js';
30+
import ParseUtil from '../ParseUtil.js';
31+
32+
33+
/**
34+
* The attributes allowed in \enclose{notation}[attributes]{math}
35+
* @type {{[key: string]: number}}
36+
*/
37+
const ALLOWED: {[key: string]: number} = {
38+
arrow: 1,
39+
color: 1, mathcolor: 1,
40+
background: 1, mathbackground: 1,
41+
padding: 1,
42+
thickness: 1
43+
};
44+
45+
46+
// Namespace
47+
export let EncloseMethods: Record<string, ParseMethod> = {};
48+
49+
50+
/**
51+
* Implements \enclose{notation}[attr]{math}
52+
* (create <menclose notation="notation">math</menclose>)
53+
* @param {TexParser} parser The current tex parser.
54+
* @param {string} name The name of the calling macro.
55+
*/
56+
EncloseMethods.Enclose = function(parser: TexParser, name: string) {
57+
let notation = parser.GetArgument(name).replace(/,/g, ' ');
58+
const attr = parser.GetBrackets(name, '');
59+
const math = parser.ParseArg(name);
60+
const def = ParseUtil.splitPackageOptions(attr, ALLOWED);
61+
def.notation = notation;
62+
if (def.arrow) {
63+
def.notation += ' updiagonalarrow';
64+
delete def.arrow;
65+
}
66+
parser.Push(parser.create('node', 'menclose', [math], def));
67+
};
68+
69+
70+
new CommandMap('enclose', {enclose: 'Enclose'}, EncloseMethods);
71+
72+
73+
export const EncloseConfiguration = Configuration.create(
74+
'enclose', {handler: {macro: ['enclose']}}
75+
);
76+
77+

0 commit comments

Comments
 (0)