diff options
author | Norbert Preining <norbert@preining.info> | 2024-02-17 03:01:13 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2024-02-17 03:01:13 +0000 |
commit | 8886ad587a305595ce543a74b0fc779f0732a6e9 (patch) | |
tree | 25f6e576a52343cad4a3b56b2f669e09432211b8 /macros/latex/contrib/tabularray/tabularray.sty | |
parent | a6e02d45ad0d10cfc3256fc91abe80d6228325a4 (diff) |
CTAN sync 202402170301
Diffstat (limited to 'macros/latex/contrib/tabularray/tabularray.sty')
-rw-r--r-- | macros/latex/contrib/tabularray/tabularray.sty | 222 |
1 files changed, 186 insertions, 36 deletions
diff --git a/macros/latex/contrib/tabularray/tabularray.sty b/macros/latex/contrib/tabularray/tabularray.sty index 5f6b43ebd2..66ec506b96 100644 --- a/macros/latex/contrib/tabularray/tabularray.sty +++ b/macros/latex/contrib/tabularray/tabularray.sty @@ -18,7 +18,7 @@ \DeclareCurrentRelease{}{2022-01-01} \RequirePackage{expl3} -\ProvidesExplPackage{tabularray}{2023-03-01}{2023A} +\ProvidesExplPackage{tabularray}{2024-02-16}{2024A} {Typeset tabulars and arrays with LaTeX3} %% \IfFormatAtLeastTF, xparse and lthooks are added in LaTeX 2020-10-01 @@ -167,6 +167,24 @@ \dim_new:N \leftsep \dim_new:N \rightsep +%% Some functions for lwarp to remove rules and boxes +\cs_new:Npn \tblr_hrule_ht:n #1 + { + \hrule height ~ #1 \scan_stop: + } +\cs_new:Npn \tblr_vrule_wd_ht_dp:nnn #1 #2 #3 + { + \vrule width ~ #1 ~ height ~ #2 ~ depth ~ #3 \scan_stop: + } +\cs_new_protected:Npn \tblr_box_use:N #1 + { + \box_use:N #1 + } +\cs_new_protected:Npn \tblr_vbox_set:Nn #1 #2 + { + \vbox_set:Nn #1 {#2} + } + %%% -------------------------------------------------------- %%> \section{Data Structures Based on Property Lists} %%% -------------------------------------------------------- @@ -1086,6 +1104,9 @@ \dim_zero_new:N \rulewidth \dim_set:Nn \rulewidth {0.4pt} +\prop_new:N \g__tblr_defined_hdash_styles_prop +\prop_new:N \g__tblr_defined_vdash_styles_prop + \prop_gset_from_keyval:Nn \g__tblr_defined_hdash_styles_prop { solid = \hrule height \rulewidth } \prop_gset_from_keyval:Nn \g__tblr_defined_vdash_styles_prop @@ -2662,6 +2683,7 @@ \cs_new_protected:Npn \__tblr_builder:nnn #1 #2 #3 { \int_gincr:N \g_tblr_level_int + \__tblr_hook_use:n { tabularray/trial/before } \bool_set_true:N \lTblrMeasuringBool \__tblr_clear_prop_lists: \__tblr_clear_spec_lists: @@ -2689,6 +2711,7 @@ \__tblr_enable_content_commands: \__tblr_calc_cell_and_line_sizes: \bool_set_false:N \lTblrMeasuringBool + \__tblr_hook_use:n { tabularray/trial/after } \LogTblrTracing { step = build ~ the ~ whole ~ table} \__tblr_build_whole: \int_gdecr:N \g_tblr_level_int @@ -2751,11 +2774,9 @@ { \__tblr_hook_split_before: \tl_set:Nx \l__tblr_expand_tl { \__tblr_spec_item:nn { outer } { expand } } - \tl_set:Nx \l__tblr_expand_tl { \tl_head:N \l__tblr_expand_tl } - \tl_if_empty:NF \l__tblr_expand_tl + \tl_map_inline:Nn \l__tblr_expand_tl { - \exp_last_unbraced:NNV - \__tblr_expand_table_body:NN \l__tblr_body_tl \l__tblr_expand_tl + \__tblr_expand_table_body:NN \l__tblr_body_tl ##1 } } @@ -2953,6 +2974,13 @@ %%> \section{Initialize Table Inner Specifications} %%% -------------------------------------------------------- +\prop_new:N \g__tblr_initial_table_prop +\prop_new:N \g__tblr_initial_rows_prop +\prop_new:N \g__tblr_initial_columns_prop +\prop_new:N \g__tblr_initial_cells_prop +\prop_new:N \g__tblr_initial_hlines_prop +\prop_new:N \g__tblr_initial_vlines_prop + \prop_gset_from_keyval:Nn \g__tblr_initial_table_prop { stretch = 1, @@ -3193,6 +3221,7 @@ B .meta:n = { baseline = B }, valign .meta:n = { baseline = #1 }, % obsolete, will be removed some day expand .code:n = \__tblr_outer_gput_spec:nn { expand } {#1}, + expand+ .code:n = \__tblr_outer_gconcat_spec:nn { expand } {#1}, headsep .code:n = \__tblr_outer_gput_spec:nn { headsep } {#1}, footsep .code:n = \__tblr_outer_gput_spec:nn { footsep } {#1}, presep .code:n = \__tblr_outer_gput_spec:nn { presep } {#1}, @@ -3210,6 +3239,11 @@ } \cs_generate_variant:Nn \__tblr_outer_gput_spec:nn { ne } +\cs_new_protected:Npn \__tblr_outer_gconcat_spec:nn #1 #2 + { + \__tblr_outer_gput_spec:ne {#1} { \__tblr_spec_item:nn { outer } { #1 } \exp_not:n { #2 } } + } + \regex_const:Nn \c__tblr_option_key_name_regex { ^ [A-Za-z\-] + $ } \msg_new:nnn { tabularray } { unknown-outer-key } @@ -5505,6 +5539,7 @@ \cs_new_protected:Npn \__tblr_build_whole: { + \__tblr_hook_use:n { tabularray/table/before } \tl_if_eq:enTF { \__tblr_spec_item:nn { outer } { long } } { true } { \__tblr_build_long_table:e { \__tblr_spec_item:nn { outer } { halign } } } { @@ -5518,6 +5553,7 @@ { \__tblr_spec_item:nn { outer } { baseline } } } } + \__tblr_hook_use:n { tabularray/table/after } } \dim_new:N \l__tblr_remain_height_dim @@ -5573,8 +5609,19 @@ % \pagetotal maybe exceed \pagegoal after adding presep, % or after adding rowhead or rowfoot of the table. % In these cases, we will not typeset table in this page, - % but rather do some negative \vskip and execute \newpage. - \skip_vertical:n { \pagegoal - \pagetotal } + % but rather force a page break. + \group_begin: + \dim_set:Nn \l_tmpb_dim + { + % Enough to overfill the page (including shrink). + \pagegoal - \pagetotal + \l_tmpa_dim + + \__tblr_box_height:N \l__tblr_table_firsthead_box + + \__tblr_box_height:N \l__tblr_table_firstfoot_box + } + \skip_vertical:n { \l_tmpb_dim } + \tex_penalty:D 9999 + \skip_vertical:n { -\l_tmpb_dim } + \group_end: } { \__tblr_build_page_table:nnx {#1} @@ -5582,8 +5629,8 @@ { \int_use:N \l__tblr_prev_i_int } \int_incr:N \l__tblr_table_page_int \int_set:Nn \l__tblr_long_from_int { \l__tblr_prev_i_int + 1 } + \TblrNewPage } - \TblrNewPage \hbox{}\kern-\topskip\nobreak \noindent \LogTblrTracing { page } @@ -5796,7 +5843,7 @@ \cs_new_protected:Npn \__tblr_build_one_table:nnNN #1 #2 #3 #4 { \box_clear:N \l__tblr_table_hlines_box - \vbox_set:Nn \l__tblr_table_box + \tblr_vbox_set:Nn \l__tblr_table_box { \int_step_variable:nnNn {#1} {#2} \l__tblr_i_tl { @@ -5804,9 +5851,9 @@ { \int_compare_p:nNn { \l__tblr_i_tl } > {#1} } { \bool_if_p:N #3 } { \__tblr_put_one_hline:n { \__tblr_build_hline:V \l__tblr_i_tl } } - \hrule height ~ 0pt % remove lineskip between hlines and rows + \tblr_hrule_ht:n { 0pt } % remove lineskip between hlines and rows \__tblr_put_one_row:n { \__tblr_build_row:N \l__tblr_i_tl } - \hrule height ~ 0pt + \tblr_hrule_ht:n { 0pt } } \bool_if:NT #4 { @@ -5818,7 +5865,7 @@ - \box_ht:N \l__tblr_table_hlines_box - \box_dp:N \l__tblr_table_hlines_box } - \box_use:N \l__tblr_table_hlines_box + \tblr_box_use:N \l__tblr_table_hlines_box } } @@ -6253,11 +6300,11 @@ \__tblr_get_row_inner_height_depth:VNNNN #1 \l__tblr_row_ht_dim \l__tblr_row_dp_dim \l__tblr_row_abovesep_dim \l__tblr_row_belowsep_dim - \vrule width ~ 0pt ~ height ~ \l__tblr_row_ht_dim ~ depth ~ \l__tblr_row_dp_dim + \__tblr_hook_use:n { tabularray/row/before } + \tblr_vrule_wd_ht_dp:nnn {0pt} {\l__tblr_row_ht_dim} {\l__tblr_row_dp_dim} \hbox_set:Nn \l__tblr_row_vlines_box { - \vrule width ~ 0pt ~ height ~ \l__tblr_row_ht_dim - ~ depth ~ \l__tblr_row_dp_dim + \tblr_vrule_wd_ht_dp:nnn {0pt} {\l__tblr_row_ht_dim} {\l__tblr_row_dp_dim} } \int_step_variable:nNn { \c@colcount } \l__tblr_j_tl { @@ -6269,6 +6316,7 @@ { \__tblr_build_vline_segment:nn {#1} { \int_eval:n {\c@colcount + 1} } } \skip_horizontal:n { - \box_wd:N \l__tblr_row_vlines_box } \box_use:N \l__tblr_row_vlines_box + \__tblr_hook_use:n { tabularray/row/after } } %% Read from table specifications and calculate inner height/depth of the row @@ -6442,8 +6490,12 @@ } } -\tl_new:N \l__tblr_cell_rowspan_tl -\tl_new:N \l__tblr_cell_colspan_tl +%% These public variables are updated by default before building a cell +\tl_new:N \lTblrCellRowSpanTl +\tl_new:N \lTblrCellColSpanTl +\tl_new:N \lTblrCellBackgroundTl +\bool_new:N \lTblrCellOmittedBool + \dim_new:N \l__tblr_cell_wd_dim \dim_new:N \l__tblr_cell_ht_dim @@ -6460,17 +6512,17 @@ { \__tblr_data_item:nen { column } {#2} { leftsep} } \tl_set:Nx \l__tblr_y_tl { \__tblr_data_item:nen { column } {#2} { rightsep } } - \tl_set:Nx \l__tblr_cell_colspan_tl + \tl_set:Nx \lTblrCellColSpanTl { \__tblr_data_item:neen { cell } {#1} {#2} { colspan } } - \int_compare:nNnTF { \l__tblr_cell_colspan_tl } < {2} + \int_compare:nNnTF { \lTblrCellColSpanTl } < {2} { \dim_set:Nn \l__tblr_cell_wd_dim { \l__tblr_w_tl } } { \__tblr_get_span_horizontal_sizes:NNNNN #1 #2 \l__tblr_o_dim \l__tblr_cell_wd_dim \l__tblr_q_dim } - \tl_set:Nx \l__tblr_cell_rowspan_tl + \tl_set:Nx \lTblrCellRowSpanTl { \__tblr_data_item:neen { cell } {#1} {#2} { rowspan } } - \int_compare:nNnTF { \l__tblr_cell_rowspan_tl } < {2} + \int_compare:nNnTF { \lTblrCellRowSpanTl } < {2} { \dim_set:Nn \l__tblr_cell_ht_dim { \l__tblr_h_tl } } { \__tblr_get_span_vertical_sizes:NNNNN #1 #2 @@ -6482,8 +6534,73 @@ \group_end: } +%% These public variables are updated by html library before building a cell +\tl_new:N \lTblrCellAboveBorderStyleTl +\tl_new:N \lTblrCellAboveBorderWidthTl +\tl_new:N \lTblrCellAboveBorderColorTl +\tl_new:N \lTblrCellBelowBorderStyleTl +\tl_new:N \lTblrCellBelowBorderWidthTl +\tl_new:N \lTblrCellBelowBorderColorTl +\tl_new:N \lTblrCellLeftBorderStyleTl +\tl_new:N \lTblrCellLeftBorderWidthTl +\tl_new:N \lTblrCellLeftBorderColorTl +\tl_new:N \lTblrCellRightBorderStyleTl +\tl_new:N \lTblrCellRightBorderWidthTl +\tl_new:N \lTblrCellRihgtBorderColorTl + +%% #1: row number in tl; #2: column number in tl +%% This function is called only when html library is loaded. +%% The properties can be used by tagpdf, tex4ht and lwarp packages +\cs_new_protected:Npn \__tblr_expose_cell_properties:NN #1 #2 + { + \__tblr_expose_cell_border:NNnn #1 #2 { hline } { Above } + \tl_set:Nx \l_tmpa_tl { \int_eval:n { #1 + \lTblrCellRowSpanTl } } + \__tblr_expose_cell_border:NNnn \l_tmpa_tl #2 { hline } { Below } + \__tblr_expose_cell_border:NNnn #1 #2 { vline } { Left } + \tl_set:Nx \l_tmpb_tl { \int_eval:n { #2 + \lTblrCellColSpanTl } } + \__tblr_expose_cell_border:NNnn #1 \l_tmpb_tl { vline } { Right } + } + +\tl_new:N \l__tblr_dash_value_tl +\tl_new:N \l__tblr_dash_value_head_tl +\tl_new:N \l__tblr_dash_value_tail_tl +\tl_new:N \l__tblr_width_value_tl +\tl_new:N \l__tblr_color_value_tl + +%% #1: row number in tl; #2: column number in tl; +%% #3: hline or vline; #4: position of border (Above/Below/Left/Right). +\cs_new_protected:Npn \__tblr_expose_cell_border:NNnn #1 #2 #3 #4 + { + %% get border style + \tl_set:Nx \l__tblr_dash_value_tl %% may be empty + { \__tblr_spec_item:ne { #3 } { [#1][#2](1) / @dash } } + \tl_set:Nx \l__tblr_dash_value_head_tl { \tl_head:N \l__tblr_dash_value_tl } + \tl_set:Nx \l__tblr_dash_value_tail_tl { \tl_tail:N \l__tblr_dash_value_tl } + \exp_args:NV \tl_if_eq:NNTF \l__tblr_dash_value_head_tl \@tblr@dash + { + \tl_set_eq:cN { lTblrCell #4 BorderStyleTl } \l__tblr_dash_value_tail_tl + %% get border width + \tl_set:Nx \l__tblr_width_value_tl + { \__tblr_spec_item:ne { #3 } { [#1][#2](1) / wd } } + \tl_if_empty:NTF \l__tblr_width_value_tl + { \tl_set:cn { lTblrCell #4 BorderWidthTl } { 0.4pt } } + { \tl_set_eq:cN { lTblrCell #4 BorderWidthTl } \l__tblr_width_value_tl } + %% get border color + \tl_set:cx { lTblrCell #4 BorderColorTl } + { \__tblr_spec_item:ne { #3 } { [#1][#2](1) / fg } } + } + { + \tl_clear:c { lTblrCell #4 BorderStyleTl } + \tl_set:cn { lTblrCell #4 BorderWidthTl } { 0pt } + \tl_clear:c { lTblrCell #4 BorderColorTl } + } + } + \cs_new_protected:Npn \__tblr_build_cell_content:NN #1 #2 { + \bool_if:NT \l__tblr_html_variables_bool + { \__tblr_expose_cell_properties:NN #1 #2 } + \__tblr_hook_use:n { tabularray/cell/before } \hbox_set_to_wd:Nnn \l__tblr_a_box { \l__tblr_cell_wd_dim } { \tl_if_eq:NnTF \g__tblr_cell_halign_tl {j} @@ -6502,7 +6619,7 @@ \c__tblr_valign_m_tl { \vfil - \int_compare:nNnT { \l__tblr_cell_rowspan_tl } < {2} + \int_compare:nNnT { \lTblrCellRowSpanTl } < {2} { \box_set_ht:Nn \l__tblr_a_box { \__tblr_data_item:nen { row } {#1} { @row-upper } } @@ -6522,7 +6639,7 @@ \c__tblr_valign_f_tl { \vfil - \int_compare:nNnTF { \l__tblr_cell_rowspan_tl } < {2} + \int_compare:nNnTF { \lTblrCellRowSpanTl } < {2} { \box_set_dp:Nn \l__tblr_a_box { \__tblr_data_item:nen { row } {#1} { @row-foot } } @@ -6532,7 +6649,7 @@ { \__tblr_data_item:nen { row } - { \int_eval:n { #1 + \l__tblr_cell_rowspan_tl - 1 } } + { \int_eval:n { #1 + \lTblrCellRowSpanTl - 1 } } { @row-foot } } } @@ -6550,16 +6667,22 @@ \skip_horizontal:n { \l__tblr_x_tl } \box_use:N \l__tblr_c_box \skip_horizontal:n { \l__tblr_y_tl - \l__tblr_cell_wd_dim + \l__tblr_w_tl } + \__tblr_hook_use:n { tabularray/cell/after } } \cs_new_protected:Npn \__tblr_build_cell_background:NN #1 #2 { - \int_compare:nNnT { \__tblr_data_item:neen { cell } {#1} {#2} { omit } } = {0} + \bool_set:Nn \lTblrCellOmittedBool { - \group_begin: - \tl_set:Nx \l__tblr_b_tl + \int_compare_p:nNn + { \__tblr_data_item:neen { cell } {#1} {#2} { omit } } = {1} + } + \bool_if:NF \lTblrCellOmittedBool + { + \tl_set:Nx \lTblrCellBackgroundTl { \__tblr_data_item:neen { cell } {#1} {#2} { background } } - \tl_if_empty:NF \l__tblr_b_tl + \group_begin: + \tl_if_empty:NF \lTblrCellBackgroundTl { \__tblr_get_cell_background_width:NNN #1 #2 \l_tmpa_dim \__tblr_get_cell_background_depth:NNN #1 #2 \l_tmpb_dim @@ -6567,7 +6690,7 @@ { \dim_use:N \l_tmpa_dim } { \l__tblr_row_ht_dim } { \dim_use:N \l_tmpb_dim } - { \l__tblr_b_tl } + { \lTblrCellBackgroundTl } } \group_end: } @@ -6576,7 +6699,7 @@ %% #1: row number; #2: column number; #3 resulting dimension \cs_new_protected:Npn \__tblr_get_cell_background_width:NNN #1 #2 #3 { - \int_compare:nNnTF { \l__tblr_cell_colspan_tl } < {2} + \int_compare:nNnTF { \lTblrCellColSpanTl } < {2} { \dim_set:Nn #3 { \l__tblr_x_tl + \l__tblr_w_tl + \l__tblr_y_tl } } { \dim_set:Nn #3 { \l__tblr_o_dim + \l__tblr_cell_wd_dim + \l__tblr_q_dim } @@ -6586,7 +6709,7 @@ %% #1: row number; #2: column number; #3 resulting dimension \cs_new_protected:Npn \__tblr_get_cell_background_depth:NNN #1 #2 #3 { - \int_compare:nNnTF { \l__tblr_cell_rowspan_tl } < {2} + \int_compare:nNnTF { \lTblrCellRowSpanTl } < {2} { \dim_set_eq:NN #3 \l__tblr_row_dp_dim } { \dim_set:Nn #3 @@ -6622,7 +6745,7 @@ \dim_zero:N #4 \dim_add:Nn #4 { \prop_item:Ne \l__tblr_row_item_skip_size_prop { item[#1] } } - \int_step_inline:nnn { #1 + 1 } { #1 + \l__tblr_cell_rowspan_tl - 1 } + \int_step_inline:nnn { #1 + 1 } { #1 + \lTblrCellRowSpanTl - 1 } { \dim_add:Nn #4 { @@ -6634,7 +6757,7 @@ \dim_set:Nn #5 { \__tblr_data_item:nen { row } - { \int_eval:n { #1 + \l__tblr_cell_rowspan_tl - 1 } } { belowsep } + { \int_eval:n { #1 + \lTblrCellRowSpanTl - 1 } } { belowsep } } %\tl_log:x { cell[#1][#2] ~:~ \dim_use:N #3, \dim_use:N #4, \dim_use:N #5 } } @@ -6651,7 +6774,7 @@ \dim_zero:N #4 \dim_add:Nn #4 { \prop_item:Ne \l__tblr_col_item_skip_size_prop { item[#2] } } - \int_step_inline:nnn { #2 + 1 } { #2 + \l__tblr_cell_colspan_tl - 1 } + \int_step_inline:nnn { #2 + 1 } { #2 + \lTblrCellColSpanTl - 1 } { \dim_add:Nn #4 { @@ -6663,7 +6786,7 @@ \dim_set:Nn #5 { \__tblr_data_item:nen { column } - { \int_eval:n {#2 + \l__tblr_cell_colspan_tl - 1} } { rightsep } + { \int_eval:n {#2 + \lTblrCellColSpanTl - 1} } { rightsep } } %\tl_log:x { cell[#1][#2] ~:~ \dim_use:N #3, \dim_use:N #4, \dim_use:N #5 } } @@ -6916,7 +7039,11 @@ \NewDocumentCommand \UseTblrLibrary { m } { - \clist_map_inline:nn {#1} { \use:c { __tblr_use_lib_ ##1: } } + \clist_map_inline:nn {#1} + { + \use:c { __tblr_use_lib_ ##1: } + \cs_undefine:c { __tblr_use_lib_ ##1: } + } } %% Library amsmath and environments +array, +matrix, +cases, ... @@ -7200,6 +7327,29 @@ } } +%% Library hook provides some public hooks + +\cs_new_protected:Npn \__tblr_hook_use:n #1 {} + +\NewTblrLibrary { hook } + { + \cs_set_eq:NN \__tblr_hook_use:n \hook_use:n + \hook_new_pair:nn { tabularray/trial/before } { tabularray/trial/after } + \hook_new_pair:nn { tabularray/table/before } { tabularray/table/after } + \hook_new_pair:nn { tabularray/row/before } { tabularray/row/after } + \hook_new_pair:nn { tabularray/cell/before } { tabularray/cell/after } + } + +%% Library html provides more public variables +%% These variables can be used by tagpdf, tex4ht and lwarp packages + +\bool_new:N \l__tblr_html_variables_bool + +\NewTblrLibrary { html } + { + \bool_set_true:N \l__tblr_html_variables_bool + } + %% Library nameref and its caption-ref template \NewTblrLibrary { nameref } |