summaryrefslogtreecommitdiff
path: root/macros/latex209/contrib/labelfig/labelfig.tex
blob: 6ad3bf13566fed00c7b93e02c740a92658a58f70 (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
 %%%%%%%%%%%%%%%%%%%--------------- CUT
 
  %%
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%
 %%%%%   LabelFig.tex FOR LABELLING FIGURE INSERTS %%%%%
  %%
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%
 %%%  AUTHOR: Laurent Siebenmann
  %%    lcs@matups.matups.fr
  %%
 %%%  VERSION: July 1991
  %%
 %%%  PURPOSE:
  %%  Occasionally, figures imported into TeX lack some labels.
  %%  It may then be most convenient to use TeX to provide
  %%  the labels.  Several macro sets, notably the
  %%  LaTeX picture environment, provide means to insert
  %%  labels.  LabelFig.tex is a small (4Ko) and fast macro file
  %%  offering labelling capability for other TeX formats such
  %%  as Plain and AmSTeX.  Hopefully it will work in essentially
  %%  all TeX environments.
  %%
 %%%  THE IDEA:
  %%  Nothing distinctly new here.
  %%  Each label is located with respect
  %%  to a grid laid down on the figure --- as in LaTeX.
  %%  The device of using TeX to print the grid in proof versions
  %%  is apparently not in LaTeX but has been since used by
  %%  others.  Many thanks to to Raymond Seroul (Strassbourg) for
  %%  pointing it out to me back in 1989.
  %%  (It was used in a Plain TeX hack of the picture
  %%  environment by Desarmenien, Ostromoukhov, and Seroule
  %%  that seems not to have been released.)
  %%
 %%%  POSTINGS (soon!!): anonymous ftp
  %%  ---  ftp 28.146.7.200 (alias shape.mps.ohio-state.edu);
  %%  login: anonymous;  password: <anything>;
  %%  directory pub/osutex
  %%  ---  ftp 130.84.128.100 (alias rsovax.circe.fr);
  %%  login: anonymous; password: <anything>; directory
  %%  [anonymous.siebenmann]
  %%
 %%%% DOCUMENTATION:
  %%  --- see Labelfig.doc
  %% (may be included at end, after \endinput)
  %%
 %%%% EXAMPLE OF USAGE:
  %%    \input LabelFig.tex
  %%    \SetLabels
  %%      (.3*.7) first label\\
  %%         % label will go to position .3 from left
  %%         % and .7 from bottom
  %%      \L(.61*.333) $\Lambda_1\leq\Gamma$\\
  %%         % \L places left edge of label
  %%         % (rather than the center)
  %%         % similarly use \R for right edge;
  %%         % and \B for bottom or \T for top
  %%      \T\R(.3*.7) last label \\
  %%    \endSetLabels
  %%    \ShowGrid
  %%         % lays grid on figure to label;
  %%         % delete for final printing
  %%    \AffixLabels{\BoxedEPSF{MyFigure}}
  %%         % argument of \AffixLabels#1 should be a TeX box
  %%         % covering the inserted figure to be labelled.
  %%         % (Here \BoxedEPSF is the figure insertion macro
  %%         % of my package \BoxedEPS.tex (same sources)
  %%         % for inserting encapsulated PostScript graphics.
  %%         % But any other means of inserting
  %%         % the figure can be used.)
 
 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 %%%%% FORBID REREADING %%%%%
  %
  \ifx \LabelFigloaded\MYundefined
  \else
    \immediate\write16{ !!! LabelFig.tex ALREADY loaded.}
  \endinput\fi
 
  \def\LabelFigloaded{\relax}% now loaded
 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%% Beyond this point we use some control sequences
  %%% that are 'padlocked'  with @ of category 11
 
  \chardef\LabelFigCatAt\the\catcode`\@
  \catcode`\@=11
 
 %%temporarily suppress Plain's logging of allocations
 \let\LabelFigwlog@ld\wlog
 \def\wlog#1{\relax}
 
 
 \ifx\\\MYundefined@
    \let\\\relax
 \fi
 
 \def\N@wif{\csname newif\endcsname }
 \def\Temp@ {\N@wif\ifIN@}
 \ifx\INN@\MYundefined@
    \else \let\Temp@\relax
 \fi
 \Temp@
 
  %%% \IN@0#1@#2@ : Is 1st exp of #1 in 1st exp of #2 ??
   %% Answer in \ifIN@
  %\newif\ifIN@
  \def\IN@{\expandafter\INN@\expandafter}
  \long\def\INN@0#1@#2@{\long\def\NI@##1#1##2##3\ENDNI@
    {\ifx\m@rker##2\IN@false\else\IN@true\fi}%
     \expandafter\NI@#2@@#1\m@rker\ENDNI@}
  \def\m@rker{\m@@rker}
 
   %%% \Shifted@@#1#2#3 puts #3 in \hbox
   %% leaves basepoint as is
   %% then translates ink only by dims #1,#2
   %% with Postscript convention
   %% For simplicity use only on scrunched boxes
 \def\Shifted@@#1#2#3{\setbox0=\hbox{#3}%
   \raise -\dp0\vbox {\kern-#2%
       \hbox {\kern#1\box0\kern-#1}%
           \kern#2}}
 
 
 
 \newcount\gridcount
 \newbox\auxGridbox@ \newbox\hGridbox@ \newbox\vGridbox@
 \newbox\Labelbox@ \newbox\auxLabelbox@
 \newbox\Coordinatebox@
 \newtoks\Labeltoks@
 \newdimen\Wdd@ \newdimen\Htt@
 
 \def\hRule@{\advance\gridcount -2%
   \vskip-.2pt\hrule\vskip-.2pt\vfil
   \llap{\smash{\raise -2.5pt
     \hbox{.\number\gridcount\kern2pt}}}%
           \vskip-.2pt\hrule\vskip-.2pt\vfil}
 
 \def\vRule@{\advance\gridcount 2%
   \hskip-.2pt\vrule\hskip-.2pt\hfil
   \setbox\auxGridbox@=\vbox to 0pt
      {\vskip \Htt@\vskip 2pt
        \hbox{\kern-3.5pt.\number\gridcount}\vss}%
      \wd\auxGridbox@=0pt \box\auxGridbox@
   \hskip-.2pt\vrule\hskip-.2pt\hfil}
 
 \def\PlaceGrid@@{\gridcount=10%
  \setbox\hGridbox@=%
    \hbox{\hbox{\GridSpider@{\hskip-.4pt\vrule}%
             \vbox to \Htt@{\offinterlineskip\parindent=\z@%
                \GridSpider@{\vskip-.4pt\hrule}\vfil
                \hRule@\hRule@\hRule@\hRule@
                  \vskip-.2pt\hrule\vskip-.2pt\vfil
                \hbox to \Wdd@{\hfil}%
             \GridSpider@{\hrule\vskip-.4pt}}%
         \GridSpider@{\vrule\hskip-.4pt}}}%
  \gridcount=0%
  \setbox\vGridbox@=
     \hbox{\vbox{\offinterlineskip\parindent=0pt\hsize=0pt
       \GridSpider@{\vskip-.4pt\hrule}%
             \hbox to \Wdd@{%
                \GridSpider@{\hskip-.4pt\vrule}\hfil
                \vtop to \Htt@{\vfil}%
                     \vRule@\vRule@\vRule@\vRule@
                     \hskip-.2pt\vrule\hskip-.2pt\hfil
             \GridSpider@{\vrule\hskip-.4pt}}%
         \GridSpider@{\hrule\vskip-.4pt}}}%
  %
  \wd\hGridbox@=0pt\ht\hGridbox@=0pt
  \wd\vGridbox@=0pt\ht\vGridbox@=0pt
  %
 \hbox{\box\hGridbox@\box\vGridbox@}%
  }
 
 \def\SetLabels#1\endSetLabels{%
   \Labeltoks@={#1}}
 
 \def\GridSpider@#1{#1}
 \let\PlaceGrid@\relax
 \def\ShowGrid{\let\PlaceGrid@\PlaceGrid@@}
 
 \def\bAdjust@@{%
     \setbox\auxLabelbox@=\hbox{\raise \dp\auxLabelbox@
            \box\auxLabelbox@}}
 \def\bAdjust@{\let\vAdjust@\bAdjust@@}
 
 \def\tAdjust@@{%
     \setbox\auxLabelbox@=\hbox{\raise-\ht\auxLabelbox@
            \box\auxLabelbox@}}
 \def\tAdjust@{\let\vAdjust@\tAdjust@@}
 
 \let\vAdjust@\relax
 
 \def\lAdjust@{\let\hAdjust@\rlap}
 \def\rAdjust@{\let\hAdjust@\llap}
 
 \let\hAdjust@\relax\let\vAdjust@\relax
 
 \def\FetchLabel@#1(#2*#3)#4\\#5\endFetchLabel@{%
     %\globaldefs=1\setbox0=\hbox{#1}\globaldefs=0%
     \ignorespaces#1\unskip
     \Labeltoks@={#5}%
     \setbox\auxLabelbox@=%
        \hbox to 0pt{\hss\ignorespaces\hAdjust@
          {\ignorespaces#4\unskip}\hss}%
     \vAdjust@
     \let\hAdjust@\relax\let\vAdjust@\relax
     \setbox\Labelbox@=\hbox to 0pt{%
       \box\Labelbox@
       \Shifted@@{#2\Wdd@}{#3\Htt@}{\box\auxLabelbox@}}%
     \ht\Labelbox@=0pt\dp\Labelbox@=0pt
     }
 
 \def\PlaceLabels@@{\bgroup\def\Cr@{\\}%
     \let\L\lAdjust@\let\R\rAdjust@
     \let\B\bAdjust@\let\T\tAdjust@
     \loop
     \IN@0\Cr@ @\the\Labeltoks@ @\relax
     \ifIN@ \expandafter
       \FetchLabel@\the\Labeltoks@\endFetchLabel@
     \repeat
     \box\Labelbox@\egroup}%
 
 \let \PlaceLabels@\PlaceLabels@@
 
 \def\AffixLabels#1{\setbox\Coordinatebox@=\hbox{#1}%
      \Wdd@=\wd\Coordinatebox@ \Htt@=\ht\Coordinatebox@
      \advance\Htt@ \dp \Coordinatebox@
      \hbox{\copy\Coordinatebox@\kern-\Wdd@%
           \Shifted@@{0pt}{-\dp\Coordinatebox@}%
            {\PlaceGrid@\PlaceLabels@}%
           \kern\Wdd@}}
 
 %%% Restoring
   \let\wlog\LabelFigwlog@ld %%restore logging
   \catcode`\@=\LabelFigCatAt  %%12 or 13
 
  \endinput
 
 %% end of  LabelFig.tex