Sublime Forum

LaTeXTools: Custom macro for cite/ref

#1

Hello. I’m new to using LaTeXTools with Sublime and I really like the auto-complete feature that comes with \cite and \ref, that is, \cite{ automatically pulls up the entries from the linked .bib file.

However, by habit, I always complete my brackets manually and immediately, that is, I always type {} or () and then reposition my cursor to inside the brackets. As a result, whenever I try to cite an entry, I usually type \cite{} and since the auto-completion is triggered by \cite{, the } goes into the search box. Is there any way to prevent this? I’ve tried disabling the cite_auto_trigger in the user preferences file and then using macros, with manually typing in C-l,x after positioning my cursor between { and }, but it doesn’t work.

Is there any work-around for this issue? My final goal is to assign a keyboard shortcut to the whole process, something like c,c,tab would automatically pull up the possible keys and let me choose from them, and after choosing I can continue typing without having to worry about closing the }, but I can do that part myself once I know how to trigger the auto-completion without worrying about the braces.

Thanks in advance.

0 Likes

#2

There isn’t really enough detail in your post do figure this out. The process you’ve laid out, i.e., disabling cite_auto_trigger is the way you would disable the {-based auto-completion and typing ctrl + l, x (or cmd + l, x on Mac) should give you the menu and let you select the bibliography entry you want to cite. Just to be abundantly clear, that’s, e.g., ctrl + l simultaneously followed by x.

There’s also the somewhat finger-bending C-l,alt+x,c command that will give you the menu and insert the citekey at your current cursor location with no additional bells and whistles.

0 Likes

#3

Hi there. Thanks for your reply. I am aware that disabling the cite_auto_trigger will not automatically bring up the citekeys as a nice drop-down. My issue is that since I immediately close braces, this is not useful since the auto-trigger detects cite{ and the extra } that I type immediately goes into the search box. I’m trying to prevent this behaviour.

One possible way I’ve thought of getting what I want is by using a macro as decribed above, but it doesn’t work as I want it to. In short, I’m trying to automate the following keystrokes, in order: \ c i t e { } left-arrow C+l x and then assign this to a shortcut, say c,c,tab so that when I press the shortcut, I get the expected drop-down from where I can choose the cite-keys.

Sorry if it was not clear earlier. Thanks in advance.

0 Likes

#4

It seems that what you need is first to deactivate the auto-completion in the Sublime settings. This would prevent the menu with citations from popping up automatically. Then, you need to install Chain of Command from package control. This package allows you to run multiple commands that are triggered with a single hotkey (in this case, a move and a latex_fill_all command).

0 Likes

#5

Hi, I just had a quick look at this and it looks promising. I’ll try it out and let you know. Thanks, and have a good day!

0 Likes