diff options
Diffstat (limited to 'macros/latex/contrib/tabularray/tabularray.sty')
-rw-r--r-- | macros/latex/contrib/tabularray/tabularray.sty | 124 |
1 files changed, 91 insertions, 33 deletions
diff --git a/macros/latex/contrib/tabularray/tabularray.sty b/macros/latex/contrib/tabularray/tabularray.sty index 9d90f1f926..5f6b43ebd2 100644 --- a/macros/latex/contrib/tabularray/tabularray.sty +++ b/macros/latex/contrib/tabularray/tabularray.sty @@ -1,9 +1,9 @@ %%% % -*- coding: utf-8 -*- %%% ---------------------------------------------------------------------------- %%% Tabularray: Typeset tabulars and arrays with LaTeX3 -%%% Copyright : 2021-2022 (c) Jianrui Lyu <tolvjr@163.com> +%%% Copyright : 2021-2023 (c) Jianrui Lyu <tolvjr@163.com> %%% Repository: https://github.com/lvjr/tabularray -%%% License : The LaTeX Project Public License 1.3 +%%% License : The LaTeX Project Public License 1.3c %%% ---------------------------------------------------------------------------- %%% -------------------------------------------------------- @@ -18,7 +18,7 @@ \DeclareCurrentRelease{}{2022-01-01} \RequirePackage{expl3} -\ProvidesExplPackage{tabularray}{2022-11-01}{2022D} +\ProvidesExplPackage{tabularray}{2023-03-01}{2023A} {Typeset tabulars and arrays with LaTeX3} %% \IfFormatAtLeastTF, xparse and lthooks are added in LaTeX 2020-10-01 @@ -62,6 +62,27 @@ \cs_set_eq:NN \TblrNewPage \newpage +%% Note that \cs_if_exist:NTF doesn't treat \relax as an existing command. +%% Therefore we define our \__tblr_cs_if_defined:NTF here. +\prg_set_conditional:Npnn \__tblr_cs_if_defined:N #1 { p, T, F, TF } + { + %% \if_cs_exist:N = \ifdefined in eTeX + \if_cs_exist:N #1 + \prg_return_true: + \else: + \prg_return_false: + \fi: + } +\prg_set_conditional:Npnn \__tblr_cs_if_defined:c #1 { p, T, F, TF } + { + %% \if_cs_exist:w = \ifcsname in eTeX + \if_cs_exist:w #1 \cs_end: + \prg_return_true: + \else: + \prg_return_false: + \fi: + } + \cs_generate_variant:Nn \msg_error:nnnn { nnVn } \cs_generate_variant:Nn \prop_item:Nn { Ne, NV } \cs_generate_variant:Nn \prop_put:Nnn { Nxn, Nxx, NxV } @@ -919,9 +940,9 @@ { \clist_put_right:Nn \l_tblr_childs_clist {##1} } } -\regex_const:Nn \c__tblr_child_name_regex { ^ [X-Z] $ } +\regex_const:Nn \c__tblr_child_name_regex { ^ [U-Z] $ } -%% Convert X, Y, Z to the indexes of the last three childs, respectively +%% Convert U, V, W, X, Y, Z to the indexes of the last six childs, respectively \cs_new_protected_nopar:Npn \__tblr_child_name_to_index:nN #1 #2 { \regex_match:NnTF \c__tblr_child_name_regex {#1} @@ -944,7 +965,7 @@ \clist_new:N \g__tblr_table_commands_clist \msg_new:nnn { tabularray } { defined-table-command } - { Table ~ commnad ~ #1 has ~ been ~ defined! } + { Table ~ command ~ #1 already ~ defined! } \NewDocumentCommand \NewTableCommand { m O{0} o m } { @@ -957,7 +978,8 @@ \__tblr_make_xparse_arg_spec:nnN { #2 } { #3 } \l__tblr_a_tl \exp_args:NcV \NewDocumentCommand { __tblr_table_command_ \cs_to_str:N #1 :w } \l__tblr_a_tl { #4 } - \cs_if_exist:NTF #1 + %% we can not use \cs_if_exist:NTF here (see issue #328) + \__tblr_cs_if_defined:NTF #1 { \cs_set_eq:cN { __tblr_table_command_ \cs_to_str:N #1 _saved:w } #1 } @@ -1004,6 +1026,9 @@ \int_set:Nn \c@colnum {#2} } +%% Add \empty as a table command so that users can write \\\empty\hline (see #328) +\NewTableCommand\empty{} + %% 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. @@ -1029,7 +1054,7 @@ \clist_new:N \g__tblr_content_commands_clist \msg_new:nnn { tabularray } { defined-content-command } - { Content ~ commnad ~ #1 has ~ been ~ defined! } + { Content ~ command ~ #1 already ~ defined! } \NewDocumentCommand \NewContentCommand { m O{0} o m } { @@ -2631,10 +2656,13 @@ \group_align_safe_end: } +\bool_new:N \lTblrMeasuringBool + %% Read, split and build the table \cs_new_protected:Npn \__tblr_builder:nnn #1 #2 #3 { \int_gincr:N \g_tblr_level_int + \bool_set_true:N \lTblrMeasuringBool \__tblr_clear_prop_lists: \__tblr_clear_spec_lists: \LogTblrTracing { step = init ~ table ~ outer ~ spec} @@ -2660,6 +2688,7 @@ \LogTblrTracing { step = calculate ~ cell ~ and ~ line ~ sizes} \__tblr_enable_content_commands: \__tblr_calc_cell_and_line_sizes: + \bool_set_false:N \lTblrMeasuringBool \LogTblrTracing { step = build ~ the ~ whole ~ table} \__tblr_build_whole: \int_gdecr:N \g_tblr_level_int @@ -4831,6 +4860,10 @@ } \SetTblrTemplate { contfoot } { normal } +\DefTblrTemplate { conthead-pre } { empty } { } +\DefTblrTemplate { conthead-pre } { normal } { \space } +\SetTblrTemplate { conthead-pre } { normal } + \DefTblrTemplate { conthead-text } { normal } { \tblrcontheadname } \SetTblrTemplate { conthead-text } { normal } @@ -4962,7 +4995,7 @@ \UseTblrTemplate { caption-tag } { default } \UseTblrTemplate { caption-sep } { default } \UseTblrTemplate { caption-text } { default } - \space + \UseTblrTemplate { conthead-pre } { default } \UseTblrTemplate { conthead-text } { default } } \dim_compare:nNnTF { \box_wd:N \l__tblr_caption_box } > { \hsize } @@ -4984,7 +5017,7 @@ \UseTblrTemplate { caption-tag } { default } \UseTblrTemplate { caption-sep } { default } \UseTblrTemplate { caption-text } { default } - \space + \UseTblrTemplate { conthead-pre } { default } \UseTblrTemplate { conthead-text } { default } } \dim_compare:nNnTF { \box_wd:N \l__tblr_caption_box } > { \hsize } @@ -5018,7 +5051,7 @@ \UseTblrTemplate { caption-tag } { default } \UseTblrTemplate { caption-sep } { default } \UseTblrTemplate { caption-text } { default } - \space + \UseTblrTemplate { conthead-pre } { default } \UseTblrTemplate { conthead-text } { default } \par } @@ -5348,6 +5381,9 @@ \cs_new_protected:Npn \__tblr_build_table_head_foot: { \__tblr_get_table_width: + % make each of \lTblrCaptionTl, \lTblrEntryTl, \lTblrLabelTl and the + % three corresponding booleans available in all head-foot templates + \__tblr_set_table_label_entry: \__tblr_build_table_head_aux:Nn \l__tblr_table_firsthead_box { \__tblr_build_table_label_entry: @@ -5375,9 +5411,37 @@ } } +\bool_new:N \l__tblr_table_no_title_bool +\bool_new:N \l__tblr_table_no_entry_bool +\bool_new:N \l__tblr_table_no_label_bool +\tl_const:Nn \c_tblr_none_tl { none } + +\cs_new_protected:Npn \__tblr_set_table_label_entry: + { + \tl_set:Nx \lTblrCaptionTl { \InsertTblrText { caption } } + \tl_set:Nx \lTblrEntryTl { \InsertTblrText { entry } } + \tl_set:Nx \lTblrLabelTl { \InsertTblrText { label } } + \bool_set:Nn \l__tblr_table_no_title_bool + { \tl_if_empty_p:N \lTblrCaptionTl } + \bool_set:Nn \l__tblr_table_no_entry_bool + { \tl_if_eq_p:NN \lTblrEntryTl \c_tblr_none_tl } + \bool_set:Nn \l__tblr_table_no_label_bool + { \tl_if_eq_p:NN \lTblrLabelTl \c_tblr_none_tl } + \bool_if:NT \l__tblr_table_no_title_bool + { + \SetTblrTemplate { conthead-pre } { empty } + } + \bool_if:NT \l__tblr_table_no_label_bool + { + \SetTblrTemplate { caption-tag }{ empty } + \SetTblrTemplate { caption-sep }{ empty } + } + } + \cs_new_protected:Npn \__tblr_build_tall_table_head_foot: { \__tblr_get_table_width: + \__tblr_set_table_label_entry: \__tblr_build_table_head_aux:Nn \l__tblr_table_firsthead_box { \__tblr_build_table_label_entry: @@ -5394,14 +5458,7 @@ \cs_new_protected:Npn \__tblr_build_table_label_entry: { - \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 } - } + \bool_if:NF \l__tblr_table_no_label_bool { \refstepcounter { table } \tl_if_empty:NF \lTblrLabelTl @@ -5411,10 +5468,10 @@ \exp_args:NV \label \lTblrLabelTl } } - %% 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 + %% We put caption-lot code at last, so that a user can modify \lTblrEntryTl + %% in a caption-label template. For example, a 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 } + \bool_if:NF \l__tblr_table_no_entry_bool { \UseTblrTemplate { caption-lot } { default } } } @@ -6340,12 +6397,6 @@ { \tl_set:Nn \l__tblr_vline_abovepos_tl {0} % default position } - \tl_set:Nx \l__tblr_vline_belowpos_tl - { \__tblr_spec_item:ne { vline } { [#1][#2](#3) / belowpos } } - \tl_if_empty:NT \l__tblr_vline_belowpos_tl - { - \tl_set:Nn \l__tblr_vline_belowpos_tl {0} % default position - } \fp_compare:nNnF { \l__tblr_vline_abovepos_tl } = {0} { \dim_set:Nn \l_tmpa_dim @@ -6361,8 +6412,10 @@ } } %% To join two vline segment above and below a cline, - %% we choose to extend every vline downwards a little (#55). - \fp_compare:nNnTF { \l__tblr_vline_belowpos_tl } = {0} + %% we choose to extend every vline downwards a little (#55, #272). + \tl_set:Nx \l__tblr_vline_belowpos_tl + { \__tblr_spec_item:ne { vline } { [#1][#2](#3) / belowpos } } + \tl_if_empty:NTF \l__tblr_vline_belowpos_tl { \dim_set:Nn \l__tblr_vline_belowskip_dim { @@ -7082,11 +7135,16 @@ { \tl_set:Nx \l__tblr_evaluate_tl { \__tblr_spec_item:nn { outer } { evaluate } } - \tl_set:Nx \l__tblr_evaluate_tl { \tl_head:N \l__tblr_evaluate_tl } \tl_if_empty:NF \l__tblr_evaluate_tl { - \exp_last_unbraced:NNV - \__tblr_evaluate_table_body:NN \l__tblr_body_tl \l__tblr_evaluate_tl + \tl_if_eq:NnTF \l__tblr_evaluate_tl { all } + { + \tlSet \l__tblr_body_tl { \evalWhole {\expValue \l__tblr_body_tl} } + } + { + \exp_last_unbraced:NNV + \__tblr_evaluate_table_body:NN \l__tblr_body_tl \l__tblr_evaluate_tl + } } } %% Evaluate every occurrence of the specified function |