How to store to-be-credited contributors for acknowledgment later in the appendix

I know this sounds like magic, but, hey, it works!

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xparse}
\usepackage{enumitem}

\ExplSyntaxOn
\NewDocumentCommand{\addcredit}{mm}
 {
  \ebo_addcredit:nn { #1 } { #2 }
 }

\NewDocumentCommand{\printcredits}{}
 {
  \ebo_printcredits:
 }

\prop_new:N \g_ebo_credit_names_prop
\seq_new:N \g_ebo_credit_list_seq
\seq_new:N \l__ebo_credit_item_seq
\clist_new:N \l__ebo_credit_list_clist

\cs_new_protected:Nn \ebo_addcredit:nn
 {
  \prop_if_exist:cF { g_ebo_credit_ \thefigure _prop }
   {
    % create a property list and register it
    \prop_new:c { g_ebo_credit_ \thefigure _prop }
    \seq_gput_right:Nx \g_ebo_credit_list_seq { \thefigure }
   }
  \prop_if_in:cnTF { g_ebo_credit_ \thefigure _prop } { #1 }
   { % there's already credit for #1
     \prop_gput:cnx { g_ebo_credit_ \thefigure _prop }
      { #1 }
      { \prop_item:cn { g_ebo_credit_ \thefigure _prop } { #1 } , \exp_not:n { { `#2' } } }
   }
   { % no credit for #1
     \prop_gput:cnn { g_ebo_credit_ \thefigure _prop }
      { #1 }
      { { `#2' } }
   }
  \prop_gput:Nnn \g_ebo_credit_names_prop { #1 } { #1 }
 }

\cs_new_protected:Nn \ebo_printcredits:
 {
  \section{Acknowledgments}
  \begin{itemize}[align=left,leftmargin=*]
  \seq_map_inline:Nn \g_ebo_credit_list_seq
   {
    \item[\textit{Figure~##1}:] \__ebo_credit_print:n { ##1 }.
   }
  \end{itemize}
 }

\cs_new_protected:Nn \__ebo_credit_print:n
 {
  \seq_clear:N \l__ebo_credit_item_seq
  \prop_map_inline:cn { g_ebo_credit_ #1 _prop }
   {% ##1 is the author, ##2 is the list of credits
    \clist_set:Nn \l__ebo_credit_list_clist { ##2 }
    \seq_put_right:Nx \l__ebo_credit_item_seq
     {
      \clist_use:Nnnn \l__ebo_credit_list_clist { ~and~ } { ,~ } { ,~and~ }~by~
      \prop_item:Nn \g_ebo_credit_names_prop { ##1 }
     }
   }
   \seq_use:Nn \l__ebo_credit_item_seq { ;~ }
 }
\ExplSyntaxOff

\begin{document}

\begin{figure}[htp]
\caption{First figure}
\addcredit{John Doe}{Sunrise}
\addcredit{Erika Musterman}{Curry Wurst}
\end{figure}

\begin{figure}[!htp]
\caption{Second figure}
\end{figure}

\begin{figure}[!htp]
\caption{Third figure}
\addcredit{John Doe}{Sunrise}
\addcredit{John Doe}{Sunset}
\end{figure}

\begin{figure}[!htp]
\caption{Fourth figure}
\addcredit{\'Accented Aüthor}{Dawn}
\addcredit{John Doe}{Sunset}
\addcredit{John Doe}{Sunrise}
\addcredit{John Doe}{Evening}
\end{figure}

\printcredits

\end{document}

The \addcredit macro adds material to a property list linked to the figure number (so it must appear after \caption).

If the same author appears further in the same figure, the corresponding property is added the new title. The figure number is stored sequentially, so we can map through those that have \addcredit commands.

It is your responsibility that the author's name is the same in all \addcredit commands for the same figure.

The \printcredits command maps the sequence of figures with credits; for each one of them, the corresponding property list is mapped to form the required text: first the list of contributions, then the author name. If there are two contributions, they're separated by “and”; if more, there will be a comma, between two of them, except the last with “, and”. Remove the comma in the code, if you don't like the Oxford comma.

Use \addcredit for the same author in one figure one after the other, or the final order would be unpredictable.

enter image description here


Here, I try to implement the syntax requested by the OP. \mymacro{Author}{Title} should be added inside each particular figure environment, as needed, and \printacknowledgement is to be invoked at the end.

The logic is set up to handle figures with one or more acknowledgements, and to handle author repitition if the repetitions within a given figure appear adjacently in the \mymacro invocations.

\documentclass{article}
\usepackage{graphicx,ifthen}
\newcounter{myack}
\newcounter{ackx}
\newcommand\mymacro[2]{%e.g. \mymacro{Erika Mustermann}{Curry wurst}
    \stepcounter{myack}%
    \expandafter\xdef\csname ack\themyack icon\endcsname{#2}% defines e.g. \ack2icon = Curry wurst
    \expandafter\xdef\csname ack\themyack auth\endcsname{#1}% defines e.g. \ack2auth = Erika Mustermann
    \expandafter\xdef\csname ack\themyack fig\endcsname{\thefigure}% defines e.g. \ack2fig = I1
}
\def\priorfig{0}
\def\isnewfig{T}
\newcommand\printacknowledgement{%
    \section*{Acknowledgement}
        \whiledo{\value{ackx}<\value{myack}}{%                                  while nb of acknowledgment printed < nb of acknowledgment defined
        \stepcounter{ackx}%                                                          number of acknowledgment printed += 1
        \ifthenelse{
            \equal{\csname ack\theackx fig\endcsname}{\priorfig}
        }{%                                                                       if acknowledgment is about same fig as the previous one
            \def\isnewfig{F}%                                                            then \isnewfig = F
        }{%                                                                       else
            \def\isnewfig{T}%                                                            isnewfig = T (this is a new figure)
            \ifthenelse{%                                                                and thus print a dot (. - except for the very first figure)
                \equal{\priorfig}{0}%
            }{%
                %
            }{%
                .%
            }%
            \par%                                                                        and create a new paragraph
        }%
        %
        \if T\isnewfig%                                                                  ... and 
            \noindent\textit{Figure \csname ack\theackx fig\endcsname:} %                start a new line with 'Figure <name of the figure>: '
        \fi%
        \if T\isnewfig%
            %
        \else%                                                                        if its not a new figure
            \if T\showauth\relax%
                , %                                                                       add ', ' only if we're crediting a new author.
            \fi%
        \fi%
        \ifthenelse{%                                                                 
            \equal{\csname ack\theackx fig\endcsname}{\csname ack\the\numexpr\theackx+1\relax fig\endcsname}%
        }{%                                                                           if this credit and the next one are from the same picture
            \ifthenelse{%
                \equal{\csname ack\theackx auth\endcsname}{\csname ack\the\numexpr\theackx+1\relax auth\endcsname}%
            }{%                                                                           
                \def\showauth{F}%                                                         \showauth = F: don't print author name right now cuz we need to add more icone names before
            }{%
                \def\showauth{T}%                                                         else \showauth = T (need to credit author name now)
            }%
        }{%
            \def\showauth{T}%                                                         else \showauth = T (need to credit author name now)
        }%
        `\csname ack\theackx icon\endcsname' %                                        print '<Icon's name> '
        \if T\showauth%
            by \csname ack\theackx auth\endcsname%                                    print 'by <Author name>' if we've to print author name, 
        \else%
            and %                                                                     else print 'and ' (waiting for next icon's name)
        \fi
        %
        \edef\priorfig{\csname ack\theackx fig\endcsname}%                            redefine Fig. nb and author of prior acknowledment
        \edef\priorauth{\csname ack\theackx auth\endcsname}%
    }.%
}

\begin{document}
    \begin{figure}[ht]
        \centering
        \includegraphics[width=1in]{example-image}
        \caption{blah blah}%
        \mymacro{John Doe}{Sunrise}%
        \mymacro{Erika Mustermann}{Curry wurst}%
    \end{figure}
    \begin{figure}[ht]
        \centering
        \includegraphics[width=1in]{example-image}
        \caption{blah blah}%
        \mymacro{John Doe}{Sunrise}%
        \mymacro{John Doe}{Sunset}%
    \end{figure}
    \begin{figure}[ht]
        \centering
        \includegraphics[width=1in]{example-image}
        \caption{blah blah}%
        \mymacro{John Doe}{Sunrise}%
    \end{figure}
    \printacknowledgement
\end{document}

enter image description here

One less than ideal behavior that could be remedied with extra work is that if a given figure has 3 (or more) icons from a given author, the acknowledgement will appear as 'Sunrise' and 'Sunset' and 'Moonglow' by John Doe, rather than as 'Sunrise', 'Sunset', and 'Moonglow' by John Doe