Latex Conditionals

If you are a graduate student, and have some sort of assistantship position I have one advice for you. Do not tell your professors that you know/enjoy/use latex. Do not talk to them about latex. If they figure out that you do use it from the superb visual quality of your written assignments they may corner you and ask you about it directly. In that case shrug, make a dumb expression and quickly change the subject/run away.

The truth is that today, most graduate students are brain-dead MS word zombies. In fact most faculty members hate non-wysiwyg stuff with a passion. So once the they spot a latex user they are going to pounce upon him, and ride him till he drops dead, or graduates (whichever comes first).

This is, ladies and gentlemen, how I got stuck making thesis templates for Dr. Antoniou who is about ready to strange me these days. I’m officially working on the templates since… Er… Sometime last semester :P

Yes, I am the undisputed king of procrastination. I could teach you all a thing or two about procrastinating to the fullest. But not today. Come back tomorrow… Or next week maybe.

What I really wanted to talk about today are the conditional statements in Latex. I just typed all this back-story to give you some background on the problem I was facing. You see, at MSU it is only possible to submit a Masters Thesis in May, August or January. Thus, I wanted to make my template automatically select the correct month.

I decided to use ifthen package to do the conditionals. The ifthenelse statement seemed to be perfect here:

\newcommand{\shorttoday}{
    \ifthenelse{\number\month<5}
    {May, }
    {
       \ifthenelse{\number\month <8}
       {August, }
       {January, }
    }
\number\year}

Now, whenever you do \shorttoday you should get an appropriate month. For example, right now it displays May. But if I change month to say December using \month 12 I will get January :)

Now my only issue is that for January I should increment the year somehow. Any tips on how to do that? So far I haven't figured out how that could be done.

Update Thu, April 27 2006, 09:57 PM

I finally figured it out:

\newcounter{theyear}
\setcounter{theyear}{\number\year}
\newcommand{\shorttoday}{
    \ifthenelse{\number\month<5}
    {May, }
   {
       \ifthenelse{\number\month <8}
       {August, }
       {\addtocounter{theyear}{1} January, }
   }
   \value{theyear}}

It works :)

This entry was posted in programming and tagged . Bookmark the permalink.



One Response to Latex Conditionals

  1. ppKKlvs GERMANY Mozilla Firefox Mac OS says:

    the MSU grad school!! Ahhhaa!! I wonder if it’s the same MSU you had to deal with… the one in the great lakes! Anyway, they are complaining about some dots missing in a very specific section of the table of contents of my thesis (bibliography), and I’m trying to solve it with \if@ statements of LaTex…. It’s surprisingly hard to fin any documentation on such kind of statements… google only gives results on webpages discussing the merits of using condoms! Do you know any god link?

    the problem: adding dots from ‘Bibliography’ to page number… I wonder if I can have something like \if@bibliography {\cftchapleader}{\cftdotfill{\cftsecdotsep}} in the renewcomand for the table of contents.

    Reply  |  Quote

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>