MathtoolsItems.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*************************************************************
  2. * Copyright (c) 2020-2022 MathJax Consortium
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @fileoverview Implementation of items for the mathtools package.
  18. *
  19. * @author v.sorge@mathjax.org (Volker Sorge)
  20. * @author dpvc@mathjax.org (Davide P. Cervone)
  21. */
  22. import {MultlineItem} from '../ams/AmsItems.js';
  23. import NodeUtil from '../NodeUtil.js';
  24. import {TexConstant} from '../TexConstants.js';
  25. /**
  26. * The StackItem for the multlined environment
  27. */
  28. export class MultlinedItem extends MultlineItem {
  29. /**
  30. * @override
  31. */
  32. get kind() {
  33. return 'multlined';
  34. }
  35. /**
  36. * @override
  37. */
  38. public EndTable() {
  39. if (this.Size() || this.row.length) {
  40. this.EndEntry();
  41. this.EndRow();
  42. }
  43. if (this.table.length > 1) {
  44. const options = this.factory.configuration.options.mathtools;
  45. const gap = options.multlinegap;
  46. const firstskip = options['firstline-afterskip'] || gap;
  47. const lastskip = options['lastline-preskip'] || gap;
  48. const first = NodeUtil.getChildren(this.table[0])[0];
  49. if (NodeUtil.getAttribute(first, 'columnalign') !== TexConstant.Align.RIGHT) {
  50. first.appendChild(this.create('node', 'mspace', [], {width: firstskip}));
  51. }
  52. const last = NodeUtil.getChildren(this.table[this.table.length - 1])[0];
  53. if (NodeUtil.getAttribute(last, 'columnalign') !== TexConstant.Align.LEFT) {
  54. const top = NodeUtil.getChildren(last)[0];
  55. top.childNodes.unshift(null);
  56. const space = this.create('node', 'mspace', [], {width: lastskip});
  57. NodeUtil.setChild(top, 0, space);
  58. }
  59. }
  60. super.EndTable.call(this);
  61. }
  62. }