6

Considering the following database:

Name,ID,Gender,Years in Service
,382473856,M,15
Francesca Joestar,461276432,F,10
Chan Ker Mei,463724631,F,5
Hikaru Yagami,154954739,M,10

The first line has the field "Name" empty. The following code does not work. In fact the function:

\DTLifnull{\name}{Mister X}{\name}

always gives the result FALSE. Why?

\documentclass[16pt]{scrartcl}
\usepackage[left=3cm,right=3cm,top=6cm,bottom=5cm]{geometry}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tgschola}
\usepackage{fourier-orns}
\usepackage{graphicx}
\usepackage{wallpaper}

\usepackage{datatool}
\DTLloaddb{names}{namelist.csv}

\begin{document}
\linespread{2}\selectfont
\pagestyle{empty}
\TileWallPaper{\paperwidth}{\paperheight}{old-border}

\DTLforeach{names}{
\name=Name, \ID=ID, \gender=Gender, \yr={Years in Service}}{
{\centering
    {\LARGE\bfseries Certificate of Appreciation}\par
    {\LARGE\decofourleft\quad{\decoone}\quad\decofourright}\par
    \vskip2em
    We thank\par
    {\large\bfseries\MakeUppercase{\DTLifnull{\name}{Mister X}{\name}}}\par
    {\large (ID: \ID)}\par
    for having been with\par
    {\large XYZ Company}\par
    {for \emph{\LARGE\yr} glorious years}\par
    \vskip1em
    We commend \DTLifeq{\gender}{M}{him}{her} on \DTLifeq{\gender}{M}{his}{her} excellent service.\par
    }

    \vfill

    \hfill
    \begin{minipage}{.4\textwidth}
    Managing Director\par
    \vskip1cm
    \rule{8em}{.5pt}
    \vskip-1em
    (MD's Name)\par
    \end{minipage}

    \pagebreak
}
\end{document}
5

This is documented on page 66 of the user manual of datatool (end of section 5.5).

You can define a test for emptyness:

\newcommand{\myDTLifempty}[3]{%
  \if\relax\detokenize\expandafter{#1}\relax#2\else#3\fi
}

and then say

\DTLforeach{names}{
\name=Name, \ID=ID, \gender=Gender, \yr={Years in Service}}{
{\centering
    {\LARGE\bfseries Certificate of Appreciation}\par
    {\LARGE\decofourleft\quad{\decoone}\quad\decofourright}\par
    \vskip2em
    We thank\par
    {\large\bfseries\MakeUppercase{\myDTLifempty{\name}{Mister X}{\name}}}\par
    {\large (ID: \ID)}\par
    for having been with\par
    {\large XYZ Company}\par
    {for \emph{\LARGE\yr} glorious years}\par
    \vskip1em
    We commend \DTLifeq{\gender}{M}{him}{her} on \DTLifeq{\gender}{M}{his}{her} excellent service.\par
    }
  ...
}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.