Skip to content

Add \noscript command#710

Merged
dpvc merged 2 commits intodevelopfrom
nonscript
Jun 8, 2021
Merged

Add \noscript command#710
dpvc merged 2 commits intodevelopfrom
nonscript

Conversation

@dpvc
Copy link
Copy Markdown
Member

@dpvc dpvc commented May 22, 2021

This PR implements the \nonscript command, which removes the following spacing command (like \hskip, \kern, \hspace, etc.). This is used int macro definitions to handle not use spacing in scripts, when given explicitly.

This is handled by using a new StackItem for the \nonscript that checks what is pushed after it, and if an mspace (or an mspace inside an mstyle, as produced by \, and similar macros), then we add the space into a list to be post-filtered (once the scriptlevel is known). The case of am mstyle containing an mspace is handled by wrapping it in an mrow so that we can test the scriptlevel (since the mstyle will have scriptlevel="0" set). The mrow is removed in the post-filter if the space is being retained (otherwise the mrow together with its contents are removed).

@dpvc dpvc requested a review from zorkow May 22, 2021 17:25
@dpvc dpvc added this to the 3.2 milestone May 22, 2021
Base automatically changed from issue2691 to develop June 1, 2021 12:51
Copy link
Copy Markdown
Member

@zorkow zorkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused about the item (and the subsequent filter method). Please see my comments.

Comment thread ts/input/tex/base/BaseItems.ts Outdated
}
if (mml.isKind('mspace')) {
//
// If the space is in an mstyle, wrap it in an mrow so we can test is scriptlevel.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Comment thread ts/input/tex/base/BaseItems.ts Outdated
item.Push(mml);
}
//
// Save the item for alter post-processing
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Comment thread ts/input/tex/base/BaseItems.ts
Comment thread ts/input/tex/base/BaseItems.ts Outdated
}
if (mml.isKind('mspace')) {
//
// If the space is in an mstyle, wrap it in an mrow so we can test is scriptlevel.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the comment was source of confusion for me. Effectively this if will only fire, if the previous unwrapping if has fired.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it can also fire if there is an explicit mspace, e.g., from \hskip or \kern.

Copy link
Copy Markdown
Member

@zorkow zorkow Jun 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant the if below.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this if only happens with the first if, true.

Comment thread ts/input/tex/base/BaseItems.ts Outdated
if (item.isKind('mml') && item.Size() === 1) {
let mml = item.First;
//
// Space macros like \, wrap with an mstyle to set scriptlevel=0 (so size is independent of level)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo wrapped?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, "are wrapped" is probably better.

//
this.factory.configuration.addNode('nonscript', item.First);
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see from my comments above, I find the structure very confusing.
So what do we want to do?

  • Any space should be marked as nonscript
  • If the space is wrapped in an mstyle we want to give it an extra mrow and mark that.
    (There is no possibility that it is wrapped in multiple mstyles?)

Can you restructure the code somewhat to reflect this, even if it introduces some duplications? And/or update the comments?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll see what I can do.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what confused me most here is that they are all called mml.

Comment thread ts/input/tex/base/BaseConfiguration.ts Outdated
for (const mml of data.getList('nonscript')) {
//
// If we are in script or script-script style
// remove the space (either mspace or mrow containing it)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand the item correctly, if the item is an mrow then we have added it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Since only actual mspace elements or the mrow elements that we added above ever get added to the nonscript list, if we have an mrow, we know it is one that we added.

Copy link
Copy Markdown
Member

@zorkow zorkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanations. I think good commenting/structuring for items is important to preserve understanding what they do. Having refactored many item objects and often spent some time working through all the cases, I know what I am talking about (Of course this is only a sample set of one. Still...)
I make a couple of suggestions in code.

Copy link
Copy Markdown
Member

@zorkow zorkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a few suggested comments for the post filter method.

Comment thread ts/input/tex/base/BaseConfiguration.ts
Comment thread ts/input/tex/base/BaseConfiguration.ts
Comment thread ts/input/tex/base/BaseConfiguration.ts
@dpvc
Copy link
Copy Markdown
Member Author

dpvc commented Jun 3, 2021

@zorkow, OK, I've added more comments that I hope will help the situation. See if that fits the bill.

@dpvc dpvc requested a review from zorkow June 3, 2021 12:24
Copy link
Copy Markdown
Member

@zorkow zorkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that makes it a lot clearer.

@dpvc dpvc merged commit 53b13c0 into develop Jun 8, 2021
@dpvc dpvc deleted the nonscript branch June 8, 2021 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants