Debian Codegraph @

texmf-dist/source/latex/familytree/ft-marriage.dtx

raw
1 % \iffalse
2 % Copyright 2022 Jiro Senju
3 %
4 % This package is free software; you can redistribute it and/or modify
5 % it under the terms of the GNU General Public License as published by
6 % the Free Software Foundation; either version 2 of the License, or
7 % any later version.
8 %
9 % This package is distributed in the hope that it will be useful,
10 % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 % GNU General Public License for more details.
13 %
14 % You should have received a copy of the GNU General Public License
15 % along with this package. If not, see <http://www.gnu.org/licenses/>.
16 % \fi
17 %
18 % \section{Marriage Box (\texttt{ft-marriage.dtx})}
19 %
20 % \DescribeMacro{\mrrgdef}
21 % \cmd{\mrrgdef
22 % \marg{new box name}
23 % \marg{spouse list A}
24 % \marg{oneself}
25 % \marg{spouse list B}
26 % \oarg{childline xlength}
27 % }
28 % \medskip
29 %
30 % Defines a marriage box with a specified name \meta{new box name}.
31 % To support remarrying and the concubines, the spouses are specified by
32 % a list. The element of the list is a box name defined by |\indvdldef|.
33 % \meta{spouse list A} is placed upper side of \meta{oneself}, and
34 % \meta{spouse list B} is lower side.
35 % All box names are NOT \CS{} (no backslash).
36 % \smallskip
37 %
38 % Aligns them in the same column, and connects them by a double line if the
39 % marriage is official. If the marriage is not official (|\private|
40 % attribute), uses a dashed double line.
41 % Those double line is placed at the center of the length of the name of
42 % \meta{oneself}.
43 % \smallskip
44 %
45 % If a spouse has a child (|\haschild| attribute),
46 % then the line to their child is drawn from the center of the
47 % double line.
48 % \smallskip
49 %
50 % Like |\sblngdef|, the interval box can be inserted if you want more
51 % spaces.
52 % \bigskip
53 %
54 % Like |\indvdldef|, some connection points are defined. Their origin
55 % is left-bottom of the box and the unit is |pt|.
56 %
57 % \begin{itemize}
58 % \item \meta{box name}|nameCY|
59 %
60 % the center of the height of the name of \meta{oneself}
61 %
62 % \item \meta{box name}\meta{individual box name}|nameCY|
63 %
64 % the center of the height of the name of who has any child-mark
65 %
66 % \item \meta{box name}\meta{individual box name}|mrrgCY|
67 %
68 % the center of the double line when any spouse has |\haschild| attribute
69 % \end{itemize}
70 %
71 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 % \subsection{Customization}
73 %
74 % \DescribeMacro{\mrrgboxcfg}
75 % \cmd{\mrrgboxcfg
76 % \marg{space between two lines}
77 % \marg{space between name and the line}
78 % \marg{line length}
79 % }
80 %
81 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 % \clearpage
83 % \subsection{Example}
84 %
85 % \begin{enumerate}
86 % \item
87 % \srcfig{fig4Robert}
88 %
89 % \clearpage
90 % \item
91 % \srcfig{fig4HenryVIII}
92 % \end{enumerate}
93 %
94 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 % \subsection{Layout and connecting in a same generation}
96 %
97 % It is not a good idea to put everything in a single family tree.
98 %
99 % For example, see King Henry VIII and his wives. Catherine of Aragon,
100 % his first wife was actually a wife of Henry's brother, Arthur. If we
101 % put King's siblings to this tree, how would it be looked? It's just
102 % ugly and hard to understand in a glance. Let's think more using an
103 % example from \refnm{sec:Lily1} again.
104 %
105 % How can we represent the Petunia -- Lily sisters tree including their husbands.
106 % As a first step, define two marriage boxes, and then define the
107 % sibling box.
108 % \medskip
109 %
110 % \srcfig{fig4Lily1}
111 % \medskip
112 %
113 % Why is this tree so ugly? There are three points to consider.
114 % \begin{enumerate}
115 % \item The position of two double lines differ from each other.
116 % \item The length of a line to their child differs too. If we connected
117 % the child, the ugliness would be improved.
118 % \item James interrupts into between Petunia and Lily. It makes the
119 % understandability worse.
120 % \end{enumerate}
121 %
122 % On fixing the first point, the position of the double line, the second
123 % point will be fixed automatically.
124 % The solution is the one already suggested in \refnm{sec:Lily1}, set
125 % the width of Lily box to Petunia's.
126 % For the third point, the position of James, how about expanding the
127 % space as a first step?
128 % \medskip
129 %
130 % \srcfig{fig4Lily2}
131 % \medskip
132 %
133 % Even spreading the space wider, James is still interrupting those two
134 % sisters. Does it look better?
135 % If we want more, the last way is to switch the position of James and Lily.
136 % \medskip
137 %
138 % \srcfig{fig4Lily3}
139 % \medskip
140 %
141 % Moreover spreading the blank is a good option.
142 % \medskip
143 %
144 % \srcfig{fig4Lily4}
145 % \medskip
146 %
147 % Is this best looking?
148 % The easiness of looking is subject to one's opinion or taste.
149 % Personally I feel resistance in the order of husband and wife. But also I
150 % admit that as long as the main purpose of this tree is to represent those
151 % sisters, this position of James is not bad.
152 %
153 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 % \subsectImpl
155 %
156 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157 %
158 % \parag{Customization}
159 %
160 % \DescribeMacro{\ftmrrgboxcfg}
161 % \DescribeMacro{\mrrgboxcfg}
162 %
163 % \begin{macrocode}
164 \newlength{\ft@mrrgline@sep}
165 \setlength{\ft@mrrgline@sep}{4pt}
166 \newlength{\ft@mrrgline@sp}
167 \setlength{\ft@mrrgline@sp}{.5\ft@unit}
168 \newlength{\ft@mrrgline@length}
169 \setlength{\ft@mrrgline@length}{1.5\ft@unit}
170 \newcommand{\ftmrrgboxcfg}[3]{% sep space length
171 \ifx#1\empty\else%
172 \setlength{\ft@mrrgline@sep}{#1}%
173 \fi%
174 \ifx#2\empty\else%
175 \setlength{\ft@mrrgline@sp}{#2}%
176 \fi%
177 \ifx#3\empty\else%
178 \setlength{\ft@mrrgline@length}{#3}%
179 \fi%
180 }
181 \ft@alias{mrrgboxcfg}
182 % \end{macrocode}
183 %
184 % \parag{Parsing}
185 %
186 % \begin{macrocode}
187 \newcommand{\ft@mrrg@parse}[1]{% spouse-list
188 \global\ft@height=0pt%
189 \global\ft@width=0pt%
190 \global\ft@box@has@malelinefalse%
191 \@for\@temptokena:=#1\do{%
192 \ifx\@temptokena\empty\else%
193 \xdef\ft@spouse{\@temptokena}%
194 \@ifundefined{\@temptokena ival}{%
195 \@ifundefined{\ft@spouse haschild}{}{%
196 \global\ft@box@has@malelinetrue%
197 }%
198 \setlength{\ft@len}{\wd\@nameuse{\ft@spouse}}%
199 \ifdim\ft@width<\ft@len%
200 \global\ft@width=\ft@len%
201 \fi%
202 \ft@dbgmsg{\ft@spouse, W \the\wd\@nameuse{\ft@spouse},%
203 H \the\ht\@nameuse{\ft@spouse},%
204 D \the\dp\@nameuse{\ft@spouse}}%
205 \global\advance\ft@height \dimexpr\ft@mrrgline@length%
206 + 2\ft@mrrgline@sp\relax%
207 \ft@dbgmsg{\ft@spouse, H \the\ft@height}%
208 }{}%
209 \global\advance\ft@height \dimexpr\ht\@nameuse{\ft@spouse}%
210 + \dp\@nameuse{\ft@spouse}\relax%
211 \ft@dbgmsg{\ft@spouse, h H \the\ft@height}%
212 \fi%
213 }%
214 %
215 \ifft@box@has@maleline%
216 \global\advance\ft@width \ft@namebox@maleline@length%
217 \fi%
218 %
219 \global\ft@depth=\dp\@nameuse{\ft@spouse}%
220 \global\advance\ft@height \dimexpr -2\ft@mrrgline@sp%
221 - \ft@mrrgline@length - \ft@depth\relax%
222 \ft@dbgmsg{final H \the\ft@height, D \the\ft@depth}%
223 }
224 % \end{macrocode}
225 %
226 % \parag{The double line}
227 %
228 % \DescribeMacro{\ft@mrrg@line}
229 %
230 % \begin{macrocode}
231 \newlength{\ft@mrrg@chlen}
232 \newcommand{\ft@mrrg@line}[5]{% box-name spouse cx sp length
233 \ft@x=#3%
234 \global\advance\ft@height -#4%
235 \@tempskipb=\dimexpr\ft@mrrgline@sep/2\relax%
236 \edef\@y{\strip@pt\ft@height}%
237 \@ifundefined{#2private}{%
238 \ft@len=#5\relax%
239 \edef\@l{\strip@pt\ft@len}%
240 \put(\strip@pt\dimexpr\ft@x - \@tempskipb, \@y){\line(0,-1){\@l}}%
241 \put(\strip@pt\dimexpr\ft@x + \@tempskipb, \@y){\line(0,-1){\@l}}%
242 }{%
243 % this divisor should match the delta_y for multiput
244 \ft@len=#5\relax%
245 \ft@len=\dimexpr\ft@len/2 + .5pt\relax%
246 \@tempcnta=\dimexpr\ft@len/65536\relax%
247 \multiput(\strip@pt\dimexpr\ft@x - \@tempskipb, \@y)%
248 (0,-2){\@tempcnta}{\line(0,-1){.5}}%
249 \multiput(\strip@pt\dimexpr\ft@x + \@tempskipb, \@y)%
250 (0,-2){\@tempcnta}{\line(0,-1){.5}}%
251 }%
252 \@ifundefined{#2haschild}{}{%
253 \ft@len=#5\relax%
254 \ft@y=\dimexpr\ft@height - \ft@len/2\relax%
255 \put(\strip@pt\dimexpr\ft@x + \@tempskipb,\strip@pt\ft@y)%
256 {\line(1,0){\strip@pt\ft@mrrg@chlen}}%
257 \ft@dbgplot{\strip@pt\ft@x,\strip@pt\ft@y}%
258 \ft@namexdefstrip{#1#2mrrgCY}{\ft@y}%
259 }%
260 \ft@len=#5\relax%
261 \@tempskipa=#4\relax%
262 \global\advance\ft@height \dimexpr -\ft@len - \@tempskipa\relax%
263 \ft@dbgmsg{line #2 H \the\ft@height}%
264 }
265 % \end{macrocode}
266 %
267 % \parag{Layout the names}
268 %
269 % \DescribeMacro{\ft@mrrg@name}
270 %
271 % \begin{macrocode}
272 \newcommand{\ft@mrrg@name}[2]{% box-name individual-name
273 \global\advance\ft@height -\ht\@nameuse{#2}%
274 \put(0,\strip@pt\ft@height){\usebox{\@nameuse{#2}}}%
275 \ft@dbgframe[0,\strip@pt\ft@height]%
276 {\strip@pt\wd\@nameuse{#2},\strip@pt\ht\@nameuse{#2}}%
277 %
278 \@ifundefined{#2hasmaleline}{}{%
279 \ft@x=\@nameuse{#2nameX}pt%
280 \ft@y=\dimexpr\ft@height + \@nameuse{#2nameCY}pt\relax%
281 \ft@len=\dimexpr\ft@width - \@nameuse{#2nameX}pt%
282 %- \ft@namebox@maleline@sp%
283 \relax%
284 \put(\strip@pt\ft@x,\strip@pt\ft@y){\line(1,0){\strip@pt\ft@len}}%
285 \ft@namexdefstrip{#1#2nameCY}{\ft@y}%
286 }%
287 %
288 \@ifundefined{#2hascmark}{}{%
289 \ft@len=\dimexpr\ft@height + \@nameuse{#2nameCY}pt\relax%
290 \ft@namexdefstrip{#1#2nameCY}{\ft@len}%
291 \ft@dbgplot{0,\strip@pt\ft@len}%
292 }%
293 \global\advance\ft@height -\dp\@nameuse{#2}%
294 \ft@dbgmsg{name #2 H \the\ft@height}%
295 }
296 % \end{macrocode}
297 %
298 % \subsubsection{Layout and connect the individuals --- core}
299 %
300 % \DescribeMacro{\ft@mrrg@spouse}
301 %
302 % \begin{macrocode}
303 \newlength{\ft@mrrg@ival}
304 \newcommand{\ft@mrrg@spouse}[2]{% box-name list
305 \global\ft@mrrg@ival=0pt%
306 \@for\@temptokena:=#2\do{%
307 \@ifundefined{\@temptokena ival}{%
308 \@tempskipa=\dimexpr\ft@mrrgline@length + \ft@mrrg@ival\relax%
309 \if@tempswa%
310 \ft@mrrg@name{#1}{\@temptokena}%
311 \ft@mrrg@line{#1}{\@temptokena}{\ft@xx}{\ft@mrrgline@sp}%
312 {\@tempskipa}%
313 \else%
314 \ft@mrrg@line{#1}{\@temptokena}{\ft@xx}{\ft@mrrgline@sp}%
315 {\@tempskipa}%
316 \ft@mrrg@name{#1}{\@temptokena}%
317 \fi%
318 \global\ft@mrrg@ival=0pt%
319 }{%
320 \global\advance\ft@mrrg@ival%
321 \dimexpr\ht\@nameuse{\@temptokena}%
322 + \dp\@nameuse{\@temptokena}\relax%
323 }%
324 }%
325 }
326 % \end{macrocode}
327 %
328 % \subsubsection{Marriage box --- interface}
329 %
330 % \DescribeMacro{\ftmrrgdef}
331 % \DescribeMacro{\mrrgdef}
332 %
333 % \begin{macrocode}
334 \NewDocumentCommand{\ftmrrgdef}{mmmmO{0pt}}{%
335 % box-name spouse-listA oneself spouse-listB [xline]
336 \ft@xx=\@nameuse{#3nameCX}pt\relax%
337 \ft@mrrg@parse{#2,#3,#4}%
338 %
339 \advance\ft@width #5%
340 \global\ft@mrrg@chlen=\dimexpr\ft@width - \ft@xx%
341 - \ft@mrrgline@sep/2\relax%
342 %
343 \ft@theight=\ft@height%
344 \ft@newnamebox{#1}{%
345 \edef\@w{\strip@pt\ft@width}%
346 \edef\@h{\strip@pt\ft@height}%
347 \begin{picture}(\@w,\@h)%
348 \ft@dbgframe{\@w,\@h}%
349 %
350 \ifx#2\@nil\else%
351 \@tempswatrue%
352 \ft@mrrg@spouse{#1}{#2}%
353 \fi%
354 %
355 \ft@mrrg@name{#1}{#3}%
356 \@ifundefined{#1#3nameCY}{}{%
357 \ft@len=\@nameuse{#1#3nameCY}pt\relax%
358 \ft@dbgplot{1,\strip@pt\ft@len}%
359 \ft@namexdefstrip{#1nameCY}{\ft@len}%
360 }%
361 \@ifundefined{#3hascmark}{}{%
362 \ft@namexdef{#1hascmark}{\@nameuse{#3hascmark}}%
363 }%
364 %
365 \ifx#4\empty\else%
366 \@tempswafalse%
367 \ft@mrrg@spouse{#1}{#4}%
368 \fi%
369 \end{picture}%
370 }%
371 \ft@nameboxsz{#1}{\ft@theight}{\ft@depth}%
372 }
373 \ft@alias{mrrgdef}
374 % \end{macrocode}