Sublime Forum

Realtime autocomplete for tex files?

#1

Hi,

in Python, Javascript, and R, I get realtime autocomplete suggestions. So I just type to letters and get a number of suggestions. In tex files, however, I don’t get the realtime autocomplete popup. Pressing tab either automatically completes my text (I guess when there is just one match) or shows the popup, which I would like to see in real time! How can I change that? I guess it doesn’t make sense to show previously defined objects but I want to see my snippets. Does it has something to to with the scope “source” vs. “text”?

Thanks!

0 Likes

#2

no one?

In html, I type ‘<’ and get a list of autocomplete options. For tex, I have create a on_query_completions function that provides similar options when typing \ but I have to invoke the autocomplete list manually. Why is that? I would like to type ‘’ in tex and immediately get the popup with autocomplete options from my on_query_completions function.

0 Likes

#3

Hope you come back to this. Came across your post when I was trying to do the same thing, and forgot to come back when I had a solution, so here it is.

I created a syntax specific config (in Packages/User/LaTeX.sublime-settings) and used the code below. The downside is there is a popup for all normal text as you are typing, but to me it’s worth it. It’s easier for me to ignore that than remember all the snippets. Obviously the “auto_complete_commit_on_tab” and “spell_check” settings aren’t required. The important thing (I think) is the “auto_complete_selector”. With no value prior to the “-” my guess is it defaults to “text” but I’m not 100% sure. It does work if you do “text - comment” though. The “- comment” prevents the pop up from occurring within comment lines in the tex file.

{
    "auto_complete_selector": "- comment",
    "auto_complete_commit_on_tab": true,
    "spell_check": true
}

The html pop up is a result of the following setting, which is part of the default preferences. So if you only want the autocomplete after “”, you may use something similar.

    "auto_complete_triggers":  {"selector": "text.html", "characters": "<"} ]

Side note, I think I replied to your post in LatexTools as well, relating to saving in a different directory.

Hope that helps!

0 Likes

#4

Yes, you did. Thanks for both replies.

Here is my solution, which might be helpful:

  1. I have a number of snippets for different cite types. They are all triggered with cite and look like this:
<snippet>
	<content><![CDATA[
\citep{${1}}
]]></content>
	<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
	<tabTrigger>cite</tabTrigger>
	<!-- Optional: Set a scope to limit where the snippet will trigger -->
	<scope>text.tex</scope>
    <!-- Optional: Description to show in the menu -->
    <description>(author year)</description>
</snippet>
  1. The syntax specific settings:
{
    "auto_complete_triggers":  {"selector": "text.tex", "characters": "\\"},{"selector": "text.tex", "characters": "ci"} ],
    "auto_complete_commit_on_tab": true,
    "spell_check": true
}
  1. And finally (very important) a user specific keybinding:
{ 	"keys": "tab"],
		"context":  
			{"key": "selector", "operator": "equal", "operand": "text.tex"},
			{ "key": "preceding_text", "operator": "regex_contains", "operand": "cite(\\w]*)?\\{", "match_all": true }
		],
		"command": "latex_ref_cite"}

This keybinding triggers the selection of a reference when the user presses tab but only if the preceding text is something like ‘citep{’. So as a result I can just type ‘c’, which triggers the popup with the different cite auto-completions. Now I select one such as (author year) using ‘tab’, which completes c to ‘\citep{}’. I press tab again and the popup for the bibtex key comes up. This works super well for me.

ps: I am also triggering the auto-completion after \ but I am still working on getting a popup with a comprehensive list of latex commands.

0 Likes

#5

Hi gregor.hoch, Did you complete the comprehensive list of all latex commands package. Expecting it soon.

0 Likes