ExtpfeilConfiguration.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 extpfeil package. Note that this is
  19. * based on AMS package and Newcommand utilities.
  20. *
  21. * @author v.sorge@mathjax.org (Volker Sorge)
  22. */
  23. import {Configuration, ParserConfiguration} from '../Configuration.js';
  24. import TexParser from '../TexParser.js';
  25. import {CommandMap} from '../SymbolMap.js';
  26. import {ParseMethod} from '../Types.js';
  27. import {AmsMethods} from '../ams/AmsMethods.js';
  28. import NewcommandUtil from '../newcommand/NewcommandUtil.js';
  29. import {NewcommandConfiguration} from '../newcommand/NewcommandConfiguration.js';
  30. import TexError from '../TexError.js';
  31. // Namespace
  32. export let ExtpfeilMethods: Record<string, ParseMethod> = {};
  33. ExtpfeilMethods.xArrow = AmsMethods.xArrow;
  34. /**
  35. * Implements \Newextarrow to define a new arrow.
  36. * @param {TexParser} parser The current tex parser.
  37. * @param {string} name The name of the calling macro.
  38. */
  39. ExtpfeilMethods.NewExtArrow = function(parser: TexParser, name: string) {
  40. let cs = parser.GetArgument(name);
  41. const space = parser.GetArgument(name);
  42. const chr = parser.GetArgument(name);
  43. if (!cs.match(/^\\([a-z]+|.)$/i)) {
  44. throw new TexError('NewextarrowArg1',
  45. 'First argument to %1 must be a control sequence name', name);
  46. }
  47. if (!space.match(/^(\d+),(\d+)$/)) {
  48. throw new TexError(
  49. 'NewextarrowArg2',
  50. 'Second argument to %1 must be two integers separated by a comma',
  51. name);
  52. }
  53. if (!chr.match(/^(\d+|0x[0-9A-F]+)$/i)) {
  54. throw new TexError(
  55. 'NewextarrowArg3',
  56. 'Third argument to %1 must be a unicode character number',
  57. name);
  58. }
  59. cs = cs.substr(1);
  60. let spaces = space.split(',');
  61. NewcommandUtil.addMacro(parser, cs, ExtpfeilMethods.xArrow,
  62. [parseInt(chr), parseInt(spaces[0]), parseInt(spaces[1])]);
  63. };
  64. new CommandMap('extpfeil', {
  65. xtwoheadrightarrow: ['xArrow', 0x21A0, 12, 16],
  66. xtwoheadleftarrow: ['xArrow', 0x219E, 17, 13],
  67. xmapsto: ['xArrow', 0x21A6, 6, 7],
  68. xlongequal: ['xArrow', 0x003D, 7, 7],
  69. xtofrom: ['xArrow', 0x21C4, 12, 12],
  70. Newextarrow: 'NewExtArrow'
  71. }, ExtpfeilMethods);
  72. let init = function(config: ParserConfiguration) {
  73. NewcommandConfiguration.init(config);
  74. };
  75. export const ExtpfeilConfiguration = Configuration.create(
  76. 'extpfeil', {
  77. handler: {macro: ['extpfeil']},
  78. init: init
  79. }
  80. );