Debian Codegraph @

texmf-dist/source/latex/coolstr/coolstr.dtx

raw
1 % \iffalse
2 %
3 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
4 %<package>\ProvidesPackage{coolstr}
5 %<package> [2023/05/03 v2.2 COntent Oriented LaTeX Strings]
6 %<package>\RequirePackage{ifthen}
7 %<package>\RequirePackage{amsmath}
8 %<package>\RequirePackage{amssymb}
9 %
10 % Update on 2023/05/03 purely to clarify the license; no code changes.
11 % This package is released under the GNU LGPL.
12 %
13 %<*driver>
14 \documentclass{ltxdoc}
15 \usepackage{coolstr}
16 \usepackage{url}
17 \usepackage{pdflscape}
18 \EnableCrossrefs
19 \CodelineIndex
20 \RecordChanges
21 \begin{document}
22 \DocInput{coolstr.dtx}
23 \end{document}
24 %</driver>
25 % \fi
26 %
27 %
28 % \CheckSum{314}
29 %
30 %
31 %% \CharacterTable
32 %% {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
33 %% 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
34 %% Digits \0\1\2\3\4\5\6\7\8\9
35 %% Exclamation \! Double quote \" Hash (number) \#
36 %% Dollar \$ Percent \% Ampersand \&
37 %% Acute accent \' Left paren \( Right paren \)
38 %% Asterisk \* Plus \+ Comma \,
39 %% Minus \- Point \. Solidus \/
40 %% Colon \: Semicolon \; Less than \<
41 %% Equals \= Greater than \> Question mark \?
42 %% Commercial at \@ Left bracket \[ Backslash \\
43 %% Right bracket \] Circumflex \^ Underscore \_
44 %% Grave accent \` Left brace \{ Vertical bar \|
45 %% Right brace \} Tilde \~}
46 %
47 % \changes{v1.0}{2006/09/17}{Initial Release}
48 % \changes{v2.0}{2006/12/29}{Added three new commands: \texttt{ifstrchareq}, \texttt{ifstrleneq}, \texttt{strlen}}
49 %
50 % \GetFileInfo{coolstr.sty}
51 %
52 % \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ ,\!,\(,\),\,}
53 % \DoNotIndex{\@ne,\expandafter}
54 % \DoNotIndex{\advance,\begingroup,\catcode,\closein}
55 % \DoNotIndex{\newcommand,\renewcommand,\providecommand}
56 % \DoNotIndex{\closeout,\day,\def,\edef,\gdef,\xdef,\let,\empty,\endgroup}
57 % \DoNotIndex{\newcounter,\providecounter,\addtocounter,\setcounter,\stepcounter,\value,\arabic}
58 % \DoNotIndex{\if,\fi,\ifthenelse,\else,\setboolean,\boolean,\newboolean,\provideboolean,\equal,\AND,\OR,\NOT,\whiledo}
59 % \DoNotIndex{\ifcase,\ifcat,\or,\else}
60 % \DoNotIndex{\par,\parbox,\mbox,\hbox,\begin,\end,\nabla,\partial}
61 % \DoNotIndex{\overline,\bar,\small,\tiny,\mathchoice,\scriptsize,\textrm,\texttt}
62 % \DoNotIndex{\alpha,\beta,\gamma,\epsilon,\varepsilon,\delta,\zeta,\eta,\theta,\vartheta,\iota,\kappa,\lambda,\mu,\nu}
63 % \DoNotIndex{\xi,\omicron,\pi,\varpi,\rho,\varrho,\sigma,\tau,\upsilon,\phi,\varphi,\chi,\psi,\omega}
64 % \DoNotIndex{\Delta,\Gamma,\Theta,\Lambda,\Xi,\Pi,\Sigma,\Phi,\Psi,\Omega}
65 % \DoNotIndex{\digamma,\lceil,\rceil,\lfloor,\rfloor,\left,\right,\inp,\inb,\inbr,\inap,\nop}
66 % \DoNotIndex{\sum,\prod,\int,\log,\ln,\exp,\sin,\cos,\tan,\csc,\sec,\cot,\arcsin,\arccos,\arctan,\det}
67 % \DoNotIndex{\sinh,\cosh,\tanh,\csch,\sech,\coth,\arcsinh,\arccosh,\arctanh}
68 % \DoNotIndex{\mod,\max,\min,\gcd,\lcm,\wp,\arg,\dots,\infty,}
69 % \DoNotIndex{\frac,\binom,\braket,\@@atop}
70 % \DoNotIndex{\cdot,\ldots,\tilde,\times,\dagger,\relax}
71 % \DoNotIndex{\mathbb,\roman,\bf,\mathord,\cal,\DeclareMathOperator,\PackageError,\PackageWarning}
72 % \DoNotIndex{\csname,\endcsname,\ifx,\ifnum}
73 % \DoNotIndex{\COOL@Hypergeometric@pq,\COOL@Hypergeometric@pq@ab@value,\hideOnSF,\COOL@decide@paren}
74 % \DoNotIndex{\COOL@decide@indicies}
75 % \DoNotIndex{\mod,\bmod,\pmod,\pod,\operatorname}
76 %
77 % \title{The \textsf{coolstr} package\thanks{This document
78 % corresponds to \textsf{cool}~\fileversion,
79 % dated~\filedate.}}
80 % \author{nsetzer}
81 %
82 % \maketitle
83 %
84 % \setcounter{IndexColumns}{2}
85 % \StopEventually{\PrintChanges\PrintIndex}
86 %
87 % The \textsf{coolstr} package is a ``sub" package of the \textsf{cool} package that seemed appropriate to publish
88 % independently since it may occur that one wishes to include the ability to check strings without having to accept
89 % all the overhead of the \textsf{cool} package itself.
90 %
91 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 %\section{Basics}
94 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 %
97 % Strings are defined as a sequence of characters (not \TeX{} tokens). The main purpose behind treating strings as
98 % characters rather than tokens is that one can then do some text manipulation on them.
99 %
100 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 %\section{Descriptions}
103 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 %
106 % \DescribeMacro{\substr} |\substr|\marg{string}\marg{start index}\marg{num char} gives at most $\|$\meta{num char}$\|$
107 % characters from \meta{string}.
108 %
109 % if \meta{start index} is greater than zero, and \meta{num char} is greater than zero, |\substr| gives at most
110 % \meta{num char} starting with index \meta{start index} and going to the end of the string.
111 %
112 % if \meta{start index} is greater than zero, and \meta{num char} is less than zero, |\substr| gives at most
113 % $-$\meta{num char} characters and going to the beginning of the string
114 %
115 % if \meta{start index} is less than zero, and \meta{num char} is greater than zero, |\substr| gives at most
116 % \meta{num char} characters starting at the $-$\meta{start index} character from the end of the string and going
117 % to the end of the string
118 %
119 % if \meta{start index} is less than zero, and \meta{num char} is less than zero, |\substr| gives at most
120 % $-$\meta{num char} characters starting at the $-$\meta{start index} character from the end of the string and going
121 % to the beginning of the string
122 %
123 % There are two special, non-numeric values that \meta{char num} may take. They are |end| or |beg|, and they will always
124 % go to the end or begining of the string, respectively
125 %
126 %
127 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 %\section{Test Cases}
130 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 %
133 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
135 %\subsection{\texttt{$\backslash$substr}}
136 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
137 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138 %
139 % \DescribeMacro{\substr}
140 %
141 % \begin{tabular}{ll}
142 % \hline
143 % |\substr{12345}{1}{2}| & \substr{12345}{1}{2} \\
144 % |\substr{12345}{3}{5}| & \substr{12345}{3}{5} \\
145 % |\substr{12345}{3}{end}| & \substr{12345}{3}{end} \\
146 % |\substr{12345}{3}{beg}| & \substr{12345}{3}{beg} \\
147 % |\substr{12345}{-2}{1}| & \substr{12345}{-2}{1} \\
148 % |\substr{12345}{3}{-2}| & \substr{12345}{3}{-2} \\
149 % |\substr{12345}{-2}{-2}| & \substr{12345}{-2}{-2} \\
150 % |\substr{12345}{0}{5}| & \substr{12345}{0}{5} (the null string) \\
151 % |\substr{12345}{2}{0}| & \substr{12345}{2}{0} (the null string) \\
152 % \hline
153 % \end{tabular}
154 %
155 %
156 % \newboolean{t}
157 %
158 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
160 %\subsection{\texttt{$\backslash$isdecimal}}
161 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
162 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 %
164 %
165 % \begin{tabular}{ll}
166 % (null str) & \isdecimal{}{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal} \\
167 % \textvisiblespace & \isdecimal{ }{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal} \\
168 % \textvisiblespace\textvisiblespace
169 % & \isdecimal{ }{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal} \\
170 % |2.345| & \isdecimal{2.345}{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal} \\
171 % |2.4.5| & \isdecimal{2.4.5}{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal} \\
172 % |+-2.45| & \isdecimal{+-2.45}{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal} \\
173 % |+2.345| & \isdecimal{+2.345}{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal} \\
174 % |-2.345| & \isdecimal{-2.345}{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal} \\
175 % |2.345-| & \isdecimal{2.345-}{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal} \\
176 % |2.4+4.| & \isdecimal{2.4+4.5}{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal} \\
177 % |+4.| & \isdecimal{+4.}{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal} \\
178 % |4.| & \isdecimal{4.}{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal} \\
179 % |+.7| & \isdecimal{+.7}{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal} \\
180 % |.3| & \isdecimal{.3}{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal} \\
181 % |4| & \isdecimal{4}{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal} \\
182 % & |\newcommand{\numberstore}{4.5}| \\
183 % |\numberstore| & \newcommand{\numberstore}{4.5} \isdecimal{\numberstore}{t} \ifthenelse{ \boolean{t} }{is decimal}{not a decimal}
184 % \end{tabular}
185 %
186 %
187 %
188 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
190 %\subsection{\texttt{$\backslash$isnumeric}}
191 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
192 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193 %
194 %
195 % \begin{tabular}{ll}
196 % (null str) & \isnumeric{}{t} \ifthenelse{ \boolean{t} }{is numeric}{not numeric} \\
197 % \textvisiblespace & \isnumeric{ }{t} \ifthenelse{ \boolean{t} }{is numeric}{not numeric} \\
198 % \textvisiblespace\textvisiblespace
199 % & \isnumeric{ }{t} \ifthenelse{ \boolean{t} }{is numeric}{not numeric} \\
200 % |4.5| & \isnumeric{4.5}{t} \ifthenelse{ \boolean{t} }{is numeric}{not numeric} \\
201 % |4.5e5| & \isnumeric{4.5e5}{t} \ifthenelse{ \boolean{t} }{is numeric}{not numeric} \\
202 % |+4.5e5| & \isnumeric{+4.5e5}{t} \ifthenelse{ \boolean{t} }{is numeric}{not numeric} \\
203 % |4.5e+5| & \isnumeric{4.5e+5}{t} \ifthenelse{ \boolean{t} }{is numeric}{not numeric} \\
204 % |+4.5e+5| & \isnumeric{+4.5e+5}{t} \ifthenelse{ \boolean{t} }{is numeric}{not numeric} \\
205 % |4.5E5| & \isnumeric{4.5E5}{t} \ifthenelse{ \boolean{t} }{is numeric}{not numeric} \\
206 % |-4.5E5| & \isnumeric{-4.5E5}{t} \ifthenelse{ \boolean{t} }{is numeric}{not numeric} \\
207 % |4.5E-5| & \isnumeric{4.5E-5}{t} \ifthenelse{ \boolean{t} }{is numeric}{not numeric} \\
208 % |-4.5E-5| & \isnumeric{-4.5E-5}{t} \ifthenelse{ \boolean{t} }{is numeric}{not numeric} \\
209 % |4.5.E-5| & \isnumeric{4.5.E-5}{t} \ifthenelse{ \boolean{t} }{is numeric}{not numeric} \\
210 % |abcdefg| & \isnumeric{abcdefg}{t} \ifthenelse{ \boolean{t} }{is numeric}{not numeric} \\
211 % |abcE-5| & \isnumeric{abcE-5}{t} \ifthenelse{ \boolean{t} }{is numeric}{not numeric}
212 % \end{tabular}
213 %
214 %
215 %
216 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
218 %\subsection{\texttt{$\backslash$isint}}
219 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
220 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 %
222 %
223 % \begin{tabular}{ll}
224 % (null str) & \isint{}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
225 % \textvisiblespace & \isint{ }{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
226 % \textvisiblespace\textvisiblespace
227 % & \isint{ }{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
228 % |4| & \isint{4}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
229 % |+4| & \isint{+4}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
230 % |4.5| & \isint{4.5}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
231 % |4.5e5| & \isint{4.5e5}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
232 % |+4.5e5| & \isint{+4.5e5}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
233 % |4.5e+5| & \isint{4.5e+5}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
234 % |+4.5e+5| & \isint{+4.5e+5}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
235 % |4.5E5| & \isint{4.5E5}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
236 % |-4.5E5| & \isint{-4.5E5}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
237 % |4.5E-5| & \isint{4.5E-5}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
238 % |-4.5E-5| & \isint{-4.5E-5}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
239 % |4.5.E-5| & \isint{4.5.E-5}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
240 % |abcdefg| & \isint{abcdefg}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
241 % |abcE-5| & \isint{abcE-5}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer} \\
242 % & |\renewcommand{\numberstore}{4}| \\
243 % |\numberstore| & \newcommand{\numberstore}{4} \isint{\numberstore}{t} \ifthenelse{ \boolean{t} }{is integer}{not integer}
244 % \end{tabular}
245 %
246 %
247 %
248 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 %\section{Acknowledgments}
251 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 %
254 % Thanks to J.~J.~Weimer for the comments and aid in coding.
255 %
256 % \noindent Thanks goes to Abraham Weishaus for pointing out a bug in |\strlenstore|
257 %
258 % \noindent Thanks to Daniel Kucerovsky for pointing the `blank-space' bug of |\isnumeric| (and consequently |\isdecimal|).
259 %
260 %
261 % \begin{landscape}
262 %
263 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265 %\section{Implementation}
266 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
267 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
268 %
269 % This is just an internal counter for dealing with the strings; most often used for the length
270 %
271 % \begin{macrocode}
272 \newcounter{COOL@strlen}%
273 % \end{macrocode}
274 %
275 % \begin{macro}{\setstrEnd}
276 %
277 % |\setstrEnd{|\meta{string}|}| allows the user to set the end of a string `character'
278 % in the rare event that the default value actually appears in the string.
279 % The default value is
280 %
281 % \begin{macrocode}
282 \newcommand{\COOL@strEnd}{\%\%\%}
283 \newcommand{\COOL@intEnd}{\%@\%@\%@}
284 \let\COOL@strStop=\relax
285 % \end{macrocode}
286 %
287 % and may be changed by the following command (which utilizes the |\renewcommand|):
288 %
289 % \begin{macrocode}
290 \newcommand{\setstrEnd}[1]{\renewcommand{\COOL@strEnd}{#1}}
291 % \end{macrocode}
292 %
293 % \end{macro}
294 %
295 %
296 % This area defines the core technology behind the \textsf{coolstr} package: the string ``gobbler".
297 %
298 % \begin{macrocode}
299 \newcounter{COOL@strpointer}
300 % \end{macrocode}
301 %
302 % Now we come to ``the gobbler"---a recursive function that eats up a string.
303 % It must be written in \TeX{} primatives.
304 %
305 % The idea behind this is that ``the gobbler" eats up everything before the desired character and everything
306 % after the desired character.
307 %
308 % \begin{macrocode}
309 \def\COOL@strgobble[#1]#2#3{%
310 \ifthenelse{\equal{#3}{\COOL@strEnd}}%
311 {%
312 \ifthenelse{\value{COOL@strpointer}=#1}%
313 {%
314 #2%
315 }%
316 % Else
317 {%
318 }%
319 }%
320 % Else
321 {%
322 \ifthenelse{\value{COOL@strpointer}=#1}%
323 {%
324 #2%
325 }%
326 % Else
327 {%
328 }%
329 \stepcounter{COOL@strpointer}%
330 \COOL@strgobble[#1]#3%
331 }%
332 }
333 % \end{macrocode}
334 %
335 % \begin{macro}{\strchar}
336 % |\strchar|\marg{index} gives the \meta{index} character of the string. Strings start indexing at $1$.
337 %
338 % \begin{macrocode}
339 \newcommand{\strchar}[2]{%
340 \setcounter{COOL@strpointer}{1}%
341 \COOL@strgobble[#2]#1\COOL@strEnd%
342 }
343 % \end{macrocode}
344 %
345 % \end{macro}
346 %
347 %
348 % \begin{macro}{\strlen}
349 % \changes{v2.0}{2006/12/29}{added to package}
350 % \changes{v2.1}{2007/01/08}{added ifthenelse to return $0$ for empty string}
351 % |\strlen|\marg{string} gives the length of the string. It is better to use |\strlenstore| to record the length
352 %
353 % |\strlen{abc}| \strlen{abc}
354 %
355 % \begin{macrocode}
356 \newcommand{\strlen}[1]{%
357 \ifthenelse{\equal{#1}{}}%
358 {%
359 0%
360 }%
361 % Else
362 {%
363 \strchar{#1}{0}%
364 \arabic{COOL@strpointer}%
365 }%
366 }
367 % \end{macrocode}
368 %
369 % \end{macro}
370 %
371 %
372 % \begin{macro}{\strlenstore}
373 % \changes{v2.0}{2006/12/29}{added to package}
374 % \changes{v2.1}{2007/01/08}{corrected error in setting counter}
375 % \changes{v2.1}{2007/01/08}{added ifthenelse to return $0$ for empty string}
376 % |\strlenstore|\marg{string}\marg{counter} stores the length of \meta{string} in \meta{counter}
377 %
378 % \begin{macrocode}
379 \newcommand{\strlenstore}[2]{%
380 \ifthenelse{\equal{#1}{}}%
381 {%
382 \setcounter{#2}{0}%
383 }%
384 % Else
385 {%
386 \strchar{#1}{0}%
387 \setcounter{#2}{\value{COOL@strpointer}}%
388 }%
389 }
390 % \end{macrocode}
391 %
392 % \end{macro}
393 %
394 %
395 %
396 %
397 % \begin{macro}{\substr}
398 % \changes{v2.1}{2007/01/08}{added to package}
399 % |\substr|\marg{string}\marg{index}\marg{numchar}
400 %
401 % a special value of |end| for \meta{numchar} gives from \meta{index} to the end of the string; |beg| gives from \meta{index} to the beginning of the string
402 %
403 % \begin{macrocode}
404 \newcounter{COOL@str@index}
405 \newcounter{COOL@str@start}
406 \newcounter{COOL@str@end}
407 \newcommand{\substr}[3]{%
408 \strlenstore{#1}{COOL@strlen}%
409 \ifthenelse{#2 < 0 \AND \NOT #2 < -\value{COOL@strlen}}%
410 {%
411 % \end{macrocode}
412 % The starting index is less than zero, so start that many characters back from the end. This means mapping the index to \meta{index}${} + {}$\meta{string length}${} + 1$
413 % \begin{macrocode}
414 \setcounter{COOL@str@index}{\value{COOL@strlen}}%
415 \addtocounter{COOL@str@index}{#2}%
416 \addtocounter{COOL@str@index}{1}%
417 }%
418 % ElseIf
419 {\ifthenelse{#2 > 0 \AND \NOT #2 > \value{COOL@strlen}}%
420 {%
421 % \end{macrocode}
422 % The starting index is greater than zero, and within the appropriate range; record it
423 % \begin{macrocode}
424 \setcounter{COOL@str@index}{#2}%
425 }%
426 % Else
427 {%
428 % \end{macroccode}
429 % The \meta{index} value is invalid. Set it to zero for returning the null string
430 % \begin{macrocode}
431 \setcounter{COOL@str@index}{0}%
432 }}%
433 % \end{macrocode}
434 % Now deal with the \meta{numchar} (which can also be negative)
435 % \begin{macrocode}
436 \ifthenelse{\equal{#3}{beg}}%
437 {%
438 \setcounter{COOL@str@start}{1}%
439 \setcounter{COOL@str@end}{\value{COOL@str@index}}%
440 }%
441 % ElseIf
442 {\ifthenelse{\equal{#3}{end}}%
443 {%
444 \setcounter{COOL@str@start}{\value{COOL@str@index}}%
445 \setcounter{COOL@str@end}{\value{COOL@strlen}}%
446 }%
447 % ElseIf
448 {\ifthenelse{#3 < 0}%
449 {%
450 % \end{macrocode}
451 % This means to take that many characters to the \emph{left} of the starting index.
452 % \begin{macrocode}
453 \setcounter{COOL@str@start}{\value{COOL@str@index}}%
454 \addtocounter{COOL@str@start}{#3}%
455 \addtocounter{COOL@str@start}{1}%
456 \ifthenelse{\NOT \value{COOL@str@start} > 0}{\setcounter{COOL@str@start}{1}}{}%
457 \setcounter{COOL@str@end}{\value{COOL@str@index}}%
458 }%
459 % ElseIf
460 {\ifthenelse{#3 > 0}%
461 {%
462 \setcounter{COOL@str@start}{\value{COOL@str@index}}%
463 \setcounter{COOL@str@end}{\value{COOL@str@index}}%
464 \addtocounter{COOL@str@end}{#3}%
465 \addtocounter{COOL@str@end}{-1}%
466 \ifthenelse{\value{COOL@str@end} > \value{COOL@strlen}}{\setcounter{COOL@str@end}{\value{COOL@strlen}}}{}%
467 }%
468 % Else
469 {%
470 % \end{macrocode}
471 % nonsense submitted, so return the null string
472 % \begin{macrocode}
473 \setcounter{COOL@str@index}{0}%
474 }}}}%
475 % \end{macrocode}
476 % Now send back the appropriate thing
477 % \begin{macrocode}
478 \ifthenelse{ \value{COOL@str@index} = 0 }%
479 {%
480 }%
481 % Else
482 {%
483 \setcounter{COOL@strpointer}{1}%
484 \COOL@substrgobbler#1\COOL@strStop\COOL@strEnd%
485 }%
486 }
487 % \end{macrocode}
488 % Now define the ``gobbler"
489 % \begin{macrocode}
490 \def\COOL@substrgobbler#1#2\COOL@strEnd{%
491 \ifthenelse{\equal{#2}{\COOL@strStop}}%
492 {%
493 \ifthenelse{ \value{COOL@strpointer} < \value{COOL@str@start} \OR \value{COOL@strpointer} > \value{COOL@str@end} }%
494 {}%
495 % Else
496 {%
497 #1%
498 }%
499 }%
500 % Else
501 {%
502 \ifthenelse{ \value{COOL@strpointer} < \value{COOL@str@start} \OR \value{COOL@strpointer} > \value{COOL@str@end} }%
503 {}%
504 % Else
505 {%
506 #1%
507 }%
508 \stepcounter{COOL@strpointer}%
509 \COOL@substrgobbler#2\COOL@strEnd%
510 }%
511 }
512 % \end{macrocode}
513 %
514 % \end{macro}
515 %
516 %
517 % Define a new boolean for comparing characters
518 %
519 % \begin{macrocode}
520 \newboolean{COOL@charmatch}
521 % \end{macrocode}
522 %
523 % \begin{macro}{\COOL@strcomparegobble}
524 % This ``gobbler" does character comparison
525 % \changes{v2.0}{2006/12/29}{added to package for single character comparisons}
526 %
527 % \begin{macrocode}
528 \def\COOL@strcomparegobble[#1]<#2>#3#4{%
529 \ifthenelse{\equal{#4}{\COOL@strEnd}}%
530 {%
531 \ifthenelse{\value{COOL@strpointer}=#1 \AND \equal{#2}{#3} }%
532 {%
533 \setboolean{COOL@charmatch}{true}%
534 }%
535 % Else
536 {%
537 }%
538 }%
539 % Else
540 {%
541 \ifthenelse{\value{COOL@strpointer}=#1 \AND \equal{#2}{#3} }%
542 {%
543 \setboolean{COOL@charmatch}{true}%
544 }%
545 % Else
546 {%
547 }%
548 \stepcounter{COOL@strpointer}%
549 \COOL@strcomparegobble[#1]<#2>#4%
550 }%
551 }
552 % \end{macrocode}
553 % \end{macro}
554 %
555 % \begin{macro}{\ifstrchareq}
556 % |\ifstrchareq|\marg{string}\marg{char index}\marg{comparison char}\marg{do if true}\marg{do if false}
557 % \changes{v2.0}{2006/12/29}{added to package to do character comparing}
558 %
559 % \begin{macrocode}
560 \newcommand{\ifstrchareq}[5]{%
561 \setboolean{COOL@charmatch}{false}%
562 \setcounter{COOL@strpointer}{1}%
563 \COOL@strcomparegobble[#2]<#3>#1\COOL@strEnd\relax%
564 \ifthenelse{ \boolean{COOL@charmatch} }%
565 {%
566 #4%
567 }%
568 % Else
569 {%
570 #5%
571 }%
572 }
573 % \end{macrocode}
574 % \end{macro}
575 %
576 %
577 % \begin{macro}{\ifstrleneq}
578 % |\ifstrleneq|\marg{string}\marg{number}\marg{do if true}\marg{do if false}
579 %
580 % \noindent |\ifstrleneq{abc}{3}{length is $3$}{length is not $3$}| \ifstrleneq{abc}{3}{length is $3$}{length is not $3$}
581 %
582 % \noindent |\ifstrleneq{abcde}{3}{length is $3$}{length is not $3$}| \ifstrleneq{abcde}{3}{length is $3$}{length is not $3$}
583 %
584 % \changes{v2.0}{2006/12/29}{added to package to do length comparison}
585 % \changes{v2.1}{2007/01/08}{altered function to use \texttt{strlenstore}}
586 %
587 % \begin{macrocode}
588 \newcommand{\ifstrleneq}[4]{%
589 \strlenstore{#1}{COOL@strlen}%
590 \ifthenelse{ \value{COOL@strlen} = #2 }%
591 {%
592 #3%
593 }%
594 % Else
595 {%
596 #4%
597 }%
598 }
599 % \end{macrocode}
600 % \end{macro}
601 %
602 %
603 % \begin{macro}{\COOL@decimalgobbler}
604 %
605 % This ``gobbler" is used to determine if the submitted string is a rational number (satisfies $d_n d_{n-1} \cdots d_1 d_0 . d_{-1} d_{-2} \cdots d_{-m}$). The idea behind the macro is that it assumes the string is rational until it encounters a non-numeric object
606 % \changes{v2.0}{2006/12/29}{added this ``gobbler'' to complete \texttt{isnumeric}}
607 %
608 % \begin{macrocode}
609 \newboolean{COOL@decimalfound}
610 \newboolean{COOL@decimal}
611 % \end{macrocode}
612 %
613 % |COOL@decimalfound| is a boolean indicating if the first decimal point is found
614 %
615 % |COOL@decimal| is the flag that tells if the string contains numeric data
616 %
617 % \begin{macrocode}
618 \def\COOL@decimalgobbler#1#2\COOL@strEnd{%
619 % \end{macrocode}
620 % \changes{v2.2}{2009/09/09}{fixed blank space bug (blank space causes code to `crash')}
621 % \begin{macrocode}
622 \ifthenelse{\equal{#1}{\COOL@strStop}}%
623 {%
624 % \end{macrocode}
625 % user submitted a null string, which can not be numeric
626 % \begin{macrocode}
627 \setboolean{COOL@decimal}{false}%
628 }%
629 {\ifthenelse{\equal{#2}{\COOL@strStop}}%
630 % \end{macrocode}
631 % this indicates we are at the end of the string. We only need to perform the check to see if the digit is a number or the first decimal point
632 % \begin{macrocode}
633 {%
634 \ifthenelse{`#1 < `0 \OR `#1 > `9}%
635 {%
636 \ifthenelse{ `#1 = `. \AND \NOT \value{COOL@strpointer} = 1 \AND \NOT \boolean{COOL@decimalfound} }%
637 {%
638 }%
639 % Else
640 {%
641 \setboolean{COOL@decimal}{false}%
642 }%
643 }%
644 % Else
645 {%
646 }%
647 }%
648 % Else
649 {%
650 \ifthenelse{ `#1 < `0 \OR `#1 > `9 }%
651 {%
652 % \end{macrocode}
653 % not at the end of a string, and have encountered a non-digit. If it is a number, then this non digit must be the first decimal point or it may be the first character and a $+$ or $-$ sign
654 % \begin{macrocode}
655 \ifthenelse{ `#1 = `. \AND \NOT \boolean{COOL@decimalfound} }%
656 {%
657 \setboolean{COOL@decimalfound}{true}%
658 }%
659 {\ifthenelse{ \(`#1 = `+ \OR `#1 = `-\) \AND \value{COOL@strpointer} = 1 }%
660 {%
661 }%
662 % Else
663 {%
664 \setboolean{COOL@decimal}{false}%
665 }}%
666 }%
667 % Else
668 {}%
669 \stepcounter{COOL@strpointer}%
670 \COOL@decimalgobbler#2\COOL@strEnd%
671 }}%
672 }
673 % \end{macrocode}
674 % \end{macro}
675 %
676 %
677 % \begin{macro}{\isdecimal}
678 % |isdecimal|\marg{string}\marg{boolean}
679 % \changes{v2.0}{2006/12/29}{added}
680 %
681 % \begin{macrocode}
682 \newcommand{\isdecimal}[2]{%
683 \setcounter{COOL@strpointer}{1}%
684 \setboolean{COOL@decimalfound}{false}%
685 \setboolean{COOL@decimal}{true}%
686 \expandafter\COOL@decimalgobbler#1\COOL@strStop\COOL@strEnd%
687 \ifthenelse{ \boolean{COOL@decimal} }%
688 {%
689 \setboolean{#2}{true}%
690 }%
691 % Else
692 {%
693 \setboolean{#2}{false}%
694 }%
695 }%
696 % \end{macrocode}
697 % \end{macro}
698 %
699 % \begin{macro}{\isnumeric}
700 % |\isnumeric|\marg{string}\marg{boolean} stores |true| in \meta{boolean} if \meta{string} is numeric
701 % \changes{v2.0}{2006/12/29}{added extra mandatory argument for storing return boolean}
702 %
703 % \begin{macrocode}
704 \newboolean{COOL@numeric}%
705 \def\COOL@eparser#1e#2\COOL@strEnd{%
706 \xdef\COOL@num@magnitude{#1}%
707 \xdef\COOL@num@exponent{#2}%
708 }
709 \def\COOL@ecorrector#1e\COOL@strStop{%
710 \xdef\COOL@num@exponent{#1}%
711 }
712 \def\COOL@Eparser#1E#2\COOL@strEnd{%
713 \xdef\COOL@num@magnitude{#1}%
714 \xdef\COOL@num@exponent{#2}%
715 }
716 \def\COOL@Ecorrector#1E\COOL@strStop{%
717 \xdef\COOL@num@exponent{#1}%
718 }
719 \newcommand{\isnumeric}[2]{%
720 \COOL@eparser#1e\COOL@strStop\COOL@strEnd%
721 \ifthenelse{ \equal{\COOL@num@exponent}{\COOL@strStop} }%
722 {%
723 \COOL@Eparser#1E\COOL@strStop\COOL@strEnd%
724 \ifthenelse{ \equal{\COOL@num@exponent}{\COOL@strStop} }%
725 {%
726 \gdef\COOL@num@exponent{0}%
727 }%
728 % Else
729 {%
730 \expandafter\COOL@Ecorrector\COOL@num@exponent%
731 }%
732 }
733 % Else
734 {%
735 \expandafter\COOL@ecorrector\COOL@num@exponent%
736 }%
737 \isdecimal{\COOL@num@magnitude}{COOL@numeric}%
738 \ifthenelse{ \boolean{COOL@numeric} }%
739 {%
740 \isdecimal{\COOL@num@exponent}{COOL@numeric}%
741 \ifthenelse{ \boolean{COOL@numeric} }%
742 {%
743 \setboolean{#2}{true}%
744 }%
745 % Else
746 {%
747 \setboolean{#2}{false}%
748 }%
749 }%
750 % Else
751 {%
752 \setboolean{#2}{false}%
753 }%
754 }
755 % \end{macrocode}
756 %
757 % \end{macro}
758 %
759 % In addition to identifying numeric data, it is useful to know if integers are present, thus another ``gobbler" is
760 % needed
761 %
762 % \begin{macrocode}
763 \newboolean{COOL@isint}
764 \def\COOL@intgobbler#1#2\COOL@strEnd{%
765 \ifcat#11%
766 \ifthenelse{\equal{#2}{\COOL@strStop}}%
767 {%
768 \ifthenelse{`#1 < `0 \OR `#1 > `9}%
769 {%
770 \setboolean{COOL@isint}{false}%
771 }%
772 % Else
773 {%
774 }%
775 }%
776 % Else
777 {%
778 \ifthenelse{ `#1 < `0 \OR `#1 > `9 }%
779 {%
780 \ifthenelse{ `#1 = `+ \OR `#1 = `- \AND \value{COOL@strpointer} = 1 }%
781 {}%
782 % Else
783 {%
784 \setboolean{COOL@isint}{false}%
785 }%
786 }%
787 % Else
788 {%
789 }%
790 \stepcounter{COOL@strpointer}%
791 \COOL@intgobbler#2\COOL@strEnd%
792 }%
793 \else%
794 \setboolean{COOL@isint}{false}%
795 \fi%
796 }
797 % \end{macrocode}
798 %
799 % \begin{macro}{\isint}
800 % \changes{v2.0}{2006/12/29}{added extra mandatory argument for storing return boolean}
801 % \changes{v2.0a}{2006/12/30}{modified internals slightly to work with \textsf{cool} package}
802 % \changes{v2.1b}{2007/10/10}{added expandafter before COOL@intgobbler to expand macros before evaluating}
803 % |\isint|\marg{string}\marg{boolean} sets the \meta{boolean} to |true| if \meta{string} is an integer or |false| otherwise
804 %
805 % \begin{macrocode}
806 \newcommand{\isint}[2]{%
807 \setcounter{COOL@strpointer}{1}%
808 \setboolean{COOL@isint}{true}%
809 \expandafter\COOL@intgobbler#1\COOL@strStop\COOL@strEnd%
810 \ifthenelse{ \boolean{COOL@isint} }%
811 {%
812 \setboolean{#2}{true}%
813 }%
814 % Else
815 {%
816 \setboolean{#2}{false}%
817 }%
818 }
819 % \end{macrocode}
820 %
821 % \end{macro}
822 %
823 % \end{landscape}
824 %
825 %
826 %
827 % \Finale
828 \endinput