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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions ts/input/tex/newcommand/NewcommandMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,9 @@ NewcommandMethods.Let = function(parser: TexParser, name: string) {
return;
}
macro = (map as sm.CharacterMap).lookup(name) as Token;
const newArgs = NewcommandUtil.disassembleToken(cs, macro);
const method = (p: TexParser, _cs: string, ...rest: any[]) => {
// @test Let Relet, Let Let, Let Circular Macro
const symb = NewcommandUtil.assembleToken(rest);
return map.parser(p, symb);
};
NewcommandUtil.addMacro(parser, cs, method, newArgs);
// @test Let Relet, Let Let, Let Circular Macro
const method = (p: TexParser) => map.parser(p, macro);
NewcommandUtil.addMacro(parser, cs, method, [cs, macro.char]);
return;
}
// @test Let Brace Equal, Let Caret
Expand Down
42 changes: 0 additions & 42 deletions ts/input/tex/newcommand/NewcommandUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,48 +33,6 @@ import * as sm from '../TokenMap.js';

namespace NewcommandUtil {

/**
* Transforms the attributes of a token into the arguments of a macro. E.g.,
* Token('ell', 'l', {mathvariant: "italic"}) is turned into Macro arguments:
* ['ell', 'l', 'mathvariant', 'italic'].
*
* @param {string} name The command name for the token.
* @param {Token} token The token associated with name.
* @return {Args[]} Arguments for a macro.
*/
export function disassembleToken(name: string, token: Token): Args[] {
let newArgs = [name, token.char] as Args[];
// @test Let Relet, Let Let, Let Circular Macro
if (token.attributes) {
// @test Let Relet
for (let key in token.attributes) {
newArgs.push(key);
newArgs.push(token.attributes[key] as Args);
}
}
return newArgs;
}


/**
* Assembles a token from a list of macro arguments. This is the inverse
* method of the one above.
*
* @param {Args[]} args The arguments of the macro.
* @return {Token} The Token generated from the arguments..
*/
export function assembleToken(args: Args[]): Token {
// @test Let Relet, Let Let, Let Circular Macro
let name = args[0] as string;
let char = args[1] as string;
let attrs: Attributes = {};
for (let i = 2; i < args.length; i = i + 2) {
// @test Let Relet
attrs[args[i] as string] = args[i + 1];
}
return new Token(name, char, attrs);
}

/**
* Get the next CS name or give an error.
* @param {TexParser} parser The calling parser.
Expand Down