2

I'm creating a large number of identical documents in LaTeX, with only the address changing (and the address will be only 1 of 5 possible )

So if my list of possible addresses is:
DC | 1600 Pennsylvania Avenue, Washington, DC FV | 2014 Forest Hills Drive, Fayetteville, NC NY | 1 World Trade Center, New York, NY SP | 742 Evergreen Terrace, Springfield, USA

I want to be able to type (for example) \fillinadd{DC} and have it fill in the proper address in text, so if I were to have a letter like:

\documentclass{letter}

\signature{Maurice Moss}
\newcommand{\fillinadd}[1]{#1}

\begin{document}

\begin{letter}{
Fire Department \\
\fillinadd{DC}}

\opening{Dear Sir / Madam,}
Fire! Fire! Help me! 123 Carrendon Road. Looking forward to hearing from you.
\closing{All the best,}

\end{letter}
\end{document}

It would replace the "DC" with "1600 Pennsylvania Avenue, Washington, DC", but if I put in "SP" it would print 742 Evergreen Terrace instead.

Alternately, if there is a better way to identify these possible addresses (ie #1, #2, etc), I'm fine with using that.

2

If you only need five addresses, then define them as commands. You could put the definitions in a separate file and input it to the main file, or just put them in the preamble.

\newcommand{\DC}{%
    123 Main Street,\\ 
    Washington, DC%
}
\newcommand{\LA}{%
    123 Main Street,\\ 
    Los Angeles, CA%
}

How you write the commands will be determined by their eventual use. Here I'm assuming something like this:

\newcommand{\fromaddress}{%
    \noindent%
    \begin{tabular}{l}
    #1\\
    \end{tabular}%
}

You can use it like this:

\fromaddress{\DC}
2
  • This makes sense. My eventual use is to be able to manipulate them using the command line (a la here), so I can generate these files on the fly. I'm assuming I would define \fromaddress{} to be either whatever I have inputted, or \DC{} if it's undefined. Jul 3 '15 at 21:26
  • I got it working! All you have to do is make your address commands (see @touhami 's answer), and then have a command named \fromaddress where you put the address, and then have a line like so: \ifthenelse{\isundefined{\fromaddress}}{\newcommand{\fromaddress}{\DC}}{} that you can use. Finally, when running pdflatex, use something like this: pdflatex "\def\fromaddress{\NY} \input{resume.tex}" to change the address. Jul 3 '15 at 21:55
2

Here is what I do

\documentclass{letter}

\signature{Maurice Moss}

\newcommand{\DC}{1600 Pennsylvania Avenue, Washington, DC}
\newcommand{\FV}{2014 Forest Hills Drive, Fayetteville, NC}
\newcommand{\NY}{1 World Trade Center, New York, NY}
\newcommand{\SP}{742 Evergreen Terrace, Springfield, USA}


\begin{document}

\begin{letter}{
Fire Department \\ \DC}

\opening{Dear Sir / Madam,}
Fire! Fire! Help me! 123 Carrendon Road. Looking forward to hearing from you.
\closing{All the best,}

\end{letter}
\end{document}

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.