|
| 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 | + |
0 commit comments