-
Notifications
You must be signed in to change notification settings - Fork 386
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
RFC: Adopting full syntax support into vimtex #1781
Comments
I would welcome this (not that Dr Chip isn't doing a great job!) and couldn't think of a person I'd trust more. Con 1 is of course a big con and would understandably be sufficient in itself. The possibility of faster updates would indeed be appealing -- there was a recent nasty bug in the syntax file that took quite a long time to percolate down to neovim. (Of course, it's trivial to put a fixed file into Another advantage is that you can be more opinionated about defaults than a default vim syntax -- for example, finally making |
Hi, Firstly, let me just say that I appreciate this plugin very much. I was able to write my honours thesis in neovim and it was awesome. Now, back on topic, I have noticed one issue in the syntax highlighting for a while, but it was not a big deal so I didn't worry. I came here to post an issue, but maybe I will piggyback in this thread first, since I am not sure now if it is a problem in vimtex or in the syntax file. When I place the cursor on a Does vimtex draw these highlights? Or should I go to the syntax maintainer (Dr Chip?). It should be trivial to reproduce, so I could post a proper issue if you prefer. Since I am here, I will give a quick vote on full syntax support: Yes. I agree with @clason that such a framework (even as an opt-in) could be useful. I am very green with LaTeX, but it seems there are many versions/variations and people could hopefully help to add support for their favourite setup. For example, I would welcome support for TikZ and friends. |
+1; notice that just looking around I found this: https://github.com/gi1242/vim-tex-syntax (not tested). Another really nice thing would be to add LaTeX3 syntax highlighting; it would be activated between (I'll copy here the file if somebody is interested in giving it a try; notice that the syntax highlight on GitHub is also off, this is quite new stuff) There is a "dirty hack" here, that I use manually: https://tex.stackexchange.com/questions/44624/vim-configuration-for-expl3 % see https://tex.stackexchange.com/questions/557511/how-to-query-iffilehaschanged
\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\str_new:N \g_myfile_name_str
\str_gset:Nn \g_myfile_name_str {myfile.txt}
\str_new:N \g_myfile_old_mdfive_str
\str_new:N \l_myfile_mdfive_str
\cs_new_protected:Npn \getmdfive % get hash is not expandable, so protect
{
\file_get_mdfive_hash:nN {\str_use:N \g_myfile_name_str} \l_myfile_mdfive_str
\str_use:N \l_myfile_mdfive_str
}
\cs_new:Npn \getoldmdfive
{
\str_use:N \g_myfile_old_mdfive_str
}
\cs_new:Npn \IfMyfileChanged #1 #2
{
\str_if_eq:NNTF \g_myfile_old_mdfive_str \l_myfile_mdfive_str {#2} {#1}
}
\AtEndDocument
{
\iow_now:cx { @auxout }
{
\token_to_str:N \ExplSyntaxOn
\iow_newline:
\str_gset:Nn \token_to_str:N \g_myfile_old_mdfive_str {\str_use:N \l_myfile_mdfive_str}
\iow_newline:
\token_to_str:N \ExplSyntaxOff
}
}
\ExplSyntaxOff
\begin{document}
MD5 was \getoldmdfive
MD5 is now \getmdfive
Changed? \IfMyfileChanged{Yes, it has changed}{No, it's the same as before}
\end{document} |
Another thing that this would allow is cleaning up and consolidating (or extending, if necessary) the highlight groups. I've been thinking of finally biting the bullet and writing my own tex-specific color scheme and ideally would like to color math commands differently from text commands (and differently from environments and labels etc.), and this would be a good opportunity. (Let me know if discussion of tex color schemes would make for a good separate issue.) If you do go for this, I'd second @Rmano's suggestion of looking at https://github.com/gi1242/vim-tex-syntax as a basis, which looks quite clean. Also, @Rmano: did you see https://github.com/wtsnjp/vim-expl3? |
No, I was not aware... is it compatible with vimtex? I really do not know how to use it alognside the normal latex. It should be a sublanguage, triggered by |
I would assume it won't conflict so you can just load it, but I don't know the best way to inject it into a tex syntax; I'd look into how vimtex extends the builtin syntax for the different packages in https://github.com/lervag/vimtex/tree/master/autoload/vimtex/syntax. In any case, Expl3 support should probably be a separate issue, independent of whether the base tex syntax file is replaced. |
@clason @Rmano @adigitoleo Thanks for the support/votes! I think I want to try this, but as said and as I think you understand, it will not be something I'll be doing first thing. Perhaps I'll start working on it and finishing a version before Christmas, but I won't make promises.
Hear hear!
Yes, this is one of the reasons I want to do this. I think and hope that it is possible to both simplify and "standardise" more on what I think are more sensible and modern defaults.
It might be. I'm not 100% sure what you mean, and I don't mind discussing things. I would prefer to keep the topics separated, so let's do it in a separate issue.
Thanks! :D
The feature you describe sounds like the
Interesting! But for my own sanity and for keeping topics separated, I would prefer if we discuss this in a new/other thread. It seems @clason found a relevant plugin. If it does not immediately work with vimtex, feel free to open an issue and we can discuss it further there.
Thanks for the heads up!
I agree that it at looks clean. I'm worried, though, that it would require a more full cleanup of all the syntax stuff. Has anyone tried to use When I start work on this I will definitely work in a separate branch that will be merged as a PR. The change will be significant, and so I think it might require a major version bump when the PR is merged. Thus I also don't want to merge until I'm confident that users will
I will be very happy if I get help with testing when things are progressing. I would also like feedback on which of the old/legacy features are important to keep and which can be "safely" removed. One relatively important aspect is efficiency. Thus, it may be very useful to be able to test the speed of the syntax before and after. I want to simplify things and remove e.g. |
👍 (it does have some bearing on this, since it involves the highlight groups that are defined in the syntax file and how they are linked, but it makes sense to first discuss what can be done with the current file).
I've briefly put it in my
Might I suggest then instead to develop on the main branch but put the new syntax behind a (by default off) option (Assuming this is even feasible.)
Definitely (you know me ;))! Another aspect would be to allow using "high-level" syntax groups to be used in ex commands -- for example, replace only in math zones, or outside math zones (but not commands) etc. |
Done! |
If it's feasible, I agree. Another possibility is to define a syntax like |
@lervag Thanks for the pointers, you are correct my issue is related to matchparen and it's not specific to vimtex. I will keep an eye on the syntax side of things and help if/when I can, although I can't say I'm very experienced in vim-fu (or development in general 😄 ) |
Ok, that does sound good! I'll look into if it is possible to use this as a starting point, then.
Good idea! I'll do this. But note, the changes will require changing a lot of the current syntax code as well, and when that starts to happen I can't simply "flip a switch". So I might take dev to a branch at that point. But as long as it is possible to keep the current behaviour intact while working on the new syntax scripts I can do this with a temporary option
Great! :D I'm not sure I fully understand what you mean by high-level syntax groups, perhaps you could give an example? Or we could discuss it later, unless it is something worth discussing early to avoid redundant work? |
Yes, perfect!
It's probably not quite relevant at this point, but maybe it helps keeping in mind? What I'm hoping for is something like a syntax group :%s/foo/\=synIDattr(synID(line('.'),col('.'),1),'name')==#'isMath'?bar:foo/g to only replace |
Ah, I see. I mean, this is sort of already possible? At least in the sense that all math is captured by groups like |
Consistent, and documented, yes -- I think that is the core of what I'm asking about here (and in the color scheme issue).
That's what I was trying to get at in #1800. Besides text and math, I'd distinguish "tex commands" -- TikZ and pgfplots would fall under that. (If I want to do something TikZ specific, I'll probably either do By the way, after writing that comment, I realized that there's already :s/A/\=vimtex#util#in_mathzone()?'B':'A'/g Not documented, though ;) |
@clason Hi, you wrote:
FWIW I agree, that is probably smarter than adding tikz specifics, generic "tex commands" patterns are probably easier to maintain. I only recently started using multiple files -- could you elaborate a bit on what |
I do not know if it's possible (I am not an expert at all here --- I know what a RE is, but I suspect that syntax highlight is more than this), the best way is to have sublanguages. I think there should be a kind of "sub-mode" for example for LUA code in LuaLaTeX (this is often inline...), and TikZ would be probably treated like this. |
@adigitoleo @Rmano That is how TikZ is currently treated. To actually inject another, full, language syntax (e.g., in Markdown code blocks) in vim is currently not possible, and one of the problems that tree-sitter is meant to solve. (Not supported yet there, either, but it's on the docket.) |
Yes, sorry. I've not really documented the "developer API". Pragmatic choice, really; everything takes time, and I've barely got enough time as it is. I try to write the code in a manner that makes it relatively easy to read, though. |
Oh, that wasn't a complaint, and no need to apologize! (Though you do have to know what's there in order to look at the code for it.) Take it simply as a (single) vote for how useful that function (and similar) might be and for promoting it to a "user API". |
Thanks, and I agree that there are probably quite a lot of more or less useful functions such as |
Yes, I think the wiki would be a good place for this (e.g., as a subsection "Advanced usage" under "Usage"). It wouldn't be quite as discoverable as in the documentation, but should still be visible to Google and could be linked from other places. The main issue remains knowing what is there in the first place -- I only know about Maybe we can open a new issue for other people to share their favorite "pro tips" (especially you ;)) to collect them for the wiki? |
Yes, that's OK. I don't really have that many "pro tips", though; if I "want" something it's typically just in the "defaults" or provided as an option :) But I'll definitely help in creating this as it seems it could be a useful resource. |
As many may know, vimtex does not provide its own syntax plugin. Instead, it builds on top of the one provided by Dr. Chip which is shipped with both Vim and neovim.
I've started to think about changing this. As a first step, I would adopt the latest version by Dr. Chip and rewrite it in terms of vimtex code style. Through some iterations of improvements, I think this could lead to a reduced workload with respect to maintenance and further development. Pros and cons of the top of my head.
Pros:
Cons:
g:tex_flavor
should be respected/overwritten and similar.tex.vim
and whether it is OK to "fork" it.My thoughts for how to do it is something like this:
g:tex_conceal
into something likeg:vimtex_syntax_config = {'conceal': ...}
and so on).g:tex_fast
is unnecessary, similar withg:tex_nospell
and perhaps alsog:tex_conceal
).In any case, I would be happy to hear other peoples thoughts and opinions on this.
The text was updated successfully, but these errors were encountered: