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