summaryrefslogtreecommitdiff
path: root/macros/generic/psbox/psbsamp.tex
blob: 112a3ef6de73002b98cee3f4aeb16ea5242a85c3 (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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
% psbsamp.tex V-1.3: a sample use of the psbox macros from Plain TeX.
%2345678 1 345678 2 345678 3 345678 4 345678 5 345678 6 345678 7 3456789
%
\input psbox.tex % 'told you it was necessary!
%
%
% These are just to get a mini verbatim:
  \def\\{\hbox{$\backslash$}}%
  \edef\{{\hbox{$\{$}}%
  \edef\}{\hbox{$\}$}}%
\def\section#1{\ifnum\pageno=1\else\vfil\break\fi
  \centerline{\frameit{1pt}{2pt}{\frameit{0.5pt}{3pt}{\hbox{#1}}}}%
  \nobreak\medskip}%
\def\LaTeX{{\rm L\kern-.36em\raise.3ex\hbox{a}\kern-.15em
    T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}%
%
%
\line{\hfil
\frameit{1pt}{2pt}{\frameit{0.5pt}{3pt}{\hbox{PS}}}
\frameit{1pt}{2pt}{\frameit{0.5pt}{3pt}{\hbox{BOX}}}
\hfil \llap{V-\psboxversion, by Jean Orloff}}
\line{\sevenrm e-mail: ORLOFF @ SURYA11.CERN.CH\hfil
Updates available by anonymous ftp from:
cs.nyu.edu:pub/tex/psbox/%;\hfil noa.huji.ac.il
}
\bigbreak
\section{Crash Overview}
{\def\nl{\hfil\break}\parindent=0pt\parskip=3ptplus3pt\def\im{\parindent=1cm}
WHAT IS IT:\nl
psbox is a set of machine-independent TeX macros to:
{\im
\item{1)\ }allow (Encapsulated) PostScript figure inclusion in all versions
   of TeX (Plain, LaTeX) on all machines using a PostScript printer

\item{2)\ }facilitate the communication (e-mail, ftp, ...) of all the files
   (text, macros, figs) needed to reproduce a TeX document by grouping
   them together into a single, TeXable file.

\bigskip
\noindent HOW TO GET IT TO WORK:
\item{1)\ }get the file psboxall.tex by one of the following ways:\nl
   -from outside CERN: ftp cs.nyu.edu(=128.122.140.24):pub/tex/psbox/\nl
   -(if all else fails) send me a mail (orloff@surya11.cern.ch);
\item{2)\ }tex psboxall.tex: this will produce a complete documentation
dvi and a
   set of files, including the raw macros named psbox.tex;
\item{3)\ }adapt your psbox.tex to your system by uncommenting the appropriate
   {\tt\%\\psfor...}-line at the end of the file;
\item{4)\ }put it in your TeX Inputs directory
}

\bigskip
MAJOR COMMANDS:

\def\tag#1{\noindent\hbox{\tt #1\hss}\nl\hangindent1cm}
\tag{\\psbox\{fname.eps\}}
   makes a box having the right size to enclose the figure fname.eps;

\tag{\\psboxto(xdim;ydim)\{fn.eps\}}
   makes a box of the given size and rescales fn.eps so that it just fits;

\tag{\\psboxto(\\hsize;0pt)\{fn.eps\}}
   has the maximal width \& a height computed from a uniformal rescaling;

\tag{\\centinsert\{\\pscaption\{\\psbox\{fn.eps\}\}\{Fig 1: the
caption...\}\}}
   recommended way to include a graphics between 2 paragraphs;

\tag{\\begin\{figure\}[hbt]\\begin\{center\}\\mbox\{\\psbox\{fn.eps\}\}\\caption\{Fig
1:\} \\end\{figure\}}
   recommended way in LaTeX;

\tag{\\autojoin}
   makes a single file called psbjoint.tex containing the currently tex'd
   file plus all the files (macros \& figs) included since the \\input of
   psbox.tex. Texing psbjoint.tex will split it into all these files with
   their original names (so think of PC's:12345678.123!!) and tex the
   first one (generally the one that issued \\autojoin).

}
\vfill\break
\section{Introduction}
\TeX{} and PostScript have become de-facto standards for
producing scientific papers and figures. The reason for this perhaps
lies in the success of electronic mail within the scientific
community as both standards produce text files that easily propagate by
e-mail and yet produce machine-independent result when printed from any
computer on any PostScript printer\footnote{*}{You might think of
sending directly the PostScript description of the whole document, but
this would mean sending 15 times more caracters and moreover
forbidding your correspondant to make any correction to the
manuscript.}. Recently, these standards have been further sanctified in
the Physics community with the advent of electronic ``Bulletin Boards"
which spread like crazy and whose very existence precisely relies on
such standards.

