summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/yax/yax.tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2011-01-26 23:20:06 +0000
committerKarl Berry <karl@freefriends.org>2011-01-26 23:20:06 +0000
commit66c848bc93dc9fa2b85a8ad329ea12e2e0d0524b (patch)
treeee1214582fac18aca02c15125f4e2b13a6eb8824 /Master/texmf-dist/tex/generic/yax/yax.tex
parent556be84e15626e95b60d671dcedfad9856dc4a82 (diff)
yax (26jan11)
git-svn-id: svn://tug.org/texlive/trunk@21183 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/yax/yax.tex')
-rw-r--r--Master/texmf-dist/tex/generic/yax/yax.tex341
1 files changed, 226 insertions, 115 deletions
diff --git a/Master/texmf-dist/tex/generic/yax/yax.tex b/Master/texmf-dist/tex/generic/yax/yax.tex
index 17374883837..3bf74298414 100644
--- a/Master/texmf-dist/tex/generic/yax/yax.tex
+++ b/Master/texmf-dist/tex/generic/yax/yax.tex
@@ -4,26 +4,27 @@
% Author: Paul Isambert.
% E-mail: zappathustra AT free DOT fr
% Comments and suggestions are welcome.
-% Date: July 2010.
+% Date: January 2011.
%
-\input texapi % Everything I need. It figures: I wrote it for this.
-
\ifcsname yax@already_loaded\endcsname
\expandafter\endinput
\fi
+\input texapi % Everything I need. It figures: I wrote it for this.
+
\ifdefined\texapiversion
- \ifdim\texapiversion pt<1.02pt
- \senderror{YaX}{You need texapi with version at least 1.02. I quit}
+ \ifdim\texapiversion pt<1.03pt
+ \senderror{YaX}{You need texapi with version at least 1.03. I quit}
\expandafter\expandafter\expandafter\endinput
\fi
\else
- \senderror{YaX}{You need texapi with version at least 1.02. I quit}
+ % \texapiversion was introduced in v.1.02.
+ \senderror{YaX}{You need texapi with version at least 1.03. I quit}
\expandafter\endinput
\fi
\setcatcodes{@_=11}
-\def\yaxversion{1.02}
+\def\yaxversion{1.03}
\let\yax@already_loaded\relax
\def\yax@error{\senderror{YaX}}
@@ -54,7 +55,7 @@
%
%
%
-% SETTING PARAMETERS
+%%%%%%%%%%%%%%% SETTING PARAMETERS %%%%%%%%%%%%%%%
%
% The crux of the biscuit.
%
@@ -74,76 +75,207 @@
\yax@getparameter\yax@setparameter_getattributes
}
\long\def\yax@setparameter_getattributes#1#2\par{%
- \yax@space_loop{\yax@setparameter{#2}}{#1 }%
- }
-\long\def\yax@setparameter#1#2{%
- \deftrim\yax@parameter{#2}%
- \yax@setattributes_loop{#1 }% The space at the end delimits the last value if needed.
- }
-\newfor\yax@setattributes_loop#1={%
- \passtrim{#1}\yax@setattributes_checkprefix
- \addright\yax@attribute{ }% Final space delimiter
- \pausefor\yax@setattributes_howgiven
- }[\iffcs{yax@\yax@parameter @active}
- {\usecs{yax@\yax@parameter @def}}]
-\def\yax@setattributes_checkprefix#1{%
- \ifprefix{e:}{#1}
- {\let\yax@dodef\edefcs \removeprefixand{e:}{#1}{\deftrim\yax@attribute}}
- {\ifprefix{g:}{#1}
- {\let\yax@dodef\gdefcs \removeprefixand{g:}{#1}{\deftrim\yax@attribute}}
- {\ifprefix{x:}{#1}
- {\let\yax@dodef\xdefcs \removeprefixand{x:}{#1}{\deftrim\yax@attribute}}
- {\let\yax@dodef\defcs \def\yax@attribute{#1}}}}%
- }
-\def\yax@setattributes_howgiven{%
+ \yax@setparameter_getpairs{}{#2 }%
+ \expandafter\yax@space_loop\expandafter{\expandafter\yax@setparameter_assign\expandafter{\yax@setparameters_pairs}}{#1 }%
+ \yax@space_loop\yax@setparameter_execute{#1 }%
+ }
+\newfor\yax@setparameter_getpairs{1}#2={%
+ \pausefor{\skipspace{\passtrim{#2}{\yax@setparameter_checkprefix{\yax@setparameter_howgiven{#1}}}}}%
+ }[\def\yax@setparameters_pairs{#1}]
+
+\newstring{e:} \newstring{g:} \newstring{x:}
+\long\def\yax@setparameter_checkprefix#1#2{%
+ \ifprefix{e:}{#2}
+ {\removeprefixand{e:}{#2}\passtrim{#1\edefcs}}
+ {\ifprefix{g:}{#2}
+ {\removeprefixand{g:}{#2}\passtrim{#1\gdefcs}}
+ {\ifprefix{x:}{#2}
+ {\removeprefixand{x:}{#2}\passtrim{#1\xdefcs}}
+ {#1\defcs{#2}}}}%
+ }
+
+\long\def\yax@setparameter_howgiven#1#2#3{%
\ifnextnospace"
- \yax@setattributes_getquote
+ {\yax@setparameter_getquote{#1}{#2}{#3}}
% No need for a new nospace: it has been removed
{\ifcatnext\foo
- \yax@setattributes_getcommand
- \yax@setattributes_getspace}%
+ {\yax@setparameter_getcommand{#1}{#2}{#3}}
+ {\yax@setparameter_getspace{#1}{#2}{#3}}}%
+ }
+
+\long\def\yax@setparameter_getquote#1#2#3"#4"{%
+ \skipspace{\resumefor\yax@setparameter_getpairs{#1{#2}{#3}{#4}}}% Better not to forget this!
}
-\long\def\yax@setattribute_single#1#2{%
- \def\yax@attribute{#2}%
- \yax@setattributes_do{#1}%
+\long\def\yax@setparameter_getcommand#1#2#3#4{%
+ \skipspace{\resumefor\yax@setparameter_getpairs{#1{#2}{#3}{#4}}}%
}
-\long\def\yax@setattributes_getquote"#1"{%
- \passexpanded{\yax@space_loop{\yax@setattribute_single{#1}}}{\yax@attribute}%
- \skipspace{\resumefor\yax@setattributes_loop}% Better not to forget this!
+\long\def\yax@setparameter_getspace#1#2#3#4 {%
+ \skipspace{\resumefor\yax@setparameter_getpairs{#1{#2}{#3}{#4}}}%
}
-\long\def\yax@setattributes_getcommand#1{%
- \passexpanded{\yax@space_loop{\yax@setattribute_single{#1}}}{\yax@attribute}%
- \skipspace{\resumefor\yax@setattributes_loop}%
+
+\long\def\yax@setparameter_assign#1#2{%
+ \yax@setparameter_assignloop{#2}{#1}%
}
-\long\def\yax@setattributes_getspace#1 {%
- \passexpanded{\yax@space_loop{\yax@setattribute_single{#1}}}{\yax@attribute}%
- \skipspace{\resumefor\yax@setattributes_loop}%
+
+\newfor\yax@setparameter_assignloop{1}#2#3#4{%
+ \yax@space_loop{\yax@setparameter_do{#1}{#2}{#4}}{#3 }%
}
+
\newif\ifyax@makedef
-\long\def\yax@setattributes_do#1{%
+% #1 = parameter; #2 = \<|e|g|x>defcs; #3 = value; #4 = attribute
+\long\def\yax@setparameter_do#1#2#3#4{%
\yax@makedeftrue
- \iffcs{yax@\yax@parameter @restricted}% Parameter restricted.
- {\reverse\iffcs{yax@\yax@parameter:\yax@attribute @allowed}% Attribute not allowed.
+ \iffcs{yax@#1@restricted}% Parameter restricted.
+ {\reverse\iffcs{yax@#1:#4@allowed}% Attribute not allowed.
{\yax@makedeffalse
- \yax@error{Attribute `\unexpandedcs{yax@attribute}'
- is not allowed in parameter `\yax@parameter'.
- Authorized attributes are `\unexpandedcs{yax@\yax@parameter @restricted}'}}}%
- \ifcs{yax@\yax@parameter:\yax@attribute @restricted}% Attribute restricted in this parameter.
- {\reverse\iffcs{yax@\yax@parameter:\yax@attribute:\detokenize{#1}@allowed}% Value not allowed.
+ \yax@error{Attribute `#4' is not allowed in parameter `#1'.
+ Authorized attributes are `\unexpandedcs{yax@#1@restricted}'}}}%
+ \ifcs{yax@#1:#4@restricted}% Attribute restricted in this parameter.
+ {\reverse\iffcs{yax@#1:#4:\detokenize{#3}@allowed}% Value not allowed.
{\yax@makedeffalse
- \yax@error{Value `\detokenize{#1}'
- is not allowed in attribute `\yax@parameter:\yax@attribute'.
- Authorized values are `\unexpandedcs{yax@\yax@parameter:\yax@attribute @restricted}'}}}%
- {\iffcs{yax@attribute@\yax@attribute @restricted}% Attribute restricted in all parameters.
- {\reverse\iffcs{yax@attribute@\yax@attribute:\detokenize{#1}@allowed}% Value not allowed.
+ \yax@error{Value `\detokenize{#4}' is not allowed in attribute `#1:#4'.
+ Authorized values are `\unexpandedcs{yax@#1:#4@restricted}'}}}%
+ {\iffcs{yax@attribute@#4@restricted}% Attribute restricted in all parameters.
+ {\reverse\iffcs{yax@attribute@#4:\detokenize{#3}@allowed}% Value not allowed.
{\yax@makedeffalse
- \yax@error{Value `\detokenize{#1}'
- is not allowed in attribute `\yax@attribute'.
- Authorized values are `\unexpandedcs{yax@attribute@\yax@attribute @restricted}'}}}}%
+ \yax@error{Value `\detokenize{#3}' is not allowed in attribute `#4'.
+ Authorized values are `\unexpandedcs{yax@attribute@#4@restricted}'}}}}%
\ifyax@makedef
- \yax@dodef{yax@\yax@parameter:\yax@attribute}{#1}%
+ \reverse\iffcs{yax@#1@attributelist}{\gdefcs{yax@#1@attributelist}{}}%
+ \ifx#2\gdefcs
+ \passexpandedcs{\yax@parameterlist_add\global{#1}{#4}}{yax@#1@attributelist}%
+ \else\ifx#2\xdefcs
+ \passexpandedcs{\yax@parameterlist_add\global{#1}{#4}}{yax@#1@attributelist}%
+ \else
+ \passexpandedcs{\yax@parameterlist_add{}{#1}{#4}}{yax@#1@attributelist}%
+ \fi\fi
+ #2{yax@#1:#4}{#3}%
\fi
}
+
+\newfor\yax@parameterlist_add{3}#4{%
+ \iffstring{#3}{#4}{\breakfor{}}%
+ }[#1\eaddrightcs{yax@#2@attributelist}{{#3}}]
+
+\def\yax@setparameter_execute#1{%
+ \iffcs{yax@#1@active}{\usecs{yax@#1@def}}%
+ }
+%
+% \setparameterlist <list of parameters>[<default value>|*<cs>]<attribute>=<value>, ...
+%
+\def\setparameterlist#1{%
+ \ifnextnospace[
+ {\yax@setparameterlist_getdefault{#1}}
+ {\yax@setparameterlist_getdefault{#1}[]}%
+ }
+
+\def\yax@setparameterlist_getdefault#1[#2]#3{%
+ \yax@setparameterlist_loop{#1}{#2}{#3,}%
+ \yax@space_loop\yax@setparameter_execute{#1 }%
+ }
+
+\newstring{=}
+\newfornoempty\yax@setparameterlist_loop{2}#3,{%
+ \ifcontains={#3}
+ {\yax@setparameterlist_getargs{#1}#3\yax@endofentry}
+ {\ifemptystring{#2}
+ {\yax@setparameterlist_getargs{#1}#3=true\yax@endofentry}
+ {\passtrim{#3}{#2}}}%
+ }
+
+\long\def\yax@setparameterlist_getargs#1#2=#3\yax@endofentry{%
+ \yax@setparameter_checkprefix{\passtrim{#3}{\yax@setparameterlist_assign{#1}}}{#2}%
+ }
+
+\long\def\yax@setparameterlist_assign#1#2#3#4{%
+ \yax@space_loop{\yax@setparameterlist_do{#3}{#2}{#4}}{#1 }%
+ }
+
+\long\def\yax@setparameterlist_do#1#2#3#4{%
+ \yax@space_loop{\yax@setparameter_do{#4}{#1}{#2}}{#3 }%
+ }
+%
+% \setattribute <parameter> : <attribute> = <value>
+%
+\def\yax@removesign#1#2#3#4={#1{#2}{#3}}%
+\pdef\setattribute{%
+ \yax@getall{\yax@removesign{\yax@setattribute\defcs}}%
+ }
+\pdef\esetattribute{%
+ \yax@getall{\yax@removesign{\yax@setattribute\edefcs}}%
+ }
+\pdef\gsetattribute{%
+ \yax@getall{\yax@removesign{\yax@setattribute\gdefcs}}%
+ }
+\pdef\xsetattribute{%
+ \yax@getall{\yax@removesign{\yax@setattribute\xdefcs}}%
+ }
+\def\yax@setattribute#1#2#3{%
+ \skipspace{\yax@setattribute_getvalue{#1}{#2}{#3}}%
+ }
+\long\def\yax@setattribute_getvalue#1#2#3#4 {%
+ \yax@setparameter_do{#2}{#1}{#4}{#3}%
+ }
+%
+% \copyparameter <list of parameters> : <parameter>
+%
+\pdef\copyparameter{%
+ \yax@getall{\yax@copyparameter{}}%
+ }
+\pdef\gcopyparameter{%
+ \yax@getall{\yax@copyparameter\global}%
+ }
+\def\yax@copyparameter#1#2#3{%
+ \reverse\iffcs{yax@#3@attributelist}{#1\letcs{yax@#3@attributelist}\emptycs}%
+ \yax@space_loop{\yax@copyparameter_do{#1}{#3}}{#2 }%
+ }
+\def\yax@copyparameter_do#1#2#3{%
+ \iffcs{yax@#3@attributelist}{%
+ \passexpandedcs{\yax@parameterlist_copy{#1}{#3}{#2}}{yax@#3@attributelist}}%
+ }
+\newfor\yax@parameterlist_copy{3}#4{%
+ #1\letcstocs{yax@#3:#4}{yax@#2:#4}%
+ \passexpandedcs{\yax@parameterlist_add{#1}{#3}{#4}}{yax@#3@attributelist}%
+ }
+%
+%
+%
+% \deleteparameter <list of parameters>:
+%
+\pdef\deleteparameter{%
+ \yax@getparameter{\yax@deleteparameter{}}%
+ }
+\pdef\gdeleteparameter{%
+ \yax@getparameter{\yax@deleteparameter\global}%
+ }
+\def\yax@deleteparameter#1#2{%
+ \yax@space_loop{\yax@deleteparameter_do{#1}}{#2 }%
+ }
+\def\yax@deleteparameter_do#1#2{%
+ \iffcs{yax@#2@attributelist}{\passexpandedcs{\yax@parameterlist_delete{#1}{#2}}{yax@#2@attributelist}}%
+ }
+\newfor\yax@parameterlist_delete{2}#3{%
+ #1\letcs{yax@#2:#3}\yax@somethinghopefullyundefined
+ }[#1\letcs{yax@#2@attributelist}\yax@somethinghopefullyundefined]
+%
+%
+% \deleteattribute <parameter> : <attribute>
+%
+\def\deleteattribute{%
+ \yax@getall{\yax@deleteattribute{}}%
+ }
+\def\gdeleteattribute{%
+ \yax@getall{\yax@deleteattribute\global}%
+ }
+\def\yax@deleteattribute#1#2#3{%
+ \iffcs{yax@#2@attributelist}{%
+ #1\letcs{yax@#2:#3}\yax@undefined
+ \passexpandedcs{\yax@parameterlist_remove{#1\edefcs}{#2}{#3}{}}{yax@#2@attributelist}}%
+ }
+
+\newfor\yax@parameterlist_remove{4}#5{%
+ \reverse\iffstring{#3}{#5}{\passarguments{#1}{#2}{#3}{#4{#5}}}%
+ }[#1{yax@#2@attributelist}{#4}]
%
%
%
@@ -224,6 +356,7 @@
}%
\def\yax@defparameter_do{%
\passexpanded{\yax@space_loop\yax@defparameter_def}\yax@parameter
+ \yax@activeparameterfalse
}
\def\defactiveparameter{%
@@ -232,7 +365,6 @@
\long\def\yax@defparameter_def#1{%
\edefcs{yax@#1@def}{\primunexpanded\expandafter{\yax@temp{#1}}}%
\ifyax@activeparameter
- \yax@activeparameterfalse
\letcs{yax@#1@active}\relax
\fi
}
@@ -246,47 +378,7 @@
%
%
%
-% \deleteattribute <parameter> : <attribute>
-%
-\def\deleteattribute{%
- \yax@getall\yax@deleteattribute
- }
-\def\yax@deleteattribute#1#2{%
- \letcs{yax@#1:#2}\yax@undefined
- }
-%
-% \setattribute <parameter> : <attribute> = <value>
-%
-\def\yax@removesign#1#2#3#4={#1{#2}{#3}}%
-\def\setattribute{%
- \let\yax@dodef\defcs
- \yax@getall{\yax@removesign\yax@setattribute}%
- }
-\def\esetattribute{%
- \let\yax@dodef\edefcs
- \yax@getall{\yax@removesign\yax@setattribute}%
- }
-\def\gsetattribute{%
- \let\yax@dodef\gdefcs
- \yax@getall{\yax@removesign\yax@setattribute}%
- }
-\def\xsetattribute{%
- \let\yax@dodef\xdefcs
- \yax@getall{\yax@removesign\yax@setattribute}%
- }
-\def\yax@setattribute#1#2{%
- \def\yax@parameter{#1}%
- \def\yax@attribute{#2}%
- \skipspace\yax@setattribute_getvalue
- }
-\def\yax@setattribute_getvalue#1 {%
- \yax@setattributes_do{#1}%
- }
-%
-%
-%
-%
-% USING VALUES
+%%%%%%%%%%%%%%%%%% USING VALUES %%%%%%%%%%%%%%%%%%
%
% These are the loops used to check whether <parameter>:<attribute> exists,
% and if not to search the meta-parameters. They are used of course in
@@ -304,15 +396,15 @@
% #4 = <attribute>
% => doesn't change from one iteration to the next.
% #5 = <or> if alone, <and> when #6 exists.
-% #6 = <and>.
+% #6 = <or>.
% => neither change.
%
% The loop does the following:
% If <parameter>:<attribute> exists, then execute #2 on it followed by <and> if any.
% Or, if <parameter> has a meta attribute, it calls
% the \yax@ifattribute_checkmeta subloop with <or> and <parameter>
-% as passed arguments and <list of previous parameters> as the list argumen.
-% This command compare each item in the list with <parameter>, and if they
+% as passed arguments and <list of previous parameters> as the list argument.
+% This command compares each item in the list with <parameter>, and if they
% have the same meta, it means we're in a meta-loop, we break and execute <or>.
% If no match obtains, we rerun the original loop (with #3 turned to its meta).
% Or, if <parameter> had no meta in the first place, we break and execute <or>.
@@ -515,8 +607,30 @@
%
%
%
+% \parameterloop<list of parameters>:<command>
+%
+\def\parameterloop{%
+ \yax@getparameter\yax@parameterloop
+ }
+\long\def\yax@parameterloop#1#2{%
+ \yax@space_loop{\yax@parameterloop_launch{#2}}{#1 }%
+ }
+\long\def\yax@parameterloop_launch#1#2{%
+ \iffcs{yax@#2@attributelist}
+ {\passexpandedcs{\yax@parameterloop_do{#1}{#2}}{yax@#2@attributelist}}%
+ }
+\newfor\yax@parameterloop_do{2}#3{%
+ \passvalue{#1{#2}{#3}}{#2}:{#3}
+ }
+%
+%
+%
+%
% \newsyntax
%
+\long\def\newsyntax#1#{%
+ \yax@newsyntax{#1}%
+ }
\long\def\yax@newsyntax_noarg#1#2#3{%
\defcs{#1}#2{\yax@ifattribute_noarg{}{#3}{##1}{##2}}%
\defcs{#1or}#2{\yax@ifattribute_or{}{#3}{##1}{##2}}%
@@ -535,16 +649,13 @@
\defcs{yax@#1or_nometa}##1#2{\yax@ifattributenometa_or{#3{##1}}{##2}{##3}}%
\defcs{yax@#1and_nometa}##1#2{\yax@ifattributenometa_and{#3{##1}}{##2}{##3}}%
}
-\long\def\newsyntax#1#{%
- \yax@newsyntax{#1}%
- }
\long\def\yax@newsyntax#1#2{%
\defcs{#2restrictattribute}#1{\yax@restrictattribute_getrestrictions{##1}{##2}}%
\defcs{#2deleteattribute}#1{\letcs{yax@##1:##2}\yax@undefined}%
- \defcs{#2setattribute}#1{\let\yax@dodef\defcs\yax@removesign{\skipspace\yax@setattribute}{##1}{##2}}%
- \defcs{#2esetattribute}#1{\let\yax@dodef\edefcs\yax@removesign{\skipspace\yax@setattribute}{##1}{##2}}%
- \defcs{#2gsetattribute}#1{\let\yax@dodef\gdefcs\yax@removesign{\skipspace\yax@setattribute}{##1}{##2}}%
- \defcs{#2xsetattribute}#1{\let\yax@dodef\xdefcs\yax@removesign{\skipspace\yax@setattribute}{##1}{##2}}%
+ \defcs{#2setattribute}#1{\yax@removesign{\skipspace{\yax@setattribute\defcs}}{##1}{##2}}%
+ \defcs{#2esetattribute}#1{\yax@removesign{\skipspace{\yax@setattribute\edefcs}}{##1}{##2}}%
+ \defcs{#2gsetattribute}#1{\yax@removesign{\skipspace{\yax@setattribute\gdefcs}}{##1}{##2}}%
+ \defcs{#2xsetattribute}#1{\yax@removesign{\skipspace{\yax@setattribute\xdefcs}}{##1}{##2}}%
\defcs{#2ifattribute}#1{\yax@ifattribute_and{}\gobbleone{##1}{##2}}%
\defcs{yax@#2ifattribute_nometa}#1{\yax@ifattributenometa_and\gobbleone{##1}{##2}}%
\yax@newsyntax_noarg{#2usevalue}{#1}\usecs
@@ -593,4 +704,4 @@
}
\restorecatcodes
-\endinput \ No newline at end of file
+\endinput