0
\documentclass{minimal}
\usepackage{etoolbox}

\newwrite\tempfile

\makeatletter
\let\features\@gobble
\makeatother
\newcommand{\feature}[1]{%
  \expandafter\def\expandafter\features\expandafter{\features,#1}%
}

\newcommand{\newText}[1]{\expandafter\newcommand\csname features#1\endcsname{}}

\newcommand{\addText}[2]{%
 \expandafter\ifdefempty\expandafter{\csname features#1\endcsname}
 {\expandafter\appto\csname features#1\endcsname{#2}}
 {\expandafter\appto\csname features#1\endcsname{,#2}}%
}

\def\lstText#1{\csname features#1\endcsname}

\makeatletter
\newcommand{\outText}[1]{%
 \immediate\openout\tempfile=\jobname_#1.tex
 \immediate\write\tempfile{\lstText{#1}}
 \immediate\closeout\tempfile
}
\makeatother

\makeatletter
\let\inputIFE\@input
\makeatother

\begin{document}

\inputIFE{test_A}

\newText{A}
\addText{A}{One}
\addText{A}{Two}
\addText{A}{Three

Birds and \textbf{bears}
}
\addText{A}{Four}
\lstText{A}
\outText{A}

\end{document}
2
  • Please never use the minimal class, it is not meant for examples,
    – daleif
    Mar 26 '20 at 18:15
  • 1
    Perhaps you should start by explaining exactly what your end goal is here? It is not clear to me what you are trying to do.
    – daleif
    Mar 26 '20 at 18:18
0

Compiling your example gives an undefined control sequence: \@nil error. \write carries an \edef-like expansion. The error comes from the full expansion of \textbf. So some care should be paid to the expansion.

Suppose you want to write one-step expansion result of command \features<#1> to file \jobname_#1.tex in \outText, try this:

\newcommand{\outText}[1]{%
  \immediate\openout\tempfile=\jobname_#1.tex
  % write out content of \feature<#1>
  \immediate\write\tempfile{%
    \expandafter\expandafter\expandafter\unexpanded
    \expandafter\expandafter\expandafter{\csname features#1\endcsname}}%
  \immediate\closeout\tempfile
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.