Skip to content

fix(macros): define \arraystretch so \renewcommand works - #4320

Open
Thanatos9404 wants to merge 1 commit into
KaTeX:mainfrom
Thanatos9404:define-arraystretch
Open

Thanatos9404 wants to merge 1 commit into
KaTeX:mainfrom
Thanatos9404:define-arraystretch

Conversation

@Thanatos9404

Copy link
Copy Markdown

What is the previous behavior before this PR?

\renewcommand{\arraystretch}{2}, the usual LaTeX way to stretch an array, failed with "\renewcommand{\arraystretch} when command \arraystretch does not yet exist; use \newcommand". KaTeX read \arraystretch in array.ts but never defined it. LaTeX defines it as 1 in lttab.dtx, so there \renewcommand works and \newcommand{\arraystretch} fails.

What is the new behavior after this PR?

\arraystretch is defined as 1 in macros.ts, as in LaTeX, so \renewcommand{\arraystretch}{1.5} works. \def and the macros option work as before. When \arraystretch still has this default, array.ts uses it without expanding it, so arrays still cost no macro expansions; \begin{matrix} keeps parsing with maxExpand: 0.

As in LaTeX:

  • \newcommand{\arraystretch}{...} now fails;
  • \providecommand{\arraystretch}{...} now does nothing;
  • a bare \arraystretch renders 1 instead of an undefined control sequence error.

No test or doc in the repo uses those.

New test next to "should grab \arraystretch" (\renewcommand, \newcommand, and maxExpand: 0); it fails on main. All jest tests and snapshots pass, and pnpm test:lint and pnpm test:ts are clean.

Fixes #2668

LaTeX defines \arraystretch as 1 in lttab.dtx, so
\renewcommand{\arraystretch}{2} is the usual way to stretch an array,
and \newcommand{\arraystretch} fails. KaTeX read the macro but never
defined it, so \renewcommand failed with "command \arraystretch does not
yet exist". Define it as 1, and use that default in arrays without
expanding it, so that it still costs no macro expansions.

Fixes KaTeX#2668
@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Defines \arraystretch as 1, allowing \renewcommand{\arraystretch}{...} to work.

  • Array rows now honor a redefined \arraystretch.

Thanatos9404 explicitly identifies these changes as intentional: \newcommand{\arraystretch} now fails, \providecommand{\arraystretch} leaves the default unchanged, and bare \arraystretch renders 1. These match the stated LaTeX behavior.

Reviews (1) · Last reviewed commit: "fix(macros): define \arraystretch so \re..." · Reviewed by Greptile

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

\arraystretch not already defined

1 participant