Repository: KaTeX/KaTeX (js)

Issue:
\text{⋮} causes error message
\text{⋮} will cause an error message:
KaTeX parse error: Can't use function '\mathord' in text mode at position 1: \̲m̲a̲t̲h̲o̲r̲d̲{\varvdots\rule…
other ellipsis unicode characters seem to work fine.

Pull request:
fix: `\vdots` and `\rule` support in text mode
**What is the previous behavior before this PR?**
`\vdots` and `\rule` worked only in math mode.

**What is the new behavior after this PR?**
`\vdots` and `\rule` work in text mode too, like LaTeX. See https://github.com/KaTeX/KaTeX/pull/3991#pullrequestreview-2487118382

Fixes #3990. Replaces #3991 to work around GitHub permissions. Thanks to @ronkok and @pzinn for authoring the original version.

Patch:
diff --git a/src/functions/rule.js b/src/functions/rule.js
index 005c1ba4..1cf85ac4 100644
--- a/src/functions/rule.js
+++ b/src/functions/rule.js
@@ -11,6 +11,8 @@ defineFunction({
     props: {
         numArgs: 2,
         numOptionalArgs: 1,
+        allowedInText: true,
+        allowedInMath: true,
         argTypes: ["size", "size", "size"],
     },
     handler({parser}, args, optArgs) {
diff --git a/src/macros.js b/src/macros.js
index feb7400b..a57989f2 100644
--- a/src/macros.js
+++ b/src/macros.js
@@ -341,7 +341,7 @@ defineMacro("\\lrcorner", "\\html@mathml{\\@lrcorner}{\\mathop{\\char\"231f}}");
 // \kern6\p@\hbox{.}\hbox{.}\hbox{.}}}
 // We'll call \varvdots, which gets a glyph from symbols.js.
 // The zero-width rule gets us an equivalent to the vertical 6pt kern.
-defineMacro("\\vdots", "\\mathord{\\varvdots\\rule{0pt}{15pt}}");
+defineMacro("\\vdots", "{\\varvdots\\rule{0pt}{15pt}}");
 defineMacro("\u22ee", "\\vdots");
 
 //////////////////////////////////////////////////////////////////////
diff --git a/src/symbols.js b/src/symbols.js
index 2d25337a..84086cd0 100644
--- a/src/symbols.js
+++ b/src/symbols.js
@@ -673,7 +673,9 @@ defineSymbol(text, main, inner, "\u2026", "\\ldots", true);
 defineSymbol(math, main, inner, "\u2026", "\\ldots", true);
 defineSymbol(math, main, inner, "\u22ef", "\\@cdots", true);
 defineSymbol(math, main, inner, "\u22f1", "\\ddots", true);
-defineSymbol(math, main, textord, "\u22ee", "\\varvdots"); // \vdots is a macro
+// \vdots is a macro that uses one of these two symbols (with made-up names):
+defineSymbol(math, main, textord, "\u22ee", "\\varvdots");
+defineSymbol(text, main, textord, "\u22ee", "\\varvdots");
 defineSymbol(math, main, accent, "\u02ca", "\\acute");
 defineSymbol(math, main, accent, "\u02cb", "\\grave");
 defineSymbol(math, main, accent, "\u00a8", "\\ddot");


Test patch:
diff --git a/test/katex-spec.js b/test/katex-spec.js
index a5b3ad2a..72b2e19c 100644
--- a/test/katex-spec.js
+++ b/test/katex-spec.js
@@ -807,6 +807,10 @@ describe("A text parser", function() {
     it("should omit spaces after commands", function() {
         expect`\text{\textellipsis !}`.toParseLike`\text{\textellipsis!}`;
     });
+
+    it("should handle ⋮ and \\vdots", function() {
+        expect`\text{a \vdots b ⋮ d}`.toParse();
+    });
 });
 
 describe("A texvc builder", function() {
@@ -1065,6 +1069,10 @@ describe("A rule parser", function() {
         expect(parse.width.number).toBeCloseTo(-1);
         expect(parse.height.number).toBeCloseTo(-0.2);
     });
+
+    it("should parse in text mode", function() {
+        expect(r`\text{a\rule{1em}{2em}b}`).toParse();
+    });
 });
 
 describe("A kern parser", function() {