In this rapidly evolving and modernish landscape, the
inclusion of figures into papers still remains a dark spot: it is
relatively uneasy and, worse, essentially non-universal. The purpose of the
{\tt psbox} macros is to try and correct for this.

To start with, let us show how to use the macros for including
Encapsulated PostScript graphics-File (EPSF) into any \TeX\ document
(Plain \TeX, Plain-based macros like Harvmac, Phyzzx,... or \LaTeX).
To get this to work, you first need to produce an EPSF. This
is different from a usual PostScript file. (For instance, with CERN's
package PAW/HIGZ, the output device specified in the metafile is -111
for simple postscript and -113 for EPSF). You can always check whether
you succeeded by looking at your EPSF: it should start with {\tt\%!}
and somewhere contain a line like:
$$
\hbox{\tt\%\%BoundingBox: llx lly urx ury\hfil}
$$
where llx \& lly (urx \& ury) are the positive integer coordinates of
the lower-left (upper-right) corners of the smallest rectangle enclosing
your graphics. If all else fails, you still have the opportunity of
adding such a line by hand: you might then want to know that
coordinates are given in ``Big Points'' (1in=72bp)%
\footnote{**}{%
Not to be confused with ``Points'' (1in=72.27pt): inventing units
related by such crazy factors as 72.27/72 definitely is a perverse and
deeply immoral sport!}
from the bottom left
corner of the printed page. You can always visualize the corresponding
{\tt\%\%BoundingBox} using {\tt\\boxit} (see below). Once you have a
good EPSF, you should save it in the same directory as the \TeX{}
file in which you want to insert your graphics.

Now you're ready for inserting. Here is how to do:
\item{1)} Check you have a copy of the file {\tt psbox.tex} somewhere on
  your system. If you don't, get it by ``anonymous ftp'' from the site
  {\tt cs.nyu.edu}. In the directory pub/tex/psbox, you will find a file
  called {\tt psboxall.tex} which is an ``archive'' containing the macros,
  this documentation, a sample PostScript figure, etc... Just ``{\tt get}''
  it by ftp, tex it on your system, and you will see how an archive splits
  into it's original files.
\item{2)} make sure the uncommented line at the end of the {\tt psbox.tex}
  file corresponds to your particular way of translating \TeX{}
  output into PostScript:
$$\vbox{\halign{\tt\\ps#\hfil&\qquad#\hfil\cr
fortextures& for TeXtures on the Macintosh\cr
foroztex&    for OzTeX shareware soft on the Macintosh\cr
fordvitops&  for IBM mainframes dvi to postscript converter DVITOPS\cr
fordvips&    for Unix, PC and VAX dvi to postscript converter DVIPS\cr
%fordvitps&   for dvitps from the TeXPS package under UNIX.\cr
fordvialw&   for Unix free converter (part GNU software)\cr
onlyboxes&   for poor people without any of these\cr
}}
$$
\item{3)} in the
  beginning of your \TeX{} file, type {\tt\\input psbox.tex}
  in order to load the relevant \TeX{} macros;


If you get the wrong postscript
converter, you will just get extremely white(!) figures but the
formatting of your text will be exactly the same.
Now you can get your graphics where you want in the text by
just typing:
$$
\hbox{\tt\$\$\\psbox\{box.ps\}\$\$}
$$
And this is what you get:
$$
\psbox{box.ps}
$$
The {\tt\\psbox\{EPSFilename\}} macro makes a \TeX{} \\vbox
having the right size to contain the graphics and issues a \\special
command for the postscript printer to put the EPSF graphics at the
right place.

