邮件合并性别问题

邮件合并性别问题

我正在尝试使用存储在文件“data.dat”中的信息构建一封格式信。一切都很顺利,但我找不到解决方案来根据主体的性别区分他/她或他/她。我猜想这将是一个条件,但它看起来会是什么样子,我不知道。我的 MWE(目前)是:

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

\Fields{\Mr\Dad\DSurName\Ms\Mum\MSurname\Address\StudentFirst\StudentLast}


\Merge{STEMdata.dat}{
\hspace{.25\textwidth}
\begin{flushright}
\bf \Mr\ \Dad\ \DSurName\ \& \Ms\ \Mum\ \MSurname\\
\bf\Address
\end{flushright}
\vspace{2 cm}
\begin{flushright}
\today
\end{flushright}
 \begin{center}
   \textsc{ADVICE OF PROGRESS\\
    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} 

我查看了 datatool 和 ifthen,但没有找到在代码中替换 \heshe 的位置。

在此先感谢您的任何建议。

答案1

您可以在合并块中添加\ifx。还有其他几个条件选项,但在这种情况下,内置选项似乎可以正常工作。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

相关内容