unicode.js 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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/unicode.js
  6. *
  7. * Implements the \unicode extension to TeX to allow arbitrary unicode
  8. * code points to be entered into the TeX file. You can specify
  9. * the height and depth of the character (the width is determined by
  10. * the browser), and the default font from which to take the character.
  11. *
  12. * Examples:
  13. * \unicode{65} % the character 'A'
  14. * \unicode{x41} % the character 'A'
  15. * \unicode[.55,0.05]{x22D6} % less-than with dot, with height .55 and depth 0.05
  16. * \unicode[.55,0.05][Geramond]{x22D6} % same taken from Geramond font
  17. * \unicode[Garamond]{x22D6} % same, but with default height, depth of .8,.2
  18. *
  19. * Once a size and font are provided for a given code point, they need
  20. * not be specified again in subsequent \unicode calls for that character.
  21. * Note that a font list can be given, but Internet Explorer has a buggy
  22. * implementation of font-family where it only looks in the first
  23. * available font and if the glyph is not in that, it does not look at
  24. * later fonts, but goes directly to the default font as set in the
  25. * Internet-Options/Font panel. For this reason, the default font list is
  26. * "STIXGeneral,'Arial Unicode MS'", so if the user has STIX fonts, the
  27. * symbol will be taken from that (almost all the symbols are in
  28. * STIXGeneral), otherwise Arial Unicode MS is tried.
  29. *
  30. * To configure the default font list, use
  31. *
  32. * MathJax.Hub.Config({
  33. * TeX: {
  34. * unicode: {
  35. * fonts: "STIXGeneral,'Arial Unicode MS'"
  36. * }
  37. * }
  38. * });
  39. *
  40. * The result of \unicode will have TeX class ORD (i.e., it will act like a
  41. * variable). Use \mathbin, \mathrel, etc, to specify a different class.
  42. *
  43. * ---------------------------------------------------------------------
  44. *
  45. * Copyright (c) 2009-2013 The MathJax Consortium
  46. *
  47. * Licensed under the Apache License, Version 2.0 (the "License");
  48. * you may not use this file except in compliance with the License.
  49. * You may obtain a copy of the License at
  50. *
  51. * http://www.apache.org/licenses/LICENSE-2.0
  52. *
  53. * Unless required by applicable law or agreed to in writing, software
  54. * distributed under the License is distributed on an "AS IS" BASIS,
  55. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  56. * See the License for the specific language governing permissions and
  57. * limitations under the License.
  58. */MathJax.Extension["TeX/unicode"]={version:"2.2",unicode:{},config:MathJax.Hub.CombineConfig("TeX.unicode",{fonts:"STIXGeneral,'Arial Unicode MS'"})};MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var c=MathJax.InputJax.TeX,e=MathJax.ElementJax.mml,d=MathJax.Extension["TeX/unicode"].unicode;c.Definitions.Add({macros:{unicode:"Unicode"}},null,!0);c.Parse.Augment({Unicode:function(a){var b=this.GetBrackets(a),c;b&&(b.replace(/ /g,"").match(/^(\d+(\.\d*)?|\.\d+),(\d+(\.\d*)?|\.\d+)$/)?(b=b.replace(/ /g,"").split(/,/),c=this.GetBrackets(a)):(c=b,b=null));a=this.trimSpaces(this.GetArgument(a));var f=parseInt(a.match(/^x/)?"0"+a:a);d[f]?c||(c=d[f][2]):d[f]=[800,200,c,f];b&&(d[f][0]=Math.floor(1E3*b[0]),d[f][1]=Math.floor(1E3*b[1]));var b=this.stack.env.font,g={};c?(d[f][2]=g.fontfamily=c.replace(/"/g,"'"),b&&(b.match(/bold/)&&(g.fontweight="bold"),b.match(/italic|-mathit/)&&(g.fontstyle="italic"))):b&&(g.mathvariant=b);g.unicode=[].concat(d[f]);this.Push(e.mtext(e.entity("#"+a)).With(g))}});MathJax.Hub.Startup.signal.Post("TeX unicode Ready")});MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function(){var c=MathJax.ElementJax.mml,e=MathJax.Extension["TeX/unicode"].config.fonts,d=c.mbase.prototype.HTMLgetVariant;c.mbase.Augment({HTMLgetVariant:function(){var a=d.call(this);a.unicode&&(delete a.unicode,delete a.FONTS);if(!this.unicode)return a;a.unicode=!0;a.defaultFont||(a=MathJax.Hub.Insert({},a),a.defaultFont={family:e});var b=this.unicode[2],b=b?b+(","+e):e;a.defaultFont[this.unicode[3]]=[this.unicode[0],this.unicode[1],500,0,500,{isUnknown:!0,isUnicode:!0,font:b}];return a}})});MathJax.Hub.Register.StartupHook("SVG Jax Ready",function(){var c=MathJax.ElementJax.mml,e=MathJax.Extension["TeX/unicode"].config.fonts,d=c.mbase.prototype.SVGgetVariant;c.mbase.Augment({SVGgetVariant:function(){var a=d.call(this);a.unicode&&(delete a.unicode,delete a.FONTS);if(!this.unicode)return a;a.unicode=!0;a.forceFamily||(a=MathJax.Hub.Insert({},a));a.defaultFamily=e;a.noRemap=!0;a.h=this.unicode[0];a.d=this.unicode[1];return a}})});MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/unicode.js");