This userscript gives users several quick key bindings to speed up the editing of mathjax/chem/etc. into StackExchange posts.
The hotkeys are customizable!
- Pressing Alt+Shift+P would insert
\pi
directly. - Pressing Alt+R would insert
\mathrm{}
with the caret auto-placed in the middle. Pressing Alt-R again would unwrap the\mathrm{}
back. - Pressing Alt+R with some
text
pre-selected would insert\mathrm{text}
, retaining the selection on the text. Pressing Alt-R again would unwrap the\mathrm{text}
back totext
, retaining the selection on text. - Prepending Ctrl to any of the above keybindings will auto-surround the insertion text with
$$
(or\$
on some other SE sites) - The keybinding and its associated insertion text can be modified by the user. So, you can set it to insert
\pi
on Alt+A instead.
Moreover, there are certain special shortcuts too:
- Alt-Z => dollar-ifying (
text
=>$text$
) - Alt-C => double dollar-ifying (
text
=>$$text$$
) - Alt-A => frac-ify (
A/B
=>\frac{A}{B}
) - Alt-S => align-ify (image demo)
You can change their keycodes or disable them as well. The given Z/C/A/etc. keycombos are just the default values.
You may use the Alt-H hotkey to get a popup containing a list of your current keybindings, in case you forget any of them ;)
Each hotkey is composed of three parts:
-
modifier: either an "altKey" or a "shiftKey+altKey" combo
-
key: the key to press.
-
LaTeX command: to be inserted on pressing modifier+key. These are of two types:
- braced: like
\mathrm{}
- non-braced: like
\pi
.
- braced: like
To customize hotkeys, head over to line 40 where SHORTCUTS =
is initialized. By default, it is set as (note it is important to escape the \
, so we write \\
):
SHORTCUTS = [
["altKey", "I", "\\pi"],
["altKey", "R", "\\mathrm{}"],
]
So, if you want to insert \large{}
on Alt-L, just add a single line:
SHORTCUTS = [
["altKey", "I", "\\pi"],
["altKey", "R", "\\mathrm{}"],
["altKey", "H", "\\large{}"]
]
To customize special hotkeys (for frac-ify, align lines, etc.), head over to the declaration for SPECIAL_SHORTCUTS
. To disable any of them, delete/comment the corresponding line.
To position the caret at a specific position, use the pipe (|
) character. Usual wrapping rules apply. In the absence of the pipe character, the caret is inserted inside the last {}
/()
pair, or at the end of the string.
Note: some Alt+key combos might be system-reserved (check this list), so you may need to prepend Shift to avoid overriding system-reserved behavior.