LaTeX key-bindings for ST
Writing down Sublime Text1 key-bindings for common triggers that have escaped my attention, despite years of writing. In the table below, depending on OS and keyboard layout,2 super is either win or cmd.
Key combination | Result |
---|---|
super + shift + b | Bold (wraps text in \textbf{} ) |
super + shift + i | Italics (wraps text in \emph{} ) |
super + shift + k | Small caps (wraps text in \textsc{} ) |
Here’s a demo.
To be able to do this, I park the following key-binding instructions into Settings → Key Bindings → Default (OS).sublime-keymap. The context part below ensures that these only work with LaTeX files.
[
// LaTeX: strongly emphasise selected text
{
"keys": ["super+shift+b"],
"command": "insert_snippet",
"args": {"contents": "\\textbf{${0:$SELECTION}}"},
"context": [{ "key": "selector", "operator": "equal", "operand": "text.tex.latex" }]
},
// LaTeX: emphasise selected text
{
"keys": ["super+shift+i"],
"command": "insert_snippet",
"args": {"contents": "\\emph{${0:$SELECTION}}"},
"context": [{ "key": "selector", "operator": "equal", "operand": "text.tex.latex" }]
},
// LaTeX: small caps selected text
{
"keys": ["super+shift+k"],
"command": "insert_snippet",
"args": {"contents": "\\textsc{${0:$SELECTION}}"},
"context": [{ "key": "selector", "operator": "equal", "operand": "text.tex.latex" }]
},
]
Optionally, adding the following line to the preamble (style) forces title case words into all small caps. This redefines the wrap tag as \sc{}
, converts the word first to lowercase, and then applies small caps tag (\textsc{}
) to it.
\renewcommand*{\sc}[1]{\textsc{\MakeLowercase{#1}}}
To use \sc{}
tag, replace small caps key-binding from above to as below, in which the only change is that the args
line replaces \textsc{}
with \sc{}
:
[
// LaTeX: small caps selected text
{
"keys": ["super+shift+k"],
"command": "insert_snippet",
"args": {"contents": "\\sc{${0:$SELECTION}}"},
"context": [{ "key": "selector", "operator": "equal", "operand": "text.tex.latex" }]
},
]
-
Other than a little helper snippets package, I use Sublime Text bare-metal to write, using its impressive default features. ↩
-
In the key combinations above, ctrl my first preference could not be used, since some of these are already taken — in OS-specific default key-bindings in Sublime Text. Therefore, for consistency, I chose super instead. To prevent impairing core functionality of Sublime Text, it is best to check the list of default key-bindings first, and avoid using them in custom key-bindings. ↩