diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/cellprops/cellprops.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/cellprops/cellprops.sty | 282 |
1 files changed, 218 insertions, 64 deletions
diff --git a/Master/texmf-dist/tex/latex/cellprops/cellprops.sty b/Master/texmf-dist/tex/latex/cellprops/cellprops.sty index 6126921c594..3679d747d81 100644 --- a/Master/texmf-dist/tex/latex/cellprops/cellprops.sty +++ b/Master/texmf-dist/tex/latex/cellprops/cellprops.sty @@ -6,7 +6,7 @@ %% %% cellprops.dtx (with options: `package') %% -%% File: cellprops.dtx (C) Copyright 2016-2020 RIVAUD Julien +%% File: cellprops.dtx (C) Copyright 2016-2021 RIVAUD Julien %% %% It may be distributed and/or modified under the conditions of the %% General Public License (GPL), either version 3 of this @@ -15,8 +15,8 @@ \RequirePackage{expl3}[2018/06/19] \def\ExplFileName{cellprops} \def\ExplFileDescription{CSS-like cell and table properties} -\def\ExplFileDate{2020/06/07} -\def\ExplFileVersion{1.7a} +\def\ExplFileDate{2021/01/30} +\def\ExplFileVersion{2.0} \ProvidesExplPackage {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} @@ -61,20 +61,16 @@ \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} = { 2 } { + \int_compare:nNnT {\seq_count:N \l_tmpb_seq} = { 2 } { \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 } { + \cs_if_exist:cT { __cellprops_property_type_\l_tmpa_str :nn } { \tl_put_right:Nx #1 { \exp_args:NVV \__cellprops_delegate_setter:nn \l_tmpa_str \l_tmpa_tl } - }{ - % TODO: ERROR-no property with that name } - }{ - % TODO: ERROR-too many : or none at all } } } @@ -165,7 +161,7 @@ } }{ \quark_if_no_value:nTF {#3} { - %% TODO: Error, one no-style value, ambiguous + %% One no-style value, ambiguous. Ignore the property }{ \__cellprops_border_setter_isstyle:nTF {#3} { \__cellprops_delegate_setter:nn {#1-width} {#2} @@ -206,6 +202,7 @@ \__cellprops_generic_setter:nnn \tl_to_str:n }{ text-align, + vertical-align, math-mode, } \__cellprops_define_properties:nn { @@ -245,13 +242,19 @@ \cs_new_protected:Nn \__cellprops_parse_css:n { \__cellprops_parse_css:w #1 \q_mark {\q_nil} \q_stop + \seq_remove_duplicates:N \l__cellprops_specificities_seq + \seq_sort:Nn \l__cellprops_specificities_seq { + \int_compare:nNnTF { ##1 } > { ##2 } + { \sort_return_swapped: } + { \sort_return_same: } + } } \tl_new:N \l__cellprops_parse_properties_tl \NewDocumentCommand \__cellprops_parse_css:w { lmu{\q_stop} } { \quark_if_nil:nF {#2} { \__cellprops_parse_properties:Nn \l__cellprops_parse_properties_tl {#2} \clist_map_inline:nn {#1} { - \__cellprops_parse_css_addprops:n {##1} + \tl_if_empty:nF {##1} { \__cellprops_parse_css_addprops:n {##1} } } \__cellprops_parse_css:w #3 \q_stop } @@ -260,16 +263,19 @@ \tl_new:N \l__cellprops_current_selector_check_tl \cs_new_protected:Nn \__cellprops_parse_css_addprops:n { \__cellprops_parse_selector:n {#1} - \tl_set:Nx \l_tmpa_tl { l__cellprops_property_group_\l__cellprops_current_selector_tl _tl } - \tl_if_exist:cF { \l_tmpa_tl } { \tl_clear:c { \l_tmpa_tl } } - \tl_if_empty:NTF \l__cellprops_current_selector_check_tl { - \tl_put_right:cV { \l_tmpa_tl } \l__cellprops_parse_properties_tl - }{ - \tl_put_right:cx { \l_tmpa_tl } { - \exp_not:N \bool_if:nT { - \exp_not:V \l__cellprops_current_selector_check_tl - }{ - \exp_not:V \l__cellprops_parse_properties_tl + \tl_if_empty:NF \l__cellprops_current_selector_tl { + \tl_set:Nx \l_tmpa_tl + { l__cellprops_property_group_\l__cellprops_current_selector_tl _tl } + \tl_if_exist:cF { \l_tmpa_tl } { \tl_clear:c { \l_tmpa_tl } } + \tl_if_empty:NTF \l__cellprops_current_selector_check_tl { + \tl_put_right:cV { \l_tmpa_tl } \l__cellprops_parse_properties_tl + }{ + \tl_put_right:cx { \l_tmpa_tl } { + \exp_not:N \bool_if:nT { + \exp_not:V \l__cellprops_current_selector_check_tl + }{ + \exp_not:V \l__cellprops_parse_properties_tl + } } } } @@ -297,28 +303,118 @@ \seq_new:N \l__cellprops_current_selector_seq \seq_new:N \l__cellprops_pseudoclasses_seq \tl_new:N \l__cellprops_current_element_tl +\tl_new:N \l__cellprops_current_tableclass_tl +\int_new:N \l__cellprops_current_level_int +\int_new:N \l__cellprops_current_specificity_int +\seq_new:N \l__cellprops_specificities_seq \cs_new_protected:Nn \__cellprops_parse_selector:n { \tl_set:Nx \l__cellprops_current_selector_tl { \tl_to_str:n {#1} } \exp_args:NNV \tl_replace_all:Nnn \l__cellprops_current_selector_tl \c_colon_str {:} \__cellprops_parse_selector_sanitize:n {nth-child} + \__cellprops_parse_selector_sanitize:n {where} \seq_set_split:NnV \l__cellprops_current_selector_seq {~} \l__cellprops_current_selector_tl \tl_clear:N \l__cellprops_current_selector_tl \tl_clear:N \l__cellprops_current_selector_check_tl + \tl_clear:N \l__cellprops_current_tableclass_tl + \int_set:Nn \l__cellprops_current_level_int {-1} + \int_zero:N \l__cellprops_current_specificity_int \seq_map_inline:Nn \l__cellprops_current_selector_seq { - \seq_set_split:Nnn \l__cellprops_pseudoclasses_seq {:} {##1} - \seq_pop_left:NN \l__cellprops_pseudoclasses_seq \l__cellprops_current_element_tl - \tl_put_right:Nn \l__cellprops_current_selector_tl {~} - \tl_put_right:NV \l__cellprops_current_selector_tl \l__cellprops_current_element_tl + \tl_clear:N \l__cellprops_current_element_tl + \__cellprops_parse_simple_selector:n {##1} + } + \tl_if_empty:NF \l__cellprops_current_element_tl { + \tl_if_empty:NF \l__cellprops_current_tableclass_tl { + \tl_set:Nx \l__cellprops_current_tableclass_tl { + l__cellprops_active_classes_\l__cellprops_current_tableclass_tl _bool + } + \bool_if_exist:cF { \l__cellprops_current_tableclass_tl } { + \bool_new:c { \l__cellprops_current_tableclass_tl } + } + \__cellprops_add_check:x { + \exp_not:n { \bool_if_p:N } + { + \exp_not:c { \l__cellprops_current_tableclass_tl } + } + } + } + \tl_set:Nx \l__cellprops_current_selector_tl { + \exp_not:V \l__cellprops_current_element_tl + \exp_not:n {~} + \int_use:N \l__cellprops_current_specificity_int + } + \seq_put_right:Nx \l__cellprops_specificities_seq { + \int_use:N \l__cellprops_current_specificity_int + } + } +} + +\tl_new:N \l__cellprops_maybe_element_tl + +\cs_new_protected:Nn \__cellprops_parse_simple_selector:n { + \tl_set:Nn \l_tmpa_tl { #1 } + \tl_replace_all:Nnn \l_tmpa_tl {.} {:.} + \seq_set_split:NnV \l__cellprops_pseudoclasses_seq {:} \l_tmpa_tl + \seq_pop_left:NN \l__cellprops_pseudoclasses_seq \l__cellprops_maybe_element_tl + \str_case:VnTF \l__cellprops_maybe_element_tl { + { table } { \int_set:Nn \l_tmpa_int { 1 } } + { tr } { \int_set:Nn \l_tmpa_int { 2 } } + { td } { \int_set:Nn \l_tmpa_int { 3 } } + { p } { \int_set:Nn \l_tmpa_int { 4 } } + }{ + \int_add:Nn \l__cellprops_current_specificity_int { 1 } + }{ + \tl_if_empty:NTF \l__cellprops_maybe_element_tl { + \int_set:Nn \l_tmpa_int { 10 } + }{ + \int_compare:nNnTF \l__cellprops_current_level_int = { -1 } { + \tl_set_eq:NN + \l__cellprops_current_tableclass_tl + \l__cellprops_maybe_element_tl + \tl_set:Nn \l__cellprops_maybe_element_tl { table } + \int_set:Nn \l_tmpa_int { 1 } + \int_add:Nn \l__cellprops_current_specificity_int { 11 } + }{ + \int_set:Nn \l_tmpa_int { -10 } + } + } + } + \tl_if_empty:NTF \l__cellprops_current_element_tl { + \tl_set_eq:NN \l__cellprops_current_element_tl \l__cellprops_maybe_element_tl + }{ + \tl_if_empty:NF \l__cellprops_maybe_element_tl { + \int_set:Nn \l_tmpa_int { -10 } + } + } + \int_compare:nNnTF \l_tmpa_int > \l__cellprops_current_level_int { + \int_compare:nNnT \l_tmpa_int < 10 { + \int_set_eq:NN \l__cellprops_current_level_int \l_tmpa_int + } \seq_map_inline:Nn \l__cellprops_pseudoclasses_seq { - \__cellprops_parse_pseudoclass:w ####1{}\q_stop + \__cellprops_parse_pseudoclass:w ##1{}\q_stop } + }{ + \tl_clear:N \l__cellprops_current_element_tl + } + \tl_if_empty:NT \l__cellprops_current_element_tl { + \seq_map_break: } } \NewDocumentCommand \__cellprops_parse_pseudoclass:w { lmu{\q_stop} } { - \exp_args:Nx \str_case:nn { #1 } { + \str_case:nnF { #1 } { {first-child} { \__cellprops_parse_selector_nth:n {1} } - {nth-child} { \__cellprops_parse_selector_nth:n {#2} } + {nth-child} { \__cellprops_parse_selector_nth:n {#2} } + {where} { \__cellprops_parse_where:n {#2} } + }{ + \str_if_eq:eeTF { \str_head:n { #1 } } {.} { + \tl_set:Nx \l__cellprops_current_tableclass_tl { + \str_tail:n { #1 } + } + \int_add:Nn \l__cellprops_current_specificity_int { 10 } + }{ + \tl_clear:N \l__cellprops_current_element_tl + \seq_map_break:n { \seq_map_break: } + } } } @@ -326,7 +422,7 @@ \int_new:N \l__cellprops_nth_coeff_int \int_new:N \l__cellprops_nth_offset_int \cs_new_protected:Nn \__cellprops_parse_selector_nth:n { - \tl_put_right:Nn \l__cellprops_current_selector_tl { :nth-child } + \int_add:Nn \l__cellprops_current_specificity_int { 10 } \str_case:nnF {#1} { {even} { \str_set:Nn \l_tmpa_str {2n} } {odd} { \str_set:Nn \l_tmpa_str {2n+1} } @@ -354,7 +450,7 @@ }{ \int_zero:N \l__cellprops_nth_coeff_int } - \exp_args:NV \str_case:nn \l__cellprops_current_element_tl { + \str_case:Vn \l__cellprops_current_element_tl { {tr} { \__cellprops_generate_check_nth:n {\g__cellprops_row_int} } {td} { \__cellprops_generate_check_nth:n {\g__cellprops_col_int} } } @@ -362,9 +458,11 @@ \cs_new_protected_nopar:Nn \__cellprops_generate_check_nth:n { \int_compare:nNnTF \l__cellprops_nth_coeff_int = { 0 } { - \tl_set:Nx \l_tmpa_tl { + \__cellprops_add_check:x { \exp_not:n { \int_compare_p:nNn #1 = } - \exp_not:V \l__cellprops_nth_offset_int + { + \exp_not:V \l__cellprops_nth_offset_int + } } }{ \tl_set:Nx \l_tmpb_tl { @@ -375,7 +473,7 @@ \exp_not:V \l__cellprops_nth_coeff_int } } - \tl_set:Nx \l_tmpa_tl { + \__cellprops_add_check:x { \exp_not:N \bool_lazy_and_p:nn { \exp_not:n { \int_compare_p:nNn 0 = } { @@ -392,26 +490,48 @@ } } } +} + +\cs_new_protected:Nn \__cellprops_parse_where:n { + \use:x { + \exp_not:n { + \__cellprops_parse_simple_selector:n { #1 } + \int_set:Nn \l__cellprops_current_specificity_int + } + { + \int_use:N \l__cellprops_current_specificity_int + } + } +} + +\cs_new_protected:Nn \__cellprops_add_check:n { \tl_if_empty:NTF \l__cellprops_current_selector_check_tl { - \tl_set_eq:NN \l__cellprops_current_selector_check_tl \l_tmpa_tl + \tl_set:Nn \l__cellprops_current_selector_check_tl { #1 } }{ \tl_set:Nx \l__cellprops_current_selector_check_tl { \exp_not:N \bool_lazy_and_p:nn { \exp_not:V \l__cellprops_current_selector_check_tl }{ - \exp_not:V \l_tmpa_tl + \exp_not:n { #1 } } } } } +\cs_generate_variant:Nn \__cellprops_add_check:n {x} -\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 } +\seq_new:N \l__cellprops_classes_seq +\NewDocumentCommand \cellpropsclass { sm } { + \seq_set_split:Nnn \l__cellprops_classes_seq {~} { #2 } + \IfBooleanF {#1} { + \seq_put_right:Nn \l__cellprops_classes_seq { \@currenvir } } - \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 } +} +\cellpropsclass{} + +\cs_set_protected:Nn \__cellprops_recall_properties:n { + \seq_map_inline:Nn \l__cellprops_specificities_seq { + \tl_if_exist:cT { l__cellprops_property_group_#1~##1_tl } { + \tl_use:c { l__cellprops_property_group_#1~##1_tl } } } } @@ -422,22 +542,23 @@ \ExplSyntaxOff \cellprops{ - td { + :where(td) { padding: 0pt \csname l__cellprops_colsep_dim\endcsname; min-height: \csname l__cellprops_strut_ht_dim\endcsname; min-depth: \csname l__cellprops_strut_dp_dim\endcsname; min-width: 0pt; text-align: left; + vertical-align: baseline; math-mode: auto; color: inherit; background-color: transparent; border: thin none inherit; } - tr { + :where(tr) { color: inherit; background-color: transparent; } - table { + :where(table) { padding: 0pt; % No change at load time color: inherit; background-color: transparent; @@ -464,6 +585,8 @@ \tl_new:N \l__cellprops_color_tl \tl_new:N \l__cellprops_bgcolor_tl +\seq_new:N \l__cellprops_classes_at_start_seq + \cs_new_protected:Nn \__cellprops_array_init: { \tl_set:Nx \l__cellprops_restore_tl { \bool_if:NTF \g__cellprops_inrow_bool { @@ -482,6 +605,13 @@ \exp_not:n { \tl_gset:Nn \g__cellprops_borders_tl } { \exp_not:V \g__cellprops_borders_tl } } + \seq_map_inline:Nn \l__cellprops_classes_at_start_seq { + \bool_set_false:c { l__cellprops_active_classes_##1_bool } + } + \seq_set_eq:NN \l__cellprops_classes_at_start_seq \l__cellprops_classes_seq + \seq_map_inline:Nn \l__cellprops_classes_at_start_seq { + \bool_set_true:c { l__cellprops_active_classes_##1_bool } + } \int_gzero:N \g__cellprops_row_int \bool_gset_false:N \g__cellprops_inrow_bool \tl_gclear:N \g__cellprops_borders_tl @@ -502,7 +632,6 @@ \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} \dim_set:Nn \l__cellprops_strut_ht_dim { \box_ht:N \@arstrutbox } \dim_set:Nn \l__cellprops_strut_dp_dim { \box_dp:N \@arstrutbox } \box_clear:N \@arstrutbox @@ -744,13 +873,7 @@ \global\@minipagefalse \everypar{} } - \__cellprops_recall_properties:n {td~p} - \__cellprops_recall_properties:n {tr~td~p} - \__cellprops_recall_properties:n {tr:nth-child~p} - \__cellprops_recall_properties:n {td:nth-child~p} - \__cellprops_recall_properties:n {tr:nth-child~td~p} - \__cellprops_recall_properties:n {tr~td:nth-child~p} - \__cellprops_recall_properties:n {tr:nth-child~td:nth-child~p} + \__cellprops_recall_properties:n {p} } } \cs_new_protected_nopar:Nn \__cellprops_end_par_cell:n { @@ -765,14 +888,9 @@ \cs_new_protected_nopar:Nn \__cellprops_begin_raw_cell:n { \group_begin: - \__cellprops_recall_properties:n {tr:nth-child} + \__cellprops_recall_properties:n {tr} \__cellprops_update_colors: \__cellprops_recall_properties:n {td} - \__cellprops_recall_properties:n {tr~td} - \__cellprops_recall_properties:n {td:nth-child} - \__cellprops_recall_properties:n {tr:nth-child~td} - \__cellprops_recall_properties:n {tr~td:nth-child} - \__cellprops_recall_properties:n {tr:nth-child~td:nth-child} \__cellprops_update_colors: % Additional init code #1 @@ -860,12 +978,50 @@ \tl_if_empty:NF \g__cellprops_borders_tl { \exp_not:n {&} } \exp_not:n { \omit \kern \c_zero_dim } } - % Handle padding-top, min-height and border-top - \__cellprops_get_border_info:n {top} + % Handle min-height, min-depth and vertical-align + % wrong values are treated as |baseline|. \box_set_ht:Nn \l__cellprops_cell_box { \dim_max:nn {\box_ht:N \l__cellprops_cell_box} {\__cellprops_get_property:n {min-height}} + } + \box_set_dp:Nn \l__cellprops_cell_box { + \dim_max:nn + {\box_dp:N \l__cellprops_cell_box} + {\__cellprops_get_property:n {min-depth}} + } + \str_case_e:nn {\__cellprops_get_property:n {vertical-align}} { + { top } { + \hbox_set:Nn \l__cellprops_cell_box { + \vbox_top:n { + \kern 0pt\relax + \box_use_drop:N \l__cellprops_cell_box + } + } + } + { bottom } { + \hbox_set:Nn \l__cellprops_cell_box { + \vbox:n { + \box_use_drop:N \l__cellprops_cell_box + \kern 0pt\relax + } + } + } + { middle } { + \hbox_set:Nn \l__cellprops_cell_box { + \dim_set:Nn \l_tmpa_dim { + (\box_dp:N \l__cellprops_cell_box + - \box_ht:N \l__cellprops_cell_box + + 1ex) / 2 + } + \raisebox{\l_tmpa_dim}{\box_use_drop:N \l__cellprops_cell_box} + } + } + } + % Handle padding-top and border-top + \__cellprops_get_border_info:n {top} + \box_set_ht:Nn \l__cellprops_cell_box { + \box_ht:N \l__cellprops_cell_box + (\__cellprops_get_property:n {padding-top}) + \l__cellprops_border_width_dim } @@ -881,12 +1037,10 @@ { \exp_not:V \l__cellprops_border_color_tl } } } - % Handle padding-bottom, min-depth and border-bottom + % Handle padding-bottom and border-bottom \__cellprops_get_border_info:n {bottom} \box_set_dp:Nn \l__cellprops_cell_box { - \dim_max:nn - {\box_dp:N \l__cellprops_cell_box} - {\__cellprops_get_property:n {min-depth}} + \box_dp:N \l__cellprops_cell_box + (\__cellprops_get_property:n {padding-bottom}) + \l__cellprops_border_width_dim } |