10

I'm fighting to find a good way to use colons in an expl3 context. The example uses tcolorbox for a demonstration but I ran into the problem also in other places where a colon was used to delimit an argument.

\documentclass{article}
\usepackage{expl3}
\usepackage[many]{tcolorbox}

\begin{document}
\tcbset{
 minimum for equal height group in expl/.style 2 args=
   {minimum for equal height group=#1:#2}
 }

\ExplSyntaxOn
\dim_set:Nn\l_tmpa_dim{3cm}
\tl_set:Nx\l_tpma_tl{C\tl_to_str:n{:}\exp_not:N\l_tmpa_dim}


\tcbset{
  width=3cm,
  equal~height~group=C,
  %minimum~for~equal~height~group=C\c_colon_str\l_tmpa_dim,  %breaks
  %minimum~for~equal~height~group=C\tl_to_str:n{:}\l_tmpa_dim, %breaks
  %minimum~for~equal~height~group=C:\l_tmpa_dim,             %breaks
  %minimum~for~equal~height~group=C\char_generate:nn {`\:} {12}\l_tmpa_dim, %breaks
  %minimum~for~equal~height~group=\l_tpma_tl, %breaks  
  %minimum~for~equal~height~group~in~expl={C}{3cm} %works
        }

%\char_set_catcode_other:N{:}     
%\tcbset{minimum~for~equal~height~group=C:\l_tmpa_dim} %works        
%\char_set_catcode_letter:N{:}      no longer works :-((

\ExplSyntaxOff        

%\tcbset{minimum for equal height group=C:\csname l_tmpa_dim\endcsname} %works

\begin{tcolorbox}
My first box. All boxes will get 3.5cm times 3.5cm
if the content height is not too large.
\end{tcolorbox}%
\begin{tcolorbox}
My second box.
\end{tcolorbox}%

\end{document}

Has someone other good ideas to get around the problem that the colon has catcode letter in expl3?

1
  • \edef\temp{\exp_not:N\tcbset{minimum~for~equal~height~group=C\c_colon_str\exp_not:N\l_tmpa_dim}} \temp Commented Apr 4, 2016 at 11:21

1 Answer 1

6

Broadly the issue here is mixing 'interface levels': at the code level there really should be well-defined arguments and a minimum of parsing 'within' them. As such, the ideal is 'do not use expl3 variables in the argument to a document-level command'. However, that's not always practical. As we often see, the issue here is that you can't 'generate' a colon 'on the fly' as the underlying parser needs a literal one and does no expansion. This can be sorted out using x-type expansion

\documentclass{article}
\usepackage{expl3}
\usepackage[many]{tcolorbox}

\begin{document}
\tcbset{
 minimum for equal height group in expl/.style 2 args=
   {minimum for equal height group=#1:#2}
 }

\ExplSyntaxOn
\dim_set:Nn \l_tmpa_dim { 3cm }
\exp_args:Nx \tcbset
  {
    width = 3cm,
    equal~height~group = C,
    minimum~for~equal~height~group = C \tl_to_str:n { : } \exp_not:N \l_tmpa_dim
  }
\ExplSyntaxOff        

\begin{tcolorbox}
My first box. All boxes will get 3.5cm times 3.5cm
if the content height is not too large.
\end{tcolorbox}%
\begin{tcolorbox}
My second box.
\end{tcolorbox}%

\end{document}

or with V-type expansion if storing in a variable is desirable

\tl_set:Nx \l_tmpa_tl
  {
    width = 3cm,
    equal~height~group = C,
    minimum~for~equal~height~group = C \tl_to_str:n { : } \exp_not:N \l_tmpa_dim
  }
\exp_args:NV \tcbset \l_tmpa_tl
1
  • I wouldn't call it a mixing of interface levels if one use setup commands like \tcbset or \KOMAoptions (I had a similar problem with the headwidth option of KOMA) in a package, it is more a mixing of language environments (I call this problems "multi-culti-problems"). Using x-expansion naturally work (and is like the suggestion of @HenriMenke) but like the other ideas I had I think it is a bit unelegant to have to handle one key in such a special way. Commented Apr 4, 2016 at 12:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .