4

According to my lights, the following code should typeset 212. However, my lights are obviously on the dark side as I actually get 111. How can I change the code to work as expected?

\documentclass{article}
\usepackage{xparse}
\begin{document}
\ExplSyntaxOn
\NewDocumentCommand \mylist {m}
{
  \clist_map_inline:nn { #1 }
  {
    \seq_set_split:Nnn \l_tmpa_seq { : } { ##1 }
    \seq_count:N \l_tmpa_seq
  }
}
\ExplSyntaxOff
\mylist{tikz:something,somethingelse,tikz:thirdthing}
\end{document}

The purpose of this is to process a sequence of images with potentially different options. For example,

\mylist{tikz:first-tikz-input,{graphics={width=.2\textwidth},rotate=30}:example-image-a,tikz:second-tikz-input}

I've tried using \clist_map_variable: instead of \clist_map_inline:. I've also tried generating \seq_set_split:Nno and \seq_set_split:Nnx, but whatever I try, the items stubbornly refuse to be split at the : delimiters.

Can I store sequences in sequences with expl3 suggests this may not be possible directly (if nesting sequences in comma-separated lists is relevantly like nesting them in sequences). However, the descriptions in the documentation suggest that nesting them should now be possible, so I'm not sure if those answers are current.

cfr
  • 198,882
  • I think the problem is really the : which has a special meaning in expl3, that's why I use / or ! in such cases –  May 02 '17 at 18:12
  • This could be related to https://tex.stackexchange.com/questions/302387/real-colons-in-a-expl3-context –  May 02 '17 at 18:18
  • egreg will frown on the 'ineffectiveness' of \clist_map_inline, but using \seq_set_from_clist:Nn may be too much... –  May 02 '17 at 18:23
  • @ChristianHupfer I'm such an idiot. Of course, you are surely right. I'm so used to : being a safe splitter in Forest/TikZ, but, of course, it can't be here. Although the documentation does not mention this .... – cfr May 02 '17 at 18:37
  • @ChristianHupfer Why is it 'ineffective'? – cfr May 02 '17 at 18:38
  • I think it's the internal storage mechanism/representation of the \seq variable compared to the \clist - type –  May 02 '17 at 19:27

1 Answers1

3

Here's a crude by-pass, generating a variant of \seq_set_split:Nnn with NVn that explicitly uses V as value expansion of the delimiter \c_colon_str in order to force a literal : there.

\documentclass{article}
\usepackage{xparse}
\begin{document}
\ExplSyntaxOn

\cs_generate_variant:Nn \seq_set_split:Nnn {NVn,cVn}
\NewDocumentCommand \mylist {m}
{
  \clist_map_inline:nn {#1} {
    \seq_set_split:NVn \l_tmpa_seq { \c_colon_str } { ##1 }
    \seq_count:N \l_tmpa_seq
  }
}
\ExplSyntaxOff
\mylist{tikz:something,somethingelse,tikz:thirdthing}
\end{document}

The output is 212 there, i.e. 2 items for the first, 1 item for 2nd and 2 items for 3rd 'seq' again.

  • Actually, I've just changed : to |. But you definitely deserve the tick! – cfr May 02 '17 at 18:40
  • @cfr: Yes, as I wrote in a comment above: I use / or ! or have a code where the separator is stored in \prop list before, which is used as string then –  May 02 '17 at 19:29
  • Oh, you understand the \prop stuff ;). Good for you. (I don't.) – cfr May 03 '17 at 00:18
  • @cfr: \prop is one of my favourite concepts of expl3. –  May 03 '17 at 16:15
  • Hmm ... maybe I should read that bit of the manual. What is it for? – cfr May 03 '17 at 21:23
  • @cfr: Think of \prop variables as hashes or as the expl3 approach of arrays. –  May 04 '17 at 13:54
  • Thanks. That doesn't actually help much but the idea of an array does mean something to me. – cfr May 04 '17 at 21:27