Skip to content

Completion source for LaTeX commands#770

Closed
lervag wants to merge 5 commits intomasterfrom
feature/completion-cwl
Closed

Completion source for LaTeX commands#770
lervag wants to merge 5 commits intomasterfrom
feature/completion-cwl

Conversation

@lervag
Copy link
Copy Markdown
Owner

@lervag lervag commented Apr 9, 2017

Adds a completion source for LaTeX commands. Very simple implementation, but should still be pretty useful.

When finished, this should solve #650.

@lervag lervag force-pushed the feature/completion-cwl branch from dbfb012 to 1d09437 Compare April 10, 2017 09:07
@lervag lervag force-pushed the feature/completion-cwl branch 2 times, most recently from d89e997 to 6606657 Compare April 10, 2017 12:47
@lervag
Copy link
Copy Markdown
Owner Author

lervag commented Apr 10, 2017

Ok, so now it remains to generate good command completion sources. I think perhaps it is not desirable to include every imaginable command. Instead, I think, it would be more useful to only have the most relevant commands. Or, what do you guys think?

@kiryph @poppyschmo

Note: The current implementation supports:

  • Loading class sources (prefixed with class-) and package sources
  • #include: to include nested packages/classes
  • Adding a mode indicator (this probably needs adjustment/improvement)
  • Adds indicator to the completion menu about the package provider

The complete file syntax is this:

# include: package
command[ mode]
...

Here the mode string is not necessary, and if it is not provided, the command is completed in both normal and math mode.

The implementation lacks unicode symbols. I don't see how to add that in a simple manner. But if you guys would help me to generate the source files, then we could define a syntax such as this:

command, mode, symbol

Or perhaps there is a way to "infer" the symbol based on the command name?

Note: I've decided not to use the cwl files directly, because they include very much more than just simply the command names. Even though it is some work to convert the cwl files to vimtex, I think it is worth the effort. But I also question the necessity of adding every possible command, and not just the frequently used ones.

@kiryph
Copy link
Copy Markdown
Contributor

kiryph commented Apr 11, 2017

Is there a possibility to setup neocomplete with this?

Regarding the conversion of latex commands to unicode. Following scripts might be helpful to create these files:

Enter \right and pressing ctrl-x ctrl-o shows me also candidates which do not start with right. I am not sure whether I like this. I think I appreciate this behaviour for citations.

@lervag
Copy link
Copy Markdown
Owner Author

lervag commented Apr 11, 2017

I use this to setup neocomplete (note the last line that will match commands):

let g:neocomplete#sources#omni#input_patterns.tex =
      \ '\v\\%('
      \ . '\a*cite\a*%(\s*\[[^]]*\]){0,2}\s*\{[^}]*'
      \ . '|\a*ref%(\s*\{[^}]*|range\s*\{[^,}]*%(}\{)?)'
      \ . '|hyperref\s*\[[^]]*'
      \ . '|includegraphics\*?%(\s*\[[^]]*\]){0,2}\s*\{[^}]*'
      \ . '|%(include%(only)?|input)\s*\{[^}]*'
      \ . '|usepackage%(\s*\[[^]]*\])?\s*\{[^}]*'
      \ . '|documentclass%(\s*\[[^]]*\])?\s*\{[^}]*'
      \ . '|\a*'
      \ . ')'

I'll look into your suggested links for unicode conversion. Also, I agree that for this completion type, we should anchor the regex. I'm updating and pushing now.

@kiryph
Copy link
Copy Markdown
Contributor

kiryph commented Apr 11, 2017

I miss the completion of \includegraphics from https://cgit.kde.org/kile.git/plain/src/data/complete/tex/graphicx.cwl

demo-complete

@poppyschmo
Copy link
Copy Markdown

The symbol stuff is pretty trivial. This .json file includes most of the common unicode glyphs. Also, many of these scripts were made expressly to scrape various sources for these same symbols, though with more of an eye toward the "web"/js side of things.

@lervag
Copy link
Copy Markdown
Owner Author

lervag commented Apr 12, 2017

Thanks, @poppyschmo! I already figured out a lot of this stuff myself, e.g. from this SO post. Do you have any idea if your sources are better than the method from that post?

@lervag lervag force-pushed the feature/completion-cwl branch from 6c58b1f to 313675f Compare April 12, 2017 20:59
@lervag
Copy link
Copy Markdown
Owner Author

lervag commented Apr 12, 2017

Ok, I ended up combining symbols from several sources. I also made a script to add symbols to complete files. In any case, the current version should also show symbols when available.

@lervag
Copy link
Copy Markdown
Owner Author

lervag commented Apr 12, 2017

The question now is: Is the feature appropriate in itself? In that case, I propose to clean up and merge, independently from working on improved sources for command completion.

@lervag lervag force-pushed the feature/completion-cwl branch from 4998a2c to 5ce8f4b Compare April 15, 2017 06:10
@lervag lervag force-pushed the feature/completion-cwl branch from 5ce8f4b to 7352298 Compare April 15, 2017 07:08
@lervag
Copy link
Copy Markdown
Owner Author

lervag commented Apr 15, 2017

Ok, I've ended up writing a parser for the cwl files and generated completion files based on texstudios cwl files. I think we now have a large set of completion candidates, as well as symbols for most (relevant) commands.

What is lacking now is mode specific completion, but I think this should be fine for now.

If someone would be willing to learn the format of the cwl files from texstudio and explain how to parse the mode specifiers, then I could try to parse that as well and add mode specific command completion.

lervag added a commit that referenced this pull request Apr 15, 2017
@lervag
Copy link
Copy Markdown
Owner Author

lervag commented Apr 15, 2017

I've merged this now. Feel free to open new issues, I think there are several things that can be improved still.

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.

3 participants