Skip to content
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

highlight #2732

Closed
aloispichler opened this issue Jun 18, 2023 · 13 comments
Closed

highlight #2732

aloispichler opened this issue Jun 18, 2023 · 13 comments

Comments

@aloispichler
Copy link
Contributor

Hello again,

Thanks for vimtex.
Vimtex does a pretty nice job in highlighting math formulae and parts of these.
Highlight groups include <texMathSymbol>, <texMathCmd>, <texCmdGreek>, etc., for example in the formula $\int\alpha(x) dx$. Conceal displays them in even different colors.

XeLaTeX or LuaLaTeX allow inputting these formulae directly, as $∫α(x) dx$; however, without highlighting.
Would it be possible to have the same highlighting? An implementation might follow the conceal-dictionary… Thanks!

@lervag
Copy link
Owner

lervag commented Jun 21, 2023

So, you want some specific list of utf8 symbols to be highlighted as the corresponding group for the corresponding command? More or less these:

Do I understand correctly?

@aloispichler
Copy link
Contributor Author

Following your table for conceal,
should share the same color group as \aleph,
as \int, etc.

For Greek letters:
δ (and its unicode friends δ𝝳𝛅𝛿𝛅𝞭): same color group as \delta, etc.

I do understand that this is making too great demands, and just for a niche.
Greetings to Trondheim, where I lived 3+ year.

@lervag
Copy link
Owner

lervag commented Jun 23, 2023

I've made an attempt at this that I think comes close (or even hits the spot). Please update and test. Let me know if you find any problems or unexpected behaviour due to this.

Also; greetings back! Trondheim is not the worst place to be these days - welcome back :)

@lervag lervag closed this as completed Jun 23, 2023
@aloispichler
Copy link
Contributor Author

Very helpful, indeed. So far, behavior as expected. Thank you!

@lervag
Copy link
Owner

lervag commented Jun 24, 2023

Great; let me know if you find any unexpected inconsistencies. :)

@cionx
Copy link

cionx commented Aug 14, 2023

Would it be possible to make this feature toggleable? I find that it leads to inconsistent highlighting, as can be seen in the following image:

highlight

In the first example, all four functions are highlighted in the same way. But in the second line, one of them is highlighted differently for no apparent reason. (Until I found this GitHub issue, I actually assumed that this was a bug.)

One of the advantages of direct Unicode input is that one doesn’t need to rely on TeX commands, which allows for a more consistent look and feel of the code, including consistent code highlighting. Adjusting the highlighting of part of the code to something that it specifically isn’t (namely a TeX command) strikes me personally as more of an anti-feature. So I think it would be good if it could be disabled by the user.

I can also open a new issue, if this is more appropriate.

@lervag
Copy link
Owner

lervag commented Aug 14, 2023

This was implemented in this function:

function! s:match_math_unicode() abort " {{{1
syntax match texCmdGreek
\ "[αβγδ𝝳𝛿𝛅𝞭ϵεζηθϑικλμνξπϖρϱσςτυϕφχψωΓΔΘΛΞΠΣΥΦΧΨΩ]" contained
if !exists('s:re_math_symbols')
let l:symbols = map(vimtex#util#uniq_unsorted(s:cmd_symbols), 'v:val[1]')
call filter(l:symbols, 'v:val =~# "[^A-Za-z]"')
let s:re_math_symbols = '"[' . join(l:symbols, '') . ']"'
endif
execute 'syntax match texMathSymbol' s:re_math_symbols 'contained'
endfunction
" }}}1

Notice that it will match greek unicode letters as texCmdGreek, but also a quite large list of unicode symbols defined near line 1528 as texMathSymbol. Would you find it OK if all of this is behind an option, or should there be more granularity?

@aloispichler
Copy link
Contributor Author

For me, this is just fine. Thanks!

@cionx
Copy link

cionx commented Aug 16, 2023

I was personally okay with the behaviour before 7bf2a74, so putting all the Unicode highlighting behind an option should be fine for me.

I think the “proper” solution to highlighting Unicode characters would be to highlight them depending on their semantics:

  • letters (Greek, Fraktur, …) the same as regular Latin letters,
  • operations (, , …) the same as +,
  • relations (, <, , …) the same as =,

But this is probably far too much work, as not many people use direct Unicode input. (I don’t know how many people use conceal.)

@lervag
Copy link
Owner

lervag commented Aug 16, 2023

I was personally okay with the behaviour before 7bf2a74, so putting all the Unicode highlighting behind an option should be fine for me.

Cool, I'll add an option for this, then.

I think the “proper” solution to highlighting Unicode characters would be to highlight them depending on their semantics: …

But this is probably far too much work, as not many people use direct Unicode input. (I don’t know how many people use conceal.)

Yes, I agree that this is a better solution, but I also agree it is quite a lot of work, and I'm not interested in doing it myself. I wouldn't mind a PR if anyone did the work, though.

lervag added a commit that referenced this issue Aug 16, 2023
@lervag
Copy link
Owner

lervag commented Aug 16, 2023

I need to specify a default value here. I'll choose default true, since that is the defacto current value. Thus, if you want to disable, you need to add

let g:vimtex_syntax_match_unicode = v:false

or, in Lua,

vim.g.vimtex_syntax_match_unicode = false

@cionx
Copy link

cionx commented Aug 17, 2023

Thanks, that works for me.

@aloispichler
Copy link
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants