Page MenuHomePhabricator

Add toolbar button and keyboard shortcut to add math tags
Closed, ResolvedPublic

Description

Related wish: W141: Editing mathematics is too difficult

One idea we had was to add a keyboard shortcut and toolbar button to insert <math></math> and put the cursor in the middle. This should reduce the manual strain of having to type <math> over and over. This seems pretty useful and non-controversial.

Acceptance criteria

If the Math extension is installed:

  • The WikiEditor (2010) toolbar should have two buttons, both in the "Insert" group of the "Advanced" section:
    • "Math formula (inline)" with the keyboard shortcut Ctrl-m (or Command-m on Mac).
    • "Math formula (block)" (no keyboard shortcut for WikiEditor-only)
  • Keyboard shortcuts for MediaWiki-extensions-CodeMirror, documented in the help dialog (available by pressing Ctrl-Shift-/ (or Cmd-Shift-/ on Mac)
    • Ctrl-m (or Command-m on Mac) for inline
    • Shift-Ctrl-m for block

Clicking on the button or using the keyboard shortcut should insert <math display="inline"></math> (or <math display="block"></math>) and place the cursor in between the opening and closing tags.

Related: T419104: Auto-closing of tags in wikitext


Derived Requirement

Ensure that when the Math extension is enabled, users can insert math tags using toolbar buttons and keyboard shortcuts in the editor.

The editor must provide options to insert both inline and block math tags, and upon insertion, the cursor must be placed between the opening and closing <math> tags for immediate input.

Test Steps

Test Case 1: Ensure math toolbar buttons are present when Math extension is enabled

  1. Ensure the Math extension is enabled on the wiki.
  2. Log in to Wikipedia.
  3. Open the editor using WikiEditor (2010) on any editable page.
  4. Navigate to the "Advanced" section of the toolbar.
  5. Locate the "Insert" group.
  6. Observe the available buttons.
  7. ✅❓❌⬜ AC1: Two buttons labeled "Math formula (inline)" and "Math formula (block)" are present in the "Insert" group of the "Advanced" section.

Test Case 2: Ensure clicking math toolbar buttons inserts correct tags with cursor placement

  1. Open WikiEditor (2010) on an editable page.
  2. Click the "Math formula (inline)" button.
  3. Observe the inserted text and cursor position.
  4. Click the "Math formula (block)" button.
  5. Observe the inserted text and cursor position.
  6. ✅❓❌⬜ AC2: Clicking each button inserts the correct <math display="inline"></math> or <math display="block"></math> tag and places the cursor between the tags.

Test Case 3: Ensure keyboard shortcuts insert inline and block math tags

  1. Open WikiEditor (2010) on an editable page.
  2. Press Cmd + M (Mac) or Ctrl + M (non-Mac).
  3. Observe the inserted text and cursor position.
  4. Ensure CodeMirror is enabled.
  5. Press Shift + Cmd + M (Mac) or Shift + Ctrl + M (non-Mac).
  6. Observe the inserted text and cursor position.
  7. ✅❓❌⬜ AC3: The correct inline and block <math> tags are inserted using their respective keyboard shortcuts and the cursor is placed between the tags.

Test Case 4: Ensure keyboard shortcuts are documented in the help dialog

  1. Open an editable page with CodeMirror enabled.
  2. Open the help dialog using Cmd + Shift + / (Mac) or Ctrl + Shift + / (non-Mac).
  3. Locate the keyboard shortcuts section.
  4. Observe the listed shortcuts for math insertion.
  5. ✅❓❌⬜ AC4: The help dialog lists keyboard shortcuts for inserting inline and block math tags.

QA Results -Beta

Event Timeline

MusikAnimal changed the task status from Open to In Progress.Mar 18 2026, 8:12 PM
MusikAnimal claimed this task.
MusikAnimal moved this task from Backlog to In Progress on the Community-Wishlist board.
MusikAnimal updated the task description. (Show Details)

Change #1255026 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] Hooks: load modules registered through CodeMirrorPluginModules

https://gerrit.wikimedia.org/r/1255026

Physikerwelt subscribed.

The default (legacy) rendering of math is a mix inline and display rendering. So for new math either inline '\(' or display '\[' rendering should be used. This is controlled by the display attribute which can be inline or block. If the display parameter is omitted math is rendered as \({\displaystyle so it generates large operators within the current text line. The reason for that is that traditionally formulae were placed on a new line with a colon :<math> However, that does not generate valid HTML with modern wikitext engines. See https://www.mediawiki.org/wiki/Extension:Math/Displaystyle for additional details.

I would this suggest to have two shortcuts, one for displaystyle which corresponds to $$ or \[ and one for textstyle which corresponds to $ or \( in TeX.

Change #1255042 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/Math@master] ext.math: module adding integration with CodeMirror and WikiEditor

https://gerrit.wikimedia.org/r/1255042

I would this suggest to have two shortcuts, one for displaystyle which corresponds to $$ or \[ and one for textstyle which corresponds to $ or \( in TeX.

Thanks! I admit I'm an Extension:Math newbie. I was just finding ways to quickly solve the wish by making inserting the <math> tag easier in an uncontroversial and wiki-agnostic way.

Is what you're suggesting basically a shortcut to enter <math display="inline"> and <math display="block">? Perhaps Ctrl-m for inline, and Shift-Ctrl-m for block? For now, I'm only try to help with adding <math> tags specifically, but eventually I think we can add some fancy helpers and highlighting in CodeMirror for the actual Math syntax.

I see that OOUI has icons for both mathematicsDisplayBlock and mathematicsDisplayInline, so we can have two separate buttons in WikiEditor.

Is what you're suggesting basically a shortcut to enter <math display="inline"> and <math display="block">? Perhaps Ctrl-m for inline, and Shift-Ctrl-m for block?

That would be great. I think. However, I would guess it would be good to explain why the key m was chosen. Many people might have an option about it.

I just went with m because it wasn't being used for anything, and in English it's easy to remember with m referring to mathematics.

Shift-Ctrl-m in some browsers opens up the developer console in a mobile emulator, but I'm assuming it's OK to override that.

Ok for me. https://marketplace.visualstudio.com/items?itemName=Naela.latex-shortcuts uses m as well. https://www.notion.com/en-gb/help/math-equations goes for e. I was under the impression that we already had a keyboard shortcut for VisualEditor but I can't find it at the moment.

There was a long discussion about display / block which dates back to 2015, but it seems that nothing was implemented after all.

HMonroy changed the task status from In Progress to Open.Mar 24 2026, 1:44 AM

Change #1255042 merged by jenkins-bot:

[mediawiki/extensions/Math@master] ext.math: module adding integration with CodeMirror and WikiEditor

https://gerrit.wikimedia.org/r/1255042

@MusikAnimal Validated the addition of a toolbar button and a keyboard shortcut to add math tags, as seen in the screenshots/videos below. I will mark this as Resolved. Thanks for all your work!

Test Result - Beta

Status: ✅ PASS
Environment: Beta
OS: macOS Tahoe 26.3.1
Browser: Chrome 146
Device: MBA
Emulated Device: NA

Test Artifact(s):

Test Steps

Test Case 1: Ensure math toolbar buttons are present when Math extension is enabled

  1. Ensure the Math extension is enabled on the wiki.
  2. Log in to Wikipedia.
  3. Open the editor using WikiEditor (2010) on any editable page.
  4. Navigate to the "Advanced" section of the toolbar.
  5. Locate the "Insert" group.
  6. Observe the available buttons.
  7. AC1: Two buttons labeled "Math formula (inline)" and "Math formula (block)" are present in the "Insert" group of the "Advanced" section.
InlineBlock
2026-03-24_16-09-12.png (642×696 px, 125 KB)
2026-03-24_16-09-49.png (709×670 px, 129 KB)

Test Case 2: Ensure clicking math toolbar buttons inserts correct tags with cursor placement

  1. Open WikiEditor (2010) on an editable page.
  2. Click the "Math formula (inline)" button.
  3. Observe the inserted text and cursor position.
  4. Click the "Math formula (block)" button.
  5. Observe the inserted text and cursor position.
  6. AC2: Clicking each button inserts the correct <math display="inline"></math> or <math display="block"></math> tag and places the cursor between the tags.

Gif

2026-03-24_16-14-42.gif (978×866 px, 1 MB)

Test Case 3: Ensure keyboard shortcuts insert inline and block math tags

  1. Open WikiEditor (2010) on an editable page.
  2. Press Cmd + M (Mac) or Ctrl + M (non-Mac).
  3. Observe the inserted text and cursor position.
  4. Ensure CodeMirror is enabled.
  5. Press Shift + Cmd + M (Mac) or Shift + Ctrl + M (non-Mac).
  6. Observe the inserted text and cursor position.
  7. AC3: The correct inline and block <math> tags are inserted using their respective keyboard shortcuts and the cursor is placed between the tags.

Test Case 4: Ensure keyboard shortcuts are documented in the help dialog

  1. Open an editable page with CodeMirror enabled.
  2. Open the help dialog using Cmd + Shift + / (Mac) or Ctrl + Shift + / (non-Mac).
  3. Locate the keyboard shortcuts section.
  4. Observe the listed shortcuts for math insertion.
  5. AC4: The help dialog lists keyboard shortcuts for inserting inline and block math tags.

It didn't work for me since I had to do Cmd + Shift + < (Mac) to bring up Syntax highlighting preferences, then click on Keyboard Shortcuts but you did validate on your end when doing Cmd + Shift + / (Mac), it brought up the Keyboard Shortcuts. Something with my mapping is off.

2026-03-25_13-06-50.png (1,459×1,042 px, 289 KB)

GMikesell-WMF updated Other Assignee, removed: GMikesell-WMF.
GMikesell-WMF updated the task description. (Show Details)
GMikesell-WMF changed the task status from Open to In Progress.Apr 9 2026, 4:36 PM
GMikesell-WMF moved this task from QA to In Development on the Community-Tech (Sea Lion Squad) board.

please change keyboard shortcut for inserting math tag as it conflicts with ULS - T421333: Math formula (inline) button uses Ctrl-m shortcut already in use for ULS preferred alternative keyboard

Will do! Let's deal with this at T421333.