summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/rlepsf/rlepsf.tex
blob: 5e2702703c4f481db17a96b6e35e7bd7ce2f6efb (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
%%%%%%%%%%%%%%%%%%%%%%   rlepsf.tex   %%%%%%%%%%%%%%%%
%                     Version 1.0 (beta test)
%
%    Comments, problems etc to :   cpr@maths.warwick.ac.uk
%
%    Macros to relabel an eps file with TeX labels,  
%    written by Michael Greene, with TeX front end 
%    written by Colin Rourke. 
%
%    Designed for use with the macro package epsf.tex 
%    and dvips converter (written by Rokicki and Knuth) 
%    and with eps output from a variety of drawing 
%    packages (tested with output from xfig and Adobe 
%    Illustrator, and with hand-drawn figures). 
%    
%    To use this package type  \input rlepsf  (in place of
%    the usual  \input epsf ).  Then place each eps file
%    in a  \relabelbox ... \endrelabelbox  with relabelling
%    instructions after the  \epsfbox{..} .
%
%    The eps file is called exactly as usual with epsf.tex
%    typical instructions being  \epsfbox{filename.eps}
%    and   \epsfxsize dimension \epsfbox{filename.eps}
%    (where "dimension" is the required finished width of 
%    the diagram).
%
%    There are three (re)labelling macros:
%
%       \relabel {pslabel}{TeX label}
%       \adjustrelabel <dx,dy> {pslabel}{TeX label}  
%       \extralabel <x,y> {extra label}
%
%    \relabel  uses the ps file position for the new TeX
%    label (which can be any TeX output).  The new label
%    is positioned with same reference point (left-hand 
%    end of baseline) as the original ps label.  
%    \adjustrelabel  adjusts the position by  dx,dy  and 
%    is useful for fine tuning the position of the
%    new label.  \extralabel  allows extra TeX labels to be
%    inserted.  The positions x,y are measured from the
%    bottom right-hand corner of the box (so x is typically
%    negative) !  The  re/extra-labelling instructions can
%    be given in any order and any TeX dimensions can
%    be used for x,y,dx,dy.   
%
%    The result is a box of dimensions the original epsbox
%    but with new TeX labels.  This can then be inserted in
%    $$ ... $$  or \centerline{ ... }  for display, or
%    combined with other boxes to form a larger display.
%
%    The  \relabelbox ... \endrelabelbox  forms a TeX group;
%    thus instructions for resizing text for the new labels
%    (eg  \small ) will remain local to this group.
%
%    There are two main uses for the package :   
%
%    (1)  Creating graphics with TeX labels :   
%    Draw the graphic with dummy ps labels (all different and in
%    some common font eg Times-Roman).  Then use \relabel 'ling 
%    instructions to replace the dummy labels by the genuine TeX
%    labels.  Use roughly the same size dummy labels as the final
%    TeX labels and then the position will probably be perfect
%    first time.  Adjust the positions if necessary by editing
%    \relabel  to  \adjustrelabel  with appropriate  <dx,dy>.
%
%    (2)  Editing the ps labels in an existing eps file to TeX
%    labels :   
%    Use  \relabel  and  \adjustrelabel  to replace the 
%    existing labels.  You may have to use  \extralabel  for
%    some of the new labels (or to edit the eps file to change
%    repeated ps labels to be different), see note (2) below.
%
%    Notes:  
%    (1)  All ps labels are removed whether or not
%    instructions for relabelling are given. 
%    (2)  If the eps file has two or more labels the
%    same, then only one will be replaced.  Therefore
%    if you are designing a diagram from scratch then
%    use different temporary ps labels for your labels
%    even if you wish them to finish the same.  If
%    you are relabelling an existing eps diagram with TeX
%    labels then use \extralabel's to replace the other 
%    label(s) or edit the eps file to change the repeated
%    labels to different ones.
%    (3)  The macros are sensitive to extra spaces and 
%    the above syntax should be used.  
%    (4)  The output will not view correctly on a dvi
%    viewer which will typically show the new labels
%    superimposed at the bottom right-hand corner.  
%    However those produced by  \extralabel  will be shown
%    correctly positioned.
%
%    A typical example of use is appended.   More realistic
%    examples are given in the postscript documentation file
%    rlepsdoc.ps.                            CPR   16-12-96
%
%
\input epsf
%
% Initialise for MTG control
%
\special{! (MTG set-up) pop userdict /MTGdict 99 dict put MTGdict begin
  /Mshow {[ MTGdict /rllist get aload length 2 add -1 roll
    currentpoint transform ] MTGdict /rllist 3 2 roll put} def
  /findlabel {/sought exch def
    /MTGx 3 index def /MTGy 2 index def aload length 3 idiv dup 0 eq
      {pop}
      {{2 index sought eq
          {/MTGy exch def /MTGx exch def pop}
          {pop pop pop}
        ifelse}
      repeat}
    ifelse exch MTGx exch sub exch MTGy exch sub idtransform translate
    } def
  end}%
%
\def\relabelbox{%
  \hbox\bgroup%
  \special{ps:(MTG takes control) pop 
    /MTGsavestate save def /p /show load def MTGdict begin gsave
    /rllist [] def /save {false} def /restore {pop} def /show {Mshow} def
    /ashow {Mshow pop pop} def /widthshow {Mshow pop pop pop} def /awidthshow
    {Mshow 5 {pop} repeat} def /xshow {pop Mshow} def /yshow {pop Mshow} def
    /xyshow {pop Mshow} def /cshow {Mshow pop} def /kshow {Mshow pop} def}%
   \special{ps:/a {moveto} bind def}%
}%
\def\endrelabelbox{%
  \special{ps:(MTG signs off) pop grestore end /restore {restore} bind def
    MTGsavestate restore}\egroup%
}%
\def\relabel #1#2 {%
  \special{ps:/a {} def}%
  \special{ps:gsave /a {moveto} bind def transform MTGdict /rllist get (#1) findlabel}%
  \smash{\rlap{#2}}%
  \special{ps:grestore}%
}%
\def\adjustrelabel <#1,#2> #3#4 {%
  \special{ps:/a {} def}%
  \special{ps:gsave /a {moveto} bind def transform MTGdict /rllist get (#3) findlabel}%
  \smash{\rlap{\kern #1 \raise #2\hbox{#4}}}%
  \special{ps:grestore}%
}%
\def\extralabel <#1,#2> #3 {\smash{\rlap{\kern #1 \raise #2\hbox{#3}}}}%
\endinput
%
%%%%   Typical example of use :
%
\input rlepsf.tex
The line before the figure.\hfil\break
\centerline{%
\relabelbox            
\epsfxsize 3truein \epsfbox {figure1.eps}  
%%  Give label size instruction (eg \small) here. 
\adjustrelabel <0pt,1pt> {Ab}{$A^b$}
\adjustrelabel <-4pt,0pt> {P}{$P$}
\relabel {Bc}{$B_c$}
\extralabel <-.3truein,0.3truein> {First extra label}
\adjustrelabel <1pt,0pt> {IP"}{$\int P''$}
\adjustrelabel <1pt,0pt> {P'}{$P'$}
\extralabel <-1.5cm,1.5cm> {Second extra label}
\endrelabelbox
}
The line after the figure.

\bye