summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-06-01 20:08:22 +0000
committerKarl Berry <karl@freefriends.org>2022-06-01 20:08:22 +0000
commit406f893ecc900db02d81719fea8fe374668d8994 (patch)
treee4f613b3c354355516843462698e559f68161a23 /Master/texmf-dist/tex/latex
parent8d14dc414fc83144e865139e86b269f970bd183a (diff)
tabularray (1jun22)
git-svn-id: svn://tug.org/texlive/trunk@63468 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r--Master/texmf-dist/tex/latex/tabularray/tabularray.sty174
1 files changed, 133 insertions, 41 deletions
diff --git a/Master/texmf-dist/tex/latex/tabularray/tabularray.sty b/Master/texmf-dist/tex/latex/tabularray/tabularray.sty
index 5ec77339f3b..bb8d02f6c40 100644
--- a/Master/texmf-dist/tex/latex/tabularray/tabularray.sty
+++ b/Master/texmf-dist/tex/latex/tabularray/tabularray.sty
@@ -12,11 +12,11 @@
%% \DeclareRelease and \DeclareCurrentRelease are added in LaTeX 2018-04-01
\NeedsTeXFormat{LaTeX2e}[2018-04-01]
-\DeclareRelease{v2021}{}{tabularray-2021.sty}
+\DeclareRelease{v2021}{2021-01-01}{tabularray-2021.sty}
\DeclareCurrentRelease{}{2022-01-01}
\RequirePackage{expl3}
-\ProvidesExplPackage{tabularray}{2022-03-01}{2022A}
+\ProvidesExplPackage{tabularray}{2022-06-01}{2022B}
{Typeset tabulars and arrays with LaTeX3}
%% \IfFormatAtLeastTF, xparse and lthooks are added in LaTeX 2020-10-01
@@ -2594,7 +2594,6 @@
\tl_new:c { l__tblr_default_ #1 _inner_tl }
\tl_new:c { l__tblr_default_ #1 _outer_tl }
\tl_set_eq:cN { l__tblr_default_ #1 _outer_tl } \l__tblr_initial_tblr_outer_tl
- \ignorespaces
}
%% Create tblr and longtblr environments
@@ -2608,14 +2607,18 @@
\bool_new:N \l__tblr_math_mode_bool
%% Main environment code
+%% We need to add \group_align_safe_begin: and \group_align_safe_end:
+%% to make tabularray correctly nest in align environment (see issue #143)
\cs_new_protected:Npn \__tblr_environ_code:nnnn #1 #2 #3 #4
{
+ \group_align_safe_begin:
\int_gincr:N \g__tblr_table_count_int
\tl_set:Nn \l__tblr_env_name_tl {#1}
\mode_if_math:TF
{ \bool_set_true:N \l__tblr_math_mode_bool }
{ \bool_set_false:N \l__tblr_math_mode_bool }
\__tblr_builder:nnn {#2} {#3} {#4}
+ \group_align_safe_end:
}
%% Read, split and build the table
@@ -2643,6 +2646,7 @@
\LogTblrTracing { step = execute ~ table ~ commands}
\__tblr_execute_table_commands:
\__tblr_disable_table_commands:
+ \__tblr_functional_calculation:
\LogTblrTracing { step = calculate ~ cell ~ and ~ line ~ sizes}
\__tblr_enable_content_commands:
\__tblr_calc_cell_and_line_sizes:
@@ -2686,39 +2690,52 @@
}
\tl_new:N \l__tblr_body_tl
-\tl_new:N \l__tblr_expand_tl
\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 }
+ \tl_set:Nn \l__tblr_body_tl {#1}
+ \tblr_modify_table_body:
\int_zero:N \c@rowcount
\int_zero:N \c@colcount
\__tblr_split_table_to_lines:NN \l__tblr_body_tl \l__tblr_lines_seq
\__tblr_split_lines_to_cells:N \l__tblr_lines_seq
}
+\tl_new:N \l__tblr_expand_tl
+
+\cs_set_eq:NN \__tblr_hook_split_before: \prg_do_nothing:
+
+\cs_new_protected:Npn \tblr_modify_table_body:
+ {
+ \__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
+ {
+ \exp_last_unbraced:NNV
+ \__tblr_expand_table_body:NN \l__tblr_body_tl \l__tblr_expand_tl
+ }
+ }
+
+%% Expand every occurrence of the specified macro once
+%% #1: tl with table content; #2: macro to be expanded
+\cs_new_protected:Npn \__tblr_expand_table_body:NN #1 #2
+ {
+ \tl_set_eq:NN \l_tmpa_tl #1
+ \tl_clear:N #1
+ \cs_set_protected:Npn \__tblr_expand_table_body_aux:w ##1 #2
+ {
+ \tl_put_right:Nn #1 {##1}
+ \peek_meaning:NTF \q_stop
+ { \use_none:n }
+ { \exp_last_unbraced:NV \__tblr_expand_table_body_aux:w #2 }
+ }
+ \exp_last_unbraced:NV \__tblr_expand_table_body_aux:w \l_tmpa_tl #2 \q_stop
+ }
+
%% Split table content to a sequence of lines
%% #1: tl with table contents, #2: resulting sequence of lines
\cs_new_protected:Npn \__tblr_split_table_to_lines:NN #1 #2
@@ -5231,14 +5248,18 @@
%% \l__tblr_row_head_tl and \l__tblr_row_foot_tl may be empty
\tl_set:Nx \l__tblr_row_head_tl { \__tblr_prop_item:ne { inner } { rowhead } }
\int_compare:nNnTF { \l__tblr_row_head_tl + 0 } > { 0 }
- { \__tblr_build_one_table:nn {1} { \l__tblr_row_head_tl } }
+ {
+ \__tblr_build_one_table:nnNN {1} { \l__tblr_row_head_tl }
+ \c_true_bool \c_true_bool
+ }
{ \__tblr_build_one_hline:n {1} }
\box_set_eq:NN \l__tblr_row_head_box \l__tblr_table_box
\tl_set:Nx \l__tblr_row_foot_tl { \__tblr_prop_item:ne { inner } { rowfoot } }
\int_compare:nNnTF { \l__tblr_row_foot_tl + 0 } > { 0 }
{
- \__tblr_build_one_table:nn
+ \__tblr_build_one_table:nnNN
{ \c@rowcount - \l__tblr_row_foot_tl + 1 } { \c@rowcount }
+ \c_true_bool \c_true_bool
}
{ \__tblr_build_one_hline:n { \int_eval:n { \c@rowcount + 1 } } }
\box_set_eq:NN \l__tblr_row_foot_box \l__tblr_table_box
@@ -5401,6 +5422,7 @@
{
\LogTblrTracing { page }
\par
+ \skip_zero:N \parskip % see issue #203
\LogTblrTracing { page }
\dim_compare:nNnTF { \pagegoal } = { \maxdimen }
{ \hbox{}\kern-\topskip\nobreak }
@@ -5578,9 +5600,7 @@
%% #1: table alignment; #2: row from; #3: row to
\cs_new_protected:Npn \__tblr_build_page_table:nnn #1 #2 #3
{
- \bool_set_false:N \l__tblr_build_first_hline_bool
- \bool_set_false:N \l__tblr_build_last_hline_bool
- \__tblr_build_one_table:nn {#2} {#3}
+ \__tblr_build_one_table:nnNN {#2} {#3} \c_false_bool \c_false_bool
\vbox_set:Nn \l__tblr_table_box
{
\box_use:N \l__tblr_table_head_box
@@ -5628,7 +5648,7 @@
{
\mode_leave_vertical:
\__tblr_build_tall_table_head_foot:
- \__tblr_build_one_table:nn {1} {\c@rowcount}
+ \__tblr_build_one_table:nnNN {1} {\c@rowcount} \c_true_bool \c_true_bool
\vbox_set:Nn \l__tblr_table_box
{
\box_use:N \l__tblr_table_firsthead_box
@@ -5646,23 +5666,20 @@
\cs_new_protected:Npn \__tblr_build_short_table:n #1
{
\mode_leave_vertical:
- \__tblr_build_one_table:nn {1} {\c@rowcount}
+ \__tblr_build_one_table:nnNN {1} {\c@rowcount} \c_true_bool \c_true_bool
\__tblr_valign_whole:Nn \l__tblr_table_box {#1}
}
\cs_generate_variant:Nn \__tblr_build_short_table:n { e }
-\bool_new:N \l__tblr_build_first_hline_bool
-\bool_new:N \l__tblr_build_last_hline_bool
-\bool_set_true:N \l__tblr_build_first_hline_bool
-\bool_set_true:N \l__tblr_build_last_hline_bool
\box_new:N \l__tblr_table_hlines_box
\box_new:N \l__tblr_hline_box
\box_new:N \l__tblr_row_box
%% #1: row from; #2: row to
+%% #3: whether build first hline or not; #4: whether build last hline or not
%% To fix disappeared hlines with colorful tables in Adobe Reader (see #76),
%% we collect all hlines and draw them at the end of the table.
-\cs_new_protected:Npn \__tblr_build_one_table:nn #1 #2
+\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
@@ -5671,13 +5688,13 @@
{
\bool_lazy_or:nnT
{ \int_compare_p:nNn { \l__tblr_i_tl } > {#1} }
- { \bool_if_p:N \l__tblr_build_first_hline_bool }
+ { \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_put_one_row:n { \__tblr_build_row:N \l__tblr_i_tl }
\hrule height ~ 0pt
}
- \bool_if:NT \l__tblr_build_last_hline_bool
+ \bool_if:NT #4
{
\__tblr_put_one_hline:n
{ \__tblr_build_hline:n { \int_eval:n {#2 + 1} } }
@@ -5689,8 +5706,6 @@
}
\box_use:N \l__tblr_table_hlines_box
}
- \bool_set_true:N \l__tblr_build_first_hline_bool
- \bool_set_true:N \l__tblr_build_last_hline_bool
}
\cs_new_protected:Npn \__tblr_put_one_hline:n #1
@@ -6962,6 +6977,81 @@
\box_use:N \l__tblr_diag_box
}
+%% Library functional with evaluate and process options
+
+\cs_set_eq:NN \__tblr_functional_calculation: \prg_do_nothing:
+
+\NewTblrLibrary { functional }
+ {
+ \RequirePackage { functional }
+ %% Add outer specification "evaluate"
+ \keys_define:nn { tblr-outer }
+ { evaluate .code:n = \__tblr_outer_gput_spec:nn { evaluate } {##1} }
+ \tl_new:N \l__tblr_evaluate_tl
+ \cs_set_protected:Npn \__tblr_hook_split_before:
+ {
+ \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
+ }
+ }
+ %% Evaluate every occurrence of the specified function
+ %% Note that funtional package runs every return processor inside a group
+ %% #1: tl with table content; #2: function to be evaluated
+ \tl_new:N \g__tblr_functional_result_tl
+ \cs_new_protected:Npn \__tblr_evaluate_table_body:NN ##1 ##2
+ {
+ \tl_gclear:N \g__tblr_functional_result_tl
+ \cs_set_protected:Npn \__tblr_evaluate_table_body_aux:w ####1 ##2
+ {
+ \tl_gput_right:Nn \g__tblr_functional_result_tl {####1}
+ \peek_meaning:NTF \q_stop { \use_none:n } {##2}
+ }
+ \fun_run_return_processor:nn
+ {
+ \exp_last_unbraced:NV \__tblr_evaluate_table_body_aux:w \gResultTl
+ }
+ {
+ \exp_last_unbraced:NV
+ \__tblr_evaluate_table_body_aux:w ##1 ##2 \q_stop
+ }
+ \tl_set_eq:NN ##1 \g__tblr_functional_result_tl
+ }
+ %% Add inner specification "process"
+ \clist_put_right:Nn \g__tblr_table_known_keys_clist { process }
+ \keys_define:nn { tblr }
+ { process .code:n = \__tblr_keys_gput:nn { process } {##1} }
+ \cs_set:Npn \__tblr_functional_calculation:
+ {
+ \LogTblrTracing { step = do ~ functional ~ calculation }
+ \__tblr_prop_item:nn { inner } { process }
+ }
+ \prgNewFunction \cellGetText { m m }
+ {
+ \expWhole { \__tblr_spec_item:nn { text } { [##1][##2] } }
+ }
+ \prgNewFunction \cellSetText { m m m }
+ {
+ \__tblr_spec_gput:nnn { text } { [##1][##2] } {##3}
+ }
+ \prgNewFunction \cellSetStyle { m m m }
+ {
+ \tblr_set_cell:nnnn {##1} {##2} {} {##3}
+ }
+ \prgNewFunction \rowSetStyle { m m }
+ {
+ \tblr_set_row:nnn {##1} {} {##2}
+ }
+ \prgNewFunction \columnSetStyle { m m }
+ {
+ \tblr_set_column:nnn {##1} {} {##2}
+ }
+ }
+
%% Library siunitx and S columns
\NewTblrLibrary { siunitx }
@@ -7003,6 +7093,9 @@
\group_end:
}
}
+ \keys_define:nn { tblr-cell-spec } { guard .meta:n = { cmd = } }
+ \keys_define:nn { tblr-row } { guard .meta:n = { cmd = } }
+ \keys_define:nn { tblr-column } { guard .meta:n = { cmd = } }
}
%% Library varwidth and measure option
@@ -7013,4 +7106,3 @@
\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 }
}
-