TransWikia.com

TikZ foreach loop with csname macro list

TeX - LaTeX Asked by GerritKi on June 11, 2021

I have a problem with a macro-defined list in a TikZ foreach loop. The macro is built by csnameendcsname.
I’ve played around with multiple expandafter or ##1 instead of #1, but with no success: The list of elements is not considered as of multiple elements then as a complete string.

Here is my MWE:

documentclass[border=10pt]{standalone}

usepackage{tikz}

% Macro to read in configuration parameters
newcommand*ReadCfg[3]{%
    expandafterxdefcsname#1#2listendcsname{#3}%
}

% Provide list for upper positions (this macro will be looped by foreach)
% jobname is 'AUT'
providecommandListUpper{%
    expandaftercsnamejobname upperlistendcsname%
}

% This configuration will be later provided by external file
ReadCfg{AUT}{upper}{Elem1,Elem2,Elem3}

begin{document}
begin{tikzpicture}
    foreach e in ListUpper {
        typeout{***spacee} % e is interpreted as "Elem1,Elem2,Elem3" instead of single elements
   }
end{tikzpicture}
end{document}

So, how can I loop throu the list of elements?

Thank you!

One Answer

documentclass[border=10pt]{standalone}

usepackage{tikz}

% Macro to read in configuration parameters
newcommand*ReadCfg[3]{%
    expandafterxdefcsname#1#2listendcsname{#3}%
}

% Provide list for upper positions (this macro will be looped by foreach)
% jobname is 'AUT'
providecommandListUpper{%
  csnamejobname upperlistendcsname%
}

% This configuration will be later provided by external file
ReadCfg{AUT}{upper}{Elem1,Elem2,Elem3}

begin{document}
begin{tikzpicture}
  edeftmpA{ListUpper}
  foreach e in tmpA {
        typeout{***spacee} % e is interpreted as "Elem1,Elem2,Elem3" instead of single elements
   }
end{tikzpicture}

end{document}

From AUT.log:

enter image description here

Answered by Steven B. Segletes on June 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP