[Tex/LaTex] Autofill letter template

automationletters

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.

example letter

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

Best Answer

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}
\setkomavar{fromaddress}{%
   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 ;-)