I'm trying to write a Tex command that automatically prints out attribution information for images I use in my document. I created 2 different commands. The first one is \nounattr (with 3 parameters) which takes the image's name, the author and the link of the image. The second command is \printnounattrs which has no arguments, but should simply print a list of all attributions added before using \nounattr. I was able to implement these commands and get a simple list, but I cannot add any styling to the list whatsoever.

Indeed some commands like \textit are not expandable, which means that they can't be used in an \edef context. There are many questions about this concept on this site, for example tex.stackexchange.com/q/35039/35864 and linked questions.
– moeweJan 4 '19 at 9:17

1

You may want to look into 'list' implementations from etoolbox or expl3 instead. I think they can usually deal with these things as they don't go full \edef on the contents.
– moeweJan 4 '19 at 9:21

@moewe Thanks for your help so far. I can't use \def as it causes TeX to go out of memory for some reason. I will take a look at the list implementations you mentioned :)
– Pieter VerschaffeltJan 4 '19 at 9:22

Yes, I realised that after I had a closer look at what the code was doing. I have removed the \def suggestion from my comment.
– moeweJan 4 '19 at 9:23

1

Here's one that should work: \expandafter\def\expandafter\printnounattrs\expandafter{\printnounattrs instead of \edef\printnounattrs{\printnounattrs
– moeweJan 4 '19 at 9:25

While the \edef would try to expand everything in its argument as far as possible, the \expandafter\def\expandafter\printnounattrs\expandafter{\printnounattrs expands only the \printnounattrs in the definition exactly once, which means that we can concatenate our list as expected. (The simple \def\printnounattrs{\printnounattrs...} would lead to an infinite loop because that would to define the macro \printnounattrs to expand to \printnounattrs.)

Note that with this approach \url suffers from its usual issues that the URL can't contain %, #, ^^ or end with \ since it is used as an argument to a command.

If I were to write a macro for a similar task from scratch I would probably look into using the powerful list macros of etoolbox or LaTeX3/expl3.

\edef expands all commands to the fullest. However not all commands can be expanded, like e.g. \textit because it doesn't know what to do with the text when it's not in "printing mode". If you still however want to expand other tokens while leaving e.g. \textit untouched it you could use \noexpand (or \unexpanded if multple tokens) to prevent it from expanding (whilst all the others are):