mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-07 04:08:43 +00:00
* Introduce MacroExpander The job of the MacroExpander is turning a stream of possibly expandable tokens, as obtained from the Lexer, into a stream of non-expandable tokens (in KaTeX, even though they may well be expandable in TeX) which can be processed by the Parser. The challenge here is that we don't have mode-specific lexer implementations any more, so we need to do everything on the token level, including reassembly of sizes and colors. * Make macros available in development server Now one can specify macro definitions like \foo=bar as part of the query string and use these macros in the formula being typeset. * Add tests for macro expansions * Handle end of input in special groups This avoids an infinite loop if input ends prematurely. * Simplify parseSpecialGroup The parseSpecialGroup methos now returns a single token spanning the whole special group, and leaves matching that string against a suitable regular expression to whoever is calling the method. Suggested by @cbreeden. * Incorporate review suggestions Add improvements suggested by Kevin Barabash during review. * Input range sanity checks Ensure that both tokens of a token range come from the same lexer, and that the range has a non-negative length. * Improved wording of two comments
30 lines
823 B
JavaScript
30 lines
823 B
JavaScript
/**
|
|
* This is a module for storing settings passed into KaTeX. It correctly handles
|
|
* default settings.
|
|
*/
|
|
|
|
/**
|
|
* Helper function for getting a default value if the value is undefined
|
|
*/
|
|
function get(option, defaultValue) {
|
|
return option === undefined ? defaultValue : option;
|
|
}
|
|
|
|
/**
|
|
* The main Settings object
|
|
*
|
|
* The current options stored are:
|
|
* - displayMode: Whether the expression should be typeset by default in
|
|
* textstyle or displaystyle (default false)
|
|
*/
|
|
function Settings(options) {
|
|
// allow null options
|
|
options = options || {};
|
|
this.displayMode = get(options.displayMode, false);
|
|
this.throwOnError = get(options.throwOnError, true);
|
|
this.errorColor = get(options.errorColor, "#cc0000");
|
|
this.macros = options.macros || {};
|
|
}
|
|
|
|
module.exports = Settings;
|