%%
%% 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-2019 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}[2018/06/19]
\def\ExplFileName{cellprops}
\def\ExplFileDescription{CSS-like cell and table properties}
\def\ExplFileDate{2019/09/29}
\def\ExplFileVersion{1.6}
\ProvidesExplPackage
  {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}

\RequirePackage{xparse}
\RequirePackage{xcolor}
\RequirePackage{etoolbox}
\RequirePackage{mdwtab}
\cs_set_nopar:Npn \tab@pop #1 { \tl_set:Nx #1 { \tl_tail:N #1 } }
\cs_new: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_new_protected_nopar:Nn \__cellprops_get_property:nN {
    \tl_if_exist:cTF { l__cellprops_property_value_#1_tl } {
        \tl_set_eq:Nc #2 { l__cellprops_property_value_#1_tl }
    }{
        \tl_clear:N #2
    }
}
\cs_new_protected:Nn \__cellprops_define_properties:nn {
    \clist_map_inline:nn {#2} {
        \cs_set:cpn { __cellprops_property_type_##1:nn } {#1}
    }
}
\cs_new:Nn \__cellprops_delegate_setter:nn {
    \use:c {__cellprops_property_type_#1:nn} {#1} {#2}
}
\cs_new_protected:Nn \__cellprops_use_setter:nn {
    \use:x {
        \__cellprops_delegate_setter:nn {#1} {#2}
    }
}
\cs_new_protected:Nn \__cellprops_parse_properties:Nn {
    \tl_clear:N #1
    \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} = { 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 } {
                    \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
            }
        }
    }
}

