| 1 |
|
| 2 |
|
| 3 |
%%% The grfpaste package |
| 4 |
|
| 5 |
%%% LaTeX support for TeXplorators / M. Spivak dvipaste program |
| 6 |
%%% David Carlisle |
| 7 |
|
| 8 |
|
| 9 |
This package can redistributed and/or modified under the terms |
| 10 |
of the LaTeX Project Public License Distributed from CTAN |
| 11 |
archives in directory macros/latex/base/lppl.txt; either |
| 12 |
version 1 of the License, or (at your option) any later version. |
| 13 |
|
| 14 |
Dvipaste comes with a plain TeX based set of macros in a file |
| 15 |
dvipaste.tex that provide an interface to the dvipaste program. That |
| 16 |
file works perfectly well in LaTeX with only minor modifications |
| 17 |
(specifically using \@@line instead of \line, and \c@page instead of |
| 18 |
\pageno). A dvipaste.sty constructed by just such modifications may be |
| 19 |
found distributed with Jean-Pierre Drucbert's `export' package on ctan. |
| 20 |
However I thought that it would be more in the `LaTeX spirit' |
| 21 |
to provide an interface via the existing LaTeX graphics package. |
| 22 |
|
| 23 |
The files produced by this grfpaste package should be fully compatible |
| 24 |
with dvipaste.tex or dvipaste.sty. That is, if dvi fragments are |
| 25 |
created using the plain TeX interface they may be included using |
| 26 |
\includegraphics via this package, and conversely if this package is |
| 27 |
used with the [write] or [writepages] options to produce a file of dvi |
| 28 |
fragments for including in another file, then the dvi file (and it's |
| 29 |
accompanying `.dat' file of size information) may be included either |
| 30 |
with this package, or via the original dvipaste.tex interface. |
| 31 |
|
| 32 |
Currently the LaTeX interface uses the graphicx package, it would be |
| 33 |
possible to also provide an interface to the more basic graphics |
| 34 |
package, but that is not done here. |
| 35 |
|
| 36 |
The package is used in one of two forms. |
| 37 |
|
| 38 |
1 Producing DVI Fragments |
| 39 |
========================= |
| 40 |
|
| 41 |
1a Writing out boxes. |
| 42 |
=========================== |
| 43 |
|
| 44 |
\documentclass{article} |
| 45 |
|
| 46 |
\usepackage[write]{grfpaste} |
| 47 |
|
| 48 |
\begin{document} |
| 49 |
|
| 50 |
\sendout{\parbox[b]{2cm}{one \sf two three \tt four \it five}} |
| 51 |
|
| 52 |
\sendout[abc]{hello} |
| 53 |
|
| 54 |
\sendout{\parbox[t]{2cm}{one \sf two three \tt four \it five}} |
| 55 |
|
| 56 |
\end{document} |
| 57 |
|
| 58 |
|
| 59 |
If the package is used with the [write] option then the document should |
| 60 |
just consist of \sendout commands, the argument of each will be marked |
| 61 |
as a `fragment' that may be pasted into another DVI file by the dvipaste |
| 62 |
program. An auxiliary file with extension .dat will be created which |
| 63 |
contains the size of each of these fragments. Normally the fragments |
| 64 |
will be accessed by their number, starting from 1, but you may |
| 65 |
optionally supply a label, as in `abc' above which allows fragments to |
| 66 |
be referenced more easily. The above example forms the example |
| 67 |
document grfp1.tex in this distribution. |
| 68 |
|
| 69 |
1b Writing out whole pages. |
| 70 |
=========================== |
| 71 |
|
| 72 |
\documentclass{article} |
| 73 |
|
| 74 |
\usepackage[writepages]{grfpaste} |
| 75 |
|
| 76 |
\begin{document} |
| 77 |
... |
| 78 |
\end{document} |
| 79 |
|
| 80 |
|
| 81 |
If the package is used with the [writepages] option then each |
| 82 |
indivdual page will be marked as a `fragment' for later processing by |
| 83 |
dvipaste. The fragments will be numbered consecutively, starting from |
| 84 |
1, whatever the value of the page counter. See the example document |
| 85 |
grfp2.tex. |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
2 Using DVI Fragments |
| 91 |
========================= |
| 92 |
|
| 93 |
|
| 94 |
\documentclass{article} |
| 95 |
|
| 96 |
\usepackage{grfpaste} |
| 97 |
|
| 98 |
\begin{document} |
| 99 |
|
| 100 |
aaa\fbox{\includegraphics |
| 101 |
[num=1,natheight=19,natdepth=2pt,natwidth=57]{grfp1.dvi}}bbb |
| 102 |
|
| 103 |
xxx\fbox{\includegraphics[num=2]{grfp1.dvi}}yyy |
| 104 |
|
| 105 |
xxx\fbox{\includegraphics[ref=abc]{grfp1.dvi}}yyy |
| 106 |
|
| 107 |
Page 3 of grfp2.dvi: |
| 108 |
aaa\fbox{\includegraphics[num=3]{grfp2}}bbb |
| 109 |
|
| 110 |
\end{document} |
| 111 |
|
| 112 |
To use the fragments then load the package with no option (or |
| 113 |
equivalently with the [include] option). You may also use any options |
| 114 |
understood by the graphicx package, these will be passed on to graphicx |
| 115 |
which is loaded by this package. |
| 116 |
|
| 117 |
To load the first fragment of a given dvi file you just need |
| 118 |
\includegraphics{filename} or \includegraphics{filename.dvi} |
| 119 |
(.dvi is added as one of the default extensions by this package) |
| 120 |
|
| 121 |
To access later fragments then you use the new num=?? key to specify |
| 122 |
the fragment number, as demonstrated above. If there are a lot of |
| 123 |
fragments maintaining the correct number may be inconvenient so you |
| 124 |
may instead use the ref= key to refer to a label previously supplied |
| 125 |
by the \sendout command. Note this label information is added to the |
| 126 |
.dat file in the form of a comment(after %) and so the .dat file is |
| 127 |
still compatible with dvipaste.tex, but if that is used, then the |
| 128 |
numeric form must be used. Thus the two examples above with num=2 |
| 129 |
and ref=abc include the same fragment from the file grfp1.dvi. |
| 130 |
|
| 131 |
|
| 132 |
Normally the size of the graphic is read from the `.dat' file which is |
| 133 |
the `read file' for the dvi graphic type, in the terminoligy of the |
| 134 |
graphics package documentation. If you have lost the .dat file, or |
| 135 |
wish to override it with altered sizes, you may specify the natural |
| 136 |
size using the natheight, natwidth and natdepth keys. As usual these |
| 137 |
take a dimension but the units may be omitted in which case bp are |
| 138 |
assumed. natheight and natwidth are standard graphicx keys, but |
| 139 |
natdepth is new, as these fragments are TeX boxes, so have height and |
| 140 |
depth, unlike most other graphic formats that may be included, which |
| 141 |
always have zero depth. |
| 142 |
|
| 143 |
The \sendout command defined by the [write] option matches that used |
| 144 |
in the plain TeX support, but the plain TeX version does not use |
| 145 |
\includegraphics to include the fragment. It defines a command \paste |
| 146 |
to achieve this. In order to help move documents between the two |
| 147 |
versions, a [defpaste] option is provided for this package which |
| 148 |
specifies that a compatible \paste command should be defined. It is |
| 149 |
defined to be the equivalent call to \includegraphics, |
| 150 |
\includegraphics[num=#2]{#1}. |
| 151 |
|
| 152 |
See the example file grfp3.tex to see examples of including dvi |
| 153 |
fragments. |
| 154 |
|
| 155 |
|
| 156 |
3 Putting it all together |
| 157 |
========================= |
| 158 |
|
| 159 |
a) Produce one or more files of fragments using |
| 160 |
LaTeX and this package with the [write] or [writepages] options. |
| 161 |
(or plain TeX using dvipaste.tex). |
| 162 |
|
| 163 |
b) LaTeX your master document, including this package and using |
| 164 |
\includegraphics to include the fragments at the appropriate points. |
| 165 |
|
| 166 |
At this stage the file will have blank spaces (but if the correct |
| 167 |
size) at the points where the dvi fragments should appear |
| 168 |
|
| 169 |
c) Run dvipaste on the master dvi file. It will incorporate the |
| 170 |
fragments and re-write the file. |
| 171 |
|
| 172 |
d) Preview or print the modified dvi file in your usual manner. |
| 173 |
|
| 174 |
|
| 175 |
4 Running the examples |
| 176 |
========================= |
| 177 |
|
| 178 |
grfp1.tex is an example of using the [write] option |
| 179 |
grfp2.tex is an example of using the [writepages] option |
| 180 |
grfp3.tex is an example of using the [include] option |
| 181 |
|
| 182 |
To process the final document (grfp3.dvi) the following steps need be |
| 183 |
taken. |
| 184 |
|
| 185 |
latex grfp1 |
| 186 |
latex grfp2 |
| 187 |
latex grfp2 |
| 188 |
latex grfp3 |
| 189 |
dvipaste grfp3 |
| 190 |
|
| 191 |
Note that grfp2 needs to be processed twice to generate a full table of |
| 192 |
contents. After grfp3.tex is processed by LaTeX the dvi file will show |
| 193 |
blank spaces at the points that the fragments are to be included. These |
| 194 |
will be filled in by running dvipaste, after which the grfp3.dvi may be |
| 195 |
processed by your driver in the normal way. |
| 196 |
|
| 197 |
|
| 198 |
5 Compiling dvipaste.c |
| 199 |
====================== |
| 200 |
|
| 201 |
/* config.h for LINUX machines for dvipaste.c (DPC) */ |
| 202 |
|
| 203 |
|
| 204 |
#define ANSI |
| 205 |
#undef MICROSOFTC |
| 206 |
#define LITTLENDIAN |
| 207 |
|
| 208 |
/* I guess this is what was meant. */ |
| 209 |
/* (dvipaste.c defines strcmp to itself */ |
| 210 |
/* leaving stricmp undefined) .*/ |
| 211 |
#ifndef MICROSOFTC |
| 212 |
#define strnicmp strncmp |
| 213 |
#define stricmp strcmp |
| 214 |
#endif |
| 215 |
|
| 216 |
#ifdef ANSI |
| 217 |
/* Other things in ANSI C are good, but this is a crock */ |
| 218 |
#define READ_BINARY "rb" |
| 219 |
#define WRITE_BINARY "wb" |
| 220 |
#else |
| 221 |
/* The good old simple and logical K&R I/O */ |
| 222 |
#define READ_BINARY "r" |
| 223 |
#define WRITE_BINARY "w" |
| 224 |
#endif |
| 225 |
|
| 226 |
|
| 227 |
When I tried compiling dvipaste.c I got error due to the function |
| 228 |
stricmp being undefined. The file has a circular definition of strcmp |
| 229 |
to itself which looks like a typo, so I corrected that by making |
| 230 |
stricmp an alias for strcmp by altering config.h as above (which also |
| 231 |
sets LITTLENDIAN for Linux. It seems to work for me, but no promises. |
| 232 |
|
| 233 |
The above suggested config.h leaves stricmp meaning the same thing as |
| 234 |
strcmp (string comparison). Jean-Pierre Drucbert points out that |
| 235 |
stricmp is (on systems that it is defined) a case-insensitive |
| 236 |
comparison function, and that rather than the crude substitution above |
| 237 |
one may define it as follows. |
| 238 |
|
| 239 |
str{n}icmp is not available on all systems. So I got the |
| 240 |
following code in ci.c : |
| 241 |
|
| 242 |
#include <ctype.h> |
| 243 |
#include "config.h" |
| 244 |
/* |
| 245 |
* str{n}icmp - case-insensitive flavors of strcmp(), strncmp() |
| 246 |
*/ |
| 247 |
#ifdef PROTOS |
| 248 |
int stricmp(register char *s1, |
| 249 |
register char *s2) |
| 250 |
#else |
| 251 |
int stricmp(s1, s2) |
| 252 |
register char *s1, *s2; |
| 253 |
#endif |
| 254 |
{ |
| 255 |
register char c1, c2; |
| 256 |
|
| 257 |
for ( ; (c1 = TOLOWER(*s1)) == (c2 = TOLOWER(*s2)); s1++, s2++) |
| 258 |
if (c1 == '\0') |
| 259 |
return 0; |
| 260 |
|
| 261 |
return c1 - c2; |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
#ifdef PROTOS |
| 266 |
int strnicmp(register char *s1, |
| 267 |
register char *s2, |
| 268 |
int n) |
| 269 |
#else |
| 270 |
int strnicmp(s1, s2, n) |
| 271 |
register char *s1, *s2; |
| 272 |
int n; |
| 273 |
#endif |
| 274 |
{ |
| 275 |
register char c1, c2; |
| 276 |
|
| 277 |
for ( ; --n >= 0 && |
| 278 |
(c1 = TOLOWER(*s1)) == (c2 = TOLOWER(*s2)); s1++, s2++) |
| 279 |
if (c1 == '\0') |
| 280 |
return 0; |
| 281 |
|
| 282 |
return n < 0 ? 0 : c1 - c2; |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
By default dvipaste.c has |
| 290 |
#define STRINGSIZE (5124) /* maximum string size */ |
| 291 |
|
| 292 |
Jean-Pierre Drucbert commented: |
| 293 |
|
| 294 |
it is necessary to increase STRINGSIZE if you paste a lot of dvi |
| 295 |
pieces (I increased it from 40592 to 2597888). In practice, do |
| 296 |
not export more than ~100 pieces from one file. You can import a |
| 297 |
lot more into one file. So it is preferable to import from |
| 298 |
several files if you have more than 100 pieces to import. |
| 299 |
|
| 300 |
|
| 301 |
|