CenternotConfiguration.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*************************************************************
  2. *
  3. * Copyright (c) 2021-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 centernot package.
  19. *
  20. * @author dpvc@mathjax.org (Davide P. Cervone)
  21. */
  22. import {Configuration} from '../Configuration.js';
  23. import ParseOptions from '../ParseOptions.js';
  24. import TexParser from '../TexParser.js';
  25. import NodeUtil from '../NodeUtil.js';
  26. import {CommandMap} from '../SymbolMap.js';
  27. import {MmlNode} from '../../../core/MmlTree/MmlNode.js';
  28. import BaseMethods from '../base/BaseMethods.js';
  29. new CommandMap('centernot', {
  30. centerOver: 'CenterOver',
  31. centernot: ['Macro', '\\centerOver{#1}{{\u29F8}}', 1]
  32. }, {
  33. /**
  34. * Implements \centerOver{base}{symbol}
  35. *
  36. * @param {TexParser} parser The active tex parser.
  37. * @param {string} name The name of the macro being processed.
  38. */
  39. CenterOver(parser: TexParser, name: string) {
  40. const arg = '{' + parser.GetArgument(name) + '}';
  41. const over = parser.ParseArg(name);
  42. const base = new TexParser(arg, parser.stack.env, parser.configuration).mml();
  43. let mml = parser.create('node', 'TeXAtom', [
  44. new TexParser(arg, parser.stack.env, parser.configuration).mml(),
  45. parser.create('node', 'mpadded', [
  46. parser.create('node', 'mpadded', [over], {width: 0, lspace: '-.5width'}),
  47. parser.create('node', 'mphantom', [base])
  48. ], {width: 0, lspace: '-.5width'})
  49. ]);
  50. parser.configuration.addNode('centerOver', base);
  51. parser.Push(mml);
  52. },
  53. Macro: BaseMethods.Macro
  54. });
  55. /**
  56. * Filter to copy texClass to the surrounding TeXAtom so that the negated
  57. * item has the same class of the base.
  58. *
  59. * @param {ParseOptions} data The active tex parser.
  60. */
  61. export function filterCenterOver({data}: {data: ParseOptions}) {
  62. for (const base of data.getList('centerOver')) {
  63. const texClass = NodeUtil.getTexClass(base.childNodes[0].childNodes[0] as MmlNode);
  64. if (texClass !== null) {
  65. NodeUtil.setProperties(base.parent.parent.parent.parent.parent.parent, {texClass});
  66. }
  67. }
  68. }
  69. export const CenternotConfiguration = Configuration.create(
  70. 'centernot', {
  71. handler: {macro: ['centernot']},
  72. postprocessors: [filterCenterOver]
  73. }
  74. );