Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support LaTeX-to-Unicode tab expansion #21

Merged
merged 4 commits into from
May 24, 2014

Conversation

carlobaldassi
Copy link
Contributor

This adds support using tab to complete LaTeX symbols in ViM like in the Julia REPL.
However, in order to do so, it may need to interact with other plug-ins installed in the system.

The default (vanilla) behaviour is that upon pressing TAB a latex entry is searched for before the cursor, but if it's not found a literal TAB is inserted. I did not add any mapping to explicitly force a literal tab insertion, which however should always be available with ^V+TAB.
The substitution is assigned to the omnicompletion setting, so it's also available with ^X^O.

I'm a user of supertab and it seems everything works great with that, but perhaps other users may have custom settings which are conflicting, or get overridden etc., in which case please do let me know.

Another popular plug-in I know about is YouCompleteMe, which at the moment is incompatible with this setting, since it overrides the TAB key binding. At the moment, it seems that the options are 1) change the YCM settings to free up the TAB key for the Julia plug-in, or use ^X^O to force the Julia omnicompletion to kick in and do the LaTeX-Unicode translation.

Any user of these or other completion plug-ins, or which have remapped the tab key somehow, are encouraged to give it a try, provide suggestions etc. If there are no major problems or objections I shall merge this as is, and then it can be refined later.

@stevengj
Copy link

If there is a previous tab-key binding, can you call it if the LaTeX completion fails?

" Support for LaTex-to-Unicode conversion as in the Julia REPL

" (The dictionary was generated from within Julia with the following line:
" println("let g:latex_symbols = {", join([string("'", latex, "': '", unicode, "'") for (latex,unicode) in Base.REPLCompletions.latex_symbols], ','), "}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the symbol table is updated in the future, this will have to be re-run. To generate smaller diffs when this happens, you might consider:

  • Putting one symbol per line
  • Sorting the symbols by codepoint: for (latex,unicode) in sort!(collect(Base.REPLCompletions.latex_symbols), by=x->x[2])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorting is a good idea. As per one symbol per line, I tried and failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok this is also fixed now.

@carlobaldassi
Copy link
Contributor Author

Updated. Now it works by overlaying the latex-to-unix machinery on top of any other mapping the user may have, i.e. it tries to complete latex symbols and if it fails falls back to the user mapping, as @stevengj was suggesting.
This should be completely generic, if not let me know / file issues. I tested it with vanilla (no previous special mapping for tab), supertab and YouCompleteMe. Of course I could not test all possible corner cases, but I hope most vim configurations and plugins are covered.
I'll add an option to disable it and then merge.

carlobaldassi added a commit that referenced this pull request May 24, 2014
Support LaTeX-to-Unicode tab expansion
@carlobaldassi carlobaldassi merged commit c69c2ab into JuliaEditorSupport:master May 24, 2014
@stevengj
Copy link

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants