EmpheqConfiguration.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. var __read = (this && this.__read) || function (o, n) {
  18. var m = typeof Symbol === "function" && o[Symbol.iterator];
  19. if (!m) return o;
  20. var i = m.call(o), r, ar = [], e;
  21. try {
  22. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  23. }
  24. catch (error) { e = { error: error }; }
  25. finally {
  26. try {
  27. if (r && !r.done && (m = i["return"])) m.call(i);
  28. }
  29. finally { if (e) throw e.error; }
  30. }
  31. return ar;
  32. };
  33. var __importDefault = (this && this.__importDefault) || function (mod) {
  34. return (mod && mod.__esModule) ? mod : { "default": mod };
  35. };
  36. var _a;
  37. Object.defineProperty(exports, "__esModule", { value: true });
  38. exports.EmpheqConfiguration = exports.EmpheqMethods = exports.EmpheqBeginItem = void 0;
  39. var Configuration_js_1 = require("../Configuration.js");
  40. var SymbolMap_js_1 = require("../SymbolMap.js");
  41. var ParseUtil_js_1 = __importDefault(require("../ParseUtil.js"));
  42. var TexError_js_1 = __importDefault(require("../TexError.js"));
  43. var BaseItems_js_1 = require("../base/BaseItems.js");
  44. var EmpheqUtil_js_1 = require("./EmpheqUtil.js");
  45. var EmpheqBeginItem = (function (_super) {
  46. __extends(EmpheqBeginItem, _super);
  47. function EmpheqBeginItem() {
  48. return _super !== null && _super.apply(this, arguments) || this;
  49. }
  50. Object.defineProperty(EmpheqBeginItem.prototype, "kind", {
  51. get: function () {
  52. return 'empheq-begin';
  53. },
  54. enumerable: false,
  55. configurable: true
  56. });
  57. EmpheqBeginItem.prototype.checkItem = function (item) {
  58. if (item.isKind('end') && item.getName() === this.getName()) {
  59. this.setProperty('end', false);
  60. }
  61. return _super.prototype.checkItem.call(this, item);
  62. };
  63. return EmpheqBeginItem;
  64. }(BaseItems_js_1.BeginItem));
  65. exports.EmpheqBeginItem = EmpheqBeginItem;
  66. exports.EmpheqMethods = {
  67. Empheq: function (parser, begin) {
  68. if (parser.stack.env.closing === begin.getName()) {
  69. delete parser.stack.env.closing;
  70. parser.Push(parser.itemFactory.create('end').setProperty('name', parser.stack.global.empheq));
  71. parser.stack.global.empheq = '';
  72. var empheq = parser.stack.Top();
  73. EmpheqUtil_js_1.EmpheqUtil.adjustTable(empheq, parser);
  74. parser.Push(parser.itemFactory.create('end').setProperty('name', 'empheq'));
  75. }
  76. else {
  77. ParseUtil_js_1.default.checkEqnEnv(parser);
  78. delete parser.stack.global.eqnenv;
  79. var opts = parser.GetBrackets('\\begin{' + begin.getName() + '}') || '';
  80. var _a = __read((parser.GetArgument('\\begin{' + begin.getName() + '}') || '').split(/=/), 2), env = _a[0], n = _a[1];
  81. if (!EmpheqUtil_js_1.EmpheqUtil.checkEnv(env)) {
  82. throw new TexError_js_1.default('UnknownEnv', 'Unknown environment "%1"', env);
  83. }
  84. if (opts) {
  85. begin.setProperties(EmpheqUtil_js_1.EmpheqUtil.splitOptions(opts, { left: 1, right: 1 }));
  86. }
  87. parser.stack.global.empheq = env;
  88. parser.string = '\\begin{' + env + '}' + (n ? '{' + n + '}' : '') + parser.string.slice(parser.i);
  89. parser.i = 0;
  90. parser.Push(begin);
  91. }
  92. },
  93. EmpheqMO: function (parser, _name, c) {
  94. parser.Push(parser.create('token', 'mo', {}, c));
  95. },
  96. EmpheqDelim: function (parser, name) {
  97. var c = parser.GetDelimiter(name);
  98. parser.Push(parser.create('token', 'mo', { stretchy: true, symmetric: true }, c));
  99. }
  100. };
  101. new SymbolMap_js_1.EnvironmentMap('empheq-env', EmpheqUtil_js_1.EmpheqUtil.environment, {
  102. empheq: ['Empheq', 'empheq'],
  103. }, exports.EmpheqMethods);
  104. new SymbolMap_js_1.CommandMap('empheq-macros', {
  105. empheqlbrace: ['EmpheqMO', '{'],
  106. empheqrbrace: ['EmpheqMO', '}'],
  107. empheqlbrack: ['EmpheqMO', '['],
  108. empheqrbrack: ['EmpheqMO', ']'],
  109. empheqlangle: ['EmpheqMO', '\u27E8'],
  110. empheqrangle: ['EmpheqMO', '\u27E9'],
  111. empheqlparen: ['EmpheqMO', '('],
  112. empheqrparen: ['EmpheqMO', ')'],
  113. empheqlvert: ['EmpheqMO', '|'],
  114. empheqrvert: ['EmpheqMO', '|'],
  115. empheqlVert: ['EmpheqMO', '\u2016'],
  116. empheqrVert: ['EmpheqMO', '\u2016'],
  117. empheqlfloor: ['EmpheqMO', '\u230A'],
  118. empheqrfloor: ['EmpheqMO', '\u230B'],
  119. empheqlceil: ['EmpheqMO', '\u2308'],
  120. empheqrceil: ['EmpheqMO', '\u2309'],
  121. empheqbiglbrace: ['EmpheqMO', '{'],
  122. empheqbigrbrace: ['EmpheqMO', '}'],
  123. empheqbiglbrack: ['EmpheqMO', '['],
  124. empheqbigrbrack: ['EmpheqMO', ']'],
  125. empheqbiglangle: ['EmpheqMO', '\u27E8'],
  126. empheqbigrangle: ['EmpheqMO', '\u27E9'],
  127. empheqbiglparen: ['EmpheqMO', '('],
  128. empheqbigrparen: ['EmpheqMO', ')'],
  129. empheqbiglvert: ['EmpheqMO', '|'],
  130. empheqbigrvert: ['EmpheqMO', '|'],
  131. empheqbiglVert: ['EmpheqMO', '\u2016'],
  132. empheqbigrVert: ['EmpheqMO', '\u2016'],
  133. empheqbiglfloor: ['EmpheqMO', '\u230A'],
  134. empheqbigrfloor: ['EmpheqMO', '\u230B'],
  135. empheqbiglceil: ['EmpheqMO', '\u2308'],
  136. empheqbigrceil: ['EmpheqMO', '\u2309'],
  137. empheql: 'EmpheqDelim',
  138. empheqr: 'EmpheqDelim',
  139. empheqbigl: 'EmpheqDelim',
  140. empheqbigr: 'EmpheqDelim'
  141. }, exports.EmpheqMethods);
  142. exports.EmpheqConfiguration = Configuration_js_1.Configuration.create('empheq', {
  143. handler: {
  144. macro: ['empheq-macros'],
  145. environment: ['empheq-env'],
  146. },
  147. items: (_a = {},
  148. _a[EmpheqBeginItem.prototype.kind] = EmpheqBeginItem,
  149. _a)
  150. });
  151. //# sourceMappingURL=EmpheqConfiguration.js.map