Skip to content

Commit 0e08352

Browse files
edemainepzinnronkok
authored
fix: \vdots and \rule support in text mode (#3997)
* fix #3990 * Unify math and text \vdots, allow \rule in text mode * Add text-mode `\rule` test --------- Co-authored-by: pzinn <pzinnjustin@gmail.com> Co-authored-by: Ron Kok <ronkok55@outlook.com>
1 parent c47d158 commit 0e08352

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

src/functions/rule.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ defineFunction({
1111
props: {
1212
numArgs: 2,
1313
numOptionalArgs: 1,
14+
allowedInText: true,
15+
allowedInMath: true,
1416
argTypes: ["size", "size", "size"],
1517
},
1618
handler({parser}, args, optArgs) {

src/macros.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ defineMacro("\\lrcorner", "\\html@mathml{\\@lrcorner}{\\mathop{\\char\"231f}}");
341341
// \kern6\p@\hbox{.}\hbox{.}\hbox{.}}}
342342
// We'll call \varvdots, which gets a glyph from symbols.js.
343343
// The zero-width rule gets us an equivalent to the vertical 6pt kern.
344-
defineMacro("\\vdots", "\\mathord{\\varvdots\\rule{0pt}{15pt}}");
344+
defineMacro("\\vdots", "{\\varvdots\\rule{0pt}{15pt}}");
345345
defineMacro("\u22ee", "\\vdots");
346346

347347
//////////////////////////////////////////////////////////////////////

src/symbols.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,9 @@ defineSymbol(text, main, inner, "\u2026", "\\ldots", true);
673673
defineSymbol(math, main, inner, "\u2026", "\\ldots", true);
674674
defineSymbol(math, main, inner, "\u22ef", "\\@cdots", true);
675675
defineSymbol(math, main, inner, "\u22f1", "\\ddots", true);
676-
defineSymbol(math, main, textord, "\u22ee", "\\varvdots"); // \vdots is a macro
676+
// \vdots is a macro that uses one of these two symbols (with made-up names):
677+
defineSymbol(math, main, textord, "\u22ee", "\\varvdots");
678+
defineSymbol(text, main, textord, "\u22ee", "\\varvdots");
677679
defineSymbol(math, main, accent, "\u02ca", "\\acute");
678680
defineSymbol(math, main, accent, "\u02cb", "\\grave");
679681
defineSymbol(math, main, accent, "\u00a8", "\\ddot");

test/katex-spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,10 @@ describe("A text parser", function() {
807807
it("should omit spaces after commands", function() {
808808
expect`\text{\textellipsis !}`.toParseLike`\text{\textellipsis!}`;
809809
});
810+
811+
it("should handle ⋮ and \\vdots", function() {
812+
expect`\text{a \vdots b ⋮ d}`.toParse();
813+
});
810814
});
811815

812816
describe("A texvc builder", function() {
@@ -1065,6 +1069,10 @@ describe("A rule parser", function() {
10651069
expect(parse.width.number).toBeCloseTo(-1);
10661070
expect(parse.height.number).toBeCloseTo(-0.2);
10671071
});
1072+
1073+
it("should parse in text mode", function() {
1074+
expect(r`\text{a\rule{1em}{2em}b}`).toParse();
1075+
});
10681076
});
10691077

10701078
describe("A kern parser", function() {

0 commit comments

Comments
 (0)