2

I need to return an iterable list (that will be used in another steps) from an previous list that includes expandable content (variables and math operations).

\def \scale {1} 
\pgfmathparse{\scale * 0.6}\edef\hc{\pgfmathresult}
%morphology coordinates x,y,..
\newcommand*{\xMorph}{0,0,0,0, 0, 0,0,0, \hc*0.5,-\hc*0.5,0,0,0, -\effdepth*0.5}

The approach that was used include an intermediate step for expand the list, but after the process the list isn´t iterable as is requested to it.

%expand aux func
\newcommand*{\expandlist}[1]{%
\edef\resultado{}
\foreach \i [remember=\i as \li (initially 0), evaluate=\i as \r using \i+\li]in {#1}{  
     \resultado{ \resultado \r}%
    }
}

A simple test, like a for loop to obtain a single element one at time,

\begin{document}
%first case
\xMorph
%second case
\expandafter\def\expandafter\xLp\expandafter{\expandlist{\xMorph}}
\xLp
%third case
\foreach \k [count=\cn] in {\xLp}{\cn}

From the previus code, the results are: first one is the list without expansion (wrong), the second one is the list expanded but as a single element (1) as it shown in the count variable (\cn) derived from the for-loop.

0,0,0,0, 0, 0,0,0, 0.6*0.5,-0.6*0.5,0,0,0, -0.5*0.5   000000000.3-0.3000-0.25 1

any ideas will be well received.

  • 2
    \expandlist is not expandable, as it starts with \def. – egreg Sep 05 '18 at 20:07
  • Thanks @egreg. Totally agree with you, my mistake; but after the change the result is the same. – Rene Valenzuela Sep 05 '18 at 20:17
  • It seems necessary to understand what you're really after: can you give an example of the expected output? – egreg Sep 05 '18 at 20:19
  • Ok. I need an iterable list like \foreach \k [count=\cn] in {4,5,6}{\cn} with a output: 123 – Rene Valenzuela Sep 05 '18 at 20:23
  • If you just want this output, you could simply do \xdef\mylst{} \foreach \k [count=\cn] in {4,5,6}{\xdef\mylst{\mylst\cn}}. I guess there is more to the story, isn't it? –  Sep 05 '18 at 20:43
  • The best way to implement a storage array is to use \csname ...\endcsname. See https://tex.stackexchange.com/questions/346260/display-item-list-in-sequential-and-random-without-repetition-order/346285?s=2|14.4647#346285 for example. – John Kormylo Sep 05 '18 at 20:53
  • Thanks @marmot, and yes indeed. What i want to say was that the desired output was a iterable element, exemplified as the count number iterable \cn. But the main goal is that i can make a list={a+b+c, d*0.5+4...} that cointains some algebraic expression inside and need to be "evaluate" (like \evaluate\list={} ... output: {1, 3.443, ....}) keeping the iterability before to pass to another function (foreach \i in {\list}{ \code}) . The final goal is obtain a list with variables and algebraic operations that can be modify. – Rene Valenzuela Sep 05 '18 at 21:12
  • I have no idea how to do this in general, but I am sure @egreg does. However, this sounds a little bit as if you were interested in tikzmath. There you will be able to define recursive relations and so on, just look for "Fibonacci" in the pgfmanual. TikZ also allows you to build and parse arrays. –  Sep 05 '18 at 21:23
  • See listofitems package for absorbing a list that can be regurgitated at will. If you were to put together a complete MWE, rather than just code snippets, I might be able to do something with it. – Steven B. Segletes Sep 24 '18 at 16:26

0 Answers0