summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/familytree/ft-gens.dtx
blob: f179f060ec3c986ee9b027ace95821ce9f78c292 (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
% \iffalse
% Copyright 2022 Jiro Senju
%
% This package is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% any later version.
%
% This package is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this package.  If not, see <http://www.gnu.org/licenses/>.
% \fi
%
% \newcommand{\tOne}{Parent-child Relationship Box or Generations Box}
% \newcommand{\tTwo}{(\texttt{ft-gens.dtx})}
% \section[\tOne{} \tTwo]{\tOne\\\tTwo}
%
% \DescribeMacro{\pcdef}
% \cmd{\pcdef
%   \marg{new box name}
%   \marg{parent box name}
%   \marg{child box name}
% }
% \medskip
%
% Defines a parent-child relationship box.
% Connects the given \meta{parent box} and \meta{child box} by a line,
% and creates a new box \meta{new box name}.
%
% \meta{parent box} is a box who has only one line from an individual
% name to one's child. For example, the box created by |\indvdldef| with
% |\maleline| attribute (and equivalent) is specified.
% Obviously, \meta{child box} is a box who has a line to one's parent.
% For example, the box created by |\indvdldef| with |\biological| or
% |\adopted| is specified as a child mark.
%
% |\pcdef| is a simplified version of |\gensdef|, which is discussed next.
% \bigskip
%
% \noindent
% \DescribeMacro{\gensdef}
% \cmd{\gensdef
%   \marg{new box name}
%   \marg{parent box name}
%   \marg{list of connection-pair}
% }
%
% \begin{tabbing}
% \hspace{4em} \=\kill
% \texttt{connection-pair :=}\\
% \> \marg{individual box name in the parent box}\\
% \> \marg{child box name}
% \end{tabbing}
% \medskip
%
% Defines a two-generations box.
% Same to |\pcdef|, \meta{child box} is a box who has only one line to
% the parent, but \meta{parent box} can have multiple lines to one's child.
% It is \meta{connection-pair} that makes it clear which parent connects
% to which child box.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Example}
%
% \begin{enumerate}
% \item
% |\sblngdef| for daughters, |\pcdef|, and then |\sblngdef| for their
% parent generation.
% \srcfig{fig3Robert1}
%
% \needspace{2\baselineskip}
% \item
% two |\sblngdef|, and then |\gensdef|. The result is essentially same.
% One difference is the space between the siblings which was
% automatically adjusted in previous example.
% \srcfig{fig3Robert2}
% \end{enumerate}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{The order of connecting multiple boxes}
% \label{sec:Lily1}
%
% If we get |\sblngdef| as a tool to align the individual boxes in
% column, then |\pcdef| and |\gensdef| are the tool to align the boxes
% in row.
% When the siblings have their child for each, then there are multiple
% parent-child relationships, so it is better to call it generations box
% rather than parent-child box.
%
% There are two ways to draw such tree. One is to define parent-child
% first and then define the siblings of the parent generation. The other
% is in the reverse order, eg. to define the siblings of the parent
% generation first and then define the parent-child relationship for each.
%
% Let's consider about these two ways.
%
% \begin{enumerate}
% \needspace{2\baselineskip}
% \item
% define two parent-child relationships, and then define the siblings.
%
% \srcfig{fig3Lily1}
%
% \needspace{3\baselineskip}
% \item
% define the sisters, and then define the parent-child for each.
%
% \srcfig{fig3Lily2}
% \end{enumerate}
%
% As you see, by the 1st method the length of two lines to their child
% differs and the positions (in horizontal) of the child generation are
% not equal. That makes the tree uneasy to understand straightforward.
% It is because that the feature of |\sblngdef| to set the line length
% to the longest one didn't work.
% The argument passed to |\sblngdef| were already connected to the child,
% so if |\sblngdef| extended the line it would be much worse result.
%
% On the other hand, by the 2nd method, the argument passed to
% |\sblngdef| were not connected to the child. So it is harmless if
% |\sblngdef| extends the line.
% \smallskip
%
% Even if you took the 1st method, there still exists to make the line
% length equal.
% Using |\indvdldef| feature to adjust the line length, set the length
% of Lily's |\femaleline| (|\matrilineal|) to the one of Petunia's.
% To achieve this, calculate the difference of the name length of these
% sisters and give an optional argument of |\indvdldef|.
% The result should be same to above.
% \medskip
%
% \srcfig{fig3Lily3}
% \medskip
%
% You can get the same result if you use |\nameboxcfg| since it has a
% feature to set the length of a line to child.
% But it is not a good idea to use |\nameboxcfg| every time when you
% |\indvdldef|. The value set by |\nameboxcfg| should be applied wider,
% and it is not supposed to use for a single |\indvdldef|. It is better
% to append an optional argument to |\indvdldef|.
% \smallskip
%
% There is one more option. It is to set the length of Lily's name to Petunia's.
% By this method, the space between Lily's name and the line to child
% becomes wider and the length of lines become equal.
% \medskip
%
% \srcfig{fig3Lily4}
% \medskip
%
% The sequence or the order to define and connect the boxes is important.
% In connecting the boxes, this package considers the size of the
% being connected individual boxes. For example, the sibling box
% considers the height of the
% individual box and makes the boxes to be never overlapped.
% But in connecting a child to the already defined sibling box, this
% feature doesn't work. So the children of the siblings may be
% overlapped. In this case, you need to insert the interval box between
% the siblings manually.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsectImpl
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsubsection{Generations box --- core}
%
% \iffalse
% \parag{Customization}
%
% \DescribeMacro{\ftgenscfg}
% \NoDescription
%    \begin{macrocode}
% \newcommand{\ftgenscfg}[1]{%
% }
%    \end{macrocode}
% \fi
%
% \parag{Connection pair}
%
% \DescribeMacro{\ft@getpair}
% Extracts a connection-pair from the given list,
% defines the connection-point in the parent box (the former of the pair)
% as |\ft@cpoint|, and defines the child box name (the latter of the
% pair) as |\ft@kids|.
% \smallskip
%
%    \begin{macrocode}
\def\ft@getpair#1#2#3{% connection-pair parent-box-name
  \ft@dbgmsg{args #1, #2, #3}%
  \@ifundefined{#3#1nameCY}{%
    \@ifundefined{#3#1mrrgCY}{%
      \xdef\ft@cpoint{#1nameCY}%
    }{%
      \xdef\ft@cpoint{#3#1mrrgCY}%
    }%
  }{%
    \xdef\ft@cpoint{#3#1nameCY}%
  }%
  \xdef\ft@kids{#2}%
}
%    \end{macrocode}
%
% \parag{Top margin}
%
% \DescribeMacro{\def@calc@xtop}
%
%    \begin{macrocode}
\newcommand{\ft@calc@xtop}[4]{% name parent cpoint kids
  % top half of kids
  \ft@len=\dimexpr\ht\@nameuse{#4} - \@nameuse{#4nameCY}pt\relax\relax%
  % top half of parent cpoint
  \@tempskipa=\dimexpr\ht\@nameuse{#2} - \@nameuse{#3}pt\relax\relax%
  %
  \ifdim\ft@len<\@tempskipa%
    \ft@len=0pt%
  \else%
    \advance\ft@len -\@tempskipa%
  \fi%
  \global#1=\ft@len%
}
%    \end{macrocode}
%
% \parag{Bottom margin}
%
% \DescribeMacro{\ft@calc@xbottom}
%
%    \begin{macrocode}
\newcommand{\ft@calc@xbottom}[4]{% name parent cpoint kids
  % bottom half of kids
  \ft@len=\@nameuse{#4nameCY}pt\relax%
  % bottom half of parent cpoint
  \@tempskipa=\@nameuse{#3}pt\relax%
  %
  \ifdim\ft@len=\@tempskipa%
    \ft@len=0pt%
    \global\setlength{\ft@depth}{\dp\@nameuse{#2}}%
    \ifdim\ft@depth<\dp\@nameuse{#4}%
      \global\setlength{\ft@depth}{\dp\@nameuse{#4}}%
    \fi%
  \else%
    \ifdim\ft@len<\@tempskipa%
      \ft@len=0pt%
      \global\setlength{\ft@depth}{\dp\@nameuse{#2}}%
    \else%
      \advance\ft@len -\@tempskipa%
      \global\setlength{\ft@depth}{\dp\@nameuse{#4}}%
    \fi%
  \fi%
  \global#1=\ft@len%
}
%    \end{macrocode}
%
% \parag{Calculate the box size}
%
% \DescribeMacro{\ft@gens@size}
%
%    \begin{macrocode}
\newlength{\ft@xtop}
\newlength{\ft@xbottom}
\newcommand{\ft@gens@size}[2]{% parent-box connect-pair-list
  \@tempswatrue%
  \ft@width=0pt%
  \@for\@temptokena:=#2\do{%
    \expandafter\ft@getpair\@temptokena{#1}%
    \ft@dbgmsg{\ft@cpoint and \ft@kids}%
    \if@tempswa%
      \ft@calc@xtop{\ft@xtop}{#1}{\ft@cpoint}{\ft@kids}%
      \@tempswafalse%
    \fi%
    \setlength{\ft@len}{\wd\@nameuse{\ft@kids}}%
    \ifdim\ft@width<\ft@len%
      \global\ft@width=\ft@len%
    \fi%
  }%
  \ft@calc@xbottom{\ft@xbottom}{#1}{\ft@cpoint}{\ft@kids}%
  \ft@dbgmsg{xtop \the\ft@xtop, xbottom \the\ft@xbottom}%
  %
  \ft@x=\dimexpr\wd\@nameuse{#1}% - \ft@cmarkbox@length\relax%
  \ft@dbgmsg{x \the\ft@x}%
  \advance\ft@width \ft@x%
  \ft@dbgmsg{w \the\ft@width}%
  \ft@height=\dimexpr\ht\@nameuse{#1} + \ft@xtop + \ft@xbottom\relax%
  \ft@dbgmsg{kids H \the\ht\@nameuse{\ft@kids}}%
  \ft@dbgmsg{H \strip@pt\ft@height, D \strip@pt\ft@depth}%
}
%    \end{macrocode}
%
% \parag{Layout}
%
% \DescribeMacro{\ft@gens@layout}
%
%    \begin{macrocode}
\newcommand{\ft@gens@layout}[3]{%
  % box-name parent-box-name {{parent-name} {child-name}, ...}
  \ft@newnamebox{#1}{%
    \edef\@w{\strip@pt\ft@width}%
    \edef\@h{\strip@pt\ft@height}%
    \begin{picture}(\@w,\@h)%
      \ft@dbgframe{\@w,\@h}%
      %
      \ft@y=\ft@xbottom%
      \ft@dbgplot{0,\strip@pt\ft@y}%
      \put(0,\strip@pt\ft@y){\usebox{\@nameuse{#2}}}%
      \advance\ft@y \@nameuse{#2nameCY}pt%
      \ft@namexdefstrip{#1nameCY}{\ft@y}%
      %\ft@namexdefstrip{#1#2nameCY}{\ft@y}%
      %
      \@for\@temptokena:=#3\do{%%
        \expandafter\ft@getpair\@temptokena{#2}%
        \ft@dbgmsg{\ft@cpoint and \ft@kids}%
        %
        \ft@y=\dimexpr\ft@xbottom + \@nameuse{\ft@cpoint}pt\relax%
        \ft@dbgmsg{parent cpoint \the\ft@y}%
        \ft@dbgplot{\strip@pt\ft@x,\strip@pt\ft@y}%
        %
        \advance\ft@y  -\@nameuse{\ft@kids nameCY}pt%
        \ft@dbgmsg{final child y \the\ft@y}%
        \put(\strip@pt\ft@x,\strip@pt\ft@y){%
          \usebox{\@nameuse{\ft@kids}}}%
        \ft@namexdefstrip{#1\ft@kids Y}{\ft@y}%
      }%
    \end{picture}%
  }%
}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsubsection{Generations box --- interface}
%
% \DescribeMacro{\ftgensdef}
%
%    \begin{macrocode}
\newcommand{\ftgensdef}[3]{%
  % box-name parent-box-name {{parent-name} {child-name}, ...}
  %
  % calculate the size of the new box
  \ft@gens@size{#2}{#3}%
  %
  % draw them all
  \ft@gens@layout{#1}{#2}{#3}%
  %
  \@ifundefined{#2hascmark}{}{%
    \ft@namexdef{#1hascmark}{\@nameuse{#2hascmark}}%
  }%
  \ft@nameboxsz{#1}{\ft@height}{\ft@depth}%
}
\ft@alias{gensdef}
%    \end{macrocode}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsubsection{Parent-child box --- interface}
%
% \DescribeMacro{\ftpcdef}
%
%    \begin{macrocode}
\newcommand{\ftpcdef}[3]{% box-name parent-box-name child-box-name
  \ftgensdef{#1}{#2}{{#2}{#3}}%
}
\ft@alias{pcdef}
%    \end{macrocode}