\section{Scalings}
You can moreover use Postscript to resize your graphics. This can be
done via the {\tt\\psboxto} macro: here you
specify the dimensions and \TeX{} uniformly scales the graphics to fit
entirely in the given box. For instance
$$\eqalign{\hbox{\tt\$\$}
&\hbox{\tt\\boxit\{\\psboxto(3cm;7cm)\{box.ps\}\}}\cr
&\hbox{\tt\\boxit\{\\psboxto(7cm;3cm)\{box.ps\}\}\$\$}\cr}
$$
gives
$$
\boxit{\psboxto(3cm;7cm){box.ps}}
\boxit{\psboxto(7cm;3cm){box.ps}}
$$
(we have here materialized the \TeX boxes by the
{\tt\\boxit\{anybox\}} command which can be useful for
boxing not only psboxes, but any kind of text boxes. To
control the thickness of the line and to have some white space
between your box and it's framing, you can use
{\tt\\frameit\{LineThickness\} \{WhiteSpaceThickness\} \{\\anybox\}}).

If you specify one zero dimension in {\tt\\psboxto}, you get a box
proportional to the natural one for your drawing, but with the scale
specified by the non-zero dimension: $$\eqalign{\hbox{\tt\$\$}
&\hbox{\tt\\boxit\{\\psboxto(3cm;0cm)\{box.ps\}\}}\cr
&\hbox{\tt\\boxit\{\\psboxto(0cm;3cm)\{box.ps\}\}\$\$}\cr} $$ yields
$$ \boxit{\psboxto(3cm;0cm){box.ps}} \boxit{\psboxto(0cm;3cm){box.ps}}
$$
Altenatively, you can specify a scale factor%
\footnote{*}{This way
you can be sure to get exactly the same size for the \TeX{} and EPSF
box: with {\tt\\psboxto}, you can have the \TeX box 1/1000 too large
because of rounding errors unavoidable for compatibility reasons}
($\times1000$ in the usual \TeX{} way):
$$\hbox{\tt\\psboxscaled\{250\}\{box.ps\}:}\psboxscaled{250}{box.ps}
$$
On certain occasions, the way PostScript computes it's BoundingBox may
may be too conservative: the box turns out to be too large because of
some invisible control point lying outside the visual bounding box.
For most purposes, this won't harm. Certain perfectionists will
nevertheless appreciate the possibility of correcting the bounding
box by specifying an offset ({\tt\\psxoffset, \\psyoffset})
for the lower left corner and incrementing the width and height
({\tt\\pswdincr, \\pshtincr}) of the graphics. For instance,
$$\hbox{\tt\\psxoffset=1cm\\psyoffset=20pt\\pswdincr=1cm\\pshtincr=20pt}
$$
will {\bf raise} the figure by 12pt, shift it to the right by
0.3cm and change it's size so that it still fits. These dimensions
get reset after each use of {\tt\\psbox...} so
you should type this just before the one you want to modify. These
dimensions also get scaled together with the figure if you later
decide to
use {\tt\\psboxto or \\psboxscaled}:
$$
\psxoffset=1cm\psyoffset=20pt
\pswdincr=1cm\pshtincr=20pt
\boxit{\psboxscaled{1200}{box.ps}}\kern2cm
\psxoffset=1cm\psyoffset=20pt
\pswdincr=1cm\pshtincr=20pt
\boxit{\psboxto(3cm;0cm){box.ps}}
$$
Since a {\tt\\psbox} is a true \TeX box, nothing prevents you to have
\psboxto(0cm;1em){box.ps} it in the middle of a line..(?) More
seriously, if you want your graphics to be as large as possible, you
can type
$$\hbox{\tt\$\$\\psboxto(\\hsize;0cm)\{box.ps\}\$\$}
$$
which gives
$$\psboxto(\hsize;0cm){box.ps}
$$

