From 8f47dba453aa78e03878288fdd5841cfdb4ffb8d Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Thu, 9 Jan 2025 16:26:18 -0500 Subject: [PATCH 1/6] chore(deps): update actions/upload-artifact to v4 (#4012) --- .github/workflows/fonts.yml | 4 ++-- .github/workflows/screenshotter.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/fonts.yml b/.github/workflows/fonts.yml index fa3cb859b1..7ed4f2da35 100644 --- a/.github/workflows/fonts.yml +++ b/.github/workflows/fonts.yml @@ -110,12 +110,12 @@ jobs: printf '[diff "font"]\n\tbinary = true\n\ttextconv = ttx -q -i -o -' >> ~/.gitconfig git diff --exit-code - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 if: failure() with: name: fonts path: fonts - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 if: failure() with: name: metrics diff --git a/.github/workflows/screenshotter.yml b/.github/workflows/screenshotter.yml index 4f0dbd9fe6..cc63197e6f 100644 --- a/.github/workflows/screenshotter.yml +++ b/.github/workflows/screenshotter.yml @@ -81,12 +81,12 @@ jobs: docker logs ${{ job.services.selenium.id }} echo "::$TOKEN::" - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 if: failure() with: name: new-${{ matrix.browser }} path: test/screenshotter/new - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 if: failure() with: name: diff-${{ matrix.browser }} From 6d30fe47b06f9da9b836fe518d5cbbecf6a6a3a1 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Sun, 12 Jan 2025 16:48:45 -0500 Subject: [PATCH 2/6] fix: \providecommand does not overwrite existing macro (#4000) Fixes #3928 --- src/macros.js | 25 ++++++++++++++++--------- test/katex-spec.js | 8 +++----- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/macros.js b/src/macros.js index 3c5c965893..182efa69e2 100644 --- a/src/macros.js +++ b/src/macros.js @@ -146,7 +146,9 @@ defineMacro("\\char", function(context) { // \newcommand{\macro}[args]{definition} // \renewcommand{\macro}[args]{definition} // TODO: Optional arguments: \newcommand{\macro}[args][default]{definition} -const newcommand = (context, existsOK: boolean, nonexistsOK: boolean) => { +const newcommand = ( + context, existsOK: boolean, nonexistsOK: boolean, skipIfExists: boolean +) => { let arg = context.consumeArg().tokens; if (arg.length !== 1) { throw new ParseError( @@ -181,16 +183,21 @@ const newcommand = (context, existsOK: boolean, nonexistsOK: boolean) => { arg = context.consumeArg().tokens; } - // Final arg is the expansion of the macro - context.macros.set(name, { - tokens: arg, - numArgs, - }); + if (!(exists && skipIfExists)) { + // Final arg is the expansion of the macro + context.macros.set(name, { + tokens: arg, + numArgs, + }); + } return ''; }; -defineMacro("\\newcommand", (context) => newcommand(context, false, true)); -defineMacro("\\renewcommand", (context) => newcommand(context, true, false)); -defineMacro("\\providecommand", (context) => newcommand(context, true, true)); +defineMacro("\\newcommand", + (context) => newcommand(context, false, true, false)); +defineMacro("\\renewcommand", + (context) => newcommand(context, true, false, false)); +defineMacro("\\providecommand", + (context) => newcommand(context, true, true, true)); // terminal (console) tools defineMacro("\\message", (context) => { diff --git a/test/katex-spec.js b/test/katex-spec.js index ceb76dd57b..70e587f96f 100644 --- a/test/katex-spec.js +++ b/test/katex-spec.js @@ -3659,17 +3659,15 @@ describe("A macro expander", function() { expect`\newcommand{\foo}{1}\foo\renewcommand{\foo}{2}\foo`.toParseLike`12`; }); - it("\\providecommand (re)defines macros", () => { + it("\\providecommand defines but does not redefine macros", () => { expect`\providecommand\foo{x^2}\foo+\foo`.toParseLike`x^2+x^2`; expect`\providecommand{\foo}{x^2}\foo+\foo`.toParseLike`x^2+x^2`; - expect`\providecommand\bar{x^2}\bar+\bar`.toParseLike`x^2+x^2`; - expect`\providecommand{\bar}{x^2}\bar+\bar`.toParseLike`x^2+x^2`; expect`\newcommand{\foo}{1}\foo\providecommand{\foo}{2}\foo` - .toParseLike`12`; + .toParseLike`11`; expect`\providecommand{\foo}{1}\foo\renewcommand{\foo}{2}\foo` .toParseLike`12`; expect`\providecommand{\foo}{1}\foo\providecommand{\foo}{2}\foo` - .toParseLike`12`; + .toParseLike`11`; }); it("\\newcommand is local", () => { From 28a0bf51139969e9dc52085b72024e0c5447cfbe Mon Sep 17 00:00:00 2001 From: KaTeX bot <33710906+KaTeX-bot@users.noreply.github.com> Date: Sun, 12 Jan 2025 21:50:45 +0000 Subject: [PATCH 3/6] chore(release): 0.16.20 [ci skip] ## [0.16.20](https://github.com/KaTeX/KaTeX/compare/v0.16.19...v0.16.20) (2025-01-12) ### Bug Fixes * \providecommand does not overwrite existing macro ([#4000](https://github.com/KaTeX/KaTeX/issues/4000)) ([6d30fe4](https://github.com/KaTeX/KaTeX/commit/6d30fe47b06f9da9b836fe518d5cbbecf6a6a3a1)), closes [#3928](https://github.com/KaTeX/KaTeX/issues/3928) --- CHANGELOG.md | 7 +++++++ README.md | 6 +++--- contrib/copy-tex/README.md | 4 ++-- contrib/mathtex-script-type/README.md | 10 +++++----- contrib/mhchem/README.md | 2 +- docs/autorender.md | 16 ++++++++-------- docs/browser.md | 24 ++++++++++++------------ docs/support_table.md | 2 +- docs/supported.md | 2 +- package.json | 2 +- 10 files changed, 41 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cbb3e9508..0a29ab057a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog All notable changes to this project will be documented in this file. This CHANGELOG roughly follows the guidelines from [www.keepachangelog.com](https://keepachangelog.com/en/1.0.0/). +## [0.16.20](https://github.com/KaTeX/KaTeX/compare/v0.16.19...v0.16.20) (2025-01-12) + + +### Bug Fixes + +* \providecommand does not overwrite existing macro ([#4000](https://github.com/KaTeX/KaTeX/issues/4000)) ([6d30fe4](https://github.com/KaTeX/KaTeX/commit/6d30fe47b06f9da9b836fe518d5cbbecf6a6a3a1)), closes [#3928](https://github.com/KaTeX/KaTeX/issues/3928) + ## [0.16.19](https://github.com/KaTeX/KaTeX/compare/v0.16.18...v0.16.19) (2024-12-29) diff --git a/README.md b/README.md index 84a2d34a1d..a01ddf914b 100644 --- a/README.md +++ b/README.md @@ -37,13 +37,13 @@ Try out KaTeX [on the demo page](https://katex.org/#demo)! - + - + - ... diff --git a/contrib/copy-tex/README.md b/contrib/copy-tex/README.md index 42f43b5be0..ca691d8fcd 100644 --- a/contrib/copy-tex/README.md +++ b/contrib/copy-tex/README.md @@ -18,7 +18,7 @@ This extension isn't part of KaTeX proper, so the script should be separately included in the page. ```html - + ``` (Note that, as of KaTeX 0.16.0, there is no longer a corresponding CSS file.) @@ -35,5 +35,5 @@ statement with `require('katex/contrib/copy-tex/katex2tex.js')`. ECMAScript module is also available: ```html - + ``` diff --git a/contrib/mathtex-script-type/README.md b/contrib/mathtex-script-type/README.md index 422e776d92..01c51f14d7 100644 --- a/contrib/mathtex-script-type/README.md +++ b/contrib/mathtex-script-type/README.md @@ -11,7 +11,7 @@ included in the page, in addition to KaTeX. Load the extension by adding the following line to your HTML file. ```html - + ``` You can download the script and use it locally, or from a local KaTeX installation instead. @@ -23,9 +23,9 @@ Then, in the body, we use a `math/tex` script to typeset the equation `x+\sqrt{1 - - - + + + @@ -35,4 +35,4 @@ Then, in the body, we use a `math/tex` script to typeset the equation `x+\sqrt{1 ECMAScript module is also available: ```html - + diff --git a/contrib/mhchem/README.md b/contrib/mhchem/README.md index bb0c825d42..00c150e76d 100644 --- a/contrib/mhchem/README.md +++ b/contrib/mhchem/README.md @@ -7,7 +7,7 @@ This extension adds to KaTeX the `\ce` and `\pu` functions from the [mhchem](htt This extension isn't part of core KaTeX, so the script should be separately included. Write the following line into the HTML page's ``. Place it *after* the line that calls `katex.js`, and if you make use of the [auto-render](https://katex.org/docs/autorender.html) extension, place it *before* the line that calls `auto-render.js`. ```html - + ``` If you remove the `defer` attribute from this tag, then you must also remove the `defer` attribute from the ` - + ``` @@ -31,9 +31,9 @@ want to use a `defer` or `onload` attribute. For example: ```html - - - + + + ``` diff --git a/docs/browser.md b/docs/browser.md index 85202cdb89..b128b3b661 100644 --- a/docs/browser.md +++ b/docs/browser.md @@ -11,13 +11,13 @@ title: Browser - + - + - ... @@ -29,15 +29,15 @@ If you include the `katex.js` directly, the `katex` object will be available as a global variable. ```html - - + + ``` KaTeX also provides minified versions: ```html - - + + ``` The examples above load the script [deferred using the `defer` attribute](https://developer.mozilla.org/en/HTML/Element/script#Attributes) @@ -81,22 +81,22 @@ for more detail. ```html - + ``` ### ECMAScript module ```html - - + + ``` > Use [`nomodule` attribute](https://developer.mozilla.org/en/HTML/Element/script#Attributes) diff --git a/docs/support_table.md b/docs/support_table.md index de81c07d69..7e0378d7aa 100644 --- a/docs/support_table.md +++ b/docs/support_table.md @@ -6,7 +6,7 @@ This is a list of TeX functions, sorted alphabetically. This list includes funct If you know the shape of a character, but not its name, [Detexify](https://detexify.kirelabs.org/classify.html) can help. - +