diff options
author | Karl Berry <karl@freefriends.org> | 2021-08-01 20:37:16 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-08-01 20:37:16 +0000 |
commit | 840ac11675dc87ad8c8ed61a9b95748fdcbaf44e (patch) | |
tree | 47af473d0e437dd020c7c523852b9e22cb9df658 /Master/texmf-dist/tex/latex/tabularray | |
parent | 9f6f0d1fd20f6010188013cbef1b8a9aa65576df (diff) |
tabularray (1aug21)
git-svn-id: svn://tug.org/texlive/trunk@60140 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/tabularray')
-rw-r--r-- | Master/texmf-dist/tex/latex/tabularray/tabularray.sty | 359 |
1 files changed, 290 insertions, 69 deletions
diff --git a/Master/texmf-dist/tex/latex/tabularray/tabularray.sty b/Master/texmf-dist/tex/latex/tabularray/tabularray.sty index 0a12e61ba5f..4717992539e 100644 --- a/Master/texmf-dist/tex/latex/tabularray/tabularray.sty +++ b/Master/texmf-dist/tex/latex/tabularray/tabularray.sty @@ -12,7 +12,7 @@ \NeedsTeXFormat{LaTeX2e} \RequirePackage{expl3} -\ProvidesExplPackage{tabularray}{2021-07-01}{2021L} +\ProvidesExplPackage{tabularray}{2021-08-01}{2021M} {Typeset tabulars and arrays with LaTeX3} \RequirePackage{xparse} @@ -359,6 +359,7 @@ \__tblr_data_new_key:nnn { row } { @row-foot } { dim } \__tblr_data_new_key:nnn { row } { @row-upper } { dim } \__tblr_data_new_key:nnn { row } { @row-lower } { dim } +\__tblr_data_new_key:nnn { row } { break } { int } \int_new:N \g__tblr_data_column_key_count_int \__tblr_data_new_key:nnn { column } { width } { dim } @@ -858,12 +859,30 @@ } } +\tl_new:N \l__tblr_child_from_tl +\tl_new:N \l__tblr_child_to_tl + \cs_new_protected_nopar:Npn \__tblr_get_childs_normal_aux:w #1 - #2 \scan_stop { - \int_step_inline:nnn {#1} {#2} + \__tblr_child_name_to_index:nN {#1} \l__tblr_child_from_tl + \__tblr_child_name_to_index:nN {#2} \l__tblr_child_to_tl + \int_step_inline:nnn { \l__tblr_child_from_tl } { \l__tblr_child_to_tl } { \clist_put_right:Nn \l_tblr_childs_clist {##1} } } +\regex_const:Nn \c__tblr_child_name_regex { ^ [X-Z] $ } + +%% Convert X, Y, Z to the indexes of the last three 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 } } + } + { \tl_set:Nx #2 { #1 } } + } + %%% -------------------------------------------------------- %% \section{New Table Commands} %%% -------------------------------------------------------- @@ -929,6 +948,20 @@ \int_set:Nn \c@colnum {#2} } +%% Table commands are defined only inside tblr environments, +%% but some packages such as csvsimple need to use them outside tblr environments, +%% therefore we define some of them first here. +\ProvideDocumentCommand \SetHlines { o m m } {} +\ProvideDocumentCommand \SetHline { o m m } {} +\ProvideDocumentCommand \SetVlines { o m m } {} +\ProvideDocumentCommand \SetVline { o m m } {} +\ProvideDocumentCommand \SetCells { o m } {} +\ProvideDocumentCommand \SetCell { o m } {} +\ProvideDocumentCommand \SetRows { o m } {} +\ProvideDocumentCommand \SetRow { o m } {} +\ProvideDocumentCommand \SetColumns { o m } {} +\ProvideDocumentCommand \SetColumn { o m } {} + %%% -------------------------------------------------------- %%> \section{New Content Commands} %%% -------------------------------------------------------- @@ -1958,8 +1991,9 @@ abovesep+ .code:n = \__tblr_row_gadd_dimen:ne { abovesep } { \dim_eval:n {#1} }, belowsep+ .code:n = \__tblr_row_gadd_dimen:ne { belowsep } { \dim_eval:n {#1} }, rowsep+ .meta:n = { abovesep+ = #1, belowsep+ = #1}, - nobreak .code:n = \__tblr_prop_gput:nxx { row } - { [\int_eval:n {\c@rownum - 1}] / nobreak } { true }, + break .code:n = \__tblr_row_gput:nn { break } {#1}, + pagebreak .meta:n = { break = 1 }, + nopagebreak .meta:n = { break = -1 }, unknown .code:n = \__tblr_row_unknown_key:V \l_keys_key_str, } @@ -2028,6 +2062,16 @@ } \cs_generate_variant:Nn \__tblr_row_unknown_key:n { V } +\NewTableCommand \pagebreak + { + \tblr_set_row:nn {} { break = 1 } + } + +\NewTableCommand \nopagebreak + { + \tblr_set_row:nn {} { break = -1 } + } + %%% -------------------------------------------------------- %% \section{Column Types and Row Types} %%% -------------------------------------------------------- @@ -2357,6 +2401,8 @@ \NewTblrEnviron { tblr } \NewTblrEnviron { longtblr } \SetTblrOuter [ longtblr ] { long } +\NewTblrEnviron { talltblr } +\SetTblrOuter [ talltblr ] { tall } \tl_new:N \l__tblr_env_name_tl \bool_new:N \l__tblr_math_mode_bool @@ -2378,16 +2424,16 @@ \int_gincr:N \g_tblr_level_int \__tblr_clear_prop_lists: \__tblr_clear_spec_lists: - \__tblr_enable_table_commands: - \LogTblrTracing { step = split ~ table} - \__tblr_split_table:n {#3} - \LogTblrTracing { command } \LogTblrTracing { step = init ~ table ~ outer ~ spec} \__tblr_init_table_outer_spec: - \LogTblrTracing { outer } \LogTblrTracing { step = parse ~ table ~ options } \__tblr_parse_table_option:n {#1} + \LogTblrTracing { outer } \LogTblrTracing { option } + \__tblr_enable_table_commands: + \LogTblrTracing { step = split ~ table} + \__tblr_split_table:n {#3} + \LogTblrTracing { command } \bool_if:NT \g__tblr_use_intarray_bool { \__tblr_init_table_data: } \LogTblrTracing { step = init ~ table ~ inner ~ spec} \__tblr_init_table_inner_spec: @@ -2439,35 +2485,54 @@ \regex_replace_all:NVN \c__tblr_remove_braces_regex \c__tblr_remove_braces_tl #1 } -%% Split table content to cells and store them -%% #1: table content +\tl_new:N \l__tblr_body_tl +\tl_new:N \l__tblr_expand_tl +\seq_new:N \l__tblr_lines_seq -\seq_new:N \l_tblr_lines_seq +%% Expand every occurrence of the specified macro once +%% #1: table content; #2: macro to be expanded +\cs_new_protected:Npn \__tblr_expand_table_body:nN #1 #2 + { + \tl_clear:N \l__tblr_body_tl + \cs_set_protected:Npn \__tblr_expand_table_body_aux:w ##1 #2 + { + \tl_put_right:Nn \l__tblr_body_tl {##1} + \peek_meaning:NTF \q_stop + { \use_none:n } + { \exp_last_unbraced:NV \__tblr_expand_table_body_aux:w #2 } + } + \__tblr_expand_table_body_aux:w #1 #2 \q_stop + } +%% Split table content to cells and store them +%% #1: table content \cs_new_protected:Npn \__tblr_split_table:n #1 { + \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:NTF \l__tblr_expand_tl + { \tl_set:Nn \l__tblr_body_tl {#1} } + { \exp_args:NnV \__tblr_expand_table_body:nN {#1} \l__tblr_expand_tl } \int_zero:N \c@rowcount \int_zero:N \c@colcount - \__tblr_split_table_to_lines:nN { #1 } \l_tblr_lines_seq - \__tblr_split_lines_to_cells:N \l_tblr_lines_seq + \__tblr_split_table_to_lines:NN \l__tblr_body_tl \l__tblr_lines_seq + \__tblr_split_lines_to_cells:N \l__tblr_lines_seq } %% Split table content to a sequence of lines -%% #1: table content, #2: resulting sequence of lines -\cs_new_protected:Npn \__tblr_split_table_to_lines:nN #1 #2 +%% #1: tl with table contents, #2: resulting sequence of lines +\cs_new_protected:Npn \__tblr_split_table_to_lines:NN #1 #2 { - \tl_set:Nn \l_tmpa_tl { #1 } - \__tblr_insert_braces:N \l_tmpa_tl - \seq_set_split:NnV \l_tmpa_seq { \\ } \l_tmpa_tl + \__tblr_insert_braces:N #1 + \seq_set_split:NnV \l_tmpa_seq { \\ } #1 \seq_clear:N #2 \seq_map_inline:Nn \l_tmpa_seq { \tl_if_head_eq_meaning:nNTF {##1} * { - \tl_set:Nn \l__tblr_b_tl { \SetRow{nobreak} } + \tl_set:Nn \l__tblr_b_tl { \SetRow { break = -1 } } \tl_set:Nx \l__tblr_c_tl { \tl_tail:n {##1} } \tl_trim_spaces:N \l__tblr_c_tl %% Ignore spaces between * and [dimen] - \tl_log:N \l__tblr_c_tl \tl_if_head_eq_meaning:VNT \l__tblr_c_tl [ { \tl_put_right:Nn \l__tblr_b_tl { \RowBefore@AddBelowSep } @@ -2699,6 +2764,8 @@ @vline-count = 0, } +\tl_new:N \l__tblr_inner_spec_verb_tl + \cs_new_protected:Npn \__tblr_init_table_inner_spec: { \prop_map_inline:Nn \g__tblr_initial_table_prop @@ -2745,6 +2812,7 @@ \__tblr_spec_gput:nen { vline } { [\int_eval:n { \c@colcount + 1}] / ##1 } {##2} } + \tl_clear:N \l__tblr_inner_spec_verb_tl \keys_set:nv { tblr } { l__tblr_default_ \l__tblr_env_name_tl _inner_tl } } @@ -2755,7 +2823,7 @@ \clist_new:N \g__tblr_table_known_keys_clist \clist_gset:Nn \g__tblr_table_known_keys_clist { - colspec, rowspec, width, hspan, vspan, stretch, + colspec, rowspec, width, hspan, vspan, stretch, verb, column, row, cell, vline, hline, columns, rows, cells, vlines, hlines, leftsep, rightsep, colsep, abovesep, belowsep, rowsep, rulesep, rowhead, rowfoot, @@ -2769,6 +2837,8 @@ hspan .code:n = \__tblr_keys_gput:nn { hspan } {#1}, vspan .code:n = \__tblr_keys_gput:nn { vspan } {#1}, stretch .code:n = \__tblr_keys_gput:nn { stretch } {#1}, + verb .tl_set:N = \l__tblr_inner_spec_verb_tl, + verb .default:n = lite, columns .code:n = \__tblr_set_every_column_aux:n {#1}, rows .code:n = \__tblr_set_every_row_aux:n {#1}, cells .code:n = \__tblr_set_every_cell_aux:n {#1}, @@ -2851,7 +2921,8 @@ \keys_define:nn { tblr-outer } { - long .code:n = \__tblr_outer_gput_spec:nn { long } {true}, + long .code:n = \__tblr_outer_gput_spec:nn { long } { true }, + tall .code:n = \__tblr_outer_gput_spec:nn { tall } { true }, halign .code:n = \__tblr_outer_gput_spec:nn { halign } {#1}, valign .code:n = \__tblr_outer_gput_spec:nn { valign } {#1}, l .meta:n = { halign = l }, @@ -2860,6 +2931,7 @@ t .meta:n = { valign = t }, m .meta:n = { valign = m }, b .meta:n = { valign = b }, + expand .code:n = \__tblr_outer_gput_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}, @@ -3252,7 +3324,11 @@ \seq_map_variable:NNn \l_tmpa_seq \l_tmpa_tl { \__tblr_remove_braces:N \l_tmpa_tl - \hbox_set:Nn \l_tmpa_box { \l__tblr_f_tl \l_tmpa_tl } + \hbox_set:Nn \l_tmpa_box + { + \l__tblr_f_tl + \__tblr_rescan_cell_tokens:N \l_tmpa_tl + } \tl_set:Nx \l__tblr_w_tl { \dim_max:nn { \l__tblr_w_tl } { \box_wd:N \l_tmpa_box } } } @@ -3267,8 +3343,8 @@ \cs_new_protected:Npn \__tblr_get_vcell_and_sizes:NN #1 #2 { \group_begin: - \vbox_set_top:Nn \l_tmpa_box { \__tblr_make_vcell_text:nN #1 #2 } - \vbox_set:Nn \l_tmpb_box { \__tblr_make_vcell_text:nN #1 #2 } + \vbox_set_top:Nn \l_tmpa_box { \__tblr_make_vcell_text:NN #1 #2 } + \vbox_set:Nn \l_tmpb_box { \__tblr_make_vcell_text:NN #1 #2 } \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 } @@ -3312,17 +3388,30 @@ %% #1: cell text; #2: box width %% All halign commands are defined at the beginning of the file -\cs_new_protected:Npn \__tblr_make_vcell_text:nN #1 #2 +\cs_new_protected:Npn \__tblr_make_vcell_text:NN #1 #2 { \dim_set:Nn \tex_hsize:D { #2 } \@arrayparboxrestore \cs:w __tblr_halign_command_ \g__tblr_cell_halign_tl : \cs_end: \mode_leave_vertical: \box_use:N \l__tblr_strut_ht_box - \bool_if:NTF \l__tblr_math_mode_bool { $#1$ } { #1 } + \bool_if:NTF \l__tblr_math_mode_bool + { $#1$ } + { \__tblr_rescan_cell_tokens:N #1 } \box_use:N \l__tblr_strut_dp_box } +\cs_new_protected:Npn \__tblr_rescan_cell_tokens:N #1 + { + \tl_if_empty:NTF \l__tblr_inner_spec_verb_tl + { #1 } + { + \regex_replace_all:nnN { . } { \c{string} \0 } #1 + \tl_set:Nx #1 { #1 } + \exp_args:NV \tex_scantokens:D #1 + } + } + %% #1: total height dimension; #2: head dimension; #3: foot dimension; %% #4: tl for resulting upper size; #5: tl for resulting lower size @@ -4315,6 +4404,7 @@ \DefTblrTemplate { contfoot-text } { normal } { Continued ~ on ~ next ~ page } \SetTblrTemplate { contfoot-text } { normal } +\DefTblrTemplate { contfoot } { empty } { } \DefTblrTemplate { contfoot } { plain } { \noindent @@ -4338,6 +4428,7 @@ \DefTblrTemplate { conthead-text } { normal } { ( Continued ) } \SetTblrTemplate { conthead-text } { normal } +\DefTblrTemplate { conthead } { empty } { } \DefTblrTemplate { conthead } { plain } { \noindent @@ -4364,6 +4455,7 @@ \tl_new:N \l__tblr_caption_short_tl +\DefTblrTemplate { caption-lot } { empty } { } \DefTblrTemplate { caption-lot } { normal } { \tl_set:Nx \l__tblr_caption_short_tl { \InsertTblrText { entry } } @@ -4377,18 +4469,22 @@ %% We need to use \hspace and \enskip, but not ~ or \space, %% since we want a correct hangindent caption paragraph. +\DefTblrTemplate { caption-tag } { empty } { } \DefTblrTemplate { caption-tag } { normal } { Table \hspace{0.25em} \thetable } \SetTblrTemplate { caption-tag } { normal } +\DefTblrTemplate { caption-sep } { empty } { } \DefTblrTemplate { caption-sep } { normal } { : \enskip } \SetTblrTemplate { caption-sep } { normal } +\DefTblrTemplate { caption-text } { empty } { } \DefTblrTemplate { caption-text } { normal } { \InsertTblrText { caption } } \SetTblrTemplate { caption-text } { normal } \box_new:N \l__tblr_caption_box \box_new:N \l__tblr_caption_left_box +\DefTblrTemplate { caption } { empty } { } \DefTblrTemplate { caption } { plain } { \hbox_set:Nn \l__tblr_caption_box @@ -4441,6 +4537,7 @@ } \SetTblrTemplate { caption } { normal } +\DefTblrTemplate { capcont } { empty } { } \DefTblrTemplate { capcont } { plain } { \hbox_set:Nn \l__tblr_caption_box @@ -4536,6 +4633,7 @@ { \textsuperscript { \sffamily \UseTblrFont { note-tag } #1 } } } +\DefTblrTemplate { note-tag } { empty } { } \DefTblrTemplate { note-tag } { normal } { \textsuperscript { \sffamily \UseTblrFont { note-tag } \InsertTblrNoteTag } @@ -4548,12 +4646,15 @@ } \SetTblrTemplate { note-target } { normal } +\DefTblrTemplate { note-sep } { empty } { } \DefTblrTemplate { note-sep } { normal } { \space } \SetTblrTemplate { note-sep } { normal } +\DefTblrTemplate { note-text } { empty } { } \DefTblrTemplate { note-text } { normal } { \InsertTblrNoteText } \SetTblrTemplate { note-text } { normal } +\DefTblrTemplate { note } { empty } { } \DefTblrTemplate { note } { plain } { \MapTblrNotes @@ -4608,18 +4709,22 @@ %%> \section{Table Remarks Templates} %%% -------------------------------------------------------- +\DefTblrTemplate { remark-tag } { empty } { } \DefTblrTemplate { remark-tag } { normal } { \itshape \UseTblrFont { remark-tag } \InsertTblrRemarkTag } \SetTblrTemplate { remark-tag } { normal } +\DefTblrTemplate { remark-sep } { empty } { } \DefTblrTemplate { remark-sep } { normal } { : \space } \SetTblrTemplate { remark-sep } { normal } +\DefTblrTemplate { remark-text } { empty } { } \DefTblrTemplate { remark-text } { normal } { \InsertTblrRemarkText } \SetTblrTemplate { remark-text } { normal } +\DefTblrTemplate { remark } { empty } { } \DefTblrTemplate { remark } { plain } { \MapTblrRemarks @@ -4687,10 +4792,12 @@ foot .meta:n = { firstfoot, middlefoot, lastfoot }, } +\DefTblrTemplate { head } { empty } { } +\DefTblrTemplate { foot } { empty } { } + \DefTblrTemplate { firsthead } { normal } { \UseTblrTemplate { caption } { default } - \UseTblrTemplate { caption-lot } { default } } \DefTblrTemplate { middlehead, lasthead } { normal } @@ -4793,8 +4900,7 @@ \__tblr_get_table_width: \__tblr_build_table_head_aux:Nn \l__tblr_table_firsthead_box { - \tl_set:Nn \l_tmpa_tl { \InsertTblrText { label } } - \tl_if_empty:NF \l_tmpa_tl { \exp_args:NV \label \l_tmpa_tl } + \__tblr_build_table_label_entry: \UseTblrTemplate { firsthead } { default } } \__tblr_build_table_head_aux:Nn @@ -4809,6 +4915,35 @@ \l__tblr_table_lastfoot_box { \UseTblrTemplate { lastfoot } { default } } } +\cs_new_protected:Npn \__tblr_build_tall_table_head_foot: + { + \__tblr_get_table_width: + \__tblr_build_table_head_aux:Nn \l__tblr_table_firsthead_box + { + \__tblr_build_table_label_entry: + \UseTblrTemplate { firsthead } { default } + } + \__tblr_build_table_foot_aux:Nn + \l__tblr_table_lastfoot_box { \UseTblrTemplate { lastfoot } { default } } + } + +\cs_new_protected:Npn \__tblr_build_table_label_entry: + { + \tl_set:Nx \l_tmpa_tl { \InsertTblrText { label } } + \tl_if_eq:NnTF \l_tmpa_tl { none } + { + \SetTblrTemplate { caption-tag }{ empty } + \SetTblrTemplate { caption-sep }{ empty } + } + { + \refstepcounter { table } + \tl_if_empty:NF \l_tmpa_tl { \exp_args:NV \label \l_tmpa_tl } + } + \tl_set:Nx \l_tmpb_tl { \InsertTblrText { entry } } + \tl_if_eq:NnF \l_tmpb_tl { none } + { \UseTblrTemplate { caption-lot } { default } } + } + \cs_new_protected:Npn \__tblr_build_table_head_aux:Nn #1 #2 { \vbox_set:Nn #1 @@ -4835,14 +4970,27 @@ { \tl_if_eq:enTF { \__tblr_spec_item:nn { outer } { long } } { true } { \__tblr_build_long_table:e { \__tblr_spec_item:nn { outer } { halign } } } - { \__tblr_build_short_table:e { \__tblr_spec_item:nn { outer } { valign } } } + { + \tl_if_eq:enTF { \__tblr_spec_item:nn { outer } { tall } } { true } + { + \__tblr_build_tall_table:e + { \__tblr_spec_item:nn { outer } { valign } } + } + { + \__tblr_build_short_table:e + { \__tblr_spec_item:nn { outer } { valign } } + } + } } \dim_new:N \l__tblr_remain_height_dim -\tl_new:N \l__tblr_long_from_tl -\tl_new:N \l__tblr_long_to_tl +\int_new:N \l__tblr_long_from_int +\int_new:N \l__tblr_long_to_int +\int_new:N \l__tblr_curr_i_int +\int_new:N \l__tblr_prev_i_int \int_new:N \l__tblr_table_page_int -\bool_new:N \l__tblr_table_page_break_bool +\bool_new:N \l__tblr_page_break_curr_bool +\bool_new:N \l__tblr_page_break_prev_bool %% #1: table alignment %% For long table, we need to leave hmode first to get correct \pagetotal @@ -4862,37 +5010,29 @@ \hrule height ~ 0pt \LogTblrTracing { page } \int_set:Nn \l__tblr_table_page_int {1} - \refstepcounter { table } \__tblr_build_head_foot: \dim_set:Nn \l__tblr_remain_height_dim { \pagegoal - \pagetotal - \l__tblr_row_head_foot_dim } - \tl_set:Nx \l__tblr_long_from_tl { \int_eval:n { \l__tblr_row_head_tl + 1 } } - \tl_set:Nx \l__tblr_long_to_tl - { \int_eval:n { \c@rowcount - ( \l__tblr_row_foot_tl + 0 ) } } - \int_step_variable:nnNn - { \l__tblr_long_from_tl } { \l__tblr_long_to_tl } \l__tblr_i_tl - { - \dim_set:Nn \l_tmpa_dim - { - \__tblr_data_item:nen { row } { \l__tblr_i_tl } { abovesep } - + - \__tblr_data_item:nen { row } { \l__tblr_i_tl } { @row-height } - + - \__tblr_data_item:nen { row } { \l__tblr_i_tl } { belowsep } - + - \__tblr_spec_item:ne { hline } - { [ \int_eval:n { \l__tblr_i_tl + 1} ] / @hline-height } - } + \int_set:Nn \l__tblr_long_from_int { \l__tblr_row_head_tl + 1 } + \int_set:Nn \l__tblr_long_to_int { \c@rowcount - ( \l__tblr_row_foot_tl + 0 ) } + \int_set:Nn \l__tblr_curr_i_int { \l__tblr_long_from_int - 1 } + \int_do_while:nNnn { \l__tblr_curr_i_int } < { \l__tblr_long_to_int } + { + \int_set_eq:NN \l__tblr_prev_i_int \l__tblr_curr_i_int + \__tblr_get_next_table_rows:NNNN + \l__tblr_long_to_int \l__tblr_curr_i_int + \l_tmpa_dim \l__tblr_page_break_curr_bool \__tblr_check_table_page_break:NNN - \l__tblr_remain_height_dim \l_tmpa_dim \l__tblr_table_page_break_bool - \bool_if:NTF \l__tblr_table_page_break_bool + \l__tblr_remain_height_dim \l_tmpa_dim \l__tblr_page_break_prev_bool + \bool_if:NTF \l__tblr_page_break_prev_bool { - \__tblr_do_if_tracing:nn { page } { \tl_log:N \l__tblr_i_tl } - \int_compare:nNnT - { \l__tblr_i_tl - \l__tblr_long_from_tl } > {1} + \__tblr_do_if_tracing:nn { page } { \int_log:N \l__tblr_curr_i_int } + \int_compare:nNnF + { \l__tblr_prev_i_int - \l__tblr_long_from_int } < {0} { \__tblr_build_page_table:nnx {#1} - { \l__tblr_long_from_tl } { \int_eval:n { \l__tblr_i_tl - 1 } } + { \int_use:N \l__tblr_long_from_int } + { \int_use:N \l__tblr_prev_i_int } \int_incr:N \l__tblr_table_page_int } \newpage @@ -4901,10 +5041,24 @@ \LogTblrTracing { page } \dim_set:Nn \l__tblr_remain_height_dim { \pagegoal - \pagetotal - \l__tblr_row_head_foot_dim - \l_tmpa_dim } - \tl_set_eq:NN \l__tblr_long_from_tl \l__tblr_i_tl + \int_set:Nn \l__tblr_long_from_int { \l__tblr_prev_i_int + 1 } } { - \dim_add:Nn \l__tblr_remain_height_dim { -\l_tmpa_dim } + \bool_if:NTF \l__tblr_page_break_curr_bool + { + \__tblr_build_page_table:nnx {#1} + { \int_use:N \l__tblr_long_from_int } + { \int_use:N \l__tblr_curr_i_int } + \int_incr:N \l__tblr_table_page_int + \newpage + \hbox{}\kern-\topskip\nobreak + \noindent + \LogTblrTracing { page } + \dim_set:Nn \l__tblr_remain_height_dim + { \pagegoal - \pagetotal - \l__tblr_row_head_foot_dim } + \int_set:Nn \l__tblr_long_from_int { \l__tblr_curr_i_int + 1 } + } + { \dim_add:Nn \l__tblr_remain_height_dim { -\l_tmpa_dim } } } } \int_compare:nNnTF { \l__tblr_table_page_int } = {1} @@ -4916,13 +5070,49 @@ \box_set_eq:NN \l__tblr_table_head_box \l__tblr_table_lasthead_box \box_set_eq:NN \l__tblr_table_foot_box \l__tblr_table_lastfoot_box } - \__tblr_build_page_table:nnn - {#1} { \l__tblr_long_from_tl } { \l__tblr_long_to_tl } + \__tblr_build_page_table:nnn {#1} + { \int_use:N \l__tblr_long_from_int } { \int_use:N \l__tblr_long_to_int } \skip_vertical:n { \__tblr_spec_item:nn { outer } { postsep } } \hrule height ~ 0pt } \cs_generate_variant:Nn \__tblr_build_long_table:n { e } +%% #1: int with index of the last row; #2: int with index of current row; +%% #3: row dimension; #4: break page or not. +\cs_new_protected:Npn \__tblr_get_next_table_rows:NNNN #1 #2 #3 #4 + { + \bool_set_true:N \l_tmpa_bool + \dim_zero:N #3 + \bool_set_false:N #4 + \bool_while_do:Nn \l_tmpa_bool + { + \int_incr:N #2 + \dim_add:Nn #3 + { + \__tblr_data_item:nen { row } { \int_use:N #2 } { abovesep } + + + \__tblr_data_item:nen { row } { \int_use:N #2 } { @row-height } + + + \__tblr_data_item:nen { row } { \int_use:N #2 } { belowsep } + + + \__tblr_spec_item:ne { hline } + { [ \int_eval:n { #2 + 1 } ] / @hline-height } + } + \int_compare:nNnTF {#2} < {#1} + { + \tl_set:Nx \l__tblr_b_tl + { \__tblr_data_item:nen { row } { \int_eval:n { #2 + 1 } } { break } } + \int_compare:nNnTF { \l__tblr_b_tl } < { 0 } + { \bool_set_true:N \l_tmpa_bool } + { + \bool_set_false:N \l_tmpa_bool + \int_compare:nNnT { \l__tblr_b_tl } > { 0 } { \bool_set_true:N #4 } + } + } + { \bool_set_false:N \l_tmpa_bool } + } + } + \box_new:N \l__tblr_table_head_box \box_new:N \l__tblr_table_foot_box \dim_new:N \l__tblr_table_head_foot_dim @@ -5000,6 +5190,28 @@ } %% #1: table alignment +%% For tall table, we need to leave vmode first. +%% Since there may be \centering in table environment, +%% We use \raggedright to reset alignement for table head/foot. +\cs_new_protected:Npn \__tblr_build_tall_table:n #1 + { + \mode_leave_vertical: + \raggedright + \__tblr_build_tall_table_head_foot: + \__tblr_build_one_table:nn {1} {\c@rowcount} + \vbox_set:Nn \l__tblr_table_box + { + \box_use:N \l__tblr_table_firsthead_box + \hrule height ~ 0pt + \box_use:N \l__tblr_table_box + \hrule height ~ 0pt + \box_use:N \l__tblr_table_lastfoot_box + } + \__tblr_valign_whole:Nn \l__tblr_table_box #1 + } +\cs_generate_variant:Nn \__tblr_build_tall_table:n { e } + +%% #1: table alignment %% For short table, we need to leave vmode first \cs_new_protected:Npn \__tblr_build_short_table:n #1 { @@ -5886,7 +6098,8 @@ \NewTblrLibrary { siunitx } { \RequirePackage { siunitx } - \NewColumnType { S } [1] [] { Q[si = {##1}] } + \NewColumnType { S } [1] [] { Q[si = {##1}, c] } + \NewColumnType { s } [1] [] { Q[si = {##1}, c, cmd = \TblrUnit] } \__tblr_data_new_key:nnn { cell } { si } { str } \keys_define:nn { tblr-column } { @@ -5895,12 +6108,20 @@ \cs_new_protected:Npn \__tblr_siunitx_setcolumn:n ##1 { \__tblr_column_gput_cell:nn { si } {##1} - \__tblr_process_text_for_every_column_cell:n { \__tblr_siunitx_tablenum:n } + \__tblr_process_text_for_every_column_cell:n { \TblrNum } + } + \NewDocumentCommand \TblrNum { m } + { + \__tblr_siunitx_process:Nn \tablenum {##1} + } + \NewDocumentCommand \TblrUnit { m } + { + \__tblr_siunitx_process:Nn \si {##1} } - \cs_new_protected:Npn \__tblr_siunitx_tablenum:n ##1 + \cs_new_protected:Npn \__tblr_siunitx_process:Nn ##1 ##2 { - \tl_if_head_is_group:nTF {##1} - { ##1 } + \tl_if_head_is_group:nTF {##2} + { ##2 } { \group_begin: \tl_set:Nx \l_tmpa_tl @@ -5909,7 +6130,7 @@ { \int_use:N \c@rownum } { \int_use:N \c@colnum } { si } } \exp_args:NV \sisetup \l_tmpa_tl - \tablenum {##1} + ##1 {##2} \group_end: } } |