summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/boolexpr
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-08-14 23:50:51 +0000
committerKarl Berry <karl@freefriends.org>2009-08-14 23:50:51 +0000
commit3cda51c4ea4ac2affd9b693c6f071d884ab6b951 (patch)
tree2c14ac8aae14b936c81e7eb5e33245bc872e2f6b /Master/texmf-dist/tex/latex/boolexpr
parent9146738aa269b91c8d1aa570381afd808a3a4c40 (diff)
new (and updated) latex package boolexpr (30jul09)
git-svn-id: svn://tug.org/texlive/trunk@14675 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/boolexpr')
-rw-r--r--Master/texmf-dist/tex/latex/boolexpr/boolexpr.sty163
1 files changed, 163 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/boolexpr/boolexpr.sty b/Master/texmf-dist/tex/latex/boolexpr/boolexpr.sty
new file mode 100644
index 00000000000..da1a501fc68
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/boolexpr/boolexpr.sty
@@ -0,0 +1,163 @@
+%%
+%% This is file `boolexpr.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% boolexpr.dtx (with options: `package')
+%%
+%% This is a generated file.
+%%
+%% boolexpr : a purely expandable boolean expressions and switch (eTeX)
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either
+%% version 1.3 of this license or (at your option) any later
+%% version. The latest version of this license is in
+%% http://www.latex-project.org/lppl.txt
+%%
+%% Copyright (C) 2009 by Florent Chervet <florent.chervet@free.fr>
+%%
+%% This work consists of the main source file boolexpr.dtx
+%% and the derived files
+%% boolexpr.sty, boolexpr.pdf, boolexpr.ins,
+%%
+%% boolexpr : a purely expandable boolean expressions and switch (eTeX)
+\ProvidesPackage{boolexpr}
+ [2009/08/12 v2.1 Purely expandable boolean expressions and switch (eTeX)]
+
+% Make a colon (:) of catcode 4 (used as delimiter)
+\let\bex@AtEnd\@empty
+\def\TMP@EnsureCode#1#2{%
+ \edef\bex@AtEnd{%
+ \bex@AtEnd
+ \catcode#1 \the\catcode#1\relax
+ }%
+ \catcode#1 #2\relax
+}
+\TMP@EnsureCode{42}{4}% :
+
+% Five helper macros
+\let\bex@truepart\@firstoftwo
+\let\bex@falsepart\@secondoftwo
+
+\def\bex@afterelse#1\else#2\fi{\fi#1}
+
+\begingroup\catcode`\|=3
+\long\gdef\bex@ifblank#1{\bex@ifbl@nk#1||\@secondoftwo\@firstoftwo:}
+\long\gdef\bex@ifbl@nk#1#2|#3#4#5:{#4}
+\endgroup
+\long\def\bex@ifblankdef#1{\expandafter\bex@ifblank\expandafter{#1}}
+
+% \bex@rel tests each atomic expression: choose which evaluation macro to use first
+\def\bex@rel#1{%
+ \bex@test@eval#1:
+ {\bex@eval{#1}}
+ {\bex@test@neq#1<>:
+ {\bex@test@infeq#1<=:
+ {\bex@test@inf#1<:
+ {\bex@test@supeq#1>=:
+ {\bex@test@sup#1>:
+ {\bex@test@eq#1=:
+ {\@latex@error{Unknown relation found while scanning
+ \noexpand\boolexpr!}\@ehd}
+ {\bex@eq#1:}}
+ {\bex@sup#1:}}
+ {\bex@supeq#1:}}
+ {\bex@inf#1:}}
+ {\bex@infeq#1:}}
+ {\bex@neq#1:}}}
+
+% Tests macros to determine the type of each atomic expression
+\def\bex@test@neq#1<>#2:{\bex@ifblank{#2}}
+\def\bex@test@eq#1=#2:{\bex@ifblank{#2}}
+\def\bex@test@infeq#1<=#2:{\bex@ifblank{#2}}
+\def\bex@test@inf#1<#2:{\bex@ifblank{#2}}
+\def\bex@test@supeq#1>=#2:{\bex@ifblank{#2}}
+\def\bex@test@sup#1>#2:{\bex@ifblank{#2}}
+\def\bex@test@eval#1#2:{%
+ \ifcat\noexpand#1\relax% #1 is a control sequence
+ \bex@afterelse\bex@test@Eval{#1}
+ \else \expandafter\@secondoftwo
+ \fi}
+\def\bex@test@Eval#1{\csname @%
+ \ifx#1\the second%
+ \else\ifx#1\numexpr second%
+ \else\ifx #1\number second%
+ \else\ifx #1\dimexpr second%
+ \else\ifx #1\glueexpr second%
+ \else\ifx #1\muexpr second%
+ \else first%
+ \fi\fi\fi\fi\fi\fi oftwo\endcsname}
+
+% Evaluation macro that evaluates an atomic expression depending on its type:
+\def\bex@true@or@false#1{\csname bex@%
+ \ifnum\numexpr#1 true\else false\fi part\endcsname}
+\def\bex@false@or@true#1{\csname bex@%
+ \ifnum\numexpr#1 false\else true\fi part\endcsname}
+
+\def\bex@eq#1=#2:{\bex@true@or@false{#1-(#2)=0}}
+\def\bex@neq#1<>#2:{\bex@false@or@true{#1-(#2)=0}}
+\def\bex@infeq#1<=#2:{\bex@false@or@true{#1-(#2)>0}}
+\def\bex@inf#1<#2:{\bex@true@or@false{#1-(#2)<0}}
+\def\bex@supeq#1>=#2:{\bex@false@or@true{#1-(#2)<0}}
+\def\bex@sup#1>#2:{\bex@true@or@false{#1-(#2)>0}}
+\def\bex@eval#1{\bex@true@or@false{#1=0}}
+
+% \bex@OR splits the string to evaluate into two parts: before the first \OR and after
+\def\bex@OR#1\OR#2:{%
+ \bex@ifblank{#2}
+ {\bex@AND{}#1\AND:}
+ {\expandafter\bex@AND\expandafter{\bex@removeOR#2:}#1\AND:}}
+
+% \remove@OR removes the extra \OR: inserted into the argument of \bex@OR
+\def\bex@removeOR#1\OR:{#1}
+
+% \bex@AND splits the string to evaluate into two parts: before the first \AND and after:
+\def\bex@AND#1#2\AND#3:{%
+ \bex@rel{#2}
+ {\bex@ifblank{#3}
+ {0}
+ {\bex@ANDAND{#1}#3:}}
+ {\bex@ifblank{#1}{+1}{\bex@OR#1 \OR:}}}
+
+% \bex@ANDAND evaluate successive atomic expressions related by \AND:
+\def\bex@ANDAND#1#2\AND#3:{%
+ \bex@rel{#2}
+ {\bex@ifblank{#3}{+0}{\bex@ANDAND{#1}#3:}}
+ {\bex@ifblank{#1}{+1}{\bex@OR#1 \OR:}}}
+
+% \boolexpr: the entry point for evaluating boolean expressions
+\newcommand\boolexpr[1]{\bex@ifblank{#1}{1}{\numexpr\bex@OR#1 \OR:+0}}
+
+\newcommand\bex@first@or@second[1]{%
+ \csname bex@\ifnum\boolexpr{#1}=0 true\else false\fi part\endcsname}
+% \ifboolexpr: the LaTeX form of \boolexpr tests
+\newcommand\ifboolexpr{}
+\let\ifboolexpr\bex@first@or@second
+
+\def\switch#1\endswitch{\bex@ifblank{#1}{}%
+ {\bex@switch@otherwise#1\otherwise\endswitch}}
+
+\def\bex@switch@otherwise#1\otherwise#2\endswitch{%
+ \bex@switch@case#1\case\endswitch
+ {\bex@ifblank{#2}{}{\bex@otherwise#2\endswitch}}
+ \endswitch}
+
+\def\bex@switch@case#1\case#2\endswitch{%
+ \bex@ifblank{#1}
+ {\bex@ifblank{#2}{\@firstoftwo}{\bex@switch@case#2\endswitch}}
+ {\case#1\endcase
+ {\bex@ifblank{#2}{\@firstoftwo}{\bex@switch@case#2\endswitch}}%
+ }}
+
+\def\case#1#2\endcase{%
+ \ifboolexpr{#1}{\bex@after@endswitch{#2}}}
+
+\def\bex@after@endswitch#1#2\endswitch{#1}
+\def\bex@otherwise#1\otherwise#2\endswitch{#1}
+% Restore original catcode
+\bex@AtEnd
+\endinput
+%%
+%% End of file `boolexpr.sty'.