-
Notifications
You must be signed in to change notification settings - Fork 389
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
completion is missing equation labels when using autonum #2976
Comments
Interesting request. I have not heard of
Well, it's a relatively big and complex change, because we would need to merge the results. To be honest, I'm not very motivated to work on this, as I don't see myself needing or using this feature. But I won't mind considering a PR for it.
For me, this never really happened frequently. Perhaps because I save more often than you? |
I don't use the vim.cmd([[
function! OrderLabels(l1, l2)
return a:l1[1] == a:l2[1] ? 0 : a:l1[1] > a:l2[1] ? 1 : -1
endfunction
" Sorts labels by proximity to the cursor position, since recently created labels are likely to be references. Also removes VimTeX's dependence on LaTeX rendering to get labels.
function! GetLabels()
let l:result = []
let l:regex_pattern = '\\label{\([^}]*\)}'
let l:cursor_line = line('.')
for line_number in range(1, line('$'))
let l:line = getline(l:line_number)
let l:distance = abs(l:cursor_line - l:line_number)
call substitute(l:line, l:regex_pattern, '\=add(l:result, [submatch(1), distance])', 'g')
endfor
return sort(l:result, "OrderLabels")
endfunction
function! PasteLabel(label)
execute "normal! a" . a:label
call feedkeys('a')
endfunction
function! FzfLabels()
call fzf#run({
\'source': map(GetLabels(), 'v:val[0]'),
\'sink': function('PasteLabel'),
\'window': {'width': 0.9, 'height': 0.6},
\})
endfunction
]])
vim.keymap.set('i', '<C-f>', '<Esc>:call FzfLabels()<CR>', { silent = true, noremap = true, buffer = true }) |
Ok, let's say I were to consider implementing label completion based on manual parsing of the LaTeX file. How should it behave with respect to the current completion parser? For instance, this might work:
Thoughts? |
That sounds good to me, assuming "compiled" means "compiled with the latest changes." In other words, if we can ensure manual parsing will add no benefit, then we will skip it and just do fancy parsing. Otherwise, do manual and fancy parsing. |
This is a rather low-priority issue.
Is your feature request related to a problem? Please describe it.
When using the
autonum
package1 equations that are\label
ed but not\ref
erenced don't appear in the aux file. Hence they don't appear in vimtex's completion.Describe the solution you'd like
Maybe it would be possible to just search the current file for
\label
s and add those to the completion function?. This would also fix\label
s not appearing in completion if the document has not been compiled since they were added (which happens frequently because most of time you add a\label
you will\ref
erence it right away.)Footnotes
The main feature of this package is that
\label
ed equations in the source that don't\ref
erenced don't get labeled in the pdf ↩The text was updated successfully, but these errors were encountered: