insert latex commands quickly by keybindings
This userscript gives users several quick key bindings to speed up the editing of mathjax/chem/etc. into StackExchange posts.
The hotkeys are customizable!
\pi
directly.\mathrm{}
with the caret auto-placed in the middle. Pressing Alt-R again would unwrap the \mathrm{}
back.text
pre-selected would insert \mathrm{text}
, retaining the selection on the text. Pressing Alt-R again would unwrap the \mathrm{text}
back to text
, retaining the selection on text.$$
(or \$
on some other SE sites)\pi
on Alt+A instead.Moreover, there are certain special shortcuts too:
text
=> $text$
)text
=> $$text$$
)A/B
=> \frac{A}{B}
)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:
\mathrm{}
\pi
.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.