| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2012 by Shengjun Pan <[email protected]> |
| 4 |
% ------------------------------------------------------- |
| 5 |
% |
| 6 |
% This file may be distributed and/or modified under the |
| 7 |
% conditions of the LaTeX Project Public License, either version 1.2 |
| 8 |
% of this license or (at your option) any later version. |
| 9 |
% The latest version of this license is in: |
| 10 |
% |
| 11 |
% http://www.latex-project.org/lppl.txt |
| 12 |
% |
| 13 |
% and version 1.2 or later is part of all distributions of LaTeX |
| 14 |
% version 1999/12/01 or later. |
| 15 |
% |
| 16 |
% \fi |
| 17 |
% |
| 18 |
% \iffalse |
| 19 |
%<*driver> |
| 20 |
\ProvidesFile{lmake.dtx} |
| 21 |
%</driver> |
| 22 |
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] |
| 23 |
%<package>\ProvidesPackage{lmake} |
| 24 |
%<*package> |
| 25 |
[2012/02/29 v1.0 .dtx lmake file] |
| 26 |
%</package> |
| 27 |
% |
| 28 |
%<*driver> |
| 29 |
\documentclass{ltxdoc} |
| 30 |
\usepackage{amsmath,amssymb} |
| 31 |
\usepackage[width=5.5in,height=8.6in]{geometry} |
| 32 |
\usepackage{multirow} |
| 33 |
\usepackage{graphicx} |
| 34 |
\usepackage{makeidx} |
| 35 |
\usepackage[usenames]{color} |
| 36 |
\usepackage{lmake}[2012/02/29] |
| 37 |
\EnableCrossrefs |
| 38 |
\CodelineIndex |
| 39 |
\RecordChanges |
| 40 |
\begin{document} |
| 41 |
\DocInput{lmake.dtx} |
| 42 |
\PrintChanges |
| 43 |
\PrintIndex |
| 44 |
\end{document} |
| 45 |
%</driver> |
| 46 |
% \fi |
| 47 |
% |
| 48 |
% \CheckSum{412} |
| 49 |
% |
| 50 |
% \CharacterTable |
| 51 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 52 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 53 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 54 |
% Exclamation \! Double quote \" Hash (number) \# |
| 55 |
% Dollar \$ Percent \% Ampersand \& |
| 56 |
% Acute accent \' Left paren \( Right paren \) |
| 57 |
% Asterisk \* Plus \+ Comma \, |
| 58 |
% Minus \- Point \. Solidus \/ |
| 59 |
% Colon \: Semicolon \; Less than \< |
| 60 |
% Equals \= Greater than \> Question mark \? |
| 61 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 62 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 63 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 64 |
% Right brace \} Tilde \~} |
| 65 |
% |
| 66 |
% |
| 67 |
% \changes{v1.0}{\filedate}{Initial version} |
| 68 |
% |
| 69 |
% \GetFileInfo{lmake.dtx} |
| 70 |
% |
| 71 |
% \DoNotIndex{\newcommand,\newenvironment} |
| 72 |
% \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ } |
| 73 |
% \DoNotIndex{\def,\edef,\if,\else,\fi,\begingroup,\endgroup} |
| 74 |
% \DoNotIndex{\@ifpackageloaded,\advance,\cdots,\csname,\endcsname} |
| 75 |
% \DoNotIndex{\dotsb,\dotsc,\empty,\end,\expandafter,\global} |
| 76 |
% \DoNotIndex{\i,\ifcase,\ifnum,\ifx,\or,\relax,\string,\the,\let} |
| 77 |
% \DoNotIndex{\ldots,\newcount,\newif,\noexpand,\protected@edef} |
| 78 |
% |
| 79 |
% |
| 80 |
% \title{The \texttt{lmake} package\thanks{This document |
| 81 |
% corresponds to \texttt{lmake}~\fileversion, dated \filedate.}} |
| 82 |
% \author{Shengjun Pan \\ \texttt{[email protected]}} |
| 83 |
% \date{} |
| 84 |
% \maketitle |
| 85 |
% \newcommand{\bs}{\char`\\} |
| 86 |
% \newcommand{\us}{\char`\_} |
| 87 |
% \newcommand{\ur}{\char`\^} |
| 88 |
% \renewcommand{\arraystretch}{1.2} |
| 89 |
% \setlength{\fboxsep}{1ex} |
| 90 |
% \definecolor{lightGray}{rgb}{0.85,0.85,0.85} |
| 91 |
% \definecolor{lightBlue}{rgb}{0.75,0.75,1} |
| 92 |
% \noindent\hspace*{-0.075\textwidth}\colorbox{lightGray}{\begin{minipage}{1.15\textwidth} |
| 93 |
% \[ |
| 94 |
% \lcmd{\hat}{h}{X,A,B,F,\mu,\phi,\sigma} |
| 95 |
% \lmake[\int_{\hX_\i=\hA_\i}^{\hB_\i},\empty] |
| 96 |
% \binom{N}{\lmake[\i\hphi_\i,,m]} |
| 97 |
% \lmake[e^{-\frac{(\hX_\i-\hmu_\i)^2}{2\hsigma_\i^2}},c=] |
| 98 |
% \lmake[d\hX_\i,\,] |
| 99 |
% \] |
| 100 |
% \tt |
| 101 |
% \bs lcmd\{\bs hat\}\{h\}\{X,A,B,F,\bs mu,\bs phi,\bs sigma\}\\ |
| 102 |
% \bs lmake[\bs in\us\{\bs hX\us\bs i=\bs hA\us\bs i\}\ur\{\bs hB\us\bs i\},\bs empty]\\ |
| 103 |
% \bs binom\{N\}\{\bs lmake[\bs i\bs hphi\us\bs i,,m]\}\\ |
| 104 |
% \bs lmake[e\ur\{-\bs frac\{(\bs hX\us\bs i-\bs hmu\us\bs i)\ur2\}\{2\bs hsigma\us\bs i\ur2\}\},c=]\\ |
| 105 |
% \bs lmake[d\bs hX\us\bs i,\bs,] |
| 106 |
% \end{minipage}} |
| 107 |
% \section{Introduction} |
| 108 |
% This package provides macros for \LaTeX2e to simplify typesetting a |
| 109 |
% list of phrases that fit a pattern.\\ |
| 110 |
% \begin{tabular}{ll} |
| 111 |
% \tt \char`\\lcmd |
| 112 |
% & makes a list of new commands by adding a prefix to existing |
| 113 |
% commands.\\ |
| 114 |
% \tt\char`\\lmake |
| 115 |
% & makes a list of the form $p(i_1),p(i_2),\dotsc,p(i_n)$, where |
| 116 |
% $p(.)$ stands for \emph{pattern}. |
| 117 |
% \end{tabular} |
| 118 |
% \section{Usage and examples} |
| 119 |
% \label{sec:usage} |
| 120 |
% \DescribeMacro{\lcmd} |
| 121 |
% \fcolorbox{black}{lightBlue}{\tt \char`\\lcmd\{command\}\{prefix\}\{list\}}\\[2ex] |
| 122 |
% makes a list of new commands from \texttt{command} by adding \texttt{prefix} |
| 123 |
% to each item in the comma-separated \texttt{list}. If an item in the |
| 124 |
% list is a macro, only its name is prefixed; the backslash is stripped away.\\[3ex] |
| 125 |
% \textbf{Examples}: |
| 126 |
% \footnote{The examples used in this document require packages {\tt amsmath, |
| 127 |
% amssymb} and {\tt graphicx}.}\\[1ex] |
| 128 |
% \lcmd{\mathcal}{c}{A,X,P} |
| 129 |
% \lcmd{\mathbb}{bb}{Z,R,E} |
| 130 |
% \lcmd{\overline}{vct}{x,\phi,psi} |
| 131 |
% \begin{tabular}{l@{ defines: }lll} |
| 132 |
% \hline |
| 133 |
% \verb|\lcmd{\mathcal}{c}{A,X,P}| |
| 134 |
% &\texttt{\char`\\ cA} $\to \cA$ |
| 135 |
% &\texttt{\char`\\ cX} $\to \cX$ |
| 136 |
% &\texttt{\char`\\ cP} $\to \cP$ |
| 137 |
% \\ |
| 138 |
% \verb|\lcmd{\mathbb}{c}{A,X,P}| |
| 139 |
% &\texttt{\char`\\ bbZ} $\to \bbZ$ |
| 140 |
% &\texttt{\char`\\ bbR} $\to \bbR$ |
| 141 |
% &\texttt{\char`\\ bbE} $\to \bbE$\\ |
| 142 |
% \verb|\lcmd{\overline}{vct}{x,psi,\phi}| |
| 143 |
% &\texttt{\char`\\ vctx} $\to \vctx$ |
| 144 |
% &\texttt{\char`\\ vctpsi} $\to \vctpsi$ |
| 145 |
% &\texttt{\char`\\ vctphi} $\to \vctphi$\\ |
| 146 |
% \hline |
| 147 |
% \end{tabular}\\[2ex] |
| 148 |
% In the last example the new command for \verb|\phi| is |
| 149 |
% \verb|\vctphi|, not \verb|\vct\phi|. Notice the difference between |
| 150 |
% \verb|\vctphi| and \verb|\vctpsi|.\\[4ex] |
| 151 |
% \DescribeMacro{\lmake} |
| 152 |
% \fcolorbox{black}{lightBlue}{\tt\bs lmake[[key1=]value1,[key2=]value2,...]}\\[2ex] |
| 153 |
% makes a list of symbols by key-value pairs. Valid keys are |
| 154 |
% described in the following table.\\[3ex] |
| 155 |
% \begin{tabular}{@{\tt }rll} |
| 156 |
% \hline |
| 157 |
% keys & default & description\\ |
| 158 |
% \hline |
| 159 |
% p & \verb|\i| & Pattern. All occurrences of \verb|\i| will be replaced |
| 160 |
% by the corresponding index.\\ |
| 161 |
% c & \verb|,| & Separator.\\ |
| 162 |
% n &\verb|n| & Last index.\\ |
| 163 |
% 1 & \verb|1| & First index.\\ |
| 164 |
% 2 & \verb|2| & Second index.\\ |
| 165 |
% d & \verb|\ldots|, \verb|\cdots| & Dots. If the separator is comma, |
| 166 |
% \verb|\ldots| is used; otherwise \verb|\cdots| is used.\\ |
| 167 |
% & \verb|\dotsc|, \verb|\dotsb| & If \verb|amsmath| is loaded, |
| 168 |
% \verb|\dotsc| and \verb|\dotsb| are used respectively.\\ |
| 169 |
% $\ell$ & \verb|{}| & List of comma-separated symbols.\\ |
| 170 |
% \hline |
| 171 |
% \end{tabular}\\[3ex] |
| 172 |
% \textbf{Examples}:\\[1ex] |
| 173 |
% \begin{tabular}{ll} |
| 174 |
% \hline |
| 175 |
% what you type & what you see\\ |
| 176 |
% \hline |
| 177 |
% \verb|\lmake[]| & $\lmake[]$\\ |
| 178 |
% \verb|\lmake[2=]| & $\lmake[2=]$\\ |
| 179 |
% \verb|\lmake[x_\i,c=]| & $\lmake[x_\i,c=]$\\ |
| 180 |
% \verb|\lmake[x_\i,,N]| & $\lmake[x_\i,,N]$\\ |
| 181 |
% \verb|\lmake[x_\i,\ge,k]| & $\lmake[x_\i,\ge,k]$\\ |
| 182 |
% \verb|\lmake[\bar x_{\i},\circ,1=i,i+1]| & $\lmake[\bar x_{\i},\circ,1=i,i+1]$\\ |
| 183 |
% \verb|\lmake[p_\i^{\mu_\i},c=,m]| & $\lmake[p_\i^{\mu_\i},c=,m]$\\ |
| 184 |
% \verb|\lmake[N_\i!,\,,\Gamma,\alpha,\beta]| & $\lmake[N_\i!,\,,\Gamma,\alpha,\beta]$\\ |
| 185 |
% \verb|\lmake[\left(\frac{\i}{\i+1}\right),\!]| |
| 186 |
% & $\lmake[\left(\frac{\i}{\i+1}\right),\!]$\\ |
| 187 |
% \verb|\lmake[(e_\i+1),c=,k,1,2]| & $\lmake[(e_\i+1),c=,k,1,2]$\\[1ex] |
| 188 |
% \verb|\lmake[x_{\i},l={1,3,5,11}]| |
| 189 |
% & $\lmake[x_{\i},l={1,3,5,11}]$\\ |
| 190 |
% \verb|\lmake[\rotatebox{-30}{\i},\to,l={A,B,C,D}]| |
| 191 |
% & $\lmake[\rotatebox{-30}{\i},\to,l={A,B,C,D}]$\\ |
| 192 |
% \hline |
| 193 |
% \end{tabular}\\[2ex] |
| 194 |
% \emph{Remarks:} |
| 195 |
% \begin{itemize} |
| 196 |
% \item If $\tt \ell$ is empty, the resulting list has the following form:\\ |
| 197 |
% \verb|p(1) c p(2) c d c p(n)| |
| 198 |
% |
| 199 |
% If $\tt \ell$ is not empty, the resulting list has the |
| 200 |
% following form, for the example $\tt \ell=\{x,y,z,u\}$:\\ |
| 201 |
% \verb|p(x) c p(y) c p(z) c p(u)| |
| 202 |
% \item A \underline{non-empty item without \texttt{=}} in the argument |
| 203 |
% list is treated as a value. Normally the key-value pairs can appear |
| 204 |
% out of order in the argument list to \verb|\lmake|. For fast typing |
| 205 |
% the key can be omitted. The missing key is searched, starting from |
| 206 |
% the key that would follow the previous key in the table-order. Only |
| 207 |
% keys without values are searched. |
| 208 |
% |
| 209 |
% For example, in \verb|\lmake[\bar x_{\i},\circ,1=i,i+1]|, the |
| 210 |
% missing key for \verb|\bar x_{\i}| is \verb|p|, the missing key for |
| 211 |
% \verb|\circ| is \verb|c| since it follows \verb|p| in the |
| 212 |
% table. Similarly, the missing key for \verb|i+1| is \verb|2| since |
| 213 |
% it follows the previous key \verb|1| in the able. |
| 214 |
% \item A key not appearing or skipped in the argument list takes its |
| 215 |
% default value, unless it's been searched as a missing key and given |
| 216 |
% a value. |
| 217 |
% |
| 218 |
% For example, in \verb|\lamke[x_\i,,N]|, all keys except for \verb|p| |
| 219 |
% and \verb|n| take default values. Particularly, the key \verb|c| is |
| 220 |
% skipped and it is treated as missing. |
| 221 |
% |
| 222 |
% Note that a skipped key does not take value \emph{empty}. To force a |
| 223 |
% value to be empty, use one of the following workarounds: |
| 224 |
% {\tt \char`\\empty}, {\tt key=}, {\tt key=\char`\\empty}, or {\tt |
| 225 |
% key=\{\}}. |
| 226 |
% \end{itemize} |
| 227 |
% |
| 228 |
% \StopEventually{} |
| 229 |
% |
| 230 |
% \section{Implementation} |
| 231 |
% This section explains in details how verb|\lmake|, \verb|\lcmd| and |
| 232 |
% necessary internal macros are implemented. |
| 233 |
% \begin{macro}{\L@Compare} |
| 234 |
% \verb|\L@Compare{string1}{string2}|\\ |
| 235 |
% compares two strings. The two arguments are fully expanded before compassion. |
| 236 |
% \verb|\ifL@Equal| is a Boolean variable for storing the result. |
| 237 |
% \begin{macrocode} |
| 238 |
\newif\ifL@Equal |
| 239 |
\def\L@Compare#1#2{% |
| 240 |
\protected@edef\L@a{#1}\protected@edef\L@b{#2}% |
| 241 |
\ifx\L@a\L@b\L@Equaltrue\else\L@Equalfalse\fi} |
| 242 |
% \end{macrocode} |
| 243 |
% \end{macro} |
| 244 |
% \begin{macro}{\L@FuzzyCompare} |
| 245 |
% \verb|\L@FuzzyCompare{string1}{string2}|\\ |
| 246 |
% tests if two strings are the same, where white spaces preceding the |
| 247 |
% second argument are ignores. This allows flexible writing of |
| 248 |
% the comma-separated argument to \verb|\lmake| so that spaces may be inserted |
| 249 |
% between an item and the previous comma. |
| 250 |
% \begin{macrocode} |
| 251 |
\def\L@FuzzyCompare#1#2{% |
| 252 |
\L@Compare{#1}{#2}\ifL@Equal\else\L@Compare{#1}{ #2}\fi} |
| 253 |
% \end{macrocode} |
| 254 |
% \end{macro} |
| 255 |
% \begin{macro}{\L@SoftCompare} |
| 256 |
% \verb|\L@SoftCompare{string1}{string2}|\\ |
| 257 |
% similar to \verb|\L@Compare|, but does not expand the two |
| 258 |
% strings. This is usefully if either argument contains undefined |
| 259 |
% macros, for example, the value to the key \verb|p| in the argument to \verb|\lmake|. |
| 260 |
% \begin{macrocode} |
| 261 |
\def\L@SoftCompare#1#2{% |
| 262 |
\def\L@a{#1}\def\L@b{#2}% |
| 263 |
\ifx\L@a\L@b\L@Equaltrue\else\L@Equalfalse\fi} |
| 264 |
% \end{macrocode} |
| 265 |
% \end{macro} |
| 266 |
% \begin{macro}{\L@FuzzySoftCompare} |
| 267 |
% \verb|\L@FuzzySoftCompare{string1}{string2}|\\ |
| 268 |
% similar to \verb|L@FuzzyCompare|, but uses \verb|\L@SoftCompare| |
| 269 |
% instead of \verb|\L@Compare|. |
| 270 |
% \begin{macrocode} |
| 271 |
\def\L@FuzzySoftCompare#1#2{% |
| 272 |
\L@SoftCompare{#1}{#2}\ifL@Equal\else\L@SoftCompare{#1}{ #2}\fi} |
| 273 |
% \end{macrocode} |
| 274 |
% \end{macro} |
| 275 |
% \begin{macro}{\L@HasEqualSign} |
| 276 |
% \verb|\L@HasEqualSign{string}|\\ |
| 277 |
% tests if a string has an equal sign \verb|=|. This is used to test |
| 278 |
% if an argument to \verb|\lmake| is a key-value pair or just a |
| 279 |
% value. It is defined indirectly via \verb|\L@HES|, which is a tail |
| 280 |
% recursion for scanning the tokens in its argument.\\[1ex] |
| 281 |
% \verb|\L@Ignore| is an auxiliary macro that simply ignores its |
| 282 |
% argument. The test result is stored in \verb|\ifL@HasEqualSign|. |
| 283 |
% \begin{macrocode} |
| 284 |
\def\L@Ignore#1\end{} |
| 285 |
\newif\ifL@HasEqualSign |
| 286 |
\def\L@HasEqualSign#1{% |
| 287 |
\L@HasEqualSignfalse\L@HES#1\end} |
| 288 |
\def\L@HES#1{% |
| 289 |
\ifx#1=\L@HasEqualSigntrue\let\L@Next=\L@Ignore% |
| 290 |
\else\ifx#1\end\let\L@Next=\relax\else\let\L@Next=\L@HES\fi% |
| 291 |
\fi\L@Next} |
| 292 |
% \end{macrocode} |
| 293 |
% \end{macro} |
| 294 |
% \begin{macro}{\L@ArName} |
| 295 |
% \verb|\L@ArName[index]|\\ |
| 296 |
% returns the name of a macro via a numeric index. |
| 297 |
% \begin{macrocode} |
| 298 |
\def\L@ArName[#1]{\ifcase#1 L@Pattern\or L@Comma\or L@Last\or% |
| 299 |
L@First\or L@Second\or L@Dots\or L@List\else L@Other\fi} |
| 300 |
% \end{macrocode} |
| 301 |
% \end{macro} |
| 302 |
% \begin{macro}{\L@Set,\L@Get} |
| 303 |
% \verb|\L@Set[index]=value;|\\ |
| 304 |
% \verb|\L@Get[Index]|\\ |
| 305 |
% set and get the value of a macro by a numeric index. Numeric indices are |
| 306 |
% used to locate missing keys in the argument to \verb|\lmake|. |
| 307 |
% \begin{macrocode} |
| 308 |
\def\L@Set[#1]=#2;{\global\expandafter\let\csname\L@ArName[#1]\endcsname=#2} |
| 309 |
\def\L@Get[#1]{\csname\L@ArName[#1]\endcsname} |
| 310 |
% \end{macrocode} |
| 311 |
% \end{macro} |
| 312 |
% \begin{macro}{\L@LDots,\L@Cdots} |
| 313 |
% denotes the default macro for low dots. If \verb|amsmath| is loaded before |
| 314 |
% \verb|\lmake|, \verb|\L@LDots| is set to \verb|\dotsc| and |
| 315 |
% \verb|\L@Cdots| is set to \verb|\dotsb|. Otherwise \verb|\L@LDots| |
| 316 |
% is set to \verb|\ldots| and \verb|\L@Cdots| is set to \verb|\cdots|. |
| 317 |
% \begin{macrocode} |
| 318 |
\@ifpackageloaded{amsmath} |
| 319 |
{\def\L@Ldots{\dotsc}\def\L@Cdots{\dotsb}} |
| 320 |
{\def\L@Ldots{\ldots}\def\L@Cdots{\cdots}} |
| 321 |
% \end{macrocode} |
| 322 |
% \end{macro} |
| 323 |
% \begin{macro}{\L@Map} |
| 324 |
% \verb|\L@Map{function}{list}{new separator}|\\ |
| 325 |
% maps a list of comma-separated items to a new list, so that each |
| 326 |
% item is transformed using the given function, and the commas are |
| 327 |
% replaced with the new separator. It is defined indirectly |
| 328 |
% indirectly via \verb|\L@Iterate|, which is a tail recursion for |
| 329 |
% scanning the comma-separated list.\\[1ex] |
| 330 |
% \verb|\ifL@Start| is used to indicate if the current item is the |
| 331 |
% first item, which is not preceded by a comma, unlike the remaining |
| 332 |
% items.\\[1ex] |
| 333 |
% \verb|\L@Map| |
| 334 |
% \begin{macrocode} |
| 335 |
\newif\ifL@Start |
| 336 |
\def\L@Map#1#2#3{% |
| 337 |
\def\L@Sym{\empty}\def\LM@Func{#1}\def\L@Sep{#3}% |
| 338 |
\L@Starttrue\expandafter\L@Iterate#2,\end} |
| 339 |
\def\L@Iterate#1,#2{% |
| 340 |
\LM@Func{#1}% |
| 341 |
\ifx#2\end\let\L@Next=\relax\def\L@Nextarg{\empty}% |
| 342 |
\else\L@Sep\let\L@Next=\L@Iterate\def\L@Nextarg{#2}\fi% |
| 343 |
\expandafter\L@Next\L@Nextarg} |
| 344 |
% \end{macrocode} |
| 345 |
% \end{macro} |
| 346 |
% \begin{macro}{\L@GetKeyValue} |
| 347 |
% \verb|\L@GetKeyValue{key-value pair}|\\ |
| 348 |
% extracts the key and value from a string, and store them in |
| 349 |
% \verb|\L@Key| and \verb|\L@Value| respectively. If the argument has no |
| 350 |
% equal sign, it is used as a value and the key is set to empty. Otherwise, |
| 351 |
% \verb|\L@GetKV| is called to extract the key and value. |
| 352 |
% \begin{macrocode} |
| 353 |
\def\L@GetKeyValue#1{% |
| 354 |
\def\L@Key{}\def\L@Value{}\L@HasEqualSign{#1}% |
| 355 |
\ifL@HasEqualSign\L@GetKV#1\end% |
| 356 |
\else\def\L@Key{}\def\L@Value{#1}% |
| 357 |
\fi} |
| 358 |
\def\L@GetKV#1=#2\end{% |
| 359 |
\def\L@Key{#1}\def\L@Value{#2}} |
| 360 |
% \end{macrocode} |
| 361 |
% \end{macro} |
| 362 |
% \begin{macro}{\L@Parse} |
| 363 |
% \verb|\L@Parse{list}|\\ |
| 364 |
% parses a list of comma-separated items, extracts each item, |
| 365 |
% extract its key and value, looks for keys \verb|p|, \verb|c|, |
| 366 |
% \verb|n|, \verb|1|, \verb|2|, \verb|d| and \verb|l|, and finally assigns the |
| 367 |
% corresponding values to \verb|\L@Pattern|, \verb|\L@Comma|, |
| 368 |
% \verb|\L@Last|, \verb|\L@First|, \verb|\l@Second|, \verb|\L@Dots| |
| 369 |
% and \verb|\L@List| respectively.\\[1ex] |
| 370 |
% The counter \verb|\L@idx| is the index of the next key yet to be assigned |
| 371 |
% with an value. |
| 372 |
% \begin{macrocode} |
| 373 |
\newcount\L@idx |
| 374 |
% \end{macrocode} |
| 375 |
% If the list is not empty, then it calls a tail recursion \verb|\l@PRS|. |
| 376 |
% \begin{macrocode} |
| 377 |
\def\L@Parse#1{\L@idx=0% |
| 378 |
\L@FuzzySoftCompare{#1}{}% |
| 379 |
\ifL@Equal\else\def\L@Extra{}\L@PRS#1,\end,\fi} |
| 380 |
% \end{macrocode} |
| 381 |
% An artificial item \verb|,\end,| |
| 382 |
% is added to the end of the actual list, which terminates the |
| 383 |
% recursion when encountered. |
| 384 |
% \begin{macrocode} |
| 385 |
\def\L@PRS#1,{% |
| 386 |
\L@SoftCompare{#1}{\end}\ifL@Equal% |
| 387 |
\let\L@Next=\relax% |
| 388 |
\else% |
| 389 |
% \end{macrocode} |
| 390 |
% If an item is empty, the missing key is searched and |
| 391 |
% the corresponding default value is used. |
| 392 |
% \begin{macrocode} |
| 393 |
\L@FuzzySoftCompare{#1}{}\ifL@Equal% |
| 394 |
\ifnum\L@idx<7% |
| 395 |
\ifcase\the\L@idx% |
| 396 |
\def\L@Default{\i}% |
| 397 |
\or\def\L@Default{,}% |
| 398 |
\or\def\L@Default{n}% |
| 399 |
\or\def\L@Default{1}% |
| 400 |
\or\def\L@Default{2}% |
| 401 |
\or\def\L@Default{}% |
| 402 |
\or\def\L@Default{}% |
| 403 |
\fi% |
| 404 |
\L@Set[\the\L@idx]=\L@Default;% |
| 405 |
\advance \L@idx by 1% |
| 406 |
\fi% |
| 407 |
% \end{macrocode} |
| 408 |
% If the item is not empty, the key and value are extracted. Depending |
| 409 |
% on what the key is, the value is assigned to the approximate macro. |
| 410 |
% \begin{macrocode} |
| 411 |
\else% |
| 412 |
\L@GetKeyValue{#1}\let\L@CV=\L@Value% |
| 413 |
\L@FuzzyCompare{\L@Key}{p}\ifL@Equal\L@idx=1\L@Set[0]=\L@CV;% |
| 414 |
\else\L@FuzzyCompare{\L@Key}{c}\ifL@Equal\L@idx=2\L@Set[1]=\L@CV;% |
| 415 |
\else\L@FuzzyCompare{\L@Key}{n}\ifL@Equal\L@idx=3\L@Set[2]=\L@CV;% |
| 416 |
\else\L@FuzzyCompare{\L@Key}{1}\ifL@Equal\L@idx=4\L@Set[3]=\L@CV;% |
| 417 |
\else\L@FuzzyCompare{\L@Key}{2}\ifL@Equal\L@idx=5\L@Set[4]=\L@CV;% |
| 418 |
\else\L@FuzzyCompare{\L@Key}{d}\ifL@Equal\L@idx=6\L@Set[5]=\L@CV;% |
| 419 |
\else\L@FuzzyCompare{\L@Key}{l}\ifL@Equal\L@idx=7\L@Set[6]=\L@CV;% |
| 420 |
% \end{macrocode} |
| 421 |
% If an item is a value without a key, the missing key is searched and |
| 422 |
% given the current value. |
| 423 |
% \begin{macrocode} |
| 424 |
\else\L@FuzzyCompare{\L@Key}{}\ifL@Equal% |
| 425 |
\ifnum\L@idx<7% |
| 426 |
\L@Set[\the\L@idx]=\L@CV;% |
| 427 |
\fi% |
| 428 |
\advance \L@idx by 1% |
| 429 |
\fi\fi\fi\fi\fi\fi\fi\fi\fi% |
| 430 |
\let\L@Next=\L@PRS% |
| 431 |
\fi% |
| 432 |
\L@Next} |
| 433 |
% \end{macrocode} |
| 434 |
% \end{macro} |
| 435 |
% \begin{macro}{\lmake} |
| 436 |
% \verb|\lmake[key-value list]|\\ |
| 437 |
% makes a list of symbols using the given key-value |
| 438 |
% pairs. \verb|\ifL@FoundFirst| is used to indicate if the first |
| 439 |
% non-empty symbol is encountered; the first symbol is not preceded |
| 440 |
% by a separator. |
| 441 |
% \begin{macrocode} |
| 442 |
\newif\ifL@FoundFirst |
| 443 |
% \end{macrocode} |
| 444 |
% \verb|\L@Parse| is used twice. The first time it is used to set the |
| 445 |
% default values. The second time it is used to set the values |
| 446 |
% supplied by the argument list. |
| 447 |
% \begin{macrocode} |
| 448 |
\newcommand{\lmake}[1][]{% |
| 449 |
\begingroup% |
| 450 |
\L@Parse{p=\i,c={,},d=,1=1,2=2,n=n,l=}% |
| 451 |
\L@Parse{#1}% |
| 452 |
% \end{macrocode} |
| 453 |
% The pattern is used to define the transforming function |
| 454 |
% \verb|\L@Func| by replacing all occurrences of \verb|\i| by the |
| 455 |
% actual argument. |
| 456 |
% \begin{macrocode} |
| 457 |
\def\L@Func##1{\def\i{##1}\L@Get[0]}% |
| 458 |
% \end{macrocode} |
| 459 |
% If the key \verb|d| is not given a value, its value is automatically determined by |
| 460 |
% the value of the separator. |
| 461 |
% \begin{macrocode} |
| 462 |
\L@Compare{\L@Dots}{\empty}\ifL@Equal% |
| 463 |
\L@Compare{\L@Comma}{,}\ifL@Equal% |
| 464 |
\def\L@Dots{\L@Ldots}\else\def\L@Dots{\L@Cdots}% |
| 465 |
\fi |
| 466 |
\fi |
| 467 |
% \end{macrocode} |
| 468 |
% The last step is to typeset the list of symbols. If the value to the key $\ell$ is |
| 469 |
% missing, the typeset list starts with two symbols followed by the dots and |
| 470 |
% ends with the last symbol. The symbols and dots are separated by the |
| 471 |
% separator. |
| 472 |
% \begin{macrocode} |
| 473 |
\L@Compare{\L@List}{\empty}\ifL@Equal% |
| 474 |
\L@FoundFirstfalse% |
| 475 |
\L@Compare{\L@First}{\empty}\ifL@Equal\else% |
| 476 |
\L@Func{\L@First}\L@FoundFirsttrue% |
| 477 |
\fi% |
| 478 |
\L@Compare{\L@Second}{\empty}\ifL@Equal\else% |
| 479 |
\ifL@FoundFirst\L@Comma\fi% |
| 480 |
\L@Func{\L@Second}\L@FoundFirsttrue% |
| 481 |
\fi% |
| 482 |
\L@Compare{\L@Dots}{\empty}\ifL@Equal\else% |
| 483 |
\ifL@FoundFirst\L@Comma\fi\L@Dots% |
| 484 |
\fi% |
| 485 |
\L@Compare{\L@Last}{\empty}\ifL@Equal\else% |
| 486 |
\L@Comma\L@Func{\L@Last}% |
| 487 |
\fi% |
| 488 |
% \end{macrocode} |
| 489 |
% If a non-empty value to the key $\ell$ is given, the typeset list |
| 490 |
% consists of symbols from the items in the value of $\ell$, |
| 491 |
% transformed by the pattern function. |
| 492 |
% \begin{macrocode} |
| 493 |
\else% |
| 494 |
\L@Map{\L@Func}{\L@List}{\L@Comma}% |
| 495 |
\fi% |
| 496 |
\endgroup} |
| 497 |
% \end{macrocode} |
| 498 |
% \end{macro} |
| 499 |
% \begin{macro}{\L@CmdName} |
| 500 |
% \verb|\L@CmdName{string}|\\ |
| 501 |
% returns the string itself if it is not a macro, otherwise returns |
| 502 |
% the macro name with the backslash stripped away. This is an |
| 503 |
% auxiliary function to \verb|\lcmd|. |
| 504 |
% \begin{macrocode} |
| 505 |
\def\L@CmdName#1{% |
| 506 |
\if\noexpand#1\noexpand\L@anycmd\expandafter\L@StripFirst\string#1\else#1\fi} |
| 507 |
\def\L@StripFirst#1#2{#2} |
| 508 |
% \end{macrocode} |
| 509 |
% \end{macro} |
| 510 |
% \begin{macro}{\lcmd} |
| 511 |
% \verb|\lcmd{command}{prefix}{list}|\\ |
| 512 |
% makes a list of new commands. See Section~\ref{sec:usage} for more details. |
| 513 |
% \begin{macrocode} |
| 514 |
\def\lcmd#1#2#3{% |
| 515 |
\def\L@MakeCmd##1{% |
| 516 |
\expandafter\def\csname #2\L@CmdName##1\endcsname{#1{##1}}}% |
| 517 |
\L@Map{\L@MakeCmd}{#3}{}} |
| 518 |
% \end{macrocode} |
| 519 |
% \end{macro} |
| 520 |
% \Finale |
| 521 |
\endinput |
| 522 |
|