Commit | Line | Data |
---|---|---|
281c40ee | 1 | % \begin{meta-comment} |
2 | % | |
0fb4766d | 3 | % slowbox.dtx |
281c40ee | 4 | % |
5 | % Cop-out for slow things | |
6 | % | |
7 | % (c) 2003 Mark Wooding | |
8 | % | |
281c40ee | 9 | % \end{meta-comment} |
10 | % | |
11 | % \begin{meta-comment} <general public licence> | |
12 | %% | |
13 | %% slowbox package -- skipping of slow boxes | |
14 | %% Copyright (c) 2003 Mark Wooding | |
15 | %% | |
16 | %% This program is free software; you can redistribute it and/or modify | |
17 | %% it under the terms of the GNU General Public License as published by | |
18 | %% the Free Software Foundation; either version 2 of the License, or | |
19 | %% (at your option) any later version. | |
e8e9e5d8 | 20 | %% |
281c40ee | 21 | %% This program is distributed in the hope that it will be useful, |
22 | %% but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | %% GNU General Public License for more details. | |
e8e9e5d8 | 25 | %% |
281c40ee | 26 | %% You should have received a copy of the GNU General Public License |
27 | %% along with this program; if not, write to the Free Software Foundation, | |
28 | %% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
29 | % \end{meta-comment} | |
30 | % | |
31 | % \begin{meta-comment} <Package preambles> | |
32 | %<+package>\NeedsTeXFormat{LaTeX2e} | |
33 | %<+package>\ProvidesPackage{slowbox} | |
34 | %<+package> [2003/08/27 1.0 skipping of slow boxes] | |
35 | % \end{meta-comment} | |
36 | % | |
ad5b9f12 | 37 | % \CheckSum{223} |
281c40ee | 38 | %% \CharacterTable |
39 | %% {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 | |
40 | %% 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 | |
41 | %% Digits \0\1\2\3\4\5\6\7\8\9 | |
42 | %% Exclamation \! Double quote \" Hash (number) \# | |
43 | %% Dollar \$ Percent \% Ampersand \& | |
44 | %% Acute accent \' Left paren \( Right paren \) | |
45 | %% Asterisk \* Plus \+ Comma \, | |
46 | %% Minus \- Point \. Solidus \/ | |
47 | %% Colon \: Semicolon \; Less than \< | |
48 | %% Equals \= Greater than \> Question mark \? | |
49 | %% Commercial at \@ Left bracket \[ Backslash \\ | |
50 | %% Right bracket \] Circumflex \^ Underscore \_ | |
51 | %% Grave accent \` Left brace \{ Vertical bar \| | |
52 | %% Right brace \} Tilde \~} | |
53 | %% | |
54 | % | |
55 | % \begin{meta-comment} | |
56 | % | |
57 | %<*driver> | |
58 | \input{mdwtools} | |
620dfe24 | 59 | \PassOptionsToPackage{hide}{slowbox} |
281c40ee | 60 | \describespackage{slowbox} |
61 | \newcommand\opt[1]{\textsf{#1}} | |
281c40ee | 62 | \def\*{\hspace{0pt plus 0.1pt}\ignorespaces} |
63 | \mdwdoc | |
64 | %</driver> | |
65 | % | |
66 | % \end{meta-comment} | |
67 | % | |
68 | %^^A------------------------------------------------------------------------- | |
69 | % \section{User guide} | |
70 | % | |
71 | % The problem is that some things, e.g., diagrams, can take a while to | |
72 | % typeset, and aren't particularly interesting as far as the global document | |
73 | % layout is concerned. Once you've got a diagram right, the only thing that | |
74 | % matters as far as general previewing is concerned is its size. | |
75 | % | |
76 | % The solution is \package{slowbox}. Put things you're usually not | |
77 | % interested in seeing in a \env{slowbox} environment. Then they get | |
78 | % replaced by a frame saying that there's meant to be something there, and | |
79 | % that's it. | |
80 | % | |
81 | % There are two modes, chosen by package options: \opt{show} and \opt{hide}. | |
82 | % The default is \opt{show} mode, because I had to pick one. In \opt{show} | |
83 | % mode, everything happens normally; in \opt{hide} mode, slow boxes are | |
84 | % replaced by frames. In order for the package to know the sizes of all of | |
85 | % your boxes, you must first run through once in \opt{show} mode. | |
e8e9e5d8 | 86 | % Thereafter, all should be well. |
281c40ee | 87 | % |
88 | % \DescribeEnv{slowbox} | |
89 | % In \opt{show} mode, the \env{slowbox} environment typesets its contents in | |
90 | % LR-mode (for \TeX nicians, restricted horizontal mode).\footnote{^^A | |
91 | % Vertical mode causes all sorts of pain, and makes things way too wide. | |
92 | % Horizontal mode seems a good `standard currency' for \LaTeX\ things like | |
93 | % diagrams.} ^^A | |
94 | % In \opt{hide} mode, the boxes are replaced by frames, and \TeX\ will skip | |
95 | % over the contents of the environment at high speed, ignoring it | |
96 | % completely. | |
97 | % | |
98 | % The \env{slowbox} environment needs an argument, a \emph{tag} which is used | |
99 | % to identify this box. This is needed because otherwise the package has no | |
100 | % way of deciding that you've inserted some new box and need to shunt | |
101 | % everything about. So the full syntax is | |
102 | % \syntax{"\\begin{slowbox}{"<tag>"}" \ldots "\\end{slowbox}"}. | |
103 | % Tags can be any piece of text. If you include control sequences in the | |
104 | % tag, then they get expanded. That might be what you want. | |
105 | % | |
106 | % \DescribeEnv{slowbox$*$} | |
107 | % Adding new slow boxes is best done using the starred version of the | |
108 | % environment. Stuff in a \env{slowbox$*$} environment is always typset in | |
109 | % \opt{show} mode, regardless of the global mode setting. The right thing to | |
110 | % do is wrap your new stuff in a \env{slowbox$*$} while you're writing it. | |
111 | % Then remove the \env{$*$} and it will turn into a frame. The | |
112 | % \env{slowbox$*$} environment takes a tag name, just like \env{slowbox} | |
113 | % does. | |
114 | % | |
ad5b9f12 MW |
115 | % However, if \package{slowbox} sees a slow box \<tag> it's not noticed |
116 | % before, it always typesets the box contents, and saves the measurements for | |
117 | % later. | |
118 | % | |
620dfe24 MW |
119 | % \begin{demo}{Slow boxes} |
120 | %\newcommand{\pic} | |
121 | % {\parbox[t]{20mm} | |
122 | % {Just pretend that there's a picture | |
123 | % here that would take aaaages to draw.}} | |
124 | %-- | |
125 | %\begin{slowbox*}{show} | |
126 | % \pic | |
127 | %\end{slowbox*} | |
128 | %-- | |
129 | %\begin{slowbox}{hide} | |
130 | % \pic | |
131 | %\end{slowbox} | |
132 | %-- | |
133 | % \end{demo} | |
134 | % | |
281c40ee | 135 | % \DescribeMacro\slowboxbegin |
136 | % \DescribeMacro\slowboxend | |
137 | % It's useful to define your own commands environments which create slow | |
138 | % boxes. Often, though, what happens is that you want to put some stuff | |
139 | % \emph{inside} the slow box, but that doesn't work properly. What you must | |
140 | % do instead is say something like | |
456186fc | 141 | %\begin{verbatim} |
281c40ee | 142 | % \newenvironment{splunt}[1] |
143 | % {...\slowboxbegin{#1}{...\startsplunt...}} | |
144 | % {\slowboxend{...\finishsplunt...}...} | |
456186fc | 145 | %\end{verbatim} |
f3d67f57 | 146 | % That is, \syntax{"\\slowboxbegin{"<tag>"}{"<stuff>"}"} starts a slow box, |
d00a940b MW |
147 | % beginning with \<stuff> if we're in \opt{show} mode; and |
148 | % \syntax{"\\slowboxend{"<stuff>"}"} finishes it, ending with \<stuff>. | |
281c40ee | 149 | % |
150 | % The |\slowboxbegin| command has a |*|-variant, which causes the box to be | |
151 | % typeset regardless of the current mode setting. | |
152 | % | |
153 | % \DescribeMacro\newslowboxenv | |
239eeba9 MW |
154 | % Plumbing all of this together is rather tedious, so there's also a |
155 | % command for building slow box environments. Say | |
156 | % \syntax{"\\newslowboxenv{"<env-name>"}"\* "["<n-args>"]"\*"["<default>"]"\* | |
281c40ee | 157 | % "{"<before-text>"}"\* "{"<start-text>"}"\* "{"<end-text>"}"\* |
158 | % "{"<after-text>"}"}. This creates a new environment (just like with | |
d66aad8b MW |
159 | % |\newenvironment|, taking \<n-args> arguments, maybe with the first one |
160 | % optional and defaulting to \<default>). The contents are put in a slow box | |
161 | % with \<start-text> on the front and \<end-text> on the end. Before the box | |
162 | % is begun, \<before-text> is performed, and \<after-text> is done | |
163 | % afterwards. The environments so created have \env{$*$}-variants which | |
164 | % ignore the current mode, just like \env{slowbox$*$}. They also gather an | |
165 | % additional \<tag> argument, which you don't have to bother with. | |
281c40ee | 166 | % |
167 | % \DescribeMacro\doslowbox | |
168 | % Finally, for commands, there's \syntax{"\\doslowbox{"<tag>"}"\* | |
169 | % "{"<stuff>"}"}. This typesets \<stuff> in a slow box with the given tag. | |
170 | % There's a |*|-variant, of course. | |
171 | % | |
172 | % \DescribeMacro\slowboxshow | |
173 | % \DescribeMacro\slowboxhide | |
174 | % \DescribeMacro\ifslowboxshow | |
175 | % The declarations |\showboxshow| and |\slowboxhide| switch between the | |
176 | % \opt{show} and \opt{hide} modes. They obey standard scoping rules. | |
177 | % They're probably not very useful. They twiddle the |\ifslowboxshow| macro, | |
178 | % which is an old-fashioned Plain \TeX\ switch. If you're the sort of person | |
179 | % who uses \package{ifthen}, then you can test |\boolean{slowboxshow}|. | |
180 | % | |
181 | %^^A------------------------------------------------------------------------- | |
182 | % \implementation | |
183 | % | |
184 | % \section{Implementation of \package{slowbox}} | |
185 | % | |
186 | % \begin{macrocode} | |
187 | %<*package> | |
188 | % \end{macrocode} | |
189 | % | |
190 | % \subsection{The mode switch} | |
191 | % | |
192 | % \begin{macro}{\ifslowboxshow} | |
193 | % \begin{macro}{\slowboxshow} | |
194 | % \begin{macro}{\slowboxhide} | |
195 | % The |\if@slowboxshow| switch remembers which mode we're in. The | |
196 | % |\slowboxshow| and |\slowboxhide| macros flip the switch. It's really | |
197 | % easy. The |\relax|es are to annoy people who say |\global\showboxshow|. | |
198 | % \begin{macrocode} | |
199 | \def\slowboxshow{\relax\let\ifslowboxshow\iftrue} | |
200 | \def\slowboxhide{\relax\let\ifslowboxshow\iffalse} | |
201 | % \end{macrocode} | |
202 | % \end{macro} | |
203 | % \end{macro} | |
204 | % \end{macro} | |
205 | % | |
206 | % \subsection{Dependencies} | |
207 | % | |
208 | % The skipping-over-stuff-at-high-speed is done by my \package{sverb} | |
209 | % package. | |
210 | % \begin{macrocode} | |
211 | \RequirePackage{sverb} | |
212 | % \end{macrocode} | |
213 | % | |
214 | % \subsection{Options} | |
215 | % | |
216 | % Oh, this is obvious. | |
217 | % \begin{macrocode} | |
218 | \DeclareOption{show}{\slowboxshow} | |
219 | \DeclareOption{hide}{\slowboxhide} | |
220 | \ExecuteOptions{show} | |
221 | \ProcessOptions | |
222 | % \end{macrocode} | |
223 | % | |
224 | % \subsection{Remembering stuff} | |
225 | % | |
226 | % \begin{macro}{\sb@def} | |
227 | % Box dimensions are recorded in the |.aux| file using | |
228 | % \syntax{"\\sb@def{"<tag>"}"\* "{"<width>"}"\* "{"<height>"}"\* | |
229 | % "{"<depth>"}"}. This turns into a definition of a strange control | |
230 | % sequence. | |
231 | % \begin{macrocode} | |
232 | \def\sb@def#1#2#3#4% | |
233 | {\expandafter\gdef\csname sb@box:#1\endcsname{{#2}{#3}{#4}}} | |
234 | % \end{macrocode} | |
235 | % \end{macro} | |
236 | % | |
237 | % \subsection{The actual work} | |
238 | % | |
239 | % \begin{macro}{\sb@begin} | |
240 | % This is where most of the intelligence is. | |
241 | % \syntax{"\\sb@begin{"<tag>"}{"<stuff>"}"} starts a slow box, putting | |
242 | % \<stuff> at the start if we're in \opt{show} mode. It doesn't ignore stuff | |
243 | % -- though it sets |\sb@ignore| to be |\relax| in \opt{show} mode and | |
244 | % |\ignore| in \opt{hide} mode. It also sets |\sb@end| correctly, so that | |
245 | % \syntax{"\\sb@end{"<stuff>"}"} ends the current box, putting \<stuff> in | |
246 | % it. | |
247 | % | |
248 | % Disappointingly, perhaps, this is in fact just a dispatcher to the right | |
249 | % implementation. | |
250 | % \begin{macrocode} | |
251 | \def\sb@begin{% | |
252 | \ifslowboxshow\expandafter\sb@begin@show% | |
253 | \else\expandafter\sb@begin@hide\fi% | |
254 | } | |
255 | % \end{macrocode} | |
256 | % \end{macro} | |
257 | % | |
258 | % \begin{macro}{\sb@begin@show} | |
259 | % Now we have the implementation for \opt{show} mode. This is sometimes | |
260 | % called directly, by |*|-variants. Needs to be |\long| because \<stuff> | |
261 | % might contain embedded vmode-material which could legitimately have |\par| | |
262 | % tokens in. | |
263 | % \begin{macrocode} | |
264 | \long\def\sb@begin@show#1#2{% | |
265 | \begingroup% | |
266 | \def\sb@end##1{% | |
267 | ##1% | |
268 | \color@endgroup% | |
269 | \egroup% | |
270 | \immediate\write\@auxout% | |
271 | {\string\sb@def{#1}{\the\wd\z@}{\the\ht\z@}{\the\dp\z@}}% | |
272 | \leavevmode\box\z@% | |
273 | \endgroup% | |
274 | }% | |
275 | \let\sb@ignore\relax% | |
276 | \setbox\z@\hbox\bgroup\color@begingroup#2% | |
277 | } | |
278 | % \end{macrocode} | |
279 | % \end{macro} | |
280 | % | |
281 | % \begin{macro}{\sb@begin@hide} | |
282 | % Now for something a bit stranger. If we're in \opt{hide} mode, we need to | |
283 | % find out whether we've saved information about this box before. We pass | |
284 | % the \emph{control sequence} containing the box dimensions to another | |
285 | % macro. Needs to be |\long| to collect the \<stuff> argument. | |
286 | % \begin{macrocode} | |
287 | \long\def\sb@begin@hide#1#2{% | |
288 | \begingroup% | |
289 | \def\sb@end##1{\endgroup}% | |
290 | \let\sb@ignore\ignore% | |
ad5b9f12 | 291 | \expandafter\sb@hidden\csname sb@box:#1\endcsname{#1}{#2}% |
281c40ee | 292 | } |
293 | % \end{macrocode} | |
294 | % \end{macro} | |
295 | % | |
296 | % \begin{macro}{\sb@hidden} | |
297 | % We're given the control token and the tag name. If the control sequence is | |
ad5b9f12 MW |
298 | % like |\relax| then |\csname| must have invented it and we should typeset it |
299 | % anyway in order to measure it. Otherwise we put the right stuff in a | |
300 | % frame. Don't forget to write out the box dimensions to the new aux file! | |
281c40ee | 301 | % \begin{macrocode} |
ad5b9f12 MW |
302 | \def\sb@hidden#1#2#3{% |
303 | \ifx#1\relax\def\next@{\endgroup\sb@begin@show{#2}{#3}}% | |
304 | \else\edef\next@{\noexpand\sb@hidden@i#1{#2}}\fi% | |
305 | \next@% | |
281c40ee | 306 | } |
307 | \def\sb@hidden@i#1#2#3#4{% | |
308 | \frameonly{#1}{#2}{#3}{Omitted \texttt{#4}}% | |
e8e9e5d8 | 309 | \immediate\write\@auxout{\string\sb@def{#4}{#1}{#2}{#3}}% |
281c40ee | 310 | } |
311 | % \end{macrocode} | |
312 | % \end{macro} | |
313 | % | |
314 | % \subsection{Stuff in frames} | |
315 | % | |
316 | % \begin{macro}{\frameonly} | |
317 | % \syntax{"\\frameonly{"<width>"}{"<height>"}{"<depth>"}{"<stuff>"}"} | |
318 | % typesets \<stuff> in a frame with the given dimensions. This is a bit | |
319 | % tricky -- we want the \<stuff> in the middle of the box, but the box's | |
320 | % reference point is somewhere else. We start with a |\vcenter| of the right | |
321 | % height, and then nudge it into position later. | |
322 | % | |
323 | % In case the label is just too big, put shrinky glue all round. It'll look | |
324 | % horrible, but at least it won't mess everything up. | |
325 | % \begin{macrocode} | |
326 | \def\frameonly#1#2#3#4{% | |
327 | \dimen\tw@#2\advance\dimen\tw@#3\advance\dimen\tw@-.8\p@% | |
328 | \setbox\z@\hbox{$\vcenter{\hrule\@height\dimen\tw@\@depth\z@}$}% | |
329 | \dimen@#1% | |
330 | \advance\dimen@-.8\p@% | |
331 | \setbox\z@\vbox{% | |
332 | \hrule\vss% | |
333 | \hb@xt@\dimen@{% | |
334 | \vrule\@height\ht\z@\@depth\dp\z@\hss% | |
335 | \advance\dimen@-2em% | |
336 | \parbox\dimen@{\centering#4}% | |
337 | \hss\vrule}% | |
338 | \vss\hrule% | |
339 | }% | |
340 | \dimen@#3\advance\dimen@-\dp\z@% | |
341 | \setbox\z@\hbox{\lower\dimen@\box\z@}% | |
e8e9e5d8 | 342 | \leavevmode\box\z@% |
281c40ee | 343 | } |
344 | % \end{macrocode} | |
345 | % \end{macro} | |
346 | % | |
347 | % \subsection{User commands} | |
348 | % | |
349 | % \begin{macro}{\slowboxbegin} | |
350 | % \begin{macro}{\slowboxend} | |
351 | % This is just a matter of using the machinery we've built already. | |
352 | % \begin{macrocode} | |
353 | \def\slowboxbegin{\@ifstar{\sb@go\sb@begin}{\sb@go\sb@begin@show}} | |
354 | \long\def\sb@go#1#2#3{#1{#2}{#3}\sb@ignore} | |
355 | \def\slowboxend{\sb@end} | |
356 | % \end{macrocode} | |
357 | % \end{macro} | |
358 | % \end{macro} | |
359 | % | |
360 | % \begin{macro}{\doslowbox} | |
361 | % And this too. | |
362 | % \begin{macrocode} | |
363 | \def\doslowbox{\@ifstar{\sb@do\sb@begin}{\sb@do\sb@begin@show}} | |
364 | \long\def\sb@do#1#2#3{#1{#2}{#3}\sb@end} | |
365 | % \end{macrocode} | |
366 | % \end{macro} | |
367 | % | |
368 | % \begin{macro}{\newslowboxenv} | |
369 | % Something a bit more interesting now. Gathering the optional arguments for | |
370 | % |\newenvironment| is a bit tedious, but we do it anyway. Picking up the | |
371 | % arguments for the environment is a bit tricky -- they come in the wrong | |
372 | % order, unfortunately. | |
373 | % \begin{macrocode} | |
374 | \def\newslowboxenv#1{\@ifnextchar[{\sb@nenv@i{#1}}{\sb@nenv@do{#1}{}}} | |
375 | \def\sb@nenv@i#1[#2]{% | |
376 | \@ifnextchar[{\sb@nenv@ii{#1}{[{#2}]}}{\sb@nenv@do{#1}{[{#2}]}}% | |
377 | } | |
378 | \def\sb@nenv@ii#1#2[#3]{\sb@nenv@do{#1}{#2[{#2}]}} | |
379 | \long\def\sb@nenv@do#1#2#3#4#5#6{% | |
380 | \newenvironment{#1}#2{#3\sb@env\sb@begin{#4}}{\sb@end{#5}#6}% | |
381 | \newenvironment{#1*}#2{#3\sb@env\sb@begin@show{#4}}{\sb@end{#5}#6}% | |
382 | } | |
383 | \def\sb@env#1#2#3{#1{#3}{#2}\sb@ignore} | |
384 | % \end{macrocode} | |
385 | % \end{macro} | |
386 | % | |
387 | % \begin{environment}{slowbox} | |
388 | % And the \env{slowbox} is built using the above equipment. | |
389 | % \begin{macrocode} | |
390 | \newslowboxenv{slowbox}{}{}{}{} | |
391 | % \end{macrocode} | |
392 | % \end{environment} | |
393 | % | |
394 | % \begin{macrocode} | |
395 | %</package> | |
396 | % \end{macrocode} | |
397 | % | |
398 | % \Finale | |
e8e9e5d8 | 399 | \endinput |