\section{Annotations}
For certain figures, you might want to add something on top of the
graphics (eg. a greek letter to name an axis, or other math symbols
you use in the text). This is what
{\tt\\psannotate\{\\psbox...\}\{annotation\}} was made for. For
instance if you type
$$\hbox{\tt\$\$%
\\psannotate\{\\psboxto(10cm;3cm)\{box.ps\}\}%
\{\\fillinggrid\\at(3\\pscm;1\\pscm)\{A sample at.\}\}\$\$}
$$
you get
$$\psannotate{\psboxto(10cm;3cm){box.ps}} {\fillinggrid
\at(3\pscm;1\pscm){A sample at.}}
$$
This example displays the 2 possible annotations:
\item{-}{\tt\\at((xdim;ydim)\{annotation text\}} will place {\tt
annotation text} xdim to the right of, and ydim higher than the
current point without actually moving it (this may prove useful in
other circumstances). The dimensions may be expressed in any valid
\TeX{} unit, but here we used {\tt\\pscm} meaning scaled centimeters
in order for the annotation to keep the same relative position inside
the figure, whatever rescaling you might do later on.

\item{-}{\tt\\fillinggrid}: in order to help you in the tedious task
of determining the position of your annotations, you can use
{\tt\\fillinggrid} as one particular annotation. This will produce a
1\\pscm by 1\\pscm grid that roughly fills your figure. You will of
course have to delete these in your final document\footnote{*} {To
suppress all these grids at once in your final document, you may type
{\tt\\let\\fillinggrid=\\relax} just after the line where you
{\tt\\input psbox.tex}.}.

\section{Figure Environment For Plain\TeX}
If you have many large figures, the probability that \TeX{}
barks at you about ``overfull or underfull vbox...'' becomes
significant, because you give it a hard time trying to cut pages
into a document that has many large unbreakable units. To
overcome this problem, La\TeX{} users simply have to type:\hfil\break
{\tt\\begin\{figure\}[hbt]\hfil\break
\\begin\{center\}\\mbox\{\\psbox...\}\\end\{center\}\hfil\break
\\caption\{Some caption\}\hfil\break \\end\{figure\}\hfil\break}
In Plain\TeX{} you should use
{\tt\\centinsert\{\\psbox...\}} instead of {\tt\$\$\\psbox...\$\$}.
This will get your graphics precisely where you typed it except if
there is not enough room in the current page, in which case you'll get
it on top of the next one.

However, you will then probably want to have a caption, in case your
graphics and explanatory text get separated. You should then
use {\tt\\pscaption\{\\psbox...\}\{caption\}}, for instance
$$\vbox{\hsize=10cm\tt\hbox{
\\centinsert\{%
  \\pscaption\{%
    \\psannotate\{%
      \\psboxto(6cm;0cm)\{box.ps\}\}\{%
}
\hbox{\qquad\\fillinggrid\\at(3\\pscm;1\\pscm)\{A sample at.\}\}\}\{%
    Figure 1: this is ...
\}\}
}}
$$
in order to get:
\centinsert{
  \pscaption{
    \psannotate{
      \psboxto(6cm;0cm){box.ps}}{
      \fillinggrid\at(3\pscm;1\pscm){A sample at.}}}{%
    Figure 1: this is probably the most stupid caption I can think of
    but it can still be useful for illustrative purposes.
}}%
If your caption is short, it will automatically get centered:
$$\pscaption{\psboxto(3cm;0cm){box.ps}}{\bf Figure 327.}
$$
When typing in the commands for catpion, annotations, etc, you may end
up with long lines which you don't know how to break (a line break is
essentially a space in \TeX, remember?). If you don't want these
spurious spaces to sneek in your text, you should simply add \%{} just
before the line break.

\section{Multiple Files Management}
Suppose you now have a few figures together with a paper, plus your favorite
macros and reference files. You want to communicate the fruits of your hard
work to the entire world, but you don't want to send ten separate files to
each collaborator/potentially interested scientist. So you create a "master"
file containing (you hope) all the files needed to re\TeX{} your paper. The
receiver will also have to do some electronic cutting and pasting. Very
quickly, it starts being a nuisance for everybody to assemble and disassemble
a large file into it's constituents. This is why I thought the following
macros might prove handy:

