| 1 |
ifthenx.sty Copyright (C) 2012 Geoffrey Jones 2012/04/01 (v0.1a) |
| 2 |
<geoffrey stop jones snailshell uqconnect stop edu stop au> |
| 3 |
|
| 4 |
Package ifthenx.sty -- this little package extends David Carlisle's |
| 5 |
ifthen package, adding a few extra tests. These include: |
| 6 |
\isinteger |
| 7 |
\ispositiveinteger |
| 8 |
\isrealnumber (synonym: \isnumber) |
| 9 |
\ispositiverealnumber (synonym: \ispositivenumber) |
| 10 |
\classloaded |
| 11 |
\packageloaded |
| 12 |
\fileexists |
| 13 |
|
| 14 |
Example: |
| 15 |
\ifthenelse{\ispositiveinteger{\foo}\AND\fileexists{\foo.log}} |
| 16 |
{ commands to execute if true } |
| 17 |
{ commands to execute if false } |
| 18 |
|
| 19 |
The production rules for numbers are quite straightforward: |
| 20 |
\ispositiveinteger (string of one or more digits) |
| 21 |
\isinteger (ditto, with optional leading minus sign) |
| 22 |
\isrealnumber (ditto, with optional decimal point) |
| 23 |
\ispositiverealnumber (ditto, with no leading minus sign) |
| 24 |
|
| 25 |
Note that well-formed numbers are considered negative if they |
| 26 |
possess a leading minus sign. Accordingly, while 0, 0.0, -0 and |
| 27 |
-0.0 are all well-formed numbers, only 0 and 0.0 test positive. |
| 28 |
Consider this a feature. |
| 29 |
|
| 30 |
Motivation: |
| 31 |
While nowadays the ifthen package is sometimes deprecated (e.g., see the |
| 32 |
March 2011 stackexchange.com conversation on this topic), it has several |
| 33 |
useful attributes that make it attractive in certain situations. |
| 34 |
Setting aside its downsides (particularly, the care needed when using it |
| 35 |
inside fragile contexts), positives include: |
| 36 |
1. it provides a simple mechanism for assembling complex logical |
| 37 |
expressions, i.e., those employing \AND, \OR, \NOT and \( ... \) |
| 38 |
2. its syntax, while always subject to preference, may be somewhat |
| 39 |
easier for LaTeX novices to read, write and understand. (To my |
| 40 |
eye, it presents a more approachable and certainly more uniform |
| 41 |
grammar than etoolbox's syntax. E.g., compare |
| 42 |
\ifboolexpr{ test {\ifnumcomp{\value{mycounter}}{>}{3}}}... |
| 43 |
with |
| 44 |
\ifthenelse{\value{mycounter} > 3}... |
| 45 |
) |
| 46 |
3. string expansion semantics (cf., etoolbox that does not) |
| 47 |
4. it is relatively lightweight compared to, say, the might of etoolbox |
| 48 |
(although note that we use etoolbox's \patchcmd if already loaded). |
| 49 |
|
| 50 |
Required Packages: |
| 51 |
ifthen.sty (that's all) |
| 52 |
|
| 53 |
However, note that ifthenx uses \patchcmd if etoolbox.sty is already |
| 54 |
loaded. |
| 55 |
|
| 56 |
Related Packages: |
| 57 |
xifthen.sty provides an alternative set of ifthen package extension |
| 58 |
tests, several of which are based around capabilities drawn from |
| 59 |
the calc package. |
| 60 |
|
| 61 |
xifthen and ifthenx are compatible, but only if xifthen is loaded |
| 62 |
before ifthenx (xifthen doesn't patch \ifthenelse but rewrites its |
| 63 |
own modified version instead). If loaded in the recommended order, |
| 64 |
users can ``mix and match'' the tests. |
| 65 |
For example: |
| 66 |
\newcommand*\foo{3} |
| 67 |
\newcommand*\baz{98} |
| 68 |
\ifthenelse{ |
| 69 |
\isnumber{\foo} % ifthenx pkg command |
| 70 |
\AND\isodd{\foo} % ifthen pkg command |
| 71 |
\AND\cnttest{\foo + \baz}{>}{100} % xifthen pkg command |
| 72 |
}{true}{false} |
| 73 |
evaluates true. |
| 74 |
|
| 75 |
Version: v0.1a *** release for comments *** |
| 76 |
The author would welcome bug reports, comments, suggestions, |
| 77 |
extensions and so forth at this early stage. |
| 78 |
|
| 79 |
Acknowledgements: |
| 80 |
Gracious thanks David Carlisle for the ifthen package and for |
| 81 |
teaching me a new technique for run-time patching macro code. |
| 82 |
|
| 83 |
-------------------------- End README ------------------------------------ |