diff options
author | Karl Berry <karl@freefriends.org> | 2022-11-01 19:52:35 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-11-01 19:52:35 +0000 |
commit | 820f14d57cd6b67d5793e43d5d1e4866a51ffaa7 (patch) | |
tree | 6d4c7796d9e0324a932ed42dd622fbb27e2342d4 /Master/texmf-dist/tex | |
parent | c9b719f44bd18c2bc6f36381664beeaef8e9ea59 (diff) |
tabularray (1nov22)
git-svn-id: svn://tug.org/texlive/trunk@64891 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/tabularray/tabularray.sty | 276 |
1 files changed, 193 insertions, 83 deletions
diff --git a/Master/texmf-dist/tex/latex/tabularray/tabularray.sty b/Master/texmf-dist/tex/latex/tabularray/tabularray.sty index ba257a42689..9d90f1f9266 100644 --- a/Master/texmf-dist/tex/latex/tabularray/tabularray.sty +++ b/Master/texmf-dist/tex/latex/tabularray/tabularray.sty @@ -18,7 +18,7 @@ \DeclareCurrentRelease{}{2022-01-01} \RequirePackage{expl3} -\ProvidesExplPackage{tabularray}{2022-07-01}{2022C} +\ProvidesExplPackage{tabularray}{2022-11-01}{2022D} {Typeset tabulars and arrays with LaTeX3} %% \IfFormatAtLeastTF, xparse and lthooks are added in LaTeX 2020-10-01 @@ -363,13 +363,13 @@ \int_gincr:c { g__tblr_data_#1_key_count_int } \tl_const:ce { - g__tblr_data_#1_key_name_ + c__tblr_data_#1_key_name_ \int_use:c { g__tblr_data_#1_key_count_int } _tl } { #2 } - \tl_const:ce { g__tblr_data_#1_key_number_#2_tl } + \tl_const:ce { c__tblr_data_#1_key_number_#2_tl } { \int_use:c { g__tblr_data_#1_key_count_int } } - \tl_const:cn { g__tblr_data_#1_key_type_#2_tl } {#3} + \tl_const:cn { c__tblr_data_#1_key_type_#2_tl } {#3} } \int_new:N \g__tblr_data_row_key_count_int @@ -406,18 +406,18 @@ \__tblr_data_new_key:nnn { cell } { @cell-height } { dim } \__tblr_data_new_key:nnn { cell } { @cell-depth } { dim } -\clist_const:Nn \g__tblr_data_clist { row, column, cell } -\tl_const:Nn \g__tblr_data_row_count_tl { \c@rowcount } -\tl_const:Nn \g__tblr_data_column_count_tl { \c@colcount } -\tl_const:Nn \g__tblr_data_cell_count_tl { \c@rowcount * \c@colcount } -\tl_const:Nn \g__tblr_data_row_index_number_tl {1} -\tl_const:Nn \g__tblr_data_column_index_number_tl {1} -\tl_const:Nn \g__tblr_data_cell_index_number_tl {2} +\clist_const:Nn \c__tblr_data_clist { row, column, cell } +\tl_const:Nn \c__tblr_data_row_count_tl { \c@rowcount } +\tl_const:Nn \c__tblr_data_column_count_tl { \c@colcount } +\tl_const:Nn \c__tblr_data_cell_count_tl { \c@rowcount * \c@colcount } +\tl_const:Nn \c__tblr_data_row_index_number_tl {1} +\tl_const:Nn \c__tblr_data_column_index_number_tl {1} +\tl_const:Nn \c__tblr_data_cell_index_number_tl {2} \int_new:N \g__tblr_array_int \cs_new_protected:Npn \__tblr_init_table_data: { - \clist_map_function:NN \g__tblr_data_clist \__tblr_init_one_data:n + \clist_map_function:NN \c__tblr_data_clist \__tblr_init_one_data:n } \cs_new_protected:Npn \__tblr_init_one_data:n #1 @@ -426,7 +426,7 @@ \intarray_new:cn { g__tblr_#1_ \int_use:N \g__tblr_array_int _intarray } { \int_use:c { g__tblr_data_#1_key_count_int } - * \tl_use:c { g__tblr_data_#1_count_tl } + * \tl_use:c { c__tblr_data_#1_count_tl } } \cs_set_eq:cc { g__tblr_#1_ \int_use:N \g_tblr_level_int _intarray } { g__tblr_#1_ \int_use:N \g__tblr_array_int _intarray } @@ -437,7 +437,7 @@ \cs_new:Npn \__tblr_data_key_to_int:nnn #1 #2 #3 { ( #2 - 1 ) * \int_use:c { g__tblr_data_#1_key_count_int } - + \tl_use:c { g__tblr_data_#1_key_number_#3_tl } + + \tl_use:c { c__tblr_data_#1_key_number_#3_tl } } %% #1: data name; #2: data index 1; #3: data index 2; #4: key name @@ -445,7 +445,7 @@ { ( #2 - 1 ) * \c@colcount * \int_use:c { g__tblr_data_#1_key_count_int } + ( #3 - 1 ) * \int_use:c { g__tblr_data_#1_key_count_int } - + \tl_use:c { g__tblr_data_#1_key_number_#4_tl } + + \tl_use:c { c__tblr_data_#1_key_number_#4_tl } } \int_new:N \l__tblr_key_count_int @@ -472,7 +472,7 @@ { \int_set_eq:NN \l__tblr_key_remainder_int \l__tblr_key_count_int } \tl_set:Nx #3 { \int_use:N \l__tblr_key_quotient_int } \tl_set_eq:Nc #4 - { g__tblr_data_#1_key_name_ \int_use:N \l__tblr_key_remainder_int _tl } + { c__tblr_data_#1_key_name_ \int_use:N \l__tblr_key_remainder_int _tl } } %% #1: data name; #2: array position; @@ -494,7 +494,7 @@ \int_compare:nNnT { \l__tblr_key_remainder_int } = { 0 } { \int_set_eq:NN \l__tblr_key_remainder_int \l__tblr_key_count_int } \tl_set_eq:Nc #5 - { g__tblr_data_#1_key_name_ \int_use:N \l__tblr_key_remainder_int _tl } + { c__tblr_data_#1_key_name_ \int_use:N \l__tblr_key_remainder_int _tl } \int_set:Nn \l__tblr_key_quotient_two_int { \int_div_truncate:nn @@ -518,7 +518,7 @@ \cs_new_protected:Npn \__tblr_data_int_from_value:nnn #1 #2 #3 { \cs:w - __tblr_data_int_from_ \tl_use:c { g__tblr_data_#1_key_type_#2_tl } :n + __tblr_data_int_from_ \tl_use:c { c__tblr_data_#1_key_type_#2_tl } :n \cs_end: {#3} } @@ -527,7 +527,7 @@ \cs_new:Npn \__tblr_data_int_to_value:nnn #1 #2 #3 { \cs:w - __tblr_data_int_to_ \tl_use:c { g__tblr_data_#1_key_type_#2_tl } :n + __tblr_data_int_to_ \tl_use:c { c__tblr_data_#1_key_type_#2_tl } :n \cs_end: {#3} } @@ -568,7 +568,7 @@ } \int_new:N \g__tblr_data_str_value_count_int -\tl_set:cn { g__tblr_data_0_to_str_tl } { } +\tl_gclear_new:c { g__tblr_data_0_to_str_tl } \cs_new_protected:Npn \__tblr_data_int_from_str:n #1 { @@ -646,7 +646,7 @@ \cs_new_protected:Npn \__tblr_data_log:n #1 { - \use:c { __tblr_data_log_ \use:c { g__tblr_data_#1_index_number_tl } :n } {#1} + \use:c { __tblr_data_log_ \use:c { c__tblr_data_#1_index_number_tl } :n } {#1} \__tblr_prop_log:n {#1} } @@ -736,7 +736,7 @@ \cs_generate_variant:Nn \__tblr_array_gadd_value:Nnn { cnn } \bool_new:N \g__tblr_use_intarray_bool -\bool_set_true:N \g__tblr_use_intarray_bool +\bool_gset_true:N \g__tblr_use_intarray_bool \AtBeginDocument { @@ -1126,8 +1126,8 @@ %%> \section{Set Hlines and Vlines} %%% -------------------------------------------------------- -\tl_set:Nn \@tblr@dash { dash } -\tl_set:Nn \@tblr@text { text } +\tl_const:Nn \@tblr@dash { dash } +\tl_const:Nn \@tblr@text { text } \regex_const:Nn \c__tblr_is_color_key_regex { ^[A-Za-z] } @@ -2580,7 +2580,8 @@ %% #1: env name; #2: specifications \NewDocumentCommand \SetTblrInner { O{tblr} m } { - \tl_put_right:cn { l__tblr_default_ #1 _inner_tl } { , #2 } + \clist_map_inline:nn {#1} + { \tl_put_right:cn { l__tblr_default_ ##1 _inner_tl } { , #2 } } \ignorespaces } \cs_new_eq:NN \SetTblrDefault \SetTblrInner @@ -2588,7 +2589,8 @@ %% #1: env name; #2: specifications \NewDocumentCommand \SetTblrOuter { O{tblr} m } { - \tl_put_right:cn { l__tblr_default_ #1 _outer_tl } { , #2 } + \clist_map_inline:nn {#1} + { \tl_put_right:cn { l__tblr_default_ ##1 _outer_tl } { , #2 } } \ignorespaces } @@ -3032,7 +3034,7 @@ colspec, rowspec, column, row, cell, hline, vline, hborder, vborder, width, rowhead, rowfoot, columns, rows, cells, hlines, vlines, % hborders, vborders, leftsep, rightsep, colsep, abovesep, belowsep, rowsep, rulesep, - baseline, hspan, vspan, stretch, verb, + baseline, hspan, vspan, stretch, verb, delimiter } \keys_define:nn { tblr } @@ -3059,6 +3061,7 @@ rulesep .code:n = \__tblr_keys_gput:nn { rulesep } {#1}, rowhead .code:n = \__tblr_keys_gput:nn { rowhead } {#1}, rowfoot .code:n = \__tblr_keys_gput:nn { rowfoot } {#1}, + delimiter .code:n = \__tblr_set_delimiter:n {#1}, baseline .code:n = \__tblr_outer_gput_spec:nn { baseline } {#1}, unknown .code:n = \__tblr_table_special_key:Vn \l_keys_key_str {#1}, } @@ -3099,6 +3102,17 @@ } \cs_generate_variant:Nn \__tblr_keys_gput:nn { nx } +\keys_define:nn { tblr-delimiter } + { + left .code:n = \__tblr_keys_gput:nn { delim-left } { \left #1 }, + right .code:n = \__tblr_keys_gput:nn { delim-right } { \right #1 } + } + +\cs_new_protected:Npn \__tblr_set_delimiter:n #1 + { + \keys_set:nn { tblr-delimiter } {#1} + } + %%% -------------------------------------------------------- %%> \section{Initialize and Parse Table Outer Specifications} %%% -------------------------------------------------------- @@ -4556,7 +4570,7 @@ { \prop_put:Nnn \l__tblr_element_styles_prop {#1} {#2} } -\cs_generate_variant:Nn \__tblr_style_put:nn { nV, ne, en } +\cs_generate_variant:Nn \__tblr_style_put:nn { nV, ne, en, eV } \cs_new:Npn \__tblr_style_item:n #1 { @@ -4599,6 +4613,7 @@ l .meta:n = { halign = l }, c .meta:n = { halign = c }, r .meta:n = { halign = r }, + j .meta:n = { halign = j }, fg .code:n = \__tblr_element_gput_style:nn { fg } {#1}, font .code:n = \__tblr_element_gput_style:nn { font } {#1}, hang .code:n = \__tblr_element_gput_style:nn { hang } {#1}, @@ -4620,7 +4635,7 @@ \tl_set_rescan:Nnn \l__tblr_f_tl {} {#1} \tl_if_head_eq_catcode:VNTF \l__tblr_f_tl \scan_stop: { - \__tblr_style_put:en { \l__tblr_element_name_tl / font } \l__tblr_f_tl + \__tblr_style_put:eV { \l__tblr_element_name_tl / font } \l__tblr_f_tl } { \__tblr_style_put:en { \l__tblr_element_name_tl / #1 } {#2} @@ -4782,7 +4797,17 @@ %%> \section{Table Continuation Templates} %%% -------------------------------------------------------- -\DefTblrTemplate { contfoot-text } { normal } { Continued ~ on ~ next ~ page } +\tl_if_exist:NF \tblrcontfootname + { + \tl_set:Nn \tblrcontfootname { Continued ~ on ~ next ~ page } + } + +\tl_if_exist:NF \tblrcontheadname + { + \tl_set:Nn \tblrcontheadname { ( Continued ) } + } + +\DefTblrTemplate { contfoot-text } { normal } { \tblrcontfootname } \SetTblrTemplate { contfoot-text } { normal } \DefTblrTemplate { contfoot } { empty } { } @@ -4806,7 +4831,7 @@ } \SetTblrTemplate { contfoot } { normal } -\DefTblrTemplate { conthead-text } { normal } { ( Continued ) } +\DefTblrTemplate { conthead-text } { normal } { \tblrcontheadname } \SetTblrTemplate { conthead-text } { normal } \DefTblrTemplate { conthead } { empty } { } @@ -4839,9 +4864,9 @@ \DefTblrTemplate { caption-lot } { empty } { } \DefTblrTemplate { caption-lot } { normal } { - \tl_set:Nx \l__tblr_caption_short_tl { \InsertTblrText { entry } } - \tl_if_empty:NT \l__tblr_caption_short_tl - { \tl_set:Nx \l__tblr_caption_short_tl { \InsertTblrText { caption } } } + \tl_if_empty:NTF \lTblrEntryTl + { \tl_set_eq:NN \l__tblr_caption_short_tl \lTblrCaptionTl } + { \tl_set_eq:NN \l__tblr_caption_short_tl \lTblrEntryTl } \addcontentsline { lot } { table } { \protect\numberline { \thetable } { \l__tblr_caption_short_tl } } } @@ -5362,20 +5387,34 @@ \l__tblr_table_lastfoot_box { \UseTblrTemplate { lastfoot } { default } } } +\tl_new:N \lTblrCaptionTl +\tl_new:N \lTblrEntryTl +\tl_new:N \lTblrLabelTl +\clist_new:N \lTblrRefMoreClist + \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 } + \tl_set:Nx \lTblrCaptionTl { \InsertTblrText { caption } } + \tl_set:Nx \lTblrEntryTl { \InsertTblrText { entry } } + \tl_set:Nx \lTblrLabelTl { \InsertTblrText { label } } + \tl_if_eq:NnTF \lTblrLabelTl { 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_if_empty:NF \lTblrLabelTl + { + \clist_map_inline:Nn \lTblrRefMoreClist + { \ExpTblrTemplate { caption-ref } { ##1 } } + \exp_args:NV \label \lTblrLabelTl + } } - \tl_set:Nx \l_tmpb_tl { \InsertTblrText { entry } } - \tl_if_eq:NnF \l_tmpb_tl { none } + %% We put caption-lot code at last, so that an user can modify \lTblrEntryTl + %% in a caption-label template. For example, an user may want to use + %% short caption in nameref, but at the same time not to add LoT entry. + \tl_if_eq:NnF \lTblrEntryTl { none } { \UseTblrTemplate { caption-lot } { default } } } @@ -5767,9 +5806,16 @@ \regex_const:Nn \c__tblr_is_positive_integer_regex { ^ \d+ $ } \regex_const:Nn \c__tblr_is_negative_integer_regex { ^ - \d+ $ } +\tl_new:N \l__tblr_delim_left_tl +\tl_new:N \l__tblr_delim_right_tl + \cs_new_protected:Npn \__tblr_valign_whole:Nn #1 #2 { \group_begin: + \tl_set:Nx \l__tblr_delim_left_tl + { \__tblr_prop_item:nn { inner } { delim-left } } + \tl_set:Nx \l__tblr_delim_right_tl + { \__tblr_prop_item:nn { inner } { delim-right } } \tl_set:Nn \__tblr_vbox_align_tl {#2} \dim_set:Nn \l__tblr_t_dim { \box_ht:N #1 + \box_dp:N #1 } \tl_case:NnF \__tblr_vbox_align_tl @@ -5805,13 +5851,40 @@ { \__tblr_valign_whole_middle:N #1 } } } - \box_use_drop:N #1 + %% we have done the job when valign is m or c + \box_if_empty:NF #1 { \__tblr_add_delimiters_to_box:N #1 } \group_end: } +%% We use the idea of delarray package to shift table box +%% when there are delimiters around the table +\cs_new_protected:Npn \__tblr_add_delimiters_to_box:N #1 + { + \tl_if_empty:NTF \l__tblr_delim_left_tl + { \box_use_drop:N #1 } + { + \box_move_down:nn + { + ( \box_dp:N #1 - \box_ht:N #1 ) / 2 + + \tex_fontdimen:D 22 \tex_textfont:D 2 + } + { \__tblr_get_vcenter_box:N #1 } + } + } + +\cs_new_protected:Npn \__tblr_get_vcenter_box:N #1 + { + \hbox:n + { + $ \m@th \l__tblr_delim_left_tl + \tex_vcenter:D { \vbox_unpack_drop:N #1 } + \l__tblr_delim_right_tl $ + } + } + \cs_new_protected:Npn \__tblr_valign_whole_middle:N #1 { - \hbox:n { $ \m@th \tex_vcenter:D { \vbox_unpack_drop:N #1 } $ } + \__tblr_get_vcenter_box:N #1 } \cs_new_protected:Npn \__tblr_valign_whole_top:N #1 @@ -6797,66 +6870,65 @@ \NewTblrLibrary { amsmath } { - \RequirePackage { amsmath, environ } + \RequirePackage { amsmath } \NewTblrEnviron { +array } \SetTblrInner[+array]{colsep = 5pt} - \NewEnviron { +matrix } [1] [] { - \begin{+array}[expand = \BODY]{ + \NewDocumentEnvironment { +matrix } { O{} +b } { + \begin{+array}{ column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt}, cells = {c}, ##1 } - \BODY + ##2 \end{+array} - } - \NewEnviron { +bmatrix } [1] [] { - \left[\begin{+array}[expand = \BODY]{ + } { } + \NewDocumentEnvironment { +bmatrix } { O{} +b } { + \begin{+array}{ column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt}, - cells = {c}, ##1 + cells = {c}, delimiter = {left = [, right = ]}, ##1 } - \BODY - \end{+array}\right] - \ignorespacesafterend - } - \NewEnviron { +Bmatrix } [1] [] { - \left\lbrace\begin{+array}[expand = \BODY]{ + ##2 + \end{+array} + } { } + \NewDocumentEnvironment { +Bmatrix } { O{} +b } { + \begin{+array} { column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt}, - cells = {c}, ##1 + cells = {c}, delimiter = {left = \lbrace, right = \rbrace}, ##1 } - \BODY - \end{+array}\right\rbrace - } - \NewEnviron { +pmatrix } [1] [] { - \left(\begin{+array}[expand = \BODY]{ + ##2 + \end{+array} + } { } + \NewDocumentEnvironment { +pmatrix } { O{} +b } { + \begin{+array} { column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt}, - cells = {c}, ##1 + cells = {c}, delimiter = {left = (, right = )}, ##1 } - \BODY - \end{+array}\right) - } - \NewEnviron { +vmatrix } [1] [] { - \left\lvert\begin{+array}[expand = \BODY]{ + ##2 + \end{+array} + } { } + \NewDocumentEnvironment { +vmatrix } { O{} +b } { + \begin{+array} { column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt}, - cells = {c}, ##1 + cells = {c}, delimiter = {left = \lvert, right = \rvert}, ##1 } - \BODY - \end{+array}\right\rvert - } - \NewEnviron { +Vmatrix } [1] [] { - \left\lVert\begin{+array}[expand = \BODY]{ + ##2 + \end{+array} + } { } + \NewDocumentEnvironment { +Vmatrix } { O{} +b } { + \begin{+array} { column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt}, - cells = {c}, ##1 + cells = {c}, delimiter = {left = \lVert, right = \rVert}, ##1 } - \BODY - \end{+array}\right\rVert - } - \NewEnviron { +cases } [1] [] { - \left\lbrace\begin{+array}[expand = \BODY]{ + ##2 + \end{+array} + } { } + \NewDocumentEnvironment { +cases } { O{} +b } { + \begin{+array} { column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt}, - colspec = {ll}, stretch = 1.2, ##1 + colspec = {ll}, stretch = 1.2, delimiter = {left=\lbrace, right=.}, ##1 } - \BODY - \end{+array}\right. - } + ##2 + \end{+array} + } { } } %% Library booktabs and commands \toprule, \midrule, \bottomrule @@ -7070,6 +7142,28 @@ } } +%% Library nameref and its caption-ref template + +\NewTblrLibrary { nameref } + { + \RequirePackage { nameref } + \clist_if_in:NnF \lTblrRefMoreClist { nameref } + { + \clist_put_right:Nn \lTblrRefMoreClist { nameref } + \DefTblrTemplate { caption-ref }{ nameref } + { + \tl_if_eq:NnTF \lTblrEntryTl { none } + { \exp_args:NV \GetTitleString \lTblrCaptionTl } + { + \tl_if_empty:NTF \lTblrEntryTl + { \exp_args:NV \GetTitleString \lTblrCaptionTl } + { \exp_args:NV \GetTitleString \lTblrEntryTl } + } + \tl_set_eq:NN \@currentlabelname \GetTitleStringResult + } + } + } + %% Library siunitx and S columns \NewTblrLibrary { siunitx } @@ -7124,3 +7218,19 @@ \clist_gput_left:Nn \g__tblr_table_known_keys_clist { measure } \keys_define:nn { tblr } { measure .tl_set:N = \l__tblr_inner_spec_measure_tl } } + +%% Library zref and its caption-ref template + +\NewTblrLibrary { zref } + { + \RequirePackage { zref-user } + \clist_if_in:NnF \lTblrRefMoreClist { zref } + { + \clist_put_right:Nn \lTblrRefMoreClist { zref } + \DefTblrTemplate { caption-ref }{ zref } + { + \exp_args:NV \zlabel \lTblrLabelTl + } + } + } + |