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
Conceal support for \mathbf and \mathrm #1968
Comments
For reference, here is how this is implemented in |
In addition, there is |
These should be all text style modification commands:
For example |
Not sure if this is a good idea. But here goes. It'd be great if it were possible to conceal custom macros/commands. Use case: I have a "master" macro that I use to define my vector and matrix text-styles. Typically this re-directs to |
@patricknraanes Are you asking for something like adding a line syn match texMathSymbol '\\C' contained conceal cchar=ℂ to |
Thanks, but I was thinking more something like the following example: \newcommand{\mat}[1]{{\mathbf{{#1}}}}
\newcommand{\vect}[1]{{\bm{#1}}} And then in the text I might write The advantage of this system is that I can easily change the text styles for vectors and matrices. And I'd be cool if I could get conceal working for it. |
Ok, so, this is developing into several related features in one issue. I understand that it might seem "trivial" to know which of the various commands should come under which category, but I don't know this. So, please, can someone please categorize according to my following list and also preferably show explicit examples (especially for the last group). This woul be a very big help for me to properly implement this.
@patrickraanes It should be simple to allow custom commands for the two categories above. I could see something like the following as an idea: let g:vimtex_syntax_custom_cmds = {
\ 'bold': ['mat', 'vect'],
\ 'italic': ['todo'],
\ 'hide': ['footnote'],
\} This would not differentiate math mode, but since we are concealing, it shouldn't be a problem. If you want a more dynamic version, then I think I'll pass: parsing the To keep things separated, could you open a new issue for this with a reference here? |
See the
See the
|
As a sidenote, not all fonts have all the characters used for concealing; for example, Dejavu Sans Mono only the more common blackboard math characters (though, for example, Droid Sans Mono is quite complete and has more of them). |
@Konfekt Thanks for clearing things up!
Yes, this is an important note. I guess I should give a comment about this in the docs. |
Do you have an idea of a reference that I could use to guide people on how to install/use fonts with good unicode support? |
I think we are getting close now. Do you miss anything here now? |
Thanks for the links! I'll write up something and/or add links to the docs to help users interested in the subject. |
I am not sure that the fonts in the list are available monospaced. Another list. There's also this free alternative to DejaVu. And Droid is very readable and complete; my gvimrc loads it. |
I personally use Juliamono, which I find to be both quite pretty and very complete wrt. symbols. |
Ok, I've added some text on the subject (see |
Is it possible to set the highlight of the text inside these commands? I would like for the text inside |
No, this requires more work, and we are getting closer to implementing a full syntax language on top of the builtin. That is, this type of customization would mean that you should specify the highlighting group yourself, in which case you must specify both styling and colors. One simple possibility is to add a new option let g:vimtex_syntax_custom_cmds = [{'name': 'test', 'conceal': v:true}]
highlight texTestArg gui=bold guifg=red Note, if we go in this direction, you should note that custom highlights like this should not go in your vimrc directly; see this gist. What do you think? This would only involve a minimal change to vimtex, but would allow to specify the custom highlight in a quite detailed manner. |
I'm not quite following. When checking I don't really know what the best solution is, but if the simple fix that you mention works I'm happy with that :) |
Sorry, you're right - I forgot that. This actually means my suggestion is already possible to use.
You can try it, e.g. something like this (see the previously linked gist for explanation of the custom highlight mechanisms): let g:vimtex_syntax_custom_cmds = [
\ {'name': 'test', 'conceal': v:true},
\]
function! MyCustomHighlights() abort
highlight texCTestArg gui=underline guifg=blue
endfunction
augroup MyColors
autocmd!
autocmd ColorScheme * call MyCustomHighlights()
augroup END |
I may have misunderstood something, but I believe the following feature is still missing (unintentionally): that the |
@lervag I tried your example code but I don't see any difference in highlighting. I'm guessing that it should highlight the text in the argument to
|
Sorry, my mistake: If you use Vim or neovim in a terminal you need highlight texCTestArg cterm=underline ctermfg=blue |
I think this should work as expected now. |
Like a charm! And thanks for #2040 too! |
Happy to hear it, and you're welcome :) |
@lervag I did try that as well but I still didn't see any change.
|
@Melkster With the following vimrc and test file everything seems to work well for me. Did you remember to update? % test.tex
\documentclass{minimal}
\begin{document}
Hello World! \test{testing}
\end{document} " minimal vimrc
set nocompatible
let &rtp = '~/.vim/bundle/vimtex,' . &rtp
let &rtp .= ',~/.vim/bundle/vimtex/after'
filetype plugin indent on
syntax enable
nnoremap q :qall!<cr>
set termguicolors
let g:vimtex_syntax_custom_cmds = [
\ {'name': 'test', 'conceal': v:true},
\]
function! MyCustomHighlights() abort
highlight texCTestArg gui=underline guifg=blue
endfunction
augroup MyColors
autocmd!
autocmd ColorScheme * call MyCustomHighlights()
augroup END
call MyCustomHighlights()
silent edit test.tex |
@lervag Thank you, your I seem to discovered two problems that I was having. The first one is related to nvim-treesitter because if I add it to your The second problem was that I tried to put the config in |
nvim-treesitter now includes a latex (and bibtex) parser, so you probably have tree-sitter-based highlighting enabled -- which disables vanilla vim syntax highlighting (and hence conceal, which relies on it). (You do have highlighting in this case, but with different highlight groups that you probably don't have set up.) What does |
Glad to hear it.
Ah; I've yet to delve into the treesitter stuff. I'll probably stay on the fence for some time, but I do see how this can give useful improvements to neovim.
Ah, no, that won't work. That is, the VimTeX options must be defined before VimTeX loads, and the |
It's surprisingly good for being that new; of course, it doesn't come close to the support for specific packages vimtex has. One advantage is that you can easily inject Lua syntax highlighting for luatex's You can also pretty easily (and efficiently) do something like I've been trying to dampen enthusiasm for getting tree-sitter support into vimtex as you probably don't want to add to your maintenance burden, but people would be excited ;) |
That sounds promising :)
Yes, I can imagine that things like this is much easier if you have a parsed syntax tree to work with! Although, even with treesitter, there has to be a lot of manual code and bookkeeping of the various LaTeX commands and packages. I imagine it may look better, be easier to read, and be more compact, than the current VimTeX implementation based on the Vim syntax scripts.
Hah, yes. Perhaps for VimTeX 3.0? Perhaps I'll leave the Vim crowd behind and go pure neovim as well? (I'm kidding; for now.) But seriously: I think it is important to follow the development of the tools, and it seems clear that treesitter is a huge upgrade to the syntax parsing and highlighting infrastructure. I don't expect to make any huge leaps in VimTeX in near future, but as I expect to still be writing LaTeX documents 10 years from now, I also imagine there will come a time when I'll seriously consider to drop the Vim syntax scripts in favor of treesitter. |
That depends on how much you like Lisp ;) (You are right; the fact that there are so many packages defining their own commands and environments is a major hassle, and tree-sitter can't help there much, if at all.)
Come to the dark side... :)
I think thinking of tree-sitter as just "faster syntax" or "prettier highlighting" is seriously selling it short. At the core, it gives you powerful tools of working with an (incrementally, error-resilient) parsed syntax tree -- and there are a lot of things you can do with that. Two early things are https://github.com/nvim-treesitter/nvim-treesitter-refactor and https://github.com/nvim-treesitter/nvim-treesitter-textobjects. Another thing I'm quite excited for is https://github.com/vigoux/architext.nvim (think (Currently, enabling tree-sitter for a language disables the built-in syntax files, which turns off many of vimtex's features; that is something that should be handled more granularly. You can tell But it's early days; official support has been postponed to neovim 0.6 (which hopefully won't take as long as 0.5...), and the current version should be considered "early access". |
I really like Lisp, or at least the ideas. I've just never had a really good opportunity of using it for anything.
For the record: I never meant to imply that. It's exactly what I meant with syntax parsing, and I'm intrigued by the opportunities this concept provides. In any case, thanks for the interesting references and info!
I consider myself somewhat experimental, but there's a time cost to most things, and I am unfortunately quite time bound. So I'll probably start to consider treesitter more seriously when I get a sense that is is more mature. I'm looking forward to it! :) |
@clason This is the output from bash [✓] installed
beancount [✓] installed
bibtex [✓] installed
c [✓] installed
c_sharp [✓] installed
clojure [✓] installed
comment [✓] installed
cpp [✓] installed
css [✓] installed
dart [✓] installed
elm [✗] not installed
fennel [✓] installed
glimmer [✓] installed
go [✓] installed
gomod [✓] installed
graphql [✓] installed
haskell [✗] not installed
html [✓] installed
java [✓] installed
javascript [✓] installed
jsdoc [✓] installed
json [✓] installed
jsonc [✓] installed
julia [✓] installed
kotlin [✓] installed
latex [✓] installed
ledger [✓] installed
lua [✓] installed
nix [✓] installed
ocaml [✓] installed
ocaml_interface [✓] installed
php [✓] installed
python [✓] installed
ql [✓] installed
query [✓] installed
r [✓] installed
regex [✓] installed
rst [✓] installed
ruby [✓] installed
rust [✓] installed
scala [✗] not installed
scss [✗] not installed
sparql [✓] installed
svelte [✓] installed
teal [✓] installed
toml [✓] installed
tsx [✓] installed
turtle [✓] installed
typescript [✓] installed
verilog [✓] installed
vue [✓] installed
yaml [✓] installed
zig [✓] installed |
@lervag Of course! That makes sense. Keeping let g:vimtex_syntax_custom_cmds = [
\ {'name': 'test', 'conceal': v:true},
\] in my function! MyCustomHighlights() abort
highlight texCTestArg gui=underline guifg=blue
endfunction
augroup MyColors
autocmd!
autocmd ColorScheme * call MyCustomHighlights()
augroup END
call MyCustomHighlights() to |
This confirms my suspicion. I suggest disabling the |
@clason This might be a stupid question, but how do I uninstall the latex parser for nvim-treesitter? I tried This is my config, I even tried removing require('nvim-treesitter.configs').setup {
ensure_installed = "maintained",
highlight = {
enable = true,
},
} |
Don't use You can add highlight = {
enable = true,
disable = "latex",
}, |
@clason I tried a bunch of stuff, including removing
worked for me. Thanks! :) |
This was raised by @Konfekt in #1883 (comment) and also discussed several years ago in #557. Since VimTeX v2.0, this should be relatively straightforward to implement.
Before I implement anything, I wanted to be sure I "understand" the feature. We want:
\mathbf{text}
to be displayed as simplytext
but bolded.\mathrm{text}
to be displayed astext
(not bold).Is there anything more?
The text was updated successfully, but these errors were encountered: