1

I want to make the data from \g to be converted to uppercase letter then I want to use that data for comparison commands like \IfStrEq{\g}{F}{}{} because in \g it may contain f or F; if it contains f then make it uppercase letter, \MakeUppercase command is not working inside \IfStrEq. Here is my MWE:

 \documentclass[10.0pt,legalpaper,landscape]{article}
 \usepackage[top=0.5cm,bottom=1.4cm,left=2cm,right=0.1cm]{geometry}
 \usepackage[table]{xcolor}
 \usepackage[all]{tcolorbox}
 \usepackage{filecontents}
 \usepackage[english]{babel}
 \usepackage{graphicx,booktabs,xstring,datatool,xintexpr,longtable,minted} %for including eps graphics
 \usepackage{multirow,colortbl}
 \usepackage{ifthen}
 \newboolean{long}   

 \renewcommand{\dtldisplaystarttab}{\toprule}
 \renewcommand{\dtldisplayafterhead}{\midrule}
 \renewcommand{\dtldisplayendtab}{\\\bottomrule}


 \begin{filecontents*}{test.csv}    
 Name,Gender,Blood Group
 Mr. A,f,A+
 Mr B,m,AB-
 Mr. C,f,O+
 Mr D,M,AB-
 Mr. E,F,O+
 Mr. F,F,O+
 Mr. G,F,O+
 \end{filecontents*}
 \newcounter{Female}
 \newcounter{Male}
 \newcounter{Total}

 \DTLloaddb{name}{test.csv}     

 \begin{document}
 \begin{longtable}{|c|l|c|c|}
 \hline
  Sl. No. & Name & Gender & Blood Group

  \DTLforeach*{name}{\name=Name,\b=Blood Group,\g=Gender}{%

  \IfStrEq{\MakeUppercase{\g}}{F}{\stepcounter{Female}\\\hline \theFemale & \name & \b & \g }{}

  }\\\hline

  &&\MakeUppercase{latex}&

  \end{longtable}
  \centering
  \MakeUppercase{latex}   

  \end{document}
lockstep
  • 250,273
Biki Teron
  • 3,275

1 Answers1

4

Test whether the gender is a sub-string of f,F instead:

enter image description here

\documentclass{article}

\usepackage{filecontents}
\usepackage{xstring,datatool}

\begin{filecontents*}{test.csv}
Name,Gender,Blood Group
Mr. A,f,A+
Mr B,m,AB-
Mr. C,f,O+
Mr D,M,AB-
Mr. E,F,O+
Mr. F,F,O+
Mr. G,F,O+
\end{filecontents*}

\newcounter{Female}

\DTLloaddb{name}{test.csv}

\begin{document}

\begin{tabular}{|c|l|c|c|}
  \hline
  Sl. No. & Name & Gender & Blood Group
  \DTLforeach*{name}{\name=Name,\b=Blood Group,\g=Gender}{%
    \IfSubStr{f,F}{\g}{\stepcounter{Female}%
    \\
    \hline \theFemale & \name & \b & \g }{}
  }\\ 
  \hline
\end{tabular}

\end{document}

\MakeUppercase{\g} is not expandable in the comparison, meaning it doesn't turn \g into its uppercase equivalent until much later. Since you're dealing with a very specific set of possibilities, \IfSubStr can work were the options are separated with some other character.

Werner
  • 603,163