I want to write value of the macro \@authortofile to a file. Inside the macro it is another macro which is defined as separator between some words:
\def\@separator{\def\@separator{, }}
When I try to do this I get in .dat file a string:
\thispaperauthor{\@separator One\@separator Two\@separator Three}
with non expanded \@separator, but I need text like:
\thispaperauthor{One, Two, Three}
PDF output iat the same time has the required form:

Here is MWE
\documentclass[]{article}
\makeatletter
\def\@separator{\def\@separator{, }} %---def separator
\def\@authortofile{\@separator One\@separator Two\@separator Three} %def \@authortofile
%---definition of newwrite as \writedatatofile
\newwrite\titleauthorfile
\newcommand\writedatatofile[1]{%
\immediate\openout\titleauthorfile=#1.dat
\immediate\write\titleauthorfile{%
\string\thispapertitle{\unexpanded\expandafter{\@title}}}%
\immediate\write\titleauthorfile{%
\string\thispaperauthor{\unexpanded\expandafter{\@authortofile}}}%
\immediate\write\titleauthorfile{\string\finishauthors}
\immediate\closeout\titleauthorfile
}
\makeatother
\title{Title}
\begin{document}
\writedatatofile{\jobname}
\makeatletter
\@authortofile
\makeatother
\end{document}
def\@separator{\def\@separator{, }} %---def separatordoes not work by expansion, so the question isn't that easy to answer. It would be possible to define a command that expanded to nothing the first time, or a comma after that but the definition there requires an assignment so is not expandable – David Carlisle Jan 22 '15 at 23:44\@authortofileto beOne, Two, Three. Please be more specific. – egreg Jan 22 '15 at 23:59