-
Notifications
You must be signed in to change notification settings - Fork 391
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
spell/nospell doesn't work properly in optional parameter for theorem-like environment #2086
Comments
This needs more refinement. Different commands work differently. The So, to move forward, we need to be more specific. I.e., for Text inside |
Thanks so much for your quick answer. I will try be more specific on theorem-like environments, which is the more important issue IMHO. I redid the example, I hope it's better explained now. This example compiles without any warning and no external packages. \documentclass{article}
% Theorem-like environment is introduced by \newtheorem
% - first mandatory argument is the code-name for the environment
% should NOT be spell-checked (but it currently is)
% - optional argument after first mandatory argument is the code-name
% of the counter to use, should NOT be spell-checked (but it
% currently is)
% - second mandatory argument is the name to print, so that one SHOULD
% BE spell checked (as it currently is OK)
% - optional argument after second mandatory argument is the code-name
% of a counter (in this case it means number theorems by sections)
% so it should NOT be spell-checked (it currently is)
\newtheorem{thm}{Theorem}[section]
\newtheorem{prp}[thm]{Proposition}
\begin{document}
% Theorem-like environment defined above, code-name "thm"
% The optional argument should be spell-checked, but not if it is
% inside \ref{...}, \cite{...}, etc.
%
% Currently: the optional argument is not spell-checked, and it also
% disables the nospell attribute for \ref{...}, \cite{...}, etc.
\begin{thm}[description of theorem abc \cite{abc}]
My theorem goes here.
\end{thm}
% Just to ilustrate another theorem-like environment
\begin{prp}[pleaze spelll check]
My proposition goes here.
\end{prp}
\begin{thebibliography}{1}
% BTW, "abc" here should not be spell-checked (it is)
\bibitem{abc} a citation.
\end{thebibliography}
\end{document} EDIT: added 'optional argument after second mandatory argument' for Documentation for |
Here's my attempt at an implementation for the syn match texCmdNewthm "\\newtheorem" nextgroup=texNewthmArg1 contains=texCmd
call vimtex#syntax#core#new_arg('texNewthmArg1', {'next': 'texNewthmOpt1,texNewthmArg2', 'contains': 'TOP,@Spell'})
call vimtex#syntax#core#new_opt('texNewthmOpt1', {'next': 'texNewthmArg2'})
call vimtex#syntax#core#new_arg('texNewthmArg2', {'next': 'texNewthmOpt2'})
call vimtex#syntax#core#new_opt('texNewthmOpt2')
highlight def link texNewthmArg1 texArg
highlight def link texNewthmOpt1 texOpt
highlight def link texNewthmOpt2 texOpt With this in place, only the second mandatory argument for As for the theorem-like environments themselves, which is the most important issue, I realized that all optional arguments for environments are treated as nospell. I would argue this is incorrect, because false negatives are worse than false positives. My preference would be to make optional arguments default to spell, and add exceptions for commands and environments that should have nospell optional arguments. Would this be ok? As an (imperfect) workaround I'm using this " environments whose arguments should be spell-checked
for s:env in g:vimtex_syntax_spell_environments
exec 'syn match texCmdEnv "\\begin{' . s:env . '}" contains=texCmdEnv'
endfor together with the following config let g:vimtex_syntax_spell_environments = [
\ "proof",
\ "thm",
\ "prp",
\ ] The problem of this is that one has to add to It would really feel much safer to default to spell with explicit exceptions. Also, a global array |
I think I've resolved this issue now, please test with latest version. |
Please note: The optional group for the theorem environments depend on the |
Thanks a lot! Note that the optional group for theorem environments doesn't depend on In fact, in |
The one other thing related to theorems is the
As mentioned in "lshort", sect 3.9, this is available when Should I open a different issue for this one? The following seems to work:
|
Ah, ok. I'm pushing a change to fix this now. I'm also changing the reference to the lshort manual, as it seems more complete. Note, in my first version I included a minor cache (which works in multi-file projects). I was not able to do that now. By moving it to core, I also moved code that parses the preamble into core. This may give a noticable impact on load times. I've checked and did not measure anything, but its hard to be sure. If I do find this negatively impacts load times, then I might consider to move this back to
Heh, nice catch.
Thanks, this should work now. |
Again, thanks a lot for the quick work!
If you have to disable this by default, could you offer an option so one can choose to reenable? |
Ah, I guess that's the reason why the last commit broke syntax highlighting for me if I use a fuzzy finder to open files... (see comment on the last commit, which is the breaking one -- if I revert only that, things work again). |
Not unexpected to see that this thing broke. @tornaria I've reverted this for now by simply disabling it. I think it is necessary to find a more reliable way to do this, so I will reopen this issue and figure out a better way. In the meantime, I hope you don't mind that I've removed the functionality. |
Yep, works again, thanks :) |
For my own reference: See #2120 for a simple way to test for errors with the functionality. My current idea is that we need to allow some syntax rules to be applied after the filetype plugin has initialized. So, something like this:
|
Ok, now the custom theorems should work again. I believe this is implemented more robust now and the previously mentioned issues should be resolved. |
Inside optional parameters for theorem-like environment and also other macros (notable exception I could find:
\title
, see below), text is usually nospell. Moreover, the arguments of a\ref{....}
or\cite{...}
inside this optional parameter are spell.Desired behaviour:
\ref{...}
or\cite{...}
is never spell-checkedTo try, just load the file below and
:set spell
.The text was updated successfully, but these errors were encountered: