Skip to content

Commit

Permalink
fix: \vdots and \rule support in text mode (#3997)
Browse files Browse the repository at this point in the history
* fix #3990

* Unify math and text \vdots, allow \rule in text mode

* Add text-mode `\rule` test

---------

Co-authored-by: pzinn <[email protected]>
Co-authored-by: Ron Kok <[email protected]>
  • Loading branch information
3 people authored Dec 8, 2024
1 parent c47d158 commit 0e08352
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/functions/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 11,8 @@ defineFunction({
props: {
numArgs: 2,
numOptionalArgs: 1,
allowedInText: true,
allowedInMath: true,
argTypes: ["size", "size", "size"],
},
handler({parser}, args, optArgs) {
Expand Down
2 changes: 1 addition & 1 deletion src/macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

//////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 3 additions & 1 deletion src/symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 8 additions & 0 deletions test/katex-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 0e08352

Please sign in to comment.