Skip to content

Add \ion, \positiveion, \negativeion commands for chemistry notation#45

Open
drdrew42 wants to merge 1 commit into
openwebwork:mainfrom
drdrew42:feature/chem-ions
Open

Add \ion, \positiveion, \negativeion commands for chemistry notation#45
drdrew42 wants to merge 1 commit into
openwebwork:mainfrom
drdrew42:feature/chem-ions

Conversation

@drdrew42
Copy link
Copy Markdown
Member

What

Adds three LaTeX commands for chemistry ion-charge notation:

  • \ion[sign]{charge} — a superscript-only command: an editable charge block followed by a fixed +/- sign, rendering e.g. the "2+" of a 2+ cation.
  • \positiveion / \negativeion — sign-bound shorthands that canonicalize to \ion[+]{…} / \ion[-]{…}.

Why

These commands existed in a downstream MathQuill fork used for WeBWorK chemistry problems — the chemistry answer-entry toolbars drive \positiveion/\negativeion for entering ion charges. They were lost when that work moved onto @openwebwork/mathquill, silently breaking those toolbar buttons. Restoring them upstream lets the downstream work drop the private fork.

How

Ion extends SupSub, mirroring the existing subscript/superscript classes in commands.tssupsub = 'sup', an htmlTemplate carrying the editable charge block plus a .mq-ion-classed sign span, and a parser() built on latexMathParser.optBlock / .block exactly like NthRoot. latex() serializes to \ion[sign]{charge}; an absent optional sign defaults to +, and an empty charge block to 1.

.mq-ion is a styling hook on the sign span — no CSS rule is added; it renders correctly with the existing mq-sup styles.

Testing

  • npm run build, npm run lint:check, and npm run format:check all pass.
  • Round-trip parse tests added to test/latex.test.ts (the ion charges test), following the existing assertParsesLatex pattern.

🤖 Generated with Claude Code

Ion charge notation — `\ion[+]{2}` rendering the "2+" of a 2+ cation — is a superscript-only command: an editable charge block followed by a fixed sign. `\positiveion` and `\negativeion` are sign-bound shorthands.

These commands existed in a downstream MathQuill fork used for WeBWorK chemistry problems (the chemQuill answer-entry toolbars); this restores them on @openwebwork/mathquill so that work can drop the private fork.

Ion extends SupSub, mirroring the existing subscript/superscript classes. latex() serializes to \ion[sign]{charge}; \positiveion / \negativeion canonicalize to the same. Round-trip tests added to test/latex.test.ts.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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