UnicodeConfiguration.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.UnicodeConfiguration = exports.UnicodeMethods = void 0;
  7. var Configuration_js_1 = require("../Configuration.js");
  8. var TexError_js_1 = __importDefault(require("../TexError.js"));
  9. var SymbolMap_js_1 = require("../SymbolMap.js");
  10. var ParseUtil_js_1 = __importDefault(require("../ParseUtil.js"));
  11. var NodeUtil_js_1 = __importDefault(require("../NodeUtil.js"));
  12. var Entities_js_1 = require("../../../util/Entities.js");
  13. exports.UnicodeMethods = {};
  14. var UnicodeCache = {};
  15. exports.UnicodeMethods.Unicode = function (parser, name) {
  16. var HD = parser.GetBrackets(name);
  17. var HDsplit = null;
  18. var font = null;
  19. if (HD) {
  20. if (HD.replace(/ /g, '').
  21. match(/^(\d+(\.\d*)?|\.\d+),(\d+(\.\d*)?|\.\d+)$/)) {
  22. HDsplit = HD.replace(/ /g, '').split(/,/);
  23. font = parser.GetBrackets(name);
  24. }
  25. else {
  26. font = HD;
  27. }
  28. }
  29. var n = ParseUtil_js_1.default.trimSpaces(parser.GetArgument(name)).replace(/^0x/, 'x');
  30. if (!n.match(/^(x[0-9A-Fa-f]+|[0-9]+)$/)) {
  31. throw new TexError_js_1.default('BadUnicode', 'Argument to \\unicode must be a number');
  32. }
  33. var N = parseInt(n.match(/^x/) ? '0' + n : n);
  34. if (!UnicodeCache[N]) {
  35. UnicodeCache[N] = [800, 200, font, N];
  36. }
  37. else if (!font) {
  38. font = UnicodeCache[N][2];
  39. }
  40. if (HDsplit) {
  41. UnicodeCache[N][0] = Math.floor(parseFloat(HDsplit[0]) * 1000);
  42. UnicodeCache[N][1] = Math.floor(parseFloat(HDsplit[1]) * 1000);
  43. }
  44. var variant = parser.stack.env.font;
  45. var def = {};
  46. if (font) {
  47. UnicodeCache[N][2] = def.fontfamily = font.replace(/'/g, '\'');
  48. if (variant) {
  49. if (variant.match(/bold/)) {
  50. def.fontweight = 'bold';
  51. }
  52. if (variant.match(/italic|-mathit/)) {
  53. def.fontstyle = 'italic';
  54. }
  55. }
  56. }
  57. else if (variant) {
  58. def.mathvariant = variant;
  59. }
  60. var node = parser.create('token', 'mtext', def, (0, Entities_js_1.numeric)(n));
  61. NodeUtil_js_1.default.setProperty(node, 'unicode', true);
  62. parser.Push(node);
  63. };
  64. new SymbolMap_js_1.CommandMap('unicode', { unicode: 'Unicode' }, exports.UnicodeMethods);
  65. exports.UnicodeConfiguration = Configuration_js_1.Configuration.create('unicode', { handler: { macro: ['unicode'] } });
  66. //# sourceMappingURL=UnicodeConfiguration.js.map