summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/pstring/pstring.sty
blob: 9e5f098fa686f367c069a79553f95f29b3909645 (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
% Copyright 2007 by William Blum (http://william.famille-blum.org/software/latex/index.html)
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{pstring}[2008/04/29 Package for representing strings with pointers]

\newif\ifRequestPSengine
\newif\ifRequestPGFengine
\newif\ifLoadPSengine
\newif\ifLoadPGFengine
\newif\ifwriteprologuefile


\DeclareOption{pstricks}{\RequestPSenginetrue}
\DeclareOption{pgf}{\RequestPGFenginetrue}
\ProcessOptions

\edef\TheAtCode{\the\catcode`\@}
\catcode`\@=11


\RequirePackage{ifpdf}

\ifRequestPSengine
    \ifpdf
        \errmessage{You have requested to use the pstricks engine when you have loaded the pstring package,
        moreover you seem to be running pdflatex to produce a pdf file. Since pstricks is not compatible with pdflatex,
        I automatically switch to the pgf engine.}
        \LoadPGFenginetrue
        \LoadPSenginefalse
    \else
        \LoadPSenginetrue
    \fi
\fi

\ifRequestPGFengine
    \LoadPGFenginetrue
\fi

% If no engine is selected then take PStricks if latex is running and PGF if it is pdflatex
\ifRequestPGFengine \else\ifRequestPSengine \else
\ifpdf
    \LoadPGFenginetrue
\else
    \LoadPSenginetrue
\fi
\fi\fi


\ifLoadPSengine
    % Implement pointing string using pstricks
    \RequirePackage{pstricks}
    \RequirePackage{pst-node}

    % Declare the use of the prologue file (for dvips)
    \pstheader{pstring.pro} %\@addtofilelist{pstring.pro} \special{header=pstring.pro}

    % Set the default drawing engine to pstricks
    \gdef\@engine{PS}
\fi

\ifLoadPGFengine
    % Implement pointing string using pgf
    \RequirePackage{pgfcore}
    \usepgfmodule{shapes}

    % Set the default drawing engine to PGF
    \gdef\@engine{PGF}
\fi


% routines used to draw the nodes and arrow
\gdef\pstr@drawArrow{\csname pstr@\@engine @drawArrow\endcsname}
\gdef\pstr@drawNode{\csname pstr@\@engine @drawNode\endcsname}
\gdef\pstr@createNodeAndArrow{\csname pstr@\@engine @createNodeAndArrow\endcsname}
\gdef\pstr@printText{\csname pstr@\@engine @printText\endcsname}

% external commands available to the package user (in pgf and pstricks mode)
\gdef\pstr{\csname pstr@\@engine\endcsname}
\gdef\Pstr{\csname Pstr@\@engine\endcsname}
\gdef\pstrSetLabelStyle#1{\gdef\pstr@LabelStyle{#1}}
\gdef\pstrSetArrowColor#1{\gdef\pstr@DefaultArrowColor{#1}}
\gdef\pstrSetArrowAngle#1{\gdef\pstr@DefaultArrowAngle{#1}}
\gdef\pstrSetArrowLabel#1{\gdef\pstr@DefaultArrowLabel{#1}}
\gdef\pstrSetArrowLineWidth#1{\gdef\pstr@ArrowLineWidth{#1}}
\gdef\pstrSetArrowLineStyle#1{\gdef\pstr@DefaultArrowLineStyle{#1}}
\gdef\pstr@linestyledashed{dashed}
\gdef\pstr@linestyledotted{dotted}
\gdef\pstr@linestylesolid{solid}
\gdef\pstr@linestylenone{none}


% Default styles and arrow parameters
\pstrSetLabelStyle{\color{blue} \tiny}
\pstrSetArrowLabel{}
\pstrSetArrowColor{orange}
\pstrSetArrowAngle{45}
\pstrSetArrowLineWidth{0.3pt}
\pstrSetArrowLineStyle{\pstr@linestylesolid} % none, solid, dashed or dotted

\def\@nil{}


% define a command \percentchar which can be used to write the percent symbol '%' in the .pro file
\chardef\letter = 11 \chardef\other = 12
{\catcode`\% = \other \gdef\percentchar{%}}%
\def^^L{\par
}%



\ifLoadPSengine

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Version of the package relying on PSTRICKS

% If the postscript prologue file does not exist then it needs to be created.
\IfFileExists{pstring.pro}{\writeprologuefilefalse}{\writeprologuefiletrue}

\ifwriteprologuefile
  \newwrite\prologuefile
  \immediate\openout\prologuefile = pstring.pro
  \newlinechar = `\^^J
  \immediate\write\prologuefile{\percentchar }
  \immediate\write\prologuefile{\percentchar PostScript prologue for pstring.sty.}
  \immediate\write\prologuefile{\percentchar For distribution, see pstring.^^J}
\fi


% Calling the following macro with \pstr@def{PROCNAME}<PSCODE> will:
%    - create a ps procedure with name PROCNAME and code PSCODE and writes it to the prologue file,
%    - define a latex macro with name \PROCNAME containing PROCNAME (the name of the ps procedure).
%
% We could have chosen to include the definitions of our custom Postscript procedures in the dvi file itself
% but as a drawback the postscript code would be copied for each use of the procedure and the
% resulting ps file would be huge.
\def\pstr@def#1<#2>{%
    \ifwriteprologuefile%
        % Add the code to the postscript prologue  file
        \immediate\write\prologuefile{/#1 { #2 } def}
    \fi
    % prologue present: just dump the name of the postscript command (the code being already defined in the .pro file)
    \@namedef{#1}{#1 }
}



\pstr@def{pstr@GetEdge}< dup 0 eq { pop begin
%%%%% WB: the cosinus and the sinus are set to 1 and 0 which correspond to a direction going toward the top of the page. This way, the node position computed by the procedure NodePos will correspond exactly to the middle of the top line of the node box (the coordinates returned by NodePos are relative to the center of the node box).
  %1 0 NodeMtrx dtransform CM idtransform
  %exch atan sub dup sin /Sin ED cos /Cos ED /NodeSep ED NodePos
%%%%% BECOMES
 pop 1 /Sin ED 0 /Cos ED /NodeSep ED NodePos
%%%%%
NodeMtrx dtransform CM idtransform
end }
{ 1 eq {{exch}} {{}} ifelse /Do ED pop XYPos } ifelse >


\pstr@def{pstr@GetEdgeA}< NodeSepA AngleA NodeA NodeSepTypeA \pstr@GetEdge
%%%% WB: The offset is not computed the same way as in pst-node: it is an horizontal offset instead of an offset along the line (AB). Thus the line
%   OffsetA AngleA AddOffset yA add /yA1 ED xA add /xA1 ED
%%%% becomes:
yA add /yA1 ED xA add OffsetA add /xA1 ED
% This last line computes the absolute position of the connector ending by adding up its relative position to the position of the center of the node box plus the horizontal offset.
%%%%
>

\pstr@def{pstr@GetEdgeB}< NodeSepB AngleB NodeB NodeSepTypeB \pstr@GetEdge
% OffsetB AngleB AddOffset yB add /yB1 ED xB add /xB1 ED
 yB add /yB1 ED xB add OffsetB sub /xB1 ED
>


\pstr@def{pstr@NCCurve}<%
%%%%%% Redirect the call to \pstr@GetEdgeA  and \pstr@GetEdgeB instead of \tx@GetEdgeA and \tx@GetEdgeB
\pstr@GetEdgeA \pstr@GetEdgeB
xA1 xB1 sub yA1 yB1 sub Pyth
2 div dup
3 -1 roll mul /ArmA ED mul /ArmB ED
/ArmTypeA 0 def /ArmTypeB 0 def GetArmA GetArmB
xA2 yA2 xA1 yA1 tx@Dict begin ArrowA end
xB2 yB2 xB1 yB1 tx@Dict begin ArrowB end
curveto
/LPutVar [ xA1 yA1 xA2 yA2 xB2 yB2 xB1 yB1 ] cvx def
/LPutPos { t LPutVar BezierMidpoint } def
/HPutPos { { HPutLines } HPutCurve } def
/VPutPos { { VPutLines } HPutCurve } def>


\ifwriteprologuefile
  \immediate\write\prologuefile{^^J\percentchar END pstring.pro^^J}
  \immediate\closeout\prologuefile
\fi



% We define a new pstricks command: ncHarc.
% The H is for "horizontal". It acts as ncarc
% except that the angle parameter
% angleA (resp. angleB) specifies the angle between the X axis
% and the tangent to the arrow at point A (resp B) instead
% of the angle between the line (AB) and the tangent of the arrow  at A (or B).
%
% This kind of arc is not really usefull for graphs however it is easier to specify angles like this for links in justified sequences.
\def\ncHarc{\pst@object{ncHarc}}
\def\ncHarc@i{\check@arrow{\ncHarc@ii}}
\def\ncHarc@ii#1#2{\nc@object{Open}{#1}{#2}{.5}{%
%yB yA sub xB xA sub \tx@Atan
  180
\psk@arcangleA\space sub /AngleA ED
\psk@arcangleB\space %sub 180 add
/AngleB ED
\psk@ncurvB\space \psk@ncurvA\space \pstr@NCCurve
%\tx@NCCurve
}}

% Create a link using psttricks
\newcommand{\link}{\@ifstar
                     \linkStar%
                     \linkNoStar%
}
\newcommand{\linkNoStar}[2][]{
\edef\options{#1}
\ifx\options\@empty
\def\opt{[linecolor=\pstr@DefaultArrowColor,linestyle=\pstr@DefaultArrowLineStyle,linewidth=\pstr@ArrowLineWidth,offset=-2pt,nodesep=0pt,arcangleA=-#2, arcangleB=-#2]}
\else
\def\opt{[linecolor=\pstr@DefaultArrowColor,linestyle=\pstr@DefaultArrowLineStyle,linewidth=\pstr@ArrowLineWidth,offset=-2pt,nodesep=0pt,arcangleA=-#2, arcangleB=-#2,#1]}
\fi
\expandafter\ncarc\opt{->}
}

% the starred version uses ncHarc instead of ncarc.
\newcommand{\linkStar}[2][]{
\edef\options{#1}
\ifx\options\@empty
\def\opt{[linecolor=\pstr@DefaultArrowColor,linestyle=\pstr@DefaultArrowLineStyle,linewidth=\pstr@ArrowLineWidth,offsetA=0pt,offsetB=2pt,nodesep=1pt,arcangleA=#2, arcangleB=#2]}
\else
\def\opt{[linecolor=\pstr@DefaultArrowColor,linestyle=\pstr@DefaultArrowLineStyle,linewidth=\pstr@ArrowLineWidth,offsetA=0pt,offsetB=2pt,nodesep=1pt,arcangleA=#2, arcangleB=#2, #1]}
\fi
\expandafter\ncHarc\opt{->}
}

% Label the last link created
\newcommand{\lnklabel}{\@ifstar
                     \lnklabelStar%
                     \lnklabelNoStar%
}
\newcommand{\lnklabelStar}[1]{\mput*{\mbox{\pstr@LabelStyle $#1$}}}
\newcommand{\lnklabelNoStar}[1]{\Bput[1pt]{\mbox{\pstr@LabelStyle $#1$}}}




\newbox\pstr@tempbox
\newdimen\pstr@tempdim


%%%%%%%%%%%%%%%%
%% First way of creating a pointing string: user command \Pstr
%  \Pstr[0.4cm][1pt]{ (b) this (a-b,45) that }

\gdef\Pstr@PS{\@ifnextchar[{\Pstr@PS@i}{\Pstr@PS@ii[0cm][1pt]}}
% Pstr with one optional parameter
\gdef\Pstr@PS@i[#1]{\@ifnextchar[{\Pstr@PS@ii[#1]}{\Pstr@PS@ii[#1][1pt]}}
% Pstr with two optional parameters
% [#1] specifies the amount of vertical space to add to the box
% containing the pointing string.
% [#2] specifies the distance between the node and the arc
% #3 contains the specification of the nodes and pointers of the sequence.
\gdef\Pstr@PS@ii[#1][#2]#3{%
\begingroup%
 \setlength\pstr@tempdim{#1}%
 \def\pstr@arcoptions{#2}%
 \setbox\pstr@tempbox=\hbox{$\Pstr@ParseSpecification#3(@-@){}\@nil$}%
 \ht\pstr@tempbox\pstr@tempdim%
 \leavevmode\box\pstr@tempbox%
\endgroup%
}

% Prints some text in the sequence (using PSTricks)
\gdef\pstr@PS@printText#1{#1}%

% Draw a node with PStricks:
%   #1 text preceding the node (ignored)
%   #2 name of the node
%   #3 content of the node
\def\pstr@PS@drawNode#1#2#3{%
  \rnode{#2}{#3}%
}

% Draw an arrow with PStricks
%    #1 source node name
%    #2 target node name
%    #3 angle
%    #4 label
%    #5 arc color
%    #6 line style
\def\pstr@PS@drawArrow#1#2#3#4#5#6{%
  \link*[linecolor=#5,linestyle=#6,nodesep=\pstr@arcoptions]{#3}{#1}{#2} \lnklabel{#4}%
}

% Create the node and store the commands for the creation of the link in the list of tokens tok0
%  (to be executed when the sequence specification is completely parsed)
%
%  #1 text to be printed out before the node content
%  #2 source node name
%  #3 target node name
%  #4 arrow angle
%  #5 link label
%  #6 link color
%  #7 node content
\gdef\pstr@PS@createNodeAndArrow#1#2#3#4#5#6#7{%
    \pstr@drawNode{#1}{#2}{#7}%
    \pstr@drawArrow{#2}{#3}{#4}{#5}{#6}{\pstr@DefaultArrowLineStyle}%
}


%%%%%%%%%%%%%%%%
%%Second way of creating a pointing string: user command \pstr
%  \pstr[raiseamount][nodesep]{ sequencespecification }
% example:
%  \pstr[0.4cm][1pt]{ \nd(b) this \nd(a-b,45) that }

\gdef\pstr@PS{\@ifnextchar[{\pstr@PS@i}{\pstr@PS@ii[0cm][1pt]}}
% pstr with one optional parameter
\gdef\pstr@PS@i[#1]{\@ifnextchar[{\pstr@PS@ii[#1]}{\pstr@PS@ii[#1][1pt]}}
% pstr with two optional parameters
\gdef\pstr@PS@ii[#1][#2]#3{%
\begingroup%
 \setlength\pstr@tempdim{#1}%
 \def\pstr@arcoptions{#2}%
 \pstr@defineUserCommands% define the command \nd and \txt that the package user can use to define the sequence
 \setbox\pstr@tempbox\hbox{$#3$}%
 \ht\pstr@tempbox\pstr@tempdim%
 \leavevmode\box\pstr@tempbox%
\endgroup%
}
\fi


\ifLoadPGFengine

\newdimen\pstr@mydimA
\newdimen\pstr@mydimB
\newdimen\pstr@mydimC
\newtoks\pstr@ptrlist

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Version of the package relying on PGF (the Tikz interface is not used)

% Draw a node with PGF:
%   #1 text preceding the node
%   #2 name of the node
%   #3 content of the node
\def\pstr@PGF@drawNode#1#2#3{%
  \pgfsetfillcolor{white!100}%
  \pgfset{inner xsep=1pt}%
  \pgfset{inner ysep=0.6pt}%
%  \pgfnode{rectangle}{base west}{\color{black}${}#1{}$}{#2@Next}{\pgfusepath{discard}}%
%  \pgftransformshift{\pgfpointanchor{#2@Next}{base east}}%
  \pgfnode{rectangle}{base west}{\color{black}${}#3{}$}{#2}{\pgfusepath{discard}}%
  \pgftransformshift{\pgfpointanchor{#2}{base east}}%
}

% Prints some text in the sequence (using PGF)
\gdef\pstr@PGF@printText#1{%
    \def\text{#1}%
    \ifx\text\empty%
    \else%
      \pgfsetfillcolor{white!100}%
      \pgfset{inner xsep=1pt}%
      \pgfset{inner ysep=0pt}%
      \pgfnode{rectangle}{base west}{\color{black}${}#1{}$}{dummy}{\pgfusepath{discard}}%
      \pgftransformshift{\pgfpointanchor{dummy}{base east}}%
    \fi%
}


% Draw an arrow with PGF
%    #1 source node name
%    #2 target node name
%    #3 angle
%    #4 label
%    #5 line color
%    #6 line style
\def\pstr@PGF@drawArrow#1#2#3#4#5#6{%
    \def\angleB{#3}%
    \count255=180 \advance \count255 by -\angleB%
    \def\angleA{\number\count255}%
    \def\ptA{\pgfpointdiff{\pgfpoint{0.5pt}{-\pstr@arcoptions}}{\pgfpointanchor{#1}{north}}}% shift the end of the arrow a bit to the right
    \def\ptB{\pgfpointdiff{\pgfpoint{0pt}{-\pstr@arcoptions}}{\pgfpointanchor{#2}{north}}}%
    \def\bendpt{ \pgfpointintersectionoflines%
    {\ptA}{\pgfpointadd{\ptA}{\pgfpointpolar{\angleA}{1cm}}}%
    {\ptB}{\pgfpointadd{\ptB}{\pgfpointpolar{\angleB}{1cm}}}}%

    \pgfextracty{\pstr@mydimA}{\ptA}%
    \pgfextracty{\pstr@mydimB}{\ptB}%
    \pgfextracty{\pstr@mydimC}{\bendpt}%
    \def\maxdim{\ifdim\pstr@mydimA>\pstr@mydimB \pstr@mydimA \else \pstr@mydimB \fi}%
    \advance \pstr@mydimC by \maxdim%
    \divide \pstr@mydimC by 2 % mydimC now contains (max(y_A, y_B) + y_C)/2

    % control points
    \def\cptC{ \pgfpointintersectionoflines{\ptA}{\bendpt}%
    {\pgfpoint{0pt}{\pstr@mydimC}}{\pgfpoint{16pt}{\pstr@mydimC}}}%
    \def\cptD{ \pgfpointintersectionoflines{\ptB}{\bendpt}%
    {\pgfpoint{0pt}{\pstr@mydimC}}{\pgfpoint{16pt}{\pstr@mydimC}}}%


    %%%% draw using two halves of parabolas
      %\pgfpathmoveto{\ptA}\pgfpathparabola{\pgfpointdiff{\ptA}{\bendpt}}{\pgfpointdiff{\bendpt}{\ptB}}%
    %%%%
    %%%% draw using lines
      %\pgfpathmoveto{\ptA}\pgflineto{\bendpt}\pgflineto{\ptB}%
    %%%%
    %%%% draw using bezier curves
      \pgfpathmoveto{\ptA}\pgfpathcurveto{\cptC}{\cptD}{\ptB}%
    %%%%
    \pgfsetcolor{#5}%

    \def\linestyle{#6}
    \ifx\linestyle\pstr@linestyledashed
        \pgfsetdash{{3pt}{3pt}}{0cm}%
        \pgfusepath{stroke}%
    \else
        \ifx\linestyle\pstr@linestyledotted
            \pgfsetdash{{1pt}{3pt}}{0cm}%
            \pgfusepath{stroke}%
        \else
            \ifx\linestyle\pstr@linestylenone

            \else%solid
                \pgfsetdash{}{0pt}%
                \pgfusepath{stroke}%
            \fi
        \fi
    \fi


   %%% Put the label on the link if there is one
    \def\label{#4}%
    \ifx\label\empty%
    \else%
%      \pgfsetfillcolor{white!100}%
%      \pgfset{inner xsep=1pt}%
      \pgfset{inner ysep=1pt}%
      %\pgftransformshift{\bendpt} % position the label at the bendpoint
      \pgftransformshift{\pgfpointcurveattime{0.5}{\ptA}{\cptC}{\cptD}{\ptB}} % position the label at half-way on the curve
      \pgfnode{rectangle}{south}{\color{black} {\pstr@LabelStyle $\label$}}{}{\pgfusepath{discard}}%
    \fi%
}





%%%%%%% First way of creating a pointing string: user command \Pstr
%%%%%%% (version for the PGF engine mode)
%%%%
%%%%  Examples of use:
%%%%        \Pstr[0.4cm][1pt]{ (b) this (a-b,45:label) that }
%%%%        \Pstr[0.4cm][1pt]{ (b) this (a-b,45) that }
%%%%        \Pstr[0.4cm][1pt]{ (b) this (a-b) that }
%%%%        \Pstr[0.4cm][1pt]{ (b) this (a) that }

\gdef\Pstr@PGF{\@ifnextchar[{\Pstr@PGF@i}{\Pstr@PGF@ii[0cm][1pt]}}
% Pstr with one optional parameter
\gdef\Pstr@PGF@i[#1]{\@ifnextchar[{\Pstr@PGF@ii[#1]}{\Pstr@PGF@ii[#1][1pt]}}
% Pstr with two optional parameters
% [#1] ignored in the PGF mode
% [#2] ignored in the PGF mode
\gdef\Pstr@PGF@ii[#1][#2]#3{%
\begin{pgfpicture}%
  \def\pstr@arcoptions{#2}%
  \pgfsetbaseline{0pt}%
  \pgfset{minimum width=0cm}%
  \pgfset{minimum height=0pt}%
  \pgfset{inner xsep=0pt}%
  \pgfset{inner ysep=0.3pt}%
  \pgfsetarrows{-stealth}%
  \pgfsetlinewidth{\pstr@ArrowLineWidth}%
  \pstr@ptrlist={}% Create an empty list of links.
  \Pstr@ParseSpecification#3(@-@){}\@nil%
  \the\pstr@ptrlist% dump the list of links.
\end{pgfpicture}%
}

% Create the node and store the commands for the creation of the link in the list of tokens tok0
%  (to be executed when the sequence specification is completely parsed)
%
%  #1 text to be printed out before the node content
%  #2 source node name
%  #3 target node name
%  #4 arrow angle
%  #5 link label
%  #6 line color
%  #7 node content
\gdef\pstr@PGF@createNodeAndArrow#1#2#3#4#5#6#7{
    %\pstr@createpgfnode{s}{s}{\mbox{C[1($#1$)  2($#2$) 3($#3$) 4(#4) 5(#5) 6(#6)]} }
    \pstr@drawNode{#1}{#2}{#7}%
    % add the arrow to the list of arrows
    \toks0={\pstr@drawArrow{#2}{#3}{#4}{#5}{#6}{\pstr@DefaultArrowLineStyle}}%
    \edef\act{\noexpand\pstr@ptrlist={\the\pstr@ptrlist \the\toks0}}%
    \act%
}


%%%%%%% Second way of creating a pointing string: user command \pstr
%%%%%%% (version for the PGF engine mode)
%%%%
%%%% Syntax:
%%%%  \pstr[raiseamount][nodesep]{ sequencespecification }
%%%% Examples of use:
%%%%  \pstr[IGNORED][IGNORED]{ \nd(b) this \nd(a-b,45) that }
%%%%

% Note that raiseamount is ignored in PGF mode since the bounding box is computed automatically.
\gdef\pstr@PGF{\@ifnextchar[{\pstr@PGF@i}{\pstr@PGF@ii[0cm][1pt]}}
% pstr with one optional parameter
\gdef\pstr@PGF@i[#1]{\@ifnextchar[{\pstr@PGF@ii[#1]}{\pstr@PGF@ii[#1][1pt]}}
% pstr with two optional parameters
\gdef\pstr@PGF@ii[#1][#2]#3{%
\begin{pgfpicture}%
  \def\pstr@arcoptions{#2}%
  \pgfsetbaseline{0pt}%
  \pgfset{minimum width=0cm}%
  \pgfset{minimum height=0pt}%
  \pgfset{inner xsep=0pt}%
  \pgfset{inner ysep=0.3pt}%
  \pgfsetarrows{-stealth}%
  \pgfsetlinewidth{\pstr@ArrowLineWidth}%
  \pstr@ptrlist={}% Create an empty list of links.
  \pstr@defineUserCommands% define the command \nd and \txt that the package user can use to define the sequence
  #3%
  \the\pstr@ptrlist% dump the list of links.
\end{pgfpicture}%
}

\fi %%% \ifpstricks  ... \else ...

%%%% End of definition of commands specific to the PSTricks mode
%%%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%%%
%%%% Functions common to all rendering modes

% When executed, the following macro will define two commands which will become available to the package user
% for the definition of the sequence within a \pstr{ } command.
%
% It is called in the \pstr@PS and \pstr@PGF macros.
\gdef\pstr@defineUserCommands{%
    % node/link creation
    \def\nd##1(##2)##3{%
     % print out the text preceding the node specification
     \pstr@printText{##1}%
     % parse the node specification
     \Pstr@ParseNodeSpecif{##1}{##2}{##3}\@nil%
    }%
    \def\txt##1{%
     % print out text
     \pstr@printText{##1}%
    }%
    % creation of an additional arrow
    \def\arrow{\pstr@drawArrow}%
}

%%%%
%%%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%%%
%%%% Code for the succint syntax parser. Used in all modes (pgf and pstricks)
%%%%

% Parse the specification of the pointing string.
% #1 stuff to be printed in the sequence before the node
% #2 node name and link specification
% #3 node content
\gdef\Pstr@ParseSpecification#1(#2)#3{%
 % print out the text preceding the node specification
 \pstr@printText{#1}
 % parse the node specification
 \Pstr@ParseNodeSpecif{#1}{#2}{#3}\@nil
 % proceeds to the rest of the specification.
 \@ifnextchar\@nil{\@gobble}{\Pstr@ParseSpecification}
}

\gdef\Pstr@ParseNodeSpecif#1#2#3{%
 \Pstr@parselinkparam@Target{#1}(#2-){#3}%
}

% Parse a node specification
% #1 stuff to be dumped (not part of the node specification)
% #2 source
% #3 link parameters (target,angle:label)
\gdef\Pstr@parselinkparam@Target#1(#2-#3){%
% if it is the the dummy node (@-@){} then skip it
\if#2@
  \def\suite{\Pstr@skipcontent}
\else
  % if a target node is specified then create the link for it.
  \def\linkparam{#3}
  \ifx\linkparam\empty
    \def\suite{\Pstr@skiplinkparam{#1}{#2}}
  \else
    \def\suite{\Pstr@parselinkparam@Target@i{#1}{#2}#3\@nil} % #3 contains an extra '-' at the end that will be removed by this command
  \fi
\fi
\suite
}

\gdef\Pstr@skipcontent#1\@nil{}

% Parameters #1 and #2 have been parsed already
%  #1 dump   #2 source node  #3 node content
\gdef\Pstr@skiplinkparam#1#2#3\@nil{\pstr@drawNode{#1}{#2}{#3}}

% remove the extra '-' (which was appended before), adds an extra ',' at the end and look for the next ','
\gdef\Pstr@parselinkparam@Target@i#1#2#3-\@nil{\Pstr@parselinkparam@Angle{#1}{#2}#3,\@nil}

\gdef\Pstr@parselinkparam@Angle#1#2#3,#4\@nil{
  \def\reste{#4}
  \ifx\reste\empty
    \def\suite{\Pstr@parseNodeContent{#1}{#2}{#3}{\pstr@DefaultArrowAngle}{\pstr@DefaultArrowLabel}{\pstr@DefaultArrowColor}}
  \else
    \def\suite{\Pstr@parselinkparam@Angle@i{#1}{#2}{#3}#4\@nil} % #4 contains an extra ',' at the end that will be removed by this command
  \fi
  \suite
}
% remove the extra ',' (which was appended before), add an extra ':' at the end and look for the next ':'
\gdef\Pstr@parselinkparam@Angle@i#1#2#3#4,\@nil{\Pstr@parselinkparam@Label{#1}{#2}{#3}#4:\@nil}

\gdef\Pstr@parselinkparam@Label#1#2#3#4:#5\@nil{
  \def\reste{#5}
  \ifx\reste\empty
    \def\suite{\Pstr@parseNodeContent{#1}{#2}{#3}{#4}{\pstr@DefaultArrowLabel}{\pstr@DefaultArrowColor}}
  \else
    \def\suite{\Pstr@parselinkparam@Label@i{#1}{#2}{#3}{#4}#5\@nil} % #5 contains an extra ':' at the end that will be removed by this command
  \fi
  \suite
}
% remove the extra ':' (which was appended before) add an extra ',' at the end and look for the next ','
\gdef\Pstr@parselinkparam@Label@i#1#2#3#4#5:\@nil{\Pstr@parselinkparam@Color{#1}{#2}{#3}{#4}#5,\@nil}

\gdef\Pstr@parselinkparam@Color#1#2#3#4#5,#6\@nil{
  \def\reste{#6}
  \ifx\reste\empty
    \def\suite{\Pstr@parseNodeContent{#1}{#2}{#3}{#4}{#5}{\pstr@DefaultArrowColor}}
  \else
    \def\suite{\Pstr@parselinkparam@Color@i{#1}{#2}{#3}{#4}{#5}#6\@nil} % #6 contains an extra ',' at the end that will be removed by this command
  \fi
  \suite
}
% remove the extra ',' (which was appended before) and then goes on with the parsing
\gdef\Pstr@parselinkparam@Color@i#1#2#3#4#5#6,\@nil{\Pstr@parseNodeContent{#1}{#2}{#3}{#4}{#5}{#6}}


% End of the parsing of the link parameter, we just need to parse the node content (#7)
% and we have all the parameters necessary to create the node and the link.
\gdef\Pstr@parseNodeContent#1#2#3#4#5#6#7\@nil{%
\pstr@createNodeAndArrow{#1}{#2}{#3}{#4}{#5}{#6}{#7}%
}

%%%%
%%%% END OF THE CODE FOR THE PARSER
%%%%%%%%%%%%%%%%%%%%%





\catcode`\@=\TheAtCode\relax

\endinput

Change log:
-----------
Version 0.3.4 29 Oct 2007:
- updated for use with the latest version of the pgf package
Version 0.3.3 12 Oct 2007:
- it is possible to specify the line style with the option \pstrSetArrowLineStyle
- additional arrows can be created with \arrow in the \pstr syntax mode (but not in \Pstr)

Version 0.3.2 24 Sep 2007:
- the file pstring.pro was not created when the preamble was precompiled using latexdaemon
Version 0.3.1, 3 May 2007:
- It is now possible to specify the link color individually with the following link specification syntax:
    (src-dst,80:label,green)
Version 0.3, 1 Mar 2007:
- added support for pgf as a drawing engine instead of the (hacked) pstricks
- incompatibility with LatexDaemon fixed: before when loading the pstring package from a precompiled
preamble, the prologue file was not included properly during the dvips conversion.

Version 0.1, 28 Jan 2007 First version


Examples:
---------

First way of creating a pointing string: user command \Pstr
Examples of use:
        \Pstr[0.4cm][1pt]{ (b) this (a-b,45:label) that }
        \Pstr[0.4cm][1pt]{ (b) this (a-b,45) that }
        \Pstr[0.4cm][1pt]{ (b) this (a-b) that }
        \Pstr[0.4cm][1pt]{ (b) this (a) that }


Second way of creating a pointing string: user command \pstr
Syntax:
    \pstr[raiseamount][nodesep]{ sequencespecification }
Examples of use:
    \pstr[10pt][1pt]{ \nd(b) this \nd(a-b,45) that }

Note: in PGF mode, the 'raiseamount' is ignored, this is because the bounding-box is computed automatically by PGF so the box is already raised appropriately.


TODO:
----

- Compute the bounding box automatically in PSTricks mode.
- Change the \nd user command so that (optional) extra horizontal space is added
before each node except the first one. This would avoid to have to write '\ ' after each node specification.
- Change the \nd user command so that it looks after the node specification for extra text to be printed out. Then the \txt user command becomes unecessary and can be removed.
- Implement a mode "PGF with overlays" which can be activated with the "overlay"  package option. In this mode, each node would be typeset within a seperate PGF environment and using the commands \pgfrememberpicturepositiononpage and
\pgfrememberpicturepositiononpage appropriately so that PGF
remembers the node names across different PGF environments.
The bounding box would need to be computed by ourselves in that case.