mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-08 12:38:39 +00:00
Create globalGroup option to place definitions in global scope (#2091)
If true, this allows \newcommand definitions to persist across calls to renderToString. Fix https://github.com/KaTeX/KaTeX/issues/2070
This commit is contained in:
committed by
Kevin Barabash
parent
f03671ce61
commit
36595343b7
@@ -3162,6 +3162,25 @@ describe("A macro expander", function() {
|
||||
expect(macros["\\foo"]).toBeFalsy();
|
||||
});
|
||||
|
||||
it("\\def changes settings.macros with globalGroup", () => {
|
||||
const macros = {};
|
||||
expect`\gdef\foo{1}`.toParse(new Settings({macros, globalGroup: true}));
|
||||
expect(macros["\\foo"]).toBeTruthy();
|
||||
});
|
||||
|
||||
it("\\newcommand doesn't change settings.macros", () => {
|
||||
const macros = {};
|
||||
expect`\newcommand\foo{x^2}\foo+\foo`.toParse(new Settings({macros}));
|
||||
expect(macros["\\foo"]).toBeFalsy();
|
||||
});
|
||||
|
||||
it("\\newcommand changes settings.macros with globalGroup", () => {
|
||||
const macros = {};
|
||||
expect`\newcommand\foo{x^2}\foo+\foo`.toParse(
|
||||
new Settings({macros, globalGroup: true}));
|
||||
expect(macros["\\foo"]).toBeTruthy();
|
||||
});
|
||||
|
||||
it("\\newcommand defines new macros", () => {
|
||||
expect`\newcommand\foo{x^2}\foo+\foo`.toParseLike`x^2+x^2`;
|
||||
expect`\newcommand{\foo}{x^2}\foo+\foo`.toParseLike`x^2+x^2`;
|
||||
|
Reference in New Issue
Block a user