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 incorrect handling of user-defined environments introduced in #856 (#1137) #1139

Merged
merged 2 commits into from
Oct 10, 2024
Merged
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
31 changes: 17 additions & 14 deletions ts/input/tex/newcommand/NewcommandMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,20 @@ const NewcommandMethods: { [key: string]: ParseMethod } = {
if (begin.getProperty('end') && parser.stack.env['closing'] === name) {
// @test Newenvironment Empty, Newenvironment Content
delete parser.stack.env['closing'];
if (edef && parser.stack.env['processing'] !== name) {
// Parse the commands in the end environment definition, and do the \end again
parser.stack.env['processing'] = name;
parser.string = ParseUtil.addArgs(
parser,
`${edef}\\end{${begin.getName()}}`,
parser.string.slice(parser.i)
);
parser.i = 0;
return null;
const beginN = parser.stack.global['beginEnv'] as number;
if (beginN) {
(parser.stack.global['beginEnv'] as number)--;
if (edef) {
// Parse the commands in the end environment definition.
let rest = parser.string.slice(parser.i);
parser.string = edef;
parser.i = 0;
parser.Parse();
// Reset to parsing the remainder of the expression.
parser.string = rest;
parser.i = 0;
}
}
delete parser.stack.env['processing'];
// Close this environment.
return parser.itemFactory.create('end').setProperty('name', name);
}
Expand All @@ -277,12 +279,12 @@ const NewcommandMethods: { [key: string]: ParseMethod } = {
const args: string[] = [];
if (def != null) {
// @test Newenvironment Optional, Newenvironment Arg Optional
const optional = parser.GetBrackets('\\begin{' + begin.getName() + '}');
const optional = parser.GetBrackets(`\\begin{${name}}`);
args.push(optional == null ? def : optional);
}
for (let i = args.length; i < n; i++) {
// @test Newenvironment Arg Optional
args.push(parser.GetArgument('\\begin{' + begin.getName() + '}'));
args.push(parser.GetArgument(`\\begin{${name}}`));
}
bdef = ParseUtil.substituteArgs(parser, args, bdef);
edef = ParseUtil.substituteArgs(parser, [], edef); // no args, but get errors for #n in edef
Expand All @@ -293,9 +295,10 @@ const NewcommandMethods: { [key: string]: ParseMethod } = {
parser.string.slice(parser.i)
);
parser.i = 0;
parser.stack.global['beginEnv'] = (parser.stack.global['beginEnv'] as number || 0) + 1;
return parser.itemFactory
.create('beginEnv')
.setProperty('name', begin.getName());
.setProperty('name', name);
},

Macro: BaseMethods.Macro,
Expand Down