diff options
author | Karl Berry <karl@freefriends.org> | 2021-09-21 19:46:31 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-09-21 19:46:31 +0000 |
commit | f8978870d707711cf4790fe169054f49679bd3bf (patch) | |
tree | 52cafe52a35846124bf2983795ead51200501917 /Master/texmf-dist/source/latex/expkv | |
parent | 2c4e4de2d3e3db565a628ffd6bae9d1e325b3a22 (diff) |
expkv (21sep21)
git-svn-id: svn://tug.org/texlive/trunk@60573 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/expkv')
-rw-r--r-- | Master/texmf-dist/source/latex/expkv/expkv.dtx | 181 |
1 files changed, 120 insertions, 61 deletions
diff --git a/Master/texmf-dist/source/latex/expkv/expkv.dtx b/Master/texmf-dist/source/latex/expkv/expkv.dtx index da6fcf2542f..8651ad97a33 100644 --- a/Master/texmf-dist/source/latex/expkv/expkv.dtx +++ b/Master/texmf-dist/source/latex/expkv/expkv.dtx @@ -43,6 +43,7 @@ This work consists of the file expkv.dtx and the derived files expkv.pdf expkv.sty expkv.tex + t-expkv.tex \endpreamble % stop docstrip adding \endinput @@ -50,6 +51,7 @@ and the derived files expkv.pdf \endpostamble \generate{\file{expkv.sty}{\from{expkv.dtx}{pkg}}} \generate{\file{expkv.tex}{\from{expkv.dtx}{tex}}} +\generate{\file{t-expkv.tex}{\from{expkv.dtx}{ctx}}} \ifx\fmtname\nameofplainTeX \expandafter\endbatchfile \else @@ -98,7 +100,7 @@ and the derived files expkv.pdf numexpr, protected, } - ,moretexcs=[5]^^A plain/LaTeX + ,moretexcs=[5]^^A plain/LaTeX/ConTeXt { approx, begin, @@ -112,6 +114,7 @@ and the derived files expkv.pdf TeX, textit,texttt, usepackage, + usemodule, } ,moretexcs=[6]^^A used packages { @@ -299,16 +302,25 @@ and the derived files expkv.pdf \newcommand\val{\meta{value}} \newcommand\set{\meta{set}} \hypersetup{linkcolor=red!80!black,urlcolor=purple!80!black} +\DoNotIndex{\directlua} \DoNotIndex{\def,\edef,\,,\=,\begingroup,\catcode,\chardef,\csname,\endcsname} \DoNotIndex{\endgroup,\endinput,\errmessage,\expandafter,\input,\let,\long} \DoNotIndex{\protected,\ProvidesFile,\ProvidesPackage,\relax,\space} -\DoNotIndex{\@,\unexpanded,\string,\expanded,\detokenize,\meaning,\lastnamedcs} -\DoNotIndex{\romannumeral,\z@} +\DoNotIndex{\^,\@,\unexpanded,\string,\expanded,\detokenize,\meaning} +\DoNotIndex{\lastnamedcs,\romannumeral,\z@} +\DoNotIndex{\noexpand,\normalexpanded,\normalunexpanded} +\DoNotIndex{\par,\protect} +\DoNotIndex{\unprotect} +\DoNotIndex{\writestatus} \DoNotIndex{\ifcsname} \DoNotIndex{\ifx} +\DoNotIndex{\iffalse} +\DoNotIndex{\ifnum} \DoNotIndex{\else} \DoNotIndex{\fi} -\@gobble\fi ^^A ignoring \ifx and \ifcsname, but only one \fi +\@gobble\fi ^^A ignoring \ifx etc., but only one \fi +\@gobble\fi ^^A ignoring \ifx etc., but only one \fi +\@gobble\fi ^^A ignoring \ifx etc., but only one \fi \@ifdefinable\gobbledocstriptag{\def\gobbledocstriptag#1>{}} \newcommand*\pmso[1] ^^A poor man's strike out {^^A @@ -365,15 +377,19 @@ and the derived files expkv.pdf % example \pkg{babel} turns characters active for some languages, for instance % the equal sign is turned active for Turkish. % -% \expkv\ is usable as generic code or as a \LaTeX\ package. To use it, just -% use one of: +% \expkv\ is usable as generic code, as a \LaTeX\ package or as a \ConTeXt\ +% module. To use it, just use one of: % \begin{lstlisting} -% \usepackage{expkv} % LaTeX % \input expkv % plainTeX +% \usepackage{expkv} % LaTeX +% \usemodule[expkv] % ConTeXt % \end{lstlisting} -% The \LaTeX\ package doesn't do more than \file{expkv.tex}, except calling -% |\ProvidesPackage| and setting things up such that \file{expkv.tex} will use -% |\ProvidesFile|. +% Both the \LaTeX\ package and the \ConTeXt\ module don't do more than +% \file{expkv.tex}, except calling |\ProvidesPackage| and setting things up such +% that \file{expkv.tex} will use |\ProvidesFile|, or printing some status +% information. The \ConTeXt\ support is not thoroughly tested, though (since I +% don't use \ConTeXt\ myself I don't know if there are additional pitfalls I +% wasn't aware of). % % In the \expkv\ family are other packages contained which provide additional % functionality. Those packages currently are: @@ -410,7 +426,7 @@ and the derived files expkv.pdf % prefixes allowed for |\let| can prefix those with ``|let|'' in their name, % accordingly. Neither \set\ nor \key\ are allowed to be empty for new keys. % \set\ will be used as is inside of |\csname ...\endcsname| and \key\ will get -% |\detokenize|d. +% |\detokenize|d. Also \set\ should not contain an explicit |\par| token. % % \begin{function}{\ekvdef} % \begin{syntax} @@ -919,6 +935,11 @@ and the derived files expkv.pdf % \end{verbatim} % Any clean up has to be done by you, |\ekverr| will expand to nothing after % throwing the error message. +% +% In \ConTeXt\ this macro works differently. While still being fully expandable, +% it doesn't have the character count limitation and doesn't impose restrictions +% on \meta{package}. It will not display the additional text and adding line +% breaks is not possible. % \example Say we set up a small calculation which works with user input. In our % calculation we need a division, so have to watch out for division by zero. If % we detect such a case we throw an error and do the recovery by using the @@ -926,7 +947,7 @@ and the derived files expkv.pdf % \begin{lstlisting} % \newcommand*\mydivision[2] % {% -% \number\numexpr +% \the\numexpr % \ifnum\numexpr#2=0 % space here on purpose % \ekverr{my}{division by 0. Setting result to 2147483647.}% % 2147483647% @@ -1562,6 +1583,27 @@ and the derived files expkv.pdf % \gobbledocstriptag %</pkg> %^^A=<< +%^^A the ConTeXt module >>= +% \subsection{The \ConTeXt\ module} +% This is pretty straight forward, we just have to change the error throwing +% mechanism for \ConTeXt\ (the approach taken for plain and \LaTeX\ breaks in +% \ConTeXt, effectively breaking \ConTeXt, dropping you in an interactive \TeX\ +% session with almost no means of escape). +% \gobbledocstriptag +%<*ctx> +% \begin{macrocode} +\writestatus{loading}{ConTeXt User Module / expkv} +\unprotect +\input expkv.tex +\long\def\ekv@err@collect#1\par#2% + {\directlua{tex.error[[\detokenize{#2} Error: #1]]}} +\writestatus{loading} + {ConTeXt User Module / expkv / Version \ekvVersion\space loaded} +\protect\endinput +% \end{macrocode} +% \gobbledocstriptag +%</ctx> +%^^A=<< %^^A main file >>= % \subsection{The Generic Code} % The rest of this implementation will be the generic code. @@ -1584,17 +1626,30 @@ and the derived files expkv.pdf \expandafter \endgroup \ifx\ekvtmpa\ekvtmpb + \expandafter\let\csname ekv@expanded\endcsname\expanded + \expandafter\let\csname ekv@unexpanded\endcsname\unexpanded \else - \errmessage{expkv Error: e-TeX and \noexpand\expanded required} - \expandafter\endinput + \begingroup + \edef\ekvtmpa{\string\expanded} + \edef\ekvtmpb{\meaning\normalexpanded} + \expandafter + \endgroup + \ifx\ekvtmpa\ekvtmpb + \expandafter\let\csname ekv@expanded\endcsname\normalexpanded + \expandafter\let\csname ekv@unexpanded\endcsname\normalunexpanded + \else + \errmessage + {expkv Error: e-TeX and the \noexpand\expanded primitive required}% + \expandafter\endinput + \fi \fi % \end{macrocode} % % \begin{macro}{\ekvVersion,\ekvDate} % We're on our first input, so lets store the version and date in a macro. % \begin{macrocode} -\def\ekvVersion{1.9} -\def\ekvDate{2021-07-15} +\def\ekvVersion{1.9a} +\def\ekvDate{2021-09-20} % \end{macrocode} % \end{macro} % @@ -1731,7 +1786,7 @@ and the derived files expkv.pdf % \begin{macrocode} \ekv@if@lastnamedcs {% - \def\ekv@ifdefined#1{\ifcsname#1\endcsname\ekv@ifdef@\fi\@secondoftwo} + \long\def\ekv@ifdefined#1{\ifcsname#1\endcsname\ekv@ifdef@\fi\@secondoftwo} \def\ekv@ifdef@\fi\@secondoftwo {% \fi @@ -1742,7 +1797,7 @@ and the derived files expkv.pdf } } {% - \def\ekv@ifdefined#1% + \long\def\ekv@ifdefined#1% {% \ifcsname#1\endcsname\ekv@ifdef@\fi\ekv@ifdef@false#1\endcsname\relax \ekv@fi@secondoftwo @@ -1853,7 +1908,7 @@ and the derived files expkv.pdf }% } \expandafter\ekv@csv@loop\expandafter{\ekv@strip{#2}} -\long\def\ekv@csv@loop@do#1#2{\unexpanded{#2{#1}}\ekv@csv@loop{#2}\ekv@mark} +\long\def\ekv@csv@loop@do#1#2{\ekv@unexpanded{#2{#1}}\ekv@csv@loop{#2}\ekv@mark} \def\ekv@csv@loop@end#1% {% \long\def\ekv@csv@loop@end @@ -1875,13 +1930,13 @@ and the derived files expkv.pdf % The keys will all follow the same naming scheme, so we define it here. % \begin{macrocode} \def\ekv@name@set#1{ekv#1(} -\def\ekv@name@key#1{#1)} +\long\def\ekv@name@key#1{#1)} \edef\ekv@name {% - \unexpanded\expandafter{\ekv@name@set{#1}}% - \unexpanded\expandafter{\ekv@name@key{\detokenize{#2}}}% + \ekv@unexpanded\expandafter{\ekv@name@set{#1}}% + \ekv@unexpanded\expandafter{\ekv@name@key{\detokenize{#2}}}% } -\ekv@exparg{\def\ekv@name#1#2}{\ekv@name} +\long\ekv@exparg{\def\ekv@name#1#2}{\ekv@name} % \end{macrocode} % \end{macro} % @@ -1908,15 +1963,15 @@ and the derived files expkv.pdf % \begin{macrocode} \edef\ekv@checkvalid {% - \unexpanded\expandafter{\ekv@ifempty{#1}}% - \unexpanded + \ekv@unexpanded\expandafter{\ekv@ifempty{#1}}% + \ekv@unexpanded {{% \def\ekv@tmp{}% \errmessage{expkv Error: empty set name not allowed}% }}% {% - \unexpanded\expandafter{\ekv@ifempty{#2}}% - \unexpanded + \ekv@unexpanded\expandafter{\ekv@ifempty{#2}}% + \ekv@unexpanded {% {% \def\ekv@tmp{}% @@ -1925,7 +1980,7 @@ and the derived files expkv.pdf \@secondoftwo }% }% - \unexpanded{\@gobble}% + \ekv@unexpanded{\@gobble}% } \ekv@exparg{\protected\def\ekv@checkvalid#1#2}{\ekv@checkvalid}% % \end{macrocode} @@ -1934,9 +1989,9 @@ and the derived files expkv.pdf % \begin{macro}{\ekvifdefined,\ekvifdefinedNoVal} % And provide user-level macros to test whether a key is defined. % \begin{macrocode} -\ekv@expargtwice{\def\ekvifdefined#1#2}% +\ekv@expargtwice{\long\def\ekvifdefined#1#2}% {\expandafter\ekv@ifdefined\expandafter{\ekv@name{#1}{#2}}} -\ekv@expargtwice{\def\ekvifdefinedNoVal#1#2}% +\ekv@expargtwice{\long\def\ekvifdefinedNoVal#1#2}% {\expandafter\ekv@ifdefined\expandafter{\ekv@name{#1}{#2}N}} % \end{macrocode} % \end{macro} @@ -1955,9 +2010,9 @@ and the derived files expkv.pdf {#1{\expandafter\def\csname#2\endcsname####1{##3}#3}}% \protected\long\def\ekvdefNoVal##1##2##3% {#1{\expandafter\def\csname#2N\endcsname{##3}#3}}% - \protected\def\ekvlet##1##2##3% + \protected\long\def\ekvlet##1##2##3% {#1{\expandafter\let\csname#2\endcsname##3#3}}% - \protected\def\ekvletNoVal##1##2##3% + \protected\long\def\ekvletNoVal##1##2##3% {#1{\expandafter\let\csname#2N\endcsname##3#3}}% \ekv@expargtwice{\protected\long\def\ekvdefunknown##1##2}% {% @@ -1981,7 +2036,7 @@ and the derived files expkv.pdf }% {\ekv@zero\ekv@checkvalid{##1}.}% }% - \protected\def\ekvletkv##1##2##3##4% + \protected\long\def\ekvletkv##1##2##3##4% {% #1% {% @@ -1990,7 +2045,7 @@ and the derived files expkv.pdf #3% }% }% - \protected\def\ekvletkvNoVal##1##2##3##4% + \protected\long\def\ekvletkvNoVal##1##2##3##4% {% #1% {% @@ -2002,13 +2057,13 @@ and the derived files expkv.pdf } \edef\ekvdefNoVal {% - {\unexpanded\expandafter{\ekv@checkvalid{#1}{#2}}}% - {\unexpanded\expandafter{\ekv@name{#1}{#2}}}% + {\ekv@unexpanded\expandafter{\ekv@checkvalid{#1}{#2}}}% + {\ekv@unexpanded\expandafter{\ekv@name{#1}{#2}}}% {% - \unexpanded{\expandafter\ekv@defsetmacro\csname}% - \unexpanded\expandafter{\ekv@undefined@set{#1}\endcsname{#1}}% + \ekv@unexpanded{\expandafter\ekv@defsetmacro\csname}% + \ekv@unexpanded\expandafter{\ekv@undefined@set{#1}\endcsname{#1}}% }% - {\unexpanded\expandafter{\ekv@name{#3}{#4}}}% + {\ekv@unexpanded\expandafter{\ekv@name{#3}{#4}}}% } \expandafter\ekvdef\ekvdefNoVal % \end{macrocode} @@ -2047,7 +2102,7 @@ and the derived files expkv.pdf \edef\ekv@tmp {% \ekvcsvloop#1{#6}% - \unexpanded{#2}% + \ekv@unexpanded{#2}% {\ekvcsvloop{}{#5,#6}}% }% \ekv@expargtwice @@ -2092,7 +2147,7 @@ and the derived files expkv.pdf {% \ifcsname#2\endcsname\ekv@redirect@kv@a\fi\@gobble{##1}% ##4{##1}{##2}% - } + }% \def\ekv@redirect@kv@a\fi\@gobble {\fi\expandafter\ekv@redirect@kv@b\lastnamedcs}% } @@ -2111,17 +2166,17 @@ and the derived files expkv.pdf \ifcsname#2\endcsname\ekv@redirect@kv@a\fi\ekv@redirect@kv@a@ #2\endcsname{##1}% ##4{##1}{##2}% - } + }% \long\def\ekv@redirect@kv@a@#4\endcsname##3{}% \def\ekv@redirect@kv@a\fi\ekv@redirect@kv@a@ {\fi\expandafter\ekv@redirect@kv@b\csname}% - } + }% } % \end{macrocode} % The key name given to this loop will already be |\detokenize|d by |\ekvset|, % so we can safely remove the |\detokenize| here for some performance gain. % \begin{macrocode} -\def\ekv@redirect@kv#1\detokenize#2#3\ekv@stop{\unexpanded{#1#2#3}} +\def\ekv@redirect@kv#1\detokenize#2#3\ekv@stop{\ekv@unexpanded{#1#2#3}} \edef\ekv@redirect@kv {% {\expandafter\ekv@redirect@kv\ekv@name{#2}{#1}N\ekv@stop}% @@ -2158,12 +2213,12 @@ and the derived files expkv.pdf % \begin{macrocode} \edef\ekv@defsetmacro {% - \unexpanded{\ifx#1\relax\edef#1##1}% + \ekv@unexpanded{\ifx#1\relax\edef#1##1}% {% - \unexpanded\expandafter{\ekv@name@set{#2}}% - \unexpanded\expandafter{\ekv@name@key{##1}}% + \ekv@unexpanded\expandafter{\ekv@name@set{#2}}% + \ekv@unexpanded\expandafter{\ekv@name@key{##1}}% }% - \unexpanded{\fi}% + \ekv@unexpanded{\fi}% } \ekv@exparg{\protected\def\ekv@defsetmacro#1#2}{\ekv@defsetmacro} % \end{macrocode} @@ -2341,12 +2396,12 @@ and the derived files expkv.pdf % \begin{macrocode} \edef\ekv@set@noeq {% - \unexpanded + \ekv@unexpanded {% \ekv@ifblank@##1\ekv@nil\ekv@ifempty@B\ekv@set@was@blank \ekv@ifempty@A\ekv@ifempty@B }% - \unexpanded\expandafter + \ekv@unexpanded\expandafter {\ekv@strip{##1}{\expandafter\ekv@set@key\detokenize}\ekv@mark}% } \ekv@exparg @@ -2398,12 +2453,15 @@ and the derived files expkv.pdf % macro, that has the same scope as |\keyval_parse:NNn| from \pkg{expl3}. % This is pretty analogue to the |\ekvset| implementation, we just put an % |\unexpanded| here and there instead of other macros to stop the |\expanded| -% on our output. The |\unexpanded\expanded{{...}}| ensures that the material is -% in an alignment safe group at all time, and that it doesn't expand any further -% in an |\edef| or |\expanded| context. +% on our output. The |\unexpanded\expanded{{...}}| ensures that the material +% is in an alignment safe group at all time, and that it doesn't expand any +% further in an |\edef| or |\expanded| context. % \begin{macrocode} \long\def\ekvparse##1##2##3% - {\unexpanded\expanded{{\ekv@parse{##1}{##2}\ekv@mark##3#1\ekv@stop#1}}} + {% + \ekv@unexpanded\ekv@expanded + {{\ekv@parse{##1}{##2}\ekv@mark##3#1\ekv@stop#1}}% + } % \end{macrocode} % \end{macro} % @@ -2485,12 +2543,12 @@ and the derived files expkv.pdf % \begin{macrocode} \edef\ekv@parse@noeq {% - \unexpanded + \ekv@unexpanded {% \ekv@ifblank@##1\ekv@nil\ekv@ifempty@B\ekv@parse@was@blank \ekv@ifempty@A\ekv@ifempty@B }% - \unexpanded\expandafter{\ekv@strip{##1}\ekv@parse@key}% + \ekv@unexpanded\expandafter{\ekv@strip{##1}\ekv@parse@key}% } \ekv@exparg {% @@ -2521,7 +2579,7 @@ and the derived files expkv.pdf {\ekv@strip{##2}\ekv@parse@pair@{##1}} \long\def\ekv@parse@pair@##1##2##3##4% {% - \unexpanded{##4{##2}{##1}}% + \ekv@unexpanded{##4{##2}{##1}}% \ekv@parse@other{##3}{##4}% } % \end{macrocode} @@ -2531,7 +2589,7 @@ and the derived files expkv.pdf % \begin{macrocode} \long\def\ekv@parse@key##1##2% {% - \unexpanded{##2{##1}}% + \ekv@unexpanded{##2{##1}}% \ekv@parse@other{##2}% } % \end{macrocode} @@ -2552,8 +2610,8 @@ and the derived files expkv.pdf % \begin{macrocode} \edef\ekvsetSneaked {% - \unexpanded{\ekvsneak{#2}}% - \unexpanded\expandafter{\ekvset{#1}{#3}}% + \ekv@unexpanded{\ekvsneak{#2}}% + \ekv@unexpanded\expandafter{\ekvset{#1}{#3}}% } \ekv@expargtwice{\long\def\ekvsetSneaked#1#2#3}{\ekvsetSneaked} % \end{macrocode} @@ -2891,7 +2949,8 @@ and the derived files expkv.pdf \ekv@exparg{\long\def\ekv@err@common@#1`#2' #3.#4#5}% {\ekv@err{#4 `#5' in set `#2'}} \ekv@exparg{\long\def\ekv@err@unknown#1}{\ekv@err@common{unknown key}{#1}} -\ekv@exparg{\long\def\ekv@err@noarg #1}{\ekv@err@common{unwanted value for}{#1}} +\ekv@exparg{\long\def\ekv@err@noarg #1} + {\ekv@err@common{unwanted value for}{#1}} \ekv@exparg{\long\def\ekv@err@reqval #1}{\ekv@err@common{missing value for}{#1}} \ekv@exparg{\long\def\ekv@err@redirect@kv@notfound#1#2#3\ekv@stop}% {\ekv@err{no key `#2' in sets #3}} |