A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/KaTeX/KaTeX/commit/1f43c84a175fb689f8c8d1d72b1e8b896a8b43d1 below:

\relax in base or exponent of super/subscript (#4045) · KaTeX/KaTeX@1f43c84 · GitHub

File tree Expand file treeCollapse file tree 3 files changed

+29

-1

lines changed

Filter options

Expand file treeCollapse file tree 3 files changed

+29

-1

lines changed Original file line number Diff line number Diff line change

@@ -211,6 +211,7 @@ export default class Parser {

211 211

if (!atom) {

212 212

break;

213 213

} else if (atom.type === "internal") {

214 +

// Internal nodes do not appear in parse tree

214 215

continue;

215 216

}

216 217

body.push(atom);

@@ -286,7 +287,12 @@ export default class Parser {

286 287

const symbol = symbolToken.text;

287 288

this.consume();

288 289

this.consumeSpaces(); // ignore spaces before sup/subscript argument

289 -

const group = this.parseGroup(name);

290 + 291 +

// Skip over allowed internal nodes such as \relax

292 +

let group: ?AnyParseNode;

293 +

do {

294 +

group = this.parseGroup(name);

295 +

} while (group?.type === "internal");

290 296 291 297

if (!group) {

292 298

throw new ParseError(

@@ -333,6 +339,12 @@ export default class Parser {

333 339

// \left(x\right)^2 work correctly.

334 340

const base = this.parseGroup("atom", breakOnTokenText);

335 341 342 +

// Internal nodes (e.g. \relax) cannot support super/subscripts.

343 +

// Instead we will pick up super/subscripts with blank base next round.

344 +

if (base?.type === "internal") {

345 +

return base;

346 +

}

347 + 336 348

// In text mode, we don't have superscripts or subscripts

337 349

if (this.mode === "text") {

338 350

return base;

Original file line number Diff line number Diff line change

@@ -7,6 +7,7 @@ defineFunction({

7 7

props: {

8 8

numArgs: 0,

9 9

allowedInText: true,

10 +

allowedInArgument: true,

10 11

},

11 12

handler({parser}) {

12 13

return {

Original file line number Diff line number Diff line change

@@ -280,6 +280,15 @@ describe("A subscript and superscript parser", function() {

280 280

it("should work with Unicode (sub|super)script characters", function() {

281 281

expect`A² + B²⁺³ + ¹²C + E₂³ + F₂₊₃`.toParseLike`A^{2} + B^{2+3} + ^{12}C + E_{2}^{3} + F_{2+3}`;

282 282

});

283 + 284 +

it("should not fail if \\relax is in an atom", function() {

285 +

expect`\hskip1em\relax^2`.toParse(strictSettings);

286 +

});

287 + 288 +

it("should skip \\relax in super/subscripts", function() {

289 +

expect`x^\relax 2`.toParseLike`x^2`;

290 +

expect`x_\relax 2`.toParseLike`x_2`;

291 +

});

283 292

});

284 293 285 294

describe("A subscript and superscript tree-builder", function() {

@@ -3337,6 +3346,12 @@ describe("A macro expander", function() {

3337 3346

}}));

3338 3347

});

3339 3348 3349 +

it("should treat \\relax as empty argument", function() {

3350 +

expect`\text{\foo\relax x}`.toParseLike(r`\text{(,x)}`, new Settings({macros: {

3351 +

"\\foo": "(#1,#2)",

3352 +

}}));

3353 +

});

3354 + 3340 3355

it("should allow for space second argument (math version)", function() {

3341 3356

expect`\foo\bar\bar`.toParseLike("(,)", new Settings({macros: {

3342 3357

"\\foo": "(#1,#2)",

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4