Skip to content

Commit e748578

Browse files
ronkokedemaine
andauthored
fix: \sout in text mode (#4173)
Co-authored-by: Erik Demaine <edemaine@mit.edu>
1 parent f3977a0 commit e748578

12 files changed

Lines changed: 46 additions & 11 deletions

contrib/render-a11y-string/test/render-a11y-string-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ describe("renderA11yString", () => {
143143
});
144144

145145
test("\\sout", () => {
146-
const result = renderA11yString("\\sout{a}");
146+
const result = renderA11yString("\\text{\\sout{a}}");
147147
expect(result).toMatchInlineSnapshot(
148-
`"start strikeout, a, end strikeout"`,
148+
`"start text, start strikeout, a, end strikeout, end text"`,
149149
);
150150
});
151151
});

docs/support_table.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ use `\ce` instead|
989989
|\smash|$\left(x^{\smash{2}}\right)$|`\left(x^{\smash{2}}\right)`|
990990
|\smile|$\smile$||
991991
|\smiley|<span style="color:firebrick;">Not supported</span>||
992-
|\sout|$\sout{abc}$|`\sout{abc}`|
992+
|\sout|$\text{\sout{abc}}$|`\text{\sout{abc}}`|
993993
|\Space|<span style="color:firebrick;">Not supported</span>|see `\space`
994994
|\space|$a\space b$|`a\space b`|
995995
|\spades|$\spades$||

docs/supported.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ Any character can be written with the `\char` function and the Unicode code in h
237237
|$\cancel{5}$ `\cancel{5}`|$\overbrace{a+b+c}^{\text{note}}$ `\overbrace{a+b+c}^{\text{note}}`
238238
|$\bcancel{5}$ `\bcancel{5}` |$\underbrace{a+b+c}_{\text{note}}$ `\underbrace{a+b+c}_{\text{note}}`
239239
|$\xcancel{ABC}$ `\xcancel{ABC}`|$\not =$ `\not =`
240-
|$\sout{abc}$ `\sout{abc}`|$\boxed{\pi=\frac c d}$ `\boxed{\pi=\frac c d}`
240+
|$\text{\sout{abc}}$ `\text{\sout{abc}}`|$\boxed{\pi=\frac c d}$ `\boxed{\pi=\frac c d}`
241241
|$a_{\angl n}$ `$a_{\angl n}`|$a_\angln$ `a_\angln`
242242
|$\phase{-78^\circ}$`\phase{-78^\circ}` |
243243

src/functions/enclose.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ defineFunction({
286286

287287
defineFunction({
288288
type: "enclose",
289-
names: ["\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\phase"],
289+
names: ["\\cancel", "\\bcancel", "\\xcancel", "\\phase"],
290290
props: {
291291
numArgs: 1,
292292
},
@@ -303,6 +303,30 @@ defineFunction({
303303
mathmlBuilder,
304304
});
305305

306+
defineFunction({
307+
type: "enclose",
308+
names: ["\\sout"],
309+
props: {
310+
numArgs: 1,
311+
allowedInText: true,
312+
},
313+
handler({parser, funcName}, args) {
314+
if (parser.mode === "math") {
315+
parser.settings.reportNonstrict("mathVsSout",
316+
`LaTeX's \\sout works only in text mode`);
317+
}
318+
const body = args[0];
319+
return {
320+
type: "enclose",
321+
mode: parser.mode,
322+
label: funcName,
323+
body,
324+
};
325+
},
326+
htmlBuilder,
327+
mathmlBuilder,
328+
});
329+
306330
defineFunction({
307331
type: "enclose",
308332
names: ["\\angl"],

test/katex-spec.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,10 +2773,11 @@ describe("A strike-through builder", function() {
27732773
expect`\cancel{x}^2`.toBuild();
27742774
expect`\cancel{x}_2`.toBuild();
27752775
expect`\cancel{x}_2^2`.toBuild();
2776-
expect`\sout{x}`.toBuild();
2777-
expect`\sout{x}^2`.toBuild();
2778-
expect`\sout{x}_2`.toBuild();
2779-
expect`\sout{x}_2^2`.toBuild();
2776+
expect`\sout{x}`.toBuild(nonstrictSettings);
2777+
expect`\sout{x}^2`.toBuild(nonstrictSettings);
2778+
expect`\sout{x}_2`.toBuild(nonstrictSettings);
2779+
expect`\sout{x}_2^2`.toBuild(nonstrictSettings);
2780+
expect`\text{\sout{abc}}`.toBuild();
27802781
});
27812782
27822783
it("should produce mords", function() {
@@ -2788,6 +2789,16 @@ describe("A strike-through builder", function() {
27882789
});
27892790
});
27902791
2792+
describe("A \\sout parser", function() {
2793+
it("should work in text mode", function() {
2794+
expect`\text{\sout{abc}}`.toParse();
2795+
});
2796+
2797+
it("should fail in math mode with strict settings", function() {
2798+
expect`\sout{x}`.not.toParse(strictSettings);
2799+
});
2800+
});
2801+
27912802
describe("A actuarial angle parser", function() {
27922803
it("should not fail in math mode", function() {
27932804
expect`a_{\angl{n}}`.toParse();
-396 Bytes
Loading
-501 Bytes
Loading
72 Bytes
Loading
-926 Bytes
Loading
-1.3 KB
Loading

0 commit comments

Comments
 (0)