Skip to content

Commit

Permalink
fix: keep braces when extracting table commands (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
muzimuzhi committed Nov 22, 2024
1 parent d441584 commit 4d39a49
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions tabularray/tabularray.sty
Original file line number Diff line number Diff line change
Expand Up @@ -2823,7 +2823,9 @@
{
\tl_clear:N \l__tblr_saved_table_commands_before_cell_text_tl
\tl_clear:N \l__tblr_saved_cell_text_after_table_commands_tl
\exp_last_unbraced:NV \__tblr_extract_table_commands_next:n #1 \q_stop
% \beginunravel
\exp_last_unbraced:No \__tblr_extract_table_commands_next: #1 \q_stop
% \endunravel
\tl_if_empty:NF \l__tblr_saved_table_commands_before_cell_text_tl
{
\__tblr_prop_gput:neV { command }
Expand All @@ -2834,19 +2836,45 @@
}
%% #1 maybe a single token or multiple tokens from a pair of braces
\cs_new_protected:Npn \__tblr_extract_table_commands_next:n #1
\cs_new_protected:Npn \__tblr_extract_table_commands_next:
{
\tl_if_single_token:nTF {#1}
\peek_after:Nw \__tblr_extract_table_commands_aux:
}
\cs_new_protected:Npn \__tblr_extract_table_commands_aux:
{
% if \q_stop, stop
% if space, skip
% if macro: if table command, extract; otherwise stop and collect
% otherwise, stop and collect the remaining as real cell text
\token_case_meaning:NnF \l_peek_token
{
\__tblr_if_table_command:NTF #1
{ \__tblr_extract_one_table_command:N #1 }
\q_stop
{ \__tblr_save_real_cell_text_aux:w \prg_do_nothing: }
\c_space_token
% similar to \peek_remove_spaces:n, especially \__peek_true_remove:w
% but quicker
{
\token_if_eq_meaning:NNF #1 \q_stop
{ \__tblr_save_real_cell_text:w #1 }
\tex_afterassignment:D \__tblr_extract_table_commands_next:
\cs_set_eq:NN \__tblr_unused:w
}
}
% prefix #1 with \prg_do_nothing: to prevent brace stripping
{ \__tblr_save_real_cell_text_aux:w \prg_do_nothing: {#1} }
{
\token_if_macro:NTF \l_peek_token
{ \__tblr_extract_table_commands_auxi:N }
{ \__tblr_save_real_cell_text_aux:w \prg_do_nothing: }
}
}
\cs_new_protected:Npn \__tblr_extract_table_commands_auxi:N #1
{
\__tblr_if_table_command:NTF #1
{
\__tblr_extract_one_table_command:N #1
}
{
\__tblr_save_real_cell_text_aux:w \prg_do_nothing: #1
}
}
\cs_new_protected:Npn \__tblr_extract_one_table_command:N #1
Expand Down Expand Up @@ -2883,7 +2911,7 @@
\int_decr:N \l__tblr_a_int
\__tblr_extract_table_command_arg_m:n
}
{ \__tblr_extract_table_commands_next:n }
{ \__tblr_extract_table_commands_next: }
}
%% The outermost set of braces of cell text #1 will be removed
Expand Down

0 comments on commit 4d39a49

Please sign in to comment.