\cs_new:Nn \__cellprops_fourval_setter:nnnnnn {
    \__cellprops_fourval_setter_aux:w
        {#1}{#2}{#3}{#4}#6~{\q_no_value}~{\q_no_value}~{\q_no_value}~\q_stop
}
\cs_new:Npn \__cellprops_fourval_setter_aux:w #1#2#3#4#5~#6~#7~#8~#9\q_stop {
    \__cellprops_delegate_setter:nn {#1} {#5}
    \quark_if_no_value:nTF {#6} {
        \__cellprops_delegate_setter:nn {#2} {#5}
        \__cellprops_delegate_setter:nn {#4} {#5}
    }{
        \__cellprops_delegate_setter:nn {#2} {#6}
        \quark_if_no_value:nTF {#8} {
            \__cellprops_delegate_setter:nn {#4} {#6}
        }{
            \__cellprops_delegate_setter:nn {#4} {#8}
        }
    }
    \quark_if_no_value:nTF {#7} {
        \__cellprops_delegate_setter:nn {#3} {#5}
    }{
        \__cellprops_delegate_setter:nn {#3} {#7}
    }
}

\cs_new_protected:Nn \__cellprops_define_fourval_properties:nnnnnn {
    \__cellprops_define_properties:nn {#1} { #3, #4, #5, #6 }
    \__cellprops_define_properties:nn {
        \__cellprops_fourval_setter:nnnnnn {#3}{#4}{#5}{#6}
    }{
        #2
    }
}

\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_e: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}
    }
}

\cs_new_nopar:Nn \__cellprops_linewidth_setter:nn {
    \str_case:nnF {#2} {
        {thin}   { \__cellprops_generic_setter:nnn \exp_not:n {#1} { \fboxrule} }
        {medium} { \__cellprops_generic_setter:nnn \exp_not:n {#1} { 2\fboxrule} }
        {thick}  { \__cellprops_generic_setter:nnn \exp_not:n {#1} { 3\fboxrule} }
    }{
        \__cellprops_generic_setter:nnn \exp_not:n {#1} {#2}
    }
}

\cs_new_nopar:Nn \__cellprops_border_setter:nn {
    \__cellprops_border_setter_aux:nw
        {#1}#2~{\q_no_value}~{\q_no_value}~\q_stop
}
\cs_new:Npn \__cellprops_border_setter_aux:nw #1#2~#3~#4~#5\q_stop {
    \quark_if_no_value:nTF {#4} {
        \__cellprops_border_setter_isstyle:nTF {#2} {
            \__cellprops_delegate_setter:nn {#1-width} {thin}
            \__cellprops_delegate_setter:nn {#1-style} {#2}
            \quark_if_no_value:nTF {#3} {
                \__cellprops_delegate_setter:nn {#1-color} {inherit}
            }{
                \__cellprops_delegate_setter:nn {#1-color} {#3}
            }
        }{
            \quark_if_no_value:nTF {#3} {
                %% TODO: Error, one no-style value, ambiguous
            }{
                \__cellprops_border_setter_isstyle:nTF {#3} {
                    \__cellprops_delegate_setter:nn {#1-width} {#2}
                    \__cellprops_delegate_setter:nn {#1-style} {#3}
                    \__cellprops_delegate_setter:nn {#1-color} {inherit}
                }{
                    \__cellprops_delegate_setter:nn {#1-width} {#2}
                    \__cellprops_delegate_setter:nn {#1-style} {none}
                    \__cellprops_delegate_setter:nn {#1-color} {#3}
                }
            }
        }
    }{
        \__cellprops_delegate_setter:nn {#1-width} {#2}
        \__cellprops_delegate_setter:nn {#1-style} {#3}
        \__cellprops_delegate_setter:nn {#1-color} {#4}
    }
}
\cs_new:Npn \__cellprops_border_setter_isstyle:nTF #1 {
    \str_case:nnTF {#1} {
        {none}{} {hidden}{} {dotted}{} {dashed}{} {solid}{}
        {double}{} {groove}{} {ridge}{} {inset}{} {outset}{}
    }
}

\__cellprops_define_properties:nn {
    \__cellprops_generic_setter:nnn \exp_not:n
}{
    min-height,
    min-depth,
    min-width,
}

\__cellprops_define_fourval_properties:nnnnnn
    { \__cellprops_generic_setter:nnn \exp_not:n }
    {padding}
    {padding-top}{padding-right}{padding-bottom}{padding-left}

\__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,
}

\__cellprops_define_fourval_properties:nnnnnn
    { \__cellprops_linewidth_setter:nn }
    {border-width}
    {border-top-width}{border-right-width}
    {border-bottom-width}{border-left-width}

\__cellprops_define_fourval_properties:nnnnnn
    { \__cellprops_generic_setter:nnn \tl_to_str:n }
    {border-style}
    {border-top-style}{border-right-style}
    {border-bottom-style}{border-left-style}

\__cellprops_define_fourval_properties:nnnnnn
    { \__cellprops_color_setter:nn }
    {border-color}
    {border-top-color}{border-right-color}
    {border-bottom-color}{border-left-color}

\__cellprops_define_properties:nn {
    \__cellprops_border_setter:nn
}{
    border, border-top, border-right, border-bottom, border-left
}

\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
}

\tl_new:N \l__cellprops_parse_tmp_tl
\NewDocumentCommand \__cellprops_parse_css:w { lmu{\q_stop} } {
    \quark_if_nil:nF {#2} {
        \__cellprops_parse_properties:Nn \l__cellprops_parse_tmp_tl {#2}
        \clist_map_inline:nn {#1} {
            \__cellprops_parse_css_addprops:nV {##1} \l__cellprops_parse_tmp_tl
        }
        \__cellprops_parse_css:w #3 \q_stop
    }
}

\seq_new:N \l__cellprops_parse_selector_seq
\tl_new:N \l__cellprops_parse_desc_tl

\str_const:Nn \c__cellprops_parse_nthchild_str { :nth-child( }
\prop_new:N \c__cellprops_parse_replace_prop
\prop_put:Nnn \c__cellprops_parse_replace_prop { :first-child } { :nth-child(1) }

\cs_new_protected:Nn \__cellprops_parse_selector:Nn {
    \str_set:Nx \l_tmpa_str {#2}
    \prop_map_inline:Nn \c__cellprops_parse_replace_prop {
        \use:x {
            \exp_not:n { \tl_replace_all:Nnn \l_tmpa_str }
            { \tl_to_str:n { ##1 } } { \tl_to_str:n { ##2 } }
        }
    }
    \tl_replace_all:Nnn \l_tmpa_str {~} {\q_stop}
    \exp_args:NNVV
        \seq_set_split:Nnn \l_tmpa_seq \c__cellprops_parse_nthchild_str \l_tmpa_str
    \seq_pop_left:NN \l_tmpa_seq \l_tmpa_tl
    \tl_replace_all:Nnn \l_tmpa_tl {\q_stop} {~}
    \seq_clear:N \l__cellprops_parse_selector_seq
    \seq_put_right:NV \l__cellprops_parse_selector_seq \l_tmpa_tl
    \seq_map_inline:Nn \l_tmpa_seq {
        \tl_set:Nn \l_tmpa_tl { ##1 }
        \tl_replace_all:Nnn \l_tmpa_tl {\q_stop} {~}
        \tl_replace_once:Nnn \l_tmpa_tl { ) } { \q_stop\prg_do_nothing: }
        \seq_set_split:NnV \l_tmpa_seq { \q_stop } \l_tmpa_tl
        \seq_pop_right:NN \l_tmpa_seq \l__cellprops_parse_desc_tl
        \tl_replace_once:Nnn \l__cellprops_parse_desc_tl { \prg_do_nothing: } {}
        \seq_get_left:NNT \l_tmpa_seq \l_tmpa_tl {
            \exp_args:NNV \__cellprops_parse_nth:Nn \l_tmpa_tl \l_tmpa_tl
            \tl_put_left:Nn \l__cellprops_parse_desc_tl { ) }
            \tl_put_left:NV \l__cellprops_parse_desc_tl \l_tmpa_tl
        }
        \seq_put_right:NV \l__cellprops_parse_selector_seq \l__cellprops_parse_desc_tl
    }
    \tl_set:Nx #1 {
        \exp_args:NNV \seq_use:Nn
            \l__cellprops_parse_selector_seq \c__cellprops_parse_nthchild_str
    }
}

\str_const:Nn \c__cellprops_parse_n_str {n}
\seq_new:N \l__cellprops_used_nth_factors_seq
\cs_new_protected:Nn \__cellprops_parse_nth:Nn {
    \str_case:nnF {#2} {
        {even} { \str_set:Nn \l_tmpa_str {2n} }
        {odd}  { \str_set:Nn \l_tmpa_str {2n+1} }
    }{
        \str_set:Nn \l_tmpa_str {#2}
    }
    \exp_args:NNVV
        \seq_set_split:Nnn \l_tmpa_seq \c__cellprops_parse_n_str \l_tmpa_str
    \seq_pop_right:NN \l_tmpa_seq \l_tmpa_tl
    \int_set:Nn \l_tmpb_int { 0\l_tmpa_tl }
    \seq_get_left:NNTF \l_tmpa_seq \l_tmpa_tl {
        \int_set:Nn \l_tmpa_int { 0\l_tmpa_tl }
    }{
        \int_zero:N \l_tmpa_int
    }
    \int_compare:nNnTF \l_tmpa_int = { 0 } {
        \tl_set:Nx #1 { \int_use:N \l_tmpb_int }
    }{
        \int_set:Nn \l_tmpb_int { \int_mod:nn {\l_tmpb_int} {\l_tmpa_int} }
        \tl_set:Nx #1 {
            \int_use:N \l_tmpa_int \exp_not:V \c__cellprops_parse_n_str
            + \int_use:N \l_tmpb_int }
        \seq_put_right:Nx
            \l__cellprops_used_nth_factors_seq { \int_use:N \l_tmpa_int }
    }
}

\cs_new_protected:Npn \__cellprops_parse_css_addprops:nV #1 #2 {
    \__cellprops_parse_selector:Nn \l_tmpa_tl {#1}
    \tl_set:Nx \l_tmpa_tl { l__cellprops_property_group_\l_tmpa_tl _tl }
    \tl_if_exist:cF { \l_tmpa_tl } { \tl_clear:c { \l_tmpa_tl } }
    \tl_put_right:cV { \l_tmpa_tl } #2
}

\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
\dim_new:N \l__cellprops_strut_ht_dim
\dim_new:N \l__cellprops_strut_dp_dim

\ExplSyntaxOff
\cellprops{
    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;
        math-mode: auto;
        color: inherit;
        background-color: transparent;
        border: thin none inherit;
    }
    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 \g__cellprops_borders_tl

\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_new_protected:Nn \__cellprops_array_init: {
    \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 }
        \exp_not:n { \tl_gset:Nn \g__cellprops_borders_tl }
            { \exp_not:V \g__cellprops_borders_tl }
    }
    \int_gzero:N \g__cellprops_row_int
    \bool_gset_false:N \g__cellprops_inrow_bool
    \tl_gclear:N \g__cellprops_borders_tl
    \cs_set_eq:NN \__cellprops_orig_tab@readpreamble:n \tab@readpreamble
    \cs_set_eq:NN \tab@readpreamble \__cellprops_readpreamble:n
    \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}
    \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
}

\cs_set_nopar:Nn \__cellprops_array_startcontent: {
    \hlx{s[\l__cellprops_tablepadding_top_dim]}
}

\cs_set_protected_nopar:Nn \__cellprops_readpreamble:n {
    \cs_set_eq:NN \tab@readpreamble \__cellprops_orig_tab@readpreamble:n
    \tl_put_left:Nn \tab@multicol {\__cellprops_startrow:}
    \tl_put_left:Nn \tab@tabtext {\int_gincr:N \g__cellprops_col_int}
    \tab@readpreamble{#1}
    \exp_args:Nx \tab@preamble
        { \exp_not:N\__cellprops_startrow: \the\tab@preamble \exp_not:N\__cellprops_endrow: }
}
\cs_new_protected_nopar:Nn \__cellprops_update_color:Nn {
    \__cellprops_get_property:nN {#2} \l_tmpa_tl
    \exp_args:NV \tl_if_eq:NNF \l_tmpa_tl \c__cellprops_inherit_color_tl {
        \tl_set_eq:NN #1 \l_tmpa_tl
    }
}

\cs_new_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}
}
\AtEndPreamble{%
\cs_set_eq:NN \__cellprops_orig_array:w \@array
\cs_set_protected_nopar:Npn \@array[#1]#2 {
    \__cellprops_array_init:
    \__cellprops_orig_array:w [#1]{#2}
    \__cellprops_array_startcontent:
}

\cs_set_eq:NN \__cellprops_orig_LTmkpream:n \@mkpream
\cs_set_protected_nopar:Npn \@mkpream#1 {
    \group_end:
    \__cellprops_array_init:
    \group_begin:
    \__cellprops_orig_LTmkpream:n {#1}
}

\cs_set_eq:NN \__cellprops_orig_LTarray:w \LT@array
\cs_set_protected_nopar:Npn \LT@array [#1]#2 {
    \__cellprops_orig_LTarray:w [#1]{#2}
    \__cellprops_array_startcontent:
}

\cs_new_nopar:Nn \__cellprops_end_array:n {
    \tl_if_empty:NF \g__cellprops_borders_tl { \\ }
    \crcr
    \hlx{s[\l__cellprops_tablepadding_bottom_dim]}
    #1
    \tl_use:N \l__cellprops_restore_tl
}

\cs_set_eq:NN \__cellprops_orig_endarray: \endarray
\cs_set_nopar:Npn \endarray {
    \__cellprops_end_array:n { \__cellprops_orig_endarray: }
}
\cs_set_eq:NN \endtabular \endarray
\cs_set_eq:cN {endtabular*} \endarray

\cs_set_eq:NN \__cellprops_orig_endLT: \endlongtable
\cs_set_nopar:Npn \endlongtable {
    \__cellprops_end_array:n { \__cellprops_orig_endLT: }
}

\cs_new_protected_nopar:Nn \__cellprops_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_int
        \dim_gzero:N \g__cellprops_ht_dim
        \dim_gzero:N \g__cellprops_dp_dim
    }
}

\cs_new_protected_nopar:Nn \__cellprops_endrow: {
    \bool_if:NT \g__cellprops_inrow_bool {
        \bool_gset_false:N \g__cellprops_inrow_bool
    }
}

\cs_new_protected_nopar:Nn \__cellprops_cr:n {
    \__cellprops_endrow:
    \tl_if_empty:NF \g__cellprops_borders_tl {
        \cr
        \noalign{\nobreak}
        \tl_use:N \g__cellprops_borders_tl
        \tl_gclear:N \g__cellprops_borders_tl
    }
    \cr
    \__cellprops_fix_valign_end:n {#1}
    \use_none:n
}

\cs_set_protected_nopar:Npn \tab@tabcr #1#2 { \__cellprops_cr:n {#2} }
\cs_set_protected_nopar:Npn \@xargarraycr #1 { \__cellprops_cr:n {#1} }
\cs_set_protected_nopar:Npn \@yargarraycr #1 { \__cellprops_cr:n {#1} }
\tl_if_exist:NT \LT@echunk {
    \tl_put_left:Nn \LT@echunk {
        \tl_if_empty:NF \g__cellprops_borders_tl { \\ }
    }
}

\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_nopar:Nn \__cellprops_fix_valign_end:n {
    \noalign{
        \dim_set:Nn \l_tmpa_dim {#1}
        \skip_vertical:n {\l_tmpa_dim}
        \exp_args:NV \tl_if_eq:nnTF \tab@hlstate {b} {
            \dim_gadd:Nn \tab@endheight { \g__cellprops_dp_dim + \l_tmpa_dim }
        }{
            \int_compare:nNnT \g__cellprops_row_int = \c_one_int {
                \dim_gadd:Nn \tab@endheight { \g__cellprops_ht_dim }
            }
        }
    }
}
\cs_set_eq:NN \firsthline \hline
\cs_set_eq:NN \lasthline \hline

\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_seq_nthchild:Nn {
    \seq_clear:N #1
    \seq_map_inline:Nn \l__cellprops_used_nth_factors_seq {
        \seq_put_right:Nx #1 {
            ##1 n + \int_eval:n{\int_mod:nn{#2}{##1}}
        }
    }
    \seq_put_right:Nx #1 { \int_eval:n{#2} }
}

\cs_new_protected_nopar:Nn \__cellprops_begincell:n {
    \__cellprops_begin_raw_cell:n {
        #1
        \hbox_set:Nw \l__cellprops_cell_box
        \str_case_e: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_e: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_seq_nthchild:Nn \l_tmpa_seq { \g__cellprops_row_int }
        \__cellprops_seq_nthchild:Nn \l_tmpb_seq { \g__cellprops_col_int }
        \__cellprops_recall_properties:n {td~p}
        \seq_map_inline:Nn \l_tmpa_seq {
            \__cellprops_recall_properties:n {tr:nth-child(##1)~p}
        }
        \seq_map_inline:Nn \l_tmpb_seq {
            \__cellprops_recall_properties:n {td:nth-child(##1)~p}
        }
        \__cellprops_recall_properties:n {tr~td~p}
        \seq_map_inline:Nn \l_tmpa_seq {
            \__cellprops_recall_properties:n {tr:nth-child(##1)~td~p}
        }
        \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)~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
}

\cs_new_protected_nopar:Nn \__cellprops_begin_raw_cell:n {
    \group_begin:
    \__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:
    % Additional init code
    #1
    % Install the cell color
    \__cellprops_update_colors:
    \tl_use:N \l__cellprops_color_tl
}

\cs_new_protected_nopar:Nn \__cellprops_make_solid_hborder:nnn {
    \group_begin:
        \hbox_set_to_wd:Nnn \l_tmpa_box {1pt} {
            \hss
            \hbox:n {
                #3 % install color
                \vrule height~\dim_eval:n{#1+#2}
                    ~depth~-\dim_eval:n{#2}
                    ~width~3pt
            }
            \hss
        }
        \box_set_ht:Nn \l_tmpa_box { \c_zero_dim }
        \box_set_dp:Nn \l_tmpa_box { \c_zero_dim }
        \kern 1pt
        \box_use:N \l_tmpa_box
        \xleaders
            \box_use:N \l_tmpa_box
            \skip_horizontal:n {-4pt~plus~1fil}
        \box_use:N \l_tmpa_box
        \kern 1pt
        \skip_horizontal:n {0pt~plus~-1fil}
    \group_end:
}
\cs_new_protected_nopar:Nn \__cellprops_make_solid_vborder:nnn {
    \group_begin:
        \hbox_set_to_wd:Nnn \l_tmpa_box {0pt} {
            \hbox:n {
                #3 % install color
                \vrule height~\dim_eval:n{#2}~width~\dim_eval:n{#1}
            }
            \hss
        }
        \box_set_ht:Nn \l_tmpa_box { \c_zero_dim }
        \box_set_dp:Nn \l_tmpa_box { \c_zero_dim }
        \box_use:N \l_tmpa_box
    \group_end:
}
\clist_map_inline:nn {
    dotted, dashed, solid, double,
    groove, ridge, inset, outset
}{
    \cs_set_eq:cN {__cellprops_make_#1_hborder:nnn} \__cellprops_make_solid_hborder:nnn
    \cs_set_eq:cN {__cellprops_make_#1_vborder:nnn} \__cellprops_make_solid_vborder:nnn
}

\dim_new:N \l__cellprops_border_width_dim
\str_new:N \l__cellprops_border_style_str
\tl_new:N \l__cellprops_border_color_tl
\cs_new_protected_nopar:Nn \__cellprops_get_border_info:n {
    \dim_set:Nn \l__cellprops_border_width_dim {\__cellprops_get_property:n {border-#1-width}}
    \__cellprops_get_property:nN {border-#1-style} \l_tmpa_tl
    \exp_args:NNV \str_set:Nn \l__cellprops_border_style_str \l_tmpa_tl
    \tl_clear:N \l__cellprops_border_color_tl
    \cs_if_exist:cTF {__cellprops_make_\l__cellprops_border_style_str _hborder:nnn} {
        \__cellprops_update_color:Nn \l__cellprops_border_color_tl {border-#1-color}
    }{
        \dim_zero:N \l__cellprops_border_width_dim
    }
}

\cs_new_protected_nopar:Npn \__cellprops_make_hborder:nnnn #1 {
    \use:c { __cellprops_make_#1_hborder:nnn }
}
\cs_new_protected_nopar:Npn \__cellprops_make_vborder:nnnn #1 {
    \use:c { __cellprops_make_#1_vborder:nnn }
}

\cs_new_protected_nopar:Nn \__cellprops_end_raw_cell: {
    % Here \l__cellprops_cell_box must contain the contents of the cell
    %
    % Prepare the borders token list
    \int_compare:nNnT \g__cellprops_col_int = 1 {
        \tl_gclear:N \g__cellprops_borders_tl
    }
    \tl_gput_right:Nx \g__cellprops_borders_tl {
        \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}
    \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})
        + \l__cellprops_border_width_dim
    }
    \dim_compare:nNnT \l__cellprops_border_width_dim > \c_zero_dim {
        \tl_gput_right:Nx \g__cellprops_borders_tl {
            \exp_not:N \__cellprops_make_hborder:nnnn
                { \exp_not:V \l__cellprops_border_style_str }
                { \dim_use:N \l__cellprops_border_width_dim }
                {
                    \exp_not:n { \g__cellprops_dp_dim + \g__cellprops_ht_dim - }
                    \dim_use:N \l__cellprops_border_width_dim
                }
                { \exp_not:V \l__cellprops_border_color_tl }
        }
    }
    % Handle padding-bottom, min-depth 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}}
        + (\__cellprops_get_property:n {padding-bottom})
        + \l__cellprops_border_width_dim
    }
    \dim_compare:nNnT \l__cellprops_border_width_dim > \c_zero_dim {
        \tl_gput_right:Nx \g__cellprops_borders_tl {
            \exp_not:N \__cellprops_make_hborder:nnnn
                { \exp_not:V \l__cellprops_border_style_str }
                { \dim_use:N \l__cellprops_border_width_dim }
                { \exp_not:n { 0pt } }
                { \exp_not:V \l__cellprops_border_color_tl }
        }
    }
    % 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 padding-left and border-left
    \__cellprops_get_border_info:n {left}
    \skip_set:Nn \l__cellprops_left_skip
        {\__cellprops_get_property:n {padding-left} + \l__cellprops_border_width_dim}
    \dim_compare:nNnT \l__cellprops_border_width_dim > \c_zero_dim {
        \tl_gput_right:Nx \g__cellprops_borders_tl {
            \exp_not:N \__cellprops_make_vborder:nnnn
                { \exp_not:V \l__cellprops_border_style_str }
                { \dim_use:N \l__cellprops_border_width_dim }
                { \exp_not:n { \g__cellprops_dp_dim + \g__cellprops_ht_dim } }
                { \exp_not:V \l__cellprops_border_color_tl }
        }
    }
    \tl_gput_right:Nx \g__cellprops_borders_tl {
        \exp_not:n {
            \skip_horizontal:n {0pt~plus~1fil}
            \kern \c_zero_dim
        }
    }
    \__cellprops_get_border_info:n {right}
    \skip_set:Nn \l__cellprops_right_skip
        {\__cellprops_get_property:n {padding-right} + \l__cellprops_border_width_dim}
    \dim_compare:nNnT \l__cellprops_border_width_dim > \c_zero_dim {
        \tl_gput_right:Nx \g__cellprops_borders_tl {
            \exp_not:N \skip_horizontal:n
                { - \dim_use:N \l__cellprops_border_width_dim }
            \exp_not:N \__cellprops_make_vborder:nnnn
                { \exp_not:V \l__cellprops_border_style_str }
                { \dim_use:N \l__cellprops_border_width_dim }
                { \exp_not:n { \g__cellprops_dp_dim + \g__cellprops_ht_dim } }
                { \exp_not:V \l__cellprops_border_color_tl }
            \exp_not:N \skip_horizontal:n
                { \dim_use:N \l__cellprops_border_width_dim }
            \exp_not:n { \kern \c_zero_dim }
        }
    }
    % 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 {
        1sp plus 1fil
    }
    \str_case_e: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_drop:N \l__cellprops_cell_box
    \skip_horizontal:N \l__cellprops_right_skip
    \kern\c_zero_dim
    \group_end:
}
%% 
%%
%% End of file `cellprops.sty'.
