EncloseConfiguration.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 enclose 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 {CommandMap} from '../SymbolMap.js';
  25. import {ParseMethod} from '../Types.js';
  26. import ParseUtil from '../ParseUtil.js';
  27. /**
  28. * The attributes allowed in \enclose{notation}[attributes]{math}
  29. * @type {{[key: string]: number}}
  30. */
  31. export const ENCLOSE_OPTIONS: {[key: string]: number} = {
  32. 'data-arrowhead': 1,
  33. color: 1,
  34. mathcolor: 1,
  35. background: 1,
  36. mathbackground: 1,
  37. 'data-padding': 1,
  38. 'data-thickness': 1
  39. };
  40. // Namespace
  41. export let EncloseMethods: Record<string, ParseMethod> = {};
  42. /**
  43. * Implements \enclose{notation}[attr]{math}
  44. * (create <menclose notation="notation">math</menclose>)
  45. * @param {TexParser} parser The current tex parser.
  46. * @param {string} name The name of the calling macro.
  47. */
  48. EncloseMethods.Enclose = function(parser: TexParser, name: string) {
  49. let notation = parser.GetArgument(name).replace(/,/g, ' ');
  50. const attr = parser.GetBrackets(name, '');
  51. const math = parser.ParseArg(name);
  52. const def = ParseUtil.keyvalOptions(attr, ENCLOSE_OPTIONS);
  53. def.notation = notation;
  54. parser.Push(parser.create('node', 'menclose', [math], def));
  55. };
  56. new CommandMap('enclose', {enclose: 'Enclose'}, EncloseMethods);
  57. export const EncloseConfiguration = Configuration.create(
  58. 'enclose', {handler: {macro: ['enclose']}}
  59. );