summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/grfpaste/grfpaste.sty
blob: 76a116b3e659ec9e70f3a28981554b64a8bbe64e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238


%%% LaTeX support for TeXplorators / M. Spivak dvipaste program
%%% Copyright 1997 David Carlisle


% This program can redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or (at your option) any later version.

%%% Usage notes in the file dvipaste.txt


\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{grfpaste}
          [1997/07/18 v0.2 dvipaste LaTeX graphics style (DPC)]

% 1997/07/17 v0.1
% 1997/07/18 v0.2  add ref system.

% To include previously prepared dvi fragments, use
% \usepackage{grfpaste}
% and include the graphics with \includegraphics{file.dvi}
% or \includegraphics[num=5]{file.dvi}
%
% To make a file that produces suitable fragments, use
% \usepackage[write]{grfpaste}
% and mark each fragment with \sendout{....}
% 
\DeclareOption{write}{\let\sendout\relax}
\DeclareOption{writepages}{\let\sendout\relax\let\GP@sendout\@empty}
\DeclareOption{include}{%
  \def\sendout#1{\PackageError{grfpaste}{Use write option}{}}}
\DeclareOption{defpaste}{\def\paste#1#2{\includegraphics[num=#2]{#1}}}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{graphicx}}
\ExecuteOptions{include}
\ProcessOptions
\RequirePackage{graphicx}

\ifx\sendout\relax
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Marking DVI Sections For Inclusion In Other Files
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Size information will be written in to a file filename.dat
% which is opened now and closed at the end of the run.

\newwrite\writedata@
\immediate\openout\writedata@=\jobname.dat
%\AtEndDocument{\immediate\closeout\writedata@}

% The format of the .dat file is identical to that written by
% dvipaste.tex, the format of the dvi file is compatible.
% dvipaste uses a more complicated scheme that uses a custom output
% routine and then \eject each section, however I can't see why
% \sendout can not just \shipout the box directly, so that is what
% this version does.

\def\sendout{\@testopt\GP@sendout{}}

\ifx\GP@sendout\@empty

\def\GP@sendout[#1]#2{\PackageError{grfpaste}{write pages
    only}{}}

\let\GP@shipout\shipout
\def\shipout{\global\setbox\xxx}
\newbox\xxx
\let\GP@outputpage\@outputpage
\def\@outputpage{%
  \GP@outputpage
  \immediate\write\writedata@
      {\the\ht\xxx\space\the\dp\xxx\space\the\wd\xxx}%
  {\let\protect\noexpand
  \advance\c@page\m@ne
  \GP@shipout\hbox{%
    \special{beginpaste:}%
    \wd\xxx\z@
    \box\xxx
    \special{endpaste:}%
    }%
  }}

\else

\long\def\GP@sendout[#1]#2{%
  \sbox\z@{#2}%
  \immediate\write\writedata@
      {\the\ht\z@\space\the\dp\z@\space\the\wd\z@
        \ifx\box#1\box\else\space\@percentchar#1\fi}%
  \shipout\vbox{%
    \vskip\ht\z@
    \special{beginpaste:}%
    \ht\z@\z@\dp\z@\z@\wd\z@\z@
    \noindent\box\z@
    \special{endpaste:}%
% the original had this rule, but seems not to be needed.
%    \smash{\vrule \@height1sp\@width1sp\@depth\z@}%
    \@@par
    \vskip2pc%
    \hbox{\normalfont File [\jobname], \#\number\c@page}}%
  \stepcounter{page}}

\fi

\else
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Including DVI Sections Into The Current File
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Graphics will be able to include dvi file segments, reading size
% info from .dat files (compatible with dvipast.tex for plain tex)

\DeclareGraphicsRule{.dvi}{dvi}{.dat}{}

% Add .dvi to the default list of extensions.

\g@addto@macro\Gin@extensions{,.dvi}


% dvipaste allows multiple dvi fragments to be included from the
% same file. Add a new key num= (defaulting to 1) which says
% which bit to include. Maintaining numbers if you have a lot of
% fragments is inconvenient so may use symbolic references
% instead of number.
% ref=xxx refers to a fragment marked with the label xxx by use
% of an optional argument \sendout[xxx]{......} to \sendout.
% If \sendout is used with such an optional argument
% the fragment may be included either by number or by label.
% (The numeric form must be used if the fragment is included using
% dvipaste.tex's \paste command.)


\define@key{Gin}{num}{\def\Gin@num{#1}}
\define@key{Gin}{ref}{\def\Gin@ref{#1 }}
\setkeys{Gin}{num=1,ref=}

% Unlike other graphics formats, which only have natural height and
% width, dvipaste fragments are TeX boxes, with depth as well.
% add a new key to set the depth (for cases where you don't want to
% use a .dat file).

\define@key{Gin}{natdepth}{%
  \Gin@defaultbp\@tempaa{#1}%
  \Gin@nat@depth\@tempaa bp\relax}

% Ah. Don't look too carefully. The internal command \Gin@setfile
% in the kernel of the graphics package was not expecting this, and
% explicitly sets the depth of the graphic box to zero, so patch that
% to make it set it to the new \Gin@req@depth macro.
%
% pulls apart the macro at \dp\z@\z@ and then puts it all back together
% again.

\def\@tempa#1\dp\z@\z@#2!{%
  \def\Gin@setfile##1##2##3{%
    #1%
    \dp\z@\Gin@req@depth
    #2}}
\expandafter\@tempa\Gin@setfile{#1}{#2}{#3}!

% Scaling is not currently supported, so natural depth and
% required depth are the same.

\def\Gin@req@depth{\Gin@nat@depth}

\newdimen\Gin@nat@depth


% For each new file type the graphics package needs two functions.
% \Gread@<type> defines how to read the size information.
% \Ginclude@type defines how to set the actual box and specials.
% These functions are pretty similar to the code in dvipaste.tex

% as in the dvipaste.tex version, the size information for
% all the fragments in a single dvi file is saved in a macro
% so the file only needs to be read once.

\def\Gread@dvi#1{%
  \expandafter\let\expandafter\@tempb\csname Gread@#1\endcsname
  \ifx\@tempb\relax
  \let\@tempb\@empty
  \let\do\relax
  \immediate\openin\@inputcheck#1 %
  \catcode`\%9\relax
  \ifeof\@inputcheck
    \@latex@error{File `#1' not found}\@ehc
  \else
     \Gread@true
     \loop
       \read\@inputcheck to\@tempa
       \ifeof\@inputcheck
         \Gread@false
       \else
         \xdef\@tempb{\@tempb\do\@tempa\relax}%
       \fi
     \ifGread@
     \repeat
    \immediate\closein\@inputcheck
  \fi
  \global\expandafter\let\csname Gread@#1\endcsname\@tempb
  \fi
%
% Temporarily set \do to count up to the required fragment number
% and then grab the size info. Then execute the list (in \@tempb).
  \count@\z@
  \Gread@false
  \def\do##1 ##2 ##3 ##4\relax{%
    \advance\count@\@ne
    \def\@tempa{##4}%
    \ifx\@tempa\Gin@ref
      \edef\Gin@num{\the\count@}%
    \fi
    \ifnum\Gin@num=\count@
      \Gread@true
  \def\Gin@llx{0}%
  \let\Gin@lly\Gin@llx
  \Gin@defaultbp\Gin@urx{##3}%
  \Gin@defaultbp\Gin@ury{##1}%
       \Gin@nat@depth##2\relax
    \fi}%
  \@tempb
  \let\do\noexpand}

\def\Ginclude@dvi#1{%
  \ifGread@
    \dimen@\Gin@nat@height
    \advance\dimen@\Gin@nat@depth
    \hbox{\special{dvipaste: \Gin@base\space\Gin@num}% 
    \lower\Gin@nat@depth\vbox to\dimen@{\hbox to\Gin@nat@width{}\vfil}}%
  \else
    \Gin@nosize{\Gin@base[\Gin@num]}%
  \fi}


\fi