Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problem with let using attributes of {} when they should be null #1030

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

dpvc
Copy link
Member

@dpvc dpvc commented Dec 10, 2023

The current disassembleToken() and assembleToken() methods produce a new token whose attributes are {} when the original had null attributes. This has implications for some tokens where the difference between these are important, as in the mathchar7 function at

export function mathchar7(parser: TexParser, mchar: Token) {
const def = mchar.attributes || {mathvariant: MATHVARIANT.NORMAL};
if (parser.stack.env['font']) {
// @test MathChar7 Single Font
def['mathvariant'] = parser.stack.env['font'];
}
// @test MathChar7 Single, MathChar7 Operator, MathChar7 Multi
const node = parser.create('token', 'mi', def, mchar.char);
parser.Push(node);
}

where line 157 provides a default attribute list when math.attributes is null (but not if it is an empty object).

This leads to the loss of the default attributes when a new control sequence is \let equal to one that uses mathchar7, as in

\let\percent=\%
\percent\%

where the result of \percent will be in italics, while \% will not.

This PR resolves the issue by actually eliminating disassembleToken() and assembleToken() and just using the original token directly in the method at new line 137 (via the same closure that preserves map).

@dpvc dpvc requested a review from zorkow December 10, 2023 13:04
@dpvc dpvc added this to the v4.0 milestone Dec 10, 2023
Copy link
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.

Looks good. Works for all my tests.

@dpvc dpvc merged commit 0a8a8b4 into develop Dec 20, 2023
@dpvc dpvc deleted the fix-let branch December 20, 2023 22:06
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