Skip to content

Commit 37d7c41

Browse files
committed
Fix incorrect removal of braces in template macros
1 parent 351698e commit 37d7c41

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

testsuite/tests/input/tex/Newcommand.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,28 @@ describe('Newcommand', () => {
552552

553553
/********************************************************************************/
554554

555+
it('Def Template Brace Removal', () => {
556+
toXmlMatch(
557+
tex2mml('\\def\\test#1\\end{\\text{#1}} \\test{a b}\\end'),
558+
`<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="\\def\\test#1\\end{\\text{#1}} \\test{a b}\\end" display="block">
559+
<mtext data-latex="\\text{a b}">a b</mtext>
560+
</math>`
561+
);
562+
});
563+
564+
/********************************************************************************/
565+
566+
it('Def Template Brace Retention', () => {
567+
toXmlMatch(
568+
tex2mml('\\def\\test#1\\end{\\text{#1}} \\test{a}{b}\\end'),
569+
`<math xmlns="http://www.w3.org/1998/Math/MathML" data-latex="\\def\\test#1\\end{\\text{#1}} \\test{a}{b}\\end" display="block">
570+
<mtext data-latex="\\text{{a}{b}}">{a}{b}</mtext>
571+
</math>`
572+
);
573+
});
574+
575+
/********************************************************************************/
576+
555577
it('Def Hash Replacement', () => {
556578
toXmlMatch(
557579
tex2mml('\\def\\x#1{\\def\\y##1#1{[##1]}\\y} \\x\\X abc \\X'),

ts/input/tex/newcommand/NewcommandUtil.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,13 @@ export const NewcommandUtil = {
200200
}
201201
let i = parser.i;
202202
let j = 0;
203-
let hasBraces = 0;
203+
let hasBraces = false;
204204
while (parser.i < parser.string.length) {
205205
const c = parser.string.charAt(parser.i);
206206
// @test Def Let, Def Optional Brace, Def Options CS
207207
if (c === '{') {
208208
// @test Def Optional Brace, Def Options CS
209-
if (parser.i === i) {
210-
// @test Def Optional Brace
211-
hasBraces = 1;
212-
}
209+
hasBraces = parser.i === i;
213210
parser.GetArgument(name);
214211
j = parser.i - i;
215212
} else if (this.MatchParam(parser, param)) {
@@ -224,7 +221,7 @@ export const NewcommandUtil = {
224221
// @test Def Options CS
225222
parser.i++;
226223
j++;
227-
hasBraces = 0;
224+
hasBraces = false;
228225
const match = parser.string.substring(parser.i).match(/[a-z]+|./i);
229226
if (match) {
230227
// @test Def Options CS
@@ -235,7 +232,7 @@ export const NewcommandUtil = {
235232
// @test Def Let
236233
parser.i++;
237234
j++;
238-
hasBraces = 0;
235+
hasBraces = false;
239236
}
240237
}
241238
// @test Runaway Argument

0 commit comments

Comments
 (0)