action.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
  2. /* vim: set ts=2 et sw=2 tw=80: */
  3. /*************************************************************
  4. *
  5. * MathJax/extensions/TeX/action.js
  6. *
  7. * Implements the \mathtip, \texttip, and \toggle macros, which give
  8. * access from TeX to the <maction> tag in the MathML that underlies
  9. * MathJax's internal format.
  10. *
  11. * Usage:
  12. *
  13. * \mathtip{math}{tip} % use "tip" (in math mode) as tooltip for "math"
  14. * \texttip{math}{tip} % use "tip" (in text mode) as tooltip for "math"
  15. * \toggle{math1}{math2}...\endtoggle
  16. * % show math1, and when clicked, show math2, and so on.
  17. * % When the last one is clicked, go back to math1.
  18. *
  19. * ---------------------------------------------------------------------
  20. *
  21. * Copyright (c) 2011-2013 The MathJax Consortium
  22. *
  23. * Licensed under the Apache License, Version 2.0 (the "License");
  24. * you may not use this file except in compliance with the License.
  25. * You may obtain a copy of the License at
  26. *
  27. * http://www.apache.org/licenses/LICENSE-2.0
  28. *
  29. * Unless required by applicable law or agreed to in writing, software
  30. * distributed under the License is distributed on an "AS IS" BASIS,
  31. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  32. * See the License for the specific language governing permissions and
  33. * limitations under the License.
  34. */
  35. MathJax.Extension["TeX/action"] = {
  36. version: "2.2"
  37. };
  38. MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
  39. var TEX = MathJax.InputJax.TeX,
  40. MML = MathJax.ElementJax.mml;
  41. //
  42. // Set up control sequenecs
  43. //
  44. TEX.Definitions.Add({
  45. macros: {
  46. toggle: 'Toggle',
  47. mathtip: 'Mathtip',
  48. texttip: ['Macro','\\mathtip{#1}{\\text{#2}}',2]
  49. }
  50. },null,true);
  51. TEX.Parse.Augment({
  52. //
  53. // Implement \toggle {math1} {math2} ... \endtoggle
  54. // (as an <maction actiontype="toggle">)
  55. //
  56. Toggle: function (name) {
  57. var data = [], arg;
  58. while ((arg = this.GetArgument(name)) !== "\\endtoggle")
  59. {data.push(TEX.Parse(arg,this.stack.env).mml())}
  60. this.Push(MML.maction.apply(MML,data).With({actiontype: MML.ACTIONTYPE.TOGGLE}));
  61. },
  62. //
  63. // Implement \mathtip{math}{tip}
  64. // (an an <maction actiontype="tooltip">)
  65. //
  66. Mathtip: function(name) {
  67. var arg = this.ParseArg(name), tip = this.ParseArg(name);
  68. this.Push(MML.maction(arg,tip).With({actiontype: MML.ACTIONTYPE.TOOLTIP}));
  69. }
  70. });
  71. MathJax.Hub.Startup.signal.Post("TeX action Ready");
  72. });
  73. MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/action.js");