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.

6
  • I think the problem is really the : which has a special meaning in expl3, that's why I use / or ! in such cases
    – user31729
    May 2, 2017 at 18:12
  • This could be related to tex.stackexchange.com/questions/302387/…
    – user31729
    May 2, 2017 at 18:18
  • egreg will frown on the 'ineffectiveness' of \clist_map_inline, but using \seq_set_from_clist:Nn may be too much...
    – user31729
    May 2, 2017 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 2, 2017 at 18:37
  • @ChristianHupfer Why is it 'ineffective'?
    – cfr
    May 2, 2017 at 18:38

1 Answer 1

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.

7
  • Actually, I've just changed : to |. But you definitely deserve the tick!
    – cfr
    May 2, 2017 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
    – user31729
    May 2, 2017 at 19:29
  • Oh, you understand the \prop stuff ;). Good for you. (I don't.)
    – cfr
    May 3, 2017 at 0:18
  • @cfr: \prop is one of my favourite concepts of expl3.
    – user31729
    May 3, 2017 at 16:15
  • Hmm ... maybe I should read that bit of the manual. What is it for?
    – cfr
    May 3, 2017 at 21:23

You must log in to answer this question.

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