# Multi-line text retrieved from file via \input, within a newcommand declaration, passing newly declared command as argument of standard letter class

I have put together a minimum working example consisting of a number of files

mwe.tex     % instance of personal letter
C:\LocalTeX\tex\latex\my\mygeneralmatter.sty    % author's address and signature defined here
C:\LocalTeX\tex\latex\my\myletter.cls   % author's address and signature defined here

Here are the file contents:

## mwe.tex

\NeedsTeXFormat{LaTeX2e}
\documentclass{myletter}

%}  % does compile
\newcommand{\theclosing}{Sincerely,}
\newcommand{\thepostscript}{}

\begin{document}
I would like to thank you for your recommendation during the hiring process for the position of position with company.

I have thoroughly enjoyed being a part of company.  It has indeed been a privelege to have worked with such a competant team.

I very much appreciate the support.
\end{document}

Person\\
Title\\

## mygeneralmatter.sty

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mygeneralmatter}[2013/05/21 a package containing general matter]

\newcommand{\phone}{(999) 999 9999}     % phone number

}%

% company name, address and phone numbers
\phone \\%
\email
}%

% signature for formal letters
\newcommand{\authorsignature}{First Last}

## myletter.cls

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myletter}[2013/04/22 a class for a personal letter which essentially preloads the authors current personal information]

\RequirePackage{mygeneralmatter}    % provides the commands: \authorsignature, \authoraddresslong

\signature{\authorsignature}    % signature of the letter defined in jclgenmatter.sty

\AtBeginDocument{%
\opening{\theopening}
}%

\AtEndDocument{%
\closing{\theclosing}
\ps{\thepostscript}
\end{letter}
}

Note that the file address.tex is alongside mwe.tex (same path). Note also that I have updated my local TeX system to be aware of the files mygeneralmatter.sty and myletter.cls by doing MikTeX --> Maintenance --> Settings --> Refresh FNDB

This is the error that I receive when compiling mwe.tex

! Argument of \@no@pgbk has an extra }.
<inserted text>
\par
l.22 \end{document}

Specifically, the problem is summarized as the newcommand \thetoaddress is being defined in mwe.tex as multi-line text which is retrieved from a file address.tex via the \input{} command. The newly declared command \thetwoaddress is then passed as an argument to the standard letter environment in the file myletter.cls

More generally, the problem may be summarized as multi-line text retrieved from file via \input, within a newcommand declaration and then passing newly declared command as argument of standard letter class

Can anyone suggest an approach which would allow me to refer to a to address' stored in a file from the instance of the personalized letter?

I suggest you to add the following lines to your class files:

\RequirePackage{catchfile}

and change the part where you start the letter with

\AtBeginDocument{%
\begingroup\def\tempa{\endgroup\begin{letter}}
\opening{\theopening}
}

In this way the \begin{letter} command will be presented with the expanded form of \thetoaddress. This is important because the letter class considers specially the part of this argument up to the first \\.

\documentclass{myletter}

\newcommand{\theclosing}{Sincerely,}
\newcommand{\thepostscript}{}

\begin{document}
I would like to thank you for your recommendation during the hiring
process for the position of position with company.

I have thoroughly enjoyed being a part of company.  It has indeed
been a privelege to have worked with such a competant team.

I very much appreciate the support.
\end{document}

42, Some Street\\
12345 Somecity}
• I modified my example code trying both of the suggestions made above. Each solution resulted in successful compilation. Thanks very much for the suggestions and thanks for pointing me to the catchfile package. May 21 '13 at 20:01