summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/boolexpr
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-09-03 00:43:56 +0000
committerKarl Berry <karl@freefriends.org>2009-09-03 00:43:56 +0000
commit382a6396f8c5958758712db789f58b00946d5667 (patch)
tree7f64e343baff9c14ad336546bf7dd246f3b32377 /Master/texmf-dist/tex/latex/boolexpr
parent87b7696d3c95e7c58da2f1ed33f5ae85a777a5a0 (diff)
boolexpr update (2sep09)
git-svn-id: svn://tug.org/texlive/trunk@15010 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, 79 insertions, 84 deletions
diff --git a/Master/texmf-dist/tex/latex/boolexpr/boolexpr.sty b/Master/texmf-dist/tex/latex/boolexpr/boolexpr.sty
index da1a501fc68..202b064b961 100644
--- a/Master/texmf-dist/tex/latex/boolexpr/boolexpr.sty
+++ b/Master/texmf-dist/tex/latex/boolexpr/boolexpr.sty
@@ -24,7 +24,7 @@
%%
%% boolexpr : a purely expandable boolean expressions and switch (eTeX)
\ProvidesPackage{boolexpr}
- [2009/08/12 v2.1 Purely expandable boolean expressions and switch (eTeX)]
+ [2009/09/03 v3.0 Purely expandable boolean expressions and switch (eTeX)]
% Make a colon (:) of catcode 4 (used as delimiter)
\let\bex@AtEnd\@empty
@@ -35,129 +35,124 @@
}%
\catcode#1 #2\relax
}
-\TMP@EnsureCode{42}{4}% :
+\TMP@EnsureCode{95}{11}% _
+\TMP@EnsureCode{36}{12}% $
+\TMP@EnsureCode{60}{12}% <
+\TMP@EnsureCode{61}{12}% =
+\TMP@EnsureCode{62}{12}% >
-% Five helper macros
+% Three 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}}
+\long\def\bex__ifnotblank#1#2$#3#4#5$${#4}
% \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=:
+\long\def\bex@rel#1{%
+ \bex@test_eval#1${\bex@eval{#1}}
+ {\bex@test_neq#1<>$${\bex@neq #1$}
+ {\bex@test_infeq#1<=$${\bex@infeq #1$}
+ {\bex@test_inf#1<$${\bex@inf #1$}
+ {\bex@test_supeq#1>=$${\bex@supeq #1$}
+ {\bex@test_sup#1>$${\bex@sup #1$}
+ {\bex@test_eq#1=$${\bex@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:}}}
+ \noexpand\boolexpr!}\@ehd}$$}$$}$$}$$}$$}$$}}
% 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:{%
+\def\bex@test_neq#1<>#2${\bex__ifnotblank#2$}
+\def\bex@test_eq#1=#2${\bex__ifnotblank #2$}
+\def\bex@test_infeq#1<=#2${\bex__ifnotblank #2$}
+\def\bex@test_inf#1<#2${\bex__ifnotblank #2$}
+\def\bex@test_supeq#1>=#2${\bex__ifnotblank #2$}
+\def\bex@test_sup#1>#2${\bex__ifnotblank #2$}
+\long\def\bex@test_eval#1#2${%
\ifcat\noexpand#1\relax% #1 is a control sequence
- \bex@afterelse\bex@test@Eval{#1}
+ \bex@test_Eval{#1}
\else \expandafter\@secondoftwo
\fi}
-\def\bex@test@Eval#1{\csname @%
+\long\def\bex@test_Eval#1#2\fi{\fi\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\ifx #1\value second%
\else first%
- \fi\fi\fi\fi\fi\fi oftwo\endcsname}
+ \fi\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@%
+\long\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@%
+\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}}
+\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}}
+\long\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}
+\long\def\bex@OR#1\OR#2${\bex@AND{#2}#1\AND$}
% \bex@AND splits the string to evaluate into two parts: before the first \AND and after:
-\def\bex@AND#1#2\AND#3:{%
+\long\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__ifnotblank #3$${\bex@ANDAND{#1}#3$}{+0}$$}
+ {\bex__ifnotblank #1$${\bex@OR#1$}{+1}$$}}
% \bex@ANDAND evaluate successive atomic expressions related by \AND:
-\def\bex@ANDAND#1#2\AND#3:{%
+\long\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:}}}
+ {\bex__ifnotblank #3$${\bex@ANDAND{#1}#3$}{+0}$$}
+ {\bex__ifnotblank #1$${\bex@OR#1$}{+1}$$}}
% \boolexpr: the entry point for evaluating boolean expressions
-\newcommand\boolexpr[1]{\bex@ifblank{#1}{1}{\numexpr\bex@OR#1 \OR:+0}}
+\newcommand\boolexpr[1]{\bex__ifnotblank #1$${\numexpr\bex@OR#1 \OR$}{+1}$$}
-\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
+\newcommand\ifboolexpr[1]{\bex@true_or_false{\boolexpr{#1}=0}}
-\def\switch#1\endswitch{\bex@ifblank{#1}{}%
- {\bex@switch@otherwise#1\otherwise\endswitch}}
+\long\def \switch#1\endswitch {\bex__ifnotblank#1$${\bex@switch_opt#1 \endswitch}{}$$}
+\long\def \bex@switch_opt#1#2\endswitch {\bex_ifsinglechar [{#1}%
+ {\bex@switch_opti#1#2\endswitch}{\bex@switch_opti[]#1#2\endswitch}}%]
+\def \bex@switch_opti[#1]#2\endswitch {\bex@switch_otherwise[{#1}]#2\otherwise\endswitch}
-\def\bex@switch@otherwise#1\otherwise#2\endswitch{%
- \bex@switch@case#1\case\endswitch
- {\bex@ifblank{#2}{}{\bex@otherwise#2\endswitch}}
+\def\bex@switch_otherwise[#1]#2\otherwise#3\endswitch{%
+ \bex@switch_case[{#1}]#2\case\endswitch
+ {\bex__ifnotblank#3$${\bex@otherwise#3\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
+\def\bex@switch_case[#1]#2\case#3\endswitch{\bex__ifnotblank#2$$%
+ {\bex@case[{#1}]#2\endcase%
+ {\bex__ifnotblank#3$${\bex@switch_case[{#1}]#3\endswitch}\@firstoftwo$$}}%
+ {\bex__ifnotblank#3$${\bex@switch_case[{#1}]#3\endswitch}\@firstoftwo$$}$$}
+
+\long\def\bex@case[#1]#2#3\endcase{\ifboolexpr{#1#2}{\bex@after_endswitch{#3}}}
+
+\long\def\bex@after_endswitch#1#2\endswitch{#1}
+\long\def\bex@otherwise#1\otherwise#2\endswitch{#1}
+\ifdefined\pdfmatch
+\long\def\bex_ifsinglechar#1#2{\csname @%
+ \ifnum\pdfmatch{\detokenize{^[#1]$}}{\detokenize{#2}}=1 first\else second\fi
+ oftwo\endcsname}
+\else
+\long\gdef\bex_ifsinglechar#1#2{\csname @%
+ \bex__ifnotblank#2$${%
+ \if\expandafter\@car\detokenize{#2}\relax\@nil\expandafter\@car\detokenize{#1}\string\\\@nil
+ \expandafter\expandafter\expandafter\ifx
+ \expandafter\expandafter\expandafter\\\expandafter\@cdr\detokenize{#2}\@nil\\%
+ first%
+ \else second%
+ \fi
+ \else second%
+ \fi}{second}$$oftwo\endcsname}
+\fi
+\bex@AtEnd\let\bex@AtEnd\@undefined
\endinput
%%
%% End of file `boolexpr.sty'.