| 1 |
% styledef.doc --- version 1.0 (16 April 1991) |
| 2 |
% This is the documentation for styledef.tex. |
| 3 |
% To read this file, process it with (plain) TeX: tex styledef.doc |
| 4 |
% (To do that, you need manmac.tex, which has |
| 5 |
% the macros for typesetting the TeXbook, as explained in appendix E. |
| 6 |
% It comes free with the standard distribution of TeX.) |
| 7 |
% |
| 8 |
% NOTE: Processing this file with TeX will create empty files |
| 9 |
% index.tex and answers.tex in your directory. And if you |
| 10 |
% have a file pages.tex in your directory, TeX will probably |
| 11 |
% get very confused. |
| 12 |
% The manmac format will try to load a font called cmman; if |
| 13 |
% TeX complains that it cannot find that font you can savely |
| 14 |
% ignore that, since the font is not actually used. |
| 15 |
% |
| 16 |
% This file: copyright (c) 1991 Marcel van der Goot. |
| 17 |
% You may redistribute this file and printed versions of it. |
| 18 |
% |
| 19 |
% original: csvax.cs.caltech.edu [131.215.131.131] in pub/tex |
| 20 |
% (use anonymous ftp). Also in various archives. |
| 21 |
% |
| 22 |
% Marcel van der Goot |
| 23 |
% [email protected] |
| 24 |
% Caltech 256--80 |
| 25 |
% Pasadena, CA 91125 |
| 26 |
% (818) 356--4603 |
| 27 |
|
| 28 |
% ------ definitions for manual pages: |
| 29 |
% The documentation is typeset using Knuth's ``manmac'' macros, with a |
| 30 |
% few additional things defined here. You are free to use or adapt these |
| 31 |
% extra definitions. |
| 32 |
|
| 33 |
\input manmac % the macros used for typesetting The TeXbook (appendix E) |
| 34 |
\catcode`^=7 % manmac makes ^ active for creating an index |
| 35 |
% we don't make an index, and we need ^ to be non-active |
| 36 |
|
| 37 |
{\catcode`\^^M=12 \endlinechar=-1 % 12 = other |
| 38 |
\long\gdef\manpagehead#1^^M#2^^M#3^^M^^M% tex-file, description, version |
| 39 |
{\egroup % matches \bgroup in \manpage |
| 40 |
\par\vfill\eject |
| 41 |
\edef\rhead{\manualname: #1\unskip}% |
| 42 |
\setbox1=\hbox{\titlefont #1\quad}% |
| 43 |
\setbox3=\vtop{\advance\hsize by-\wd1 \parindent=0pt \raggedright |
| 44 |
#2\par |
| 45 |
#3\par |
| 46 |
\cnotice |
| 47 |
}% |
| 48 |
\line{\box1\box3}% |
| 49 |
\bigskip\bigskip\bigskip\noindent |
| 50 |
}% |
| 51 |
} % restore \catcode`\^^M |
| 52 |
|
| 53 |
\outer\def\manpage |
| 54 |
{\bgroup\catcode`\^^M=12 |
| 55 |
\manpagehead |
| 56 |
} |
| 57 |
|
| 58 |
\hsize=6.5in\vsize=8.9in % default plain TeX values |
| 59 |
\pagewidth=\hsize \pageheight=\vsize |
| 60 |
|
| 61 |
\def\cnotice{Copyright \copyright\ 1991 Marcel R. van der Goot} |
| 62 |
\def\manualname{Midnight Macros} |
| 63 |
|
| 64 |
% LaTeX logo, from latex.tex (except for the capital `A': manmac |
| 65 |
% doesn't have a real smallcaps font) |
| 66 |
\def\LaTeX{{\rm L\kern-.36em\raise.3ex\hbox{\sc A}\kern-.15em |
| 67 |
T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}} |
| 68 |
|
| 69 |
\tenpoint |
| 70 |
|
| 71 |
% (end of extra definitions) |
| 72 |
|
| 73 |
% -------------------- styledef.doc: |
| 74 |
|
| 75 |
\pageno=14 % follows labels.doc |
| 76 |
|
| 77 |
\manpage styledef.tex |
| 78 |
styledef.tex: Macros to selectively input parts of a file. |
| 79 |
Version: 1.0 (16 April 1991) (doc: 19 Sep 1991) |
| 80 |
|
| 81 |
Consider the following situation: You write a set of \TeX\ macros |
| 82 |
to typeset letters. These macros must set fonts, margins, offsets, etc. |
| 83 |
However, you want to use different styles for different types of letters. |
| 84 |
For instance, a short letter may need extra white space at the top to |
| 85 |
get a full page, whereas this is not needed for a letter several pages |
| 86 |
long. And a business letter has a standard header, with subject and |
| 87 |
references, whereas a small note to a friend only has a date. Probably |
| 88 |
the macros for the different styles have a lot in common, a reason to put |
| 89 |
them all in one file. But the different styles may have some conflicting |
| 90 |
definitions, of which you only want to include one. |
| 91 |
Styledef.tex\footnote*{You also need Midnight/dolines.tex and |
| 92 |
Midnight/loop.tex, which will be |\input| automatically.} |
| 93 |
provides |
| 94 |
some macros to |\input| from a file only parts belonging to a particular |
| 95 |
``style.'' (Partial inclusion can also be useful for other things than |
| 96 |
styles; see the end of this manual section for an example.) |
| 97 |
|
| 98 |
Before we explain the macros from styledef.tex, let us look at two other |
| 99 |
solutions. First, say the only difference between styles ``wide'' and |
| 100 |
``narrow'' is the width of the text. Then we can write macros |\widestyle| |
| 101 |
and |\narrowstyle| that set the appropriate width. As long as the differences |
| 102 |
between styles are small and easily parametrized, this method works fine. |
| 103 |
If there are many differences, however, the macros for setting the style |
| 104 |
soon get very large. Furthermore, it is hard too share parts of styles. |
| 105 |
|
| 106 |
A second method is the one used by \LaTeX. One makes one file ``letter.sty'' |
| 107 |
with all the common definitions for letters; an additional file is made |
| 108 |
for each style. \LaTeX's |\documentstyle| macro is then used to include |
| 109 |
the proper files. E.g., one could write |
| 110 |
\begintt |
| 111 |
\documentstyle[business,narrow]{letter} |
| 112 |
\endtt |
| 113 |
to write a letter with the ``business'' and ``narrow'' style options. |
| 114 |
This method allows sharing of common definitions, and also allows the |
| 115 |
combination of different style options. The disadvantage is that it soon |
| 116 |
leads to a very large number of files, many of them with only a few |
| 117 |
definitions. |
| 118 |
|
| 119 |
With the macros in styledef.tex, you would use only one or two files. |
| 120 |
Typical would be to have one file, ``letter.tex,'' with all the common |
| 121 |
definitions for letters, and one file, ``letter.style,'' with all the |
| 122 |
different styles. Only some parts of the latter file are included, |
| 123 |
through the macros below. Alternatively, everything can be put in a single |
| 124 |
file. (Using two files has the advantage that ``letter.tex'' can be shared |
| 125 |
by several users, who each have there own personalized ``letter.style.'') |
| 126 |
Styledef.tex is of course especially useful with plain \TeX, since that does |
| 127 |
not have an equivalent mechanism. However, the macros can also be used |
| 128 |
with \LaTeX; later on we describe how to |
| 129 |
make the |\documentstyle| command interact with the styledef macros. |
| 130 |
|
| 131 |
First we describe how to |\input| only parts of a file. In order to use |
| 132 |
any of these macros, you first have to |\input styledef|. Then you have to |
| 133 |
allocate one or more ``style registers'': a style register called |
| 134 |
``|\myst|'' is allocated with the command |
| 135 |
\begintt |
| 136 |
\newstyle\myst |
| 137 |
\endtt |
| 138 |
|
| 139 |
You can give a new value to a style register through the |\setstyle| command. |
| 140 |
It takes a style register and a list of styles as arguments. E.g., |
| 141 |
\begintt |
| 142 |
\setstyle\myst{business, narrow} |
| 143 |
\endtt |
| 144 |
For this command, as for all others, a style list is a list of style names |
| 145 |
separated by spaces and/or commas; the whole list must be enclosed in braces. |
| 146 |
The style names |
| 147 |
themselves can be any names that are meaningful to the macro package you are |
| 148 |
using. The |\addstyle| command is used in the same way as |\setstyle|, but |
| 149 |
it adds one or more styles to the style register without removing the old |
| 150 |
contents. You can use |\the\myst| to get the contents of the style register, |
| 151 |
and style registers can be assigned to each other using `|=|'. |
| 152 |
The last operation involving style registers is |\readstyle|. It takes |
| 153 |
a style register and a file name: The command |
| 154 |
\begintt |
| 155 |
\readstyle\myst{letter.style} |
| 156 |
\endtt |
| 157 |
will |\input| file letter.style, but includes only those parts of it that |
| 158 |
belong to one of the styles in register |\myst|. That is all that is needed |
| 159 |
to selectively |\input| a file. The other macros from styledef.tex and the |
| 160 |
remainder of this manual section describe how to indicate in a file like |
| 161 |
letter.style which parts belong to which styles. If you don't intend to |
| 162 |
create such files yourself, there is no need to read on. |
| 163 |
|
| 164 |
There are only three commands that govern which parts of a file belong |
| 165 |
to a particular style: |\styledef|, |\negstyledef|, and |\endstyle|. |
| 166 |
The first two are followed by a brace-enclosed list of styles (but not |
| 167 |
by a style register). When a file is read with |\readstyle|, the file |
| 168 |
is just |\input| by \TeX. However, when in that file a command |
| 169 |
\begintt |
| 170 |
\styledef{business, long} |
| 171 |
\endtt |
| 172 |
is encountered, \TeX\ checks whether the style register that is used |
| 173 |
with |\readstyle| contains style ``business'' or style ``long.'' If at |
| 174 |
least one of them is contained in the register, \TeX\ continues to input |
| 175 |
the file. But if none of the styles match, \TeX\ skips lines of the file until |
| 176 |
an |\endstyle| command is encountered. |\negstyledef| has exactly the |
| 177 |
opposite effect: if any style matches, the file is skipped till the next |
| 178 |
|\endstyle| command; only if no style matches is this part of the file |
| 179 |
included. The |\endstyle| command must occur on a line by itself, with nothing, |
| 180 |
not even a comment, following it. The |\endstyle| command stops \TeX\ from |
| 181 |
skipping text; if it is encountered when \TeX\ is not skipping text, it |
| 182 |
is equivalent to |\relax|. |
| 183 |
|
| 184 |
Text that is not enclosed by a |\styledef| \dots |\endstyle| (or |\negstyledef| |
| 185 |
equivalent) is always included. |\styledef| commands can be used within |
| 186 |
each other's range, but they do not actually nest: when part of the text is |
| 187 |
skipped, skipping always stops at the first |\endstyle|; any intervening |
| 188 |
|\styledef| commands are also skipped. E.g., |
| 189 |
\begintt |
| 190 |
\styledef{business} |
| 191 |
\negstyledef{narrow} |
| 192 |
... |
| 193 |
\endstyle |
| 194 |
\endtt |
| 195 |
The text corresponding to `|...|' (which does not include any |\endstyle|) |
| 196 |
is only included if the style register contains style ``business'' and does |
| 197 |
not contain ``narrow.'' If style ``business'' is not contained in the |
| 198 |
register, the |\negstyledef| command as well as the `|...|' are skipped. |
| 199 |
As a catch-all you may want to put an |\endstyle| at the end of the included |
| 200 |
file: if you missed an |\endstyle| somewhere, this catch-all will at |
| 201 |
least restrict the effects to this file. |
| 202 |
|
| 203 |
\danger The |\readstyle| command uses an internal style register to store |
| 204 |
which styles must be included. Therefore, if a file which is being read with |
| 205 |
|\readstyle|, uses |\readstyle| to read yet another file, the original list |
| 206 |
of styles will be lost. Although this situation seldomly occurs, there |
| 207 |
is a command |\savereadstyle| which takes a style register as argument and |
| 208 |
saves the internal style list in this register. Of course, if the second |
| 209 |
file should be read with exactly the same style list, you should just use |
| 210 |
|\input| instead of |\readstyle|. To restore the original style list, you |
| 211 |
use |\setreadstyle|, which also takes a style register as argument. |
| 212 |
|\setreadstyle| can also be used instead of |\readstyle|, if you want to |
| 213 |
select certain parts of the current file rather than |\input| a different |
| 214 |
file. |
| 215 |
|
| 216 |
\danger Style names can be built from any characters, except for spaces, |
| 217 |
commas, dots, and some characters with a special meaning to \TeX\ (e.g., |
| 218 |
braces, hash signs (|#|), and percentage signs). |
| 219 |
Also, characters in a style name must have the same catcode in the |
| 220 |
|\styledef| command as in the |\setstyle| command. |
| 221 |
When a |\styledef| or |
| 222 |
|\negstyledef| command is encountered, the following conditions must hold: |
| 223 |
The only escape character (catcode 0) is `|\|'; the only grouping characters |
| 224 |
(catcodes 1 and 2) are `|{|' and `|}|'; the only parameter character (catcode |
| 225 |
6) is `|#|'; and the only comment character (catcode 14) is `|%|'. After the |
| 226 |
|\styledef| command these catcodes may be changed, as long as the conditions |
| 227 |
hold again when the next |\styledef| is encountered. These particular |
| 228 |
catcode assignments are so standard that this rule is unlikely to ever cause |
| 229 |
problems. |
| 230 |
|
| 231 |
Suppose you have written a file letter.tex, which is to be used by several |
| 232 |
people. You also have a file letter.style with some standard styles; people |
| 233 |
can copy and change this file to suit their own needs. To make life |
| 234 |
easier for those who only want to use your standard styles, you may not want |
| 235 |
to force them to learn about styledef.tex. Instead, you can define a macro |
| 236 |
|\style| which always reads a file with name letter.style. Its usage would |
| 237 |
be: |
| 238 |
\begintt |
| 239 |
\input letter |
| 240 |
\style business, long, narrow. |
| 241 |
... |
| 242 |
\endtt |
| 243 |
so that users need not be concerned about style registers etc. Here is |
| 244 |
part of an appropriate letter.tex: |
| 245 |
\beginlines |
| 246 |
|\input styledef| |
| 247 |
\nobreak |
| 248 |
|\newstyle\letterstyle| |
| 249 |
\medskip |
| 250 |
|\def\style#1.% terminate the argument with a dot| |
| 251 |
\nobreak |
| 252 |
| {\setstyle\letterstyle{#1}| |
| 253 |
| \readstyle\letterstyle{letter.style}| |
| 254 |
\nobreak |
| 255 |
| }| |
| 256 |
\endlines |
| 257 |
|
| 258 |
\ddanger Something similar can be done with \LaTeX's |\documentstyle|, provided |
| 259 |
you know which styles can appear in letter.style. This is done as follows: |
| 260 |
first, rename letter.tex to letter.sty, so that \LaTeX\ can read it. Then |
| 261 |
add the following to the end of that file: |
| 262 |
\begintt |
| 263 |
\newstyle\lst |
| 264 |
\def\ds@business{\addstyle\lst{business}} |
| 265 |
\def\ds@narrow{\addstyle\lst{narrow}} |
| 266 |
... % same for every style |
| 267 |
\@options |
| 268 |
\readstyle\lst{letter.style} |
| 269 |
\endtt |
| 270 |
You can then write |\documentstyle[narrow]{letter}|. \LaTeX\ takes this |
| 271 |
as a command to read letter.sty. The |\@options| command causes \LaTeX\ to |
| 272 |
execute, for every option `xyz,' the command |\ds@xyz|, if it exists. All |
| 273 |
options for which this command does not exist lead to the input of a file |
| 274 |
xyz.sty, so that standard \LaTeX\ options can still be used. Note that |
| 275 |
letter.sty is here the main style file (only there can |\@options| be used); |
| 276 |
be warned that it is not easy to write a main style file that satisfies all |
| 277 |
of \LaTeX's assumptions. |
| 278 |
|
| 279 |
Although we have suggested that these macros are suitable to handle different |
| 280 |
``styles,'' selective inclusion can also be useful in contexts unrelated |
| 281 |
to styles. For instance, you may write a paper which has some details and |
| 282 |
speculations which are not relevant for every reader. |
| 283 |
You can write the paper like this: |
| 284 |
\beginlines |
| 285 |
| ... % relevant thoughts| |
| 286 |
\goodbreak |
| 287 |
|\styledef{details}| |
| 288 |
| ... % messy details| |
| 289 |
|\endstyle| |
| 290 |
\goodbreak |
| 291 |
|\negstyledef{details}| |
| 292 |
|Details are left as an exercise for the reader.| |
| 293 |
|\endstyle| |
| 294 |
\goodbreak |
| 295 |
| ... % important stuff| |
| 296 |
|\styledef{speculations}| |
| 297 |
| ... % wild fantasies| |
| 298 |
|\endstyle| |
| 299 |
\endlines |
| 300 |
If you want to print a version with speculations but without details, you |
| 301 |
can start the file with |
| 302 |
\begintt |
| 303 |
\newstyle\print |
| 304 |
\setstyle\print{speculations} |
| 305 |
\setreadstyle\print |
| 306 |
... |
| 307 |
\endtt |
| 308 |
|
| 309 |
\bye |