Debian Codegraph @

texmf-dist/source/latex/12many/12many.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2005 by Ulrich M. Schwarz
4 %
5 % This file may be distributed and/or modified under the conditions of
6 % the LaTeX Project Public License, either version 1.3a or, at your
7 % option, any later version. The latest version of this license is in
8 %
9 % http://www.latex-project.org/lppl.txt
10 %
11 % \fi
12 %
13 %\iffalse (hide this from DocInput)
14 %<*driver>
15 \documentclass{ltxdoc}
16 \usepackage{12many}
17 \GetFileInfo{12many.sty}
18 \usepackage[T1]{fontenc}
19 \EnableCrossrefs
20 \CodelineIndex
21 \RecordChanges
22 \begin{document}
23 \DocInput{12many.dtx}
24 \end{document}
25 %</driver>
26 %<*sty>
27 %\fi
28 %
29 % \CharacterTable
30 % {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
31 % 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
32 % Digits \0\1\2\3\4\5\6\7\8\9
33 % Exclamation \! Double quote \" Hash (number) \#
34 % Dollar \$ Percent \% Ampersand \&
35 % Acute accent \' Left paren \( Right paren \)
36 % Asterisk \* Plus \+ Comma \,
37 % Minus \- Point \. Solidus \/
38 % Colon \: Semicolon \; Less than \<
39 % Equals \= Greater than \> Question mark \?
40 % Commercial at \@ Left bracket \[ Backslash \\
41 % Right bracket \] Circumflex \^ Underscore \_
42 % Grave accent \` Left brace \{ Vertical bar \|
43 % Right brace \} Tilde \~}
44 % \CheckSum{160}
45 %
46 % \DoNotIndex{\@for,\addtocounter,\arabic,\csname,\endcsname,\cup,\CurrentOption}
47 % \DoNotIndex{\{,\},\do,\define@key,\def,\DeclareOption,\else,\ensuremath,\expandafter}
48 % \DoNotIndex{\hspace,\fi,\rule,\ifcase,\ifx,\in,\InputIfFileExists,\leq,\let,\mathpalette}
49 % \DoNotIndex{\NeedsTeXFormat,\ldots,\ldotp,\newcommand,\newcounter,\or}
50 % \DoNotIndex{\PackageInfo,\PackageWarning,\parm,\ProcessOptions,\protected@edef}
51 % \DoNotIndex{\providecommand,\ProvidesPackage,\relax,\renewcommand,\RequirePackage}
52 % \DoNotIndex{\setcounter,\setkeys,\rlap,\setminus,\widthof,\mathrm}
53 %
54 %\changes{0.3}{2005/05/09}{Changed to dtx/ins}
55 %
56 % \newcommand\pkg{\textsf}
57 % \newcommand\otm{\textsf{1, 2, many}}%
58 % \newcommand\otmstyle{\texttt}%
59 %
60 % \title{The \otm{} package\ignorespaces
61 % \thanks{This documents \otm{}~\fileversion\ of~\filedate}}
62 % \author{Ulrich M. Schwarz\thanks{\texttt{[email protected]}}}
63 %
64 % \maketitle
65 % \begin{abstract}
66 % In the discrete branches of mathematics and the computer sciences,
67 % it will only take some seconds until you're faced with a set like
68 % $\{1,\ldots,m\}$. Only some people write $1\ldotp\ldotp m$, or $\{j:1\leq
69 % j\leq m\}$, and that journal you're submitting to might want
70 % something else entirely. \otm{} provides an interface that makes
71 % changing from one to another a one-line change.
72 % \end{abstract}
73 %
74 % \tableofcontents
75 %
76 % \section{Command overview}\label{sec:command-overview}
77 %
78 % To use \otm{} in your \LaTeX{} document, place 12many.sty into your
79 % local texmf tree and load it by \verb|\usepackage{12many}|. Three
80 % in-document commands are provided:
81 % \DescribeMacro{\nto}
82 % \cs{nto}\marg{from}\marg{to} takes two arguments and typesets the
83 % range from the first to the second, ends inclusive: |\nto{3}{4}|
84 % might yield something like $\nto{3}{4}$.
85 %
86 % \DescribeMacro{\ito}
87 % \cs{ito} is an alias to |\nto{1}|, i.e. \verb|\ito{3}| is
88 % \verb|\nto{1}{3}| and yields $\ito3$.
89 %
90 % \DescribeMacro{\oto}
91 % \cs{oto} is an alias to |\nto{0}|, i.e. \verb|\ito{3}| is
92 % \verb|\nto{0}{3}| and yields $\oto3$.
93 % %
94 % \DescribeMacro{\setOTMstyle}
95 % To select the style, use \cs{setOTMstyle}\oarg{params}\marg{style},
96 % where style is a style name, and params are style-specific options in
97 % a key=val fashion. For a list of pre-defined styles and their options,
98 % see section~\ref{sec:pre-defined-styles}. It's as simple as that!
99 % If you don't need to change the default parameters of a style, you
100 % can also pass it as a package option: \verb|\usepackage[laue]{12many}|
101 %
102 %
103 % \section{Pre-defined styles}\label{sec:pre-defined-styles}
104 %
105 % The following styles are predefined by \otm:
106 %
107 % \subsection{Style \otmstyle{set}}
108 % \label{sec:style:set}\setOTMstyle{set}
109 % The ``proper'' way of specifying a range: $\nto{2}{233}$. Supported
110 % parameters:
111 % \begin{description}
112 % \item [var] The variable name to use. Default: the popular
113 % scratch integer $i$.
114 % \item [naturals] The way you write the set of natural numbers, $0$
115 % included. Defaults to the (rather ugly) |\mathrm{N}_0|
116 % $\mathrm{N}_0$, but depending on your style, you'll use blackboard,
117 % boldface or even fraktur here.
118 % \item [where] This goes between the naturals set symbol and the
119 % lower bound. I've seen both colons and bars used here, and you
120 % might want to do fancy extra spacing. The default is \verb.|.
121 % \end{description}
122 %
123 % \subsection{Style \otmstyle{dots}}
124 % \label{sec:style:dots}\setOTMstyle{dots}
125 % The somewhat less formal enumeration style: $\nto{2}{233}$. Supported
126 % parameters:
127 % \begin{description}
128 % \item [dots] What goes between the bounds. The default,
129 % |,\ldots,|, is the most formal one but takes up a lot of
130 % horizontal space, so you might use something like
131 % |,\ldotp\ldotp| here.
132 % \end{description}
133 %
134 % \subsection{Style \otmstyle{nude}}
135 % \label{sec:style:nude}\setOTMstyle{nude}
136 % An even less formal enumeration style, popular with economics and CS
137 % people, but certainly not mathematicians: $\nto{2}{233}$. Supported
138 % parameters:
139 % \begin{description}
140 % \item [dots] Works just like in the case of dots-style, but for
141 % nude, it defaults to |\ldotp\ldotp|.
142 % \end{description}
143 %
144 % \subsection{Style \otmstyle{laue}}
145 % \label{sec:style:laue}\setOTMstyle{laue}
146 % A style championed by a local maths professor: $\ito{233}$. (Note that
147 % this is the one-to variant. The other variants are derived from this:
148 % $\oto{233}$ and $\nto{2}{233}$. Also note that the outer parens are
149 % added by \otm\ to make sure the semantics do not change.) Supported parameters:
150 % \begin{description}
151 % \item [setminus] Used for the variants that do not start at $0$ or
152 % $1$. Defaults to |\setminus|.
153 % \item [setplus] Used to add in the $\{0\}$. Defaults to
154 % |\cup|.
155 % \item [ybelow] How far below the baseline the rule is. I don't think
156 % you'd need to change this---the default of $0.3$ ex looks good to me
157 % in Computer Modern, Palatino and Utopia/Fourier.
158 % \item [strokewidth] The width of the rule, with a default of $0.08$ ex.
159 % \item [innersidegap] The rule protudes beyond the number above it,
160 % by default by $0.05$ em.
161 % \item [outersidegap] There is an additional space after the hook, by
162 % default $0.05$ em.
163 % \end{description}
164 %
165 % \section{Creating new styles}\label{sec:creating-new-styles}
166 %
167 % If none of the styles above float your boat, you can still define your
168 % own. To this end, \otm{} provides three commands:
169 %
170 % \DescribeMacro{\newOTMstyle}
171 % \cs{newOTMstyle}\oarg{params}\marg{name}\marg{definition} takes three
172 % arguments: optional parameters, the style name and its definition. The
173 % definition has access to the bounds that are passed in the parameters
174 % |#1| (lower) and |#2| (upper). For example, the dots style is defined
175 % like this:
176 % \begin{verbatim}
177 % \newOTMstyle[dots={,\ldots,}]{dots}{%
178 % \{#1\getOTMparameter{dots}#2\}%
179 % }
180 % \end{verbatim}
181 % {\em
182 % Please be careful when declaring parameters with the optional
183 % arguments: spaces are not stripped. If you declare
184 % \verb*|foo=bar, baz=bam|, |\getOTMparameter{baz}| won't find anything.}
185 %
186 % \DescribeMacro{\renewOTMstyle} This macro is just the same as
187 % |\newOTMstyle|, only a newcommand in a crucial place is changed to a
188 % renewcommand, i.e. this can be used to change an existing style.
189 %
190 % \DescribeMacro{\newOTMparameter} This macro declares parameters and
191 % their defaults to a style. For example, we have already seen that the
192 % dots style accesses its dots with |\getOTMparameter{dots}|. This
193 % parameter was declared with
194 % \begin{verbatim}
195 % \newOTMparameter{dots}{dots}{,\ldots,}
196 % \end{verbatim}
197 % i.e., ``(style) \otmstyle{dots} has a parameter \texttt{dots} that
198 % defaults to $,\ldots,$''.
199 %
200 % \subsection{Configuration files}
201 % \otm{} will also look for your new style declarations in a file
202 % called \verb|12many.cfg|. This file is read in before the package
203 % parameter is evaluated, so it's legal to name a style that will only
204 % be defined in \verb|12many.cfg|.
205 % \StopEventually{\PrintChanges\PrintIndex}
206 % %
207 % %
208 % %
209 % %
210 % %
211 % %
212 % \section{Implementation}
213 % First of all, we identify ourselves, and require packages we need.
214 %
215 % \begin{macrocode}
216 \NeedsTeXFormat{LaTeX2e}
217 \ProvidesPackage{12many}[2005/05/09 v0.3 1, 2, many: numbersets (ums)]
218
219 \RequirePackage{calc, keyval}
220 % \end{macrocode}
221 %
222 % \subsection{Providing new styles and their parameters}
223 %
224 % First of all, we define the two commands for defining and changing
225 % styles. We do this with a two-level redirection because they really do
226 % the same thing, apart from the fact that one uses \cs{newcommand} and
227 % one uses \cs{renewcommand}.
228 %
229 % \begin{macro}{\newOTMstyle}
230 % \begin{macrocode}
231 \newcommand\newOTMstyle{%
232 \let\otm@@newcmd\newcommand
233 \otm@@fooOTMstyle
234 }
235 % \end{macrocode}
236 % \end{macro}
237 %
238 % \begin{macro}{\renewOTMstyle}
239 % \begin{macrocode}
240 \newcommand\renewOTMstyle{%
241 \let\otm@@newcmd\renewcommand
242 \otm@@fooOTMstyle
243 }
244 % \end{macrocode}
245 % \end{macro}
246 %
247 % \begin{macro}{\otm@@fooOTMstyle}
248 % This macro does the real work. Note that we designate internal
249 % macros with |\otm@@|, since we store style info below |\otm@|. If
250 % the user gives parameter definitions, we pass each to
251 % \cs{otm@@newkvOTMparameter}. Finally, we assemble the name of the
252 % style macro and call \cs{(re)newcommand*}. Note that we still have a
253 % parameter left from the call to \cs{newOTMstyle}, and that is the
254 % definition.
255 % \begin{macrocode}
256 \newcommand*\otm@@fooOTMstyle[2][\relax]{%
257 \ifx #1\relax\else
258 \@for\parm:=#1\do{%
259 \expandafter\otm@@newkvOTMparameter\parm={#2}%
260 }%
261 \fi
262 \expandafter\otm@@newcmd\expandafter*\csname otm@style@#2\endcsname[2]%
263 }
264 % \end{macrocode}
265 % \end{macro}
266 %
267 % Next, we disassemble a new user parameter definition. To be rechecked:
268 % I'm sure \textsf{keyval} can do all of that.
269 %
270 % \begin{macro}{otm@@newkvOTMparameter}
271 % \begin{macrocode}
272 \def\otm@@newkvOTMparameter#1=#2=#3{%
273 \newOTMparameter{#3}{#1}{#2}%
274 }
275 % \end{macrocode}
276 %\end{macro}
277 % \begin{macro}{newOTMparameter}
278 % This is either called directly by the user, or we have massaged the
279 % optional argument of \cs{newOTMstyle} sufficiently by now, so that
280 % we can just tell \textsf{keyval} about the new parameter.
281 % \begin{macrocode}
282 \newcommand\newOTMparameter[3]{%
283 \expandafter\providecommand\csname otm@#1@#2\endcsname{#3}%
284 \define@key{otm@#1}{#2}{\expandafter\renewcommand\csname otm@#1@#2\endcsname{##1}}%
285 }
286 % \end{macrocode}
287 %\end{macro}
288 %
289 % \begin{macro}{setOTMparameter}
290 % This is just a simple setter. We use \cs{renewcommand} since all
291 % params are already setup at declaration time. The third parameter is
292 % picked up by partial application.
293 % \begin{macrocode}
294 \newcommand\setOTMparameter[2]{%
295 \expandafter\renewcommand\csname otm@#1@#2\endcsname%
296 }
297 % \end{macrocode}
298 %\end{macro}
299 %
300 % \begin{macro}{getOTMparameter}
301 % Just hiding the internal macro name. Note that we are slightly
302 % asymmetric, since here the style parameter is optional. The reason
303 % for this is that this is usually called from within a \cs{nto},
304 % where the style is clear from context. Still, giving a style name
305 % here allows for very rudimentary inheritance.
306 % \begin{macrocode}
307 \newcommand\getOTMparameter[2][\otm@@currentstyle]{%
308 \csname otm@#1@#2\endcsname%
309 }
310 % \end{macrocode}
311 %\end{macro}
312 %
313 % \begin{macro}{setOTMstyle}
314 % With all the preliminaries defined, setting the style is easy: we
315 % remember the style name for \cs{getOTMparameter} purposes,
316 % let \textsf{keyval} set the parameters, and \cs{let} \cs{nto} to the
317 % appropriate macro.
318 % \begin{macrocode}
319 \newcommand*\setOTMstyle[2][]{%
320 \protected@edef\otm@@currentstyle{#2}%
321 \PackageInfo{12many}{Using style \otm@@currentstyle[#1]}%
322 \setkeys{otm@\otm@@currentstyle}{#1}%
323 \expandafter\let\expandafter\nto\csname otm@style@\otm@@currentstyle\endcsname%
324 }
325 % \end{macrocode}
326 %\end{macro}
327 %
328 % \begin{macro}{nto}
329 % This is just a preliminary fallback definition---\cs{nto} is set to
330 % something better by \cs{setOTMstyle}. We log a warning and go to a
331 % vaguely sane default. The re-defined \cs{nto} will then pick up the
332 % parameters.
333 % \begin{macrocode}
334 \newcommand\nto{%
335 \PackageWarning{12many}{No style selected. Using dots.}%
336 \setOTMstyle{dots}%
337 \nto%
338 }
339 % \end{macrocode}
340 %\end{macro}
341 %
342 % Ironically, the two most-used macros of this package are also the shortest.
343 %\begin{macro}{oto}
344 % \begin{macrocode}
345 \newcommand\oto{\nto{0}}
346 % \end{macrocode}
347 %\end{macro}
348 %\begin{macro}{ito}
349 % \begin{macrocode}
350 \newcommand\ito{\nto{1}}
351 % \end{macrocode}
352 %\end{macro}
353 %
354
355
356 %\subsection{Predefined styles}
357 %
358 %\subsubsection{\otmstyle{set}}
359 %
360 %This is a very simple style, but it demonstrates the power of the
361 %keyval system.
362 % \begin{macrocode}
363 %% Style "`set"': the "`proper way"': {i\in N: x<=i<=y}
364 \newOTMstyle[var=i,naturals={\mathrm{N}_0},where=|]{set}{%
365 \{\getOTMparameter{var}\in\getOTMparameter{naturals}%
366 \getOTMparameter{where} #1\leq\getOTMparameter{var}\leq#2\}%
367 }
368 % \end{macrocode}
369 %
370 %\subsubsection{\otmstyle{laue}}
371 %
372 %This is a bit more involved and involves manual drawing of rules, to
373 %yield something that looks a little like \cs{rharpoon}.
374 % \begin{macrocode}
375 %% Style "`laue"': 1 to n is n with some sort of rharpoon below.
376 \newcounter{otm@scratch}
377
378 \newOTMstyle{laue}{%
379 % \end{macrocode}
380 % Since we can only give one definition, that for \cs{nto}, we need to
381 % distinguish cases here since \otmstyle{laue} defines itself via the
382 % one-to case. Note that the third case need not handle the case that
383 % the range starts at $0$ or $1$, hence we don't subtract one-element
384 % sets. Note also that this doesn't cater for |\oto{0}|, but that really
385 % should be obvious at the writer-level.
386 % \begin{macrocode}
387 \ifcase#1\relax
388 (\{0\}\otm@laue@setplus\otm@@laue@laue{#2})%
389 \or
390 \otm@@laue@laue{#2}%
391 \else
392 \setcounter{otm@scratch}{#1}%
393 \addtocounter{otm@scratch}{-1}%
394 (\otm@@laue@laue{#2}%
395 \otm@laue@setminus\otm@@laue@laue{\arabic{otm@scratch}})%
396 \fi
397 }
398 % \end{macrocode}
399 %This style is actually older than the pacakge itself, so there are
400 %lots of things to customize.
401 % \begin{macrocode}
402 \newOTMparameter{laue}{setminus}{\setminus}
403 \newOTMparameter{laue}{setplus}{\cup}
404 \newOTMparameter{laue}{ybelow}{0.3ex}
405 \newOTMparameter{laue}{strokewidth}{0.08ex}
406 \newOTMparameter{laue}{innersidegap}{0.05em}
407 \newOTMparameter{laue}{outersidegap}{0.05em}
408 % \end{macrocode}
409 % Finally, the drawing proper. It took me a while to figure out how
410 % \cs{mathpalette} is supposed to be used. Otherwise, nothing
411 % interesting happens. Theoretically, possibly the argument could end up
412 % on one line and the rule on the next, if we are very close to the end
413 % of the line, but I've never seen that happen.
414 % \begin{macrocode}
415 \newcommand{\otm@@laue@laue}[1]{%
416 \mathpalette{\let\laue@mathstyle}{\ensuremath{%
417 \rlap{\hspace*{\otm@laue@innersidegap}$\laue@mathstyle #1$}%
418 \rule[-\otm@laue@ybelow]%
419 {\widthof{\ensuremath{\laue@mathstyle #1}}+\otm@laue@innersidegap *2}%
420 {\otm@laue@strokewidth}%
421 \rule[-\otm@laue@ybelow]%
422 {\otm@laue@strokewidth}%
423 {\otm@laue@ybelow *2}}}}
424 % \end{macrocode}
425 %
426 %\subsubsection{\otmstyle{dots}}
427 %Trivial.
428 % \begin{macrocode}
429 %% Style "`dots"': variations of the {1,...,n} theme.
430
431 \newOTMstyle[dots={,\ldots,}]{dots}{%
432 \{#1\getOTMparameter{dots}#2\}%
433 }
434 % \end{macrocode}
435 %
436 %\subsubsection{\otmstyle{nude}}
437 %Also trivial.
438 % \begin{macrocode}
439 %% Style "`nude"': variations of the 1..n theme.
440
441 \newOTMstyle[dots={\ldotp\ldotp}]{nude}{%
442 #1\getOTMparameter{dots}#2%
443 }
444 % \end{macrocode}
445 %
446 %\subsection{Customization and package parameter}
447 %
448 %Nothing interesting happens here.
449 % \begin{macrocode}
450 %%
451 %% PART III: Use existing customization file
452 %%
453 \InputIfFileExists{12many.cfg}{%
454 \PackageInfo{12many}{Also using customization file 12many.cfg}
455 }{%
456 \PackageInfo{12many}{No customization file used}
457 }
458
459 %%
460 %% PART IV: Use package parameter
461 %%
462 \DeclareOption*{\setOTMstyle{\CurrentOption}}
463 \ProcessOptions\relax
464 % \end{macrocode}
465 %
466 %\Finale
467 % \iffalse
468 % </!sty>
469 % X Local Variables:
470 % X mode: latex
471 % X End:
472 % \fi