tabularray
tabularray copied to clipboard
Clean up begin/end pairs and scratch variables
There are quite a few functions in tabularray enclose their body with \group_begin:/\group_end: pairs, such as
\cs_new_protected:Npn \__tblr_get_vcell_and_sizes:NN #1 #2
{
\group_begin:
\vbox_set:Nn \l_tmpb_box { \__tblr_make_vcell_text:NN #1 #2 }
\vbox_set_top:Nn \l_tmpa_box { \vbox_unpack:N \l_tmpb_box }
\__tblr_process_stretch:
\dim_gset:Nn \g__tblr_cell_wd_dim { \box_wd:N \l_tmpb_box }
\dim_gset:Nn \g__tblr_cell_ht_dim
{ \box_ht:N \l_tmpb_box + \box_dp:N \l_tmpb_box }
\dim_gset:Nn \g__tblr_cell_head_dim { \box_ht:N \l_tmpa_box }
\dim_gset:Nn \g__tblr_cell_foot_dim { \box_dp:N \l_tmpb_box }
\tl_case:Nn \g__tblr_cell_valign_tl
{
\c__tblr_valign_h_tl
{ \box_use:N \l_tmpa_box }
\c__tblr_valign_m_tl
{
\tl_case:Nn \g__tblr_cell_middle_tl
{
\c__tblr_middle_t_tl
{ \box_use:N \l_tmpa_box }
\c__tblr_middle_m_tl
{
\tl_set:Nx \l__tblr_b_tl
{
\dim_eval:n
{
( \g__tblr_cell_ht_dim - \g__tblr_cell_head_dim
- \g__tblr_cell_foot_dim ) / 2
}
}
\box_set_ht:Nn \l_tmpb_box
{ \g__tblr_cell_head_dim + \l__tblr_b_tl }
\box_set_dp:Nn \l_tmpb_box
{ \g__tblr_cell_foot_dim + \l__tblr_b_tl }
\box_use:N \l_tmpb_box
}
\c__tblr_middle_b_tl
{ \box_use:N \l_tmpb_box }
}
}
\c__tblr_valign_f_tl
{ \box_use:N \l_tmpb_box }
}
\group_end:
}
One of the reason is that tabularray uses too many scratch variables (\l_tmpa_box, \l__tblr_b_tl, etc). The same variable may have different meanings in different functions, which causes some conflicts, especially in subtables. We need to clean up them.
When cleaning up this, I strongly suggest to make use of the proper types of relevant token list variables, so _int for integer values etc. This will probably even reduce code overhead, because in some cases it is no longer necessary to use things like \int_eval:n to make sure that the result has the proper type. At least, cleaning up this will make it much easier for contributors to access certain values. Where it makes sense, some variables could even be made global, in order to be able to access them outside of groups without the need to recalculate.
I needs to clean up them step by step and case by case. Maybe I can start from variables used in tikz library.