summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/pinlabel/pinlabel.sty
blob: 7ea568bc523817c69ab5643fb802e7493a3487a8 (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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
%%%%                   pinlabel.sty     Version 1.1
%%%% 
%%%%                     Written by Colin Rourke 
%%%%   
%%%%              Based on geompsfi.sty by Silvio Levy
%%%%              Based on psfig.sty by Trevor Darrell
%%%%
%%%%        Copyright 2006 Mathematical Sciences Publishers (MSP)
%%%% 
%%%%                              NOTICE
%%%%  
%%%%  This package may be distributed and/or modified under the 
%%%%  conditions of the LaTeX Project Public License, either version 
%%%%  1.3 of this license or (at your option) any later version.
%%%%  The latest version of this license is in
%%%%
%%%%           http://www.latex-project.org/lppl.txt
%%%%
%%%%  and version 1.3 or later is part of all distributions of LaTeX
%%%%  version 2005/12/01 or later.
%%%%
%%%%  This package has the LPPL maintenance status `maintained' and is
%%%%  currently maintained by MSP:  contact@mathscipub.org 
%%%%
%%%%  It comprises two files: pinlabel.sty (this file) and the manual
%%%%  pinlabdoc.pdf where full documentation may be found.
%%%% 
%%%% 
%%%%  pinlabel.sty  is designed for inserting perfectly formatted TeX
%%%%       labels in eps or pdf files for inclusion in documents.
%%%%       It uses the coordinates provided by ghostview (or gv) to
%%%%       position the label and reads the relevant bounding box
%%%%       information from the eps file (which must be provided: if
%%%%       your figure exists only as a pdf file, then run pdf2eps).
%%%%       Several features are provided which facilitate perfect 
%%%%       first-time label positioning, of which the most important
%%%%       is auto-spacing, which sets the label a predetermined gap
%%%%       away from the figure object which is being labelled.  The
%%%%       gap is \hair (a TeX dimension, preset to 3pt, but settable
%%%%       on the fly) and the direction of the spacing is chosen 
%%%%       automatically.  The result is consistent and eye-pleasing
%%%%       spacing.
%%%%       In use, read the position of the object that you wish to
%%%%       label and do not guess the position of the actual label.
%%%%       Then choose the orientation of the label (eg [tr] which
%%%%       means top-right) and the label will automatically be set
%%%%       so that top-right of the label bounding box is set one  
%%%%       \hair away from the object being labelled.
%%%%       
%%%%       
%%%%  pinlabel.sty  was written specifically for the use of editors and  
%%%%       authors of MSP papers and is the recommended package for
%%%%       use for labelling diagrams for MSP.
%%%%        
%%%%  pinlabel.sty  is a revised version of geomsfig.sty with improved 
%%%%       functionality and simpler syntax.  The old syntax remains
%%%%       available for backwards compatibility, see below.
%%%% 
%%%%  new syntax: \pinlabel {label} by x-pin y-pin at x-location y-location
%%%%       and   \pinlabel* {label} by x-pin y-pin at x-location y-location
%%%% 
%%%%       where "x-pin y-pin" is the point in intrinsic coords in label
%%%%       space where we are placing the pin and "x-location y-location" 
%%%%       is the point in diagram space (in PS points as read in gv) where
%%%%       the label is pinned.  \pinlabel uses \hair autospacing \pinlabel*
%%%%       does not.  See the manual for full details. 
%%%%       \mathsurround is set to 0pt for parsing the label
%%%% 
%%%%  options:  "by x-pin y-pin" may be omitted the default is 0 0
%%%%       orientation commands [r], [l] etc may replace "by x-pin y-pin"
%%%%                            [r] is right-centre (same as "by 0 1") etc
%%%%       a manual adjustment "<x-adj, y-adj>" may be added before "at"
%%%%       or directly after the label
%%%%          
%%%%  Examples  \pinlabel $a^b$ [l] <-2pt,1pt> at 231 47 
%%%%  Same as   \pinlabel $a^b$ by -1 0  <-2pt,1pt> at 231 47 
%%%%  Same as   \pinlabel $a^b$ <-2pt,1pt> [l] at 231 47 
%%%%  Same as   \pinlabel $a^b$ <-2pt,1pt> by -1 0  at 231 47 
%%%%           
%%%%           which pins "$a^b$" by centre-left at 231 47 with two 
%%%%           adjustments: \hair (autospacing) and then (-2pt,1pt) manual
%%%%
%%%%           \pinlabel* {A nice figure} [Bl] <-5pt,0pt> at 231 47 
%%%%           
%%%%           which pins "A nice figure" by baseline-left at 231 47  
%%%%           with one adjustment: (-5pt,0pt)
%%%%
%%%%  Full list of orientation commands:  r=right, l=left, t=top, b=bottom
%%%%       and B=baseline,  default is centre and any sensible combination 
%%%%       of two commands may be give (in either order) eg 
%%%%       [tl]=[lt]=top-left of label bounding box
%%%% 
%%%%  NB the commands are syntax sensitive and use spaces as separators so
%%%%       they DON'T work with \obeyspaces set.    Braces must be placed 
%%%%       around labels containing spaces but may be omitted if there are
%%%%       no spaces in the label code (see the examples above and below).
%%%%
%%%%  Label instructions go either in the file inside \labellist 
%%%%       ... \endlabellist  or in a separate .lab file (ie if fig 
%%%%       is fig4-1.eps or .ps, then labels go in \figdir/fig4-1.lab 
%%%%       where \figdir/ is the directory containing fig4-1.eps).  
%%%%       The \labellist overrides a .lab file.
%%%%       \labellist ... \endlabellist can be given at any time before 
%%%%       the next figure, but typically will be included in the figure 
%%%%       code, as in the following example.
%%%%
%%%%  Here is a complete example of a relabelled figure:
%%%%
%%%%          \begin{figure}[ht!]
%%%%          \labellist\small\hair 2.5pt
%%%%          \pinlabel {$\partial _1 X$} by 1 0 at 156 426
%%%%          \pinlabel {$\partial _2 X$} by -1 1 at 334 429
%%%%          \pinlabel $X_1$ at 431 513 
%%%%          \pinlabel $X_2$ at 428 460 
%%%%          \pinlabel $H_X$ [lb] at 311 622
%%%%          \pinlabel* $H_X'$ [tr] <-1.5pt,-2pt> at 178 370
%%%%          \endlabellist
%%%%          \centerline{\psfig{file=\figdir/decomp,width=3in}}
%%%%          \caption{Labelling the boundary components of $X$}
%%%%          \label{Fig:decomp}
%%%%          \end{figure}
%%%%
%%%%  The actual figure can be included by using either psfig or 
%%%%      graphicx.  psfig is used by the code, but graphicx 
%%%%      commands are translated automatically, so in the above
%%%%      example the alternative code:
%%%%
%%%%          \centerline{\includegraphics[width=3in]{\figdir/decomp}}
%%%%          
%%%%      would produce identical results.  Automatic translation ONLY  
%%%%      takes place is a labellist is present, so if you use a .lab
%%%%      file then you MUST use the psfig syntax.
%%%%          
%%%%          
%%%%                            VERY IMPORTANT   
%%%%                            ==============
%%%%      
%%%%      The file extension MUST NOT be given.  The program will find
%%%%      the correct file (\figdir/decomp.eps or .ps or .pdf).
%%%%      
%%%%      READ THE BUGS below before using \includegraphics with pinlabel.
%%%%      
%%%%          
%%%%  old syntax: \setlabel is unchanged (but \mathsurround is set to 0pt) 
%%%%       \setlabel* is a new variant which sets \hair to 0pt (no 
%%%%       autospacing) and an optional manual adjustment may be added
%%%%       eg:
%%%%
%%%%           \setlabel<-2pt,-1pt>{a^b}{321}{33}{1}{1}
%%%%           \setlabel*<-2pt,-1pt>{a^b}{321}{33}{1}{1}
%%%%           \setlabel{a^b}{321}{33}{1}{1}
%%%%           \setlabel*{a^b}{321}{33}{1}{1}
%%%%       
%%%%       the first uses autospacing and adds a (-2pt,-1pt) manual
%%%%       adjustment;  the second uses just the manual adjustment,
%%%%       the third just autospacing and the fourth nothing.
%%%%
%%%%       old and new syntax may be mixed in a label list and given 
%%%%       either in a .lab file or inside \labellist ... \endlabellist
%%%%
%%%%    ***Users of geomsfig note the change to \mathsurround.  If you 
%%%%       do not use it, there will be no change in label positioning.
%%%%       If you do, labels may move a small amount horizontally.***
%%%%
%%%% 
%%%% !!!NBNB label is in horizontal mode in new syntax and math mode in old!!!
%%%% 
%%%%
%%%%  BUGS:  NO spaces are permitted in the file argument of \psfig
%%%%      Autotranslation of \includegraphics[]{} means that no
%%%%      spaces are permitted in the file argument to \includegraphics
%%%%      Eg  \includegraphics[width=4in]{ foo } will produce errors,
%%%%      use \includegraphics[width=4in]{foo}.  Spaces are permitted
%%%%      with other arguments.
%%%%          
%%%%      Many of the options in graphicx are not supported.  The     
%%%%      supported ones are:  width, height, scale, bbllx, bblly
%%%%      bburx, bbury and clip.  The syntax for clip is "clip=".
%%%%      Replace "keepaspectratio=true" by "proportional=".
%%%%      
%%%%      The command \reallyincludegraphics will force the use of
%%%%      graphicx (ie cancel autotranslation).  Since code will use 
%%%%      graphicx automatically if there is no labellist present, 
%%%%      \reallyincludegraphics will only be needed if a labellist 
%%%%      has already been given for a later figure.
%%%%     
%%%%      \graphicspath{} is not supported.  Use \figdir instead.
%%%%              
%%%%
%%%%     Automatic configuration for dvips and pdflatex is included 
%%%%     in this file.  No support is provided for other drivers.
%%%% 
%%%%     NB \psfig ouputs a vbox, which is not centred in latex' {center} 
%%%%     environment.  Either use \centerline{} or type \leavevmode
%%%%     before \psfig{..}.  The translator adds \leavevmode for 
%%%%     \includegraphics, which therefore centres correctly as usual
%%%%     in the {center} environment.
%%%%
%%%%  PLAIN TeX compatibility:  uses miniltx.tex and works with dvips 
%%%%     but NOT with pdftex.  For pdf output from plain TeX use dvips 
%%%%     followed by ps2pdf.                        
%%%%
%%%%

\edef\atcatcode{\the\catcode`\@} \catcode`@=11
\def\@message#1{\immediate\write16{#1}}

\newif\ifoldlabels \oldlabelsfalse
\expandafter\ifx\csname @ifundefined\endcsname\relax 
\long\def\@ifundefined#1#2#3{\expandafter\ifx\csname
  #1\endcsname\relax#2\else#3\fi}

\def\@iden#1{#1}
%\newdimen\@tempdima
\alloc@1\dimen\dimendef\insc@unt\@tempdima
\def\@warning#1{\@message{Warning: #1.}}
\fi

%%% if not latex \input miniltx (for plain tex compatibility) 
\@ifundefined{RequirePackage}{\input miniltx}{\relax}

%%% make sure graphicx is loaded
\RequirePackage{graphicx}
\let\@includegraphics@\includegraphics %%% for auto translation of graphicx
\let\reallyincludegraphics\@includegraphics@  %%% to override translation

\@ifundefined{ps@init}{}{\endinput}

\@ifundefined{hyperactivelabels}{\let\hyperactivelabels\relax}{}

%%% in-line label list handling %%%
\long\def\labellist#1\endlabellist{\gdef\thelabellist{#1}}
\let\thelabellist\relax %%%% initialise

\newif\if@topspecials %false for Rokicki's dvips: \special is at bottom of box
                      % true for dvitps, dvi2ps

\newif\ifdvi\dvitrue
\@ifundefined{pdfoutput}{}{\ifnum\pdfoutput>0 \dvifalse\fi}
\ifdvi
%%% start of driver.chg
{\catcode`\p=12 \catcode`\t=12 \gdef\read@PT#1pt{#1}}
\def\sp@topt#1#2{\psfig@dimen=#2sp \if\psfig@dimen=0pt \psfig@dimen=1sp\fi
  \edef#1{\expandafter\read@PT \the\psfig@dimen}}
\def\sp@tobp#1#2{\psfig@dimen=#2sp \if\psfig@dimen=0pt \psfig@dimen=1sp\fi
  \expandafter\@tempdima\expandafter\read@PT \the\psfig@dimen bp
  \advance\psfig@dimen-.5 \@tempdima \multiply\psfig@dimen 2
  \edef#1{\expandafter\read@PT \the\psfig@dimen}}
\def\ps@init{}
\def\ps@begin{\sp@tobp\@tempa\@p@sbbllx \sp@tobp\@tempb\@p@sbblly
  \sp@tobp\@tempc\@p@sbburx \sp@tobp\@tempd\@p@sbbury
  \sp@tobp\@tempe{\@p@swidth0} \sp@tobp\@tempf{\@p@sheight0}
  \special{PSfile=\@p@sfile\space llx=\@tempa\space lly=\@tempb\space 
     urx=\@tempc\space ury=\@tempd\space rwi=\@tempe\space rhi=\@tempf}}
% rwi is the total width, in tenths of the units used for the
% other dimensions (this is dvips's brain damage)
\def\ps@prolog{}
\def\ps@clip{}                     %
\def\ps@include{}                  %
\def\ps@postlog{}                  %
\def\ps@end{}                      %
%%% end of driver.chg
\else
\@ifundefined{usepackage}{\@message{}
\@message {!!! pinlabel.sty cannot be used for direct pdf output except with latex !!!}
\@message {For pdf outlut from plain tex use dvips and ps2pdf}
\@message{}}{}
%%% start of gpdftex.chg
{\catcode`\p=12 \catcode`\t=12 \gdef\read@PT#1pt{#1}}
\def\sp@topt#1#2{\psfig@dimen=#2sp \if\psfig@dimen=0pt \psfig@dimen=1sp\fi
  \edef#1{\expandafter\read@PT \the\psfig@dimen}}
\def\sp@tobp#1#2{\psfig@dimen=#2sp \if\psfig@dimen=0pt \psfig@dimen=1sp\fi
  \expandafter\@tempdima\expandafter\read@PT \the\psfig@dimen bp
  \advance\psfig@dimen-.5 \@tempdima \multiply\psfig@dimen 2
  \edef#1{\expandafter\read@PT \the\psfig@dimen}}
\def\ps@init{}
\def\ps@begin{\sp@tobp\@tempa\@p@sbbllx \sp@tobp\@tempb\@p@sbblly
  \sp@tobp\@tempc\@p@sbburx \sp@tobp\@tempd\@p@sbbury
  \sp@tobp\@tempe\@p@swidth \sp@tobp\@tempf\@p@sheight%
\edef\foobar{[width=\@p@swidth sp,height=\@p@sheight sp]{\@p@dffile}}%
%,viewport=\@tempa\space\@tempb\space\@tempc\space\@tempd
\@message{\string\@includegraphics@\foobar}%
\rlap{\smash{\expandafter\@includegraphics@\foobar}}%
}
% rwi is the total width, in tenths of the units used for the
% other dimensions (this is dvips's brain damage)
\def\ps@prolog{}
\def\ps@clip{}                     %
\def\ps@include{}                  %
\def\ps@postlog{}                  %
\def\ps@end{}                      %
%%%% end of gpdftex.chg
\fi

%%%% graphicx translation
%%%% first set a flag to detect use of graphicx and initialise
%%%% the default is \relax (graphicx not used) any other value
%%%% means graphicx is used
\let\inc@graph@flag\relax 

%%%% redefine \includegraphics to mimic \psfig ONLY IF a labellist is present
\def\includegraphics{\ifx\thelabellist\relax\let\next\@includegraphicsnolist@%
\else\let\next\@includegraphics@list@\fi\next}

\let\@includegraphicsnolist@\reallyincludegraphics

\def\@includegraphics@list@{\def\inc@graph@flag{1}%
\@ifnextchar[{\includegraphicswithoptions}{\includegraphicsplain}}
\def\includegraphicswithoptions[#1]#2{\leavevmode\psfig{file=#2,#1}}
\def\includegraphicsplain#1{\leavevmode\psfig{file=#1}}


\newcount\psfc@a
\newcount\psfc@b
\newcount\psfc@c
\newcount\psfc@d
\newcount\psfc@e
\newcount\psfc@f
\newcount\psfc@g
\newcount\psfc@h
\newcount\psfc@i
\newcount\psfc@j
\newcount\psscale@count
\newtoks\psfigtoks@
% A dimension register for temporarily storing a dimension in
% \@pDimenToSpNumber.
\newdimen\psfig@dimen
%
%\newwrite\@unused
%\def\typeout#1{{\let\protect\string\immediate\write\@unused{#1}}}

% Identifying message is here.
% \typeout{psfig/tex 1.4.gcg / TeXPS}\fi
%
% @psdo control structure -- similar to Latex @for.
% I redefined these with different names so that psfig can
% be used with TeX as well as LaTeX, and so that it will not 
% be vunerable to future changes in LaTeX's internal
% control structure.
\def\@nnil{\@nil}
\def\@empty{}
\def\@psdonoop#1\@@#2#3{}
\def\@psdo#1:=#2\do#3{\edef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
    \expandafter\@psdoloop#2,\@nil,\@nil\@@#1{#3}\fi}
\def\@psdoloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else
       #5\def#4{#2}\ifx #4\@nnil \else#5\@ipsdoloop #3\@@#4{#5}\fi\fi}
\def\@ipsdoloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
       \let\@nextwhile=\@psdonoop \else
      #4\relax\let\@nextwhile=\@ipsdoloop\fi\@nextwhile#2\@@#3{#4}}
\def\@tpsdo#1:=#2\do#3{\xdef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
    \@tpsdoloop#2\@nil\@nil\@@#1{#3}\fi}
\def\@tpsdoloop#1#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
       \let\@nextwhile=\@psdonoop \else
      #4\relax\let\@nextwhile=\@tpsdoloop\fi\@nextwhile#2\@@#3{#4}}
% 
\def\psdraft{%
  \def\@psdraft{0}
  %\typeout{draft level now is \@psdraft \space.}
}
\def\psfull{%
  \def\@psdraft{100}
  %\typeout{draft level now is \@psdraft \space.}
}
\psfull
\newif\if@prologfile
\newif\if@postlogfile
\newif\if@noisy
\def\pssilent{%
  \@noisyfalse
}
\def\psnoisy{%
  \@noisytrue
}
%\psnoisy
\pssilent
% These are for the option list: 
%  a specification of the form a = b maps to calling \@p@@sa{b}.
\newif\if@bbllx
\newif\if@bblly
\newif\if@bburx
\newif\if@bbury
\newif\if@height
\newif\if@width
\newif\if@rheight
\newif\if@rwidth
\newif\if@clip
\newif\if@proportional
\newif\if@scale
\newif\if@verbose
\def\@p@@sclip#1{\@cliptrue}
\def\@p@@sproportional#1{\@proportionaltrue}
\def\@p@@sfile#1{% 
  %\typeout{file is #1}
  \def\@filestem{#1}%
  \def\@p@dffile{#1.pdf}%
  \def\@labfile{#1.lab}% 
}
\let\@p@@sfigure\@p@@sfile
% \@pDimenToSpNumber
% ==================
% Convert a dimension into scaled points.
% #1: the name of macro which will expand to the dimension in
%     scaled points, without the unit 'sp' though, i.e. as a pure
%     integer.
% #2: the dimension (not a dimension register, use
%     \the if dimension is stored in a dimension register).
\def\@pDimenToSpNumber #1#2{% 
  \psfig@dimen = #2\relax
  \edef#1{\number\psfig@dimen}%
}
\def\@p@@sbbllx#1{% 
  %\typeout{bbllx is #1}
  \@bbllxtrue
  \@pDimenToSpNumber{\@p@sbbllx}{#1}% 
}
\def\@p@@sbblly#1{% 
  %\typeout{bblly is #1}
  \@bbllytrue
  \@pDimenToSpNumber{\@p@sbblly}{#1}% 
}
\def\@p@@sbburx#1{%
  %\typeout{bburx is #1}
  \@bburxtrue
  \@pDimenToSpNumber{\@p@sbburx}{#1}% 
}
\def\@p@@sbbury#1{%
  %\typeout{bbury is #1}
  \@bburytrue
  \@pDimenToSpNumber{\@p@sbbury}{#1}% 
}
\def\@p@@sheight#1{%
  \@heighttrue
  \@pDimenToSpNumber{\@p@sheight}{#1}% 
  %\typeout{Height is \@p@sheight}
}
\def\@p@@swidth#1{%
  %\typeout{Width is #1}
  \@widthtrue
  \@pDimenToSpNumber{\@p@swidth}{#1}% 
}
\def\@p@@srheight#1{%
  %\typeout{Reserved height is #1}
  \@rheighttrue
  \@pDimenToSpNumber{\@p@srheight}{#1}% 
}
\def\@p@@srwidth#1{%
  %\typeout{Reserved width is #1}
  \@rwidthtrue
  \@pDimenToSpNumber{\@p@srwidth}{#1}% 
}
\def\@p@@ssilent#1{% 
  \@verbosefalse
}
\def\@p@@sscale #1{% 
  \def\@p@scale{#1}%
  \@scaletrue
}

\def\@p@@sprolog#1{\@prologfiletrue\def\@prologfileval{#1}}
\def\@p@@spostlog#1{\@postlogfiletrue\def\@postlogfileval{#1}}
\def\@cs@name#1{\csname #1\endcsname}
\def\@setparms#1=#2,{\def\@tempa{#2}\ifx\@tempa\@empty
  \@warning{bad syntax (missing = or extra comma) in argument of \string\psfig}%
  \else\@@setparms#1=#2,\fi}
\def\@@setparms#1=#2=,{\@cs@name{@p@@s#1}{#2}}
%
% Initialize the defaults.
%
\def\ps@init@parms{%
  \@bbllxfalse \@bbllyfalse
  \@bburxfalse \@bburyfalse
  \@heightfalse \@widthfalse
  \@rheightfalse \@rwidthfalse
  \@scalefalse
  \def\@p@sbbllx{}\def\@p@sbblly{}%
  \def\@p@sbburx{}\def\@p@sbbury{}%
  \def\@p@sheight{}\def\@p@swidth{}%
  \def\@p@srheight{}\def\@p@srwidth{}%
  \def\@p@sfile{}%
  \def\@labfile{}%
  \def\@p@scost{10}%
  \def\@sc{}%
  \@prologfiletrue
  \@postlogfilefalse
  \@clipfalse
  \@proportionalfalse
  \if@noisy
    \@verbosetrue
  \else
    \@verbosefalse
  \fi
}

%%%% space bug fixes 
\expandafter\let\csname @p@@s scale \endcsname\@p@@sscale
\expandafter\let\csname @p@@sscale \endcsname\@p@@sscale
\expandafter\let\csname @p@@s scale\endcsname\@p@@sscale

\expandafter\let\csname @p@@s file \endcsname\@p@@sfile
\expandafter\let\csname @p@@sfile \endcsname\@p@@sfile
\expandafter\let\csname @p@@s file\endcsname\@p@@sfile

\expandafter\let\csname @p@@s width \endcsname\@p@@swidth
\expandafter\let\csname @p@@swidth \endcsname\@p@@swidth
\expandafter\let\csname @p@@s width\endcsname\@p@@swidth

\expandafter\let\csname @p@@s rwidth \endcsname\@p@@srwidth
\expandafter\let\csname @p@@srwidth \endcsname\@p@@srwidth
\expandafter\let\csname @p@@s rwidth\endcsname\@p@@srwidth

\expandafter\let\csname @p@@s height \endcsname\@p@@sheight
\expandafter\let\csname @p@@sheight \endcsname\@p@@sheight
\expandafter\let\csname @p@@s height\endcsname\@p@@sheight

\expandafter\let\csname @p@@s rheight \endcsname\@p@@srheight
\expandafter\let\csname @p@@srheight \endcsname\@p@@srheight
\expandafter\let\csname @p@@s rheight\endcsname\@p@@srheight

\expandafter\let\csname @p@@s bbllx \endcsname\@p@@sbbllx
\expandafter\let\csname @p@@sbbllx \endcsname\@p@@sbbllx
\expandafter\let\csname @p@@s bbllx\endcsname\@p@@sbbllx

\expandafter\let\csname @p@@s bblly \endcsname\@p@@sbblly
\expandafter\let\csname @p@@sbblly \endcsname\@p@@sbblly
\expandafter\let\csname @p@@s bblly\endcsname\@p@@sbblly

\expandafter\let\csname @p@@s bburx \endcsname\@p@@sbburx
\expandafter\let\csname @p@@sbburx \endcsname\@p@@sbburx
\expandafter\let\csname @p@@s bburx\endcsname\@p@@sbburx

\expandafter\let\csname @p@@s clip \endcsname\@p@@sclip
\expandafter\let\csname @p@@sclip \endcsname\@p@@sclip
\expandafter\let\csname @p@@s clip\endcsname\@p@@sclip

\expandafter\let\csname @p@@s proportional \endcsname\@p@@sproportional
\expandafter\let\csname @p@@sproportional \endcsname\@p@@sproportional
\expandafter\let\csname @p@@s proportional\endcsname\@p@@sproportional

%
% Go through the options setting things up.
%
\def\parse@ps@parms#1{%
   \@psdo\@psfiga:=#1\do
     {\expandafter\@setparms\@psfiga=,}% 
}

\newif\ifno@file
\newif\ifno@bb
\newif\ifnot@eof
\newif\if@bbmatch
\newread\ps@stream
\newread\lab@stream
\newcount\@linecount
\newcount\maxheaderlines
\maxheaderlines=100

%
% Scan header of file, looking for ``BoundingBox'' line
%
\def\scan@header{%
  \openin\lab@stream=\@labfile
  \openin\ps@stream=\@filestem.ps
  \ifeof\ps@stream
    \relax\closein\ps@stream
    \openin\ps@stream=\@filestem.eps
    \ifeof\ps@stream
      \relax %needed here so the \@warning won't cause trouble
      \@warning{cannot open \@filestem.ps or .eps}
      \no@filetrue
    \else
      \relax
      \edef\@p@sfile{\@filestem.eps}
    \fi 
  \else
    \relax
    \edef\@p@sfile{\@filestem.ps}
  \fi
  \ifno@file\else
    \not@eoftrue
    \ifno@bb \@bbmatchfalse \else \@bbmatchtrue \fi
    \catcode`\%=12
    \catcode`\:=12 % in case punctuation is active (e.g., under french.sty)
    \@linecount=\maxheaderlines
    \loop
      \read\ps@stream to \line@in
      \global\psfigtoks@=\expandafter{\line@in}
      \ifeof\ps@stream \not@eoffalse \fi
      %\typeout{ looking at :: \the\psfigtoks@ }
      \if@bbmatch \else \@bbtest{\psfigtoks@} \fi
      \if@bbmatch \not@eoffalse \fi 
      \advance\@linecount-1
      \ifnum\@linecount=0 \not@eoffalse \fi
    \ifnot@eof \repeat
  \fi
  \catcode`\%=14
}  

% '% ' becomes a regular character for a very short time.
{ 
  \catcode`\%=12
  \catcode`\:=12
  \gdef\@bbtest#1{\expandafter\@bb@\the#1%%BoundingBox:\@bbtest\@bb@}
  \global\long\def\@bb@#1%%BoundingBox:#2#3\@bb@{\ifx\@bbtest#2
    \else\@bbmatchtrue\expandafter\bb@cull\the\psfigtoks@\fi}
}

\def\bb@cull#1:{\expandafter\bb@@cull\@iden}
\long\def\bb@@cull#1 #2 #3 #4 {%
  \@pDimenToSpNumber{\@p@sbbllx}{#1bp}%
  \@pDimenToSpNumber{\@p@sbblly}{#2bp}%
  \@pDimenToSpNumber{\@p@sbburx}{#3bp}%
  \@pDimenToSpNumber{\@p@sbbury}{#4bp}%
  \no@bbfalse
}

% Compute \@bbw and \@bbh, the width and height of the
% bounding box.
\def\compute@bb{%
  \no@bbfalse
  \if@bbllx \else \no@bbtrue \fi
  \if@bblly \else \no@bbtrue \fi
  \if@bburx \else \no@bbtrue \fi
  \if@bbury \else \no@bbtrue \fi
  \scan@header 
  \ifno@file
  \else
    \ifno@bb
      \@warning{no bounding box found in \@p@sfile}
      \no@filetrue
    \else
  % Now compute the size of the bounding box.
      \psfc@c=\@p@sbburx
      \psfc@b=\@p@sbbury
      \advance\psfc@c by -\@p@sbbllx
      \advance\psfc@b by -\@p@sbblly
      \edef\@bbw{\number\psfc@c}
      \edef\@bbh{\number\psfc@b}
      %\typeout{\string\compute@bb: bbh = \@bbh, bbw = \@bbw}
    \fi
  \fi
}

%
% \in@hundreds performs #1 * (#2 / #3) correct to the hundreds,
%    then leaves the result in \@result.
%
% note: #3 should be a big number, or a multiple of 10.
%
\def\in@hundreds #1#2#3{% 
  \psfc@g=#2
  \psfc@d=#3
  \divide\psfc@d 10
  \psfc@a=\psfc@g  % First two digits #2/#3.
  \divide\psfc@a by \psfc@d
  \psfc@f=\psfc@a
  \multiply\psfc@f by \psfc@d
  \advance\psfc@g by -\psfc@f
  \multiply\psfc@g by 10
  \psfc@f=\psfc@g  % Third digit of #2/#3.
  \divide\psfc@f by \psfc@d
  \psfc@j=\psfc@f
  \multiply\psfc@j by \psfc@d
  \advance\psfc@g by -\psfc@j
  \multiply\psfc@g by 10
  \psfc@j=\psfc@g  % Third digit.
  \divide\psfc@j by \psfc@d
  \psfc@h=#1\psfc@i=0
  \psfc@e=\psfc@h
  \multiply\psfc@e by \psfc@a
  \advance\psfc@i by \psfc@e
  \psfc@e=\psfc@h
  \divide\psfc@e by 10
  \multiply\psfc@e by \psfc@f
  \advance\psfc@i by \psfc@e
  %
  \psfc@e=\psfc@h
  \divide\psfc@e by 100
  \multiply\psfc@e by \psfc@j
  \advance\psfc@i by \psfc@e
  \divide\psfc@i 10
  %
  \edef\@result{\number\psfc@i}
}
% Scale a value #1 by the current scaling factor and reassign the new
% scaled value.
\def\@ScaleInHundreds #1{% 
  \in@hundreds{#1}{\@p@scale}{100}%
  \edef#1{\@result}% 
}
% 
%
% Compute width from height.
\def\compute@wfromh{%
  % computing : width = height * (bbw / bbh)
  \in@hundreds{\@p@sheight}{\@bbw}{\@bbh}%
  %\typeout{ \@p@sheight * \@bbw / \@bbh, = \@result }
  \edef\@p@swidth{\@result}%
  %\typeout{w from h: width is \@p@swidth}%
}
%
% Compute height from width.
%
\def\compute@hfromw{%
  % computing : height = width * (bbh / bbw)
  \in@hundreds{\@p@swidth}{\@bbh}{\@bbw}%
  %\typeout{ \@p@swidth * \@bbh / \@bbw = \@result }
  \edef\@p@sheight{\@result}%
  %\typeout{h from w : height is \@p@sheight}%
}
%
% Compute height and width when both are given and proportionality
% must be preserved.
%
\def\compute@minhw{%
  \in@hundreds{\@p@swidth}{\@bbh}{\@bbw}%
  \ifnum\@p@sheight<\@result
    \in@hundreds{\@p@sheight}{\@bbw}{\@bbh}%
    \edef\@p@swidth{\@result}%
  \else
    \edef\@p@sheight{\@result}%
  \fi
}
%
% Compute height and width, i.e. \@p@sheight and \@p@swidth.
%
\def\compute@handw{%
  % If height is given.
  \if@height 
    % If width is given
    \if@width
      \if@proportional
        \compute@minhw
      \fi
    \else
      % Height, no width: compute width.
      \compute@wfromh
    \fi
  \else 
    % No height.
    \if@width
      % Width is given, no height though: compute it.
      \compute@hfromw
    \else
      % Neither width no height is give.
      \edef\@p@sheight{\@bbh}
      \edef\@p@swidth{\@bbw}
    \fi
  \fi
}
% Compute the amount of space to reserve. Unless defined
% using rheight and rwidth when \psfig is called, these values
% default to \@p@sheight and \@p@swidth.
\def\compute@resv{%
  \if@rheight \else \edef\@p@srheight{\@p@sheight} \fi
  \if@rwidth \else \edef\@p@srwidth{\@p@swidth} \fi
}
%
%
% \psfig
% ======
% usage: \psfig{file=, height=, width=, bbllx=, bblly=, bburx=, bbury=,
%      rheight=, rwidth=, clip=, scale=, proportional=}
%
% "clip=" and "proportional=" are switches and take no value, 
% but the `=' must be present.
%
\def\partest{\par}
\def\psfig#1{% 
  \vbox {%
    \offinterlineskip
    \ps@init@parms
    \parse@ps@parms{#1}%
    % Compute any missing sizes.
    \compute@bb
                \ifno@file\vbox{\hbox{\footnotesize{\tt\@filestem.\{ps,eps\}}
                    not found (or no BBox)}}%
                \else
    \compute@handw
    \compute@resv
    \if@scale
      \ifx\inc@graph@flag\relax\else  %% \graphicx syntax used so
          \psfig@dimen=100sp          %% multiply scale by 100
          \psfig@dimen=\@p@scale\psfig@dimen
          \def\@p@scale{\number\psfig@dimen}
          \let\inc@graph@flag\relax   %% reset 
      \fi
      %\if@verbose \typeout{psfig: scaling by \@p@scale}\fi
      %\if@verbose \typeout{psfig: scaling by \@p@scale}\fi
      % We now scale the width and height as reported to the PS printer.
      \@ScaleInHundreds{\@p@swidth}% 
      \@ScaleInHundreds{\@p@sheight}% 
      \@ScaleInHundreds{\@p@srwidth}% 
      \@ScaleInHundreds{\@p@srheight}% 
    \fi
    %
    \ifnum\@p@scost<\@psdraft
      %\if@verbose \typeout{psfig: including \@p@sfile \space}\fi
      \if@topspecials\do@specials\fi
      % Create a vbox to reserve the proper amount of space for the figure.
      \vbox to \@p@srheight sp{%
        \hbox to \@p@srwidth sp{}%
        \vss
      }%
      \if@topspecials\else\do@specials\fi
      \ifx\thelabellist\relax   %%% no labellist so look for .lab file
        \ifeof\lab@stream
        \else{%
        \hyperactivelabels
        \not@eoftrue
        \loop
          \read\lab@stream to \line@in \ifx\line@in\partest\else\line@in\fi
          \ifeof\lab@stream \not@eoffalse \fi
        \ifnot@eof \repeat
      }\fi
      \else
        \hyperactivelabels\thelabellist      %%% use labellist and
        \global\let\thelabellist\relax       %%% reset for next figure
        \ifeof\lab@stream 
        \else{
	  \@message{}
	  \@message{I have found both a labellist AND a .lab file for \@p@sfile.}
	  \@message{I am using the labellist.}
	  \@message{If this is not what you want, then edit out the labellist.}
	  \@message{}
	 }\fi
       \fi
    \else
      % Draft mode: reserve the space for the figure and print the path name.
      \vbox to \@p@srheight sp{%
        \hbox to \@p@srwidth sp{%
          \if@verbose
            \@p@sfile
          \fi
        }%
        \vss
      }%
    \fi
  \fi
  }%
}

\def\do@specials{\ps@init\ps@begin
  \if@clip 
     %\if@verbose \typeout{(clip)} \fi 
    \ps@clip \fi
  \if@prologfile \ps@prolog \fi \ps@include \if@postlogfile \ps@postlog \fi
  \ps@end}

\newbox\label@box
\newdimen\x@lab \newdimen\y@lab
\newdimen\x@aux \newdimen\y@aux
\newdimen\hair\hair=3pt

%%%%% version without math mode, with \mathsurround set to 0pt 
%%%%%             and final manual adjustment <#6,#7>
\def\@setlabel@#1#2#3#4#5#6#7{%
  \setbox\label@box\hbox{\mathsurround 0pt\ignorespaces#1}%
  \x@lab.5\wd\label@box \x@lab#4\x@lab
  \y@lab.5\ht\label@box\advance\y@lab.5\dp\label@box \y@lab#5\y@lab 
% rotate lab clockwise by 22.5 degrees to get aux
  \x@aux.92388\x@lab \advance\x@aux.38268\y@lab
  \y@aux-.38268\x@lab \advance\y@aux.92388\y@lab
% choose 
  \ifdim\x@aux>0pt
    \ifdim\y@aux>0pt
      \ifdim\x@aux>\y@aux\advance\x@lab.7071\hair\advance\y@lab.7071\hair
      \else\advance\y@lab\hair\fi
    \else
      \ifdim\x@aux>-\y@aux\advance\x@lab\hair
      \else\advance\x@lab.7071\hair\advance\y@lab-.7071\hair\fi
    \fi
  \else
    \ifdim\y@aux>0pt
      \ifdim\x@aux>-\y@aux\advance\x@lab-.7071\hair\advance\y@lab.7071\hair
      \else\advance\x@lab-\hair\fi
    \else
      \ifdim\x@aux>\y@aux\advance\y@lab-\hair
      \else
        \ifdim\x@aux<0pt 
           \advance\x@lab-.7071\hair\advance\y@lab-.7071\hair\fi
      \fi
    \fi
  \fi
  \advance\x@lab.5\wd\label@box
  \advance\y@lab.5\ht\label@box\advance\y@lab.5\dp\label@box
  \x@aux=#2bp \ifoldlabels \else \advance\x@aux by -\@p@sbbllx sp \fi
  \y@aux=#3bp \ifoldlabels \else \advance\y@aux by -\@p@sbblly sp \fi
  \in@hundreds{\x@aux}{\@p@swidth}{\@bbw}
  \edef\@xpos{\@result}
  \in@hundreds{\y@aux}{\@p@sheight}{\@bbh}
  \edef\@ypos{\@result}
  \vbox to 0pt{%
    \vss\hbox to\@p@srwidth sp{\hskip \@xpos sp \hskip-\x@lab \hskip #6
    \box\label@box\hss}\vskip \@ypos sp \vskip-\y@lab \vskip #7}}


%%%% old syntax: \setlabel and variant \setlabel* (\hair set 0pt) 
%%%%             both start in math mode for back-compatibility:
\def\setlabel{\@ifnextchar*{\setlabel@nohair}{\setlabel@hair}}

%%%% manual adjustment added?
\def\setlabel@nohair*%
{\@ifnextchar<{\setlabel@nohair@adj}{\setlabel@nohair@noadj}}
\def\setlabel@hair%
{\@ifnextchar<{\setlabel@hair@adj}{\setlabel@hair@noadj}}

\def\setlabel@nohair@noadj#1#2#3#4#5%
{{\hair 0pt\@setlabel@{$#1$}{#2}{#3}{#4}{#5}{0pt}{0pt}}}
\def\setlabel@nohair@adj<#1,#2>#3#4#5#6#7%
{{\hair 0pt\@setlabel@{$#3$}{#4}{#5}{#6}{#7}{#1}{#2}}}

\def\setlabel@hair@noadj#1#2#3#4#5%
{\@setlabel@{$#1$}{#2}{#3}{#4}{#5}{0pt}{0pt}}
\def\setlabel@hair@adj<#1,#2>#3#4#5#6#7%
{\@setlabel@{$#3$}{#4}{#5}{#6}{#7}{#1}{#2}}


%%% \pinlabel macro starts here

%%% set up two flags for killing autospacing and using baseline
%%% and initialise: 
%%% \relax is default ie \hair used but baseline not used
%%% any other value means \hair not used but baseline used
\let\hair@flag\relax\let\baseline@flag\relax  

%%% define four control sequences to carry the auxiliary information
%%% and set to default values
\def\@labxpos@{0}\def\@labypos@{0}%
\def\@xadj@{0pt}\def\@yadj@{0pt}

%%%% endgame
\def\finally@pinlabel #1 {\@ifnextchar a%
{\finally@pinlabel@ {#1} }{\@message{}%
\@message{There is something wrong with your syntax for label #1;}
\@message{you must finish with " at XXX YYY " : the "at" and spaces are important!}
\@message{I'm going to try to ignore this label: don't blame me if there are some}
\@message{funny numbers in your diagram and later labels are out-of-position.}
\@message{}}}

\def\finally@pinlabel@ #1 at #2 #3 {%
\ifx\hair@flag\relax%
\@setlabel@{\ifx\baseline@flag\relax\the@label\else\smash{\the@label}\fi}%
{#2}{#3}{\@labxpos@}{\@labypos@}{\@xadj@}{\@yadj@}%   
\else 
{\hair 0pt \@setlabel@{\ifx\baseline@flag\relax\the@label\else\smash{\the@label}\fi}%
{#2}{#3}{\@labxpos@}{\@labypos@}{\@xadj@}{\@yadj@}}
\fi
%%%% don't forget to reset the flags etc to default values
\let\hair@flag\relax\let\baseline@flag\relax%
\def\@labxpos@{0}\def\@labypos@{0}%
\def\@xadj@{0pt}\def\@yadj@{0pt}}

%%%% start to parse the argument
%%%% is this a starred form or not?
\def\pinlabel{\@ifnextchar*%
{\pin@nohair}{\@pinlabel@}}
\def\pin@nohair* #1 {\def\hair@flag{0}\@pinlabel@ {#1} }

%%%% store the label for safety then
%%%% is there any label position information?
\def\@pinlabel@ #1 {\def\the@label{#1}\@ifnextchar a%
{\finally@pinlabel {#1} }{\@pinlabel@@ {#1} }}  

%%%% are we using "by" or [ or going directly to <..,..>
\def\@pinlabel@@ #1 {\@ifnextchar [%
{\pin@by@letters {#1} }{\@@pinlabel@@ {#1} }}

\def\@@pinlabel@@ #1 {\@ifnextchar b
{\pin@by@numbers {#1} }{\@@pinlabel@@@ {#1} }}

\def\@@pinlabel@@@ #1 {\@ifnextchar <%
{\pin@with@adj {#1} }{\@message{}%
\@message{I don't understand your positioning information for label #1 and shall}
\@message{ignore it; or perhaps your label has a space and needs braces.}
\finally@pinlabel {#1} }}

%%%% pin@with@adj recycles from the top (to allow <Xpt,Ypt> to come first)
\def\pin@with@adj #1  <#2,#3> {%
\def\@xadj@{#2}\def\@yadj@{#3}
\@pinlabel@ {#1} }

%%%% we are using letters, is there adjustment?
\def\pin@by@letters #1 [#2] {\@ifnextchar <%
{\pin@by@letters@with@adj {#1} [#2] }{\pin@by@letters@no@adj {#1} [#2] }}

%%%% we are using numbers, is there adjustment?
\def\pin@by@numbers #1 by #2 #3 {\@ifnextchar <%
{\pin@by@numbers@with@adj {#1} by #2 #3 }{\pin@by@numbers@no@adj {#1} by #2 #3 }}

\def\pin@by@numbers@with@adj #1 by #2 #3 <#4,#5> at #6 #7{%
\def\@labxpos@{#2}\def\@labypos@{#3}%
\def\@xadj@{#4}\def\@yadj@{#5}
\finally@pinlabel {#1} at #6 #7}

\def\pin@by@numbers@no@adj #1 by #2 #3 at #4 #5{%
\def\@labxpos@{#2}\def\@labypos@{#3}%
\def\@xadj@{0pt}\def\@yadj@{0pt}
\finally@pinlabel {#1} at #4 #5}

%%% read the letter pin positions to a control sequence
\def\pin@by@letters@no@adj #1 [#2] {%
\expandafter\ifx\csname position@#2\endcsname\relax
\@message{}
\@message{Unkown position code [#2]; I shall ignore it.}
\@message{}\else
\csname position@#2\endcsname\fi
\finally@pinlabel {#1} }

\def\pin@by@letters@with@adj #1 [#2] <#3,#4> {%
\expandafter\ifx\csname position@#2\endcsname\relax
\@message{}
\@message{Unkown position code [#2]; I shall ignore it.}
\@message{}\else
\csname position@#2\endcsname\fi
\def\@xadj@{#3}\def\@yadj@{#4}
\finally@pinlabel {#1} }


%%%% final task: parse the letter pin positions
\def\position@t{\def\@labxpos@{0}\def\@labypos@{1}}
\def\position@b{\def\@labxpos@{0}\def\@labypos@{-1}}
\def\position@l{\square@left\def\@labxpos@{-1}\def\@labypos@{0}}
\def\position@r{\square@right\def\@labxpos@{1}\def\@labypos@{0}}
\def\position@B{\def\baseline@flag{1}\def\@labxpos@{0}\def\@labypos@{0}}
\def\position@rt{\square@right\def\@labxpos@{1}\def\@labypos@{1}}
\def\position@tr{\square@right\def\@labxpos@{1}\def\@labypos@{1}}
\def\position@br{\square@right\def\@labxpos@{1}\def\@labypos@{-1}}
\def\position@rb{\square@right\def\@labxpos@{1}\def\@labypos@{-1}}
\def\position@lt{\square@left\def\@labxpos@{-1}\def\@labypos@{1}}
\def\position@tl{\square@left\def\@labxpos@{-1}\def\@labypos@{1}}
\def\position@bl{\square@left\def\@labxpos@{-1}\def\@labypos@{-1}}
\def\position@lb{\square@left\def\@labxpos@{-1}\def\@labypos@{-1}}
\def\position@lB{\square@left\def\baseline@flag{1}%
\def\@labxpos@{-1}\def\@labypos@{0}}
\def\position@Bl{\square@left\def\baseline@flag{1}%
\def\@labxpos@{-1}\def\@labypos@{0}}
\def\position@rB{\square@right\def\baseline@flag{1}%
\def\@labxpos@{1}\def\@labypos@{0}}
\def\position@Br{\square@right\def\baseline@flag{1}%
\def\@labxpos@{1}\def\@labypos@{0}}

%%%% \square@left and \square@right are hacks to force diagonal
%%%% autospacing for the corner letter pin positions

\def\square@left{%
\setbox\label@box\hbox{\mathsurround 0pt\ignorespaces\the@label}%
\y@lab\ht\label@box\advance\y@lab\dp\label@box\let\old@label\the@label
\def\the@label{\hbox to \y@lab{\old@label\hss}}}

\def\square@right{%
\setbox\label@box\hbox{\mathsurround 0pt\ignorespaces\the@label}%
\y@lab\ht\label@box\advance\y@lab\dp\label@box\let\old@label\the@label
\def\the@label{\hbox to \y@lab{\hss \old@label}}}

%%%% end of \pinlabel macro

\catcode`@=\atcatcode

\endinput

%%%%% History:  Version 1.1 released 25 March 2006
%%%%% 28/Mar/06: bugfixes and code to detect mathematica/illustrator deleted
%%%%%  5/Apr/06: bugfix and extra utility: <Xpt,Ypt> can come first
%%%%% 20/Apr/06: \includegraphics uses graphicx if no labellist (Naom)
%%%%%  1/May/06: bugfix to \includegraphics code 
%%%%% 23/Oct/06: LPPL license added (for CTAN)