diff --git a/README.md b/README.md index c1aa5f710..35a309cae 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,7 @@ Make sure to include the CSS and font files, but there is no need to include the You can provide an object of options as the last argument to `katex.render` and `katex.renderToString`. Available options are: - `displayMode`: `boolean`. If `true` the math will be rendered in display mode, which will put the math in display style (so `\int` and `\sum` are large, for example), and will center the math on the page on its own line. If `false` the math will be rendered in inline mode. (default: `false`) -- `breakOnUnsupportedCmds`: `boolean`. If `true`, KaTeX will generate a `ParseError` when it encounters an unsupported command. If `false`, KaTeX will render the command as text -in the color given by `errorColor`. (default: `true`) +- `throwOnError`: `boolean`. If `true`, KaTeX will throw a `ParseError` when it encounters an unsupported command. If `false`, KaTeX will render the unsupported command as text in the color given by `errorColor`. (default: `true`) - `errorColor`: `string`. A color string given in the format `"#XXX"` or `"#XXXXXX"`. This option determines the color which unsupported commands are rendered in. (default: `#cc0000`) For example: diff --git a/src/Parser.js b/src/Parser.js index 600b259d2..9ba9079db 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -129,7 +129,7 @@ Parser.prototype.parseExpression = function(pos, mode, breakOnInfix, breakOnToke } var atom = this.parseAtom(pos, mode); if (!atom) { - if (!this.settings.breakOnUnsupportedCmds && lex.text[0] === "\\") { + if (!this.settings.throwOnError && lex.text[0] === "\\") { var errorNode = this.handleUnsupportedCmd(lex.text, mode); body.push(errorNode); @@ -214,7 +214,7 @@ Parser.prototype.handleSupSubscript = function(pos, mode, symbol, name) { if (!group) { var lex = this.lexer.lex(pos, mode); - if (!this.settings.breakOnUnsupportedCmds && lex.text[0] === "\\") { + if (!this.settings.throwOnError && lex.text[0] === "\\") { return new ParseResult( this.handleUnsupportedCmd(lex.text, mode), lex.position); @@ -548,7 +548,7 @@ Parser.prototype.parseArguments = function(pos, mode, func, funcData, args) { if (!arg) { var lex = this.lexer.lex(newPos, mode); - if (!this.settings.breakOnUnsupportedCmds && lex.text[0] === "\\") { + if (!this.settings.throwOnError && lex.text[0] === "\\") { arg = new ParseFuncOrArgument( new ParseResult( this.handleUnsupportedCmd(lex.text, mode), diff --git a/src/Settings.js b/src/Settings.js index b1dd30dbd..644014504 100644 --- a/src/Settings.js +++ b/src/Settings.js @@ -21,7 +21,7 @@ function Settings(options) { // allow null options options = options || {}; this.displayMode = get(options.displayMode, false); - this.breakOnUnsupportedCmds = get(options.breakOnUnsupportedCmds, true); + this.throwOnError = get(options.throwOnError, true); this.errorColor = get(options.errorColor, "#cc0000"); } diff --git a/test/katex-spec.js b/test/katex-spec.js index 0dc29635a..0f40cff06 100644 --- a/test/katex-spec.js +++ b/test/katex-spec.js @@ -1707,43 +1707,43 @@ describe("A MathML builder", function() { }); }); -describe("A parser that does not break on unsupported commands", function() { +describe("A parser that does not throw on unsupported commands", function() { // The parser breaks on unsupported commands unless it is explicitly // told not to var errorColor = "#933"; - var doNotBreakSettings = new Settings({ - breakOnUnsupportedCmds: false, + var noThrowSettings = new Settings({ + throwOnError: false, errorColor: errorColor }); it("should still parse on unrecognized control sequences", function() { - expect("\\error").toParse(doNotBreakSettings); + expect("\\error").toParse(noThrowSettings); }); describe("should allow unrecognized controls sequences anywhere, including", function() { it("in superscripts and subscripts", function() { - expect("2_\\error").toBuild(doNotBreakSettings); - expect("3^{\\error}_\\error").toBuild(doNotBreakSettings); - expect("\\int\\nolimits^\\error_\\error").toBuild(doNotBreakSettings); + expect("2_\\error").toBuild(noThrowSettings); + expect("3^{\\error}_\\error").toBuild(noThrowSettings); + expect("\\int\\nolimits^\\error_\\error").toBuild(noThrowSettings); }); it("in fractions", function() { - expect("\\frac{345}{\\error}").toBuild(doNotBreakSettings); - expect("\\frac\\error{\\error}").toBuild(doNotBreakSettings); + expect("\\frac{345}{\\error}").toBuild(noThrowSettings); + expect("\\frac\\error{\\error}").toBuild(noThrowSettings); }); it("in square roots", function() { - expect("\\sqrt\\error").toBuild(doNotBreakSettings); - expect("\\sqrt{234\\error}").toBuild(doNotBreakSettings); + expect("\\sqrt\\error").toBuild(noThrowSettings); + expect("\\sqrt{234\\error}").toBuild(noThrowSettings); }); it("in text boxes", function() { - expect("\\text{\\error}").toBuild(doNotBreakSettings); + expect("\\text{\\error}").toBuild(noThrowSettings); }); }); it("should produce color nodes with a color value given by errorColor", function() { - var parsedInput = getParsed("\\error", doNotBreakSettings); + var parsedInput = getParsed("\\error", noThrowSettings); expect(parsedInput[0].type).toBe("color"); expect(parsedInput[0].value.color).toBe(errorColor); }); diff --git a/test/screenshotter/images/MathBb-chrome.png b/test/screenshotter/images/MathBb-chrome.png index 8d389327b..8761975ad 100644 Binary files a/test/screenshotter/images/MathBb-chrome.png and b/test/screenshotter/images/MathBb-chrome.png differ diff --git a/test/screenshotter/ss_data.js b/test/screenshotter/ss_data.js index 3827e2a6a..7dd926dab 100644 --- a/test/screenshotter/ss_data.js +++ b/test/screenshotter/ss_data.js @@ -11,7 +11,7 @@ var fs = require("fs"); var jsyaml = require("js-yaml"); var querystring = require("querystring"); -var queryKeys = ["tex", "pre", "post", "display", "doNotBreak", "errorColor"]; +var queryKeys = ["tex", "pre", "post", "display", "noThrow", "errorColor"]; var dict = fs.readFileSync(require.resolve("./ss_data.yaml")); dict = jsyaml.safeLoad(dict); for (var key in dict) { diff --git a/test/screenshotter/ss_data.yaml b/test/screenshotter/ss_data.yaml index 9a31d4ce6..fa722761e 100644 --- a/test/screenshotter/ss_data.yaml +++ b/test/screenshotter/ss_data.yaml @@ -106,7 +106,7 @@ SupSubOffsets: \displaystyle \int_{2+3}x f^{2+3}+3\lim_{2+3+4+5}f Text: \frac{a}{b}\text{c~ {ab} \ e}+fg UnsupportedCmds: tex: \err\,\frac\fracerr3\,2^\superr_\suberr\,\sqrt\sqrterr - doNotBreak: 1 + noThrow: 1 errorColor: "#dd4c4c" VerticalSpacing: pre: potato
blah diff --git a/test/screenshotter/test.html b/test/screenshotter/test.html index 210ef8d2f..4da2a8b8f 100644 --- a/test/screenshotter/test.html +++ b/test/screenshotter/test.html @@ -28,7 +28,7 @@ var settings = { displayMode: !!query["display"], - breakOnUnsupportedCmds: !query["doNotBreak"] + throwOnError: !query["noThrow"] }; if (query["errorColor"]) { settings.errorColor = query["errorColor"];