2 %% The preview style for extracting previews from LaTeX documents.
3 %% Developed as part of AUCTeX <URL:http://www.gnu.org/software/auctex>.
5 % Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006,
6 % 2010 Free Software Foundation
8 % This program is free software; you can redistribute it and/or modify
9 % it under the terms of the GNU General Public License as published by
10 % the Free Software Foundation; either version 3 of the License, or
11 % (at your option) any later version.
13 % This program is distributed in the hope that it will be useful,
14 % but WITHOUT ANY WARRANTY; without even the implied warranty of
15 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 % GNU General Public License for more details.
18 % You should have received a copy of the GNU General Public License
19 % along with this program; if not, write to the
20 % Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 % Boston, MA 02110-1301 USA
24 % \GetFileInfo{preview.sty}
26 % \author{David Kastrup\thanks{\texttt{dak@gnu.org}}}
27 % \title{The \texttt{preview} Package for \LaTeX\\Version \fileversion}
29 % \section{Introduction}
30 % The main purpose of this package is the extraction of certain
31 % environments (most notably displayed formulas) from \LaTeX\ sources
32 % as graphics. This works with DVI files postprocessed by either
33 % Dvips and Ghostscript or dvipng, but it also works when you are
34 % using PDF\TeX\ for generating PDF files (usually also postprocessed
37 % Current uses of the package include the \previewlatex\ package for
38 % WYSIWYG functionality in the AUC\TeX\ editing environment,
39 % generation of previews in LyX, as part of the operation of the
40 % ps4pdf package, the tbook XML system and some other tools.
42 % Producing EPS files with Dvips and its derivatives using the
43 % \texttt{-E} option is not a good alternative: People make do by
44 % fiddling around with |\thispagestyle{empty}| and hoping for the best
45 % (namely, that the specified contents will indeed fit on single
46 % pages), and then trying to guess the baseline of the resulting code
47 % and stuff, but this is at best dissatisfactory. The preview package
48 % provides an easy way to ensure that exactly one page per request
49 % gets shipped, with a well-defined baseline and no page decorations.
50 % While you still can use the preview package with the `classic'
54 % invocation, there are better ways available that don't rely on Dvips
55 % not getting confused by PostScript specials.
57 % For most applications, you'll want to make use of the |tightpage|
58 % option. This will embed the page dimensions into the PostScript or
59 % PDF code, obliterating the need to use the |-E -i| options to Dvips.
60 % You can then produce all image files with a single run of
61 % Ghostscript from a single PDF or PostScript (as opposed to EPS)
64 % Various options exist that will pass \TeX\ dimensions and other
65 % information about the respective shipped out material (including
66 % descender size) into the log file, where external applications might
69 % The possibility for generating a whole set of graphics with a single
70 % run of Ghostscript (whether from \LaTeX\ or PDF\LaTeX) increases
71 % both speed and robustness of applications. It is also feasible to
72 % use dvipng on a DVI file with the options
74 % |-picky -noghostscript|
76 % to omit generating any image file that requires Ghostscript, then
77 % let a script generate all missing files using Dvips/Ghostscript.
78 % This will usually speed up the process significantly.
80 % \section{Package options}
81 % The package is included with the customary
83 % |\usepackage|\oarg{options}|{preview}|
85 % You should usually load this package as the last one, since it
86 % redefines several things that other packages may also provide.
88 % The following options are available:
90 % \item[|active|] is the most essential option. If this option is not
91 % specified, the |preview| package will be inactive and the document
92 % will be typeset as if the |preview| package were not loaded,
93 % except that all declarations and environments defined by the
94 % package are still legal but have no effect. This allows defining
95 % previewing characteristics in your document, and only activating
96 % them by calling \LaTeX\ as
99 % |latex '\PassOptionsToPackage{active}{preview}| |\input|\marg{filename}|'|
101 % \item[|noconfig|] Usually the file |prdefault.cfg| gets loaded
102 % whenever the |preview| package gets activated. |prdefault.cfg| is
103 % supposed to contain definitions that can cater for otherwise bad
104 % results, for example, if a certain document class would otherwise
105 % lead to trouble. It also can be used to override any settings
106 % made in this package, since it is loaded at the very end of it.
107 % In addition, there may be configuration files specific for certain
108 % |preview| options like |auctex| which have more immediate needs.
109 % The |noconfig| option suppresses loading of those option files,
111 % \item[|psfixbb|] Dvips determines the bounding boxes from the
112 % material in the DVI file it understands. Lots of PostScript
113 % specials are not part of that. Since the \TeX\ boxes do not make
114 % it into the DVI file, but merely characters, rules and specials
115 % do, Dvips might include far too small areas. The option |psfixbb|
116 % will include |/dev/null| as a graphic file in the ultimate upper
117 % left and lower right corner of the previewed box. This will make
118 % Dvips generate an appropriate bounding box.
119 % \item[|dvips|] If this option is specified as a class option or to
120 % other packages, several packages pass things like page size
121 % information to Dvips, or cause crop marks or draft messages
122 % written on pages. This seriously hampers the usability of
123 % previews. If this option is specified, the changes will be undone
125 % \item[|pdftex|] If this option is set, PDF\TeX\ is assumed as the
126 % output driver. This mainly affects the |tightpage| option.
127 % \item[|xetex|] If this option is set, Xe\TeX\ is assumed as the
128 % output driver. This mainly affects the |tightpage| option.
129 % \item[|displaymath|] will make all displayed math environments
130 % subject to preview processing. This will typically be the most
132 % \item[|floats|] will make all float objects subject to preview
133 % processing. If you want to be more selective about what floats to
134 % pass through to a preview, you should instead use the
135 % \cmd{\PreviewSnarfEnvironment} command on the floats you want to
137 % \item[|textmath|] will make all text math subject to previews.
138 % Since math mode is used throughly inside of \LaTeX\ even for other
139 % purposes, this works by redefining \cmd\(, \cmd\)
140 % and |$| and the |math| environment (apparently some people use
141 % that). Only occurences of these text math delimiters in later
142 % loaded packages and in the main document will thus be affected.
143 % \item[|graphics|] will subject all \cmd{\includegraphics} commands
145 % \item[|sections|] will subject all section headers to a preview.
146 % \item[|delayed|] will delay all activations and redefinitions the
147 % |preview| package makes until |\||begin{document}|. The purpose
148 % of this is to cater for documents which should be subjected to the
149 % |preview| package without having been prepared for it. You can
150 % process such documents with
152 % |latex '\RequirePackage[active,delayed,|\meta{options}|]{preview}|
153 % |\input|\marg{filename}|'|
155 % This relaxes the requirement to be loading the |preview| package
157 % \item[\meta{driver}] loads a special driver file
158 % |pr|\meta{driver}|.def|. The remaining options are implemented
159 % through the use of driver files.
160 % \item[|auctex|] This driver will produce fake error messages at the
161 % start and end of every preview environment that enable the Emacs
162 % package \previewlatex\ in connection with AUC\TeX\ to pinpoint
163 % the exact source location where the previews have originated.
164 % Unfortunately, there is no other reliable means of passing the
165 % current \TeX\ input position \emph{in} a line to external
166 % programs. In order to make the parsing more robust, this option
167 % also switches off quite a few diagnostics that could be
170 % You should not specify this option manually, since it will only be
171 % needed by automated runs that want to parse the pseudo error
172 % messages. Those runs will then use \cmd{\PassOptionsToPackage} in
173 % order to effect the desired behaviour. In addition,
174 % |prauctex.cfg| will get loaded unless inhibited by the |noconfig|
175 % option. This caters for the most frequently encountered
176 % problematic commands.
177 % \item[|showlabels|] During the editing process, some people like to
178 % see the label names in their equations, figures and the like. Now
179 % if you are using Emacs for editing, and in particular
180 % \previewlatex, I'd strongly recommend that you check out the
181 % Ref\TeX\ package which pretty much obliterates the need for this
182 % kind of functionality. If you still want it, standard \LaTeX\
183 % provides it with the |showkeys| package, and there is also the
184 % less encompassing |showlabels| package. Unfortunately, since
185 % those go to some pain not to change the page layout and spacing,
186 % they also don't change |preview|'s idea of the \TeX\ dimensions of
187 % the involved boxes. So if you are using |preview| for determing
188 % bounding boxes, those packages are mostly useless. The option
189 % |showlabels| offers a substitute for them.
190 % \item[|tightpage|] It is not uncommon to want to use the results of
191 % |preview| as graphic images for some other application. One
192 % possibility is to generate a flurry of EPS files with
194 % |dvips -E -i -Pwww -o| \meta{outputfile}|.000| \meta{inputfile}
196 % However, in case those are to be processed further into graphic
197 % image files by Ghostscript, this process is inefficient since all
198 % of those files need to be processed one by one. In addition, it
199 % is necessary to extract the bounding box comments from the EPS
200 % files and convert them into page dimension parameters for
201 % Ghostscript in order to avoid full-page graphics. This is not
202 % even possible if you wanted to use Ghostscript in a~\emph{single}
203 % run for generating the files from a single PostScript file, since
204 % Dvips will in that case leave no bounding box information
207 % The solution is to use the |tightpage| option. That way a single
211 % \texttt{gs -sDEVICE=png16m -dTextAlphaBits=4 -r300
212 % -dGraphicsAlphaBits=4 -dSAFER -q -dNOPAUSE
213 % -sOutputFile=\meta{outputfile}\%d.png \meta{inputfile}.ps}
215 % will be able to produce tight graphics from a single PostScript
216 % file generated with Dvips \emph{without} use of the options
217 % |-E -i|, in a single run.
219 % The |tightpage| option actually also works when using the |pdftex|
220 % option and generating PDF files with PDF\TeX. The resulting PDF
221 % file has separate page dimensions for every page and can directly
222 % be converted with one run of Ghostscript into image files.
224 % If neither |dvips| or |pdftex| have been specified, the
225 % corresponding option will get autodetected and invoked.
227 % If you need this in a batch environment where you don't want to
228 % use |preview|'s automatic extraction facilities, no problem: just
229 % don't use any of the extraction options, and wrap everything to be
230 % previewed into |preview| environments. This is how LyX does its
233 % If the pages under the |tightpage| option are just too tight, you
234 % can adjust by setting the length |\PreviewBorder| to a different
235 % value by using \cmd{\setlength}. The default value is
236 % |0.50001bp|, which is half of a usual PostScript point, rounded
237 % up. If you go below this value, the resulting page size may drop
238 % below |1bp|, and Ghostscript does not seem to like that. If you
239 % need finer control, you can adjust the bounding box dimensions
240 % individually by changing the macro |\PreviewBbAdjust| with the
241 % help of |\renewcommand|. Its default value is
244 % |\newcommand| |\PreviewBbAdjust|
245 % |{-\PreviewBorder| |-\PreviewBorder|
246 % |\PreviewBorder| |\PreviewBorder}|
248 % This adjusts the left, lower, right and upper borders by the given
249 % amount. The macro must contain 4~\TeX\ dimensions after another,
250 % and you may not omit the units if you specify them explicitly
251 % instead of by register. PostScript points have the unit~|bp|.
252 % \item[|lyx|] This option is for the sake of LyX developers. It will
253 % output a few diagnostics relevant for the sake of LyX' preview
254 % functionality (at the time of writing, mostly implemented for math
255 % insets, in versions of LyX starting with 1.3.0).
256 % \item[|counters|] This writes out diagnostics at the start and the
257 % end of previews. Only the counters changed since the last output
258 % get written, and if no counters changed, nothing gets written at
259 % all. The list consists of counter name and value, both enclosed
260 % in |{}| braces, followed by a space. The last such pair is
261 % followed by a colon (|:|) if it is at the start of the preview
262 % snippet, and by a period (|.|) if it is at the end. The order of
263 % different diagnostics like this being issued depends on the order
264 % of the specification of the options when calling the package.
266 % Systems like \previewlatex\ use this for keeping counters accurate
267 % when single previews are regenerated.
268 % \item[|footnotes|] This makes footnotes render as previews, and only
269 % as their footnote symbol. A convenient editing feature inside of
272 % The following options are just for debugging purposes of the package
273 % and similar to the corresponding \TeX\ commands they allude to:
274 % \begin{description}
275 % \item[|tracingall|] causes lots of diagnostic output to appear in
276 % the log file during the preview collecting phases of \TeX's
277 % operation. In contrast to the similarly named \TeX\ command, it
278 % will not switch to |\errorstopmode|, nor will it change the
279 % setting of |\tracingonline|.
280 % \item[|showbox|] This option will show the contents of the boxes
281 % shipped out to the DVI files. It also sets |\showboxbreadth| and
282 % |\showboxdepth| to their maximum values at the end of loading this
283 % package, but you may reset them if you don't like that.
285 % \section{Provided Commands}
286 % \DescribeEnv{preview} The |preview| environment causes its contents
287 % to be set as a single preview image. Insertions like figures and
288 % footnotes (except those included in minipages) will typically lead
289 % to error messages or be lost. In case the |preview| package has not
290 % been activated, the contents of this environment will be typeset
293 % \DescribeEnv{nopreview} The |nopreview| environment will cause its
294 % contents not to undergo any special treatment by the |preview|
295 % package. When |preview| is active, the contents will be discarded
296 % like all main text that does not trigger the |preview| hooks. When
297 % |preview| is not active, the contents will be typeset just like the
300 % Note that both of these environments typeset things as usual when
301 % preview is not active. If you need something typeset conditionally,
302 % use the \cmd{\ifPreview} conditional for it.
304 % \DescribeMacro{\PreviewMacro} If you want to make a macro like
305 % \cmd{\includegraphics} (actually, this is what is done by the
306 % |graphics| option to |preview|) produce a preview image, you put a
309 % |\PreviewMacro[*[[!]{\includegraphics}|
313 % |\PreviewMacro[{*[][]{}}]{\includegraphics}|
315 % into your preamble. The optional argument to \cmd{\PreviewMacro}
316 % specifies the arguments \cmd{\includegraphics} accepts, since this
317 % is necessary information for properly ending the preview box. Note
318 % that if you are using the more readable form, you have to enclose
319 % the argument in a |[{| and |}]| pair. The inner braces are
320 % necessary to stop any included |[]| pairs from prematurely ending
321 % the optional argument, and to make a single |{}|
322 % denoting an optional argument not get stripped away by \TeX's
325 % The letters simply mean
326 % \begin{description}
327 % \item[|*|] indicates an optional |*| modifier, as in
328 % |\includegraphics*|.
330 % indicates an optional argument in brackets. This syntax
331 % is somewhat baroque, but brief.
332 % \item[{|[]|}] also indicates an optional argument in brackets. Be
333 % sure to have encluded the entire optional argument specification
334 % in an additional pair of braces as described above.
335 % \item[|!|] indicates a mandatory argument.
336 % \item[|\char`{\char`}|] indicates the same. Again, be sure to have
337 % that additional level of braces around the whole argument
339 % \item[|?|\meta{delimiter}\marg{true case}\marg{false case}] is a
340 % conditional. The next character is checked against being equal to
341 % \meta{delimiter}. If it is, the specification \meta{true case} is
342 % used for the further parsing, otherwise \meta{false case} will be
343 % employed. In neither case is something consumed from the input,
344 % so \marg{true case} will still have to deal with the upcoming
346 % \item[|@|\marg{literal sequence}] will insert the given sequence
347 % literally into the executed call of the command.
348 % \item[|-|] will just drop the next token. It will probably be most
349 % often used in the true branch of a |?| specification.
350 % \item[|\#|\marg{argument}\marg{replacement}] is a transformation
351 % rule that calls a macro with the given argument and replacement
352 % text on the rest of the argument list. The replacement is used in
353 % the executed call of the command. This can be used for parsing
354 % arbitrary constructs. For example, the |[]| option could manually
355 % be implemented with the option string |?[{#{[#1]}{[{#1}]}}{}|.
356 % PStricks users might enjoy this sort of flexibility.
357 % \item[|:|\marg{argument}\marg{replacement}] is again a
358 % transformation rule. As opposed to |#|, however, the result of
359 % the transformation is parsed again. You'll rarely need this.
362 % There is a second optional argument in brackets that can be used to
363 % declare any default action to be taken instead. This is mostly for
364 % the sake of macros that influence numbering: you would want to keep
365 % their effects in that respect. The default action should use |#1|
366 % for referring to the original (not the patched) command with the
367 % parsed options appended. Not specifying a second optional argument
368 % here is equivalent to specifying~|[#1]|.
370 % \DescribeMacro{\PreviewMacro*} A similar invocation
371 % \cmd{\PreviewMacro*} simply throws the macro and all of its
372 % arguments declared in the manner above away. This is mostly useful
373 % for having things like \cmd{\footnote} not do their magic on their
374 % arguments. More often than not, you don't want to declare any
375 % arguments to scan to \cmd{\PreviewMacro*} since you would want the
376 % remaining arguments to be treated as usual text and typeset in that
377 % manner instead of being thrown away. An exception might be, say,
378 % sort keys for \cmd{\cite}.
380 % A second optional argument in brackets can be used to declare any
381 % default action to be taken instead. This is for the sake of macros
382 % that influence numbering: you would want to keep their effects in
383 % that respect. The default action might use |#1| for referring to
384 % the original (not the patched) command with the parsed options
385 % appended. Not specifying a second optional argument here is
386 % equivalent to specifying~|[]| since the command usually gets thrown
389 % As an example for using this argument, you might want to specify
391 % |\PreviewMacro*\footnote[{[]}][#1{}]|
393 % This will replace a footnote by an empty footnote, but taking any
394 % optional parameter into account, since an optional paramter changes
395 % the numbering scheme. That way the real argument for the footnote
396 % remains for processing by \previewlatex.
398 % \DescribeMacro{\PreviewEnvironment} The macro
399 % \cmd{\PreviewEnvironment} works just as \cmd{\PreviewMacro} does,
400 % only for environments. \DescribeMacro{\PreviewEnvironment*} And the
401 % same goes for \cmd{\PreviewEnvironment*} as compared to
402 % \cmd{\PreviewMacro*}.
404 % \DescribeMacro{\PreviewSnarfEnvironment} This macro does not typeset
405 % the original environment inside of a preview box, but instead
406 % typesets just the contents of the original environment inside of the
407 % preview box, leaving nothing for the original environment. This has
408 % to be used for figures, for example, since they would
410 % \item produce insertion material that cannot be extracted to the
412 % \item complain with an error message about not being in outer par
416 % \DescribeMacro{\PreviewOpen}
417 % \DescribeMacro{\PreviewClose}
418 % Those Macros form a matched preview pair. This is for macros that
419 % behave similar as \cmd{\begin} and \cmd{\end} of an environment. It
420 % is essential for the operation of \cmd{\PreviewOpen} that the macro
421 % treated with it will open an additional group even when the preview
422 % falls inside of another preview or inside of a |nopreview|
423 % environment. Similarly, the macro treated with \cmd{PreviewClose}
424 % will close an environment even when inactive.
426 % \DescribeMacro{\ifPreview} In case you need to know whether
427 % |preview| is active, you can use the conditional \cmd{\ifPreview}
428 % together with |\else| and |\fi|.
431 % \section{The Implementation}
432 % Here we go: the start is somewhat obtuse since we figure out version
433 % number and date from RCS strings. This should really be done at
434 % docstrip time instead. Takers?
435 % \begin{macro}{\pr@version}
439 \NeedsTeXFormat{LaTeX2e} \def\reserved@a #1#2$#3:
440 #4${\xdef#1{\reserved@c #2#4 $}} \def\reserved@c #1 #2${#1}
441 \begingroup \catcode`\_=12
442 \reserved@a\pr@version $Name: release_11_86 $ \ifx\pr@version\@empty
443 \reserved@a\pr@version CVS-$Revision: 1.126 $ \endgroup \else
444 \def\next release_{} \lccode`\_=`.
445 \edef\next{\lowercase{\endgroup
446 \def\noexpand\pr@version{\expandafter\next\pr@version}}} \next \fi
447 \reserved@a\next $Date: 2010/02/14 16:19:00 $
448 \edef\next{\noexpand\ProvidesPackage{preview}%
449 [\next\space \pr@version\space (AUCTeX/preview-latex)]}
453 % Since many parts here will not be needed as long as the package is
454 % inactive, we will include them enclosed with |<*active>| and
455 % |</active>| guards. That way, we can append all of this stuff at a
456 % place where it does not get loaded if not necessary.
458 %\begin{macro}{\ifPreview}
459 % Setting the \cmd{\ifPreview} command should not be done by the
460 % user, so we don't use \cmd{\newif} here. As a consequence, there
461 % are no \cmd{\Previewtrue} and \cmd{\Previewfalse} commands.
463 \let\ifPreview\iffalse
467 %\begin{macro}{\ifpr@outer}
468 % We don't allow previews inside of previews. The macro
469 % \cmd{\ifpr@outer} can be used for checking whether we are outside
470 % of any preview code.
479 %\begin{macro}{\preview@delay}
480 % The usual meaning of \cmd{\preview@delay} is to just echo its
481 % argument in normal |preview| operation. If |preview| is inactive,
482 % it swallows its argument. If the |delayed| option is active, the
483 % contents will be passed to the \cmd{\AtBeginDocument} hook.
484 %\begin{macro}{\pr@advise}
485 % The core macro for modifying commands is \cmd{\pr@advise}. You
486 % pass it the original command name as first argument and what should
487 % be executed before the saved original command as second argument.
488 %\begin{macro}{\pr@advise@ship}
489 % The most often used macro for modifying commands is
490 % \cmd{\pr@advise@ship}. It receives three arguments. The first is
491 % the macro to modify, the second specifies some actions to be done
492 % inside of a box to be created before the original macro gets
493 % executed, the third one specifies actions after the original macro
495 %\begin{macro}{\pr@loadcfg}
496 % The macro \cmd{\pr@loadcfg} is used for loading in configuration
497 % files, unless disabled by the |noconfig| option.
500 \let\preview@delay=\@gobble
501 \let\pr@advise=\@gobbletwo
502 \long\def\pr@advise@ship#1#2#3{}
503 \def\pr@loadcfg#1{\InputIfFileExists{#1.cfg}{}{}}
504 \DeclareOption{noconfig}{\let\pr@loadcfg=\@gobble}
506 %\begin{macro}{\pr@addto@front}
507 % This adds code globally to the front of a macro.
509 \long\def\pr@addto@front#1#2{%
510 \toks@{#2}\toks@\expandafter{\the\expandafter\toks@#1}%
514 % These commands get more interesting when |preview| is active:
516 \DeclareOption{active}{%
517 \let\ifPreview\iftrue
519 \expandafter\pr@adviseii\csname pr@\string#1\endcsname#1}%
520 \long\def\pr@advise@ship#1#2#3{\pr@advise#1{\pr@protect@ship{#2}{#3}}}%
521 \let\preview@delay\@firstofone}
528 % \begin{macro}{\pr@adviseii}
529 % Now \cmd{\pr@advise} needs its helper macro. In order to avoid
530 % recursive definitions, we advise only macros that are not yet
531 % advised. Or, more exactly, we throw away the old advice and only
532 % take the new one. We use e\TeX's \cmd{\protected} where available
533 % for some extra robustness.
535 \long\def\pr@adviseii#1#2#3{\preview@delay{%
536 \ifx#1\relax \let#1#2\fi
538 \ifx\@undefined\protected \else \protected\fi
539 \long\edef#2{\the\toks@}}}
543 % The |delayed| option is easy to implement: this is \emph{not} done
544 % with \cmd{\let} since at the course of document processing, \LaTeX\
545 % redefines \cmd{\AtBeginDocument} and we want to follow that
548 \DeclareOption{delayed}{%
549 \ifPreview \def\preview@delay{\AtBeginDocument}\fi
553 %\begin{macro}{\ifpr@fixbb}
554 % Another conditional. \cmd{\ifpr@fixbb} tells us whether we want to
555 % surround the typeset materials with invisible rules so that Dvips
556 % gets the bounding boxes right for, say, pure PostScript inclusions.
558 % If you are installing this on an operating system different from
559 % the one |preview| has been developed on, you might want to redefine
560 % |\pr@markerbox| in your |prdefault.cfg| file to use a file known to
561 % be empty, like |/dev/null| is under Unix. Make this redefinition
562 % depend on \cmd{\ifpr@fixbb} since only then |\pr@markerbox| will be
567 \DeclareOption{psfixbb}{\ifPreview%
570 \setbox\pr@markerbox\hbox{\special{psfile=/dev/null}}\fi
574 % \begin{macro}{\pr@graphicstype}
575 % The |dvips| option redefines the |bop-hook| to reset the page
578 \let\pr@graphicstype=\z@
579 \DeclareOption{dvips}{%
580 \let\pr@graphicstype\@ne
581 \preview@delay{\AtBeginDvi{%
582 \special{!/preview@version(\pr@version)def}
583 \special{!userdict begin/preview-bop-level 0 def%
584 /bop-hook{/preview-bop-level dup load dup 0 le{/isls false def%
585 /vsize 792 def/hsize 612 def}if 1 add store}bind def%
586 /eop-hook{/preview-bop-level dup load dup 0 gt{1 sub}if
587 store}bind def end}}}}
589 % The |pdftex| option just sets \cmd{\pr@graphicstype}.
591 \DeclareOption{pdftex}{%
592 \let\pr@graphicstype\tw@}
594 % And so does the |xetex| option.
596 \DeclareOption{xetex}{%
597 \let\pr@graphicstype\thr@@}
601 % \subsection{The internals}
603 % Those are only needed if |preview| is active.
607 % \begin{macro}{\pr@snippet}
608 % \cmd{\pr@snippet} is the current snippet number. We need a
609 % separate counter to \cmd{\c@page} since several other commands
610 % might fiddle with the page number.
616 % \begin{macro}{\pr@protect}
617 % This macro gets one argument which is unpacked and executed in
618 % typesetting situations where we are not yet inside of a preview.
620 \def\pr@protect{\ifx\protect\@typeset@protect
621 \ifpr@outer \expandafter\expandafter\expandafter
622 \@secondoftwo\fi\fi\@gobble}
625 % \begin{macro}{\pr@protect@ship}
626 % Now for the above mentioned \cmd{\pr@protect@ship}. This gets
627 % three arguments. The first is what to do at the beginning of the
628 % preview, the second what to do at the end, the third is the macro
629 % where we stored the original definition.
631 % In case we are not in a typesetting situation,
632 % \cmd{\pr@protect@ship} leaves the stored macro to fend for its
633 % own. No better or worse protection than the original. And we
634 % only do anything different when \cmd{\ifpr@outer} turns out to be
637 \def\pr@protect@ship{\pr@protect{\@firstoftwo\pr@startbox}%
641 % \begin{macro}{\pr@insert}
642 % \begin{macro}{\pr@mark}
643 % \begin{macro}{\pr@marks}
644 % We don't want insertions to end up on our lists. So we disable
645 % them right now by replacing them with the following:
647 \def\pr@insert{\begingroup\afterassignment\pr@insertii\count@}
648 \def\pr@insertii{\endgroup\setbox\pr@box\vbox}
650 % Similar things hold for marks.
652 \def\pr@mark{{\afterassignment}\toks@}
653 \def\pr@marks{{\aftergroup\pr@mark\afterassignment}\count@}
658 % \begin{macro}{\pr@box}
659 % \begin{macro}{\pr@startbox}
660 % Previews will be stored in \cmd{\box}\cmd{\pr@box}.
661 % \cmd{\pr@startbox} gets two arguments: code to execute immediately
662 % before the following stuff, code to execute afterwards. You have
663 % to cater for \cmd{\pr@endbox} being called at the right time
664 % yourself. We will use a \cmd{\vsplit} on the box later in order
665 % to remove any leading glues, penalties and similar stuff. For
666 % this reason we start off the box with an optimal break point.
669 \long\def\pr@startbox#1#2{%
672 \edef\pr@cleanup{\the\toks@}%
673 \setbox\pr@box\vbox\bgroup
675 \pr@outerfalse\@arrayparboxrestore
676 \let\insert\pr@insert
679 \expandafter\expandafter\expandafter
681 \expandafter\@firstofone
683 \expandafter \@gobble
688 % \begin{macro}{\pr@endbox}
689 % Cleaning up also is straightforward. If we have to watch the
690 % bounding \TeX\ box, we want to remove spurious skips. We also
691 % want to unwrap a possible single line paragraph, so that the box
692 % is not full line length. We use \cmd{\vsplit} to clean up leading
693 % glue and stuff, and we make some attempt of removing trailing
694 % ones. After that, we wrap up the box including possible material
695 % from \cmd{\AtBeginDvi}. If the |psfixbb| option is active, we
696 % adorn the upper left and lower right corners with copies of
697 % \cmd{\pr@markerbox}. The first few lines cater for \LaTeX\ hiding
698 % things like like the code for \cmd{\paragraph} in \cmd{\everypar}.
701 \let\reserved@a\relax
702 \ifvmode \edef\reserved@a{\the\everypar}%
703 \ifx\reserved@a\@empty\else
706 \setbox\z@\lastbox\unskip\unpenalty
708 \setbox\z@\hbox\bgroup\penalty-\maxdimen\unhbox\z@
709 \ifnum\lastpenalty=-\maxdimen\egroup
710 \else\egroup\box\z@ \fi\fi\fi
711 \ifhmode \par\unskip\setbox\z@\lastbox
712 \nointerlineskip\hbox{\unhbox\z@\/}%
713 \else \unskip\unpenalty\unskip \fi
715 \setbox\pr@box\vbox{%
716 \baselineskip\z@skip \lineskip\z@skip \lineskiplimit\z@
719 \splittopskip\z@skip\setbox\z@\vsplit\pr@box to\z@
727 % \begin{macro}{\pr@ship@end}
728 % \label{sec:prshipend}At this point, \cmd{\pr@ship@end} gets
729 % called. You must not under any circumstances change |\box\pr@box|
730 % in any way that would add typeset material at the front of it,
731 % except for PostScript header specials, since the front of
732 % |\box\pr@box| may contain stuff from \cmd{\AtBeginDvi}.
733 % \cmd{\pr@ship@end} contains two types of code additions: stuff
734 % that adds to |\box\pr@box|, like the |labels| option does, and
735 % stuff that measures out things or otherwise takes a look at the
736 % finished |\box\pr@box|, like the |auctex| or |showbox| option do.
737 % The former should use \cmd{pr@addto@front} for adding to this
738 % hook, the latter use \cmd{g@addto@macro} for adding at the end of
741 % Note that we shift the output box up by its height via
742 % \cmd{\voffset}. This has three reasons: first we make sure that
743 % no package-inflicted non-zero value of \cmd{\voffset} or
744 % \cmd{\hoffset} will have any influence on the positioning of our
745 % box. Second we shift the box such that its basepoint will exactly
746 % be at the (1in,1in)~mark defined by \TeX. That way we can
747 % properly take ascenders into account. And the third reason is
748 % that \TeX\ treats a \cmd{\hbox} and a \cmd{\vbox} differently with
749 % regard to the treating of its depth. Shifting \cmd{\voffset} and
750 % \cmd{\hoffset} can be inhibited by setting |\pr@offset@override|.
753 {\let\protect\noexpand
754 \ifx\pr@offset@override\@undefined
765 \llap{\raise\@tempdima\copy\pr@markerbox\kern\dimen@}%
766 \lower\@tempdimb\copy\pr@markerbox}%
767 \else \box\pr@box \fi}%
768 \global\advance\pr@snippet\@ne
774 % Oh, and we kill off the usual meaning of \cmd{\shipout} in case
775 % somebody makes a special output routine. The following test is
776 % pretty much the same as in |everyshi.sty|. One of its implications
777 % is that if someone does a \cmd{\shipout} of a \emph{void} box,
778 % things will go horribly wrong.
779 % \begin{macro}{\shipout}
781 \let\pr@shipout=\shipout
782 \def\shipout{\deadcycles\z@\bgroup\setbox\z@\box\voidb@x
783 \afterassignment\pr@shipoutegroup\setbox\z@}
784 \def\pr@shipoutegroup{\ifvoid\z@ \expandafter\aftergroup\fi \egroup}
787 % \subsection{Parsing commands}
788 % \begin{macro}{\pr@parseit}
789 % \begin{macro}{\pr@endparse}
790 % \begin{macro}{\pr@callafter}
791 % The following stuff is for parsing the arguments of commands we
792 % want to somehow surround with stuff. Usage is
794 % \cmd{\pr@callafter}\meta{aftertoken}\meta{parsestring}\cmd{\pr@endparse}\\
795 % \qquad\meta{macro}\meta{parameters}
797 % \meta{aftertoken} is stored away and gets executed once parsing
798 % completes, with its first argument being the parsed material.
799 % \meta{parsestring} would be, for example for the
800 % \cmd{\includegraphics} macro, |*[[!|, an optional |*| argument
801 % followed by two optional arguments enclosed in |[]|, followed by
802 % one mandatory argument.
804 % For the sake of a somewhat more intuitive syntax, we now support
805 % also the syntax |{*[]{}}| in the optional argument. Since \TeX\
806 % strips redundant braces, we have to write |[{{}}]| in this syntax
807 % for a single mandatory argument. Hard to avoid. We use an
808 % unusual character for ending the parsing. The implementation is
811 \def\pr@parseit#1{\csname pr@parse#1\endcsname}
812 \let\pr@endparse=\@percentchar
815 \afterassignment\pr@parseit
817 \expandafter\next\csname pr@parse\pr@endparse\endcsname
822 % \begin{macro}{\pr@parse*}
823 % Straightforward, same mechanism \LaTeX\ itself employs. We take
824 % some care not to pass potential |#| tokens unprotected through
827 \long\expandafter\def\csname pr@parse*\endcsname#1\pr@endparse#2{%
828 \begingroup\toks@{#1\pr@endparse{#2}}%
829 \edef\next##1{\endgroup##1\the\toks@}%
830 \@ifstar{\next{\pr@parse@*}}{\next\pr@parseit}}
833 % \begin{macro}{\pr@parse[}
834 % \begin{macro}{\pr@brace}
835 % Copies optional parameters in brackets if present. The additional
836 % level of braces is necessary to ensure that braces the user might
837 % have put to hide a~|]| bracket in an optional argument don't get
838 % lost. There will be no harm if such braces were not there at the
841 \long\expandafter\def\csname pr@parse[\endcsname#1\pr@endparse#2{%
842 \begingroup\toks@{#1\pr@endparse{#2}}%
843 \edef\next##1{\endgroup##1\the\toks@}%
844 \@ifnextchar[{\next\pr@bracket}{\next\pr@parseit}}
845 \long\def\pr@bracket#1\pr@endparse#2[#3]{%
846 \pr@parseit#1\pr@endparse{#2[{#3}]}}
850 % \begin{macro}{\pr@parse]}
851 % This is basically a do-nothing, so that we may use the syntax
852 % |{*[][]!}| in the optional argument instead of the more concise
853 % but ugly |*[[!| which confuses the brace matchers of editors.
855 \expandafter\let\csname pr@parse]\endcsname=\pr@parseit
858 % \begin{macro}{\pr@parse}
859 % \begin{macro}{\pr@parse!}
860 % Mandatory arguments are perhaps easiest to parse.
862 \long\def\pr@parse#1\pr@endparse#2#3{%
863 \pr@parseit#1\pr@endparse{#2{#3}}}
864 \expandafter\let\csname pr@parse!\endcsname=\pr@parse
868 % \begin{macro}{\pr@parse?}
869 % \begin{macro}{\pr@parsecond}
870 % This does an explicit call of |\@ifnextchar| and forks into the
871 % given two alternatives as a result.
873 \long\expandafter\def\csname pr@parse?\endcsname#1#2\pr@endparse#3{%
874 \begingroup\toks@{#2\pr@endparse{#3}}%
875 \@ifnextchar#1{\pr@parsecond\@firstoftwo}%
876 {\pr@parsecond\@secondoftwo}}
877 \def\pr@parsecond#1{\expandafter\endgroup
878 \expandafter\expandafter\expandafter\pr@parseit
879 \expandafter#1\the\toks@}
883 % \begin{macro}{\pr@parse@}
884 % This makes it possible to insert literal material into the
887 \long\def\pr@parse@#1#2\pr@endparse#3{%
888 \pr@parseit #2\pr@endparse{#3#1}}
891 % \begin{macro}{\pr@parse-}
892 % This will just drop the next token.
894 \long\expandafter\def\csname pr@parse-\endcsname
895 #1\pr@endparse#2{\begingroup
896 \toks@{\endgroup\pr@parseit #1\pr@endparse{#2}}%
897 {\aftergroup\the\aftergroup\toks@ \afterassignment}%
901 % \begin{macro}{\pr@parse:}
902 % The following is a transform rule. A macro is being defined with
903 % the given argument list and replacement, and the transformed
904 % version replaces the original. The result of the transform is
905 % still subject to being parsed.
907 \long\expandafter\def\csname pr@parse:\endcsname
908 #1#2#3\pr@endparse#4{\begingroup
909 \toks@{\endgroup \pr@parseit#3\pr@endparse{#4}}%
910 \long\def\next#1{#2}%
911 \the\expandafter\toks@\next}
914 % \edef\next{\noexpand\begin{macro}{\noexpand
915 % \pr@parse\string#}}
917 % Another transform rule, but this passes the transformed material
918 % into the token list.
920 \long\expandafter\def\csname pr@parse#\endcsname
921 #1#2#3\pr@endparse#4{\begingroup
923 \long\edef\next##1{\toks@{\the\toks@##1}}%
924 \toks@{\endgroup \pr@parseit#3\pr@endparse}%
925 \long\def\reserved@a#1{{#2}}%
926 \the\expandafter\next\reserved@a}
931 % \subsection{Selection options}
932 % The |displaymath| option. The |equation| environments in AMS\LaTeX\
933 % already do too much before our hook gets to interfere, so we hook
934 % earlier. Some juggling is involved to ensure we get the original
935 % |\everydisplay| tokens only once and where appropriate.
937 % The incredible hack with |\dt@ptrue| is necessary for working around
938 % bug `amslatex/3425'.
943 \@firstofone{\endgroup
944 \DeclareOption{displaymath}{%
945 \preview@delay{\toks@{%
946 \pr@startbox{\noindent$$%
947 \aftergroup\pr@endbox\@gobbletwo}{$$}\@firstofone}%
948 \everydisplay\expandafter{\the\expandafter\toks@
949 \expandafter{\the\everydisplay}}}%
950 \pr@advise@ship\equation{\begingroup\aftergroup\pr@endbox
951 \def\dt@ptrue{\m@ne=\m@ne}\noindent}%
953 \pr@advise@ship\equation*{\begingroup\aftergroup\pr@endbox
954 \def\dt@ptrue{\m@ne=\m@ne}\noindent}%
956 \PreviewOpen[][\def\dt@ptrue{\m@ne=\m@ne}\noindent#1]\[%
958 \PreviewEnvironment[][\noindent#1]{eqnarray}%
959 \PreviewEnvironment[][\noindent#1]{eqnarray*}%
960 \PreviewEnvironment{displaymath}%
964 % The |textmath| option. Some folderol in order to define the active
966 % math mode delimiter. \cmd\pr@textmathcheck is used for checking
967 % whether we have a single |$| or double |$$|.
968 % In the latter case, we enter display math (this sort of display math
969 % is not allowed inside of \LaTeX\ because of inconsistent spacing,
970 % but surprisingly many people use it nevertheless). Strictly
971 % speaking, this is incorrect, since not every
972 % |$$| actually means display math. For example, |\hbox{$$}| will
973 % because of restricted horizontal mode rather yield an empty text
974 % math formula. Since our implementation moved the sequence inside of
975 % a |\vbox|, the interpretation will change. People should just not
976 % enter rubbish like that.
981 \DeclareOption{textmath}{%
982 \PreviewEnvironment{math}%
983 \preview@delay{\ifx#1\@undefined \let#1=$%$
984 \fi\catcode`\$=\active
985 \ifx\xyreuncatcodes\@undefined\else
986 \edef\next{\catcode`@=\the\catcode`@\relax}%
987 \makeatother\expandafter\xyreuncatcodes\next\fi}%
988 \pr@advise@ship\(\pr@endaftergroup{}% \)
989 \pr@advise@ship#1{\@firstoftwo{\let#1=#2%
990 \futurelet\reserved@a\pr@textmathcheck}}{}}%
991 \def\pr@textmathcheck{\expandafter\pr@endaftergroup
992 \ifx\reserved@a#1{#2#2}\expandafter\@gobbletwo\fi#2}}
994 \lowercase{\expandafter\next\expandafter~}%
995 \csname pr@\string$%$
999 % \begin{macro}{\pr@endaftergroup}
1000 % This justs ends the box after the group opened by |#1| is closed
1004 \def\pr@endaftergroup#1{#1\aftergroup\pr@endbox}
1009 % The |graphics| option.
1012 \DeclareOption{graphics}{%
1013 \PreviewMacro[*[[!]{\includegraphics}%]]
1016 % The |floats| option. The complications here are merely to spare us
1017 % bug reports about broken document classes that use |\let| on
1018 % |\endfigure| and similar. Notable culprits that have not been
1019 % changed in years in spite of reports are |elsart.cls| and
1020 % |IEEEtran.cls|. Complain when you are concerned.
1022 \def\pr@floatfix#1#2{\ifx#1#2%
1023 \ifx#1\@undefined\else
1024 \PackageWarningNoLine{preview}{%
1025 Your document class has a bad definition^^J
1026 of \string#1, most likely^^J
1027 \string\let\string#1=\string#2^^J
1028 which has now been changed to^^J
1029 \string\def\string#1{\string#2}^^J
1030 because otherwise subsequent changes to \string#2^^J
1031 (like done by several packages changing float behaviour)^^J
1032 can't take effect on \string#1.^^J
1033 Please complain to your document class author}%
1036 \def\next#1#2{\endgroup
1037 \DeclareOption{floats}{%
1038 \pr@floatfix\endfigure\end@float
1039 \pr@floatfix\endtable\end@float
1040 \pr@floatfix#1\end@dblfloat
1041 \pr@floatfix#2\end@dblfloat
1042 \PreviewSnarfEnvironment[![]{@float}%]
1043 \PreviewSnarfEnvironment[![]{@dblfloat}%]
1045 \expandafter\next\csname endfigure*\expandafter\endcsname
1046 \csname endtable*\endcsname
1048 % The |sections| option. Two optional parameters might occur in
1051 \DeclareOption{sections}{%
1052 \PreviewMacro[!!!!!!*[[!]{\@startsection}%]]
1053 \PreviewMacro[*[[!]{\chapter}%]]
1056 % We now interpret any further options as driver files we load. Note
1057 % that these driver files are loaded even when |preview| is not
1058 % active. The reason is that they might define commands (like
1059 % \cmd{\PreviewCommand}) that should be available even in case of an
1060 % inactive package. Large parts of the |preview| package will not
1061 % have been loaded in this case: you have to cater for that.
1064 {\InputIfFileExists{pr\CurrentOption.def}{}{\OptionNotUsed}}
1067 % \subsection{Preview attaching commands}
1068 % \begin{macro}{\PreviewMacro}
1069 % As explained above. Detect possible |*| and call appropriate
1072 \def\PreviewMacro{\@ifstar\pr@starmacro\pr@macro}
1074 % The version without |*| is now rather straightforward.
1075 % \begin{macro}{\pr@macro}
1076 % \begin{macro}{\pr@domacro}
1077 % \begin{macro}{\pr@macroii}
1078 % \begin{macro}{\pr@endmacro}
1080 \long\def\pr@domacro#1#2{%
1081 \long\def\next##1{#2}%
1082 \pr@callafter\next#1]\pr@endparse}
1083 \newcommand\pr@macro[1][]{%
1084 \toks@{\pr@domacro{#1}}%
1085 \long\edef\next[##1]##2{%
1086 \noexpand\pr@advise@ship{##2}{\the\toks@{##1\noexpand\pr@endbox}}{}}%
1087 \@ifnextchar[\next\pr@macroii}
1088 \def\pr@macroii{\next[##1]}
1089 \long\def\pr@endmacro#1{#1\pr@endbox}
1096 % \begin{macro}{PreviewMacro*}
1097 % \begin{macro}{\pr@protect@domacro}
1098 % \begin{macro}{\pr@starmacro}
1099 % The version with |*| has to parse the arguments, then throw them
1100 % away. Some internal macros first, then the interface call.
1102 \long\def\pr@protect@domacro#1#2{\pr@protect{%
1103 \long\def\next##1{#2}%
1104 \pr@callafter\next#1]\pr@endparse}}
1105 \newcommand\pr@starmacro[1][]{\toks@{\pr@protect@domacro{#1}}%
1106 \long\edef\next[##1]##2{%
1107 \noexpand\pr@advise##2{\the\toks@{##1}}}%
1108 \@ifnextchar[\next{\next[]}}
1113 % \begin{macro}{\PreviewOpen}
1114 % As explained above. Detect possible |*| and call appropriate macro.
1116 \def\PreviewOpen{\@ifstar\pr@starmacro\pr@open}
1118 % The version without |*| is now rather straightforward.
1119 % \begin{macro}{\pr@open}
1121 \newcommand\pr@open[1][]{%
1122 \toks@{\pr@domacro{#1}}%
1123 \long\edef\next[##1]##2{%
1124 \noexpand\pr@advise##2{\begingroup
1125 \noexpand\pr@protect@ship
1126 {\the\toks@{\begingroup\aftergroup\noexpand\pr@endbox##1}}%
1128 \@ifnextchar[\next\pr@macroii}
1132 % \begin{macro}{\PreviewClose}
1133 % As explained above. Detect possible |*| and call appropriate
1136 \def\PreviewClose{\@ifstar\pr@starmacro\pr@close}
1138 % The version without |*| is now rather straightforward.
1139 % \begin{macro}{\pr@close}
1141 \newcommand\pr@close[1][]{%
1142 \toks@{\pr@domacro{#1}}%
1143 \long\edef\next[##1]##2{%
1144 \noexpand\pr@advise{##2}{\the\toks@{##1\endgroup}}}%
1145 \@ifnextchar[\next\pr@macroii}
1149 % \begin{macro}{\PreviewEnvironment}
1150 % Actually, this ignores any syntax argument. But don't tell
1151 % anybody. Except for the |*|~variant, it respects (actually
1152 % ignores) any argument! Of course, we'll need to deactivate
1153 % |\end{|\meta{environment}|}| as well.
1155 \def\PreviewEnvironment{\@ifstar\pr@starenv\pr@env}
1156 \newcommand\pr@starenv[1][]{\toks@{\pr@starmacro[{#1}]}%
1157 \long\edef\next##1##2{%
1158 \the\toks@[{##2}]##1}%
1159 \begingroup\pr@starenvii}
1160 \newcommand\pr@starenvii[2][]{\endgroup
1161 \expandafter\next\csname#2\endcsname{#1}%
1162 \expandafter\pr@starmacro\csname end#2\endcsname}
1163 \newcommand\pr@env[1][]{%
1164 \toks@{\pr@domacro{#1}}%
1165 \long\edef\next[##1]##2{%
1166 \noexpand\expandafter\noexpand\pr@advise@ship
1167 \noexpand\csname##2\noexpand\endcsname{\the\toks@
1168 {\begingroup\aftergroup\noexpand\pr@endbox##1}}{\endgroup}}%
1169 \@ifnextchar[\next\pr@macroii %]
1173 % \begin{macro}{\PreviewSnarfEnvironment}
1174 % This is a nuisance since we have to advise \emph{both} the
1175 % environment and its end.
1177 \newcommand{\PreviewSnarfEnvironment}[2][]{%
1178 \expandafter\pr@advise
1179 \csname #2\endcsname{\pr@snarfafter{#1}}%
1180 \expandafter\pr@advise
1181 \csname end#2\endcsname{\pr@endsnarf}}
1185 % \begin{macro}{\pr@snarfafter}
1186 % \begin{macro}{\pr@startsnarf}
1187 % \begin{macro}{\pr@endsnarf}
1188 % Ok, this looks complicated, but we have to start a group in order
1189 % to be able to hook \cmd{\pr@endbox} into the game only when
1190 % \cmd{\ifpr@outer} has triggered the start. And we need to get our
1191 % start messages out before parsing the arguments.
1194 \let\pr@endsnarf\relax
1195 \long\def\pr@snarfafter#1{\ifpr@outer
1197 \let\pr@ship@start\relax
1198 \let\pr@endsnarf\endgroup
1200 \let\pr@endsnarf\relax
1202 \pr@protect{\pr@callafter\pr@startsnarf#1]\pr@endparse}}
1203 \def\pr@startsnarf#1{#1\begingroup
1204 \pr@startbox{\begingroup\aftergroup\pr@endbox}{\endgroup}%
1211 % \begin{macro}{\pr@ship@start}
1212 % \begin{macro}{\pr@ship@end}
1213 % The hooks \cmd{\pr@ship@start} and \cmd{\pr@ship@end} can be added
1214 % to by option files by the help of the \cmd{\g@addto@macro} command
1215 % from \LaTeX, and by the \cmd{\pr@addto@front} command from
1216 % |preview.sty| itself. They are called just before starting to
1217 % process some preview, and just after it. Here is the policy for
1218 % adding to them: \cmd{\pr@ship@start} is called inside of the vbox
1219 % |\pr@box| before typeset material gets produced. It is, however,
1220 % preceded by a break command that is intended for usage in
1221 % \cmd{\vsplit}, so that any following glue might disappear. In
1222 % case you want to add any material on the list, you have to precede
1223 % it with \cmd{\unpenalty} and have to follow it with \cmd{\break}.
1224 % You have make sure that under no circumstances any other legal
1225 % breakpoints appear before that, and your material should
1226 % contribute no nonzero dimensions to the page. For the policies of
1227 % the \cmd{\pr@ship@end} hook, see the description on
1228 % page~\pageref{sec:prshipend}.
1231 \let\pr@ship@start\@empty
1232 \let\pr@ship@end\@empty
1236 % \begin{environment}{preview}
1237 % \begin{environment}{nopreview}
1238 % First we write the definitions of these environments when
1239 % |preview| is inactive. We will redefine them if |preview| gets
1242 \newenvironment{preview}{\ignorespaces}{\ifhmode\unskip\fi}
1243 \newenvironment{nopreview}{\ignorespaces}{\ifhmode\unskip\fi}
1248 % We now process the options and finish in case we are not active.
1250 \ProcessOptions\relax
1251 \ifPreview\else\expandafter\endinput\fi
1254 % Now for the redefinition of the |preview| and |endpreview|
1258 \renewenvironment{preview}{\begingroup
1259 \pr@startbox{\begingroup\aftergroup\pr@endbox}%
1262 {\ifhmode\unskip\fi\endgroup}
1263 \renewenvironment{nopreview}{\pr@outerfalse\ignorespaces}%
1264 {\ifhmode\unskip\fi}
1266 % We use the normal output routine, but hijack it a bit for our
1267 % purposes to preserve \cmd{\AtBeginDvi} hooks and not get previews
1268 % while in output: that could become rather ugly.
1270 % The main work of disabling normal output relies on a \cmd{\shipout}
1272 % \begin{macro}{\pr@output}
1278 \let\@begindvi\@empty
1280 \let\output\pr@output
1283 % \begin{macro}{\pr@typeinfos}
1284 % Then we have some document info that style files might want to
1287 \def\pr@typeinfos{\typeout{Preview: Fontsize \f@size pt}%
1288 \ifnum\mag=\@m\else\typeout{Preview: Magnification \number\mag}\fi
1289 \ifx\pdfoutput\@undefined
1290 \ifx\XeTeXversion\@undefined \else
1291 % FIXME: The message should not be emitted if XeTeX does not produce
1292 % PDF. There does not seem to be a primitive for that, though.
1293 \typeout{Preview: PDFoutput 1}%
1296 \ifx\pdfoutput\relax \else
1297 \ifnum\pdfoutput>\z@
1298 \typeout{Preview: PDFoutput 1}%
1303 \AtBeginDocument{\pr@typeinfos}
1306 % And at the end we load the default configuration file, so that it
1307 % may override settings from this package:
1309 \pr@loadcfg{prdefault}
1314 % \section{The option files}
1315 % \subsection{The \texttt{auctex} option}
1316 % The AUC\TeX\ option will cause error messages to spew. We want them
1317 % on the terminal, but we don't want \LaTeX\ to stop its automated
1318 % run. We delay \cmd{\nonstopmode} in case the user has any
1319 % pseudo-interactive folderol like reading in of file names in his
1320 % preamble. Because we are so good-hearted, we will not break this as
1321 % long as the document has not started, but after that we need the
1322 % error message mechanism operative.
1324 % The |\nofiles| command here tries to avoid clobbering input files
1325 % used for references and similar. It will come too late if you call
1326 % the package with \cmd{\AtBeginDocument}, so you'll need to issue
1327 % |\nofiles| yourself in that case. Previously, this was done
1328 % unconditionally in the main style file, but since we don't know what
1329 % the package may be used for, this was inappropriate.
1331 % So here is the contents of the |prauctex.def| file:
1333 %<auctex>\ifPreview\else\expandafter\endinput\fi
1335 %<auctex>\preview@delay{\nonstopmode}
1337 % Ok, here comes creative error message formatting. It turns out a
1338 % sizable portion of the runtime is spent in I/O. Making the error
1339 % messages short is an advantage. It is not possible to convince
1340 % \TeX\ to make shorter error messages than this: \TeX\ always wants
1341 % to include context. This is about the shortest \ae sthetic one we
1344 %<auctex>\begingroup
1345 %<auctex>\lccode`\~=`\-
1346 %<auctex>\lccode`\{=`\<
1347 %<auctex>\lccode`\}=`\>
1348 %<auctex>\lowercase{\endgroup
1349 %<auctex> \def\pr@msgi{{~}}}
1350 %<auctex>\def\pr@msgii{Preview:
1351 %<auctex> Snippet \number\pr@snippet\space}
1352 %<auctex>\begingroup
1353 %<auctex>\catcode`\-=13
1354 %<auctex>\catcode`\<=13
1355 %<auctex>\@firstofone{\endgroup
1356 %<auctex>\def\pr@msg#1{{%
1357 %<auctex> \let<\pr@msgi
1358 %<auctex> \def-{\pr@msgii#1}%
1359 %<auctex> \errhelp{Not a real error.}%
1360 %<auctex> \errmessage<}}}
1361 %<auctex>\g@addto@macro\pr@ship@start{\pr@msg{started}}
1362 %<auctex>\g@addto@macro\pr@ship@end{\pr@msg{ended.%
1363 %<auctex> (\number\ht\pr@box+\number\dp\pr@box x\number\wd\pr@box)}}
1365 % This looks pretty baffling, but it produces something short and
1366 % semi-graphical, namely |<-><->|. That is a macro |<| that expands
1367 % into |<->|, where |<| and |>| are the braces around an
1368 % \cmd{\errmessage} argument and |-| is a macro expanding to the full
1369 % text of the error message. Cough cough. You did not really want to
1372 % Since over/underfull boxes are about the messiest things to parse,
1373 % we disable them by setting the appropriate badness limits and making
1374 % the variables point to junk. We also disable other stuff. While we
1375 % set \cmd{\showboxbreadth} and \cmd{\showboxdepth} to indicate as
1376 % little diagnostic output as possible, we keep them operative, so
1377 % that the user retains the option of debugging using this stuff. The
1378 % other variables concerning the generation of warnings and
1379 % daignostics, however, are more often set by commonly employed
1380 % packages and macros such as \cmd{\sloppy}. So we kill them off for
1383 %<auctex>\hbadness=\maxdimen
1384 %<auctex>\newcount\hbadness
1385 %<auctex>\vbadness=\maxdimen
1386 %<auctex>\let\vbadness=\hbadness
1387 %<auctex>\hfuzz=\maxdimen
1388 %<auctex>\newdimen\hfuzz
1389 %<auctex>\vfuzz=\maxdimen
1390 %<auctex>\let\vfuzz=\hfuzz
1391 %<auctex>\showboxdepth=-1
1392 %<auctex>\showboxbreadth=-1
1394 % Ok, now we load a possible configuration file.
1396 %<auctex>\pr@loadcfg{prauctex}
1398 % And here we cater for several frequently used commands in
1401 %<auccfg>\PreviewMacro*[[][#1{}]\footnote
1402 %<auccfg>\PreviewMacro*[?[{@{[]}}{}][#1]\item
1403 %<auccfg>\PreviewMacro*\emph
1404 %<auccfg>\PreviewMacro*\textrm
1405 %<auccfg>\PreviewMacro*\textit
1406 %<auccfg>\PreviewMacro*\textsc
1407 %<auccfg>\PreviewMacro*\textsf
1408 %<auccfg>\PreviewMacro*\textsl
1409 %<auccfg>\PreviewMacro*\texttt
1410 %<auccfg>\PreviewMacro*\textcolor
1411 %<auccfg>\PreviewMacro*\mbox
1412 %<auccfg>\PreviewMacro*[][#1{}]\author
1413 %<auccfg>\PreviewMacro*[][#1{}]\title
1414 %<auccfg>\PreviewMacro*\and
1415 %<auccfg>\PreviewMacro*\thanks
1416 %<auccfg>\PreviewMacro*[][#1{}]\caption
1417 %<auccfg>\preview@delay{\@ifundefined{pr@\string\@startsection}{%
1418 %<auccfg> \PreviewMacro*[!!!!!!*][#1{}]\@startsection}{}}
1419 %<auccfg>\preview@delay{\@ifundefined{pr@\string\chapter}{%
1420 %<auccfg> \PreviewMacro*[*][#1{}]\chapter}{}}
1421 %<auccfg>\PreviewMacro*\index
1424 % \subsection{The \texttt{lyx} option}
1425 % The following is the option providing LyX with info for its preview
1428 %<lyx>\ifPreview\else\expandafter\endinput\fi
1429 %<lyx>\pr@loadcfg{prlyx}
1430 %<lyx>\g@addto@macro\pr@ship@end{\typeout{Preview:
1431 %<lyx> Snippet \number\pr@snippet\space
1432 %<lyx> \number\ht\pr@box\space \number\dp\pr@box \space\number\wd\pr@box}}
1435 % \subsection{The \texttt{counters} option}
1436 % This outputs a checkpoint. We do this by saving all counter
1437 % registers in backup macros starting with |\pr@c@| in their name. A
1438 % checkpoint first writes out all changed counters (previously
1439 % unchecked counters are not written out unless different from zero),
1440 % then saves all involved counter values. \LaTeX\ tracks its counters
1441 % in the global variable \cmd{\cl@ckpt}.
1443 %<counters>\ifPreview\else\expandafter\endinput\fi
1444 %<counters>\def\pr@eltprint#1{\expandafter\@gobble\ifnum\value{#1}=0%
1445 %<counters> \csname pr@c@#1\endcsname\else\relax
1446 %<counters> \space{#1}{\arabic{#1}}\fi}
1447 %<counters>\def\pr@eltdef#1{\expandafter\xdef
1448 %<counters> \csname pr@c@#1\endcsname{\arabic{#1}}}
1449 %<counters>\def\pr@ckpt#1{{\let\@elt\pr@eltprint\edef\next{\cl@@ckpt}%
1450 %<counters> \ifx\next\@empty\else\typeout{Preview: Counters\next#1}%
1451 %<counters> \let\@elt\pr@eltdef\cl@@ckpt\fi}}
1452 %<counters>\pr@addto@front\pr@ship@start{\pr@ckpt:}
1453 %<counters>\pr@addto@front\pr@ship@end{\pr@ckpt.}
1456 % \subsection{Debugging options}
1457 % Those are for debugging the operation of |preview|, and thus are
1458 % mostly of interest for people that want to use |preview| for their
1459 % own purposes. Since debugging output is potentially confusing to
1460 % the error message parsing from AUC\TeX, you should not turn on
1461 % |\tracingonline| or switch from |\nonstopmode| unless you are
1462 % certain your package will never be used with \previewlatex.
1464 % \paragraph{The \texttt{showbox} option} will generate diagnostic
1465 % output for every produced box. It does not delay the resetting of
1466 % the |\showboxbreadth| and |\showboxdepth| parameters so that you can
1467 % still change them after the loading of the package. It does,
1468 % however, move them to the end of the package loading, so that they
1469 % will not be affected by the |auctex| option.
1471 %<showbox>\ifPreview\else\expandafter\endinput\fi
1472 %<showbox>\AtEndOfPackage{%
1473 %<showbox> \showboxbreadth\maxdimen
1474 %<showbox> \showboxdepth\maxdimen}
1475 %<showbox>\g@addto@macro\pr@ship@end{\showbox\pr@box}
1478 % \paragraph{The \texttt{tracingall} option} is for the really heavy
1479 % diagnostic stuff. For the reasons mentioned above, we do not want
1480 % to change the setting of the interaction mode, nor of the
1481 % |tracingonline| flag. If the user wants them different, he should
1482 % set them outside of the preview boxes.
1484 %<tracingall>\ifPreview\else\expandafter\endinput\fi
1485 %<tracingall>\pr@addto@front\pr@ship@start{\let\tracingonline\count@
1486 %<tracingall> \let\errorstopmode\@empty\tracingall}
1489 % \subsection{Supporting conversions}
1490 % It is not uncommon to want to use the results of |preview| as
1491 % images. One possibility is to generate a flurry of EPS files with
1493 % |dvips -E -i -Ppdf -o| \meta{outputfile}|.000| \meta{inputfile}
1495 % However, in case those are to be processed further into graphic
1496 % image files by Ghostscript, this process is inefficient. One cannot
1497 % use Ghostscript in a single run for generating the files, however,
1498 % since one needs to set the page size (or full size pages will be
1499 % produced). The |tightpage| option will set the page dimensions at
1500 % the start of each PostScript page so that the output will be sized
1501 % appropriately. That way, a single pass of Dvips followed by a
1502 % single pass of Ghostscript will be sufficient for generating all
1505 % You will have to specify the output driver to be used, either
1506 % |dvips| or |pdftex|.
1508 % \begin{macro}{\PreviewBorder}
1509 % \begin{macro}{\PreviewBbAdjust}
1510 % We start this off with the user tunable parameters which get
1511 % defined even in the case of an inactive package, so that
1512 % redefinitions and assignments to them will always work:
1514 %<tightpage>\ifx\PreviewBorder\@undefined
1515 %<tightpage> \newdimen\PreviewBorder
1516 %<tightpage> \PreviewBorder=0.50001bp
1518 %<tightpage>\ifx\PreviewBbAdjust\@undefined
1519 %<tightpage> \def\PreviewBbAdjust{-\PreviewBorder -\PreviewBorder
1520 %<tightpage> \PreviewBorder \PreviewBorder}
1525 % Here is stuff used for parsing this:
1527 %<tightpage>\ifPreview\else\expandafter\endinput\fi
1528 %<tightpage>\def\pr@nextbb{\edef\next{\next\space\number\dimen@}%
1529 %<tightpage> \expandafter\xdef\csname pr@bb@%
1530 %<tightpage> \romannumeral\count@\endcsname{\the\dimen@}%
1531 %<tightpage> \advance\count@\@ne\ifnum\count@<5
1532 %<tightpage> \afterassignment\pr@nextbb\dimen@=\fi}
1534 % And here is the stuff that we fudge into our hook. Of course, we
1535 % have to do it in a box, and we start this box off with our special.
1536 % There is one small consideration here: it might come before any
1537 % |\AtBeginDvi| stuff containing header specials. It turns out Dvips
1538 % rearranges this amicably: header code specials get transferred to
1539 % the appropriate header section, anyhow, so this ensures that we come
1540 % right after the bop section. We insert the 7~numbers here: the
1541 % 4~bounding box adjustments, and the 3~\TeX\ box dimensions. In case
1542 % the box adjustments have changed since the last time, we write them
1543 % out to the console.
1545 %<tightpage>\ifnum\pr@graphicstype=\z@
1546 %<tightpage> \ifcase
1547 %<tightpage> \ifx\XeTeXversion\@undefined
1548 %<tightpage> \ifx\pdfoutput\@undefined \@ne\fi
1549 %<tightpage> \ifx\pdfoutput\relax \@ne\fi
1550 %<tightpage> \ifnum\pdfoutput>\z@ \tw@\fi \@ne
1551 %<tightpage> \else \thr@@\fi
1552 %<tightpage> \or \ExecuteOptions{dvips}\relax
1553 %<tightpage> \or \ExecuteOptions{pdftex}\relax
1554 %<tightpage> \or \ExecuteOptions{xetex}\relax\fi\fi
1555 %<tightpage>\global\let\pr@bbadjust\@empty
1556 %<tightpage>\pr@addto@front\pr@ship@end{\begingroup
1557 %<tightpage> \let\next\@gobble
1558 %<tightpage> \count@\@ne\afterassignment\pr@nextbb
1559 %<tightpage> \dimen@\PreviewBbAdjust
1560 %<tightpage> \ifx\pr@bbadjust\next
1561 %<tightpage> \else \global\let\pr@bbadjust\next
1562 %<tightpage> \typeout{Preview: Tightpage \pr@bbadjust}%
1563 %<tightpage> \fi\endgroup}
1564 %<tightpage>\ifcase\pr@graphicstype
1566 %<tightpage> \g@addto@macro\pr@ship@end{\setbox\pr@box\hbox{%
1567 %<tightpage> \special{ps::\pr@bbadjust\space
1568 %<tightpage> \number\ifdim\ht\pr@box>\z@ \ht\pr@box
1569 %<tightpage> \else \z@
1570 %<tightpage> \fi \space
1571 %<tightpage> \number\ifdim\dp\pr@box>\z@ \dp\pr@box
1572 %<tightpage> \else \z@
1573 %<tightpage> \fi \space
1574 %<tightpage> \number\ifdim\wd\pr@box>\z@ \wd\pr@box
1575 %<tightpage> \else \z@
1576 %<tightpage> \fi}\box\pr@box}}
1578 %<tightpage> \g@addto@macro\pr@ship@end{{\dimen@\ht\pr@box
1579 %<tightpage> \ifdim\dimen@<\z@ \dimen@\z@\fi
1580 %<tightpage> \advance\dimen@\pr@bb@iv
1581 %<tightpage> \dimen@ii=\dimen@
1582 %<tightpage> \global\pdfvorigin\dimen@
1583 %<tightpage> \dimen@\dp\pr@box
1584 %<tightpage> \ifdim\dimen@<\z@ \dimen@\z@\fi
1585 %<tightpage> \advance\dimen@-\pr@bb@ii
1586 %<tightpage> \advance\dimen@\dimen@ii
1587 %<tightpage> \global\pdfpageheight\dimen@
1588 %<tightpage> \dimen@\wd\pr@box
1589 %<tightpage> \ifdim\dimen@<\z@ \dimen@=\z@\fi
1590 %<tightpage> \advance\dimen@-\pr@bb@i
1591 %<tightpage> \advance\dimen@\pr@bb@iii
1592 %<tightpage> \global\pdfpagewidth\dimen@
1593 %<tightpage> \global\pdfhorigin-\pr@bb@i}}
1595 %<tightpage> \g@addto@macro\pr@ship@end{\dimen@\ht\pr@box
1596 %<tightpage> \ifdim\dimen@<\z@ \dimen@\z@\fi
1597 %<tightpage> \advance\dimen@\pr@bb@iv
1598 %<tightpage> \dimen@ii=\dimen@
1599 %<tightpage> \voffset=-1in
1600 %<tightpage> \advance\voffset\dimen@
1601 %<tightpage> \advance\voffset-\ht\pr@box
1602 %<tightpage> \dimen@\dp\pr@box
1603 %<tightpage> \ifdim\dimen@<\z@ \dimen@\z@\fi
1604 %<tightpage> \advance\dimen@-\pr@bb@ii
1605 %<tightpage> \advance\dimen@\dimen@ii
1606 %<tightpage> \global\pdfpageheight\dimen@
1607 %<tightpage> \global\paperheight\dimen@
1608 %<tightpage> \dimen@\wd\pr@box
1609 %<tightpage> \ifdim\dimen@<\z@ \dimen@=\z@\fi
1610 %<tightpage> \advance\dimen@-\pr@bb@i
1611 %<tightpage> \advance\dimen@\pr@bb@iii
1612 %<tightpage> \global\pdfpagewidth\dimen@
1613 %<tightpage> \hoffset=-1in
1614 %<tightpage> \advance\hoffset-\pr@bb@i
1615 %<tightpage> \let\pr@offset@override\@empty}
1618 % Ok, here comes the beef. First we fish the 7~numbers from the file
1619 % with |token| and convert them from \TeX~|sp| to PostScript points.
1621 %<tightpage>\ifnum\pr@graphicstype=\@ne
1622 %<tightpage>\preview@delay{\AtBeginDvi{%
1624 % Backwards-compatibility. Once we are certain that dvipng-1.6 or
1625 % later is widely used, the three following specials can be exchanged
1626 % for the simple |\special{!/preview@tightpage true def}|
1628 %<tightpage> \special{!/preview@tightpage true def (%
1629 %<tightpage> compatibility PostScript comment for dvipng<=1.5 }
1630 %<tightpage> \special{!userdict begin/bop-hook{%
1631 %<tightpage> 7{currentfile token not{stop}if
1632 %<tightpage> 65781.76 div DVImag mul}repeat
1633 %<tightpage> 72 add 72 2 copy gt{exch}if 4 2 roll
1634 %<tightpage> neg 2 copy lt{exch}if dup 0 gt{pop 0 exch}%
1635 %<tightpage> {exch dup 0 lt{pop 0}if}ifelse 720 add exch 720 add
1636 %<tightpage> 3 1 roll
1637 %<tightpage> 4{5 -1 roll add 4 1 roll}repeat
1638 %<tightpage> <</PageSize[5 -1 roll 6 index sub 5 -1 roll 5 index sub]%
1639 %<tightpage> /PageOffset[7 -2 roll [1 1 dtransform exch]%
1640 %<tightpage> {0 ge{neg}if exch}forall]>>setpagedevice%
1641 %<tightpage> //bop-hook exec}bind def end}
1642 %<tightpage> \special{!userdict (some extra code to avoid
1643 %<tightpage> dvipng>=1.6 unknown special:
1644 %<tightpage> 7{currentfile token not{stop}if 65781.76 div })) pop}
1646 % The ``userdict'' at the start of the last special is also there to
1647 % avoid an unknown special in dvipng<=1.6. This is the end of the
1648 % backwards-compatibility code.
1650 %<tightpage> \special{!userdict begin/bop-hook{%
1651 %<tightpage> preview-bop-level 0 le{%
1652 %<tightpage> 7{currentfile token not{stop}if
1653 %<tightpage> 65781.76 div DVImag mul}repeat
1655 % Next we produce the horizontal part of the bounding box as
1656 % \[ (1\mathrm{in},1\mathrm{in}) +
1657 % \bigl(\min(|\wd\pr@box|,0),\max(|\wd\pr@box|,0)\bigr) \]
1658 % and roll it to the bottom of the stack:
1660 %<tightpage> 72 add 72 2 copy gt{exch}if 4 2 roll
1662 % Next is the vertical part of the bounding box. Depth counts in
1663 % negatively, and we again take $\min$ and $\max$ of possible extents
1664 % in the vertical direction, limited by 0. 720 corresponds to
1665 % $10\,\mathrm{in}$ and is the famous $1\,\mathrm{in}$ distance away
1666 % from the edge of letterpaper.
1668 %<tightpage> neg 2 copy lt{exch}if dup 0 gt{pop 0 exch}%
1669 %<tightpage> {exch dup 0 lt{pop 0}if}ifelse 720 add exch 720 add
1670 %<tightpage> 3 1 roll
1672 % Ok, we now have the bounding box on the stack in the proper order
1673 % llx, lly, urx, ury. We add the adjustments:
1675 %<tightpage> 4{5 -1 roll add 4 1 roll}repeat
1677 % The page size is calculated as the appropriate differences, the page
1678 % offset consists of the coordinates of the lower left corner, with
1679 % those coordinates negated that would be reckoned positive in the
1680 % device coordinate system.
1682 %<tightpage> <</PageSize[5 -1 roll 6 index sub 5 -1 roll 5 index sub]%
1683 %<tightpage> /PageOffset[7 -2 roll [1 1 dtransform exch]%
1684 %<tightpage> {0 ge{neg}if exch}forall]>>setpagedevice}if%
1686 % So we now bind the old definition of |bop-hook| into our new
1687 % definition and finish it.
1689 %<tightpage> //bop-hook exec}bind def end}}}
1693 % \subsection{The \texttt{showlabels} option}
1694 % During the editing process, some people like to see the label names
1695 % in their equations, figures and the like. Now if you are using
1696 % Emacs for editing, and in particular \previewlatex, I'd strongly
1697 % recommend that you check out the Ref\TeX\ package which pretty much
1698 % obliterates the need for this kind of functionality. If you still
1699 % want it, standard \LaTeX\ provides it with the |showkeys| package,
1700 % and there is also the less encompassing |showlabels| package.
1701 % Unfortunately, since those go to some pain not to change the page
1702 % layout and spacing, they also don't change |preview|'s idea of the
1703 % \TeX\ dimensions of the involved boxes.
1705 % So those packages are mostly useless. So we present here an
1706 % alternative hack that will get the labels through.
1707 % \begin{macro}{\pr@labelbox}
1708 % This works by collecting them into a separate box which we then
1709 % tack to the right of the previews.
1711 %<showlabels>\ifPreview\else\expandafter\endinput\fi
1712 %<showlabels>\newbox\pr@labelbox
1715 % \begin{macro}{\pr@label}
1716 % We follow up with our own definition of the \cmd{\label} macro
1717 % which will be active only in previews. The original definition is
1718 % stored in |\pr@@label|. |\pr@lastlabel| contains the last typeset
1719 % label in order to avoid duplication in certain environments, and
1720 % we keep the stuff in |\pr@labelbox|.
1722 %<showlabels>\def\pr@label#1{\pr@@label{#1}%
1724 % Ok, now we generate the box, by placing the label below any existing
1727 %<showlabels> \ifpr@setbox\z@{#1}%
1728 %<showlabels> \global\setbox\pr@labelbox\vbox{\unvbox\pr@labelbox
1729 %<showlabels> \box\z@}\egroup\fi}
1732 % \begin{macro}{\ifpr@setbox}
1733 % |\ifpr@setbox| receives two arguments, |#1| is the box into which
1734 % to set a label, |#2| is the label text itself. If a label needs
1735 % to be set (if it is not a duplicate in the current box, and is
1736 % nonempty, and we are in the course of typesetting and so on), we
1737 % are left in a true conditional and an open group with the preset
1738 % box. If nothing should be set, no group is opened, and we get
1739 % into skipping to the closing of the conditional. Since
1740 % |\ifpr@setbox| is a macro, you should not place the call to it
1741 % into conditional text, since it will not pair up with |\fi| until
1744 % We have some trickery involved here. |\romannumeral\z@| expands
1745 % to empty, and will also remove everything between the two of them
1746 % that also expands to empty, like a chain of |\fi|.
1748 %<showlabels>\def\ifpr@setbox#1#2{%
1749 %<showlabels> \romannumeral%
1750 %<showlabels> \ifx\protect\@typeset@protect\ifpr@outer\else
1752 % Ignore empty labels\dots
1754 %<showlabels> \z@\bgroup
1755 %<showlabels> \protected@edef\next{#2}\@onelevel@sanitize\next
1756 %<showlabels> \ifx\next\@empty\egroup\romannumeral\else
1758 % and labels equal to the last one.
1760 %<showlabels> \ifx\next\pr@lastlabel\egroup\romannumeral\else
1761 %<showlabels> \global\let\pr@lastlabel\next
1762 %<showlabels> \setbox#1\pr@boxlabel\pr@lastlabel
1763 %<showlabels> \expandafter\expandafter\romannumeral\fi\fi\fi\fi
1764 %<showlabels> \z@\iffalse\iftrue\fi}
1767 % \begin{macro}{\pr@boxlabel}
1768 % Now the actual typesetting of a label box is done. We use a small
1769 % typewriter font inside of a framed box (the default frame/box
1770 % separating distance is a bit large).
1772 %<showlabels>\def\pr@boxlabel#1{\hbox{\normalfont
1773 %<showlabels> \footnotesize\ttfamily\fboxsep0.4ex\relax\fbox{#1}}}
1776 % \begin{macro}{\pr@maketag}
1777 % And here is a version for |amsmath| equations. They look better
1778 % when the label is right beside the tag, so we place it there, but
1779 % augment |\box\pr@labelbox| with an appropriate placeholder.
1781 %<showlabels>\def\pr@maketag#1{\pr@@maketag{#1}%
1782 %<showlabels> \ifpr@setbox\z@{\df@label}%
1783 %<showlabels> \global\setbox\pr@labelbox\vbox{%
1784 %<showlabels> \hrule\@width\wd\z@\@height\z@
1785 %<showlabels> \unvbox\pr@labelbox}%
1787 % Set the width of the box to empty so that the label placement gets
1788 % not disturbed, then append it.
1790 %<showlabels> \wd\z@\z@\box\z@ \egroup\fi}
1793 % \begin{macro}{\pr@lastlabel}
1794 % Ok, here is how we activate this: we clear out box and label info
1796 %<showlabels>\g@addto@macro\pr@ship@start{%
1797 %<showlabels> \global\setbox\pr@labelbox\box\voidb@x
1798 %<showlabels> \xdef\pr@lastlabel{}%
1800 % The definitions above are global because we might be in any amount
1801 % of nesting. We then reassign the appropriate labelling macros:
1803 %<showlabels> \global\let\pr@@label\label \let\label\pr@label
1804 %<showlabels> \global\let\pr@@maketag\maketag@@@
1805 %<showlabels> \let\maketag@@@\pr@maketag
1809 % Now all we have to do is to add the stuff to the box in question.
1810 % The stuff at the front works around a bug in |ntheorem.sty|.
1812 %<showlabels>\pr@addto@front\pr@ship@end{%
1813 %<showlabels> \ifx \label\pr@label \global\let\label\pr@@label \fi
1814 %<showlabels> \ifx \maketag@@@\pr@maketag
1815 %<showlabels> \global\let\maketag@@@\pr@@maketag \fi
1816 %<showlabels> \ifvoid\pr@labelbox
1817 %<showlabels> \else \setbox\pr@box\hbox{%
1818 %<showlabels> \box\pr@box\,\box\pr@labelbox}%
1821 % \subsection{The \texttt{footnotes} option}
1822 % This is rather simplistic right now. It overrides the default
1823 % footnote action (which is to disable footnotes altogether for better
1826 %<footnotes>\PreviewMacro[[!]\footnote %]
1829 % \section{Various driver files}
1830 % The installer, in case it is missing. If it is to be used via
1831 % |make|, we don't specify an installation path, since
1835 % is supposed to cater for the installation itself.
1837 %<installer> \input docstrip
1838 %<installer&make> \askforoverwritefalse
1839 %<installer> \generate{
1840 %<installer> \file{preview.drv}{\from{preview.dtx}{driver}}
1841 %<installer&!make> \usedir{tex/latex/preview}
1842 %<installer> \file{preview.sty}{\from{preview.dtx}{style}
1843 %<installer> \from{preview.dtx}{style,active}}
1844 %<installer> \file{prauctex.def}{\from{preview.dtx}{auctex}}
1845 %<installer> \file{prauctex.cfg}{\from{preview.dtx}{auccfg}}
1846 %<installer> \file{prshowbox.def}{\from{preview.dtx}{showbox}}
1847 %<installer> \file{prshowlabels.def}{\from{preview.dtx}{showlabels}}
1848 %<installer> \file{prtracingall.def}{\from{preview.dtx}{tracingall}}
1849 %<installer> \file{prtightpage.def}{\from{preview.dtx}{tightpage}}
1850 %<installer> \file{prlyx.def}{\from{preview.dtx}{lyx}}
1851 %<installer> \file{prcounters.def}{\from{preview.dtx}{counters}}
1852 %<installer> \file{prfootnotes.def}{\from{preview.dtx}{footnotes}}
1854 %<installer> \endbatchfile
1856 % And here comes the documentation driver.
1858 %<driver> \documentclass{ltxdoc}
1859 %<driver> \usepackage{preview}
1860 %<driver> \let\ifPreview\relax
1861 %<driver> \newcommand\previewlatex{\texttt{preview-latex}}
1862 %<driver> \begin{document}
1863 %<driver> \DocInput{preview.dtx}
1864 %<driver> \end{document}
1870 % TeX-master: "preview.drv"