LaTeX if then examples (LaTeX ifthen package)

Here is a LaTeX example file where I'm experimenting with the LaTeX "ifthen" package (ifthen.sty).

These are simple examples, where I'm playing with the if/then decision making capability with the LaTeX "ifthen" package. These two examples are pretty easy, but make a nice introduction to the "ifthen" package.

Without any further ado, here are my LaTeX if/then examples:

\documentclass[a4paper,11pt]{article}
\author{Al Alexander}
\title{}

\usepackage{ifthen}

\begin{document}

%-----------------------------------------
% (1) a simple test to get started.
%-----------------------------------------
\newcommand{\printTrueOrFalse}[1]
{
  \ifthenelse{\equal{#1}{true}}{TRUE}{}
  \ifthenelse{\equal{#1}{false}}{FALSE}{}
}

\printTrueOrFalse{true}


%-----------------------------------------
% (2) print the day of the week
%-----------------------------------------
\newcommand{\dayOfWeek}[1]
{
  \ifthenelse{\equal{#1}{0}}{Sunday}{}
  \ifthenelse{\equal{#1}{1}}{Monday}{}
  \ifthenelse{\equal{#1}{2}}{Tuesday}{}
  \ifthenelse{\equal{#1}{3}}{Wednesday}{}
  \ifthenelse{\equal{#1}{4}}{Thursday}{}
  \ifthenelse{\equal{#1}{5}}{Friday}{}
  \ifthenelse{\equal{#1}{6}}{Saturday}{}
}

\dayOfWeek{0}
\dayOfWeek{1}
\dayOfWeek{2}
\dayOfWeek{3}
\dayOfWeek{4}
\dayOfWeek{5}
\dayOfWeek{6}

\end{document}

Comments

Permalink

That was helpful..

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.