summaryrefslogtreecommitdiff
path: root/tex
diff options
context:
space:
mode:
Diffstat (limited to 'tex')
-rw-r--r--tex/preamble.tex6
-rw-r--r--tex/preview.dtx1872
-rw-r--r--tex/preview.ins44
3 files changed, 1922 insertions, 0 deletions
diff --git a/tex/preamble.tex b/tex/preamble.tex
new file mode 100644
index 0000000..531506a
--- /dev/null
+++ b/tex/preamble.tex
@@ -0,0 +1,6 @@
1\usepackage[utf8]{inputenc}
2
3\usepackage{amssymb}
4\usepackage{amsmath}
5\usepackage{amsthm}
6\usepackage{thmtools}
diff --git a/tex/preview.dtx b/tex/preview.dtx
new file mode 100644
index 0000000..0675c27
--- /dev/null
+++ b/tex/preview.dtx
@@ -0,0 +1,1872 @@
1% \iffalse
2%% The preview style for extracting previews from LaTeX documents.
3%% Developed as part of AUCTeX <URL:http://www.gnu.org/software/auctex>.
4%
5% Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006,
6% 2010 Free Software Foundation
7%
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.
12%
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.
17%
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
22% \fi
23% \CheckSum{1758}
24% \GetFileInfo{preview.sty}
25% \date{\filedate}
26% \author{David Kastrup\thanks{\texttt{dak@gnu.org}}}
27% \title{The \texttt{preview} Package for \LaTeX\\Version \fileversion}
28% \maketitle
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
35% by Ghostscript).
36%
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.
41%
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'
51% \begin{quote}
52% |dvips -E -i|
53% \end{quote}
54% invocation, there are better ways available that don't rely on Dvips
55% not getting confused by PostScript specials.
56%
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)
62% file.
63%
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
67% make use of it.
68%
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
73% \begin{quote}
74% |-picky -noghostscript|
75% \end{quote}
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.
79%
80% \section{Package options}
81% The package is included with the customary
82% \begin{quote}
83% |\usepackage|\oarg{options}|{preview}|
84% \end{quote}
85% You should usually load this package as the last one, since it
86% redefines several things that other packages may also provide.
87%
88% The following options are available:
89% \begin{description}
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
97% \begin{quote}
98% \raggedright
99% |latex '\PassOptionsToPackage{active}{preview}| |\input|\marg{filename}|'|
100% \end{quote}
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,
110% too.
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
124% if possible.
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
131% desired option.
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
136% have previewed.
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
144% to a preview.
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
151% \begin{quote}
152% |latex '\RequirePackage[active,delayed,|\meta{options}|]{preview}|
153% |\input|\marg{filename}|'|
154% \end{quote}
155% This relaxes the requirement to be loading the |preview| package
156% as last 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
168% misinterpreted.
169%
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
193% \begin{quote}
194% |dvips -E -i -Pwww -o| \meta{outputfile}|.000| \meta{inputfile}
195% \end{quote}
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
205% anywhere.
206%
207% The solution is to use the |tightpage| option. That way a single
208% command line like
209% \begin{quote}
210% \raggedright
211% \texttt{gs -sDEVICE=png16m -dTextAlphaBits=4 -r300
212% -dGraphicsAlphaBits=4 -dSAFER -q -dNOPAUSE
213% -sOutputFile=\meta{outputfile}\%d.png \meta{inputfile}.ps}
214% \end{quote}
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.
218%
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.
223%
224% If neither |dvips| or |pdftex| have been specified, the
225% corresponding option will get autodetected and invoked.
226%
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
231% math previews.
232%
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
242% \begin{quote}
243% \raggedright
244% |\newcommand| |\PreviewBbAdjust|
245% |{-\PreviewBorder| |-\PreviewBorder|
246% |\PreviewBorder| |\PreviewBorder}|
247% \end{quote}
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.
265%
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
270% Emacs.
271% \end{description}
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.
284% \end{description}
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
291% normally.
292%
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
298% main text.
299%
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.
303%
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
307% declaration like
308% \begin{quote}
309% |\PreviewMacro[*[[!]{\includegraphics}|
310% \end{quote}
311% or, more readable,
312% \begin{quote}
313% |\PreviewMacro[{*[][]{}}]{\includegraphics}|
314% \end{quote}
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
323% argument parsing.
324%
325% The letters simply mean
326% \begin{description}
327% \item[|*|] indicates an optional |*| modifier, as in
328% |\includegraphics*|.
329% \item[|[|]^^A]
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
338% specification.
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
345% delimiter.
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.
360% \end{description}
361%
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]|.
369%
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}.
379%
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
387% away.
388%
389% As an example for using this argument, you might want to specify
390% \begin{quote}
391% |\PreviewMacro*\footnote[{[]}][#1{}]|
392% \end{quote}
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.
397%
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*}.
403%
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
409% \begin{enumerate}
410% \item produce insertion material that cannot be extracted to the
411% preview properly,
412% \item complain with an error message about not being in outer par
413% mode.
414% \end{enumerate}
415%
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.
425%
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|.
429%
430% \StopEventually{}
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}
436% \begin{macrocode}
437%<*style>
438%<*!active>
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_88 $ \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)]}
450\next
451% \end{macrocode}
452% \end{macro}
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.
457%
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.
462% \begin{macrocode}
463\let\ifPreview\iffalse
464%</!active>
465% \end{macrocode}
466%\end{macro}
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.
471% \begin{macrocode}
472%<*active>
473\newif\ifpr@outer
474\pr@outertrue
475%</active>
476% \end{macrocode}
477%\end{macro}
478%
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
494% got executed.
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.
498% \begin{macrocode}
499%<*!active>
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}
505% \end{macrocode}
506%\begin{macro}{\pr@addto@front}
507% This adds code globally to the front of a macro.
508% \begin{macrocode}
509\long\def\pr@addto@front#1#2{%
510 \toks@{#2}\toks@\expandafter{\the\expandafter\toks@#1}%
511 \xdef#1{\the\toks@}}
512% \end{macrocode}
513% \end{macro}
514% These commands get more interesting when |preview| is active:
515% \begin{macrocode}
516\DeclareOption{active}{%
517 \let\ifPreview\iftrue
518 \def\pr@advise#1{%
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}
522% \end{macrocode}
523% \end{macro}
524% \end{macro}
525% \end{macro}
526% \end{macro}
527%
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.
534% \begin{macrocode}
535\long\def\pr@adviseii#1#2#3{\preview@delay{%
536 \ifx#1\relax \let#1#2\fi
537 \toks@{#3#1}%
538 \ifx\@undefined\protected \else \protected\fi
539 \long\edef#2{\the\toks@}}}
540% \end{macrocode}
541%\end{macro}
542%
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
546% redefinition.
547% \begin{macrocode}
548\DeclareOption{delayed}{%
549 \ifPreview \def\preview@delay{\AtBeginDocument}\fi
550}
551% \end{macrocode}
552%
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.
557%
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
563% defined.
564% \begin{macrocode}
565\newif\ifpr@fixbb
566\pr@fixbbfalse
567\DeclareOption{psfixbb}{\ifPreview%
568 \pr@fixbbtrue
569 \newbox\pr@markerbox
570 \setbox\pr@markerbox\hbox{\special{psfile=/dev/null}}\fi
571}
572% \end{macrocode}
573% \end{macro}
574% \begin{macro}{\pr@graphicstype}
575% The |dvips| option redefines the |bop-hook| to reset the page
576% size.
577% \begin{macrocode}
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}}}}
588% \end{macrocode}
589% The |pdftex| option just sets \cmd{\pr@graphicstype}.
590% \begin{macrocode}
591\DeclareOption{pdftex}{%
592 \let\pr@graphicstype\tw@}
593% \end{macrocode}
594% And so does the |xetex| option.
595% \begin{macrocode}
596\DeclareOption{xetex}{%
597 \let\pr@graphicstype\thr@@}
598%</!active>
599% \end{macrocode}
600% \end{macro}
601% \subsection{The internals}
602%
603% Those are only needed if |preview| is active.
604% \begin{macrocode}
605%<*active>
606% \end{macrocode}
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.
611% \begin{macrocode}
612\newcount\pr@snippet
613\global\pr@snippet=1
614% \end{macrocode}
615% \end{macro}
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.
619% \begin{macrocode}
620\def\pr@protect{\ifx\protect\@typeset@protect
621 \ifpr@outer \expandafter\expandafter\expandafter
622 \@secondoftwo\fi\fi\@gobble}
623% \end{macrocode}
624% \end{macro}
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.
630%
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
635% true.
636% \begin{macrocode}
637\def\pr@protect@ship{\pr@protect{\@firstoftwo\pr@startbox}%
638 \@gobbletwo}
639% \end{macrocode}
640% \end{macro}
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:
646% \begin{macrocode}
647\def\pr@insert{\begingroup\afterassignment\pr@insertii\count@}
648\def\pr@insertii{\endgroup\setbox\pr@box\vbox}
649% \end{macrocode}
650% Similar things hold for marks.
651% \begin{macrocode}
652\def\pr@mark{{\afterassignment}\toks@}
653\def\pr@marks{{\aftergroup\pr@mark\afterassignment}\count@}
654% \end{macrocode}
655% \end{macro}
656% \end{macro}
657% \end{macro}
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.
667% \begin{macrocode}
668\newbox\pr@box
669\long\def\pr@startbox#1#2{%
670 \ifpr@outer
671 \toks@{#2}%
672 \edef\pr@cleanup{\the\toks@}%
673 \setbox\pr@box\vbox\bgroup
674 \break
675 \pr@outerfalse\@arrayparboxrestore
676 \let\insert\pr@insert
677 \let\mark\pr@mark
678 \let\marks\pr@marks
679 \expandafter\expandafter\expandafter
680 \pr@ship@start
681 \expandafter\@firstofone
682 \else
683 \expandafter \@gobble
684 \fi{#1}}
685% \end{macrocode}
686% \end{macro}
687% \end{macro}
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}.
699% \begin{macrocode}
700\def\pr@endbox{%
701 \let\reserved@a\relax
702 \ifvmode \edef\reserved@a{\the\everypar}%
703 \ifx\reserved@a\@empty\else
704 \dimen@\prevdepth
705 \noindent\par
706 \setbox\z@\lastbox\unskip\unpenalty
707 \prevdepth\dimen@
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
714 \egroup
715 \setbox\pr@box\vbox{%
716 \baselineskip\z@skip \lineskip\z@skip \lineskiplimit\z@
717 \@begindvi
718 \nointerlineskip
719 \splittopskip\z@skip\setbox\z@\vsplit\pr@box to\z@
720 \unvbox\z@
721 \nointerlineskip
722 %\color@setgroup
723 \box\pr@box
724 %\color@endgroup
725 }%
726% \end{macrocode}
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
739% this hook.
740%
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|.
751% \begin{macrocode}
752 \pr@ship@end
753 {\let\protect\noexpand
754 \ifx\pr@offset@override\@undefined
755 \voffset=-\ht\pr@box
756 \hoffset=\z@
757 \fi
758 \c@page=\pr@snippet
759 \pr@shipout
760 \ifpr@fixbb\hbox{%
761 \dimen@\wd\pr@box
762 \@tempdima\ht\pr@box
763 \@tempdimb\dp\pr@box
764 \box\pr@box
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
769 \pr@cleanup
770}
771% \end{macrocode}
772% \end{macro}
773% \end{macro}
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}
780% \begin{macrocode}
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}
785% \end{macrocode}
786% \end{macro}
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
793% \begin{quote}
794% \cmd{\pr@callafter}\meta{aftertoken}\meta{parsestring}\cmd{\pr@endparse}\\
795% \qquad\meta{macro}\meta{parameters}
796% \end{quote}
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.
803%
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
809% rather trivial.
810% \begin{macrocode}
811\def\pr@parseit#1{\csname pr@parse#1\endcsname}
812\let\pr@endparse=\@percentchar
813\def\next#1{%
814\def\pr@callafter{%
815 \afterassignment\pr@parseit
816 \let#1= }}
817\expandafter\next\csname pr@parse\pr@endparse\endcsname
818% \end{macrocode}
819% \end{macro}
820% \end{macro}
821% \end{macro}
822% \begin{macro}{\pr@parse*}
823% Straightforward, same mechanism \LaTeX\ itself employs. We take
824% some care not to pass potential |#| tokens unprotected through
825% macros.
826% \begin{macrocode}
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}}
831% \end{macrocode}
832% \end{macro}
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
839% start.
840% \begin{macrocode}
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}]}}
847% \end{macrocode}
848% \end{macro}
849% \end{macro}
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.
854% \begin{macrocode}
855\expandafter\let\csname pr@parse]\endcsname=\pr@parseit
856% \end{macrocode}
857% \end{macro}
858% \begin{macro}{\pr@parse}
859% \begin{macro}{\pr@parse!}
860% Mandatory arguments are perhaps easiest to parse.
861% \begin{macrocode}
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
865% \end{macrocode}
866% \end{macro}
867% \end{macro}
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.
872% \begin{macrocode}
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@}
880% \end{macrocode}
881% \end{macro}
882% \end{macro}
883% \begin{macro}{\pr@parse@}
884% This makes it possible to insert literal material into the
885% argument list.
886% \begin{macrocode}
887 \long\def\pr@parse@#1#2\pr@endparse#3{%
888 \pr@parseit #2\pr@endparse{#3#1}}
889% \end{macrocode}
890% \end{macro}
891% \begin{macro}{\pr@parse-}
892% This will just drop the next token.
893% \begin{macrocode}
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}%
898 \let\next= }
899% \end{macrocode}
900% \end{macro}
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.
906% \begin{macrocode}
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}
912% \end{macrocode}
913% \end{macro}
914% \edef\next{\noexpand\begin{macro}{\noexpand
915% \pr@parse\string#}}
916% \next
917% Another transform rule, but this passes the transformed material
918% into the token list.
919% \begin{macrocode}
920\long\expandafter\def\csname pr@parse#\endcsname
921 #1#2#3\pr@endparse#4{\begingroup
922 \toks@{#4}%
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}
927%</active>
928% \end{macrocode}
929% \end{macro}
930%
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.
936%
937% The incredible hack with |\dt@ptrue| is necessary for working around
938% bug `amslatex/3425'.
939% \begin{macrocode}
940%<*!active>
941\begingroup
942\catcode`\*=11
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}%
952 {\endgroup}%
953 \pr@advise@ship\equation*{\begingroup\aftergroup\pr@endbox
954 \def\dt@ptrue{\m@ne=\m@ne}\noindent}%
955 {\endgroup}%
956 \PreviewOpen[][\def\dt@ptrue{\m@ne=\m@ne}\noindent#1]\[%
957 \PreviewClose\]%
958 \PreviewEnvironment[][\noindent#1]{eqnarray}%
959 \PreviewEnvironment[][\noindent#1]{eqnarray*}%
960 \PreviewEnvironment{displaymath}%
961}}
962% \end{macrocode}
963%
964% The |textmath| option. Some folderol in order to define the active
965% |$|
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.
977% \begin{macrocode}
978\begingroup
979\def\next#1#2{%
980 \endgroup
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}}
993\lccode`\~=`\$
994\lowercase{\expandafter\next\expandafter~}%
995 \csname pr@\string$%$
996 \endcsname
997%</!active>
998% \end{macrocode}
999% \begin{macro}{\pr@endaftergroup}
1000% This justs ends the box after the group opened by |#1| is closed
1001% again.
1002% \begin{macrocode}
1003%<*active>
1004\def\pr@endaftergroup#1{#1\aftergroup\pr@endbox}
1005%</active>
1006% \end{macrocode}
1007% \end{macro}
1008%
1009% The |graphics| option.
1010% \begin{macrocode}
1011%<*!active>
1012\DeclareOption{graphics}{%
1013 \PreviewMacro[*[[!]{\includegraphics}%]]
1014}
1015% \end{macrocode}
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.
1021% \begin{macrocode}
1022\def\pr@floatfix#1#2{\ifx#1#2%
1023 \ifx#1\@undefined\else
1024 \PackageWarningNoLine{preview}{%
1025Your document class has a bad definition^^J
1026of \string#1, most likely^^J
1027\string\let\string#1=\string#2^^J
1028which has now been changed to^^J
1029\string\def\string#1{\string#2}^^J
1030because otherwise subsequent changes to \string#2^^J
1031(like done by several packages changing float behaviour)^^J
1032can't take effect on \string#1.^^J
1033Please complain to your document class author}%
1034 \def#1{#2}\fi\fi}
1035\begingroup
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}%]
1044 }}
1045\expandafter\next\csname endfigure*\expandafter\endcsname
1046 \csname endtable*\endcsname
1047% \end{macrocode}
1048% The |sections| option. Two optional parameters might occur in
1049% |memoir.cls|.
1050% \begin{macrocode}
1051\DeclareOption{sections}{%
1052 \PreviewMacro[!!!!!!*[[!]{\@startsection}%]]
1053 \PreviewMacro[*[[!]{\chapter}%]]
1054}
1055% \end{macrocode}
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.
1062% \begin{macrocode}
1063\DeclareOption*
1064 {\InputIfFileExists{pr\CurrentOption.def}{}{\OptionNotUsed}}
1065% \end{macrocode}
1066%
1067% \subsection{Preview attaching commands}
1068% \begin{macro}{\PreviewMacro}
1069% As explained above. Detect possible |*| and call appropriate
1070% macro.
1071% \begin{macrocode}
1072\def\PreviewMacro{\@ifstar\pr@starmacro\pr@macro}
1073% \end{macrocode}
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}
1079% \begin{macrocode}
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}
1090% \end{macrocode}
1091% \end{macro}
1092% \end{macro}
1093% \end{macro}
1094% \end{macro}
1095% \end{macro}
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.
1101% \begin{macrocode}
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[]}}
1109% \end{macrocode}
1110% \end{macro}
1111% \end{macro}
1112% \end{macro}
1113% \begin{macro}{\PreviewOpen}
1114% As explained above. Detect possible |*| and call appropriate macro.
1115% \begin{macrocode}
1116\def\PreviewOpen{\@ifstar\pr@starmacro\pr@open}
1117% \end{macrocode}
1118% The version without |*| is now rather straightforward.
1119% \begin{macro}{\pr@open}
1120% \begin{macrocode}
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}}%
1127 {\endgroup}}}%
1128 \@ifnextchar[\next\pr@macroii}
1129% \end{macrocode}
1130% \end{macro}
1131% \end{macro}
1132% \begin{macro}{\PreviewClose}
1133% As explained above. Detect possible |*| and call appropriate
1134% macro.
1135% \begin{macrocode}
1136\def\PreviewClose{\@ifstar\pr@starmacro\pr@close}
1137% \end{macrocode}
1138% The version without |*| is now rather straightforward.
1139% \begin{macro}{\pr@close}
1140% \begin{macrocode}
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}
1146% \end{macrocode}
1147% \end{macro}
1148% \end{macro}
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.
1154% \begin{macrocode}
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 %]
1170 }
1171% \end{macrocode}
1172% \end{macro}
1173% \begin{macro}{\PreviewSnarfEnvironment}
1174% This is a nuisance since we have to advise \emph{both} the
1175% environment and its end.
1176% \begin{macrocode}
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}}
1182%</!active>
1183% \end{macrocode}
1184% \end{macro}
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.
1192% \begin{macrocode}
1193%<*active>
1194\let\pr@endsnarf\relax
1195\long\def\pr@snarfafter#1{\ifpr@outer
1196 \pr@ship@start
1197 \let\pr@ship@start\relax
1198 \let\pr@endsnarf\endgroup
1199 \else
1200 \let\pr@endsnarf\relax
1201 \fi
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}%
1205 \ignorespaces}
1206%</active>
1207% \end{macrocode}
1208% \end{macro}
1209% \end{macro}
1210% \end{macro}
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}.
1229% \begin{macrocode}
1230%<*!active>
1231\let\pr@ship@start\@empty
1232\let\pr@ship@end\@empty
1233% \end{macrocode}
1234% \end{macro}
1235% \end{macro}
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
1240% activated.
1241% \begin{macrocode}
1242\newenvironment{preview}{\ignorespaces}{\ifhmode\unskip\fi}
1243\newenvironment{nopreview}{\ignorespaces}{\ifhmode\unskip\fi}
1244% \end{macrocode}
1245% \end{environment}
1246% \end{environment}
1247%
1248% We now process the options and finish in case we are not active.
1249% \begin{macrocode}
1250\ProcessOptions\relax
1251\ifPreview\else\expandafter\endinput\fi
1252%</!active>
1253% \end{macrocode}
1254% Now for the redefinition of the |preview| and |endpreview|
1255% environments:
1256% \begin{macrocode}
1257%<*active>
1258\renewenvironment{preview}{\begingroup
1259 \pr@startbox{\begingroup\aftergroup\pr@endbox}%
1260 {\endgroup}%
1261 \ignorespaces}%
1262 {\ifhmode\unskip\fi\endgroup}
1263\renewenvironment{nopreview}{\pr@outerfalse\ignorespaces}%
1264 {\ifhmode\unskip\fi}
1265% \end{macrocode}
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.
1269%
1270% The main work of disabling normal output relies on a \cmd{\shipout}
1271% redefinition.
1272% \begin{macro}{\pr@output}
1273% \begin{macrocode}
1274\newtoks\pr@output
1275\pr@output\output
1276\output{%
1277 \pr@outerfalse
1278 \let\@begindvi\@empty
1279 \the\pr@output}
1280\let\output\pr@output
1281% \end{macrocode}
1282% \end{macro}
1283% \begin{macro}{\pr@typeinfos}
1284% Then we have some document info that style files might want to
1285% output.
1286% \begin{macrocode}
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}%
1294 \fi
1295 \else
1296 \ifx\pdfoutput\relax \else
1297 \ifnum\pdfoutput>\z@
1298 \typeout{Preview: PDFoutput 1}%
1299 \fi
1300 \fi
1301 \fi
1302}
1303\AtBeginDocument{\pr@typeinfos}
1304% \end{macrocode}
1305% \end{macro}
1306% And at the end we load the default configuration file, so that it
1307% may override settings from this package:
1308% \begin{macrocode}
1309\pr@loadcfg{prdefault}
1310%</active>
1311%</style>
1312% \end{macrocode}
1313%
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.
1323%
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.
1330%
1331% So here is the contents of the |prauctex.def| file:
1332% \begin{macrocode}
1333%<auctex>\ifPreview\else\expandafter\endinput\fi
1334%<auctex>\nofiles
1335%<auctex>\preview@delay{\nonstopmode}
1336% \end{macrocode}
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
1342% can muster.
1343% \begin{macrocode}
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)}}
1364% \end{macrocode}
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
1370% know, did you?
1371%
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
1381% good.
1382% \begin{macrocode}
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
1393% \end{macrocode}
1394% Ok, now we load a possible configuration file.
1395% \begin{macrocode}
1396%<auctex>\pr@loadcfg{prauctex}
1397% \end{macrocode}
1398% And here we cater for several frequently used commands in
1399% |prauctex.cfg|:
1400% \begin{macrocode}
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
1422% \end{macrocode}
1423%
1424% \subsection{The \texttt{lyx} option}
1425% The following is the option providing LyX with info for its preview
1426% implementation.
1427% \begin{macrocode}
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}}
1433% \end{macrocode}
1434%
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}.
1442% \begin{macrocode}
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.}
1454% \end{macrocode}
1455%
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.
1463%
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.
1470% \begin{macrocode}
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}
1476% \end{macrocode}
1477%
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.
1483% \begin{macrocode}
1484%<tracingall>\ifPreview\else\expandafter\endinput\fi
1485%<tracingall>\pr@addto@front\pr@ship@start{\let\tracingonline\count@
1486%<tracingall> \let\errorstopmode\@empty\tracingall}
1487% \end{macrocode}
1488%
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
1492% \begin{quote}
1493% |dvips -E -i -Ppdf -o| \meta{outputfile}|.000| \meta{inputfile}
1494% \end{quote}
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
1503% images.
1504%
1505% You will have to specify the output driver to be used, either
1506% |dvips| or |pdftex|.
1507%
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:
1513% \begin{macrocode}
1514%<tightpage>\ifx\PreviewBorder\@undefined
1515%<tightpage> \newdimen\PreviewBorder
1516%<tightpage> \PreviewBorder=0.50001bp
1517%<tightpage>\fi
1518%<tightpage>\ifx\PreviewBbAdjust\@undefined
1519%<tightpage> \def\PreviewBbAdjust{-\PreviewBorder -\PreviewBorder
1520%<tightpage> \PreviewBorder \PreviewBorder}
1521%<tightpage>\fi
1522% \end{macrocode}
1523% \end{macro}
1524% \end{macro}
1525% Here is stuff used for parsing this:
1526% \begin{macrocode}
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}
1533% \end{macrocode}
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.
1544% \begin{macrocode}
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
1565%<tightpage>\or
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}}
1577%<tightpage>\or
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}}
1594%<tightpage>\or
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}
1616%<tightpage>\fi
1617% \end{macrocode}
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.
1620% \begin{macrocode}
1621%<tightpage>\ifnum\pr@graphicstype=\@ne
1622%<tightpage>\preview@delay{\AtBeginDvi{%
1623% \end{macrocode}
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}|
1627% \begin{macrocode}
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}
1645% \end{macrocode}
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.
1649% \begin{macrocode}
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
1654% \end{macrocode}
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:
1659% \begin{macrocode}
1660%<tightpage> 72 add 72 2 copy gt{exch}if 4 2 roll
1661% \end{macrocode}
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.
1667% \begin{macrocode}
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
1671% \end{macrocode}
1672% Ok, we now have the bounding box on the stack in the proper order
1673% llx, lly, urx, ury. We add the adjustments:
1674% \begin{macrocode}
1675%<tightpage> 4{5 -1 roll add 4 1 roll}repeat
1676% \end{macrocode}
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.
1681% \begin{macrocode}
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%
1685% \end{macrocode}
1686% So we now bind the old definition of |bop-hook| into our new
1687% definition and finish it.
1688% \begin{macrocode}
1689%<tightpage> //bop-hook exec}bind def end}}}
1690%<tightpage>\fi
1691% \end{macrocode}
1692%
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.
1704%
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.
1710% \begin{macrocode}
1711%<showlabels>\ifPreview\else\expandafter\endinput\fi
1712%<showlabels>\newbox\pr@labelbox
1713% \end{macrocode}
1714% \end{macro}
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|.
1721% \begin{macrocode}
1722%<showlabels>\def\pr@label#1{\pr@@label{#1}%
1723% \end{macrocode}
1724% Ok, now we generate the box, by placing the label below any existing
1725% stuff.
1726% \begin{macrocode}
1727%<showlabels> \ifpr@setbox\z@{#1}%
1728%<showlabels> \global\setbox\pr@labelbox\vbox{\unvbox\pr@labelbox
1729%<showlabels> \box\z@}\egroup\fi}
1730% \end{macrocode}
1731% \end{macro}
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
1742% being expanded.
1743%
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|.
1747% \begin{macrocode}
1748%<showlabels>\def\ifpr@setbox#1#2{%
1749%<showlabels> \romannumeral%
1750%<showlabels> \ifx\protect\@typeset@protect\ifpr@outer\else
1751% \end{macrocode}
1752% Ignore empty labels\dots
1753% \begin{macrocode}
1754%<showlabels> \z@\bgroup
1755%<showlabels> \protected@edef\next{#2}\@onelevel@sanitize\next
1756%<showlabels> \ifx\next\@empty\egroup\romannumeral\else
1757% \end{macrocode}
1758% and labels equal to the last one.
1759% \begin{macrocode}
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}
1765% \end{macrocode}
1766% \end{macro}
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).
1771% \begin{macrocode}
1772%<showlabels>\def\pr@boxlabel#1{\hbox{\normalfont
1773%<showlabels> \footnotesize\ttfamily\fboxsep0.4ex\relax\fbox{#1}}}
1774% \end{macrocode}
1775% \end{macro}
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.
1780% \begin{macrocode}
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}%
1786% \end{macrocode}
1787% Set the width of the box to empty so that the label placement gets
1788% not disturbed, then append it.
1789% \begin{macrocode}
1790%<showlabels> \wd\z@\z@\box\z@ \egroup\fi}
1791% \end{macrocode}
1792% \end{macro}
1793% \begin{macro}{\pr@lastlabel}
1794% Ok, here is how we activate this: we clear out box and label info
1795% \begin{macrocode}
1796%<showlabels>\g@addto@macro\pr@ship@start{%
1797%<showlabels> \global\setbox\pr@labelbox\box\voidb@x
1798%<showlabels> \xdef\pr@lastlabel{}%
1799% \end{macrocode}
1800% The definitions above are global because we might be in any amount
1801% of nesting. We then reassign the appropriate labelling macros:
1802% \begin{macrocode}
1803%<showlabels> \global\let\pr@@label\label \let\label\pr@label
1804%<showlabels> \global\let\pr@@maketag\maketag@@@
1805%<showlabels> \let\maketag@@@\pr@maketag
1806%<showlabels>}
1807% \end{macrocode}
1808% \end{macro}
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|.
1811% \begin{macrocode}
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}%
1819%<showlabels> \fi}
1820% \end{macrocode}
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
1824% visibility).
1825% \begin{macrocode}
1826%<footnotes>\PreviewMacro[[!]\footnote %]
1827% \end{macrocode}
1828%
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
1832% \begin{quote}
1833% |make install|
1834% \end{quote}
1835% is supposed to cater for the installation itself.
1836% \begin{macrocode}
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}}
1853%<installer> }
1854%<installer> \endbatchfile
1855% \end{macrocode}
1856% And here comes the documentation driver.
1857% \begin{macrocode}
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}
1865% \end{macrocode}
1866% \Finale{}
1867% \iffalse
1868% Local Variables:
1869% mode: doctex
1870% TeX-master: "preview.drv"
1871% End:
1872% \fi
diff --git a/tex/preview.ins b/tex/preview.ins
new file mode 100644
index 0000000..1d4229d
--- /dev/null
+++ b/tex/preview.ins
@@ -0,0 +1,44 @@
1%%
2%% This is file `preview.ins',
3%% generated with the docstrip utility.
4%%
5%% The original source files were:
6%%
7%% preview.dtx (with options: `installer')
8%%
9%% IMPORTANT NOTICE:
10%%
11%% For the copyright see the source file.
12%%
13%% Any modified versions of this file must be renamed
14%% with new filenames distinct from preview.ins.
15%%
16%% For distribution of the original source see the terms
17%% for copying and modification in the file preview.dtx.
18%%
19%% This generated file may be distributed as long as the
20%% original source files, as listed above, are part of the
21%% same distribution. (The sources need not necessarily be
22%% in the same archive or directory.)
23%% The preview style for extracting previews from LaTeX documents.
24%% Developed as part of AUCTeX <URL:http://www.gnu.org/software/auctex>.
25 \input docstrip
26 \generate{
27 \file{preview.drv}{\from{preview.dtx}{driver}}
28 \usedir{tex/latex/preview}
29 \file{preview.sty}{\from{preview.dtx}{style}
30 \from{preview.dtx}{style,active}}
31 \file{prauctex.def}{\from{preview.dtx}{auctex}}
32 \file{prauctex.cfg}{\from{preview.dtx}{auccfg}}
33 \file{prshowbox.def}{\from{preview.dtx}{showbox}}
34 \file{prshowlabels.def}{\from{preview.dtx}{showlabels}}
35 \file{prtracingall.def}{\from{preview.dtx}{tracingall}}
36 \file{prtightpage.def}{\from{preview.dtx}{tightpage}}
37 \file{prlyx.def}{\from{preview.dtx}{lyx}}
38 \file{prcounters.def}{\from{preview.dtx}{counters}}
39 \file{prfootnotes.def}{\from{preview.dtx}{footnotes}}
40 }
41 \endbatchfile
42\endinput
43%%
44%% End of file `preview.ins'.