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

Two small improvements for named indexes U-Z #385

Merged
merged 6 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions tabularray.sty
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
}

\cs_generate_variant:Nn \msg_error:nnnn { nnVn }
\cs_generate_variant:Nn \msg_error:nnnnn { nnnVV }
\cs_generate_variant:Nn \prop_item:Nn { Ne, NV }
\cs_generate_variant:Nn \prop_put:Nnn { Nxn, Nxx, NxV }
\cs_generate_variant:Nn \regex_replace_all:NnN { NVN }
Expand Down Expand Up @@ -877,14 +878,15 @@
\cs_new_protected:Npn \__tblr_child_selector_odd_or_even:nn #1 #2
{
\seq_set_split:Nnn \l_tmpa_seq {-} { #2 - Z }
\tl_set:Nx \l__tblr_child_from_tl { \seq_item:Nn \l_tmpa_seq {1} }
\tl_set:Nx \l__tblr_child_to_tl { \seq_item:Nn \l_tmpa_seq {2} }
\__tblr_child_name_to_index:eN { \seq_item:Nn \l_tmpa_seq {1} }
\l__tblr_child_from_tl
\__tblr_child_name_to_index:eN { \seq_item:Nn \l_tmpa_seq {2} }
\l__tblr_child_to_tl
\tl_use:c { int_if_ #1 :nF } { \l__tblr_child_from_tl }
{
\tl_set:Nx \l__tblr_child_from_tl
{ \int_eval:n { \l__tblr_child_from_tl + 1 } }
}
\__tblr_child_name_to_index:VN \l__tblr_child_to_tl \l__tblr_child_to_tl
\int_step_inline:nnnn { \l__tblr_child_from_tl } {2} { \l__tblr_child_to_tl }
{ \clist_put_right:Nn \l_tblr_childs_clist {##1} }
}
Expand Down Expand Up @@ -942,17 +944,26 @@

\regex_const:Nn \c__tblr_child_name_regex { ^ [U-Z] $ }

\msg_new:nnn { tabularray } { named-index-out-of-bound }
{ Named ~ index ~ ``#1'' ~ (#2) ~ out ~ of ~ bound ~ [1, ~ #3]. }

%% Convert U, V, W, X, Y, Z to the indexes of the last six childs, respectively
\cs_new_protected_nopar:Npn \__tblr_child_name_to_index:nN #1 #2
{
\regex_match:NnTF \c__tblr_child_name_regex {#1}
{
\tl_set:Nx #2
{ \int_eval:n { \l_tblr_childs_total_tl + \int_from_alph:n {#1} - 26 } }
\int_compare:nNnT #2 < 1
{
\msg_error:nnnVV { tabularray } { named-index-out-of-bound }
{#1} {#2} {\l_tblr_childs_total_tl}
\tl_set:Nn #2 {1}
}
}
{ \tl_set:Nx #2 { #1 } }
}
\cs_generate_variant:Nn \__tblr_child_name_to_index:nN { VN }
\cs_generate_variant:Nn \__tblr_child_name_to_index:nN { VN, eN }

%%% --------------------------------------------------------
%%> \section{New Table Commands}
Expand Down
2 changes: 1 addition & 1 deletion testfiles/extra-002.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5e1656f7611de36d23ef861c609ba7e8
9d7895b1283ee571643baaf1b0828fd4
Binary file modified testfiles/extra-002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions testfiles/extra-002.tex
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,25 @@
\end{tblr}
\ENDTEST

\bigskip\hrule\bigskip

\BEGINTEST{named indexes U-Z in child from}
\begin{tblr}{
hlines, vlines,
cell{-}{even[X-Z]}={preto=x}
}
& & & \\
\end{tblr}
\ENDTEST

\bigskip\hrule\bigskip

\BEGINTEST{name indexes U-Z ensured positive}
\begin{tblr}{
hlines, vlines,
cell{-}{U-Z}={preto=x}
}
& & & \\
\end{tblr}
\ENDTEST
\end{document}
16 changes: 16 additions & 0 deletions testfiles/extra-002.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,21 @@ LaTeX Font Info: External font `cmex10' loaded for size
TEST 2: named indexes U-Z
============================================================
============================================================
============================================================
TEST 3: named indexes U-Z in child from
============================================================
============================================================
============================================================
TEST 4: name indexes U-Z ensured positive
============================================================
! Package tabularray Error: Named index ``U'' (-1) out of bound [1, 4].
Type <return> to continue.
...
l. ...\end
{tblr}
LaTeX does not know anything more about this error, sorry.
Try typing <return> to proceed.
If that doesn't work, type X <return> to quit.
============================================================
[1
] (extra-002.aux)