jlelong / vscode-latex-basics

LaTeX grammars for Visual Studio Code
MIT License
19 stars 10 forks source link

Highlight tabulararray redefined amsmath environments #37

Closed jlelong closed 2 years ago

jlelong commented 2 years ago

Originally posted by @Firestar-Reimu in James-Yu/LaTeX-Workshop#3485

With \UseTblrLibrary{amsmath} in the preamble of the document, tabularray will load amsmath package, and define +array, +matrix, +bmatrix, +Bmatrix, +pmatrix, +vmatrix, +Vmatrix and +cases environments. Each of the environments is similar to the environment without + prefix in its name, but has default rowsep=2pt just as tblr environment. Every environment except +array accepts an optional argument, where you can write inner specifications.

This is another issue besides #2851, relating to tabularray package

You can see that, after adding the + the highlight is wrong:

Screenshot_20220918_235436

I used to think all \begin and \end pairs will be highlighted?

Firestar-Reimu commented 2 years ago

I think it is this line

https://github.com/James-Yu/LaTeX-Workshop/blob/ef04d42bb2e13b1381961163672ef8b734703fab/syntax/LaTeX.tmLanguage.json#L816

Change it to:

      "begin": "(?:\\s*)((\\\\)begin)(\\{)((?:array|equation|(?:IEEE)?eqnarray|multline|align|aligned|alignat|flalign|flaligned|flalignat|split|gather|gathered|[\+]*cases|(?:display)?math|[a-zA-Z\+]*matrix|(?:(?:arg)?(?:mini|maxi)))(?:\\*|!)?)(\\})(\\s*\\n)?",

may work.

for example, \begin{nothistypematrix} \end{nothistypematrix} will be highlighted

jlelong commented 2 years ago

There are two issues here

  1. We currently only accept letters and an optional ending * for environments
  2. You expect that the +matrix environment is recognized as a tabular environment, ie & is highlighted as a column separator.
jlelong commented 2 years ago

I think it is this line

https://github.com/James-Yu/LaTeX-Workshop/blob/ef04d42bb2e13b1381961163672ef8b734703fab/syntax/LaTeX.tmLanguage.json#L816

See https://github.com/James-Yu/LaTeX-Workshop/tree/master/syntax#grammars-and-language-configuration-files

Firestar-Reimu commented 2 years ago

I changed that line and all syntax highlighting disappeared

2. You expect that the `+matrix` environment is recognized as a tabular environment, ie `&` is highlighted as a column separator.

all +matrixes and +cases should be the same as the envs without +

Firestar-Reimu commented 2 years ago

Thanks! @jielong when will the users get this update?

jlelong commented 2 years ago

The fix will be available in the next release of LaTeX-Workshop.