Vimtex: Problem Context Math

Created on 24 Nov 2020  路  15Comments  路  Source: lervag/vimtex

Hello.
I use Ultrasnip for snippets and, with the last vimtex update it doesent work. In particular the function for the math context

global !p
texMathZones = ['texMathZone' + x for x in ['A', 'AS', 'B', 'BS', 'C', 'CS', 'D', 'DS', 'E', 'ES', 'F', 'FS', 'G', 'GS', 'H', 'HS', 'I', 'IS', 'J', 'JS', 'K', 'KS', 'L', 'LS', 'DS', 'V', 'W', 'X', 'Y', 'Z', 'AmsA', 'AmsB', 'AmsC', 'AmsD', 'AmsE', 'AmsF', 'AmsG', 'AmsAS', 'AmsBS', 'AmsCS', 'AmsDS', 'AmsES', 'AmsFS', 'AmsGS' ]]

texIgnoreMathZones = ['texMathText']

texMathZoneIds = vim.eval('map('+str(texMathZones)+", 'hlID(v:val)')")

texIgnoreMathZoneIds = vim.eval('map('+str(texIgnoreMathZones)+", 'hlID(v:val)')")

ignore = texIgnoreMathZoneIds[0]


def math():
    synstackids = vim.eval("synstack(line('.'), col('.') - (col('.')>=2 ? 1 : 0))")
    try:
        first = next(i for i in reversed(synstackids) if i in texIgnoreMathZoneIds or i in texMathZoneIds)
        return first != ignore
    except StopIteration:
        return False
endglobal

with the previous version of vimtex all works perfectly. Thank you for the support.

Most helpful comment

Yes, this is "expected": The latest update brings major changes, see the release notes.

In particular, the math zones are no longer named texMathZone... I think the following should work quite well:

texMathZones = ['texMathRegion' + x for x in ['', 'X', 'XX', 'Env', 'EnvStarred', 'Ensured']]
texIgnoreMathZones = ['texMathTextArg']

All 15 comments

Yes, this is "expected": The latest update brings major changes, see the release notes.

In particular, the math zones are no longer named texMathZone... I think the following should work quite well:

texMathZones = ['texMathRegion' + x for x in ['', 'X', 'XX', 'Env', 'EnvStarred', 'Ensured']]
texIgnoreMathZones = ['texMathTextArg']

Thank you so much!

My pleasure! :)

Perfect! It does work on my nvim! Thanks for taking care of it!

Hi all: Please note that the newly released v2.1 reverts the naming scheme tex{type}Region back to tex{type}Zone, which means the code should now be:

texMathZones = ['texMathZone' + x for x in ['', 'X', 'XX', 'Env', 'EnvStarred', 'Ensured']]

Thank you..

Where can I read all changes or where do you add this informations?

@TornaxO7 The best sources are:

  • The release notes. The first "release" was v1.0 in July this year, so this particular source is recent. However, I plan to use this as the main source for changes and important version related messages in future development.

  • There is a type of changelog in the docs, see :help vimtex-changelog. However, this is mainly to document changes where e.g. options change name. It is not really that relevant any more since I now make more proper release notes and versioning.

  • The full Git commit log. Every detail, but of course way to verbose for most people.

@lervag Nice! Thank you for the information! According to the release notes there are multiple zones, am I right? If yes, where can I look them up?

@TornaxO7 Not quite sure what you mean. But perhaps you are looking for :help vimtex-syntax and :help vimtex-syntax-reference?

@lervag In your release notes, you wrote this sentence:

The syntax plugin used the naming scheme tex{type}Region for syntax regions, e.g. texMathRegion for math-mode regions.

Yes. But what are you actually interested in; what do you want to do? If you want to look up all the different groups, then you should look in the source code (which is also explained in the docs I already referred to).

For example adding to my snippets that it should add automatically \item if I'm in an itemize environment.

Yeah! I found it under :help vimtex-syntax-reference. Awesome! :)

For example adding to my snippets that it should add automatically \item if I'm in an itemize environment.

Essentially, your questions make a good example of the x-y problem, because it is _much_ easier to answer that specific question than the original ones, and the answer is not related to the original ones. It is not surprising that this _is_ surprising to you, though.

So: Most environments do _not_ make zones similar to math mode. There is really no need for that. Thus, you can't use the same mechanism to detect e.g. the itemize environment. Instead, you can use the function if vimtex#env#is_inside('itemize') ....

We've now "hijacked" this issue thread for long enough. Feel free to open a new issue if you have more questions. I don't mind answering and helping, but I do prefer to keep threads separate, as that helps "discoveribility" when you search for older issues/topics.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LuxGiammi picture LuxGiammi  路  3Comments

Davidnet picture Davidnet  路  4Comments

lervag picture lervag  路  5Comments

vsbuffalo picture vsbuffalo  路  3Comments

David-Fu picture David-Fu  路  5Comments