I created some kind of switch statement with a help of \ifthenelse
command. Now, I would like to pass its output to another command. In my example I want to colorize each sentence with a color specified by a number. My code is:
\documentclass{article}
\usepackage{ifthen}
\usepackage{color}
\newcommand{\num}{1}
\newcommand{\mySwitch}[1]{
\ifthenelse{#1=1}{red}{ % color no 1 is red
\ifthenelse{#1=2}{blue}{}}} % color no 2 is blue ... and so on
\begin{document}
\color{\mySwitch{\num}}
\mySwitch{\num} is the color no \num.
\renewcommand{\num}{2}
\color{\mySwitch{\num}}
\mySwitch{\num} is the color no \num.
\end{document}
I would like to obtain something like this:
but the result of compilation is:
What is more, I keep getting a number of errors from which the first one is
Missing \endcsname inserted \color{\NoToColor{\num}}.
I suppose the proper solution should have something to do with \expandafter
command but simply putting
\expandafter\color\expandafter{\mySwitch{\num}}
gives no results. I must be missing something but I can't get it to work and I can't find any similar example. Please give some hints.
\color
, which unfortunately\ifthenelse
isn't.\ifthenelse{#1=X}{<true>}{<false>}
, you can use\ifnum#1=X <true> \else <false> \fi
construction.