Skip to content

Commit 5b61e46

Browse files
committed
Fix tblr (Michal)
1 parent 9577d2f commit 5b61e46

File tree

3 files changed

+187
-75
lines changed

3 files changed

+187
-75
lines changed

table/tabularray.4ht

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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+

table/tblr.tex

Lines changed: 27 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
%\documentclass{ximera}
2-
\title{Tables}
1+
\documentclass{ximera}
2+
\title{Tables: tblr}
33

44
%\input{preamble.tex}% Only add a preamble file if it is actually necessary for the demo/test.
55
\begin{document}
@@ -9,78 +9,31 @@
99

1010
\section{Basic Usage}
1111

12-
ximera
13-
14-
With \verb|tabular| (and \verb|center|):
15-
\begin{center}
16-
\begin{tabular}{lr}
17-
x & 1 \\
18-
y & 2 \\
19-
z & 1
20-
\end{tabular}
21-
\end{center}
22-
23-
With \verb|tabular and @{} | (and \verb|center|):
24-
\begin{center}
25-
\begin{tabular}{@{}l@{ }r@{.}}
26-
x & 1 \\
27-
y & 2 \\
28-
z & 1
29-
\end{tabular}
30-
\end{center}
31-
32-
With \verb|tabular and p{} | (and \verb|center|):
33-
\begin{center}
34-
\begin{tabular}{|p{1cm}|p{2cm}|p{3cm}|}
35-
x & 1 & 2\\
36-
y & 2 & 3\\
37-
z & 1 & 4
38-
\end{tabular}
39-
\end{center}
40-
41-
With \verb|array|:
42-
$$
43-
\begin{array}{l|r}
44-
x & 1 \\
45-
\hline
46-
y & 2 \\
47-
z & 1
48-
\end{array}
49-
$$
50-
With \verb|array and @{} and p{}|:
51-
$$
52-
\begin{array}{@{X }l@{|}p{2cm}|}
53-
x & 1 \\
54-
\hline
55-
y & 2 \\
56-
z & 1
57-
\end{array}
58-
$$
59-
60-
% \begin{tblr}{colspec={XXXX}, row{1}=purple, rowhead=1}
61-
% Alpha
62-
% & Beta & Gamma
63-
% & Delta
64-
% \\
65-
% Epsilon & Zeta & Eta
66-
% & Theta
67-
% \\
68-
% Iota
69-
% & Kappa & Lambda & Mu
70-
% \\
71-
% Nu
72-
% & Xi
73-
% & Omicron & Pi
74-
% \\
75-
% Rho
76-
% & Sigma & Tau
77-
% & Upsilon \\
78-
% Phi
79-
% & Chi
80-
% & Psi
81-
% & Omega
82-
% \\
83-
% \end{tblr}
12+
13+
\begin{tblr}{colspec={XXXX}, row{1}=purple, rowhead=1}
14+
Alpha
15+
& Beta & Gamma
16+
& Delta
17+
\\
18+
Epsilon & Zeta & Eta
19+
& Theta
20+
\\
21+
Iota
22+
& Kappa & Lambda & Mu
23+
\\
24+
Nu
25+
& Xi
26+
& Omicron & Pi
27+
\\
28+
Rho
29+
& Sigma & Tau
30+
& Upsilon \\
31+
Phi
32+
& Chi
33+
& Psi
34+
& Omega
35+
\\
36+
\end{tblr}
8437

8538
\section{Intended Outcome of Test}
8639

testXourses/tableTest.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
\maketitle
88

99
\activity{../table/tableBase}
10-
%\activity{../table/tblr}
10+
\activity{../table/tblr}
1111

1212
\end{document}

0 commit comments

Comments
 (0)