Skip to content

Commit 9cae258

Browse files
committed
Comments all the stack items in detail.
1 parent b996e55 commit 9cae258

File tree

5 files changed

+100
-12
lines changed

5 files changed

+100
-12
lines changed

mathjax3-ts/input/tex/StackItem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export interface StackItem extends NodeStack {
234234
isOpen: boolean;
235235

236236
/**
237-
* Is this a finalising item, e.g., end.
237+
* Is this a finalising item, i.e., one that only collects nodes.
238238
* @type {boolean}
239239
*/
240240
isFinal: boolean;
@@ -306,7 +306,7 @@ export interface StackItem extends NodeStack {
306306
}
307307

308308
export interface StackItemClass {
309-
new (factory: StackItemFactory, ...nodes: MmlNode[]): StackItem;
309+
new (factory: StackItemFactory, ...args: any[]): StackItem;
310310
}
311311

312312

mathjax3-ts/input/tex/ams/AmsItems.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ import TexError from '../TexError.js';
3333
import {TexConstant} from '../TexConstants.js';
3434

3535

36+
/**
37+
* Item dealing with multiline environments as a special case of arrays. Note,
38+
* that all other AMS equation environments (e.g., align, split) can be handled
39+
* by the regular EqnArrayItem class.
40+
*
41+
* Handles tagging information according to the given tagging style.
42+
*/
3643
export class MultlineItem extends ArrayItem {
3744

3845
/**

mathjax3-ts/input/tex/base/BaseItems.ts

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
/*************************************************************
2-
*
3-
* MathJax/jax/input/TeX/BaseItems.ts
4-
*
5-
* Implements the TeX InputJax that reads mathematics in
6-
* TeX and LaTeX format and converts it to the MML ElementJax
7-
* internal format.
8-
*
9-
* ---------------------------------------------------------------------
102
*
113
* Copyright (c) 2009-2018 The MathJax Consortium
124
*
@@ -45,14 +37,17 @@ import StackItemFactory from '../StackItemFactory.js';
4537
import {BaseItem, StackItem, EnvList} from '../StackItem.js';
4638

4739

40+
41+
/**
42+
* Initial item on the stack. It's pushed when parsing begins.
43+
*/
4844
export class StartItem extends BaseItem {
4945

5046
/**
5147
* @override
5248
*/
53-
constructor(factory: StackItemFactory, ...global: any[]) {
49+
constructor(factory: StackItemFactory, public global: EnvList) {
5450
super(factory);
55-
this.global = global[0] as EnvList;
5651
}
5752

5853

@@ -87,6 +82,11 @@ export class StartItem extends BaseItem {
8782

8883
}
8984

85+
86+
/**
87+
* Final item on the stack. Errors will be thrown if other items than the start
88+
* item are still on the stack.
89+
*/
9090
export class StopItem extends BaseItem {
9191

9292
/**
@@ -106,6 +106,10 @@ export class StopItem extends BaseItem {
106106

107107
}
108108

109+
110+
/**
111+
* Item indicating an open brace.
112+
*/
109113
export class OpenItem extends BaseItem {
110114

111115
/**
@@ -148,6 +152,9 @@ export class OpenItem extends BaseItem {
148152
}
149153

150154

155+
/**
156+
* Item indicating an close brace. Collapses stack until an OpenItem is found.
157+
*/
151158
export class CloseItem extends BaseItem {
152159

153160
/**
@@ -168,6 +175,9 @@ export class CloseItem extends BaseItem {
168175
}
169176

170177

178+
/**
179+
* Item indicating an we are currently dealing with a prime mark.
180+
*/
171181
export class PrimeItem extends BaseItem {
172182

173183
/**
@@ -192,6 +202,11 @@ export class PrimeItem extends BaseItem {
192202
}
193203
}
194204

205+
206+
/**
207+
* Item indicating an we are currently dealing with a sub/superscript
208+
* expression.
209+
*/
195210
export class SubsupItem extends BaseItem {
196211

197212
/**
@@ -255,6 +270,10 @@ export class SubsupItem extends BaseItem {
255270

256271
}
257272

273+
274+
/**
275+
* Item indicating an we are currently dealing with an \\over command.
276+
*/
258277
export class OverItem extends BaseItem {
259278

260279
/**
@@ -322,6 +341,10 @@ export class OverItem extends BaseItem {
322341

323342
}
324343

344+
345+
/**
346+
* Item pushed when a \\left opening delimiter has been found.
347+
*/
325348
export class LeftItem extends BaseItem {
326349

327350
/**
@@ -367,6 +390,11 @@ export class LeftItem extends BaseItem {
367390

368391
}
369392

393+
394+
/**
395+
* Item pushed when a \\right closing delimiter has been found. Stack is
396+
* collapsed until a corresponding LeftItem is encountered.
397+
*/
370398
export class RightItem extends BaseItem {
371399

372400
/**
@@ -394,6 +422,10 @@ export class RightItem extends BaseItem {
394422

395423
}
396424

425+
426+
/**
427+
* Item pushed for opening an environment with \\begin{env}.
428+
*/
397429
export class BeginItem extends BaseItem {
398430

399431
/**
@@ -435,6 +467,12 @@ export class BeginItem extends BaseItem {
435467

436468
}
437469

470+
471+
/**
472+
* Item pushed for closing an environment with \\end{env}. Stack is collapsed
473+
* until a corresponding BeginItem for 'env' is found. Error is thrown in case
474+
* other open environments interfere.
475+
*/
438476
export class EndItem extends BaseItem {
439477

440478
/**
@@ -454,6 +492,10 @@ export class EndItem extends BaseItem {
454492

455493
}
456494

495+
496+
/**
497+
* Item pushed for remembering styling information.
498+
*/
457499
export class StyleItem extends BaseItem {
458500

459501
/**
@@ -477,6 +519,10 @@ export class StyleItem extends BaseItem {
477519

478520
}
479521

522+
523+
/**
524+
* Item pushed for remembering positioning information.
525+
*/
480526
export class PositionItem extends BaseItem {
481527

482528
/**
@@ -516,6 +562,9 @@ export class PositionItem extends BaseItem {
516562
}
517563

518564

565+
/**
566+
* Item indicating a table cell.
567+
*/
519568
export class CellItem extends BaseItem {
520569

521570
/**
@@ -535,6 +584,9 @@ export class CellItem extends BaseItem {
535584
}
536585

537586

587+
/**
588+
* Final item for collating Nodes.
589+
*/
538590
export class MmlItem extends BaseItem {
539591

540592
/**
@@ -554,6 +606,9 @@ export class MmlItem extends BaseItem {
554606
}
555607

556608

609+
/**
610+
* Item indicating a named function operator (e.g., \\sin) as been encountered.
611+
*/
557612
export class FnItem extends BaseItem {
558613

559614
/**
@@ -606,6 +661,11 @@ export class FnItem extends BaseItem {
606661
}
607662
}
608663

664+
665+
/**
666+
* Item indicating a \\not has been encountered and needs to be applied to the
667+
* next operator.
668+
*/
609669
export class NotItem extends BaseItem {
610670

611671
private remap = MapHandler.getMap('not_remap') as CharacterMap;
@@ -658,6 +718,9 @@ export class NotItem extends BaseItem {
658718
}
659719

660720

721+
/**
722+
* Item indicating a dots command has been encountered.
723+
*/
661724
export class DotsItem extends BaseItem {
662725

663726
/**
@@ -688,6 +751,10 @@ export class DotsItem extends BaseItem {
688751
}
689752

690753

754+
/**
755+
* Item indicating an array is assembled. It collates cells, rows and
756+
* information about column/row separator and framing lines.
757+
*/
691758
export class ArrayItem extends BaseItem {
692759

693760
/**
@@ -892,6 +959,10 @@ export class ArrayItem extends BaseItem {
892959
}
893960

894961

962+
/**
963+
* Item dealing with equation arrays as a special case of arrays. Handles
964+
* tagging information according to the given tagging style.
965+
*/
895966
export class EqnArrayItem extends ArrayItem {
896967

897968
/**
@@ -952,6 +1023,10 @@ export class EqnArrayItem extends ArrayItem {
9521023
}
9531024

9541025

1026+
/**
1027+
* Item dealing with simple equation environments. Handles tagging information
1028+
* according to the given tagging style.
1029+
*/
9551030
export class EquationItem extends BaseItem {
9561031

9571032
/**

mathjax3-ts/input/tex/base/BaseMethods.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,7 @@ BaseMethods.BeginEnd = function(parser: TexParser, name: string) {
13601360
parser.Push(mml);
13611361
return;
13621362
}
1363+
// Remember the user defined environment we are closing.
13631364
parser.stack.env['closing'] = env;
13641365
}
13651366
if (++parser.macroCount > parser.configuration.options['maxMacros']) {

mathjax3-ts/input/tex/newcommand/NewcommandItems.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ import ParseUtil from '../ParseUtil.js';
3131
import {MmlNode, TextNode} from '../../../core/MmlTree/MmlNode.js';
3232

3333

34+
/**
35+
* Opening Item dealing with definitions of new environments. It's pushed onto
36+
* the stack whenever a user defined environment is encountered and remains
37+
* until a corresponding \\end collapses the stack.
38+
*/
3439
export class BeginEnvItem extends BaseItem {
3540

3641
/**

0 commit comments

Comments
 (0)