Create a function that generates a letter

automation

I have to write many letters where each time I have to modify just the names, dates and address, but it is always the same content.

A short version would be something like "Dear [name], from [address] you have to present yourself at [time] [date]."

Is there anyway to automate this? I would just like to insert the right fields for Latex to create the letter from a template.

Best Answer

I like to do it like this, using the datatool package (like also suggested in the comments) :

\documentclass[10pt,a4paper]{scrlttr2}  
\usepackage{datatool}

\begin{document}        
\setkomavar{date}{\today}
\setkomavar{subject}{Very Important Letter}
\setkomavar{fromname}{Tom}
\setkomavar{fromaddress} {%
    My Company\\
    Company Way 42\\
    1337~Corporatetown%
}   

\DTLloaddb{list}{addresses.csv}
\DTLforeach{list}{\first=Firstname,\last=Lastname,\address=Street,
    \town=Town,\postal=Postal}{% start of loop
\begin{letter}{\first~\last \\ \address \\ \postal~\town}%
\opening{Dear \first~\last,}%

    some text   
    
    some more text

        \closing{Best regards}

\end{letter}
} % end of for loop
\end{document}

Then I have all the addresses in a separate addresses.csv, like this:

Firstname,Lastname,Street,Postal,Town
John,Doe,Example Street 1, 12345, North Pole
Jane,Doe,Example Street 2, 12345, North Pole

The resulting letter is probably not styled like you prefer, of course. But you have the whole world of KOMA options at your disposal, just check the KOMA manual!

Related Question