# Autofill letter template

I'm an MD and I have to write a lot of letters to collegues and I want to try to do this in LaTex to increase productivity. I wonder if it's possible to make a basic letter template without any names, DOB, etc. After that, define all the patients' information (in the preamble? somewhere else?) so LaTeX automatically generates the letter without fiddling too much with the code.

Automatically edit everything in italics to the patient's data.

One option is to use scrlttr2 from the KOMA-Script bundle. Then you can define some variables with \newkomavar, set them with \setkomavar and use them in the letter (template) with \usekomavar. Here is a very basic example:

\documentclass{scrlttr2}

% predefined variables
\setkomavar{fromname}{Dr. House, MD}
Sesamestreet 5532\\
Elsewhere
}
\setkomavar{subject}{Next Examination}

% own vars
\newkomavar{nextdate}
\setkomavar{nextdate}{5th of September 2015}
\newkomavar{bodypart}
\setkomavar{bodypart}{left Arm}

\begin{document}
\begin{letter}{%
Jon Doe\\
Somestreet 1234\\
Somewhere
}
\opening{Dear Mr Doe,}

your next examination will be on \usekomavar{nextdate}
and we will check your \usekomavar{bodypart}.

\closing{Regards}
\end{letter}
\end{document}


More can be found in the manual (scrguien.pdf, chapter 4).

Your own settings (address etc. and layout) can be set in a definition file that you can use with \input, an .lco file (see §4.21) or you write a wrapper class.

PS: I’m not familiar with non-german addresses so don’t mind if the example has nonsense addresses ;-)

• Your welcome! The manual is quite comprehensive but explains everything you need I guess. If you com to a more specific problem don’t hesitate to ask (with positing a MWE) ;-) – Tobi Aug 31 '15 at 17:51
• probably having lco-files might be a good idea for automation (I have no experience with this so I'm just guessing…) – clemens Aug 31 '15 at 18:21
• @clemens: Indeed, good point. I didn’t had them in mind since I use the class not often. I added this to my answer. – Tobi Aug 31 '15 at 18:44