mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-11 22:18:41 +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
@@ -115,9 +115,11 @@ export default class Parser {
|
||||
* Main parsing function, which parses an entire input.
|
||||
*/
|
||||
parse(): AnyParseNode[] {
|
||||
// Create a group namespace for the math expression.
|
||||
// (LaTeX creates a new group for every $...$, $$...$$, \[...\].)
|
||||
this.gullet.beginGroup();
|
||||
if (!this.settings.globalGroup) {
|
||||
// Create a group namespace for the math expression.
|
||||
// (LaTeX creates a new group for every $...$, $$...$$, \[...\].)
|
||||
this.gullet.beginGroup();
|
||||
}
|
||||
|
||||
// Use old \color behavior (same as LaTeX's \textcolor) if requested.
|
||||
// We do this within the group for the math expression, so it doesn't
|
||||
@@ -133,7 +135,9 @@ export default class Parser {
|
||||
this.expect("EOF");
|
||||
|
||||
// End the group namespace for the expression
|
||||
this.gullet.endGroup();
|
||||
if (!this.settings.globalGroup) {
|
||||
this.gullet.endGroup();
|
||||
}
|
||||
return parse;
|
||||
}
|
||||
|
||||
|
@@ -50,6 +50,7 @@ export type SettingsOptions = {
|
||||
trust?: boolean | TrustFunction;
|
||||
maxSize?: number;
|
||||
maxExpand?: number;
|
||||
globalGroup?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -76,6 +77,7 @@ export default class Settings {
|
||||
trust: boolean | TrustFunction;
|
||||
maxSize: number;
|
||||
maxExpand: number;
|
||||
globalGroup: boolean;
|
||||
|
||||
constructor(options: SettingsOptions) {
|
||||
// allow null options
|
||||
@@ -96,6 +98,7 @@ export default class Settings {
|
||||
this.trust = utils.deflt(options.trust, false);
|
||||
this.maxSize = Math.max(0, utils.deflt(options.maxSize, Infinity));
|
||||
this.maxExpand = Math.max(0, utils.deflt(options.maxExpand, 1000));
|
||||
this.globalGroup = utils.deflt(options.globalGroup, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user