diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/cellprops/cellprops.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/cellprops/cellprops.sty | 587 |
1 files changed, 587 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/cellprops/cellprops.sty b/Master/texmf-dist/tex/latex/cellprops/cellprops.sty new file mode 100644 index 00000000000..78777063c4d --- /dev/null +++ b/Master/texmf-dist/tex/latex/cellprops/cellprops.sty @@ -0,0 +1,587 @@ +%% +%% This is file `cellprops.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% cellprops.dtx (with options: `package') +%% +%% File: cellprops.dtx (C) Copyright 2016 RIVAUD Julien +%% +%% It may be distributed and/or modified under the conditions of the +%% General Public License (GPL), either version 3 of this +%% license or (at your option) any later version. +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\RequirePackage{expl3}[2016/01/19] +\def\ExplFileName{cellprops} +\def\ExplFileDescription{CSS-like cell and table properties} +\def\ExplFileDate{2016/04/05} +\def\ExplFileVersion{1.0} +\ProvidesExplPackage + {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} + +\RequirePackage{xparse} +\RequirePackage{xcolor} +\RequirePackage{mdwtab} +\cs_set_nopar:Npn \tab@pop #1 { \tl_set:Nx #1 { \tl_tail:N #1 } } + +\cs_set:Nn \__cellprops_generic_setter:nnn { + \exp_not:N \tl_set:Nn + \exp_not:c { l__cellprops_property_value_#2_tl } + {#1 {#3}} +} + +\cs_set_nopar:Nn \__cellprops_get_property:n { + \tl_use:c { l__cellprops_property_value_#1_tl } +} + +\cs_set_protected_nopar:Nn \__cellprops_get_property:nN { + \tl_set_eq:Nc #2 { l__cellprops_property_value_#1_tl } +} +\cs_set_protected:Nn \__cellprops_define_properties:nn { + \clist_map_inline:nn {#2} { + \cs_set:cpn { __cellprops_property_type_##1:nn } {#1} + } +} +\cs_set_protected:Nn \__cellprops_use_setter:nn { + \use:x { + \use:c {__cellprops_property_type_#1:nn} {#1} {#2} + } +} +\cs_set_protected:Nn \__cellprops_parse_properties:nn { + \tl_if_exist:cF { l__cellprops_property_group_#1_tl } { + \tl_clear:c { l__cellprops_property_group_#1_tl } + } + \seq_set_split:Nnn \l_tmpa_seq {;} {#2} + \seq_map_inline:Nn \l_tmpa_seq { + \tl_if_empty:nF {##1} { + \exp_args:NNV \seq_set_split:Nnn \l_tmpb_seq \c_colon_str {##1} + \int_compare:nNnTF {\seq_count:N \l_tmpb_seq} = \c_two { + \seq_get_left:NN \l_tmpb_seq \l_tmpa_tl + \exp_args:NNV \str_set:Nn \l_tmpa_str \l_tmpa_tl + \seq_get_right:NN \l_tmpb_seq \l_tmpa_tl + \cs_if_exist:cTF { __cellprops_property_type_\l_tmpa_str :nn } { + \tl_put_right:cx { l__cellprops_property_group_#1_tl } { + \exp_args:Nc \exp_args:NVV + { __cellprops_property_type_\l_tmpa_str :nn } + \l_tmpa_str \l_tmpa_tl + } + }{ + % TODO: ERROR-no property with that name + } + }{ + % TODO: ERROR-too many : or none at all + } + } + } +} + +\cs_set:Nn \__cellprops_fourdim_setter:nn { + \__cellprops_fourdim_setter_aux:w + {#1}#2~{\q_no_value}~{\q_no_value}~{\q_no_value}~\q_stop +} +\cs_set:Npn \__cellprops_fourdim_setter_aux:w #1#2~#3~#4~#5~#6\q_stop { + \__cellprops_generic_setter:nnn \exp_not:n {#1-top} {#2} + \quark_if_no_value:nTF {#3} { + \__cellprops_generic_setter:nnn \exp_not:n {#1-right} {#2} + \__cellprops_generic_setter:nnn \exp_not:n {#1-left} {#2} + }{ + \__cellprops_generic_setter:nnn \exp_not:n {#1-right} {#3} + \quark_if_no_value:nTF {#5} { + \__cellprops_generic_setter:nnn \exp_not:n {#1-left} {#3} + }{ + \__cellprops_generic_setter:nnn \exp_not:n {#1-left} {#5} + } + } + \quark_if_no_value:nTF {#4} { + \__cellprops_generic_setter:nnn \exp_not:n {#1-bottom} {#2} + }{ + \__cellprops_generic_setter:nnn \exp_not:n {#1-bottom} {#4} + } +} + +\tl_const:Nn \c__cellprops_inherit_color_tl { \q_nil } + +\cs_new_nopar:Nn \__cellprops_color_setter:nn { + \str_if_eq:nnTF {#2} {inherit} { + \__cellprops_generic_setter:nnn \exp_not:n {#1} {\c__cellprops_inherit_color_tl} + }{ + \str_case_x:nnF { \str_range:nnn {#2} {1} {4} } { + {rgb(} { + \__cellprops_generic_setter:nnn \use:n {#1} { + \exp_not:n {\color[RGB]} {\str_range:nnn {#2} {5} {-2}} + }} + {hsl(} { + \__cellprops_generic_setter:nnn \use:n {#1} { + \exp_not:n {\color[Hsb]} {\str_range:nnn {#2} {5} {-2}} + }} + }{ + \__cellprops_generic_setter:nnn \exp_not:n {#1} { + \color{#2} + } + } + } +} +\cs_new_nopar:Nn \__cellprops_bgcolor_setter:nn { + \str_if_eq:nnTF {#2} {transparent} { + \__cellprops_color_setter:nn {#1} {inherit} + }{ + \__cellprops_color_setter:nn {#1} {#2} + } +} + +\__cellprops_define_properties:nn { + \__cellprops_generic_setter:nnn \exp_not:n +}{ + padding-top, + padding-right, + padding-bottom, + padding-left, + min-height, + min-depth, + min-width, +} + +\__cellprops_define_properties:nn { + \__cellprops_fourdim_setter:nn +}{ + padding +} + +\__cellprops_define_properties:nn { + \__cellprops_generic_setter:nnn \tl_to_str:n +}{ + text-align, + math-mode, +} + +\__cellprops_define_properties:nn { + \__cellprops_color_setter:nn +}{ + color, +} + +\__cellprops_define_properties:nn { + \__cellprops_bgcolor_setter:nn +}{ + background-color, +} + +\NewDocumentCommand \cellprops { m } { + \__cellprops_parse_css:n {#1} +} + +\cs_new_protected:Nn \__cellprops_parse_css:n { + \__cellprops_parse_css:w #1 \q_mark {\q_nil} \q_stop +} +\NewDocumentCommand \__cellprops_parse_css:w { lmu{\q_stop} } { + \quark_if_nil:nF {#2} { + \clist_map_inline:nn {#1} { + \__cellprops_parse_properties:nn {##1} {#2} + } + \__cellprops_parse_css:w #3 \q_stop + } +} + +\cs_set_protected:Nn \__cellprops_recall_properties:n { + \tl_if_exist:cT { l__cellprops_property_group_#1_tl } { + \tl_use:c { l__cellprops_property_group_#1_tl } + } + \clist_map_inline:nn { \@currenvir } { + \tl_if_exist:cT { l__cellprops_property_group_##1~#1_tl } { + \tl_use:c { l__cellprops_property_group_##1~#1_tl } + } + } +} + +\dim_new:N \l__cellprops_colsep_dim +\ExplSyntaxOff +\cellprops{ + td { + padding: 0pt \csname l__cellprops_colsep_dim\endcsname; + min-height: 0pt; + min-depth: 0pt; + min-width: 0pt; + text-align: left; + math-mode: auto; + color: inherit; + background-color: transparent; + } + tr { + color: inherit; + background-color: transparent; + } + table { + padding: 0pt; % No change at load time + color: inherit; + background-color: transparent; + } +} +\ExplSyntaxOn + +\int_new:N \g__cellprops_row_int +\int_new:N \g__cellprops_col_int +\bool_new:N \g__cellprops_inrow_bool +\bool_gset_false:N \g__cellprops_inrow_bool + +\box_new:N \l__cellprops_cell_box +\skip_new:N \l__cellprops_left_skip +\skip_new:N \l__cellprops_right_skip +\dim_new:N \g__cellprops_ht_dim +\dim_new:N \g__cellprops_dp_dim + +\tl_new:N \l__cellprops_restore_tl + +\dim_new:N \l__cellprops_tablepadding_top_dim +\dim_new:N \l__cellprops_tablepadding_bottom_dim +\tl_new:N \l__cellprops_color_tl +\tl_new:N \l__cellprops_bgcolor_tl + +\cs_set_eq:NN \__cellprops_orig_array: \@array +\cs_set_protected_nopar:Npn \@array[#1]#2 { + \tl_set:Nx \l__cellprops_restore_tl { + \bool_if:NTF \g__cellprops_inrow_bool { + \exp_not:n {\bool_gset_true:N \g__cellprops_inrow_bool} + }{ + \exp_not:n {\bool_gset_false:N \g__cellprops_inrow_bool} + } + \exp_not:n { \int_gset:Nn \g__cellprops_row_int } + { \int_use:N \g__cellprops_row_int } + \exp_not:n { \int_gset:Nn \g__cellprops_col_int } + { \int_use:N \g__cellprops_col_int } + \exp_not:n { \dim_gset:Nn \g__cellprops_ht_dim } + { \dim_use:N \g__cellprops_ht_dim } + \exp_not:n { \dim_gset:Nn \g__cellprops_dp_dim } + { \dim_use:N \g__cellprops_dp_dim } + } + \int_gzero:N \g__cellprops_row_int + \bool_gset_false:N \g__cellprops_inrow_bool + \cs_set_eq:NN \__cellprops_orig_tab@initread: \tab@initread + \cs_set_protected_nopar:Npn \tab@initread { + \cs_set_eq:NN \tab@initread \__cellprops_orig_tab@initread: + \tab@initread + \tl_put_left:Nn \tab@tabtext {\int_gincr:N \g__cellprops_col_int} + } + \dim_set_eq:NN \l__cellprops_colsep_dim \col@sep + \dim_zero:N \col@sep + \dim_zero:N \tab@extrasep + \group_begin: + \__cellprops_recall_properties:n {table} + \dim_gset:Nn \g_tmpa_dim { \__cellprops_get_property:n {padding-top} } + \dim_gset:Nn \g_tmpb_dim { \__cellprops_get_property:n {padding-bottom} } + \__cellprops_update_colors: + \tl_gset_eq:NN \g_tmpa_tl \l__cellprops_color_tl + \tl_gset_eq:NN \g_tmpb_tl \l__cellprops_bgcolor_tl + \group_end: + \dim_set_eq:NN \l__cellprops_tablepadding_top_dim \g_tmpa_dim + \dim_set_eq:NN \l__cellprops_tablepadding_bottom_dim \g_tmpb_dim + \tl_set_eq:NN \l__cellprops_color_tl \g_tmpa_tl + \tl_set_eq:NN \l__cellprops_bgcolor_tl \g_tmpb_tl + \__cellprops_recall_properties:n {tr} + \__cellprops_orig_array:[{#1}]{#2} + \hlx{s[\l__cellprops_tablepadding_top_dim]} +} + + +\cs_new_protected_nopar:Nn \__cellprops_update_color:Nn { + \__cellprops_get_property:nN {#2} \l_tmpc_tl + \exp_args:NV \tl_if_eq:NNF \l_tmpc_tl \c__cellprops_inherit_color_tl { + \tl_set_eq:NN #1 \l_tmpc_tl + } +} + +\cs_set_protected_nopar:Nn \__cellprops_update_colors: { + \__cellprops_update_color:Nn \l__cellprops_color_tl {color} + \__cellprops_update_color:Nn \l__cellprops_bgcolor_tl {background-color} +} + +\cs_set_eq:NN \__cellprops_orig_endarray: \endarray +\cs_set_nopar:Npn \endarray { + \crcr + \hlx{s[\l__cellprops_tablepadding_bottom_dim]} + \__cellprops_orig_endarray: + \tl_use:N \l__cellprops_restore_tl +} + +\cs_set_eq:NN \__cellprops_orig_tab@startrow: \tab@startrow +\cs_set_nopar:Npn \tab@startrow { + \__cellprops_orig_tab@startrow: + \bool_if:NF \g__cellprops_inrow_bool { + \bool_gset_true:N \g__cellprops_inrow_bool + \int_gincr:N \g__cellprops_row_int + \int_gset_eq:NN \g__cellprops_col_int \c_one + \dim_gzero:N \g__cellprops_ht_dim + \dim_gzero:N \g__cellprops_dp_dim + } +} + +\cs_set_eq:NN \__cellprops_orig_tab@arraycr: \tab@arraycr +\cs_set_protected_nopar:Npn \tab@arraycr { + \bool_if:NT \g__cellprops_inrow_bool { + \bool_gset_false:N \g__cellprops_inrow_bool + \__cellprops_fix_valign_end: + } + \__cellprops_orig_tab@arraycr: +} + +\cs_set_eq:NN \__cellprops_orig_multicolumn:w \multicolumn +\cs_set:Npn \multicolumn#1#2#3 { + \__cellprops_orig_multicolumn:w {#1}{#2}{ + #3 + \int_gadd:Nn \g__cellprops_col_int {#1} + } +} + +\cs_new_protected_nopar:Nn \__cellprops_fix_valign_end: { + \exp_args:NV \tl_if_eq:nnTF \tab@hlstate {b} { + \dim_gadd:Nn \tab@endheight { + \g__cellprops_dp_dim - \box_dp:N \@arstrutbox + } + }{ + \int_compare:nNnT \g__cellprops_row_int = \c_one { + \dim_gadd:Nn \tab@endheight { + \g__cellprops_ht_dim - \box_ht:N \@arstrutbox + } + } + } +} + +\colpush{tabular} + +\coldef n{\tabcoltype{ + \__cellprops_begincell:n{} +}{ + \__cellprops_endcell: +}} +\coldef l{\tabcoltype{ + \__cellprops_begincell:n + {\__cellprops_use_setter:nn {text-align} {left}} +}{ + \__cellprops_endcell: +}} +\coldef c{\tabcoltype{ + \__cellprops_begincell:n + {\__cellprops_use_setter:nn {text-align} {center}} +}{ + \__cellprops_endcell: +}} +\coldef r{\tabcoltype{ + \__cellprops_begincell:n + {\__cellprops_use_setter:nn {text-align} {right}} +}{ + \__cellprops_endcell: +}} +\coldef M#1{\__cellprops_MTcol:nn {math}{#1}} +\coldef T#1{\__cellprops_MTcol:nn {text}{#1}} +\cs_new_protected_nopar:Nn \__cellprops_MTcol:nn { + % TODO: error if align not l, c, or r + \exp_args:Nx \tabcoltype { + \exp_not:N \__cellprops_begincell:n { + \exp_not:n {\__cellprops_use_setter:nn {math-mode} {#1} } + \exp_not:n {\__cellprops_use_setter:nn {text-align}} { + \str_case:nn {#2} { + {l} {left} + {c} {center} + {r} {right} + } + } + } + }{ + \__cellprops_endcell: + } +} + +\coldef p#1{\tabcoltype{ + \__cellprops_begin_par_cell:nn \vtop {#1} +}{ + \__cellprops_end_par_cell:n {} +}} +\coldef m#1{\tabcoltype{ + \__cellprops_begin_par_cell:nn {\c_math_toggle_token\vcenter} {#1} +}{ + \__cellprops_end_par_cell:n{\c_math_toggle_token} +}} +\coldef b#1{\tabcoltype{ + \__cellprops_begin_par_cell:nn \vbox {#1} +}{ + \__cellprops_end_par_cell:n {} +}} + +\colpop + + +\cs_new_protected_nopar:Nn \__cellprops_nthchild_anb:Nnn { + \tl_set:Nx \l_tmpa_tl { +\int_eval:n{\int_mod:nn{#2}{#3}} } + \exp_args:NV \tl_if_eq:nnT \l_tmpa_tl { +0 } { + \tl_clear:N \l_tmpa_tl + } + \seq_put_right:Nx #1 { #3n\l_tmpa_tl } +} + +\cs_new_protected_nopar:Nn \__cellprops_seq_nthchild:Nn { + \seq_clear:N #1 + \seq_put_right:Nx #1 { + \int_compare:nNnTF{\int_mod:nn{#2}{2}}={0}{even}{odd} + } + \__cellprops_nthchild_anb:Nnn #1 {#2} {2} + \__cellprops_nthchild_anb:Nnn #1 {#2} {3} + \seq_put_right:Nx #1 { \int_eval:n{#2} } +} + +\cs_new_protected_nopar:Nn \__cellprops_begincell:n { + \__cellprops_begin_raw_cell:n { + \__cellprops_seq_nthchild:Nn \l_tmpa_seq { \g__cellprops_row_int } + \__cellprops_seq_nthchild:Nn \l_tmpb_seq { \g__cellprops_col_int } + \seq_map_inline:Nn \l_tmpa_seq { + \__cellprops_recall_properties:n {tr:nth-child(##1)} + } + \__cellprops_update_colors: + \__cellprops_recall_properties:n {td} + \__cellprops_recall_properties:n {tr~td} + \seq_map_inline:Nn \l_tmpb_seq { + \__cellprops_recall_properties:n {td:nth-child(##1)} + } + \seq_map_inline:Nn \l_tmpa_seq { + \__cellprops_recall_properties:n {tr:nth-child(##1)~td} + } + \seq_map_inline:Nn \l_tmpa_seq { + \seq_map_inline:Nn \l_tmpb_seq { + \__cellprops_recall_properties:n {tr:nth-child(##1)~ + td:nth-child(####1)} + } + } + \__cellprops_update_colors: + #1 + \hbox_set:Nw \l__cellprops_cell_box + \str_case_x:nnF {\__cellprops_get_property:n {math-mode}} { + { text } { \tab@btext } + { math } { \tab@bmaths } + }{% any other treated as |auto| + \tab@bgroup + } + } +} + +\cs_new_protected_nopar:Nn \__cellprops_endcell: { + \str_case_x:nnF {\__cellprops_get_property:n {math-mode}} { + { text } { \tab@etext } + { math } { \tab@emaths } + }{% any other treated as |auto| + \tab@egroup + } + \hbox_set_end: + \__cellprops_end_raw_cell: +} + +\cs_new_protected_nopar:Nn \__cellprops_begin_par_cell:nn { + \savenotes + \__cellprops_begin_raw_cell:n{ + \hbox_set:Nw \l__cellprops_cell_box + #1 + \bgroup + \hsize#2\relax + \@arrayparboxrestore + \global\@minipagetrue + \everypar{ + \global\@minipagefalse + \everypar{} + } + \__cellprops_recall_properties:n {td~p} + } +} +\cs_new_protected_nopar:Nn \__cellprops_end_par_cell:n { + \ifhmode\@maybe@unskip\par\fi + \unskip + \egroup + #1 + \hbox_set_end: + \__cellprops_end_raw_cell: + \spewnotes\hfil +} + +\cs_new_protected_nopar:Nn \__cellprops_begin_raw_cell:n { + \group_begin: + % Additional init code + #1 + % Install the cell color + \__cellprops_update_colors: + \tl_use:N \l__cellprops_color_tl +} + +\cs_new_protected_nopar:Nn \__cellprops_end_raw_cell: { + % Here \l__cellprops_cell_box must contain the contents of the cell + % + % Handle vpadding and min-height/depth + \box_set_ht:Nn \l__cellprops_cell_box { + \dim_max:nn + {\box_ht:N \l__cellprops_cell_box} + {\__cellprops_get_property:n {min-height}} + + (\__cellprops_get_property:n {padding-top}) + } + \box_set_dp:Nn \l__cellprops_cell_box { + \dim_max:nn + {\box_dp:N \l__cellprops_cell_box} + {\__cellprops_get_property:n {min-depth}} + + (\__cellprops_get_property:n {padding-bottom}) + } + % To fix vertical alignment later + \dim_gset:Nn \g__cellprops_ht_dim { + \dim_max:nn + {\g__cellprops_ht_dim} + {\box_ht:N \l__cellprops_cell_box} + } + \dim_gset:Nn \g__cellprops_dp_dim { + \dim_max:nn + {\g__cellprops_dp_dim} + {\box_dp:N \l__cellprops_cell_box} + } + % Handle hpadding and halign + \skip_set:Nn \l_tmpa_skip { + \dim_max:nn + {0pt} + { (\__cellprops_get_property:n {min-width}) + - \box_wd:N \l__cellprops_cell_box } + } + \skip_add:Nn \l_tmpa_skip { + 0pt plus 1fil + } + \skip_set:Nn \l__cellprops_left_skip + {\__cellprops_get_property:n {padding-left}} + \skip_set:Nn \l__cellprops_right_skip + {\__cellprops_get_property:n {padding-right}} + \str_case_x:nnF {\__cellprops_get_property:n {text-align}} { + { right } { + \skip_add:Nn \l__cellprops_left_skip { \l_tmpa_skip } + } + { center } { + \skip_add:Nn \l__cellprops_left_skip { \l_tmpa_skip / 2 } + \skip_add:Nn \l__cellprops_right_skip { \l_tmpa_skip / 2 } + } + }{% any other treated as |left| + \skip_add:Nn \l__cellprops_right_skip { \l_tmpa_skip } + } + \kern\c_zero_dim + \tl_if_empty:NF \l__cellprops_bgcolor_tl { + \group_begin: + % Paint a background with leaders + \tl_use:N \l__cellprops_bgcolor_tl % install the color + \skip_set:Nn \l_tmpa_skip { + \l__cellprops_left_skip + + \box_wd:N \l__cellprops_cell_box + + \l__cellprops_right_skip + } + \leaders + \vrule + \skip_horizontal:N \l_tmpa_skip + \skip_horizontal:n {-\l_tmpa_skip} + \group_end: + } + \skip_horizontal:N \l__cellprops_left_skip + \box_use_clear:N \l__cellprops_cell_box + \skip_horizontal:N \l__cellprops_right_skip + \kern\c_zero_dim + \group_end: +} +%% +%% +%% End of file `cellprops.sty'. |