mathchoice.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/mathchoice.js
  6. *
  7. * Implements the \mathchoice macro (rarely used)
  8. *
  9. * ---------------------------------------------------------------------
  10. *
  11. * Copyright (c) 2009-2013 The MathJax Consortium
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the "License");
  14. * you may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. */
  25. MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
  26. var VERSION = "2.2";
  27. var MML = MathJax.ElementJax.mml;
  28. var TEX = MathJax.InputJax.TeX;
  29. var TEXDEF = TEX.Definitions;
  30. TEXDEF.Add({macros: {mathchoice: 'MathChoice'}},null,true);
  31. TEX.Parse.Augment({
  32. MathChoice: function (name) {
  33. var D = this.ParseArg(name),
  34. T = this.ParseArg(name),
  35. S = this.ParseArg(name),
  36. SS = this.ParseArg(name);
  37. this.Push(MML.TeXmathchoice(D,T,S,SS));
  38. }
  39. });
  40. MML.TeXmathchoice = MML.mbase.Subclass({
  41. type: "TeXmathchoice", notParent: true,
  42. choice: function () {
  43. if (this.selection == null) {
  44. this.selection = 0;
  45. var values = this.getValues("displaystyle","scriptlevel");
  46. if (values.scriptlevel > 0) {this.selection = Math.min(3,values.scriptlevel+1)}
  47. else {this.selection = (values.displaystyle ? 0 : 1)}
  48. }
  49. return this.selection;
  50. },
  51. selected: function () {return this.data[this.choice()]},
  52. setTeXclass: function (prev) {return this.selected().setTeXclass(prev)},
  53. isSpacelike: function () {return this.selected().isSpacelike()},
  54. isEmbellished: function () {return this.selected().isEmbellished()},
  55. Core: function () {return this.selected()},
  56. CoreMO: function () {return this.selected().CoreMO()},
  57. toHTML: function (span) {
  58. span = this.HTMLcreateSpan(span);
  59. span.bbox = this.Core().toHTML(span).bbox;
  60. // Firefox doesn't correctly handle a span with a negatively sized content,
  61. // so move marginLeft to main span (this is a hack to get \iiiint to work).
  62. // FIXME: This is a symptom of a more general problem with Firefox, and
  63. // there probably needs to be a more general solution (e.g., modifying
  64. // HTMLhandleSpace() to get the width and adjust the right margin to
  65. // compensate for negative-width contents)
  66. if (span.firstChild && span.firstChild.style.marginLeft) {
  67. span.style.marginLeft = span.firstChild.style.marginLeft;
  68. span.firstChild.style.marginLeft = "";
  69. }
  70. return span;
  71. },
  72. toSVG: function () {return this.Core().toSVG()}
  73. });
  74. MathJax.Hub.Startup.signal.Post("TeX mathchoice Ready");
  75. });
  76. MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/mathchoice.js");