\item{a.}{\tt\\joinfiles filename1, filename2, ..., filenamen \\into%
\{JOINTFIL.TEX\}}\hfil\break
joins several files into a big one that can be split later on. Since
the goal here is universality, you should remember that PC's still form
the majority of personal computers, and they like filenames of the form
12345678.123 where you can only replace digits by a letter (no
*,\&,\$,', etc...), without distinction between upper-case and
lower-case. So, if you want portability, save your texts as
{\tt12345678.tex} and your figures as {\tt12345678.eps} (ie. no
empty extensions): this will save you from later troubles!
The file {\tt JOINTFIL.TEX} has a header explaining how to split
it (see below) and is in fact auto-splittable. Namely, you just have to
run \TeX, or \LaTeX{} depending of what is required by the first file in
the list. This should first split the file and then tex it while
including properly the figures. You can edit the ``archive'' {\tt
JOINTFIL.TEX}, for instance to change the header, or to modify the names
under which files will be stored when split. For this you may need to
know that each file in the archive has a header line containing it's
name, eg:\hfil\break
{\tt\%Beginning-Of-File-Named:box.ps}.

\item{b.} {\tt\\autojoin}:\hfil\break
since it is painful to remember the list of all figure's names, you can
generate a joint file called {\tt psbjoint.tex} by simply typing
{\tt\\autojoin} close to the end (ie. after all {\tt\\psbox...} and
{\tt\\input ...} have been issued) of the file you want to tex. This
will first close and then read in a file called {\tt psbjoin.aux} that is
always generated automatically and that basically contains the list of
all your inclusions (both figures and macro files {\tt\\input}ted). If
you never say {\tt\\autojoin}, the file {\tt psbjoin.aux} will
nevertheless be created and will by the end of the day contain the list
of files needed for your texing session. This list will appear as an
incomplete {\tt\\joinfiles}-command, which you can complete and tex to
do the joining. Notice: all these macro and figure files do not need to
be in the same directory to be found. If \TeX{} is able to find them
for {\tt\\input} or {\tt\\psbox} (because they are in some directory
named {\tt TeX Inputs} or pointed at by an environment variable {\tt
TEXINPUTS}), it will be able to join them too. Unix users should resist
the temptation of specifying explicit path in filenames (eg: {\tt
../../TeX/mymacros.tex}): this makes their \TeX{} files non-portable.
They should rather add an entry in their {\tt TEXINPUTS} list of paths.

\item{c.}{\tt\\splitfile\{JOINTFIL.TEX\}}\hfil\break
splits {\tt JOINTFIL.TEX} into it's constituents. Anything before the
first {\tt\%Beginning-Of-File-Named:} line is trashed into a special
file called {\tt TrashMe}: never store precious info in such a file
anyhow!  You may fear what happens if one of the constituent-file
names coincides with a previoulsy existing file on your disk. Does it
silently replace it? Well, no, relax, all output produced by these
macros use {\tt\\warnopenout} instead of the standard {\tt\\openout},
which will give you a chance to break precisely in this case. Notice
{\tt\\warnopenout} is sometimes too cautious: it can warn you before
erasing a file that doesn't exist! This is because a file with the same
name exists in some directory \TeX{} is searching in for input files,
but relax, it will only write files in the same directory as {\tt
JOINTFIL.TEX}. Finally,
notice you can say {\tt\\splitfile \{\\jobname\}} in which case you will
split the very file that issued such a command (this is in fact what
makes the output of {\tt\\joinfiles} auto-splittable). However,
watchout: {\tt\\jobname} has peculiar and machine-dependent
definition. It gives the name of the file currently texed MINUS it's
{\tt.tex} extension if it has one (and on most machines, minus any
extension your filename could have). So, \TeX{} will not
be able to read in from the file named {\tt\\jobname} (without
extension). But it always tries to read in {\tt\\jobname.tex} (in fact,
on IBM \& VAX machines, it doesn't even try to read {\tt\\jobname}
without extension). This mess explains the
precaution taken in the header of a joint file, reproduced below:
{\obeylines\tt\def
{\hfil\break}
\% This collection of files was produced with CERN psbox package
\% To decompose and tex it:
\%-save this with a filename CONTAINING ONLY LETTERS and a .TEX
\% extension (say, JOINTFIL.TEX), in some uncrowded directory;
\%-make sure you can \string\input\space psbox.tex (version>=1.3);
\%  (else ftp cs.nyu.edu(=128.122.140.24):pub/TeX/psbox/, then get
\%  and tex the file psboxall.tex; more info in psbREAD.ME)
\%-tex JOINTFIL.TEX using Plain, or LaTeX, or whatever is needed by
\%  the first file in the joining (after splitting JOINTFIL.TEX into
\%  it's constituents, TeX will try to process it as it stands).
\\input psbox.tex
\\splitfile\{\\jobname\}
\\let\\autojoin\\=\\relax
}
\joinfiles psbREAD.ME, psboxOK.tex\into{TrashMe}
\section{Errors}
\message{RELAX!!!
The following error messages should not frighten you, they are
intentional tests. Just continue and see what comes out!}
If \TeX{} cannot find the file you specified, you will get the following
output:
$$\psbox{in_exist.ps}$$
On the other hand, an existing file which is not EPSF will produce:
$$\psbox{psbsamp.tex}$$
\autojoin
\bye