Skip to content

Commit

Permalink
Merge pull request #539 from muzimuzhi/fix/fragile-hvline-text
Browse files Browse the repository at this point in the history
Suppress full expansion of hvline text
  • Loading branch information
lvjr authored Nov 28, 2024
2 parents a012abe + 1943fca commit 6bc1176
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 21 deletions.
43 changes: 22 additions & 21 deletions tabularray.sty
Original file line number Diff line number Diff line change
Expand Up @@ -1190,8 +1190,8 @@
%%> \section{Set Hlines and Vlines}
%%% --------------------------------------------------------
\tl_const:Nn \@tblr@dash { dash }
\tl_const:Nn \@tblr@text { text }
\quark_new:N \q__tblr_dash
\quark_new:N \q__tblr_text
\regex_const:Nn \c__tblr_is_color_key_regex { ^[A-Za-z] }
Expand Down Expand Up @@ -1256,7 +1256,8 @@
{
\group_begin:
\keys_set_groups:nnn { tblr-hline } { text } {#3}
\tl_if_eq:NnF \l__tblr_hline_dash_tl { \exp_not:N \@tblr@text }
% true if "text=" is set
\tl_if_eq:NNF \l__tblr_hline_dash_tl \q__tblr_text
{
\__tblr_set_hline_num:n {#1}
\tl_clear:N \l__tblr_hline_dash_tl
Expand Down Expand Up @@ -1332,8 +1333,8 @@
\keys_define:nn { tblr-hline }
{
dash .code:n = \tl_set:Nn \l__tblr_hline_dash_tl { \exp_not:N \@tblr@dash #1 },
text .code:n = \tl_set:Nn \l__tblr_hline_dash_tl { \exp_not:N \@tblr@text #1 },
dash .code:n = \tl_set:Nn \l__tblr_hline_dash_tl { \q__tblr_dash #1 },
text .code:n = \tl_set:Nn \l__tblr_hline_dash_tl { \q__tblr_text #1 },
text .groups:n = { text },
wd .code:n = \tl_set:Nn \l__tblr_hline_wd_tl { \dim_eval:n {#1} },
fg .code:n = \tl_set:Nn \l__tblr_hline_fg_tl {#1},
Expand All @@ -1352,7 +1353,7 @@
\cs_new_protected:Npn \__tblr_hline_unknown_key:n #1
{
\prop_if_in:NnTF \g__tblr_defined_hdash_styles_prop {#1}
{ \tl_set:Nn \l__tblr_hline_dash_tl { \exp_not:N \@tblr@dash #1 } }
{ \tl_set:Nn \l__tblr_hline_dash_tl { \q__tblr_dash #1 } }
{
\regex_match:NnTF \c__tblr_is_color_key_regex {#1}
{ \tl_set:Nn \l__tblr_hline_fg_tl {#1} }
Expand All @@ -1369,7 +1370,9 @@
\__tblr_get_childs:nx {#1} { \int_use:N \c@colcount }
\clist_map_inline:Nn \l_tblr_childs_clist
{
\__tblr_set_hline_option:nnn { ##1 } { @dash } { \l__tblr_hline_dash_tl }
% prevent expansion of vline text (see issue #303)
\__tblr_set_hline_option:nnn { ##1 } { @dash }
{ \exp_not:V \l__tblr_hline_dash_tl }
\tl_if_empty:NF \l__tblr_hline_wd_tl
{
\__tblr_set_hline_option:nnn { ##1 } { wd } { \l__tblr_hline_wd_tl }
Expand Down Expand Up @@ -1498,7 +1501,8 @@
{
\group_begin:
\keys_set_groups:nnn { tblr-vline } { text } {#3}
\tl_if_eq:NnF \l__tblr_vline_dash_tl { \exp_not:N \@tblr@text }
% true if "text=" is set
\tl_if_eq:NNF \l__tblr_vline_dash_tl \q__tblr_text
{
\__tblr_set_vline_num:n {#1}
\tl_clear:N \l__tblr_vline_dash_tl
Expand Down Expand Up @@ -1574,8 +1578,8 @@
\keys_define:nn { tblr-vline }
{
dash .code:n = \tl_set:Nn \l__tblr_vline_dash_tl { \exp_not:N \@tblr@dash #1 },
text .code:n = \tl_set:Nn \l__tblr_vline_dash_tl { \exp_not:N \@tblr@text #1 },
dash .code:n = \tl_set:Nn \l__tblr_vline_dash_tl { \q__tblr_dash #1 },
text .code:n = \tl_set:Nn \l__tblr_vline_dash_tl { \q__tblr_text #1 },
text .groups:n = { text },
wd .code:n = \tl_set:Nn \l__tblr_vline_wd_tl { \dim_eval:n {#1} },
fg .code:n = \tl_set:Nn \l__tblr_vline_fg_tl {#1},
Expand All @@ -1587,7 +1591,7 @@
\cs_new_protected:Npn \__tblr_vline_unknown_key:n #1
{
\prop_if_in:NnTF \g__tblr_defined_vdash_styles_prop {#1}
{ \tl_set:Nn \l__tblr_vline_dash_tl { \exp_not:N \@tblr@dash #1 } }
{ \tl_set:Nn \l__tblr_vline_dash_tl { \q__tblr_dash #1 } }
{
\regex_match:NnTF \c__tblr_is_color_key_regex {#1}
{ \tl_set:Nn \l__tblr_vline_fg_tl {#1} }
Expand All @@ -1606,7 +1610,8 @@
{
\__tblr_spec_gput:nee { vline }
{ [##1][\int_use:N \c@colnum](\l__tblr_vline_num_tl) / @dash }
{ \l__tblr_vline_dash_tl }
% prevent expansion of vline text (see issue #303)
{ \exp_not:V \l__tblr_vline_dash_tl }
\tl_if_empty:NF \l__tblr_vline_wd_tl
{
\__tblr_spec_gput:nee { vline }
Expand Down Expand Up @@ -3446,9 +3451,8 @@
\tl_if_empty:NF \l__tblr_w_tl { \dim_set:Nn \rulewidth { \l__tblr_w_tl } }
\tl_set:Nx \l__tblr_d_tl
{ \__tblr_spec_item:ne { vline } { [#1][#2](#3) / @dash } }
\tl_set:Nx \l__tblr_a_tl { \tl_head:N \l__tblr_d_tl }
\tl_set:Nx \l__tblr_b_tl { \tl_tail:N \l__tblr_d_tl }
\exp_args:NV \tl_if_eq:NNTF \l__tblr_a_tl \@tblr@dash
\tl_if_head_eq_meaning:VNTF \l__tblr_d_tl \q__tblr_dash
{
\__tblr_get_vline_dash_style:N \l__tblr_b_tl
\xleaders \l__tblr_b_tl \vfil
Expand Down Expand Up @@ -3516,7 +3520,7 @@
{ \__tblr_spec_item:ne { hline } { [#1][#2](#3) / @dash } }
\tl_set:Nx \l__tblr_a_tl { \tl_head:N \l__tblr_d_tl }
\tl_set:Nx \l__tblr_b_tl { \tl_tail:N \l__tblr_d_tl }
\exp_args:NV \tl_if_eq:NNTF \l__tblr_a_tl \@tblr@dash
\tl_if_head_eq_meaning:VNTF \l__tblr_d_tl \q__tblr_dash
{
\__tblr_get_hline_dash_style:N \l__tblr_b_tl
\xleaders \l__tblr_b_tl \hfil
Expand Down Expand Up @@ -6606,8 +6610,6 @@
}
\tl_new:N \l__tblr_dash_value_tl
\tl_new:N \l__tblr_dash_value_head_tl
\tl_new:N \l__tblr_dash_value_tail_tl
\tl_new:N \l__tblr_width_value_tl
\tl_new:N \l__tblr_color_value_tl
Expand All @@ -6618,11 +6620,10 @@
%% get border style
\tl_set:Nx \l__tblr_dash_value_tl %% may be empty
{ \__tblr_spec_item:ne { #3 } { [#1][#2](1) / @dash } }
\tl_set:Nx \l__tblr_dash_value_head_tl { \tl_head:N \l__tblr_dash_value_tl }
\tl_set:Nx \l__tblr_dash_value_tail_tl { \tl_tail:N \l__tblr_dash_value_tl }
\exp_args:NV \tl_if_eq:NNTF \l__tblr_dash_value_head_tl \@tblr@dash
\tl_if_head_eq_meaning:VNTF \l__tblr_dash_value_tl \q__tblr_dash
{
\tl_set_eq:cN { lTblrCell #4 BorderStyleTl } \l__tblr_dash_value_tail_tl
\tl_set:ce { lTblrCell #4 BorderStyleTl }
{ \tl_tail:N \l__tblr_dash_value_tl }
%% get border width
\tl_set:Nx \l__tblr_width_value_tl
{ \__tblr_spec_item:ne { #3 } { [#1][#2](1) / wd } }
Expand Down
1 change: 1 addition & 0 deletions testfiles/hvline-004.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e1c300e619803038d1f20340e4780598
Binary file added testfiles/hvline-004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions testfiles/hvline-004.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
\documentclass{article}
\usepackage[b5paper,margin=1cm]{geometry}
\pagestyle{empty}

\input{regression-test}

\usepackage{tabularray}

\SetTblrTracing{none}
\setlength\parindent{0pt}
\setbox0=\hbox{$h$\small$h$}

\begin{document}

\START
\hrule\bigskip

\BEGINTEST{empty text}
\begin{tblr}{
hlines,
vlines,
hline{1}={text={}},
vline{1}={text={}},
}
a
\end{tblr}
\ENDTEST

\bigskip\hrule\bigskip

% lvjr/tabularray#303
\BEGINTEST{fragile text}
\begin{tblr}{
hlines,
vlines,
hline{1}={text={\def\x{}\rlap{--h--}}},
vline{1}={text={\textbf{v}}},
}
a
\end{tblr}
\ENDTEST

\end{document}
12 changes: 12 additions & 0 deletions testfiles/hvline-004.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
============================================================
TEST 1: empty text
============================================================
============================================================
============================================================
TEST 2: fragile text
============================================================
============================================================
[1
] (hvline-004.aux)

0 comments on commit 6bc1176

Please sign in to comment.