You can use pgfmath
for this:
\documentclass{article}
\usepackage{pgf}
\begin{document}
\newcommand\ifismultiple[4]{%
\pgfmathparse{mod(#1,#2)==0}
\ifnum \pgfmathresult=1
#3%
\else
#4%
\fi
}
\ifismultiple{15}{4}{true}{false}
\end{document}
As in almost any programming language, \if...
statements can be nested, however, there's no \elseif
, so \else \if....
has to be used and concluded with \fi
.
A new \if...
variable (well, macro actually) can be defined with
\newif\ifsomename
which is initially set to the false state. \somenametrue
will set to true
, \somenamefalse
will set it false.
Nested \if...\fi
can be very tedious, in TeX, however.
Here's some pseudo-code
\ifsomething...
do this and that
\else
\ifsomethingother
...
\else
\ifsomethingmore
\fi
\fi
\fi
The following small example should print 'Foo that' with bold font, since \dothattrue
was specified.
\documentclass{article}
\newif\ifdothis
\newif\ifdothat
\dothattrue % Setting the state of the boolean variable \ifdothat` to true, otherwise it's false already (or use \dothatfalse explicitly)
\ifdothis
\newcommand{\foo}{\textbf{Foo}}
\else
\ifdothat
\newcommand{\foo}{\textbf{Foo that}}
\else
\newcommand{\foo}{\textbf{Dummy content}}
\fi % \fi of \ifdothat
\fi % Outer \fi
\begin{document}
\foo
\end{document}
Best Answer
You can use the logical combination
and
andor
in the test\ifboolexpr
For more details see the documentation (section 3.6.5).
I want to show an example.
Result: