Skip to content

Commit c54a989

Browse files
committed
Improve comments, as request in code review.
1 parent 15e4d13 commit c54a989

2 files changed

Lines changed: 29 additions & 12 deletions

File tree

ts/input/tex/base/BaseConfiguration.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,32 @@ function envUndefined(_parser: TexParser, env: string) {
9898
function filterNonscript({data}: {data: ParseOptions}) {
9999
for (const mml of data.getList('nonscript')) {
100100
//
101-
// If we are in script or script-script style
102-
// remove the space (either mspace or mrow containing it)
103-
// and remove it (and its contents) from the other lists.
104-
// Otherwise, if it is an mrow (which we added),
105-
// replace the mrow with its contents
106-
// and remove it from its list
101+
// This is the list of mspace elements or mrow > mstyle > mspace
102+
// that followed \nonscript macros to be tested for removal.
107103
//
108104
if (mml.attributes.get('scriptlevel') > 0) {
105+
//
106+
// The mspace needs to be removed, since we are in a script style.
107+
// Remove it from the DOM and from the list of mspace elements.
108+
//
109109
const parent = mml.parent;
110110
parent.childNodes.splice(parent.childIndex(mml), 1);
111111
data.removeFromList(mml.kind, [mml]);
112+
//
113+
// If it is an mrow > mstyle > mspace, then we have just
114+
// removed the mrow from its list, and must remove
115+
// the mstyle and mspace from their lists as well.
116+
//
112117
if (mml.isKind('mrow')) {
113118
const mstyle = mml.childNodes[0] as MmlNode;
114119
data.removeFromList('mstyle', [mstyle]);
115120
data.removeFromList('mspace', mstyle.childNodes[0].childNodes as MmlNode[]);
116121
}
117122
} else if (mml.isKind('mrow')) {
123+
//
124+
// This is an mrow > mstyle > mspace but we're not in a script
125+
// style, so remove the mrow that we had added in the NonscriptItem.
126+
//
118127
mml.parent.replaceChild(mml.childNodes[0], mml);
119128
data.removeFromList('mrow', [mml]);
120129
}

ts/input/tex/base/BaseItems.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,9 @@ export class NotItem extends BaseItem {
774774
}
775775
}
776776

777+
/**
778+
* A StackItem that removes an mspace that follows it (for \nonscript).
779+
*/
777780
export class NonscriptItem extends BaseItem {
778781

779782
/**
@@ -787,25 +790,30 @@ export class NonscriptItem extends BaseItem {
787790
* @override
788791
*/
789792
public checkItem(item: StackItem): CheckType {
793+
//
794+
// Check if the next item is an mspace (or an mspace in an mstyle) and remove it.
795+
//
790796
if (item.isKind('mml') && item.Size() === 1) {
791797
let mml = item.First;
792798
//
793-
// Space macros like \, wrap with an mstyle to set scriptlevel=0 (so size is independent of level)
799+
// Space macros like \, are wrapped with an mstyle to set scriptlevel="0"
800+
// (so size is independent of level), we look at the contents of the mstyle for the mspace.
794801
//
795802
if (mml.isKind('mstyle') && mml.notParent) {
796803
mml = NodeUtil.getChildren(NodeUtil.getChildren(mml)[0])[0];
797804
}
798805
if (mml.isKind('mspace')) {
799806
//
800-
// If the space is in an mstyle, wrap it in an mrow so we can test is scriptlevel.
801-
// The mrow will be removed in the post-filter.
807+
// If the space is in an mstyle, wrap it in an mrow so we can test its scriptlevel
808+
// in the post-filter (the mrow will be removed in the filter). We can't test
809+
// the mstyle's scriptlevel, since it is ecxplicitly setting it to 0.
802810
//
803811
if (mml !== item.First) {
804-
mml = this.create('node', 'mrow', [item.Pop()]);
805-
item.Push(mml);
812+
const mrow = this.create('node', 'mrow', [item.Pop()]);
813+
item.Push(mrow);
806814
}
807815
//
808-
// Save the item for alter post-processing
816+
// Save the mspace for later post-processing.
809817
//
810818
this.factory.configuration.addNode('nonscript', item.First);
811819
}

0 commit comments

Comments
 (0)