| 1 |
% macro polyset |
| 2 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 |
% Petr Olsak Sep. 2003 |
| 4 |
|
| 5 |
% This macro expands sequences of type "ab{12}c{123}de" to sequences: |
| 6 |
% "ab1c1de" "ab1c2de" "ab1c3de" "ab2c1de" "ab2c2de" "ab2c3de". |
| 7 |
% |
| 8 |
% For more information see end of this file. |
| 9 |
|
| 10 |
\newtoks\leftpart \newtoks\rightpart \newtoks\restpart |
| 11 |
|
| 12 |
\def\applyset#1{\def\cumuseq{}\letleftseq #1{}\sep{}\sep} |
| 13 |
|
| 14 |
\def\letleftseq #1#{\def\tmp{#1}\letrest} |
| 15 |
\def\letrest #1#2\sep{\edef\oneset{#1} |
| 16 |
\ifx\oneset\empty |
| 17 |
\ifx\tmp\empty |
| 18 |
\ifx\cumuseq\empty \let\next=\relax % finish |
| 19 |
\else \let\next=\resetseq % next batch of sequences |
| 20 |
\fi |
| 21 |
\else \expandafter \runseq \expandafter |
| 22 |
{\tmp}\let\next=\letleftseq % next sequence |
| 23 |
\fi |
| 24 |
\else % expand sequence |
| 25 |
\leftpart=\expandafter{\tmp}\rightpart={#2} |
| 26 |
\def\tmp{#2}\ifx\tmp\empty \rightpart={{}}\fi |
| 27 |
\expandseq \let\next=\letleftseq |
| 28 |
\fi \next} |
| 29 |
\def\resetseq{\let\tmp=\cumuseq \def\cumuseq{} |
| 30 |
\expandafter \letleftseq \tmp {}\sep} |
| 31 |
\def\expandseq { |
| 32 |
\ifx\oneset\empty |
| 33 |
\else \expandafter \letelement \oneset \sep |
| 34 |
\restpart=\expandafter{\cumuseq} |
| 35 |
\edef \cumuseq{\the\restpart |
| 36 |
\the\leftpart \firstelement \the\rightpart |
| 37 |
\noexpand\sep } |
| 38 |
\expandafter \expandseq |
| 39 |
\fi} |
| 40 |
\def\letelement #1#2\sep{\def\firstelement{#1}\def\oneset{#2}} |
| 41 |
|
| 42 |
\def\runseq #1{\message{#1}} |
| 43 |
|
| 44 |
\endinput |
| 45 |
|
| 46 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 47 |
|
| 48 |
If you type, for example, \applyset{ab{12}c{123}de} then TeX runs |
| 49 |
\runseq{ab1c1de} \runseq{ab1c2de} \runseq{ab1c3de} |
| 50 |
\runseq{ab2c1de} \runseq{ab2c2de} \runseq{ab2c3de} |
| 51 |
|
| 52 |
Generally: If the argument of \applyset includes "sets" typed by |
| 53 |
{...}, then each set is replaced by its elements: successively all |
| 54 |
elements from each set is used. The \runseq macro is invoked to all |
| 55 |
resulting sequences. |
| 56 |
|
| 57 |
The body of each set {...} is expanded before getting the elements. |
| 58 |
On the other hand, the text surrounded of the sets is not expanded |
| 59 |
during \applyset is working. |
| 60 |
|
| 61 |
An example of an application of this macro follows. |
| 62 |
It gives the possibility of more powerfull \mubyte ... \endmubyte |
| 63 |
declarations for encTeX: |
| 64 |
|
| 65 |
------------------------------------------------------------------------ |
| 66 |
|
| 67 |
\input polyset |
| 68 |
|
| 69 |
\def\setmubyte #1#2{\def\runseq##1{\mubyte #1 ##1\endmubyte}\applyset{#2}} |
| 70 |
|
| 71 |
\def\ndigits {123456789} |
| 72 |
\def\digits {0\ndigits} |
| 73 |
|
| 74 |
\setmubyte {\dat ##0} {{\ndigits}.{\ndigits}.} %% needs encTeX v. Feb. 2003 |
| 75 |
\setmubyte {\dat ##0} {{12}{\digits}.{\ndigits}.} |
| 76 |
\setmubyte {\dat ##0} {3{01}.{\ndigits}.} |
| 77 |
\setmubyte {\dat ##0} {{\ndigits}.1{012}.} |
| 78 |
\setmubyte {\dat ##0} {{12}{\digits}.1{012}.} |
| 79 |
\setmubyte {\dat ##0} {3{01}.1{012}.} %% total: 372 \mubyte |
| 80 |
%% declarations |
| 81 |
\def\dat #1.#2.{#1.\kern.15em #2.} |
| 82 |
|
| 83 |
\mubytein=1 |
| 84 |
|
| 85 |
This example inserts the little space in (czech) date format automaticaly. |
| 86 |
Example 24.12. -> 24.\kern.15em 12. (means December 24). |
| 87 |
|
| 88 |
\end |