Apologies for an unclear title; I'm not sure how to describe what it is I want to do (please feel free to edit my tags). But here is my best shot:
I have a collection of data; each datum is an ordered pair of text. Let's suppose that for each datum, I can make a corresponding macro that "knows" both its pieces of text. I don't know how such a macro would work, but let's say that the macro \mynumber represents (six,two) and \mycolor represents (blue,red).
What I'd like is a macro \arrange such that compiling
Lorem ipsum \mynumber, dolor sit amet \mycolor, etc...
\arrange
produces
Lorem ipsum six, dolor sit amet blue, etc...
two, red
The key property I am looking for is that \arrange presents the second entries in the order that the data were mentioned in the text above. That is, if I edit the first part of my document so that \mycolor occurs before \mynumber, I want two and red to switch positions below.
What I hope to avoid is having to separately specify the order I will mention the data in the first part of my text, and then passing it to \arrange; the whole point is that I want to be able to edit the first part of my document carefree, and have the second entries of my data appear below in the right order, without having to painstakingly reorder anything elsewhere in the document by hand.
The greater the versatility of the output formatting of \arrange, the better - e.g., if I change my mind and want \arrange to put its results on separate lines instead of being separated by commas, I'd like that to be possible.
