I want to define the following command, which is to render an arbitrary number of subfigures. The argument is a nested list:

\multifig{{{fig_1, T0D0, TODO}, {fig_2, T0D0, TODO}}}

Is the following possible?

\foreach \x in #1 {
    % here I need the element at index 1 of the list \x. how?
    \customfig{\x at 1}

Thank you.

  • Do you need to use pgffor or would another solution be accepted? – TeXnician Jun 2 '17 at 14:22
  • I'm happy with any way to loop over a list of lists and then access the inner list by index. – Gerry Jun 2 '17 at 14:23
  • What do fig_1, T0D0 and TODO represent? Perhaps you want to access all three items. Can you specify more clearly what \customfig should do? – egreg Jun 2 '17 at 20:43
  • fig_1 is the name of a figure. T0D0 and TODO are captions. I want to access all of them, but they represent different things. So I need to access each one by index explicitly. – Gerry Jun 3 '17 at 10:36

The following code gives you access to a specific item of a (sub)list using expl3.

In its current state it will produce a figure with subfigures and the first item of the sublist printed (change \__gerry_customfig to alter that behavior). Please note that I have set the subfigures to a fixed width by now (I do not know your \somewidth).


\clist_new:N \l__gerry_mycl
\cs_new:Npn \__gerry_customfig:n #1 {
\clist_set:Nn \l__gerry_mycl {#1}
\clist_map_inline:Nn \l__gerry_mycl {
    \clist_set:Nn \l_tmpa_clist {##1}
    \exp_args:Nx \__gerry_customfig:n {\clist_item:Nn \l_tmpa_clist {1}}

\multifig{{fig_1, T0D0, TODO}, {fig_2, T0D0, TODO}}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.