First: I've found "Checking if two conditionals are met" but I don't know how to change it do suit my needs.
Wanted: I have eight different predefined values and I want different definitions of a constant dependnig on the eight values.
\documentclass{article}
\usepackage{etoolbox}
\usepackage{verbatim}
\begin{document}
\noindent Define the following:
\begin{verbatim}
\def\cumuA{33.3}
\def\cumuB{59.5}
\def\cumuC{73.8}
\def\cumuD{83.3}
\def\cumuE{88.1}
\def\cumuF{90.5}
\def\cumuG{97.6}
\def\cumuH{100}
\end{verbatim}
What I want:
\begin{verbatim}
\cumuA > 75 : \def\quartileC{0}
\cumuA < 75 < \cumuB: \def\quartileC{1}
\cumuB < 75 < \cumuC: \def\quartileC{2}
\cumuC < 75 < \cumuD: \def\quartileC{3}
\cumuD < 75 < \cumuE: \def\quartileC{4}
\cumuE < 75 < \cumuF: \def\quartileC{5}
\cumuF < 75 < \cumuG: \def\quartileC{6}
\cumuG < 75 < \cumuH: \def\quartileC{7}
\end{verbatim}
This should then result in
\begin{verbatim}
\def\quartileC{3}
\end{verbatim}
\end{document}
I guess that etoolbox
is the way to go here but (as said before) I don't know how use it properly for this task.
Best Answer
In this update I add a second simple no package method. As in the other answers naturally I use
\ifdim
because I need to compare fixed point numbers.Let me first point out that your conditions should read
\cumuA >= 75
, then\cumuA<75<=\cumuB
then\cumuB<75<=\cumuC
etc... (i.e. not only strict inequalities).Notice that
TeX
has no direct proviso for testing>=
or<=
: the programmer is suppose to negate the result of testing, respectively<
or>
thanks to the\else
. Or there is\unless
from e-TeX (not used in my answer).In both approaches I arrange things to test only one inequality at each step. First approach, the most simple minded:
The second approach uses some delimited macros borrowed from code of
xint
.The advantage of the second approach is to allow also, if desired, the easy definition of an expandable one-parameter macro
\mypercentile
which will be used asfor example. This is added at bottom.
for this I needed to add spaces after each
pt
from the first posted version, as TeX inserts a non expandable\relax
token if not. (This changed nothing to the original functioning, but has to be done if one wants the\mypercentile
thing).the expandability is in the strongest sense (
\romannumeral-`0
will fully expand\mypercentile
).The code: