CancelConfiguration.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*************************************************************
  2. *
  3. * Copyright (c) 2018-2022 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. * @fileoverview Configuration file for the cancel package.
  19. *
  20. * @author v.sorge@mathjax.org (Volker Sorge)
  21. */
  22. import {Configuration} from '../Configuration.js';
  23. import TexParser from '../TexParser.js';
  24. import {TexConstant} from '../TexConstants.js';
  25. import {CommandMap} from '../SymbolMap.js';
  26. import {ParseMethod} from '../Types.js';
  27. import ParseUtil from '../ParseUtil.js';
  28. import {ENCLOSE_OPTIONS} from '../enclose/EncloseConfiguration.js';
  29. // Namespace
  30. export let CancelMethods: Record<string, ParseMethod> = {};
  31. /**
  32. * Parse function for cancel macros of the form \(b|x)?cancel[attributes]{math}
  33. * @param {TexParser} parser The current tex parser.
  34. * @param {string} name The name of the calling macro.
  35. * @param {string} notation The type of cancel notation to use.
  36. */
  37. CancelMethods.Cancel = function(parser: TexParser, name: string, notation: string) {
  38. const attr = parser.GetBrackets(name, '');
  39. const math = parser.ParseArg(name);
  40. const def = ParseUtil.keyvalOptions(attr, ENCLOSE_OPTIONS);
  41. def['notation'] = notation;
  42. parser.Push(parser.create('node', 'menclose', [math], def));
  43. };
  44. /**
  45. * Parse function implementing \cancelto{value}[attributes]{math}
  46. * @param {TexParser} parser The current tex parser.
  47. * @param {string} name The name of the calling macro.
  48. */
  49. CancelMethods.CancelTo = function(parser: TexParser, name: string) {
  50. const attr = parser.GetBrackets(name, '');
  51. let value = parser.ParseArg(name);
  52. const math = parser.ParseArg(name);
  53. const def = ParseUtil.keyvalOptions(attr, ENCLOSE_OPTIONS);
  54. def ['notation'] = [TexConstant.Notation.UPDIAGONALSTRIKE,
  55. TexConstant.Notation.UPDIAGONALARROW,
  56. TexConstant.Notation.NORTHEASTARROW].join(' ');
  57. value = parser.create('node', 'mpadded', [value],
  58. {depth: '-.1em', height: '+.1em', voffset: '.1em'});
  59. parser.Push(parser.create('node', 'msup',
  60. [parser.create('node', 'menclose', [math], def), value]));
  61. };
  62. new CommandMap('cancel', {
  63. cancel: ['Cancel', TexConstant.Notation.UPDIAGONALSTRIKE],
  64. bcancel: ['Cancel', TexConstant.Notation.DOWNDIAGONALSTRIKE],
  65. xcancel: ['Cancel', TexConstant.Notation.UPDIAGONALSTRIKE + ' ' +
  66. TexConstant.Notation.DOWNDIAGONALSTRIKE],
  67. cancelto: 'CancelTo'
  68. }, CancelMethods);
  69. export const CancelConfiguration = Configuration.create(
  70. 'cancel', {handler: {macro: ['cancel']}}
  71. );