# Mail Merge Gender problem

I'm trying to construct a form letter, using information stored in a file "data.dat". It all works, but I am having trouble finding a solution to discriminate between he/she or him/her, depending on the gender of the subject. I presume it would be a conditional, but how it would look, I have no clue. My MWE (at the moment) is:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{textmerg}
\usepackage[margin=0.75in]{geometry}
\pagenumbering{gobble}
\begin{document}

\Merge{STEMdata.dat}{
\hspace{.25\textwidth}
\begin{flushright}
\bf \Mr\ \Dad\ \DSurName\ \& \Ms\ \Mum\ \MSurname\\
\end{flushright}
\vspace{2 cm}
\begin{flushright}
\today
\end{flushright}
\begin{center}
COURSE:}
\end{center}

Dear \Mr\ \DSurName,\par
\StudentFirst\,\StudentLast: \par

This matter has been discussed with \StudentFirst\ and \heshe understands     what is expected in iSTEM in the future.\\
\vfill
\begin{flushright}
\rule{6cm}{0.025cm}\\
Joe Bloggs
\end{flushright}
\newpage
}
\end{document}


I have looked at datatool and ifthen, but no luck on where I would replace \heshe in the code.

Thanks in advance for any suggestions.

• do you or any of your packages include ctan.org/pkg/he-she? – marczellm May 4 '16 at 9:02
• There's also the person package that comes with datatool. – Nicola Talbot May 4 '16 at 10:27

You can add an \ifx within the merge block. Several other options for conditionals exist, but in this case the built-in seems to work ok. MWE:

\documentclass{article}
\usepackage{textmerg}
\begin{document}

\def\he{male}
\def\she{female}

\Fields{\SurName\StudentFirst\gender}

\Merge{STEMdatashort.dat}{
\ifx\gender\he
\def\heshe{he}
\else
\def\heshe{she}
\fi
Dear Mr. \SurName,\par

The grade of \StudentFirst\ has been discussed and \heshe\ understands what is expected in iSTEM in the future.\\

Joe Bloggs
\newpage
}
\end{document}


STEMdatashort.dat:

Smith
Jenny
female
Brown
Josh
male