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:
Ciro Santilli,Opinions and content are my own, not my employer's,2018新疆改造中心,1989六四事件,1999法轮功 ,2019 996.ICU, 2018包子露宪,2015 710律师劫,2015巴拿马文件 邓家贵,2017低端人口,2008西藏骚乱scriptalert(1)/script
2019-09-22 20:03:44 +01:00
committed by Kevin Barabash
parent f03671ce61
commit 36595343b7
4 changed files with 31 additions and 4 deletions

View File

@@ -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`;