summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2010-01-15 00:18:54 +0000
committerKarl Berry <karl@freefriends.org>2010-01-15 00:18:54 +0000
commitc873315ca2aa88a1dbfb1e8114b2172d13f05e64 (patch)
treecd90297e6f9cf7c4bdfc648912b87d5c73654ff7 /Master/texmf-dist/tex/latex
parentb8016f8b15fd4d572edf93863460b8584fdff367 (diff)
keyreader 0.2 (14jan10)
git-svn-id: svn://tug.org/texlive/trunk@16716 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r--Master/texmf-dist/tex/latex/keyreader/keyreader.sty102
1 files changed, 65 insertions, 37 deletions
diff --git a/Master/texmf-dist/tex/latex/keyreader/keyreader.sty b/Master/texmf-dist/tex/latex/keyreader/keyreader.sty
index f240c803946..5b28021c5b2 100644
--- a/Master/texmf-dist/tex/latex/keyreader/keyreader.sty
+++ b/Master/texmf-dist/tex/latex/keyreader/keyreader.sty
@@ -1,14 +1,14 @@
%+++++++++++++++++++++++++++++++++++++ LICENSE ++++++++++++++++++++++++++++++++++++++%
% %
-% This is file 'keyreader.sty', version 0.1. %
+% This is file 'keyreader.sty', version 0.2. %
% %
% This package reads multiple keys to be defined by xkeyval.sty. %
% %
-% 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 any later version. %
-% The latest version of this license is in http://www.latex-project.org/lppl.txt %
-% and version 1.3 or later is part of all distributions of LaTeX version %
-% 2005/12/01 or later. %
+% This package and accompanying files may be distributed and/or modified under %
+% the conditions of the LaTeX Project Public License, either version 1.3 of %
+% this license or any later version. The latest version of this license is in %
+% http://www.latex-project.org/lppl.txt and version 1.3 or later is part of all %
+% distributions of LaTeX version 2005/12/01 or later. %
% %
% The LPPL maintenance status of this software is 'author-maintained'. %
% %
@@ -52,20 +52,16 @@
\kr@ensurecode{059}{12}% ;
\kr@ensurecode{038}{03}% &
\ProvidesPackage{keyreader}%
- [2010/01/01 v0.1 Read multiple keys for the xkeyval parser (AM)]
+ [2010/01/13 v0.2 Read multiple keys for the xkeyval parser (AM)]
\NeedsTeXFormat{LaTeX2e}[1996/12/01]
\@ifpackageloaded{xkeyval}{}{\RequirePackage{xkeyval}[2008/08/13]}
\protected\long\def\kr@warn#1{\PackageWarningNoLine{keyreader}{#1}}
\protected\long\def\kr@err#1{\PackageError{keyreader}{#1}{\@ehc}}
\protected\long\def\kr@afterfi#1\fi{\fi#1}
\def\kr@CommandListParser#1{%
- \long\def\define@keylist##1{%
- \mathchardef\kr@cntb=\z@
- \kr@readlist##1#1&
- }%
- \long\def\cmddefine@keylist##1{%
- \mathchardef\kr@cntb=\z@%
- \expandafter\kr@readlist##1#1&
+ \long\def\kr@define@keylist##1##2{%
+ \mathchardef\kr@tempcntb=\z@
+ ##1\kr@readlist##2#1&
}%
\long\def\kr@readlist##1#1##2&{%
\kr@ifblank{##1}{}%
@@ -73,13 +69,13 @@
\edef\@i{\detokenize{##1}}%
\edef\@ii{\detokenize{\stopread}}%
\ifx\@i\@ii
- \mathchardef\kr@cntb=\@ne
+ \mathchardef\kr@tempcntb=\@ne
\stopread##2&
\else
\kr@define@key##1&
\fi
}%
- \ifnum\kr@cntb=\z@
+ \ifnum\kr@tempcntb=\z@
\kr@ifblank{##2}{}{\kr@readlist##2&}%
\fi
}%
@@ -91,20 +87,34 @@
\define@cmdkey[KV]{keyreader}[kr@]{keyprefix}[KV]{}
\define@cmdkey[KV]{keyreader}[kr@]{keyfamily}[fam]{}
\define@cmdkey[KV]{keyreader}[kr@]{macroprefix}[mp@]{}
+\define@boolkey[KV]{keyreader}[kr@]{xchoicelist}[true]{}
\DeclareOptionX*{\kr@warn{Unknown option '\CurrentOption' ignored}}
\ExecuteOptionsX[KV]<keyreader>{parser,keyprefix,keyfamily,macroprefix}
\ProcessOptionsX*[KV]<keyreader>\relax
\newcommand\krsetup[1]{\setkeys[KV]{keyreader}{#1}}
-\def\kr@namedef#1{%
- \ifcsname#1\endcsname
- \def\reserved@a{#1}%
- \@notdefinable
+\def\kr@defcommand#1#2{%
+ \ifcsname#2\endcsname
+ \expandafter\ifx\csname#2\endcsname\relax\else
+ \def\reserved@a{#2}%
+ \expandafter\expandafter\expandafter\@notdefinable
+ \fi
\else
- \expandafter\def\csname#1\expandafter\endcsname
+ \expandafter#1\csname#2\expandafter\endcsname
\fi
}
-\def\kr@nameuse#1{%
- \ifcsname#1\endcsname\csname#1\expandafter\endcsname\fi
+\def\kr@namedef#1{\kr@defcommand\def{#1}}
+\def\kr@nameedef#1{\kr@defcommand\edef{#1}}
+\def\kr@nameuse#1{\ifcsname#1\endcsname\csname#1\expandafter\endcsname\fi}
+\def\kr@ifnameundef#1{%
+ \ifcsname#1\endcsname
+ \expandafter\ifx\csname#1\endcsname\relax
+ \expandafter\expandafter\expandafter\@firstoftwo
+ \else
+ \expandafter\expandafter\expandafter\@secondoftwo
+ \fi
+ \else
+ \expandafter\@firstoftwo
+ \fi
}
\long\def\kr@ifnextchar#1#2#3{% \new@ifnextchar
\let\tmp@d=#1\def\tmp@a{#2}\def\tmp@b{#3}%
@@ -119,13 +129,30 @@
\long\def\kr@csexpandonce#1{\expandafter\kr@expandonce\csname#1\endcsname}
\@ifdefinable\stopread{\long\def\stopread#1&{\long\def\kr@remainder{#1}}}
\long\def\kr@inputerr#1#2{\kr@err{Erroneous value '#1' for key '#2'}}
-\mathchardef\kr@cnta=\z@\mathchardef\kr@cntb=\z@\mathchardef\kr@cntc=\z@
-\let\kr@altlist\@empty
+\mathchardef\kr@tempcnta=\z@\mathchardef\kr@tempcntb=\z@
+\mathchardef\kr@tempcntc=\z@
+\protected\long\def\define@keylist{%
+ \kr@ifstar{\kr@define@keylist\expandafter}{\kr@define@keylist\@firstofone}%
+}
+\def\ChoiceKeyValues#1#2{%
+ \ifkr@xchoicelist
+ \expandafter\edef\csname kr@altlist@\kr@keyfamily @#1\endcsname{#2}%
+ \else
+ \kr@ifnameundef{kr@altlist@\kr@keyfamily @#1}{%
+ \kr@nameedef{kr@altlist@\kr@keyfamily @#1}{#2}%
+ }{%
+ \kr@err{You have attempted to set two \MessageBreak
+ \string\ChoiceKeyValues\space for the same choice key,\MessageBreak
+ in the same family}%
+ }%
+ \fi
+}
+\@ifdefinable\CKVS{\global\let\CKVS\ChoiceKeyValues}
\def\kr@define@key#1,#2,#3,#4&{%
\begingroup
\protected@edef\x{\endgroup
\ifcase#1\relax
- \mathchardef\kr@cntc=\@ne
+ \mathchardef\kr@tempcntc=\@ne
\or
\noexpand\define@key[\kr@keyprefix]{\kr@keyfamily}%
{#2}[#3]{\kr@expandonce{#4}}%
@@ -137,23 +164,24 @@
[\kr@macroprefix]{#2}[#3]{\kr@expandonce{#4}}%
{\unexpanded{\kr@inputerr{##1}{#2}}}%
\or
- \ifx\kr@altlist\@empty
- \mathchardef\kr@cnta=\@ne
- \fi
+ \kr@ifnameundef{kr@altlist@\kr@keyfamily @#2}{\mathchardef\kr@tempcnta=\@ne}{}
\noexpand\define@choicekey*+[\kr@keyprefix]{\kr@keyfamily}{#2}%
- [\unexpanded{\kr@val\kr@nr}]{\kr@altlist}[#3]%
+ [\unexpanded{\val\nr}]{\kr@nameuse{kr@altlist@\kr@keyfamily @#2}}[#3]%
{\kr@expandonce{#4}}{\unexpanded{\kr@inputerr{##1}{#2}}}%
\else
- \mathchardef\kr@cntc=\@ne\relax
+ \mathchardef\kr@tempcntc=\@ne
\fi
}\x
- \ifnum\kr@cnta=\@ne\kr@afterfi
- \kr@err{'\string\kr@altlist' is empty: choicekey can't be defined.
- \MessageBreak You need to first define '\string\kr@altlist'
- \MessageBreak as a nonempty set. It is the list of
- \MessageBreak alternates values for your choicekey.}%
+ \ifnum\kr@tempcnta=\@ne\kr@afterfi
+ \kr@err{%
+ Alternate key values list for '#2' is empty:
+ \MessageBreak choicekey can't be defined.
+ \MessageBreak You need to first define admissible
+ \MessageBreak key values through '\string\ChoiceKeyValues'
+ \MessageBreak for choice key '#2'
+ }%
\fi
- \ifnum\kr@cntc=\@ne\kr@afterfi
+ \ifnum\kr@tempcntc=\@ne\kr@afterfi
\kr@err{Unknown key type/identifier '#1'}%
\fi
}