0

This question already has an answer here:

I'm trying to generate cover letters starting from a single document. Since I'm sending the same letter to different persons with different address I thought it would be great to use this document as template and change only the information pulling data from another file, much in the way dynamic HTML documents works.

Now I have two documents, the main one that will contain all the letters and pull the information, and the other with the content. Here are my documents:

This document is called "Infection-Label_letters:"

\documentclass[11pt,a4paper,sans]{moderncv}   
\moderncvstyle{classic}    

\usepackage{datetime}
\usepackage[ngerman,english]{babel} 
\usepackage[english,ngerman]{babel}     
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox

\makeatletter

\patchcmd{\makelettertitle}% <cmd>
 {\raggedright \@opening}% <search>
 {\@opening}% <replace>
 {}{}% <success><failure>
 \patchcmd{\makelettertitle}%
  {\end{minipage}\\[1em]}%
  {\end{minipage}\\[2em]}%
  {}{}

 \renewcommand*{\makeletterclosing}{ 
  \@closing\\[6em]% 
  {\bfseries \@firstname~\@familyname}% 
  \ifthenelse{\isundefined{\@jobtitle}}{}{\\\@jobtitle}% <-- added to orig. def
  \ifthenelse{\isundefined{\@enclosure}}{}{%
    \\% 
    \vfill% 
    {\color{color2}\itshape\enclname: \@enclosure}}}

\def\jobtitle#1{\def\@jobtitle{#1}}

\makeatother

\moderncvcolor{green}    
\usepackage[utf8]{inputenc}  
\usepackage[scale=0.75]{geometry}
\name{Name}{Surname}
\address{Address}{City}{Country}
\phone[mobile]{+00~(000)~0000~0000} 
\email{name@domain.com}     
\homepage{www.domain.com} 

\begin{document}

% Label #001
\begin{}
\newcommand{\labelName}{Name}
\newcommand{\addressFirstLine}{Address 1}
\newcommand{\addressSecondLine}{Address 2}
\newcommand{\addressThirdLine}{Address 3}
\newcommand{\theName}{Sir}
\newcommand{\theSurname}{ or Madam}
\newcommand{\recipientJob}{News Editor}
\newcommand{\enclosedItems}{one-sheet, demo CD, ''Title'' reviews.}
\include{Infection-Label_letter_template}
\end{}

% Label #002
\begin{}
\newcommand{\labelName}{Name}
\newcommand{\addressFirstLine}{Address 1}
\newcommand{\addressSecondLine}{Address 2}
\newcommand{\addressThirdLine}{Address 3}
\newcommand{\theName}{Sir}
\newcommand{\theSurname}{ or Madam}
\newcommand{\recipientJob}{News Editor}
\newcommand{\enclosedItems}{one-sheet, demo CD, ''Title'' reviews.}
\include{Infection-Label_letter_template}
\end{}


\jobtitle{Band Leader}
\makeletterclosing

\end{document}

This one is called "Infection-Label_letter_template:"

\begin{document}

\recipient{\labelName}{\addressFirstLine\\\addressSecondLine\\\addressThirdLine}
\date{\today}
\opening{Dear \theName\theSurname,}
\closing{Sincerely,}
\enclosure[Attached]{\enclosedItems}    
\makelettertitle
\parskip 11pt

I'm writing to introduce Band, a death metal band in the vein of Death, Cannibal Corpse, and Monstrosity. During the time the band has been active, we have independently-released our first album, "Title,'' which received positive reviews from magazines and international press. We are now willing to take one step ahead and reach a broader audience with our music.

Infection have finished recording a new album entitled "Title.'' Therefore, our band is currently seeking a recording contract with a quality label like \labelName. 

I have enclosed a CD and full press kit. I hope you can give Band's music a listen and consider us for a position on your roster. If you have questions, you can contact me by email at nameo@domain.com or at the address and phone above. Thanks for your time.

\end{document}

I acknowledge that my code is not working, but that's I have at this very moment. I tried to adapt the idea from this link: http://kb.mit.edu/confluence/pages/viewpage.action?pageId=3907466

Any help will be appreciated!

marked as duplicate by percusse, Andrew Swann, Werner, cmhughes, texenthusiast May 7 '14 at 18:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • There is an explanation of form letters in LaTeX here: kb.mit.edu/confluence/pages/viewpage.action?pageId=3907466 – Benjamin McKay May 5 '14 at 16:25
  • If you use LuaTeX, it is pretty easy to read in comma-separated values files (using standard Lua libraries), and then you can use any of the popular spreadsheet or database programmes to store your names and output the comma-separated values file. – Benjamin McKay May 5 '14 at 16:26
  • @ Benjamin McKay I updated my post, now I have two files but the linking part is not working propely. – killthepixelnow May 6 '14 at 20:01
  • 2
    This question may solve your problem tex.stackexchange.com/a/89810/4885 or else do a search for mail merge – Leeser May 6 '14 at 22:17
  • @killthepixelnow I'll make my comment an answer and then mark it as accepted so others who have the same question can see that it is solved. – Leeser May 7 '14 at 17:27
1

Take a look at this question Mail-merging documents from a database and it's solution by Yiannis Lazarides. It discusses mail merge etc.

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