5

Does anyone know a way to set custom hotkeys for often used code on Overleaf, so I can make my typing more efficient? I know there are default hotkeys for things such as bolden text (ctrl + b), but I can't find any option for setting up custom ones on google.

update: I switch from overleaf to vim on linux and found the plugin Ultisnips super useful, it allowed me to take note real time in class with the amount of snippet I set up.

2
  • Hi there, Tom from Overleaf Support here. I'm afraid we don't have a way how to set up custom hotkeys, sorry for the limitation. (I also think that the question is not answerable so it might get closed, but I'll leave that to the active members of this community to decide.)
    – yo'
    Jun 30, 2021 at 12:49
  • Unfortunately, Overleaf only has "predecided" hot keys, which is a great limitation. I would like to respond mainly to Tom of Overleaf Support. The way an Overleaf formatting hot key works is that the user highlights a section of text, which then forms input to the macro that is replacing this text with some modification. At the top of my list would be a "programmer's" hot key with the following functionality: 1. a buffer containing a user programmed regular expression (regex) somewhat similar to what "grep" wants as input. 2. a shortcut "hot key" that allows this regex to be applied to the La Oct 24, 2021 at 9:14

2 Answers 2

2

While Overleaf does not support this functionality (yet), this (and much more) can be accomplished using an AutoHotkey script:

SetTitleMatchMode, 2  ; Window title can contain the specified substring anywhere

GroupAdd, browser, ahk_exe chrome.exe
GroupAdd, browser, ahk_exe firefox.exe
GroupAdd, browser, ahk_exe iexplore.exe
GroupAdd, browser, ahk_exe msedge.exe
; You can add any additional browsers you use here

#IfWinActive Overleaf ahk_group browser
; Blue color text (CTRL + SHIFT + B)
^+b::
clipSaved := ClipboardAll
Clipboard :=
Send, ^c
SendRaw, \textcolor{blue}{
Send, ^v
SendRaw, }
Sleep, 1000
Clipboard := clipSaved
clipSaved :=
return

This code will, for example, wrap selected text in \textcolor{blue}{<text here>} or simply insert \textcolor{blue}{} if no text is selected. You can then set this script to start automatically at system startup so you always have this hotkey available.

Pros:

  • This method can easily be extended to any custom commands you want to use
  • The method can also easily be extended to work with other websites or even other programs (e.g. TeXstudio)

Cons:

  • Requires external tools (AHK) to be installed
  • Only available on Windows platforms
  • Takes some time (10 minutes) to set up
  • Relies on browser tab having "Overleaf" in the title so it may occasionally trigger on other websites too (for instance here, since the question title contains "Overleaf")
2
  • It should be mentioned that this is a very restrictive solution, since AHK is Windows-only. The OP didn't mention any operating system.
    – Miyase
    Jun 18, 2022 at 16:08
  • Fair point, I have added this information to the list of cons. Jun 18, 2022 at 16:48
3

As Tom from Overleaf Support said in a comment under your question, there is no built-in way to do that currently in Overleaf. I also wanted that functionality badly, so I developed a user script for personal use to do just that. Since a few other people I know found it useful, I polished it a bit and published it as a chrome browser extension called Shortleaf. If you're interested you can install it from the chrome web store (also works on Edge), or check out the github project.

It's fully configurable, but here are some examples of the built-in defaults for symbols: Default symbol shortcuts

And for commands ("things with arguments"): Default command shortcuts

It's an essential part of my workflow now, so hope you find it useful too!

4
  • 1
    Great extension Andre! Is there a way to define shortcuts with untypeable keys? I wanted to define super-/subscript as alt-Up/DownArrow (alt-^ is not doable on my keyboard). Oct 19, 2023 at 12:57
  • One wish I would have for this extension would be support for environments with arguments, such as tabular, frame, or subfigure. Oct 19, 2023 at 12:59
  • Hi Mate, thanks for the kind comment! In the next version, which should be up soon, I included examples of how to use arrows in the default shortcuts. For your specific need, it would be alt-ArrowUp. Keep in mind that is already a (useful!) default keyboard shortcut in Overleaf. You will overwrite it if you add it like that (which is a new feature also coming with the new version: custom shortctus will now take precedence). As for the second comment, could you ellaborate on what you would like? Oct 30, 2023 at 22:28
  • Environments like tabular have additional arguments (for example \begin{tabular}{lrcc} or \begin{subfigure}{0.5\textwidth}). I'm currently using a Command definition for this kind of environments: \begin{tabular}{%|%}%.%\end{tabular}. However, this doesn't insert the new lines like smart environments do. Ideally, the selection and cursor could be handled like they are in Commands, while the rest should still get handled as an Environment. Nov 7, 2023 at 15:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .