Debian Codegraph @

texmf-dist/tex/generic/dcpic/dcpic.sty

raw
1 %% DC-PiCTeX
2 %% Copyright (c) 1990-2013 Pedro Quaresma, University of Coimbra, Portugal
3 %% 11/1990 (version 1.0);
4 %% 10/1991 (version 1.1);
5 %% 9/1993 (version 1.2);
6 %% 3/1995 (version 1.3);
7 %% 7/1996 (version 2.1);
8 %% 5/2001 (version 3.0);
9 %% 11/2001 (version 3.1);
10 %% 1/2002 (version 3.2)
11 %% 5/2002 (version 4.0);
12 %% 3/2003 (version 4.1);
13 %% 12/2004 (version 4.1.1)
14 %% 3/2007 (version 4.2)
15 %% 5/2008 (version 4.2.1)
16 %% 8/2008 (version 4.3)
17 %% 12/2008 (version 4.3.1)
18 %% 12/2009 (version 4.3.2)
19 %% 4/2013 (version 4.4.0)
20 %% 5/2013 (version 5.0)
21
22 \immediate\write10{Package DCpic 2013/05/01 v5.0}
23
24 \ProvidesPackage{dcpic}[2013/05/01 v5.0]
25
26 %% Version X.Y.Z
27 %% X - major versions
28 %% Y - minor versions
29 %% Z - bug corrections
30 %%
31 %% Copyright (c) 1990-2013 Pedro Quaresma <[email protected]>
32 %%
33 % This work may be distributed and/or modified under the
34 % conditions of the LaTeX Project Public License, either version 1.3
35 % of this license or (at your option) any later version.
36 % The latest version of this license is in
37 % http://www.latex-project.org/lppl.txt
38 % and version 1.3 or later is part of all distributions of LaTeX
39 % version 2005/12/01 or later.
40 %
41 % This work has the LPPL maintenance status `maintained'.
42 %
43 % The Current Maintainer of this work is Pedro Quaresma ([email protected]).
44 %
45 % This work consists of the files dcpic.sty.
46 %%
47 %% Coimbra, 1st of May, 2013 (2013/05/01)
48 %% Pedro Quaresma
49 %%
50 %% DCpic is a package of \TeX\ macros for graph modelling in a
51 %% (La)\TeX\ or Con\TeX t document. Its distinguishing features are:
52 %% the use of \PiCTeX\ a powerful graphical engine, and a simple
53 %% specification syntax. A graph is described in terms of its objects
54 %% and its edges. The objects are textual elements and the edges can
55 %% have various straight or curved forms.
56 %%
57 %%
58 %% A graph in DCpic is a "picture" in \PiCTeX, in which we place our
59 %% {\em objects} and {\em morphisms} (edges). The user's commands in
60 %% DCpic are: {\tt begindc} and {\tt enddc} which establishe the
61 %% coordinate system where the objects will by placed; {\tt obj}, the
62 %% command which defines the place and the contents of each object;
63 %% {\tt mor}, and {\tt cmor}, the commands which define the
64 %% morphisms, linear and curved edges, and its labels.
65 %%
66 %% Example:
67 %% \begindc{\commdiag}[30]
68 %% \obj(10,15){$A$}
69 %% \obj(25,15){$B$}
70 %% \obj(40,15){$C$}
71 %% \mor{$A$}{$B$}{$f$}
72 %% \mor{$B$}{$C$}{$g$}
73 %% \cmor((10,11)(11,7)(15,6)(25,6)(35,6)(39,7)(40,11))
74 %% \pup(25,3){$g\circ f$}
75 %% \enddc
76 %%
77 %% NOTES:
78 %% all the numeric values should be integer values.
79 %%
80 %% Available commands:
81 %%
82 %% The environment:
83 %% \begindc{#1}[#2]
84 %% #1 - Graph type
85 %% 0 = "commdiag" (commutative diagram)
86 %% 1 = "digraph" (direct graph)
87 %% 2 = "undigraph" (undirect graph)
88 %% 3 = "cdigraph" with incircled objects
89 %% 4 = "cundigraph" with incircled objects
90 %% (optional) #2 - magnification factor (default value, 300)
91 %%
92 %% \enddc
93 %%
94 %% Objects:
95 %% \obj(#1,#2)[#3]{#4}[#5]
96 %% #1 and #2 - coordenates
97 %% (optional) #3 - Label, to be used in the morphims command, if not
98 %% present the #4 will be used to that purpose
99 %% #4 - Object contents
100 %% (optional) #5 - placement of the object (default value \north)
101 %% 0="\pcent", center
102 %% 1="\north", north
103 %% 2="\northeast", northeast
104 %% 3="\east", east
105 %% 4="\southeast", southeast
106 %% 5="\south", south
107 %% 6="\southwest", southwest
108 %% 7="\west", west
109 %% 8="\northwest", northwest
110 %% !!! Note !!!
111 %% if you omit the #3 argument (label) and the #4 argument is a
112 %% complex LaTeX command this can cause this command to crash. In
113 %% this case you must specify a label (the empty label [], if you do
114 %% needed it it for nothing).
115 %%
116 %% Morphims (linear edges). This commando has to two major variants
117 %% i) Starting and Ending objects specification
118 %% \mor{#1}{#2}[#5,#6]{#7}[#8,#9]
119 %%
120 %% As you can see this first form is (intencionaly) badly formed, the
121 %% arguments #3 and #4 are missing (the actual command is correctly
122 %% formed).
123 %%
124 %% #1 - The starting object reference
125 %% #2 - The ending object reference
126 %%
127 %% from this two we will obtain the objects coordinates, and also the
128 %% dimensions of the enclosing box.
129 %%
130 %% The objects box dimensions are used to do an automatic adjustment of
131 %% the edge width.
132 %%
133 %% from #1 we obtain (x,y), (#1,#2) in the second form
134 %% from #2 we obtain (x',y'), (#3,#4) in the second form
135 %%
136 %% this values will be passed to the command second form
137 %%
138 %%ii) Two points coordinates specification
139 %% \mor(#1,#2)(#3,#4)[#5,#6]{#7}[#8,#9]
140 %%
141 %% Now we can describe all the arguments
142 %%
143 %% #1 and #2 - coordinates (beginning)
144 %% #3 and #4 - coordinates (ending)
145 %%(optional)#5,#6 - correction factors (defaul values, 100 and 100 (10pt))
146 %% #5 - actual beginning of the edge
147 %% #6 - actual ending of the edge
148 %% #7 - text (morphism label)
149 %%(optional)#8,#9
150 %% #8 - label placement
151 %% 1 = "\atright", at right, default value
152 %% -1 = "\atleft", at left
153 %% #9 - edge type
154 %% 0 = "\solidarrow", default edge
155 %% 1 = "\dashArrow"
156 %% 2 = "\dotArrow (thanks to Xingliang Liang <[email protected]>)
157 %% 3 = "\solidline"
158 %% 4 = "\dashline"
159 %% 5 = "\dotline"
160 %% 6 = "\injectionarrow"
161 %% 7 = "\aplicationarrow"
162 %% 8 = "\surjectivearrow"
163 %% 9 = "\equalline" (thanks to Ruben Debeerst <[email protected]>)
164 %% 10 = "\doublearrow"
165 %% 11 = "\doubleopposite"
166 %% 12 = "\nullarrow" (to allow adding labels to existing arrows)
167 %%
168 %% Notes: the equalline "arrow" does not provide a second label.
169 %%
170 %% Curved Morphisms (quadratic edges):
171 %% \cmor(#1) #2(#3,#4){#5}[#6]
172 %% #1 - list of points (odd number)
173 %% #2 - tip direction
174 %% 0 = "\pup", pointing up
175 %% 1 = "\pdown", pointing down
176 %% 2 = "\pright", pointing right
177 %% 3 = "\pleft", pointing left
178 %% #3 and #4 - coordenates of the label
179 %% #5 - morphism label
180 %%(optional)#6 - edge type
181 %% 0 ="\solidarrow", default value
182 %% 1 = "\dashArrow"
183 %% 2 = "\solidline"
184 %%
185 %% Notes: insert a space after the command.
186 %% the space after the list of points is mandatory
187 %%
188 %% Examples:
189 %% \documentclass[a4paper,11pt]{article}
190 %% \usepackage{dcpic,pictexwd}
191 %%
192 %% \begin{document}
193 %% \begindc[3]
194 %% \obj(14,11){$A$}
195 %% \obj(39,11){$B$}
196 %% \mor(14,12)(39,12){$f$}%[\atright,\solidarrow]
197 %% \mor(39,10)(14,10){$g$}%[\atright,\solidarrow]
198 %% \cmor((10,10)(6,11)(5,15)(6,19)(10,20)(14,19)(15,15))
199 %% \pdown(2,20){$id_A$}
200 %% \cmor((40,7)(41,3)(45,2)(49,3)(50,7)(49,11)(45,12))
201 %% \pleft(54,3){$id_B$}
202 %% \enddc
203 %%
204 %% \begindc{\commdiag}[3]
205 %% \obj(10,15)[A]{$A$}
206 %% \obj(40,15)[Aa]{$A$}
207 %% \obj(25,15)[B]{$B$}
208 %% \mor{A}{B}{$f$}%[\atright,\solidarrow]
209 %% \mor{B}{Aa}{$g$}%[\atright,\solidarrow]
210 %% \cmor((10,11)(11,7)(15,6)(25,6)(35,6)(39,7)(40,11))
211 %% \pup(25,3){$id_A$}
212 %% \enddc
213 %%
214 %% \newcommand{\barraA}{\vrule height2em width0em depth0em}
215 %% \newcommand{\barraB}{\vrule height1.6em width0em depth0em}
216 %% \begindc{\commdiag}[35]
217 %% \obj(1,1)[Gr]{$G$}
218 %% \obj(3,1)[Grstar]{$G_{r^*}$}
219 %% \obj(5,1)[H]{$H$}
220 %% \obj(2,2)[SigmaG]{$\Sigma^G$}
221 %% \obj(6,2)[SigmaH]{$\Sigma^H$}
222 %% \obj(1,3)[Lm]{$L_m$}
223 %% \obj(3,3)[Krm]{$K_{r,m}$}
224 %% \obj(5,3)[Rmstar]{$R_{m^*}$}
225 %% \obj(1,5)[L]{$L$}
226 %% \obj(3,5)[Lr]{$L_r$}
227 %% \obj(5,5)[R]{$R$}
228 %% \obj(2,6)[SigmaL]{$\Sigma^L$}
229 %% \obj(6,6)[SigmaR]{$\Sigma^R$}
230 %% \mor{Gr}{SigmaG}{$\lambda^G$}
231 %% \mor{Grstar}{Gr}{$i_5$}[\atleft,\aplicationarrow]
232 %% \mor{Grstar}{H}{$r^*$}[\atright,\solidarrow]
233 %% \mor{H}{SigmaH}{$\lambda^H$}[\atright,\dashArrow]
234 %% \mor{SigmaG}{SigmaH}{$\varphi^{r^*}$}[\atright,\solidarrow]
235 %% \mor{Lm}{Gr}{$m$}[\atright,\solidarrow]
236 %% \mor{Lm}{L}{$i_2$}[\atleft,\aplicationarrow]
237 %% \mor{Krm}{Lm}{$i_3\quad$}[\atright,\aplicationarrow]
238 %% \mor{Krm}{Rmstar}{$r$}
239 %% \mor{Krm}{Lr}{$i_4$}[\atright,\aplicationarrow]
240 %% \mor{Krm}{Grstar}{$m$}
241 %% \mor{Rmstar}{R}{$i_6$}[\atright,\aplicationarrow]
242 %% \mor{Rmstar}{H}{$m^*$}
243 %% \mor{L}{SigmaL}{$\lambda^L$}
244 %% \mor{Lr}{L}{$i_1\quad$}[\atright,\aplicationarrow]
245 %% \mor{Lr}{R}{$r$}
246 %% \mor{R}{SigmaR}{$\lambda^R$}[\atright,\solidarrow]
247 %% \mor{SigmaL}{SigmaG}{$\varphi^m$}[\atright,\solidarrow]
248 %% \mor{SigmaL}{SigmaR}{$\varphi^r$}
249 %% \mor{SigmaR}{SigmaH}{$\varphi^{m^*}$}
250 %% \enddc
251 %%
252 %% \end{document}
253 %%-----------------//-------------
254 %% Modifications (9/1993)
255 %% argument "distance" between de tip of the arrow and the objects
256 %% became optional; a new option for the "arrows" (option 3)
257 %%
258 %% 2/3/1995 (version 1.3)
259 %% adds "the aplication arrow" (option 4); the distance between
260 %% the label and the "arrow" is now a fixed value (100 units).
261 %% 15/7/1996 (version 2.1)
262 %% The comand "\mor" has a new sintax. The 5th and 6th
263 %% parameters are now the distance between the two objects and
264 %% the arrow tips. The 7th parameter is the label. The 8th e 9th
265 %% parameters (label position and type of arrow) are now optional
266 %%
267 %% 5/2001 (version 3.0)
268 %% Implementation of the comand "\cmor" based on the quadratic
269 %% curver comand of PiCTeX
270 %%
271 %% 11/2001 (version 3.1)
272 %% Changes on the tips of the arrow to became more LaTeX style
273 %% (after a conversation on EuroTeX 2001).
274 %%
275 %% 1/2002 (version 3.2)
276 %% Modification of the commands "obj" and "mor" in such a way
277 %% that allows the logical specification of the morphisms, that
278 %% is, it is now possible to specify the starting object and the
279 %% ending object instead of specify the coordinates.
280 %%
281 %% The length of the arrows is automatically trimmed to the
282 %% objects' size.
283 %%
284 %% 5/2002 (version 4.0)
285 %% New syntax for the commands "begindc" e "obj"
286 %% !!! New syntax !!!
287 %% The command "begindc" now have an obligatory argument, this
288 %% argument allows the specification of the graph type
289 %% "commdiag" (0), commutative diagrams
290 %% "digraph" (1), directed graphs
291 %% "undigraph" (2), undirected graphs
292 %% The command "obj" has a new syntax: after the coordinates
293 %% specification, an optional argument specifying a label, an
294 %% obligatory argument given the "value" of the object and the
295 %% final optional argument used in the graphs to set the
296 %% relative position of the "value" to the "dot" defining the
297 %% objects position, the default value is "north".
298 %%
299 %% 3/2003 (version 4.1)
300 %% Responding to a request of Jon Barker <[email protected]> I
301 %% create a new type of arrow, the surjective arrow.
302 %% For now only horizontal and vertical versions, other angles
303 %% are poorly rendered.
304 %% 12/2004 (version 4.1.1)
305 %% New version for the surjective arrows, solve the problems
306 %% with the first implementation of this option.
307 %% 3/2007 (version 4.2)
308 %% Adds the "providespackage" directive that was missing.
309 %% Adds dashed lines, and dotted lines.
310 %% 5/2008 (version 4.2.1)
311 %% Deleting some counters, trying to avoid the problem "running
312 %% out of counters", that occurs because of the use of PiCTeX
313 %% and DCpic (only two...)
314 %% 8/2008 (version 4.3)
315 %% Thanks to Ruben Debeerst ([email protected]),
316 %% he added a new arrow "equalline". After that I
317 %% decided to add: the doublearrow; the doublearrow with
318 %% opposite directions; the null arrow. This last can be used as
319 %% a simple form of adding new labels.
320 %%12/2008 (version 4.3.1)
321 %% The comand \id is internalised (\!id), it should be that way
322 %% from the begining because it is not to be used from the
323 %% outside.
324 %% The comand \dasharrow was changed to \dashArrow to avoid a
325 %% clash with the AMS command with the same name.
326 %%12/2009 (version 4.3.2)
327 %% There is a conflict between dcpic.sty and hyperref in current
328 %% texlive-2009 due to the one letter macro \d (thanks Thorsten
329 %% S <[email protected]>).
330 %% The \d changed to \deuc (Euclidian Distance). The \x and \y
331 %% changed to \xO \yO
332 %% 4/2013 (version 4.4.0)
333 %% Thanks to Xingliang Liang <[email protected]>. He added a new
334 %% arrow "dotarrow".
335 %% 5/2013 (version 5.0)
336 %% The base scale of the graph has changed from 1pt to .1pt to
337 %% solve a problem with the implementation of the oblique
338 %% equalline (Thanks to Antonio de Nicola).
339 %% The LaTeX circle and oval commands where replaced by the
340 %% PiCTeX circulararc and ellipticalarc commands to avoid
341 %% differences in scales.
342 %%-----------------//-------------
343
344 \catcode`!=11 % ***** THIS MUST NEVER BE OMITTED (See PiCTeX)
345
346 \newcount\aux%
347 \newcount\auxa%
348 \newcount\auxb%
349 \newcount\xO%
350 \newcount\yO%
351 \newcount\xl%
352 \newcount\yl%
353 \newcount\deuc%
354 \newcount\dnm%
355 \newcount\xa%
356 \newcount\xb%
357 \newcount\xmed%
358 \newcount\xc%
359 \newcount\xd%
360 \newcount\xe
361 \newcount\xf
362 \newcount\ya%
363 \newcount\yb%
364 \newcount\ymed%
365 \newcount\yc%
366 \newcount\yd
367 \newcount\ye
368 \newcount\yf
369 %% "global variables"
370 \newcount\expansao%
371 \newcount\tipografo% version 4.0
372 \newcount\distanciaobjmor% version 4.0
373 \newcount\tipoarco% version 4.0
374 \newif\ifpara%
375 %% version 3.2
376 \newbox\caixa%
377 \newbox\caixaaux%
378 \newif\ifnvazia%
379 \newif\ifvazia%
380 \newif\ifcompara%
381 \newif\ifdiferentes%
382 \newcount\xaux%
383 \newcount\yaux%
384 \newcount\guardaauxa%
385 \newcount\alt%
386 \newcount\larg%
387 \newcount\prof%
388 %% for the triming
389 \newcount\auxqx
390 \newcount\auxqy
391 \newif\ifajusta%
392 \newif\ifajustadist
393 \def\objPartida{}%
394 \def\objChegada{}%
395 \def\objNulo{}%
396
397 %%
398 %% Stack specification
399 %%
400
401 %%
402 %% Emtpy stack
403 %%
404 \def\!vazia{:}
405
406 %%
407 %% Is Empty? : Stack -> Bool
408 %%
409 %% nvazia - True if Not Empy
410 %% vazia - True if Empty
411 \def\!pilhanvazia#1{\let\arg=#1%
412 \if:\arg\ \nvaziafalse\vaziatrue \else \nvaziatrue\vaziafalse\fi}
413
414 %%
415 %% Push : Elems x Stack -> Stack
416 %%
417 \def\!coloca#1#2{\edef\pilha{#1.#2}}
418
419 %%
420 %% Top : Stack -> Elems
421 %%
422 %% the empty stack is not taken care
423 %% the element is "kept" ("guardado")
424 \def\!guarda(#1)(#2,#3)(#4,#5,#6){\def\!id{#1}%
425 \xaux=#2%
426 \yaux=#3%
427 \alt=#4%
428 \larg=#5%
429 \prof=#6%
430 }
431
432 \def\!topaux#1.#2:{\!guarda#1}
433 \def\!topo#1{\expandafter\!topaux#1}
434
435 %%
436 %% Pop : Stack -> Stack
437 %%
438 %% the empty stack is not taken care
439 \def\!popaux#1.#2:{\def\pilha{#2:}}
440 \def\!retira#1{\expandafter\!popaux#1}
441
442 %%
443 %% Compares words : Word x Word -> Bool
444 %%
445 %% compara - True if equal
446 %% diferentes - True if not equal
447 \def\!comparaaux#1#2{\let\argA=#1\let\argB=#2%
448 \ifx\argA\argB\comparatrue\diferentesfalse\else\comparafalse\diferentestrue\fi}
449
450 \def\!compara#1#2{\!comparaaux{#1}{#2}}
451
452 %% Private Macro
453 %% Absolute Value)
454 %% \absoluto{n}{absn}
455 %% input
456 %% n - integer
457 %% output
458 %% absn - |n|
459 \def\!absoluto#1#2{\aux=#1%
460 \ifnum \aux > 0
461 #2=\aux
462 \else
463 \multiply \aux by -1
464 #2=\aux
465 \fi}
466
467 %% Name definitions for edge types and directions
468 \def\solidarrow{0}
469 \def\dashArrow{1}
470 \def\dotArrow{2}
471 \def\solidline{3}
472 \def\dashline{4}
473 \def\dotline{5}
474 \def\injectionarrow{6}
475 \def\aplicationarrow{7}
476 \def\surjectivearrow{8}
477 \def\equalline{9}
478 \def\doublearrow{10}
479 \def\doubleopposite{11}
480 \def\nullarrow{12}
481
482 %% Name definitions for edge label placement
483 \def\atright{-1}
484 \def\atleft{1}
485 %% Tip direction for curved edges
486 \def\pup{0}
487 \def\pdown{1}
488 \def\pright{2}
489 \def\pleft{3}
490 %% Type of graph
491 \def\commdiag{0}
492 \def\digraph{1}
493 \def\undigraph{2}
494 \def\cdigraph{3}
495 \def\cundigraph{4}
496 %% Positioning of labels in graphs
497 \def\pcent{0}
498 \def\north{1}
499 \def\northeast{2}
500 \def\east{3}
501 \def\southeast{4}
502 \def\south{5}
503 \def\southwest{6}
504 \def\west{7}
505 \def\northwest{8}
506
507 %%Private Macro
508 %% Adjust the distance between the arrows and the objects regarding
509 %% the dimensions of the objects.
510 %%
511 %% \ajusta{x}{xl}{y}{yl}{d}{Object} (ajusta = adjust)
512 %%
513 %% Input
514 %% (x,y) e (xl,yl) - start, end coordinates of arrow
515 %% d - distance specified by the user (default value, 100)
516 %% Objecto - reference of the object pointed by the arrow
517 %% Output
518 %% d - adjusted distance
519 %%
520 %% The adjusted distance is the greatest value between 100 and the
521 %% object's box dimensions. If the user specify a value this is not
522 %% altered.
523 %%
524 %% If the arrow is horizontal the length is used.
525 %% If the arrow is vertical the height is used for arrows in the 1st
526 %% or 2nd quadrante, or the depth if the arrow is in the 3rd or 4th
527 %% quadrante. If the arrow is oblique the value is chosen accordingly:
528 %% from 315 to 45 degrees length is used
529 %% from 45 to 135 degrees height is used
530 %% from 135 to 225 degrees length is used
531 %% from 225 to 315 degrees depth is used
532 \def\!ajusta#1#2#3#4#5#6{\aux=#5%
533 \let\auxobj=#6%
534 \ifcase \tipografo % commutative diagrams
535 \ifnum\number\aux=100
536 \ajustadisttrue % if needed, adjust
537 \else
538 \ajustadistfalse % if not, keeps unchanged
539 \fi
540 \else % graphs (directed, undirected, with frames)
541 \ajustadistfalse
542 \fi
543 \ifajustadist
544 \let\pilhaaux=\pilha%
545 \loop%
546 \!topo{\pilha}%
547 \!retira{\pilha}%
548 \!compara{\!id}{\auxobj}%
549 \ifcompara\nvaziafalse \else\!pilhanvazia\pilha \fi%
550 \ifnvazia%
551 \repeat%
552 %% push the values into the stack
553 \let\pilha=\pilhaaux%
554 \ifvazia%
555 \ifdiferentes%
556 %%
557 %% It is not possible to make de adjustment given the fact that the
558 %% user did not provide a label for the object in question. We set a
559 %% value equal to the default value (100)
560 %%
561 \larg=131072% these values are for unit of .1pt
562 \prof=65536%
563 \alt=65536%
564 \fi%
565 \fi%
566 \divide\larg by 13107% these values are for unit of .1pt
567 \divide\prof by 6553%
568 \divide\alt by 6553%
569 \ifnum\number\yO=\number\yl
570 %% Case 1 -- horizontal arrow
571 %%
572 %% with the division by 13107 we get half the size of the box, for a
573 %% centered text, the adding of 30 is an empirical adjustment.
574 \advance\larg by 30
575 \ifnum\number\larg>\aux
576 #5=\larg
577 \fi
578 \else
579 \ifnum\number\xO=\number\xl
580 \ifnum\number\yl>\number\yO
581 %% Case 2.1 -- vertical arrow, down direction
582 %%
583 \ifnum\number\alt>\aux
584 #5=\alt
585 \fi
586 \else
587 %% Case 2.2 -- vertical arrow, up direction
588 %%
589 %% with the division by 6553 we get the box height. The adjustment
590 %% of 50 is an empirical adjustment.
591 \advance\prof by 50
592 \ifnum\number\prof>\aux
593 #5=\prof
594 \fi
595 \fi
596 \else
597 %% Case 3 -- oblique arrow
598 %% Case 3.1 --- from 315o to 45o; |x-xl|>|y-yl|
599 %% Case 3.3 --- from 135o to 225o; |x-xl|>|y-yl|; Length
600 \auxqx=\xO
601 \advance\auxqx by -\xl
602 \!absoluto{\auxqx}{\auxqx}%
603 \auxqy=\yO
604 \advance\auxqy by -\yl
605 \!absoluto{\auxqy}{\auxqy}%
606 \ifnum\auxqx>\auxqy
607 \ifnum\larg<100
608 \larg=100
609 \fi
610 \advance\larg by 30
611 #5=\larg
612 \else
613 %% Case 3.2 --- from 45o to 135o; |x-xl|<|y-yl| e y>0; Length
614 \ifnum\yl>\yO
615 \ifnum\larg<100
616 \larg=100
617 \fi
618 \advance\alt by 60
619 #5=\alt
620 \else
621 %% Case 3.4 -- from 225o to 315o; |x-xl|<|y-yl| e y<0; Depth
622 \advance\prof by 110
623 #5=\prof
624 \fi
625 \fi
626 \fi
627 \fi
628 \fi} % the branch else is missing
629
630 %%Private Macro
631 %% Square root
632 %% raiz{n}{m} (raiz = root)
633 %% ->
634 %% n - natural number
635 %% <-
636 %% n - natural number
637 %% m - greatest natural number less then the square root of n
638 \def\!raiz#1#2{\auxa=#1%
639 \auxb=1%
640 \loop
641 \aux=\auxb%
642 \advance \aux by 1%
643 \multiply \aux by \aux%
644 \ifnum \aux < \auxa%
645 \advance \auxb by 1%
646 \paratrue%
647 \else\ifnum \aux=\auxa%
648 \advance \auxb by 1%
649 \paratrue%
650 \else\parafalse%
651 \fi
652 \fi
653 \ifpara%
654 \repeat
655 #2=\auxb}
656
657 %%Private Macro
658 %% Find the starting and ending points of the "arrow" and also the
659 %% label position (one coordinate at a time)
660 %%
661 %% ucoord{x1}{x2}{x3}{x4}{x5}{x6}{+|- 1}
662 %% Input
663 %% x1,x2,x3,x4,x5
664 %% Output
665 %% x6
666 %%
667 %% x2 - x1
668 %% x6 = x3 +|- ------- x4
669 %% x5
670 \def\!ucoord#1#2#3#4#5#6#7{\aux=#2%
671 \advance \aux by -#1%
672 \multiply \aux by #4%
673 \divide \aux by #5%
674 \ifnum #7 = -1 \multiply \aux by -1 \fi%
675 \advance \aux by #3%
676 #6=\aux}
677
678 %%Private Macro
679 %% Euclidean distance between two points
680 %%
681 %% quadrado = square
682 %%
683 %% quadrado{n}{m}{l}
684 %% Input
685 %% n - natural number
686 %% m - natural number
687 %% Output
688 %% l = (n-m)*(n-m)
689 \def\!quadrado#1#2#3{\aux=#1%
690 \advance \aux by -#2%
691 \multiply \aux by \aux%
692 #3=\aux}
693
694 %%Private Macro
695 %% Euclidean distance between arrows and its tags
696 %%
697 %% Input
698 %% (x,y), (x',y') morphism's name (tag)
699 %% Output
700 %% dnm - distance between an arrow and its tags
701 %% (with a trim given by the tag's size
702 %% Observations
703 %% The trimming is for horizontal and vertical arrows
704 %% only. Oblique arrows are dealt in a different way
705 %%
706 %% Algorithm
707 %% caixa0 <- morfism name
708 %% if x-xl = 0 then {vertical arrow}
709 %% aux <- caixa0 width
710 %% dnm <- converstion-sp-pt(aux)/2+3
711 %% else {non-vertical arrow}
712 %% if y-yl = 0 then {horizontal arrow}
713 %% aux <- caixa0 height+depth
714 %% dnm <- converstion-sp-pt(aux)/2+3
715 %% else {oblique arrow}
716 %% dnm <- 3
717 %% endif
718 %% endif
719 %% endalgorithm
720 \def\!distnomemor#1#2#3#4#5#6{\setbox0=\hbox{#5}%
721 \aux=#1
722 \advance \aux by -#3
723 \ifnum \aux=0
724 \aux=\wd0 \divide \aux by 13107%2
725 \advance \aux by 30
726 #6=\aux
727 \else
728 \aux=#2
729 \advance \aux by -#4
730 \ifnum \aux=0
731 \aux=\ht0 \advance \aux by \dp0 \divide \aux by 13107%2
732 \advance \aux by 30
733 #6=\aux%
734 \else
735 #6=30
736 \fi
737 \fi
738 }
739
740 %%
741 %% The environment "begindc...enddc"
742 %%
743 \def\begindc#1{\!ifnextchar[{\!begindc{#1}}{\!begindc{#1}[30]}}
744 \def\!begindc#1[#2]{\beginpicture
745 \let\pilha=\!vazia
746 \setcoordinatesystem units <.1pt,.1pt>
747 \expansao=#2
748 \ifcase #1
749 \distanciaobjmor=100
750 \tipoarco=0 % arrow
751 \tipografo=0 % commutative diagram
752 \or
753 \distanciaobjmor=20
754 \tipoarco=0 % arrow
755 \tipografo=1 % directed graph
756 \or
757 \distanciaobjmor=10
758 \tipoarco=3 % line
759 \tipografo=2 % undirected graph
760 \or
761 \distanciaobjmor=80
762 \tipoarco=0 % arrow
763 \tipografo=3 % directed graph
764 \or
765 \distanciaobjmor=80
766 \tipoarco=3 % line
767 \tipografo=4 % undirected graph
768 \fi}
769
770 \def\enddc{\endpicture}
771
772 \def\drawarrowhead <#1> [#2,#3]{%
773 \!ifnextchar<{\!drawarrowhead{#1}{#2}{#3}}{\!drawarrowhead{#1}{#2}{#3}<\!zpt,\!zpt> }}
774
775 % Xingliang Liang <[email protected]>
776 % ** \!ljoin (XCOORD,YCOORD)
777 % ** Draws a straight line starting at the last point specified
778 % ** by the most recent \!start, \!ljoin, or \!qjoin, and
779 % ** ending at (XCOORD,YCOORD).
780 \def\!ljoindummy (#1,#2){%
781 \advance\!intervalno by 1
782 \!xE=\!M{#1}\!xunit \!yE=\!M{#2}\!yunit
783 \!rotateaboutpivot\!xE\!yE
784 \!xdiff=\!xE \advance \!xdiff by -\!xS%** xdiff = xE - xS
785 \!ydiff=\!yE \advance \!ydiff by -\!yS%** ydiff = yE - yS
786 \!Pythag\!xdiff\!ydiff\!arclength% ** arclength = sqrt(xdiff**2+ydiff**2)
787 \global\advance \totalarclength by \!arclength%
788 %\!drawlinearsegment% ** set by dashpat to \!linearsolid or \!lineardashed
789 \!xS=\!xE \!yS=\!yE% ** shift ending points to starting points
790 \ignorespaces}
791
792 %%
793 %% \!drawarrowhead{4pt}{DimC}{DimD} <xshift,yshift> from {\xa} {\ya} to {\xb} {\yb}
794 %%
795 \def\!drawarrowhead#1#2#3<#4,#5> from #6 #7 to #8 #9 {%
796 %
797 % ** convert to dimensions
798 \!xloc=\!M{#8}\!xunit
799 \!yloc=\!M{#9}\!yunit
800 \!dxpos=\!xloc \!dimenA=\!M{#6}\!xunit \advance \!dxpos -\!dimenA
801 \!dypos=\!yloc \!dimenA=\!M{#7}\!yunit \advance \!dypos -\!dimenA
802 \let\!MAH=\!M% ** save current c/d mode
803 \!setdimenmode% ** go into dimension mode
804 %
805 \!xshift=#4\relax \!yshift=#5\relax% ** pick up shift
806 \!reverserotateonly\!xshift\!yshift% ** back rotate shift
807 \advance\!xshift\!xloc \advance\!yshift\!yloc
808 %
809 % ** draw shaft of arrow
810 \!xS=-\!dxpos \advance\!xS\!xshift
811 \!yS=-\!dypos \advance\!yS\!yshift
812 \!start (\!xS,\!yS)
813 \!ljoindummy (\!xshift,\!yshift)
814 %
815 % ** find 32*cosine and 32*sine of angle of rotation
816 \!Pythag\!dxpos\!dypos\!arclength
817 \!divide\!dxpos\!arclength\!dxpos
818 \!dxpos=32\!dxpos \!removept\!dxpos\!!cos
819 \!divide\!dypos\!arclength\!dypos
820 \!dypos=32\!dypos \!removept\!dypos\!!sin
821 %
822 % ** construct arrowhead
823 \!halfhead{#1}{#2}{#3}% ** draw half of arrow head
824 \!halfhead{#1}{-#2}{-#3}% ** draw other half
825 %
826 \let\!M=\!MAH% ** restore old c/d mode
827 \ignorespaces}
828
829 %% Public macro: "mor"
830 %%
831 %% Funtion to built the "arrow" between two points
832 %%
833 %% The points that are uses to built all the elements of the "arrows"
834 %% are:
835 %%
836 %% (xc,yc)
837 %% o
838 %% |
839 %% o------o---------o---------o------o
840 %%(x,y) (xa,ya) (xm,ym) (xb,yb)(xl,yl)
841 %%
842 %% auxa - distance between (x,y) and (xa,ya), 10pt by default
843 %% auxb - distance between (xl,yl) and (xb,yb), 10pt by default
844 %%
845 \def\mor{%
846 \!ifnextchar({\!morxy}{\!morObjA}}
847 \def\!morxy(#1,#2){%
848 \!ifnextchar({\!morxyl{#1}{#2}}{\!morObjB{#1}{#2}}}
849 \def\!morxyl#1#2(#3,#4){%
850 \!ifnextchar[{\!mora{#1}{#2}{#3}{#4}}{\!mora{#1}{#2}{#3}{#4}[\number\distanciaobjmor,\number\distanciaobjmor]}}%
851 \def\!morObjA#1{%
852 \let\pilhaaux=\pilha%
853 \def\objPartida{#1}%
854 \loop%
855 \!topo\pilha%
856 \!retira\pilha%
857 \!compara{\!id}{\objPartida}%
858 \ifcompara \nvaziafalse \else \!pilhanvazia\pilha \fi%
859 \ifnvazia%
860 \repeat%
861 \ifvazia%
862 \ifdiferentes%
863 %%
864 %% error message and ficticious parameters
865 %%
866 Error: Incorrect label specification%
867 \xaux=1%
868 \yaux=1%
869 \fi%
870 \fi%
871 \let\pilha=\pilhaaux%
872 \!ifnextchar({\!morxyl{\number\xaux}{\number\yaux}}{\!morObjB{\number\xaux}{\number\yaux}}}
873 \def\!morObjB#1#2#3{%
874 \xO=#1
875 \yO=#2
876 \def\objChegada{#3}%
877 \let\pilhaaux=\pilha%
878 \loop
879 \!topo\pilha %
880 \!retira\pilha%
881 \!compara{\!id}{\objChegada}%
882 \ifcompara \nvaziafalse \else \!pilhanvazia\pilha \fi
883 \ifnvazia
884 \repeat
885 \ifvazia
886 \ifdiferentes%
887 %%
888 %% error message and ficticious parameters
889 %%
890 Error: Incorrect label specification
891 \xaux=\xO%
892 \advance\xaux by \xO%
893 \yaux=\yO%
894 \advance\yaux by \yO%
895 \fi
896 \fi
897 \let\pilha=\pilhaaux
898 \!ifnextchar[{\!mora{\number\xO}{\number\yO}{\number\xaux}{\number\yaux}}{\!mora{\number\xO}{\number\yO}{\number\xaux}{\number\yaux}[\number\distanciaobjmor,\number\distanciaobjmor]}}
899 \def\!mora#1#2#3#4[#5,#6]#7{%
900 \!ifnextchar[{\!morb{#1}{#2}{#3}{#4}{#5}{#6}{#7}}{\!morb{#1}{#2}{#3}{#4}{#5}{#6}{#7}[1,\number\tipoarco] }}
901 \def\!morb#1#2#3#4#5#6#7[#8,#9]{\xO=#1%
902 \yO=#2%
903 \xl=#3%
904 \yl=#4%
905 \multiply \xO by \expansao%
906 \multiply \yO by \expansao%
907 \multiply \xl by \expansao%
908 \multiply \yl by \expansao%
909 %%
910 %% Euclidean distance between two points
911 %% d = \sqrt((x-xl)^2+(y-yl)^2)
912 %%
913 \!quadrado{\number\xO}{\number\xl}{\auxa}%
914 \!quadrado{\number\yO}{\number\yl}{\auxb}%
915 \deuc=\auxa%
916 \advance \deuc by \auxb%
917 \!raiz{\deuc}{\deuc}%
918 %%
919 %% the point (xa,ya) is at a distance #5 (default value 100) from the
920 %% point (x,y)
921 %%
922 %% given the fact that we have two points (start,end) we need to
923 %% recover their value searching the stack
924 \auxa=#5
925 \!compara{\objNulo}{\objPartida}%
926 \ifdiferentes% adjusting only when needed
927 \!ajusta{\xO}{\xl}{\yO}{\yl}{\auxa}{\objPartida}%
928 \ajustatrue
929 \def\objPartida{}% reset the value of the starting object
930 \fi
931 %% save the value of aux (after adjustment) to be used in the case of
932 %% an injective morphism
933 \guardaauxa=\auxa
934 %%
935 \!ucoord{\number\xO}{\number\xl}{\number\xO}{\auxa}{\number\deuc}{\xa}{1}%
936 \!ucoord{\number\yO}{\number\yl}{\number\yO}{\auxa}{\number\deuc}{\ya}{1}%
937 %% auxa has the value of the distance between the objects minus the
938 %% distance between the arrow and the objects (100 default value)
939 \auxa=\deuc%
940 %%
941 %% the point (xb,yb) is at a distance #6 (default value 100) from the
942 %% point (xl,yl)
943 %%
944 \auxb=#6
945 \!compara{\objNulo}{\objChegada}%
946 \ifdiferentes% adjusting only when needed
947 % adjustment
948 \!ajusta{\xO}{\xl}{\yO}{\yl}{\auxb}{\objChegada}%
949 \def\objChegada{}% reset the value of the end object
950 \fi
951 \advance \auxa by -\auxb%
952 \!ucoord{\number\xO}{\number\xl}{\number\xO}{\number\auxa}{\number\deuc}{\xb}{1}%
953 \!ucoord{\number\yO}{\number\yl}{\number\yO}{\number\auxa}{\number\deuc}{\yb}{1}%
954 \xmed=\xa%
955 \advance \xmed by \xb%
956 \divide \xmed by 2
957 \ymed=\ya%
958 \advance \ymed by \yb%
959 \divide \ymed by 2
960 %%
961 %% find the coordinates of the label position: (xc,yc)
962 %%
963 %% after this the values of xmed and ymed are no longer important
964 %%
965 \!distnomemor{\number\xO}{\number\yO}{\number\xl}{\number\yl}{#7}{\dnm}%
966 \!ucoord{\number\yO}{\number\yl}{\number\xmed}{\number\dnm}{\number\deuc}{\xc}{-#8}%
967 \!ucoord{\number\xO}{\number\xl}{\number\ymed}{\number\dnm}{\number\deuc}{\yc}{#8}%
968 %%
969 %% draw the "arrow"
970 %%
971 \ifcase #9 % 0=solid arrow
972 \arrow <4pt> [.2,1.1] from {\xa} {\ya} to {\xb} {\yb}
973 \or % 1=dashed arrow
974 \setdashes <2pt>
975 \plot {\xa} {\ya} {\xb} {\yb} /
976 \setsolid%
977 \drawarrowhead <4pt> [.2,1.1] from {\xa} {\ya} to {\xb} {\yb}
978 \or % 2=dotted arrow (Xingliang Liang <[email protected]> - 4.4.0)
979 \setdots <2pt>
980 \plot {\xa} {\ya} {\xb} {\yb} /
981 \setsolid%
982 \drawarrowhead <4pt> [.2,1.1] from {\xa} {\ya} to {\xb} {\yb}
983 \or % 3=solid line
984 \setlinear
985 \plot {\xa} {\ya} {\xb} {\yb} /
986 \or % 4=dashed line
987 \setdashes <2pt>
988 \setlinear
989 \plot {\xa} {\ya} {\xb} {\yb} /
990 \setsolid
991 \or % 5=dotted line
992 \setdots <2pt>
993 \setlinear
994 \plot {\xa} {\ya} {\xb} {\yb} /
995 \setsolid
996 \or % 6=injective arrow
997 %%
998 %% 30 units, the radius for the tail of the arrow
999 %%
1000 %% recover the value of auxa
1001 \auxa=\guardaauxa
1002 %% makes an adjustment to cope with the tail of the arrow, giving
1003 %% space to the semi-circle
1004 \advance \auxa by 30%
1005 %%
1006 %% Note: the values of (xa,ya) will be modified, they will be
1007 %% "pushed" further away from (x,y) in order to acomodate the tail
1008 %% of the "arrow"
1009 %%
1010 %% find the point (xd,yd), the center of a 2pt (20*0.1) circle
1011 %%
1012 \!ucoord{\number\xO}{\number\xl}{\number\xO}{\number\auxa}{\number\deuc}{\xa}{1}%
1013 \!ucoord{\number\yO}{\number\yl}{\number\yO}{\number\auxa}{\number\deuc}{\ya}{1}%
1014 \!ucoord{\number\yO}{\number\yl}{\number\xa}{20}{\number\deuc}{\xd}{-1}%
1015 \!ucoord{\number\xO}{\number\xl}{\number\ya}{20}{\number\deuc}{\yd}{1}%
1016 %% building the "arrow"
1017 \arrow <4pt> [.2,1.1] from {\xa} {\ya} to {\xb} {\yb}
1018 %% and its "tail"
1019 \circulararc -180 degrees from {\xa} {\ya} center at {\xd} {\yd}
1020 \or % 7=maps "arrow" ("|-->")
1021 \auxa=20 %
1022 %%
1023 %% Note: the values of xmed and ymed will be modified
1024 %%
1025 %% find the two points that defines the tail of the arrow (segment
1026 %% (xmed,ymed)(xd,yd))
1027 \!ucoord{\number\yO}{\number\yl}{\number\xa}{\number\auxa}{\number\deuc}{\xmed}{-1}%
1028 \!ucoord{\number\xO}{\number\xl}{\number\ya}{\number\auxa}{\number\deuc}{\ymed}{1}%
1029 \!ucoord{\number\yO}{\number\yl}{\number\xa}{\number\auxa}{\number\deuc}{\xd}{1}%
1030 \!ucoord{\number\xO}{\number\xl}{\number\ya}{\number\auxa}{\number\deuc}{\yd}{-1}%
1031 %% building the "arrow"
1032 \arrow <4pt> [.2,1.1] from {\xa} {\ya} to {\xb} {\yb}
1033 %% and its "tail"
1034 \setlinear
1035 \plot {\xmed} {\ymed} {\xd} {\yd} /
1036 \or % 8=surjective arrow ("-->>")
1037 %% building arrow with the first tip
1038 \arrow <4pt> [.2,1.1] from {\xa} {\ya} to {\xb} {\yb}
1039 %% and the second tip
1040 \setlinear
1041 \arrow <6pt> [0,.72] from {\xa} {\ya} to {\xb} {\yb}
1042 \or % 9=equalline
1043 %% by Ruben Debeerst: equal-line
1044 %%
1045 %% sets the separation (distance) between the two parallel lines, if
1046 %% horizontal or vertical 1pt (10*0.1) is enough, if not 1.1pt (11*0.1)
1047 \auxa=11
1048 \ifnum\number\yO=\number\yl
1049 \auxa=10
1050 \fi
1051 \ifnum\number\xO=\number\xl
1052 \auxa=10
1053 \fi
1054 %% the two parallel lines will be given by (xmed,ymed)(xd,yd), and
1055 %% (xe,ye)(xf,yf)
1056 \!ucoord{\number\yO}{\number\yl}{\number\xa}{\number\auxa}{\number\deuc}{\xmed}{-1}%
1057 \!ucoord{\number\xO}{\number\xl}{\number\ya}{\number\auxa}{\number\deuc}{\ymed}{1}%
1058 \!ucoord{\number\yO}{\number\yl}{\number\xa}{\number\auxa}{\number\deuc}{\xd}{1}%
1059 \!ucoord{\number\xO}{\number\xl}{\number\ya}{\number\auxa}{\number\deuc}{\yd}{-1}%
1060
1061 \!ucoord{\number\yO}{\number\yl}{\number\xb}{\number\auxa}{\number\deuc}{\xe}{-1}%
1062 \!ucoord{\number\xO}{\number\xl}{\number\yb}{\number\auxa}{\number\deuc}{\ye}{1}%
1063 \!ucoord{\number\yO}{\number\yl}{\number\xb}{\number\auxa}{\number\deuc}{\xf}{1}%
1064 \!ucoord{\number\xO}{\number\xl}{\number\yb}{\number\auxa}{\number\deuc}{\yf}{-1}%
1065 \setlinear
1066 \plot {\xmed} {\ymed} {\xe} {\ye} /
1067 \plot {\xd} {\yd} {\xf} {\yf} /
1068 \or % 10=double arrow
1069 %%
1070 %% sets the separation (distance) between the two parallel lines, if
1071 %% horizontal or vertical 2pt is enough, if not 2.5pt. The extra space
1072 %% is needed because of the arrow tip.
1073 \auxa=25
1074 \ifnum\number\yO=\number\yl
1075 \auxa=20
1076 \fi
1077 \ifnum\number\xO=\number\xl
1078 \auxa=20
1079 \fi
1080 %% the two parallel lines will be given by (xmed,ymed)(xd,yd), and
1081 %% (xe,ye)(xf,yf)
1082 \!ucoord{\number\yO}{\number\yl}{\number\xa}{\number\auxa}{\number\deuc}{\xmed}{-1}%
1083 \!ucoord{\number\xO}{\number\xl}{\number\ya}{\number\auxa}{\number\deuc}{\ymed}{1}%
1084 \!ucoord{\number\yO}{\number\yl}{\number\xa}{\number\auxa}{\number\deuc}{\xd}{1}%
1085 \!ucoord{\number\xO}{\number\xl}{\number\ya}{\number\auxa}{\number\deuc}{\yd}{-1}%
1086
1087 \!ucoord{\number\yO}{\number\yl}{\number\xb}{\number\auxa}{\number\deuc}{\xe}{-1}%
1088 \!ucoord{\number\xO}{\number\xl}{\number\yb}{\number\auxa}{\number\deuc}{\ye}{1}%
1089 \!ucoord{\number\yO}{\number\yl}{\number\xb}{\number\auxa}{\number\deuc}{\xf}{1}%
1090 \!ucoord{\number\xO}{\number\xl}{\number\yb}{\number\auxa}{\number\deuc}{\yf}{-1}%
1091 \arrow <4pt> [.2,1.1] from {\xmed} {\ymed} to {\xe} {\ye}
1092 \arrow <4pt> [.2,1.1] from {\xd} {\yd} to {\xf} {\yf}
1093 \or % 10=double arrow, opposite directions
1094 %%
1095 %% sets the separation (distance) between the two parallel lines, if
1096 %% horizontal or vertical 2pt is enough, if not 2.5pt. The extra space
1097 %% is needed because of the arrow tip.
1098 \auxa=22
1099 \ifnum\number\yO=\number\yl
1100 \auxa=20
1101 \fi
1102 \ifnum\number\xO=\number\xl
1103 \auxa=20
1104 \fi
1105 %% the two parallel lines will be given by (xmed,ymed)(xd,yd), and
1106 %% (xe,ye)(xf,yf)
1107 \!ucoord{\number\yO}{\number\yl}{\number\xa}{\number\auxa}{\number\deuc}{\xmed}{-1}%
1108 \!ucoord{\number\xO}{\number\xl}{\number\ya}{\number\auxa}{\number\deuc}{\ymed}{1}%
1109 \!ucoord{\number\yO}{\number\yl}{\number\xa}{\number\auxa}{\number\deuc}{\xd}{1}%
1110 \!ucoord{\number\xO}{\number\xl}{\number\ya}{\number\auxa}{\number\deuc}{\yd}{-1}%
1111
1112 \!ucoord{\number\yO}{\number\yl}{\number\xb}{\number\auxa}{\number\deuc}{\xe}{-1}%
1113 \!ucoord{\number\xO}{\number\xl}{\number\yb}{\number\auxa}{\number\deuc}{\ye}{1}%
1114 \!ucoord{\number\yO}{\number\yl}{\number\xb}{\number\auxa}{\number\deuc}{\xf}{1}%
1115 \!ucoord{\number\xO}{\number\xl}{\number\yb}{\number\auxa}{\number\deuc}{\yf}{-1}%
1116 \arrow <4pt> [.2,1.1] from {\xmed} {\ymed} to {\xe} {\ye}
1117 \arrow <4pt> [.2,1.1] from {\xf} {\yf} to {\xd} {\yd}
1118 \or % 11=null arrow (no arrow, only a label)
1119 %%
1120 %% does not draw the arrow, it allows to put two labels in one "arrow"
1121 %%
1122 \fi
1123 %% The label positioning.
1124 %% If the arrows are horizontal or verticals the box is built centered
1125 %% in the object center. If the arrows are oblique the box is built in
1126 %% such a way to avoid the arrow label, having in account the
1127 %% quadrante and the relative position of the arrow and the
1128 %% corresponding label
1129 \auxa=\xl
1130 \advance \auxa by -\xO%
1131 \ifnum \auxa=0
1132 \put {#7} at {\xc} {\yc}
1133 \else
1134 \auxb=\yl
1135 \advance \auxb by -\yO%
1136 \ifnum \auxb=0 \put {#7} at {\xc} {\yc}
1137 \else
1138 \ifnum \auxa > 0
1139 \ifnum \auxb > 0
1140 \ifnum #8=1
1141 \put {#7} [rb] at {\xc} {\yc}
1142 \else
1143 \put {#7} [lt] at {\xc} {\yc}
1144 \fi
1145 \else
1146 \ifnum #8=1
1147 \put {#7} [lb] at {\xc} {\yc}
1148 \else
1149 \put {#7} [rt] at {\xc} {\yc}
1150 \fi
1151 \fi
1152 \else
1153 \ifnum \auxb > 0
1154 \ifnum #8=1
1155 \put {#7} [rt] at {\xc} {\yc}
1156 \else
1157 \put {#7} [lb] at {\xc} {\yc}
1158 \fi
1159 \else
1160 \ifnum #8=1
1161 \put {#7} [lt] at {\xc} {\yc}
1162 \else
1163 \put {#7} [rb] at {\xc} {\yc}
1164 \fi
1165 \fi
1166 \fi
1167 \fi
1168 \fi
1169 }
1170
1171 %%
1172 %% Curved arrow command
1173 %%
1174 %% \cmor(<list of points (n. odd)>){<label>}
1175 %%
1176 %% The plot must be changed in such a way that its syntax is coherent
1177 %% with the other commands
1178 %%
1179 \def\modifplot(#1{\!modifqcurve #1}
1180 \def\!modifqcurve(#1,#2){\xO=#1%
1181 \yO=#2%
1182 \multiply \xO by \expansao%
1183 \multiply \yO by \expansao%
1184 \!start (\xO,\yO)
1185 \!modifQjoin}
1186 \def\!modifQjoin(#1,#2)(#3,#4){\xO=#1%
1187 \yO=#2%
1188 \xl=#3%
1189 \yl=#4%
1190 \multiply \xO by \expansao%
1191 \multiply \yO by \expansao%
1192 \multiply \xl by \expansao%
1193 \multiply \yl by \expansao%
1194 \!qjoin (\xO,\yO) (\xl,\yl) % \!qjoin is defined in QUADRATIC
1195 \!ifnextchar){\!fim}{\!modifQjoin}}
1196 \def\!fim){\ignorespaces}
1197
1198 %%
1199 %% The command to draw the arrow tip receives the list of points, get
1200 %% from it the last pair of points and depending of the user choice
1201 %% the arrow tip is drawn.
1202 %%
1203 \def\setaxy(#1{\!pontosxy #1}
1204 \def\!pontosxy(#1,#2){%
1205 \!maispontosxy}
1206 \def\!maispontosxy(#1,#2)(#3,#4){%
1207 \!ifnextchar){\!fimxy#3,#4}{\!maispontosxy}}
1208 \def\!fimxy#1,#2){\xO=#1%
1209 \yO=#2
1210 \multiply \xO by \expansao
1211 \multiply \yO by \expansao
1212 \xl=\xO%
1213 \yl=\yO%
1214 \aux=1%
1215 \multiply \aux by \auxa%
1216 \advance\xl by \aux%
1217 \aux=1%
1218 \multiply \aux by \auxb%
1219 \advance\yl by \aux%
1220 \arrow <4pt> [.2,1.1] from {\xO} {\yO} to {\xl} {\yl}}
1221
1222
1223 %%
1224 %% The definition of the command "cmor"
1225 %%
1226 \def\cmor#1 #2(#3,#4)#5{%
1227 \!ifnextchar[{\!cmora{#1}{#2}{#3}{#4}{#5}}{\!cmora{#1}{#2}{#3}{#4}{#5}[0] }}
1228 \def\!cmora#1#2#3#4#5[#6]{%
1229 \ifcase #2% "\pup" (pointing up)
1230 \auxa=0% x do not change
1231 \auxb=1% y "up"
1232 \or% \pdown" (pointing down)
1233 \auxa=0% x do not change
1234 \auxb=-1% y "down"
1235 \or% "\pright" (pointing right)
1236 \auxa=1% x "right"
1237 \auxb=0% y do not change
1238 \or% "\pleft" (pointing left)
1239 \auxa=-1% x "left"
1240 \auxb=0% y do not change
1241 \fi % the line
1242 \ifcase #6 % arrow solid
1243 \modifplot#1% draw the line
1244 % and the arrow tip
1245 \setaxy#1
1246 \or % arrow (with tip) dashed
1247 \setdashes
1248 \modifplot#1% draw the line
1249 \setaxy#1
1250 \setsolid
1251 \or % arrow (without tip)
1252 \modifplot#1% draw the line
1253 \fi % injection morphism
1254 %% label
1255 \xO=#3%
1256 \yO=#4%
1257 \multiply \xO by \expansao%
1258 \multiply \yO by \expansao%
1259 \put {#5} at {\xO} {\yO}}
1260
1261 %%
1262 %% Command to build the objects
1263 %% \obj(x,y){<text>}[<label>]
1264 %%
1265 \def\obj(#1,#2){%
1266 \!ifnextchar[{\!obja{#1}{#2}}{\!obja{#1}{#2}[Nulo]}}
1267 \def\!obja#1#2[#3]#4{%
1268 \!ifnextchar[{\!objb{#1}{#2}{#3}{#4}}{\!objb{#1}{#2}{#3}{#4}[1]}}
1269 \def\!objb#1#2#3#4[#5]{%
1270 \xO=#1%
1271 \yO=#2%
1272 \def\!pinta{\normalsize$\bullet$}% sets the normal size of the bullet
1273 \def\!nulo{Nulo}%
1274 \def\!arg{#3}%
1275 \!compara{\!arg}{\!nulo}%
1276 \ifcompara\def\!arg{#4}\fi%
1277 \multiply \xO by \expansao%
1278 \multiply \yO by \expansao%
1279 \setbox\caixa=\hbox{#4}%
1280 \!coloca{(\!arg)(#1,#2)(\number\ht\caixa,\number\wd\caixa,\number\dp\caixa)}{\pilha}%
1281 \auxa=\wd\caixa \divide \auxa by 13107%2
1282 \advance \auxa by 50
1283 \auxb=\ht\caixa
1284 \advance \auxb by \number\dp\caixa
1285 \divide \auxb by 13107%2
1286 \advance \auxb by 50
1287 \ifcase \tipografo % commutative diagrams
1288 \put{#4} at {\xO} {\yO}
1289 \or % directed graphs
1290 \ifcase #5 % c=0, placement of the object (c=center)
1291 \put{#4} at {\xO} {\yO}
1292 \or % n=1
1293 \put{\!pinta} at {\xO} {\yO}
1294 \advance \yO by \number\auxb % height+depth+5
1295 \put{#4} at {\xO} {\yO}
1296 \or % ne=2
1297 \put{\!pinta} at {\xO} {\yO}
1298 \advance \auxa by -2 % para fazer o ajuste (imperfeito)
1299 \advance \auxb by -2 % ao raio da circunferencia de centro (x,y)
1300 \advance \xO by \number\auxa % width+5
1301 \advance \yO by \number\auxb % height+depth+5
1302 \put{#4} at {\xO} {\yO}
1303 \or % e=3
1304 \put{\!pinta} at {\xO} {\yO}
1305 \advance \xO by \number\auxa % width+5
1306 \put{#4} at {\xO} {\yO}
1307 \or % se=4
1308 \put{\!pinta} at {\xO} {\yO}
1309 \advance \auxa by -2 % para fazer o ajuste (imperfeito)
1310 \advance \auxb by -2 % ao raio da circunferencia de centro (x,y)
1311 \advance \xO by \number\auxa % width+5
1312 \advance \yO by -\number\auxb % height+depth+5
1313 \put{#4} at {\xO} {\yO}
1314 \or % s=5
1315 \put{\!pinta} at {\xO} {\yO}
1316 \advance \yO by -\number\auxb % height+depth+5
1317 \put{#4} at {\xO} {\yO}
1318 \or % sw=6
1319 \put{\!pinta} at {\xO} {\yO}
1320 \advance \auxa by -20 % adjusting to the radius of the circle
1321 \advance \auxb by -20 % with center in (x,y)
1322 \advance \xO by -\number\auxa % width+5
1323 \advance \yO by -\number\auxb % height+depth+5
1324 \put{#4} at {\xO} {\yO}
1325 \or % w=7
1326 \put{\!pinta} at {\xO} {\yO}
1327 \advance \xO by -\number\auxa % width+5
1328 \put{#4} at {\xO} {\yO}
1329 \or % nw=8
1330 \put{\!pinta} at {\xO} {\yO}
1331 \advance \auxa by -20 % adjusting to the radius of the circle
1332 \advance \auxb by -20 % with center in (x,y)
1333 \advance \xO by -\number\auxa % width+5
1334 \advance \yO by \number\auxb % height+depth+5
1335 \put{#4} at {\xO} {\yO}
1336 \fi
1337 \or % undirect graphs
1338 \ifcase #5 % c=0
1339 \put{#4} at {\xO} {\yO}
1340 \or % n=1
1341 \put{\!pinta} at {\xO} {\yO}
1342 \advance \yO by \number\auxb % height+depth+5
1343 \put{#4} at {\xO} {\yO}
1344 \or % ne=2
1345 \put{\!pinta} at {\xO} {\yO}
1346 \advance \auxa by -20 % adjusting to the radius of the circle
1347 \advance \auxb by -20 % with center in (x,y)
1348 \advance \xO by \number\auxa % width+5
1349 \advance \yO by \number\auxb % height+depth+5
1350 \put{#4} at {\xO} {\yO}
1351 \or % e=3
1352 \put{\!pinta} at {\xO} {\yO}
1353 \advance \xO by \number\auxa % width+5
1354 \put{#4} at {\xO} {\yO}
1355 \or % se=4
1356 \put{\!pinta} at {\xO} {\yO}
1357 \advance \auxa by -20 % see above
1358 \advance \auxb by -20
1359 \advance \xO by \number\auxa % width+5
1360 \advance \yO by -\number\auxb % height+depth+5
1361 \put{#4} at {\xO} {\yO}
1362 \or % s=5
1363 \put{\!pinta} at {\xO} {\yO}
1364 \advance \yO by -\number\auxb % height+depth+5
1365 \put{#4} at {\xO} {\yO}
1366 \or % sw=6
1367 \put{\!pinta} at {\xO} {\yO}
1368 \advance \auxa by -20 % see above
1369 \advance \auxb by -20
1370 \advance \xO by -\number\auxa % width+5
1371 \advance \yO by -\number\auxb % height+depth+5
1372 \put{#4} at {\xO} {\yO}
1373 \or % w=7
1374 \put{\!pinta} at {\xO} {\yO}
1375 \advance \xO by -\number\auxa % width+5
1376 \put{#4} at {\xO} {\yO}
1377 \or % nw=8
1378 \put{\!pinta} at {\xO} {\yO}
1379 \advance \auxa by -20 % see above
1380 \advance \auxb by -20
1381 \advance \xO by -\number\auxa % width+5
1382 \advance \yO by \number\auxb % height+depth+5
1383 \put{#4} at {\xO} {\yO}
1384 \fi
1385 \else % graphs with circular frames
1386 \ifnum\auxa<\auxb % set aux to be the greatest dimension
1387 \aux=\auxb
1388 \else
1389 \aux=\auxa
1390 \fi
1391 % if the length of the box is less then 1em, the size of the circle is
1392 % adjust in order not to be less then 10pt
1393 \ifdim\wd\caixa<1em
1394 \dimen99 = 10pt
1395 \aux=\dimen99
1396 \divide \aux by 13107
1397 \advance \aux by 50
1398 \fi
1399 \advance\aux by -20
1400 \xl=\xO
1401 \advance\xl by \aux
1402 \ifnum\aux<120 % gives (more or less) three digits
1403 \circulararc 360 degrees from {\xl} {\yO} center at {\xO} {\yO}
1404 \else
1405 \ellipticalarc axes ratio {\auxa}:{\auxb} 360 degrees from {\xl} {\yO} center at {\xO} {\yO}
1406 \fi
1407 \put{#4} at {\xO} {\yO}
1408 \fi
1409 }
1410
1411
1412 \catcode`!=12 % ***** THIS MUST NEVER BE OMITTED (see PiCTeX)