ActionConfiguration.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 action 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 BaseMethods from '../base/BaseMethods.js';
  27. // Namespace
  28. export let ActionMethods: Record<string, ParseMethod> = {};
  29. ActionMethods.Macro = BaseMethods.Macro;
  30. /**
  31. * Implement \toggle {math1} {math2} ... \endtoggle
  32. * (as an <maction actiontype="toggle">)
  33. * @param {TexParser} parser The current tex parser.
  34. * @param {string} name The name of the calling macro.
  35. */
  36. ActionMethods.Toggle = function(parser: TexParser, name: string) {
  37. const children = [];
  38. let arg;
  39. while ((arg = parser.GetArgument(name)) !== '\\endtoggle') {
  40. children.push(
  41. new TexParser(arg, parser.stack.env, parser.configuration).mml());
  42. }
  43. parser.Push(
  44. parser.create('node', 'maction', children, {actiontype: 'toggle'}));
  45. };
  46. /**
  47. * Implement \mathtip{math}{tip}
  48. * (an an <maction actiontype="tooltip">)
  49. * @param {TexParser} parser The current tex parser.
  50. * @param {string} name The name of the calling macro.
  51. */
  52. ActionMethods.Mathtip = function(parser: TexParser, name: string) {
  53. const arg = parser.ParseArg(name);
  54. const tip = parser.ParseArg(name);
  55. parser.Push(
  56. parser.create('node', 'maction', [arg, tip], {actiontype: 'tooltip'}));
  57. };
  58. new CommandMap('action-macros', {
  59. toggle: 'Toggle',
  60. mathtip: 'Mathtip',
  61. texttip: ['Macro', '\\mathtip{#1}{\\text{#2}}', 2]
  62. }, ActionMethods);
  63. export const ActionConfiguration = Configuration.create(
  64. 'action', {handler: {macro: ['action-macros']}}
  65. );