-
Notifications
You must be signed in to change notification settings - Fork 409
RFC: Add completion file for tkz-euclide #3175
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
Conversation
Sort of. The way these completion packages work is that they are loaded if the package with a corresponding name is recognized. Do you have a small compilable sample
I don't think that's possible, and I don't see an immediate simple solution for it, sorry. But again, it would be easier to consider it if I saw an example of how this looks.
Good question! It is not possible through any features, but you can force it. E.g., if you open some minimal latex file - doing I don't think I want to add a specific feature for it, but it should be very easy to make a simple custom feature here, e.g. a custom mapping or custom command that simply loads a package for you. Something like this, for instance: command -nargs=1 AddPackage :let b:vimtex.packages[<q-args>] = {} |
Version: v5.10c (April 2024) with a sample document
ce3265a to
03711b4
Compare
If I get this correctly, the answer is closer to no. They are not shown if the package is not loaded, but it does not depend on the current surrounding environment. I have looked at the default omni-completions as described under Another possibility is to look into completion plugins like nvm-cmp and their filtering capabilities: https://github.com/hrsh7th/nvim-cmp/blob/main/doc/cmp.txt#L678-L700 However, I am not sure how to create different sources for the LaTeX preamble, default LaTeX context, math environments, TikZ environments, and others. or LuaSnip: https://github.com/L3MON4D3/LuaSnip/wiki/Cool-Snippets#context-aware-snippets
I have added one.
That's ok. I just wanted to ask.
Thanks for pointing a custom solution out. I actually would do it the following way using one of local au_group = vim.api.nvim_create_augroup("vimtex_events", {})
vim.api.nvim_create_autocmd('User', {
pattern = 'VimtexEventInitPost',
group = au_group,
command = "let b:vimtex.packages['tkz-euclide'] = {}"
})I have placed this in my When I open a minimal.tex document \documentclass{article}
\begin{document}
\end{document}and then press System info:
OS: macOS 12.6.1 (21G217)
Vim version: NVIM v0.11.1
Has clientserver: true
Servername: /var/folders/2z/bljkcy1j2cbf7l9zf3dk0nqc0000gn/T/nvim.kiryph/IzSTOs/nvim.69250.0
VimTeX project: minimal
base: minimal.tex
root: /Users/kiryph
tex: /Users/kiryph/minimal.tex
main parser: current file verified
document class: article
packages: tkz-euclide
compiler: latexmk
engine: -pdf
options:
-shell-escape
-verbose
-file-line-error
-synctex=1
-interaction=nonstopmode
callback: 1
continuous: 1
executable: latexmk
viewer: sioyek
qf method: LaTeX logfileFirst I was surprised, the buffer-local variable |
I'm sorry, but I didn't quite understand your thoughts here. VimTeX relies on omni completion and uses the line context to determine which type of completion will be performed. The https://github.com/lervag/vimtex/blob/main/autoload/vimtex/complete.vim#L292
Thanks! I'll adjust it so that the tests work and merge this, then.
Or even more Lua: local au_group = vim.api.nvim_create_augroup("vimtex_events", {})
vim.api.nvim_create_autocmd('User', {
pattern = 'VimtexEventInitPost',
group = au_group,
callback = function()
vim.b.vimtex.packages['tkz-euclide'] = {}
end
})
That's strange - this does not happen on my end. The variable is present as expected whenever I test it. |
Consider the lines 299 and 302 in vimtex/autoload/vimtex/complete.vim Lines 297 to 305 in 22d9ae5
They apparently check if a user tries to complete a command in a math zone and filter candidates accordingly. I had to search for a while in the repo to find the completion candidates which offer the value They are in https://github.com/lervag/vimtex/blob/master/autoload/vimtex/complete/tools/symbols.json If I overlooked something, let me know. So I miss something which filters based on let l:mode = vimtex#syntax#in_mathzone() ? 'm' : vimtex#env#in_tikz() ? 't' : vimtex#env#in_document() ? 'n' : 'p'Relevant existing vimtex functions vimtex#env#get_inner
vimtex#env#get_outer
vimtex#env#get_all
vimtex#env#is_inside
vimtex#syntax#in_mathzone
vimtex#syntax#inAnd of course the command completion candidates have to be added to the So I checked the repo of TeXstudio. Apparently, TeXstudio has many handwritten https://github.com/texstudio-org/texstudio/blob/master/completion/tkz-euclide.cwl The https://texstudio-org.github.io/background.html#description-of-the-cwl-format and supports many features. For example a long list of classifications: https://texstudio-org.github.io/background.html#classification-format I actually miss a dedicated The
Update: Also environments can be marked as an alias for other, so that Is it clearer now what I am talking about? Since so much work has been done for the
Thanks. But as indicated I get tkz-euclide omni-completion candidates also outside of a And apparently, TeXstudio has the same behavior: |
|
Update I checked old issues and apparently we had already a command completion discussion in 2017:
I guess I was asking what you have mentioned back then that this was left to implement:
2nd Update Someone else has asked more or less the same for LuaSnip: I guess I will go down this road as well. |
Ah, yes. I've comletely forgotten about that!
Yes, I guess this was something I was thinking about back then.
Yes, definitely.
Well, to be honest, this feels like a big task, and one where I'm not immediately sure where to start. And I'm sorry to say I don't think I have the time to work on this. As you noticed, the completion works, but it is not context dependent. So, clearly, it could be improved, but it is also better than nothing. I would not mind considering PR's, of course, but I don't think I'll pursue this personally. |
I agree that this is probably a big task. Right now I think delegating this to a snippet plugin like LuaSnip is probably the best option without putting too much burden on VimTeX. LuaSnip has already a wiki entry how to define snippets using conditions based on information from vimtex: So defining the completion candidates can be left to the user. However, I am not sure how to check if a package was loaded. I will raise a separate issue/discussion for this. Nevertheless in the long run I see value in collections of snippets or support existing cwl files since most people do the same thing. A few references, if someone wants to take on the cwl path, e.g. a converter from cwl format to LuaSnip format:
Alternatively, I think a |
Yes, agreed, this sounds like a good option.
Thanks for sharing! |


I have several questions:
The completions should only be visible within tikz environments. Is this possible?
tkz-euclide offers a package option
[mini]. In this case only a subset of the completion candidates should be loaded. Here the user wants to use the package tkz-elements and write the coordinate calculations and definitions in lua code.Is it possible to have variants of completion files for the same package dependent on a package option?
When using the tool robust-externalize, it is possible to NOT load tikz and the tkz-* packages in the main document. However, the code is still in the main document. Can a VimTeX user specify manually to load certain packages for completion regardless of
.flsand preamble parsing? I have seen the optiong:vimtex_syntax_packageswith theloadvalue of 2. But it is not clear if this option is also considered for omni-completion.Note
The list of commands is generated from the texmf tree of TeXLive 2024 and tkz-euclide version: v5.10c (April 2024)
with following ripgrep command applied on the path
/usr/local/texlive/2024/texmf-dist/doc/latex/tkz-euclide:Other possible source is the
.cwlfile for tkz-euclide in TeXStudio:https://github.com/texstudio-org/texstudio/blob/master/completion/tkz-euclide.cwl