mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-06 11:48:41 +00:00
Add \message, \errmessage, and \show for debugging (#2135)
* Add \message, \errmessage, and \show for debugging * Remove unnecessary parentheses * add tests for \message and \errmessage
This commit is contained in:
committed by
Kevin Barabash
parent
e5333ad04d
commit
0d8830af30
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
import fontMetricsData from "../submodules/katex-fonts/fontMetricsData";
|
||||
import functions from "./functions";
|
||||
import symbols from "./symbols";
|
||||
import utils from "./utils";
|
||||
import {Token} from "./Token";
|
||||
@@ -300,6 +301,28 @@ defineMacro("\\newcommand", (context) => newcommand(context, false, true));
|
||||
defineMacro("\\renewcommand", (context) => newcommand(context, true, false));
|
||||
defineMacro("\\providecommand", (context) => newcommand(context, true, true));
|
||||
|
||||
// terminal (console) tools
|
||||
defineMacro("\\message", (context) => {
|
||||
const arg = context.consumeArgs(1)[0];
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(arg.reverse().map(token => token.text).join(""));
|
||||
return '';
|
||||
});
|
||||
defineMacro("\\errmessage", (context) => {
|
||||
const arg = context.consumeArgs(1)[0];
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(arg.reverse().map(token => token.text).join(""));
|
||||
return '';
|
||||
});
|
||||
defineMacro("\\show", (context) => {
|
||||
const tok = context.popToken();
|
||||
const name = tok.text;
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(tok, context.macros.get(name), functions[name],
|
||||
symbols.math[name], symbols.text[name]);
|
||||
return '';
|
||||
});
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Grouping
|
||||
// \let\bgroup={ \let\egroup=}
|
||||
|
@@ -3732,3 +3732,23 @@ describe("Extending katex by new fonts and symbols", function() {
|
||||
expect(katex.renderToString("۹۹^{۱۱}")).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe("debugging macros", () => {
|
||||
describe("message", () => {
|
||||
it("should print the argument using console.log", () => {
|
||||
jest.spyOn(console, "log");
|
||||
expect`\message{Hello, world}`.toParse();
|
||||
// eslint-disable-next-line no-console
|
||||
expect(console.log.mock.calls[0][0]).toEqual("Hello, world");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errmessage", () => {
|
||||
it("should print the argument using console.error", () => {
|
||||
jest.spyOn(console, "error");
|
||||
expect`\errmessage{Hello, world}`.toParse();
|
||||
// eslint-disable-next-line no-console
|
||||
expect(console.error.mock.calls[0][0]).toEqual("Hello, world");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user