www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

mathchoice.js (4162B)


      1 /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      3 
      4 /*************************************************************
      5  *
      6  *  MathJax/extensions/TeX/mathchoice.js
      7  *  
      8  *  Implements the \mathchoice macro (rarely used)
      9  *
     10  *  ---------------------------------------------------------------------
     11  *  
     12  *  Copyright (c) 2009-2015 The MathJax Consortium
     13  * 
     14  *  Licensed under the Apache License, Version 2.0 (the "License");
     15  *  you may not use this file except in compliance with the License.
     16  *  You may obtain a copy of the License at
     17  * 
     18  *      http://www.apache.org/licenses/LICENSE-2.0
     19  * 
     20  *  Unless required by applicable law or agreed to in writing, software
     21  *  distributed under the License is distributed on an "AS IS" BASIS,
     22  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     23  *  See the License for the specific language governing permissions and
     24  *  limitations under the License.
     25  */
     26 
     27 MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
     28   var VERSION = "2.6.0";
     29 
     30   var MML = MathJax.ElementJax.mml;
     31   var TEX = MathJax.InputJax.TeX;
     32   var TEXDEF = TEX.Definitions;
     33   
     34   TEXDEF.Add({macros: {mathchoice: 'MathChoice'}},null,true);
     35 
     36   TEX.Parse.Augment({
     37     MathChoice: function (name) {
     38       var D  = this.ParseArg(name),
     39           T  = this.ParseArg(name),
     40           S  = this.ParseArg(name),
     41           SS = this.ParseArg(name);
     42       this.Push(MML.TeXmathchoice(D,T,S,SS));
     43     }
     44   });
     45   
     46   MML.TeXmathchoice = MML.mbase.Subclass({
     47     type: "TeXmathchoice", notParent: true,
     48     choice: function () {
     49       if (this.selection != null) return this.selection;
     50       if (this.choosing) return 2; // prevent infinite loops:  see issue #1151
     51       this.choosing = true;
     52       var selection = 0, values = this.getValues("displaystyle","scriptlevel");
     53       if (values.scriptlevel > 0) {selection = Math.min(3,values.scriptlevel+1)}
     54         else {selection = (values.displaystyle ? 0 : 1)}
     55       // only cache the result if we are actually in place in a <math> tag.
     56       var node = this.inherit; while (node && node.type !== "math") node = node.inherit;
     57       if (node) this.selection = selection;
     58       this.choosing = false;
     59       return selection;
     60     },
     61     selected: function () {return this.data[this.choice()]},
     62     setTeXclass: function (prev) {return this.selected().setTeXclass(prev)},
     63     isSpacelike: function () {return this.selected().isSpacelike()},
     64     isEmbellished: function () {return this.selected().isEmbellished()},
     65     Core: function () {return this.selected()},
     66     CoreMO: function () {return this.selected().CoreMO()},
     67     toHTML: function (span) {
     68       span = this.HTMLcreateSpan(span);
     69       span.bbox = this.Core().toHTML(span).bbox;
     70       // Firefox doesn't correctly handle a span with a negatively sized content,
     71       //   so move marginLeft to main span (this is a hack to get \iiiint to work).
     72       //   FIXME:  This is a symptom of a more general problem with Firefox, and
     73       //           there probably needs to be a more general solution (e.g., modifying
     74       //           HTMLhandleSpace() to get the width and adjust the right margin to
     75       //           compensate for negative-width contents)
     76       if (span.firstChild && span.firstChild.style.marginLeft) {
     77         span.style.marginLeft = span.firstChild.style.marginLeft;
     78         span.firstChild.style.marginLeft = "";
     79       }
     80       return span;
     81     },
     82     toSVG: function () {
     83       var svg = this.Core().toSVG();
     84       this.SVGsaveData(svg);
     85       return svg;
     86     },
     87     toCommonHTML: function (node) {
     88       node = this.CHTMLcreateNode(node);
     89       this.CHTMLhandleStyle(node);
     90       this.CHTMLhandleColor(node);
     91       this.CHTMLaddChild(node,this.choice(),{});
     92       return node;
     93     },
     94     toPreviewHTML: function(span) {
     95       span = this.PHTMLcreateSpan(span);
     96       this.PHTMLhandleStyle(span);
     97       this.PHTMLhandleColor(span);
     98       this.PHTMLaddChild(span,this.choice(),{});
     99       return span;
    100     }
    101   });
    102   
    103   MathJax.Hub.Startup.signal.Post("TeX mathchoice Ready");
    104   
    105 });
    106 
    107 MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/mathchoice.js");