Skip to content

Commit e2e10b8

Browse files
authored
Merge pull request #713 from mathjax/centernot-package
Add centernot package
2 parents 27ea029 + e66a4c5 commit e2e10b8

7 files changed

Lines changed: 103 additions & 0 deletions

File tree

components/src/dependencies.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const dependencies = {
1313
'[tex]/braket': ['input/tex-base'],
1414
'[tex]/bussproofs': ['input/tex-base'],
1515
'[tex]/cancel': ['input/tex-base', '[tex]/enclose'],
16+
'[tex]/centernot': ['input/tex-base'],
1617
'[tex]/color': ['input/tex-base'],
1718
'[tex]/colorv2': ['input/tex-base'],
1819
'[tex]/colortbl': ['input/tex-base', '[tex]/color'],
@@ -47,6 +48,7 @@ const allPackages = [
4748
'[tex]/braket',
4849
'[tex]/bussproofs',
4950
'[tex]/cancel',
51+
'[tex]/centernot',
5052
'[tex]/color',
5153
'[tex]/colortbl',
5254
'[tex]/configmacros',
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"component": "input/tex/extensions/centernot",
3+
"targets": ["input/tex/centernot"]
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './lib/centernot.js';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const PACKAGE = require('../../../../../webpack.common.js');
2+
3+
module.exports = PACKAGE(
4+
'input/tex/extensions/centernot', // the package to build
5+
'../../../../../../js', // location of the MathJax js library
6+
[ // packages to link to
7+
'components/src/input/tex-base/lib',
8+
'components/src/core/lib'
9+
],
10+
__dirname // our directory
11+
);

components/src/source.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const source = {
1616
'[tex]/braket': `${src}/input/tex/extensions/braket/braket.js`,
1717
'[tex]/bussproofs': `${src}/input/tex/extensions/bussproofs/bussproofs.js`,
1818
'[tex]/cancel': `${src}/input/tex/extensions/cancel/cancel.js`,
19+
'[tex]/centernot': `${src}/input/tex/extensions/centernot/centernot.js`,
1920
'[tex]/color': `${src}/input/tex/extensions/color/color.js`,
2021
'[tex]/colorv2': `${src}/input/tex/extensions/colorv2/colorv2.js`,
2122
'[tex]/configmacros': `${src}/input/tex/extensions/configmacros/configmacros.js`,

ts/input/tex/AllPackages.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import './boldsymbol/BoldsymbolConfiguration.js';
3030
import './braket/BraketConfiguration.js';
3131
import './bussproofs/BussproofsConfiguration.js';
3232
import './cancel/CancelConfiguration.js';
33+
import './centernot/CenternotConfiguration.js';
3334
import './color/ColorConfiguration.js';
3435
import './colorv2/ColorV2Configuration.js';
3536
import './colortbl/ColortblConfiguration.js';
@@ -60,6 +61,7 @@ if (typeof MathJax !== 'undefined' && MathJax.loader) {
6061
'[tex]/braket',
6162
'[tex]/bussproofs',
6263
'[tex]/cancel',
64+
'[tex]/centernot',
6365
'[tex]/color',
6466
'[tex]/colorv2',
6567
'[tex]/colortbl',
@@ -91,6 +93,7 @@ export const AllPackages: string[] = [
9193
'braket',
9294
'bussproofs',
9395
'cancel',
96+
'centernot',
9497
'color',
9598
'colortbl',
9699
'enclose',
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*************************************************************
2+
*
3+
* Copyright (c) 2021 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 centernot package.
21+
*
22+
* @author dpvc@mathjax.org (Davide P. Cervone)
23+
*/
24+
25+
import {Configuration} from '../Configuration.js';
26+
import ParseOptions from '../ParseOptions.js';
27+
import TexParser from '../TexParser.js';
28+
import NodeUtil from '../NodeUtil.js';
29+
import {CommandMap} from '../SymbolMap.js';
30+
import {MmlNode} from '../../../core/MmlTree/MmlNode.js';
31+
import BaseMethods from '../base/BaseMethods.js';
32+
33+
new CommandMap('centernot', {
34+
centerOver: 'CenterOver',
35+
centernot: ['Macro', '\\centerOver{#1}{{\u29F8}}', 1]
36+
}, {
37+
/**
38+
* Implements \centerOver{base}{symbol}
39+
*
40+
* @param {TexParser} parser The active tex parser.
41+
* @param {string} name The name of the macro being processed.
42+
*/
43+
CenterOver(parser: TexParser, name: string) {
44+
const arg = '{' + parser.GetArgument(name) + '}';
45+
const over = parser.ParseArg(name);
46+
const base = new TexParser(arg, parser.stack.env, parser.configuration).mml();
47+
let mml = parser.create('node', 'TeXAtom', [
48+
new TexParser(arg, parser.stack.env, parser.configuration).mml(),
49+
parser.create('node', 'mpadded', [
50+
parser.create('node', 'mpadded', [over], {width: 0, lspace: '-.5width'}),
51+
parser.create('node', 'mphantom', [base])
52+
], {width: 0, lspace: '-.5width'})
53+
]);
54+
parser.configuration.addNode('centerOver', base);
55+
parser.Push(mml);
56+
},
57+
Macro: BaseMethods.Macro
58+
});
59+
60+
/**
61+
* Filter to copy texClass to the surrounding TeXAtom so that the negated
62+
* item has the same class of the base.
63+
*
64+
* @param {ParseOptions} data The active tex parser.
65+
*/
66+
export function filterCenterOver({data}: {data: ParseOptions}) {
67+
for (const base of data.getList('centerOver')) {
68+
const texClass = NodeUtil.getTexClass(base.childNodes[0].childNodes[0] as MmlNode);
69+
if (texClass !== null) {
70+
NodeUtil.setProperties(base.parent.parent.parent.parent.parent.parent, {texClass});
71+
}
72+
}
73+
}
74+
75+
76+
export const CenternotConfiguration = Configuration.create(
77+
'centernot', {
78+
handler: {macro: ['centernot']},
79+
postprocessors: [filterCenterOver]
80+
}
81+
);

0 commit comments

Comments
 (0)