Conversation
|
As requested, here are all the syntax groups in (The last is obviously OK; just maybe in the wrong section of the file.) |
|
And here are some gaps and inconsistencies I noticed going through some TeX files and using the following code (which everyone else probably knows already) to check which highlight groups are actually used: function! SynGroup()
let l:s = synID(line('.'), col('.'), 1)
echo synIDattr(l:s, 'name') . ' -> ' . synIDattr(synIDtrans(l:s), 'name')
endfun
|
Ok, and your point is that we should make this consistent so that every "auxiliary" TeX group by default links to one of the "primitive" tex groups, right? I very much agree, but it does raise the question of what the primitive tex groups should be and to which primitive Vim highlight group they should link. Do you have a good suggestion for this?
Thanks! I've added a TODO list for consistency based on your remarks and my own thoughts. What do you think of it? |
|
I've updated the original post TODO, and I'd appreciate feedback on the suggested changes. |
Yes, exactly. The point is to have a (somewhat) stable and contained external "color scheme API" that abstracts from specific syntax groups.
That is a very good question, and at the heart of what #1800 was about (beyond improving consistency in the syntax/highlight groups). Since it's always possible in your own config to re-link specific highlight groups to other default highlight groups or colors, it would probably be enough to have a handful of such primitive TeX groups -- your edited todo sounds very reasonable for this. As for the primitive Vim groups, I wouldn't worry too much about this -- any choice will be wrong for as many color schemes as for which it works well, and ideally color schemes would ship with their own links. On this point, it should be noted that renaming the primitive TeX groups will be "breaking" for color schemes with TeX support, since they are based on Dr Chip's syntax file. Personally, I'd say the improvements are definitely worth it, but something to keep in mind and document maybe. As a single data point, here are the highlight groups I use (overriding https://github.com/cocopon/iceberg.vim/): " section and environments
hi! link texSection Title
hi! link texBeginEndName Title
" braces should be colored
hi! link Delimiter Constant
hi! link texBeginEndModifier Special
" math in blue
hi! link texMath Identifier
hi! link texSubscript Identifier
hi! link texSuperscript Identifier
hi! link texSpecialChar Identifier
hi! link texMathSymbol Identifier
" labels and reference
hi! link texRefZone Constant
Perfect, although I wouldn't differentiate between, say |
Sounds good. I'll just make a first version for you (and everyone) to comment on.
Good point. But I guess one has to break some eggs to make an omelet. I think I'll take my chances :)
Do you mean to use e.g.
My idea was this: Math environments need to define a math syntax region. But the By the way: does it make sense to differentiate between different math environments? I.e., are these differences used for anything? Do we need |
:)
Exactly, or (It may still make sense to define them separately as you indicated, but then group them in a single primitive TeX highlight group for convenience.)
Then that is perfect, exactly what I had in mind.
To be honest, I don't know what they could be useful for. Presumably, you could match improper nesting (e.g., |
I've currently implemented the "minimal" version (with
Yes, I think it could be of interest to have more fine grained control.
This is now implemented and should work well now, I think.
Agreed; this also allows more simplifications, which I like. I've made some progress now and things are slowly moving towards something that is IMHO better than before. Still a lot more work to do, but I believe I should finish before Christmas. |
|
I would not mind if someone started to test run this branch. It is not ready yet, but I think a lot of stuff is getting quite good. Good enough for the brave to look into it, at least :) |
|
I'd be happy to test -- do you have a list of the "basic TeX" highlight groups (so far)? One thing I noticed out of the box is that there is a problem with nested commands outside of math mode: \foo{ \bar{baz} }has problems with the argument of |
I'm not ready to post my initial "hypothesis" yet, but you will probably get the gist of you look at the syntax groups. A very large set of groups are related to
Sorry, I made a silly mistake yesterday! It is fixed now. |
|
I think this is getting pretty good now. The current list of main "primitive" groups are represented by these highlight def link texArg Include
highlight def link texArgAuthor Identifier
highlight def link texArgEnvMathName Delimiter
highlight def link texArgEnvName PreCondit
highlight def link texArgRef Special
highlight def link texArgTitle Underlined
highlight def link texCmd Statement
highlight def link texCmdSpaceCodeChar Special
highlight def link texCmdTodo Todo
highlight def link texComment Comment
highlight def link texCommentTodo Todo
highlight def link texDelim Delimiter
highlight def link texDelimMath Statement
highlight def link texError Error
highlight def link texLength Number
highlight def link texMath Special
highlight def link texMathOper Operator
highlight def link texOpt Identifier
highlight def link texOptSep NormalNC
highlight def link texParm Special
highlight def link texRegion PreCondit
highlight def link texSpecialChar SpecialChar
highlight def link texSymbol SpecialChar
highlight def link texSymbolString String
highlight def link texTitle String
highlight def link texType TypeAs you can see, it is now possible to reduce this to: Still not perfect, and I assume that there will be a lot of comments and suggestions for changing things, but at least I think this is moving very much in the right direction. The main thing left, I think, is to go through the large lists of symbols and delimiters that are defined for conceal replacement in math mode. I'll try to make this more consistently separated between symbol and delimiter ( I think it should be possible to use this branch as a "daily driver" for those who want to test and give feedback. |
|
I haven't yet switched to it as a daily driver (will do that soon), but here's some things I noticed playing around today:
As a general comment: it's a matter of taste and probably too much effort to change now, but I think I'd prefer a "hierarchical" naming scheme |
Yes, perhaps. But in this case you might want to use
Yes; the latter accepts multiple arguments separated by comma.
Thanks, I'll look into these and fix them!
You mean like
I guess that may make sense. It is easy to add support for it. Do you have a concrete suggestion?
I'm not quite sure what you mean here. In general, it is not so hard to change things now (global replace statements).
I will write about this in more detail later. The gist is that most things are centered around the primitive being a |
I like living dangerously :] (In seriousness, you are probably right, but I'm just pointing out a regression/visible change from the old highlighting. If it's a necessary change due to the better implementation, that's fine.)
Right, makes sense. And I assume that
Thanks! (How did you fix my checkbox list, by the way? I tried and couldn't get it to work...)
Yes, that would probably be useful.
Not really, no... I guess the same group as
Well, I think it'd be easier (for me) if things started from (I'm thinking from setting up the color scheme here, where I'd be going down the list "commands, environments (command, name, option), references,..." rather than "all commands, and then all arguments, and then all options, ...". Not a big deal either way, just curious.) |
Not necessary; I think in the old highlighting the error was not highlighted at all. It's all a question of what we want.
Yes, that makes sense. I'm updating that now.
For some reason, the
No, because that is
I don't agree, but I might not understand properly what you mean. Yes, there will be quite large trees, but I don't find the |
Indeed; especially whether you want the syntax group highlighting to serve as a sort of linter. I personally don't, because I don't think you can make it robust enough, but your view may be different (and that is fine).
Curious; I used
That makes sense as well, and is certainly least surprising. My thought was coming from the similarity to
Not sure I can explain it any better, I just find |
I think we mostly agree on this. I'd like to think about it some more, though.
No problem, I'm happy to get some feedback and further suggestions! :)
I've pushed this now where
Ah, I think I get the "gist" now. You mean the group names should be e.g.:
And so on. This is currently named like this:
If I understand correctly, your point is to collect the various parts of a family of syntax items with the same stem. It's like BFS vs DFS, right? It is not hard to make this change. The question is what would be better. I've been thinking in the opposite manner where I've "stemmed" the type of item first and the "family" later. It felt right when changing things and has been easy to work with, but it might not be the optimal "UI" for users. |
Hmm, I think I prefer (I don't think the separate highlight group will be needed in general, since most people will leave
Yes, exactly!
You are probably right that this comes down to what's more natural to "developers" vs. "users". Either is a valid choice; I just wanted to bring it up as an alternative. If it's down to us two only, your vote carries more weight, of course ;) |
|
Here's another possible syntax group missing from the builtin syntax file: Not sure what the best default highlight group for this is, though -- it feels most related to sectioning, but not very strongly? Kinda on the same level as |
"Minor" things
Sounds reasonable; changing this now.
Do you think Structure of syntax group names
Hah, yes, I guess that's the benefit of being the developer. Still, although I think I am often able to find good patterns, I don't believe I also make the right calls. So, I'm more than willing to discuss this. So. We have sort of "two" proposals right now:
I think both schemes should generally work well, and I have no very strong opinions. But if I hear a strong argument for why proposal 2 would be better than 1, then I will accept it and update the PR accordingly. I'll take the liberty to tag some more people here: @Rmano, @clason, @Konfekt RFC: Remove the general purpose
|
I think the syntax/highlight groups are perfect as you propose (modulo the discussion on naming ;)). Regarding default linking, (Basically, my view is that it's good to add as many specific groups as feasible, but not necessarily color them all as differently as possible; people can make their own rainbows ;))
Since I already put in my vote, I'll just wait what others say. Either choice is fine with me.
That is a very good question indeed. I guess strictly speaking, this would be a regression, so there should be a clear benefit in another area to make up for it -- ideally for users as well, such as performance. (I assume it'll make your life much easier, which is already a benefit.) One point that is often prominently mentioned in favor of tree-sitter is that it "localizes" parsing failures, so that, e.g., a missing brace somewhere doesn't break highlighting in the rest of the file. If this simplification had a similar effect, that'd be a big plus in my book. |
|
First, let me say that this is shaping up to look very nice! A few things I'm still missing are
EDIT Hmmm, looking at the actual code, this should work. For some reason my code snippet is not picking up that top level group... If I link
|
I think my idea was good, but it seems to not work as intended. The problem is that, if I remove the At the moment, I think the conclusion to this is that we really need the Better naming would be good in this case. I'm changing to
Thanks!
Yes; I've just changed this to
It is intended; it is necessary because, unless we specify otherwise, we need to assume that the content of arguments of commands in math mode is still math mode. If we instead used the
Can you give some more specific examples? In my (simple) tests, it looked like I was close to consistent here.
Good question; I'll mirror it back to you. Feel free to suggest explicit symbols and target groups.
You mean something like
You're right. I could add that, but it would help if you/someone could provide me the full list of commands (both short and long names).
Agreed. Another possibility is to just keep it unstyled?
Can you be specific? For me in my examples, it seems to work OK. |
I agree
But not yet pushed?
I thought these were specific? (It's not enough to look at the color, because it might happen that the specific color scheme you or I are using happens to assign the same color to different highlight groups.) So is it intended that
(And going back to the initial three,
What do you mean by "long name"? The commands themselves are
Also good! (In fact, probably simplest.)
Hmm, with the latest pushed commits, the results are different for me as well. But something like this: \begin{document}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[%
width=0.75\linewidth,
height=6cm,
xmin=-0.25,
xmax=2.5,
ymin=-0.25,
ymax=2.5,
ytick=\empty,
extra y tick style={grid=major},
extra y ticks={0,1,2},
extra y tick labels={$u_1$,$u_2$,$u_3$},
axis y line=left,
axis x line=bottom,
]
\pgfmathsetmacro{\ua}{0}
\pgfmathsetmacro{\ub}{1}
\pgfmathsetmacro{\uc}{2}
\pgfmathsetmacro{\at}{0.2}
\addplot[%
domain=-0.25:2.5,samples=200,
color=DarkBlue,solid,line width=1.5pt,
]
{
(x<=\ua)*\ua + %
and(x>(1+\at/2)*\ua+\at/2*\ub,x<(1+\at/2)*\ub+\at/2*\ua)*(x-\at/2*(\ua+\ub)) + %
and(x>=(1+\at/2)*\ub+\at/2*\ua,x<=(1+\at/2)*\ub+\at/2*\uc)*\ub + %
and(x>(1+\at/2)*\ub+\at/2*\uc,x<(1+\at/2)*\uc+\at/2*\ub)*(x-\at/2*(\ub+\uc)) + %
(x>=(1+\at/2)*\uc+\at/2*\ub)*\uc
};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}(Interestingly, in the full file, I get |
Sorry, pushed now.
The I'll look into this again and make some more specific tests for it.
Agreed!
Right now, I think
Yes, that could work. But I'm not fully sure I understand the distinction between "literal" and "syntax" here.
I think all or most of these have long name equivalents, such as I'll also look into the tikz thing later. I just pushed a major update where I've changed the naming scheme to something much more similar to what you've asked for. I'm not sure if it is fully what you asked for, so feel free to comment on it. The main idea is this: Almost everything starts from a command, e.g. I also use |
You've got an email :-) |
|
See: https://github.com/lervag/vimtex/releases/tag/v2.0 (Feel free to let me know if you think I should make some minor updates to the release text!) |
|
Great news, thank you so much for doing this! TeX files have never looked so good :) (Seriously.) If you think it's helpful, you could put my colorscheme snippet in the Wiki and refer to that from the release notes? (The colors and links are personal preference, of course, but it's always easier to tinker with something existing than to start from scratch.) |
I agree! There're still some things that need improving (e.g. TikZ support), but I think it will be much easier to do it now.
Yes, that's not a bad idea. I've not really spent much time on the wiki myself, as I prefer to keep the README and docs updated as the main references. But I agree that for things like this, the wiki makes sense. Would you mind writing a first version of this that I could review and then link to in the release notes? |
|
Done! Feel free to edit any way you deem fit (including outright deletion)! |
|
Thanks! I think that looks good. I'll add a link both from the docs and from the release page. |
|
Thanks @lervag for the amazing work! I see g:tex_comment_nospell is disabled, so how to mimic this function, to ignore comment in spell checking? I have tried textidote and vlty, they can skip comment spell checking, but I only managed to show the spell check result in the quickfix window rather than vim's native in-line display. If I can use them in a manner of output-to-html, it would be a lot easier to use :) |
|
Happy to hear you like it, @g6ai! You ask a good question. We did discuss spell checking comments at some time, but I don't remember where (and when). The conclusion was to enable spell checking and remove the option. This might have been a bad conclusion, but it is easy to change. Can you open a new issue in which we can have a new discussion? |

This PR implements full syntax support as part of vimtex. It is essentially what is referred to as Phase 2 in #1799. It contains breaking changes with the current master and implies a major change to vimtex. When this is merged, it should bump the version of vimtex to v2.0.
To test the WIP branch, you can do one of the following:
Manuall checkout git branch:
Checkout branch with plugin manager. For example, with vim-plug:
Then
:PlugUpdate vimtexto update and check out the branch.Finished tasks:
g:vimtex_syntax_autoload_packages.\addplot [x] {y}commands for TikZ picturesalignedand similar envsminipageenvp/minted.vimtexCmdwithtexOptandtexArgtexClusterCmd(it fails when people define groups before the syntax script is loaded)p/listings.vim\,texMatcherdiscussion: We needtexMatcher!texCmdFootnotewith argument grouptexArgFootnoteafter/syntax/...to being loaded properly on startup.let g:vimtex_syntax_config = {'conceal': ...}.texStatementtotexCmd(shorter and more inline with TeX syntax specifications).\chapter,\section, etc.) should get a special group:\texCmdSection, and the title argument should betexSectionTitle. Possibly also match the shorttitle optional argument?\texCmdParagraphand the argument should betexParagraphTitle.\appendix,\(front|main|back)mattershould be matched astexCmdPart.\beginand\endshould betexCmdEnv, the following{...}should betexEnvName. This should be the same in all cases. This will fix current inconsistency between e.g.\begin{equation}and\begin{lemma}.texEnvMathName.$,$$,\[, and\(type of delimiters should betexMathMatcher.texMathDelimiteror similar. This includes(,[,\{,\|,\left(, and so on.texMathSymbol, similar to the current state. Ensure this is consistent.\usepackageand\RequirePackageshould be matched as a normaltexCmd(no reason to differentiate?). The optional argument should be a generaltexOptions, and the real argument should betexFilename.\bibliography,\bibliographystyle,\addbibresourceshould be matched withtexCmdbut take a "general" file argument liketexFilename.texInputFileshould be changed to be consistent with the parent task.\verbcommands should betexCmdwith a followingtexRegionVerbtexUrlfromp/hyperref.vimtexTikzEqualfromp/tikz.vimtexTikzSemicolonfromp/tikz.vimtexTabularColfromp/tabularx.vimtexTabularAtSepfromp/tabularx.vimtexTabularVertlinefromp/tabularx.vimtexTabularPostPrefromp/tabularx.vimtexMathDelimSinglefromp/tabularx.vimtexBeamerOptfromp/beamer.vimtexBeamerDelimiterfromp/beamer.vim\author{A. Author\thanks{An Institute}}-- the last brace is labeledtexError\section*{Acknowledgments}has theAcknowledgmentslabeled astexMatchertexRegionRefis not yet linked to a highlight group? (this is from\cref, where the argument is labeled differently from\ref)\titleand\authorbe labeled special (maybe astexCmdParts, too)?\itemspecial?