BraketMethods.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. var BaseMethods_js_1 = __importDefault(require("../base/BaseMethods.js"));
  7. var MmlNode_js_1 = require("../../../core/MmlTree/MmlNode.js");
  8. var TexError_js_1 = __importDefault(require("../TexError.js"));
  9. var BraketMethods = {};
  10. BraketMethods.Macro = BaseMethods_js_1.default.Macro;
  11. BraketMethods.Braket = function (parser, _name, open, close, stretchy, barmax) {
  12. var next = parser.GetNext();
  13. if (next === '') {
  14. throw new TexError_js_1.default('MissingArgFor', 'Missing argument for %1', parser.currentCS);
  15. }
  16. var single = true;
  17. if (next === '{') {
  18. parser.i++;
  19. single = false;
  20. }
  21. parser.Push(parser.itemFactory.create('braket')
  22. .setProperties({ barmax: barmax, barcount: 0, open: open,
  23. close: close, stretchy: stretchy, single: single }));
  24. };
  25. BraketMethods.Bar = function (parser, name) {
  26. var c = name === '|' ? '|' : '\u2225';
  27. var top = parser.stack.Top();
  28. if (top.kind !== 'braket' ||
  29. top.getProperty('barcount') >= top.getProperty('barmax')) {
  30. var mml = parser.create('token', 'mo', { texClass: MmlNode_js_1.TEXCLASS.ORD, stretchy: false }, c);
  31. parser.Push(mml);
  32. return;
  33. }
  34. if (c === '|' && parser.GetNext() === '|') {
  35. parser.i++;
  36. c = '\u2225';
  37. }
  38. var stretchy = top.getProperty('stretchy');
  39. if (!stretchy) {
  40. var node_1 = parser.create('token', 'mo', { stretchy: false, braketbar: true }, c);
  41. parser.Push(node_1);
  42. return;
  43. }
  44. var node = parser.create('node', 'TeXAtom', [], { texClass: MmlNode_js_1.TEXCLASS.CLOSE });
  45. parser.Push(node);
  46. top.setProperty('barcount', top.getProperty('barcount') + 1);
  47. node = parser.create('token', 'mo', { stretchy: true, braketbar: true }, c);
  48. parser.Push(node);
  49. node = parser.create('node', 'TeXAtom', [], { texClass: MmlNode_js_1.TEXCLASS.OPEN });
  50. parser.Push(node);
  51. };
  52. exports.default = BraketMethods;
  53. //# sourceMappingURL=BraketMethods.js.map