|
| 1 | +% tabularray.4ht (2025-06-20-11:36), generated from tex4ht-4ht.tex |
| 2 | +% Copyright 2022-2025 TeX Users Group |
| 3 | +% |
| 4 | +% This work may be distributed and/or modified under the |
| 5 | +% conditions of the LaTeX Project Public License, either |
| 6 | +% version 1.3c of this license or (at your option) any |
| 7 | +% later version. The latest version of this license is in |
| 8 | +% http://www.latex-project.org/lppl.txt |
| 9 | +% and version 1.3c or later is part of all distributions |
| 10 | +% of LaTeX version 2005/12/01 or later. |
| 11 | +% |
| 12 | +% This work has the LPPL maintenance status "maintained". |
| 13 | +% |
| 14 | +% The Current Maintainer of this work |
| 15 | +% is the TeX4ht Project <http://tug.org/tex4ht>. |
| 16 | +% |
| 17 | +% If you modify this program, changing the |
| 18 | +% version identification would be appreciated. |
| 19 | +\immediate\write-1{version 2025-06-20-11:36} |
| 20 | + |
| 21 | +\NewConfigure{tabularray}{8} |
| 22 | +\NewConfigure{tabularrayignoredcell}{2} |
| 23 | +\NewConfigure{tabularrayattributes}[1]{\concat:config\CellAttributes{#1\space}} |
| 24 | +\NewConfigure{tabularraystyles}[1]{\concat:config\CellStyle{#1}} |
| 25 | +\NewConfigure{tabularraycolumnwidth}{1} |
| 26 | + |
| 27 | +\ExplSyntaxOn |
| 28 | +\NewConfigure{tabularrayhalign}[2]{% |
| 29 | + \cs_set:cpn{tabularray_halign:#1}{#2} |
| 30 | +} |
| 31 | + |
| 32 | +\NewConfigure{tabularrayvalign}[2]{% |
| 33 | + \cs_set:cpn{tabularray_valign:#1}{#2} |
| 34 | +} |
| 35 | +\ExplSyntaxOff |
| 36 | + |
| 37 | +\ExplSyntaxOn |
| 38 | +\long\def\:tempa#1#2#3#4{% |
| 39 | + % insert <table>...</table> |
| 40 | + \a:tabularray\o:__tblr_environ_code:nnnn:{#1}{#2}{#3}{#4}\b:tabularray |
| 41 | +} |
| 42 | +\HLet\__tblr_environ_code:nnnn\:tempa |
| 43 | + |
| 44 | +\long\def\:tempa#1{\int_set:Nn \c@rownum {#1}\xdef\HRow{\@arabic\c@rownum}\c:tabularray\o:__tblr_build_row:N:{#1}\d:tabularray} |
| 45 | +\HLet\__tblr_build_row:N\:tempa |
| 46 | +\ExplSyntaxOff |
| 47 | + |
| 48 | +% disable rules |
| 49 | +\ht:special{t4ht@_} |
| 50 | +\ExplSyntaxOn |
| 51 | +% #1 row number, #2 column, #3 hline number (there can be multiple), #4 css property to be set |
| 52 | +\def\:tblr:hlinestyle#1#2#3#4{ |
| 53 | + % get line height |
| 54 | + \tl_set:Ne \l__tblr_h_tl{ \__tblr_spec_item:ne { hline } { [#1](#3) / @hline-height } } |
| 55 | + % get dash style |
| 56 | + \def\@tblr@dash{} % remove "dash" word from the variable for correct CSS string |
| 57 | + \tl_set:Ne \l__tblr_f_tl{\__tblr_spec_item:ne { hline } { [#1][#2](#3) / @dash }} |
| 58 | + % create CSS only when a dash style is set |
| 59 | + \tl_if_empty:NF\l__tblr_f_tl{ |
| 60 | + % get hline color |
| 61 | + \tl_set:Ne \l__tblr_g_tl { \__tblr_spec_item:ne { hline } { [#1][#2](#3) / fg } } |
| 62 | + \def\:hlinecolor{\#000000} |
| 63 | + % convert color to CSS value if color is set |
| 64 | + \tl_if_empty:NF\l__tblr_g_tl{\get:xcolorcss{\l__tblr_g_tl}\:hlinecolor} |
| 65 | + % \Configure{tabularraystyles} doesn't expand attributes, so we need to expand it here |
| 66 | + % otherwise, we would get wrong color and hline style in the last row, because this macro is called twice here |
| 67 | + \cs_set:ce{#4:}{#4:\dim_to_decimal_in_unit:nn{\l__tblr_h_tl*2}{1px}px~\l__tblr_f_tl\space~\:hlinecolor;} |
| 68 | + \Configure{tabularraystyles}{\csname#4:\endcsname} |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +\def\:tblr:vlinestyle#1#2#3#4{ |
| 73 | + \tl_set:Ne \l__tblr_t_tl{ \__tblr_spec_item:ne { vline } { [#2](#3) / @vline-width } } |
| 74 | + \def\@tblr@dash{} % remove "dash" word from the variable for correct CSS string |
| 75 | + \tl_set:Ne \l__tblr_f_tl{\__tblr_spec_item:ne { vline } { [#1][#2](#3) / @dash }} |
| 76 | + \tl_if_empty:NF\l__tblr_f_tl{ |
| 77 | + \tl_set:Ne \l__tblr_g_tl { \__tblr_spec_item:ne { vline } { [#1][#2](#3) / fg } } |
| 78 | + \def\:hlinecolor{\#000000} |
| 79 | + % convert color to CSS value if color is set |
| 80 | + \tl_if_empty:NF\l__tblr_g_tl{\get:xcolorcss{\l__tblr_g_tl}\:hlinecolor} |
| 81 | + % \Configure{tabularraystyles} doesn't expand attributes, so we need to expand it here |
| 82 | + % otherwise, we would get wrong color and hline style in the last row, because this macro is called twice here |
| 83 | + \cs_set:ce{#4:}{#4:\dim_to_decimal_in_unit:nn{\l__tblr_t_tl*2}{1px}px~\l__tblr_f_tl\space~\:hlinecolor;} |
| 84 | + \Configure{tabularraystyles}{\csname#4:\endcsname} |
| 85 | + } |
| 86 | +} |
| 87 | +\ExplSyntaxOff |
| 88 | + |
| 89 | +\ExplSyntaxOn |
| 90 | +\long\def\:tempa#1#2{% |
| 91 | +% find columns that are covered by rowspan and colspan |
| 92 | + \xdef\HCol{\@arabic\c@colnum} |
| 93 | + \xdef\HRow{\@arabic\c@rownum} |
| 94 | + \xdef\HMultispan{\lTblrCellColSpanInt} |
| 95 | + \xdef\HRowspan{\lTblrCellRowSpanInt} |
| 96 | + \let\CellAttributes\@empty |
| 97 | + \let\CellStyle\@empty |
| 98 | + % calculate ignored cells, if the current cell uses colspan or rowspan |
| 99 | + \int_step_inline:nnn{\c@rownum }{\c@rownum - 1 + \lTblrCellRowSpanInt}{ |
| 100 | + \int_step_inline:nnn{\c@colnum }{\c@colnum - 1 + \lTblrCellColSpanInt}{ |
| 101 | + % the loop always matches the current cell, we must ignore it |
| 102 | + \str_if_eq:eeF{\HCol.\HRow}{####1.##1}{% |
| 103 | + \cs_gset:cpn{ignoredcell-####1-##1}{} |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + \cs_if_exist_use:c{tabularray_halign:\g__tblr_cell_halign_tl} |
| 108 | + \cs_if_exist_use:c{tabularray_valign:\g__tblr_cell_valign_tl} |
| 109 | + % the vertical aligment can be set also in \g__tblr_cell_middle_tl, so we should try it as well |
| 110 | + \cs_if_exist_use:c{tabularray_valign:\g__tblr_cell_middle_tl} |
| 111 | + % calculate column width |
| 112 | + \dim_compare:nNnT {\__tblr_data_item:nen{column}{\HCol}{@col-width}} > {0pt}{ |
| 113 | + \__tblr_get_table_width:% initialize \tablewidth |
| 114 | + \edef\HColWidth{\fp_eval:n{\__tblr_data_item:nen{column}{\HCol}{@col-width}/\tablewidth*100}\%} |
| 115 | + % save table width, preferably in CSS |
| 116 | + \a:tabularraycolumnwidth% |
| 117 | + } |
| 118 | + % there can be multiple hlines for each cell, but we only suport the first one, because of limitations of CSS |
| 119 | + \:tblr:hlinestyle{#1}{#2}{1}{border-top} |
| 120 | + \int_compare:nNnT{\HRow + \HRowspan - 1} = {\c@rowcount}{% |
| 121 | + % draw hline below the last row |
| 122 | + \:tblr:hlinestyle{\int_eval:n{\c@rownum + 1}}{#2}{1}{border-bottom} |
| 123 | + } |
| 124 | + % the same is true for vlines |
| 125 | + \:tblr:vlinestyle{#1}{#2}{1}{border-left} |
| 126 | + \int_compare:nNnT{\HCol + \HMultispan - 1} = {\c@colcount}{% |
| 127 | + % draw hline below the last row |
| 128 | + \:tblr:vlinestyle{#1}{\int_eval:n{\c@colnum + 1}}{1}{border-right} |
| 129 | + } |
| 130 | + % support for the background color |
| 131 | + \tl_set:Ne \l__tblr_b_tl |
| 132 | + { \__tblr_data_item:neen { cell } {#1} {#2} { background } } |
| 133 | + % save background color to the list of CSS, if it is set |
| 134 | + \tl_if_empty:NF \l__tblr_b_tl{ |
| 135 | + \get:xcolorcss{\l__tblr_b_tl}\:bgcolor |
| 136 | + \Configure{tabularraystyles}{background-color: \:bgcolor;} |
| 137 | + } |
| 138 | + % We can use something like \Configure{tabularrayattributes}{rowspan="\HRowspan"} in \Configure{tabularray} |
| 139 | + % to declare correct attributes for joined cells |
| 140 | + \int_compare:nNnT {\HRowspan} > {1}{\g:tabularray} |
| 141 | + \int_compare:nNnT {\HMultispan} > {1}{\h:tabularray} |
| 142 | + \cs_if_exist:cTF{ignoredcell-\the\c@colnum-\the\c@rownum}{% |
| 143 | + \a:tabularrayignoredcell\e:tabularray\o:__tblr_build_cell_content:NN:{#1}{#2}\f:tabularray\b:tabularrayignoredcell |
| 144 | + }{% |
| 145 | + \e:tabularray\o:__tblr_build_cell_content:NN:{#1}{#2}\f:tabularray |
| 146 | + } |
| 147 | + % the ignored cell is global, so we must undefine it after the thes |
| 148 | + \cs_undefine:c{ignoredcell-\the\c@colnum-\the\c@rownum}% |
| 149 | +} |
| 150 | +\HLet\__tblr_build_cell_content:NN\:tempa |
| 151 | + |
| 152 | +\HLet\__tblr_get_vcenter_box:N\:gobble |
| 153 | + |
| 154 | + |
| 155 | +\ExplSyntaxOff |
| 156 | + |
| 157 | +\Hinput{tabularray} |
| 158 | +\endinput |
| 159 | + |
0 commit comments