% This file is embedded in datatool-user.pdf version 3.4.5 2026-08-23
% Example 193 Mail Merging
% Label: "ex:mailmerge"
% arara: pdflatex
% arara: pdfcrop
\documentclass[12pt]{letter}
\pagestyle{empty}
\usepackage[shortcuts]{person}
\DTLsetup{store-datum,default-name=scores}
% define database:
\DTLaction{new}
% add columns in desired order:
\DTLaction[key=forename,value={First Name}]{add column}
\DTLaction[key=surname,value={Surname}]{add column}
\DTLaction[key=regnum,value={Student Number}]{add column}
\DTLaction[key=gender]{add column}
\DTLaction[key=parent]{add column}
\DTLaction[key=score,value={Score (\%)}]{add column}
\DTLaction[key=award]{add column}
% 1st row:
\DTLaction[
 assign={ forename = Jane, surname = Brown,
  regnum = 102647, score = 75, award = {\$1,830},
  gender = F, parent = {Ms Brown}
 }
]{new row}
% 2nd row:
\DTLaction[
 assign={ forename = John, surname = {Smith, Jr},
  regnum = 102689, score = 68, award = {\$1,560},
  gender = M, parent = {Mr and Mrs Smith}
 }
]{new row}
% 3rd row:
\DTLaction[
 assign={ forename = Quinn, surname = Ó Coinn,
  regnum = 103294, score = 91, award = {\$3,280},
  parent = {Mr and Mrs Ó Coinn}
 }
]{new row}
% 4th row:
\DTLaction[
 assign={ forename = Evelyn, surname = O'Leary,
  regnum = 107569, score = 81.5, award = {\$2,460},
  gender = n, parent = {Prof O'Leary}
 }
]{new row}
% 5th row:
\DTLaction[
 assign={ forename = Zoë, surname = Adams,
  regnum = 105987, score = 52, award = {\$1,250},
  gender = f, parent = {Mr and Mrs Adams}
 }
]{new row}
% 6th row:
\DTLaction[
 assign={ forename = Clare, surname = Vernon,
  regnum = 104356, score = 45, award = {\$500},
  gender = Female, parent = {Mr Vernon}
 }
]{new row}
% 7th row:
\DTLaction[
 assign={ forename = Roger, surname = Brady,
  regnum = 106872, score = 58, award = {\$1,350},
  gender = m, parent = {Dr Brady and Dr Mady}
 }
]{new row}
% 8th row:
\DTLaction[
 assign={
  forename = Andy, surname = Brown, regnum = 103569,
  score = 42, award = {\$980},
  gender = male, parent = {Mr Brown and Prof Sepia}
 }
]{new row} 
\begin{document}
\begin{DTLenvmapdata}
\begin{letter}{}
 \DTLmapgetvalues{
  \Forename=forename,
  \Surname=surname,
  \Gender=gender
 }
 \newperson*{
  expand-once-name=\Forename,
  expand-once-surname=\Surname,
  gender=\Gender
 }
 \opening{Dear \DTLmapget{key=parent}} 

Your \personchild\ \personfullname\ received a score of
  \DTLmapget{key=score} and was awarded a scholarship of
  \DTLmapget{key=award}. We look forward to seeing
  \them\ on \their\ arrival. 

\closing{Yours Sincerely}
 \end{letter}
\end{DTLenvmapdata} 
\end{document}
