Skip to content

Add support for tabularx#2403

Closed
MarcelRobitaille wants to merge 6 commits intolervag:masterfrom
MarcelRobitaille:feat/tabularx
Closed

Add support for tabularx#2403
MarcelRobitaille wants to merge 6 commits intolervag:masterfrom
MarcelRobitaille:feat/tabularx

Conversation

@MarcelRobitaille
Copy link
Copy Markdown
Contributor

This properly highlights the arguments of the tabularx environment, which takes two arguments unlike tabular that only takes one. The reason I added this was so that the second argument would properly get recognized as @texClusterTabular. Otherwise, the column specifiers get marked as a misspelled word when using set spell. This is a big problem for me because I use ]s and [s to jump around and fix things. It is also preferable to have proper highlight groups for more reasons than just spelling.

Copy link
Copy Markdown
Owner

@lervag lervag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! In addition to my comment to the code, could you also add a test file for this under test/test-syntax/test-tabularx.{vim,tex}?

@lervag
Copy link
Copy Markdown
Owner

lervag commented Jun 4, 2022

Also sorry for the late reply!

@MarcelRobitaille
Copy link
Copy Markdown
Contributor Author

Also sorry for the late reply!

Don't worry about it. I know how it is to be an open source developer :)

I moved the files and added some tests.

I know I'm new around here, but have you considered using something like vader for the tests? It would be really nice to run a single test at a time. As far as I can tell, you can't with this makefile.

@lervag
Copy link
Copy Markdown
Owner

lervag commented Jun 5, 2022

Also sorry for the late reply!

Don't worry about it. I know how it is to be an open source developer :)

:)

I moved the files and added some tests.

Great; thanks!

I know I'm new around here, but have you considered using something like vader for the tests? It would be really nice to run a single test at a time. As far as I can tell, you can't with this makefile.

I actually much prefer my way of testing. It is really quite easy to run a single test at a time:

cd $VIMTEX/test

# Run ALL tests
make

# Run all test-syntax tests
make -C test-syntax

# Run all test-syntax tests (alternative)
cd test-syntax
make

# Run only the tabularx test
make test-tabularx

# Run the tabularx tests but stay within neovim/Vim
nvim --clean -u test-tabularx.vim
vim -u test-tabularx.vim

1 & 2 & 3 & 4 \\
\end{tabularx}

% Tabularx does not seem to have options
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean with this? In the implementation, you do allow options..?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added texTabularxOpt for consistency with normal tabular, but as far as I can tell reading the tabularx docs, there are no supported [] options for this environment. Should we keep it like this for consistency and in case they decide to add some, or should we take it away?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should aim to implement the correct behaviour. If you are right, then we should not include the option group. I don't think you are wrong, but if so, it is easy to adjust later if someone shows a relevant proof.

@lervag
Copy link
Copy Markdown
Owner

lervag commented Jun 5, 2022

I think the only thing lacking now is to set the default highlight groups. I think you can use this as an inspiration:

https://github.com/lervag/vimtex/blob/master/autoload/vimtex/syntax/p/array.vim#L56-L66

@MarcelRobitaille
Copy link
Copy Markdown
Contributor Author

I added some default highlight groups. How does that look?

\})

highlight def link texTabularxArg texOpt
highlight def link texTabularxWidth texOpt
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would be better to link this to texLength? If it is a number, at least?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be getting the vocabulary wrong, but I think it's a length, not a number. For example, it's quite common to use \tabularx{\linewidth}....

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe it is a length. The texLength group matches things like 1em and similar, and I believe it is a better default highlight group.

@lervag
Copy link
Copy Markdown
Owner

lervag commented Jun 6, 2022

Looks more or less good! I have one comment, and also a response regarding the option group. I looked at the docs, and I notice the syntax description looks like this:

\begin{tabularx}{WIDTH}[POS]{PREAMBLE}

Thus, there is a possible option group after the WIDTH argument. The WIDTH argument does not need a default highlight group, but it should contain the texLength group to match length specifications. Give it one more shot, and in the next iteration I'll either merge (possibly with minor adjustments) or be more concrete and helpful!

@MarcelRobitaille
Copy link
Copy Markdown
Contributor Author

Sorry for the delay. I think I got what you mean. Also, thanks for explaining how to run only the tests for test-tabularx. I am not an expert with Makefiles.

I just realise that the first link for tabularx points to the doc for the 1999 version of tabularx, which has no [pos] as far as I can tell. I see the option in the 2020 version.

@lervag
Copy link
Copy Markdown
Owner

lervag commented Jul 10, 2022

Sorry for the delay. I think I got what you mean. Also, thanks for explaining how to run only the tests for test-tabularx. I am not an expert with Makefiles.

No problem!

I just realise that the first link for tabularx points to the doc for the 1999 version of tabularx, which has no [pos] as far as I can tell. I see the option in the 2020 version.

Ah, cool. Then we should keep the [pos] argument. It seems it remains to change the default highlight group for texTabularxWidth?

@MarcelRobitaille
Copy link
Copy Markdown
Contributor Author

It seems it remains to change the default highlight group for texTabularxWidth?

Sorry, I thought you meant to put the 'contains': 'texLength' like I did on line 17. Did I get it right now?

lervag added a commit that referenced this pull request Jul 11, 2022
@lervag
Copy link
Copy Markdown
Owner

lervag commented Jul 11, 2022

Thanks, I've merged now with a few minor adjustments. The most important one: The 'contains': 'texLength' was not right and not needed.

@lervag lervag closed this Jul 11, 2022
@MarcelRobitaille MarcelRobitaille deleted the feat/tabularx branch July 11, 2022 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants