| 1 |
\ifx\STYLEDEF\relax\endinput\else\let\STYLEDEF=\relax\fi % \input only once |
| 2 |
% |
| 3 |
% styledef.tex: Macros to selectively input parts of a file. |
| 4 |
% version: 1.0 release: 16 April 1991 |
| 5 |
% |
| 6 |
% copyright (c) 1991 Marcel R. van der Goot |
| 7 |
% You can use these macros to typeset documents. You may |
| 8 |
% distribute this file freely, provided that you also distribute |
| 9 |
% the accompanying documentation. |
| 10 |
% You may make changes to this file, or extract portions |
| 11 |
% of it for inclusion in other files, provided that |
| 12 |
% (1) you change the name of the file; |
| 13 |
% (2) you give proper credit and include copyright |
| 14 |
% information where applicable; |
| 15 |
% (3) explain how an unchanged version can be obtained; and |
| 16 |
% (4) document the usage of your macros/changes (if usage |
| 17 |
% of your macros is not worth documenting, they must not |
| 18 |
% be worth using). |
| 19 |
% You are not allowed to use the name ``Midnight Macros'' for |
| 20 |
% any changed files. |
| 21 |
% The above rules for making changes do not apply where it |
| 22 |
% is explicitly noted in this file that something can be changed |
| 23 |
% to conform to your local installation. |
| 24 |
% |
| 25 |
% USAGE: |
| 26 |
% See the file styledef.doc. |
| 27 |
% You need Midnight/dolines.tex and Midnight/loop.tex to use these macros. |
| 28 |
% |
| 29 |
% original: csvax.cs.caltech.edu [131.215.131.131] in pub/tex |
| 30 |
% (use anonymous ftp). Also in various archives. |
| 31 |
% |
| 32 |
% Caltech, Pasadena --- Marcel van der Goot |
| 33 |
% [email protected] |
| 34 |
% Caltech 256--80 |
| 35 |
% Pasadena, CA 91125 |
| 36 |
% USA |
| 37 |
% (818) 356--4603 |
| 38 |
% |
| 39 |
|
| 40 |
% update history: |
| 41 |
% version 1.0: This one. |
| 42 |
% release 16 April 1991: the original (this one) |
| 43 |
% |
| 44 |
|
| 45 |
%%%%%% CODE: (you don't need to read this to use the macros) |
| 46 |
|
| 47 |
\edef\next{\the\catcode`\_} % to remember that catcode |
| 48 |
\catcode`\_=11 % 11=letter (for private macros) |
| 49 |
|
| 50 |
%%%%%%%%%%%%%%%%%%%% the current style list |
| 51 |
% A style list is represented by a token register. The register is either |
| 52 |
% empty or contains a sequence of words separated by single commas (no spaces). |
| 53 |
% A non-empty list starts with a comma. A list denotation is a list of words |
| 54 |
% separated by commas and spaces. |
| 55 |
% \setstyle#1#2. makes style list reg #1 equal to #2 (a list denotation), |
| 56 |
% \addstyle#1#2. adds the list #2 to the list register #1. |
| 57 |
|
| 58 |
\let\newstyle=\newtoks |
| 59 |
|
| 60 |
\def\setstyle#1#2% #1 a token reg, #2 a list denotation |
| 61 |
{#1={}% |
| 62 |
\make_stylelist#1#2 .% space before the dot |
| 63 |
} |
| 64 |
|
| 65 |
\def\addstyle#1#2% #1 a token reg, #2 a list denotation |
| 66 |
{\make_stylelist#1#2 .% space before the dot |
| 67 |
} |
| 68 |
|
| 69 |
%%%%%%%%%%%%%%%%%%%% reading a style list denotation |
| 70 |
% \make_stylelist takes as first argument the name of a token register. |
| 71 |
% Following that name there should be a list of words separated by spaces |
| 72 |
% and/or commas, terminated by ` .' (a space and a dot). It constructs |
| 73 |
% the corresponding style list in #1. |
| 74 |
% \make_stylelist takes the sequence up till the first space, calls |
| 75 |
% \nocomma_stylelist with that sequence, and recurses with the sequence after |
| 76 |
% the first space. \nocomma_stylelist works similarly, but strips a comma |
| 77 |
% rather than a space. (Note: separation by single commas without spaces |
| 78 |
% is slightly more efficient.) |
| 79 |
|
| 80 |
\def\eat_style#1.{} % skip everything till first dot |
| 81 |
|
| 82 |
\def\make_stylelist#1#2 #3.% #1=name of list; #2#3=list ending in ` .' |
| 83 |
{\if.#2.\else\nocomma_stylelist#1#2,.\fi |
| 84 |
\if.#3.\let\style_tmp=\eat_style |
| 85 |
\else\let\style_tmp=\make_stylelist |
| 86 |
\fi |
| 87 |
\style_tmp#1#3.% |
| 88 |
} |
| 89 |
|
| 90 |
\def\nocomma_stylelist#1#2,#3.% #1=name of list; #2#3=list ending in `,.' |
| 91 |
{\if.#2.\else#1=\expandafter{\the#1,#2}\fi |
| 92 |
\if.#3.\let\style_tmp=\eat_style |
| 93 |
\else\let\style_tmp=\nocomma_stylelist |
| 94 |
\fi |
| 95 |
\style_tmp#1#3.% |
| 96 |
} |
| 97 |
|
| 98 |
%%%%%%%%%%%%%%%%%%%% determining whether lists intersect |
| 99 |
% \isect_style is used to check whether two lists have a non-empty |
| 100 |
% intersection. The switch \if_style will be set to indicate whether |
| 101 |
% the lists intersect. |
| 102 |
% \style_member takes two arguments, a style list register and a word. |
| 103 |
% It sets the switch if the word is in the style list. This check is done |
| 104 |
% by TeX's pattern match mechanism rather than through word-by-word comparison: |
| 105 |
% To check for the presence of word `xyz' a macro `\style_tmp#1,xyz,#2.' is |
| 106 |
% defined. If it is called as `\style_tmp<list>,xyz,.' where <list> is the |
| 107 |
% contents of the style list, then #2 will not be empty if and only if the |
| 108 |
% pattern `,xyz,' is part of <list>, i.e., iff `xyz' is in the list. |
| 109 |
% \doisect_style calls \style_member repeatedly for each word in the second |
| 110 |
% list. |
| 111 |
|
| 112 |
\newif\if_style |
| 113 |
|
| 114 |
\def\style_member#1#2% #1 a style list (token reg), #2 a word |
| 115 |
{\def\style_tmp##1,#2,##2.{\check_style{##2}}% |
| 116 |
\expandafter\style_tmp\the#1,#2,.% |
| 117 |
} |
| 118 |
|
| 119 |
\def\check_style#1% check whether #1 is empty |
| 120 |
{\if.#1.\else\_styletrue\fi |
| 121 |
} |
| 122 |
|
| 123 |
\def\doisect_style#1,#2,#3.% #1=reg, #2#3=expansion of list reg ending in ,. |
| 124 |
{\if.#2.\else\style_member#1{#2}\fi |
| 125 |
\if_style\let\style_tmp=\eat_style |
| 126 |
\else\if.#3.\let\style_tmp=\eat_style |
| 127 |
\else\let\style_tmp=\doisect_style |
| 128 |
\fi \fi |
| 129 |
\style_tmp#1,#3.% |
| 130 |
} |
| 131 |
|
| 132 |
\def\isect_style#1#2% two list regs |
| 133 |
{\_stylefalse |
| 134 |
\expandafter\doisect_style\expandafter#1\the#2,,.% extra comma for #2={} |
| 135 |
} |
| 136 |
|
| 137 |
%%%%%%%%%%%%%%%%%%%% including a style |
| 138 |
% \readstyle takes a style list register and a filename. It puts the style list |
| 139 |
% in \style_list, then inputs the file. |
| 140 |
% \skip_style skips everything till the next \endstyle. It uses |
| 141 |
% dolines.tex to read the input line-by-line. To make that possible, |
| 142 |
% the grouping characters are disabled (because they must balance on a line), |
| 143 |
% the comment char is disabled (because it causes wraparound), the argument |
| 144 |
% character is disabled (because a macro is defined that has the line as |
| 145 |
% body --- it should not have undeclared arguments in the body), and the |
| 146 |
% escape character is disabled (not to prevent expansion, but to prevent lines |
| 147 |
% containing an `outer' control sequence). Note: If you wanted a real |
| 148 |
% ``comment environment,'' you should set all catcodes of all characters to |
| 149 |
% 11 or 12. |
| 150 |
% \styledef and \negstyledef have list denotations as arguments. They create |
| 151 |
% a list \style_other, then skip based on the intersection of \style_other |
| 152 |
% and \style_list. If no skip is done, \endstyle is equivalent to \relax. |
| 153 |
% \savereadstyle and \setreadstyle serve to access the protected \style_list |
| 154 |
% register. |
| 155 |
|
| 156 |
\input Midnight/dolines |
| 157 |
|
| 158 |
\newtoks\style_list |
| 159 |
\newtoks\style_other |
| 160 |
|
| 161 |
\def\readstyle#1#2% #1 a token reg, #2 a filename |
| 162 |
{\style_list=#1% |
| 163 |
\input#2 % significant space (sometimes) |
| 164 |
} |
| 165 |
|
| 166 |
\def\savereadstyle#1% a style (token) reg |
| 167 |
{#1=\style_list} |
| 168 |
|
| 169 |
\def\setreadstyle#1% a style reg |
| 170 |
{\style_list=#1} |
| 171 |
|
| 172 |
{\catcode`\/=0 /catcode`/\=12 % see dolines.doc |
| 173 |
/gdef/end_style{\endstyle} |
| 174 |
} |
| 175 |
|
| 176 |
\let\endstyle=\relax |
| 177 |
|
| 178 |
\def\skip_style |
| 179 |
{\begingroup |
| 180 |
\let\beforelines=\relax |
| 181 |
\let\afterlines=\relax |
| 182 |
\def\everyline##1{}% |
| 183 |
\let\enddolines=\end_style |
| 184 |
\let\finishdolines=\endgroup |
| 185 |
\catcode`\{=12 \catcode`\}=12 \catcode`\%=12 |
| 186 |
\catcode`\#=12 \catcode`\\=12 |
| 187 |
\begindolines |
| 188 |
} |
| 189 |
|
| 190 |
\def\styledef#1% #1 a list denotation |
| 191 |
{\style_other={}% |
| 192 |
\make_stylelist\style_other#1 .% space before dot |
| 193 |
\isect_style\style_list\style_other |
| 194 |
\if_style |
| 195 |
\else\expandafter\skip_style |
| 196 |
\fi |
| 197 |
} |
| 198 |
|
| 199 |
\def\negstyledef#1% #1 a list denotation |
| 200 |
{\style_other={}% |
| 201 |
\make_stylelist\style_other#1 .% space before dot |
| 202 |
\isect_style\style_list\style_other |
| 203 |
\if_style\expandafter\skip_style\fi |
| 204 |
} |
| 205 |
|
| 206 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 207 |
|
| 208 |
\catcode`\_=\next |