Home Download Buy Blog Forum Support

realtime autocomplete for tex files?

realtime autocomplete for tex files?

Postby gregor.hoch on Mon Oct 01, 2012 10:01 pm

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!
gregor.hoch
 
Posts: 128
Joined: Sat Oct 01, 2011 7:54 pm

Re: realtime autocomplete for tex files?

Postby gregor.hoch on Sun Oct 07, 2012 1:08 pm

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.
gregor.hoch
 
Posts: 128
Joined: Sat Oct 01, 2011 7:54 pm

Re: realtime autocomplete for tex files?

Postby skuroda on Mon Oct 08, 2012 6:41 am

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.
Code: Select all
{
    "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.
Code: Select all
    "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!
skuroda
 
Posts: 674
Joined: Fri Oct 05, 2012 8:11 am

Re: realtime autocomplete for tex files?

Postby gregor.hoch on Mon Oct 08, 2012 11:22 pm

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:

Code: Select all
<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>



2) The syntax specific settings:

Code: Select all
{
    "auto_complete_triggers": [ {"selector": "text.tex", "characters": "\\"},{"selector": "text.tex", "characters": "ci"} ],
    "auto_complete_commit_on_tab": true,
    "spell_check": true
}


3) And finally (very important) a user specific keybinding:
Code: Select all
{    "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.
gregor.hoch
 
Posts: 128
Joined: Sat Oct 01, 2011 7:54 pm

Re: realtime autocomplete for tex files?

Postby sathishkumar on Thu Jan 02, 2014 8:33 am

Hi gregor.hoch, Did you complete the comprehensive list of all latex commands package. Expecting it soon.
sathishkumar
 
Posts: 1
Joined: Thu Jan 02, 2014 8:30 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 13 guests

cron