From 2f6000f28f9662342c1cfe6e59abfdf345bd3a23 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 6 Nov 2012 22:34:41 +0000 Subject: keyreader (6nov12) git-svn-id: svn://tug.org/texlive/trunk@28195 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/keyreader/keyreader.sty | 140 ++++++++++++++------- 1 file changed, 94 insertions(+), 46 deletions(-) (limited to 'Master/texmf-dist/tex') diff --git a/Master/texmf-dist/tex/latex/keyreader/keyreader.sty b/Master/texmf-dist/tex/latex/keyreader/keyreader.sty index e30f0dcaf02..3b6ad1d7cfb 100644 --- a/Master/texmf-dist/tex/latex/keyreader/keyreader.sty +++ b/Master/texmf-dist/tex/latex/keyreader/keyreader.sty @@ -1,5 +1,5 @@ %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% -% This is file 'keyreader.sty', version 0.5, October 2012. % +% This is file 'keyreader.sty', version 0.5b, 2012/11/06. % % % % This package and accompanying files may be distributed and/or % % modified under the conditions of the LaTeX Project Public License, % @@ -19,7 +19,7 @@ %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% \ProvidesPackage{keyreader} - [2012/10/10 v0.5 Robust interfaces to xkeyval package (AM)] + [2012/11/06 v0.5b Robust interfaces to xkeyval package (AM)] \newdimen\krdz@ \ifcase \ifx\eTeXversion\@undefined\krdz@\else @@ -211,6 +211,9 @@ \csname @\ifnum\krd@pdfstrcmp{\detokenize{#1}}% {\detokenize{#2}}=0first\else second\fi oftwo\endcsname } +\def\krdifcond#1\fi{% + \csname @#1first\else second\fi oftwo\endcsname +} % If we were to use \krdtrimspace for \krdifbraced, then the need % for double \romannumeral will cause problems of premature expansion. % We need the \romannumeral below to make \krdifbraced expandable: @@ -230,6 +233,21 @@ \def\krd@ifbraced@d#1\krd@nil#2{% \krdifstrcmp{#1}{#2}\@secondoftwo\@firstoftwo } +% \krdstripouterbraces{} +\protected\def\krdstripouterbraces#1#2{% + \begingroup + \@tempcnta\krdz@ + \expandafter\krd@stripouterbraces#2\krd@stripbrace{#2}{#1}% +} +\protected\def\krd@stripouterbraces#1\krd@stripbrace#2#3{% + \advance\@tempcnta\@ne + \krdifcond\ifnum\@tempcnta=#3\fi{% + \edef#2{\unexpanded{#1}}% + \edef\x{\endgroup\krdaftergr#2}\x + }{% + \krd@stripouterbraces#1\krd@stripbrace{#2}{#3}% + }% +} \def\krdoxdetok#1{\detokenize\expandafter{#1}} \def\krdusearg#1#2{% @@ -237,6 +255,7 @@ } \def\krdexpandonce#1{\unexpanded\expandafter{#1}} \def\krdnoexpandcs#1{\krdexpandonce{\csname#1\endcsname}} +\def\krdncsname{\expandafter\noexpand\csname} \protected\def\krdexpanded#1{% \begingroup \protected@edef\reserved@a{\endgroup#1}\reserved@a @@ -249,6 +268,9 @@ \protected\def\krdexpandsecondonce#1#2{% \krdexpanded{\unexpanded{#1}\krdexpandonce{#2}}% } +\def\krdaftergr#1{% + \edef\noexpand#1{\noexpand\unexpanded{\krdexpandonce{#1}}}% +} \protected\def\krdifescaped#1{% \begingroup \escapechar92\relax @@ -256,9 +278,6 @@ \expandafter\endgroup \csname @\ifx\x\@backslashchar first\else second\fi oftwo\endcsname } -\def\krdifcond#1\fi{% - \csname @#1first\else second\fi oftwo\endcsname -} % Eg, % \newcount\nr\nr=\tw@ % \def\do#1{% @@ -324,7 +343,6 @@ \edef#1{\unexpanded{#2}}% \krdcsvnormalize#1% } - \protected\def\krd@pushmacros#1#2#3{% \begingroup \global\advance#2\@ne @@ -622,7 +640,7 @@ {\@testopt\XKV@define@choicekey{choice\XKV@header}}}% } \def\XKV@define@choicekey[#1]#2{% - \def\XKV@macropf{#1#2}% + \edef\XKV@macropf{\krdtrimspace{#1}\krdtrimspace{#2}}% \@testopt{\XKV@d@fine@choicekey{#2}}{}% } \def\XKV@d@fine@choicekey#1[#2]#3{% @@ -632,7 +650,12 @@ \@ifnextchar[{\XKV@d@fine@ch@icekey{#1}}{\XKV@d@fine@ch@ic@key{#1}}% } \def\XKV@d@fine@ch@icekey#1[#2]{% - \XKV@define@default{#1}{#2}% + \edef\krd@default{\krdtrimspace{#2}}% + % Choice keys shouldn't have braced values: + \krdstripouterbraces{2}\krd@default + \krdexpanded{% + \noexpand\XKV@define@default{#1}{\krdexpandonce\krd@default}% + }% \XKV@d@fine@ch@ic@key{#1}% } \def\XKV@d@fine@ch@ic@key#1{% @@ -892,9 +915,10 @@ \edef\krd@macpref{\krdtrimspace{#3}}% \toks@{}% \def\krd@rej{^?^}% + \def\krd@defna{.na}% \def\krd@vals{}% - \def\krd@altlist@a{}% - \def\krd@altlist@b{}% + \let\krduserinput\relax + \let\krdorder\relax \def\krd@splita##1/##2/{\krd@splitb##1/##2/.}% \def\krd@splitb##1/##2/##3/##4/##5/##6/##7/##8/##9\krd@nil{% \edef\krd@type{\krdzapspace{##1}}% @@ -919,67 +943,81 @@ \ifin@\else \krd@err{Unknown key type '\krd@type'}\krd@ehd \fi - \@expandtwoargs\in@ - {,\krdoxdetok\krd@default,}{,\detokenize{true,false},}% - \edef\krd@vals{% - \ifx\krd@vals\@empty\else\krdexpandonce\krd@vals,\fi - \ifx\krd@default\krd@rej\else - \krd@name=\ifin@ false\else\krdexpandonce\krd@default\fi - \fi - }% % ord{0}cmd{1}bool{2}bool+{3}choice{4}choice+{5} \krdusearg\krd@gettypenr{\krd@type}% \ifnum\krd@typenr>\thr@@ - \def\reserved@a{% + \krdstripouterbraces{2}\krd@default + \ifcase0% + \ifx\krd@itemfour\@empty\else + \ifx\krd@itemfour\krd@rej\else + \ifx\krd@itemfour\krd@defna\else 1\fi\fi\fi\relax \krd@err{Empty nominations for choice key \krd@name}\krd@ehd - }% - \ifx\krd@itemfour\@empty - \reserved@a \else - \ifx\krd@itemfour\krd@rej - \reserved@a - \else - \krd@getaltlist{##4}% - \fi + \krd@getaltlist{##4}% \fi \fi + \@expandtwoargs\in@ + {,\krdoxdetok\krd@default,}{,\detokenize{true,false},}% + \edef\krd@vals{% + \ifx\krd@vals\@empty\else\krdexpandonce\krd@vals,\fi + \ifx\krd@default\krd@rej\else + \ifx\krd@default\krd@defna\else + \krd@name=\ifin@ false\else\krdexpandonce\krd@default\fi + \fi + \fi + }% \krdexpanded{% \toks@{\the\toks@ - \krdnoexpandcs{define@\krd@typefordef key}% - \ifnum\krd@typenr>\thr@@*\fi + \krdncsname define@\krd@typefordef key\endcsname \if\krd@plustype+\fi [\krd@prefix]{\krd@family}% \ifnum\krd@typenr>\krdz@[\krd@macpref]\fi {\krd@name}% \ifnum\krd@typenr>\thr@@ - [\unexpanded{\krduserinput\krdorder}]% - {\krdexpandonce\krd@altlist@a}% + [\krduserinput\krdorder]{\krdexpandonce\krd@altlist@a}% \fi - \ifx\krd@default\krd@rej\else\XKV@afterfi - [{\expandafter\krdifbraced\expandafter{\krd@default}% - {{{\krdexpandonce\krd@default}}}{\krdexpandonce\krd@default}}]% + \ifx\krd@default\krd@rej\else + \ifx\krd@default\krd@defna\else + [{\krdexpandonce\krd@default}]% + \fi \fi - {% callback1 + {% callback-1 \ifnum\krd@typenr>\thr@@ - \ifx\krd@itemfive\krd@rej\else\krdexpandonce\krd@itemfive\fi + \ifx\krd@itemfive\krd@rej\else + \ifx\krd@itemfive\krd@defna\else + \krdexpandonce\krd@itemfive + \fi + \fi \krd@executealt{########1}{\krdexpandonce\krd@altlist@b}% \else - \ifx\krd@itemfour\krd@rej\else\krdexpandonce\krd@itemfour\fi + \ifx\krd@itemfour\krd@rej\else + \ifx\krd@itemfour\krd@defna\else + \krdexpandonce\krd@itemfour + \fi + \fi \fi }% \if\krd@plustype - {% + {% callback-2 \ifnum\krd@typenr>\thr@@ \ifx\krd@itemsix\krd@rej \noexpand\krd@keyvalerr \else - \krdexpandonce\krd@itemsix + \ifx\krd@itemsix\krd@defna + \noexpand\krd@keyvalerr + \else + \krdexpandonce\krd@itemsix + \fi \fi \else \ifx\krd@itemfive\krd@rej \noexpand\krd@keyvalerr \else - \krdexpandonce\krd@itemfive + \ifx\krd@itemfive\krd@defna + \noexpand\krd@keyvalerr + \else + \krdexpandonce\krd@itemfive + \fi \fi \fi }% @@ -1027,8 +1065,11 @@ } \protected\def\krd@getaltlist#1{% \begingroup + \def\krd@altlist@a{}% + \def\krd@altlist@b{}% \def\krd@g@taltlist##1.do=##2.do=##3\krd@nil{% \edef\XKV@tempa{\krdtrimspace{##1}}% + \krdstripouterbraces{2}\XKV@tempa \edef\XKV@tempb{\krdoxdetok\XKV@tempa{\krdtrimspace{##2}}}% \def\@do####1####2{% \edef####1{% @@ -1043,14 +1084,21 @@ \krd@g@taltlist##1.do=.do=\krd@nil }% \krdfor{#1}% - \global\let\krd@altlist@a\krd@altlist@a - \global\let\krd@altlist@b\krd@altlist@b - \endgroup + \ifx\krd@altlist@a\@empty + \krd@err{No nominations for choice key}\@ehd + \def\krd@altlist@b{}% + \fi + \krdexpanded{\endgroup + \krdaftergr\krd@altlist@a\krdaftergr\krd@altlist@b + }% } \protected\def\krd@executealt#1#2{% \edef\reserved@a{\krdtrimspace{#1}}% + \krdstripouterbraces{2}\reserved@a \edef\reserved@a{\krdoxdetok\reserved@a}% - \def\reserved@b##1{% + % There may be parameters characters in #2. So hide #2 in a macro: + \edef\reserved@b{\unexpanded{#2}}% + \def\reserved@c##1{% \def\reserved@a####1##1####2####3\krd@nil{% \edef\reserved@a{\unexpanded{####2}}% \krdifx\reserved@a\krd@nnil{% @@ -1059,9 +1107,9 @@ ####2% }% }% - \reserved@a#2#1{\krd@nil}\krd@nil + \expandafter\reserved@a\reserved@b#1{\krd@nil}\krd@nil }% - \krdusearg\reserved@b{\reserved@a}% + \krdusearg\reserved@c\reserved@a } \def\krd@lengthofival{20} \protected\def\krd@getinnoval{% -- cgit v1.2.3