Skip to content

Add configurable piecewise command - #3056

Open
Shrookin wants to merge 2 commits into
arnog:masterfrom
Shrookin:agent/piecewise-shortcut
Open

Add configurable piecewise command#3056
Shrookin wants to merge 2 commits into
arnog:masterfrom
Shrookin:agent/piecewise-shortcut

Conversation

@Shrookin

@Shrookin Shrookin commented Aug 4, 2026

Copy link
Copy Markdown

What

Adds a new \\piecewise{n} LaTeX input command. The command creates a native cases array with n editable rows, with an expression placeholder and a condition placeholder in each row.

It also adds an upstream-generic compact virtual-keyboard keycap class for tall structured labels such as a two-row piecewise template. The class scales the rendered label to fit the standard keycap without changing the inserted LaTeX.

Why

Constructing a piecewise function currently requires manually inserting a cases environment and adding rows. A parameterized command gives MathLive users and virtual-keyboard integrations a compact, discoverable way to create the structure they need:

\\piecewise{2}
\\piecewise{3}

Structured keycap labels can exceed the normal key height. The documented compact class gives keyboard integrations a supported way to make those labels readable and fully visible.

How

  • Registers piecewise with the LaTeX command parser alongside the existing environments.
  • Accepts only a positive integer row count and caps it at 100 rows to avoid unbounded allocation from malformed input.
  • Builds the same native cases array used by regular cases editing, populated with MathLive placeholders.
  • Invalid or missing counts produce parser diagnostics and fall back to a one-row structure.
  • Existing cases, dcases, and rcases behavior is unchanged.
  • Expanded serialization uses the standard \\begin{cases}...\\end{cases} representation, so the resulting value does not depend on a nonstandard command.
  • Adds and documents the compact virtual-keyboard class, scaling only the rendered key label.

Verification

  • npx jest test/latex.test.ts --runInBand — 87 tests passed, 34 snapshots passed.
  • npx tsc --noEmit --pretty false — passed.
  • npx eslint src/public/virtual-keyboard.ts — passed.
  • npm run build — passed; static CSS and API documentation regenerated.
  • npx playwright test test/playwright-tests/virtual-keyboard.spec.ts -g "compact keycap" — passed in Chromium, Firefox, and WebKit.
  • npx playwright test test/playwright-tests/physical-keyboard.spec.ts -g "piecewise command" — passed in Chromium, Firefox, and WebKit.
  • The full Playwright suite was not rerun for this incremental commit; both focused feature tests completed successfully in all three configured engines.

This branch is based on the latest upstream master and MathLive 0.110.0, which is also the latest published npm version.

@Shrookin
Shrookin marked this pull request as ready for review August 4, 2026 18:36
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.

1 participant