5

I've three variable statements :

  • Statement1 = You are Great Student.
  • Statement2 = You are average Student.
  • Statement3 = You Need improvement on list of topics mentioned below.

In the report card for student, I want to show one of this statement based on marks scored by the student [I'm reading marks from external csv file as \markscore]

  • If value of \markscore is greater than or equal to 90 i want to print Statement1
  • If value of \markscore is greater than or equal to 80 but less than 90 i want to print Statement2
  • Else I want to print Statement3 in the report card.

Can you please suggest latex package to print statements conditionally?

cgnieder
  • 66,645
Pawan Mude
  • 2,921

2 Answers2

7

The 'official' way to do this is to use a package: traditionally ifthen but perhaps now you might choose etoolbox instead. I'll use ifthen, which here works reasonably clearly:

\documentclass{article}
\usepackage{ifthen}
\newcommand{\markscore}{90} % For testing
\begin{document}

\ifthenelse{\markscore<80}
  {You need improvement on list of topics mentioned below}
  {%
    \ifthenelse{\markscore<90}
      {You are average student}
      {You are great student}%
  }%
\end{document}

You could of course use the same logic as in David's answer and have the flow of statements perhaps a little clearer.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • 1
    Tbh my first reaction to the OP was \ifnum. So i, personally, would stick to DCs answer. I guess you aimed at the \ifnumless macro by bringing etoolbox into play. Therewith http://tex.stackexchange.com/questions/36201/placing-many-conditionals-in-a-series/36202#36202 maybe is intereresting here. – Ruben Oct 02 '13 at 07:50
  • Thank you Joseph. Somehow I'm getting warning mentioned below (while executing using xelatex) : (similar to one without package)! Missing = inserted for \ifnum. . l.333 }

    ? ! Missing number, treated as zero.

    . l.333 }

    ? ! Missing = inserted for \ifnum.

    . l.333 }

    ? ! Missing number, treated as zero.

    . l.333 }

    ?

    – Pawan Mude Oct 02 '13 at 08:44
  • 1
    @PawanMude Are you trying exactly what I've put? If not, please detail what you've changed: if it's a big change then a new linked question might be best. – Joseph Wright Oct 02 '13 at 09:32
  • Thanks Joseph, for your comments and sharing linked post. Somehow after making few changes in my code option mentioned by David is working without warning. I'll analyze it further. – Pawan Mude Oct 02 '13 at 11:37
6

You don't need a package:

\ifnum\markscore>89
statement 1
\else
\ifnum\markscore>79
statement 2
\else
statement 3
\fi
\fi
David Carlisle
  • 757,742
  • 2
    Well, the 'official' LaTeX way is to use ifthen, but you knew that ;-) – Joseph Wright Oct 02 '13 at 07:28
  • Thank You Sir for reply. While excuting tex file using xelatex ; i'm getting warnings mentioned below: ! Missing = inserted for \ifnum. . l.334 }

    ? ! Missing number, treated as zero.

    . l.334 }

    ? ! Missing = inserted for \ifnum.

    . l.334 }

    ? ! Missing number, treated as zero.

    . l.334 }
    – Pawan Mude Oct 02 '13 at 08:38
  • 2
    In that case \markscore does not expand to an integer. I had to guess as you did not provide a real example document. Joseph did the same, – David Carlisle Oct 02 '13 at 11:05
  • Thank You Sir. I've updated my CSV to store only integers and now warning is gone. – Pawan Mude Oct 02 '13 at 11:39