3

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

mwe.tex     % instance of personal letter
address.tex % full address of individual being addressed in mwe.tex
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}

\newcommand{\thetoaddress}{\input{address}} % doesn't compile
%\newcommand{\thetoaddress}{%
%Addressee name\\
%Addressee title\\
%Address line 1\\
%Address line 2\\
%Address line 3%
%}  % does compile
\newcommand{\theopening}{Dear addressee,}
\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}

address.tex

Person\\
Title\\
Address line 1\\
Address line 2\\
Address line 3

mygeneralmatter.sty

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

\newcommand{\email}{first.last@domain.com}  % appropriate email address

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

% company name and address
\newcommand{\authoraddress}{%
Address line 1 \\%
Address line 2  \\%
Address line 3 %
}%

% company name, address and phone numbers
\newcommand{\authoraddresslong}{%
\authoraddress \\%
\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]
\LoadClass[]{letter}

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

\signature{\authorsignature}    % signature of the letter defined in jclgenmatter.sty
\address{\authoraddresslong}    % author's long address defined in jclgenmatter.sty

\AtBeginDocument{%
\begin{letter}{\thetoaddress}
\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?

1

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

\RequirePackage{catchfile}
\newcommand{\getaddressfrom}[1]{\CatchFileDef{\thetoaddress}{#1}{}}
\newcommand{\defineaddress}[1]{\def\thetoaddress{#1}}

and change the part where you start the letter with

\AtBeginDocument{%
  \begingroup\def\tempa{\endgroup\begin{letter}}
    \expandafter\tempa\expandafter{\thetoaddress}%
  \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 \\.

In order to read an address from a file, say

\documentclass{myletter}

\getaddressfrom{address}

\newcommand{\theopening}{Dear addressee,}
\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}

Alternatively, instead of \getaddressfrom you can specify directly an address with

\defineaddress{John Doe\\
  42, Some Street\\
  12345 Somecity}
1
  • 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.
    – John Chris
    May 21 '13 at 20:01
2
\newcommand{\thetoaddress}{\protect\input{address}} % does compile
0

With the same problem, I decided to increase variables and 8 to 9 and 6.5 to 7 in

\textheight=9in % text height can be bigger for a longer letter
\textwidth=7in  % text width of `6.5in` leaves 1 inch for right margin

I hope it useful.

1
  • This does not answer the question.
    – Werner
    Mar 15 '16 at 17:54

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.