|
| 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