Debian Codegraph @

texmf-dist/source/latex/forest-ext/forest-ext.dtx

raw
1 % \iffalse meta-comment
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % forest-ext.dtx
4 % Additions and changes Copyright (C) 2025-2026 Clea F. Rees.
5 % Code from skeleton.dtx Copyright (C) 2015-2024 Scott Pakin (see below).
6 %
7 % This work may be distributed and/or modified under the
8 % conditions of the LaTeX Project Public License, either version 1.3c
9 % of this license or (at your option) any later version.
10 % The latest version of this license is in
11 % https://www.latex-project.org/lppl.txt
12 % and version 1.3c or later is part of all distributions of LaTeX
13 % version 2008-05-04 or later.
14 %
15 % This work has the LPPL maintenance status 'muaintained'.
16 %
17 % The Current Maintainer of this work is Clea F. Rees.
18 %
19 % This work consists of all files listed in manifest.txt.
20 %
21 % The file forest-ext.dtx is a derived work under the terms of the
22 % LPPL. It is based on version 2.4 of skeleton.dtx which is part of
23 % dtxtut by Scott Pakin. A copy of dtxtut, including the
24 % unmodified version of skeleton.dtx is available from
25 % https://www.ctan.org/pkg/dtxtut and released under the LPPL.
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 %
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29 % biber --output_format=bibtex --output_resolve forest-ext.bcf to generate .bib for upload
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 % \fi
32 %
33 % \iffalse
34 %<*driver>
35 \RequirePackage{svn-prov}
36 % ^^A ref. ateb Max Chernoff: https://tex.stackexchange.com/a/723294/
37 \def\MyMakePrivateLetters{\makeatletter\ExplSyntaxOn\endlinechar13}
38 \ExplSyntaxOff
39 \ProvidesFileSVN{$Id: forest-ext.dtx 11668 2026-02-21 02:34:38Z cfrees $}[v0.3 \revinfo][\filebase DTX: ]
40 \DefineFileInfoSVN[forestextdoc]
41 \GetFileInfoSVN*
42 \let\forestextdocversion\fileversion
43 \let\forestextdocrev\filerev
44 \let\forestextdocbase\filebase
45 \let\forestextdocinfo\fileinfo
46 \let\forestextdocdate\filedate
47 \let\forestextdocname\filename
48 %^^A preamble <<<
49 \documentclass[10pt,british]{ltxdoc}
50 \partokencontext=0
51 % ^^A % if hiding first level of docstrip guards
52 % ^^A \setcounter{StandardModuleDepth}{0}
53 % ^^A l3doc loads fancyvrb
54 % ^^A fancyvrb overwrites svn-prov's macros without warning
55 % ^^A restore \fileversion \filerev in case we're using l3doc
56 \EnableCrossrefs
57 \CodelineIndex
58 \RecordChanges
59 % ^^A \OnlyDescription
60 \DoNotIndex{\verb,\ProvidesPackageSVN,\NeedsTeXFormat,\ProcessKeyOptions}
61 \usepackage{babel}
62 \usepackage{fancyhdr}
63 \usepackage[inline]{enumitem}
64 \usepackage{forest}
65 \useforestlibrary{linguistics,edges,ext.ling-debug,ext.multi-debug,ext.utils-debug}
66 \usepackage{amssymb}
67 \usepackage{mathtools}
68 \usepackage[tt={mono,tabular,lining}]{cfr-lm}
69 \usepackage{xurl}
70 \urlstyle{sf}
71 \usepackage{microtype}
72 \usepackage[a4paper,headheight=14pt,marginparwidth=45mm,hmarginratio=4:1,vscale=.8,hscale=.7,verbose]{geometry} % use 14pt for 11pt text, 15pt for 12pt text
73 %^^A % addaswyd o chronos.tex, prooftrees.dtx
74 \newlength\tewadjust
75 \newlength\forestextdoctemplgth
76 \AddToHook {begindocument/end}[.]
77 {%
78 \setlength\tewadjust{\dimeval{\marginparwidth+\marginparsep-\paperwidth+\textwidth+\oddsidemargin+1in}}%
79 \setlength\forestextdoctemplgth{0pt}%
80 \newgeometry{headheight=14pt,scale=.8,marginparwidth=0pt,marginparsep=0pt}%
81 \savegeometry{safonol}%
82 \fancyheadoffset[lh]{0pt}% ^^A REQUIRED - do NOT remove this line!!
83 \pagenumbering{arabic}%
84 }
85 \newcommand \twmarg {%
86 \restoregeometry
87 \fancyheadoffset[lh]{\tewadjust}%
88 }
89 \newcommand \twreg {%
90 \loadgeometry{safonol}%
91 \fancyheadoffset[lh]{0pt}% ^^A REQUIRED - do NOT remove this line!!
92 }
93 \usepackage{csquotes}
94 \MakeAutoQuote{‘}{’}
95 \MakeAutoQuote*{“}{”}
96 \usepackage[citestyle=authoryear-comp,bibstyle=authoryear,mergedate=basic,isbn=false,url=true,sortcites=true,backend=biber,mincrossrefs=6]{biblatex}
97 \DeclareFieldFormat{eprint:ctan}{%
98 \mkbibacro{CTAN}\addcolon\space
99 \ifhyperref
100 {\href{https://www.ctan.org/pkg/#1}{\nolinkurl{#1}}}
101 {\nolinkurl{#1}}%
102 }
103 \DeclareFieldAlias{eprint:CTAN}{eprint:ctan}
104 %^^A % \bibliography{abbrv, authors, journals-series, pub, lleoedd, ref}
105 \bibliography{forest-ext_biber}% generate for upload (gweler uchod)
106 \usepackage[section]{placeins}
107 \usepackage{tcolorbox}
108 \usepackage{varwidth}
109 %^^A if you use skins, you need to disable externalisation for boxes which use the relevant options - gweler nodiadau/tex/tex.se/tcolorbox-coursepacket-exp.tex
110 \tcbuselibrary{minted}
111 \tcbuselibrary{skins}
112 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 % ^^A Sašo Živanović: https://github.com/sasozivanovic/memoize/issues/31#issuecomment-2424700001
114 %^^A % \csappto{tcb@shield@@externalize}{\ifdefined\memoizefalse\memoizefalse\fi}
115 %^^A % \tcbset{shield externalize}
116 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 %^^A % sicrhau hyperindex=false: llwytho CYN bookmark
118 \usepackage{hypdoc}% ateb Ulrike Fischer: https://tex.stackexchange.com/a/695555/
119 \usepackage{bookmark}
120 \usepackage{cleveref}
121 \hypersetup{%
122 colorlinks=true,
123 citecolor={moss},
124 extension=pdf,
125 linkcolor={strawberry},
126 linktocpage=true,
127 pdfcreator={TeX},
128 pdfproducer={pdfeTeX},
129 urlcolor={blueberry}%
130 }
131 \makeatletter
132 % ^^A lliwiau <<<
133 \definecolor{strawberry}{rgb}{1.000,0.000,0.502}
134 \definecolor{blueberry}{rgb}{0.000,0.000,1.000}
135 \definecolor{moss}{rgb}{0.000,0.502,0.251}
136 \colorlet{doc@frame@col}{darkgray}
137 \colorlet{doc@title@col}{doc@frame@col}
138 \colorlet{doc@bg@col}{white}
139 %^^A \colorlet{doc@fg@col}{white}
140 % ^^A lliwiau >>>
141 \setminted{style=sas,breaklines=true,breakafter={\,},}
142 % ^^A tcolorbox <<<
143 \tcbset{%^^A
144 base/.style={%
145 colback=doc@bg@col,
146 colframe=doc@frame@col,
147 listing only,
148 },
149 coeden/.style={
150 colback=doc@bg@col,
151 colframe=doc@frame@col,
152 coltitle=doc@title@col,
153 boxrule=0.4pt, % 0.5mm default
154 halign=center,
155 fonttitle=\sffamily\plstyle\bfseries,
156 title={#1},
157 sharpish corners,
158 },
159 coeden dew/.style={
160 coeden=#1,
161 grow to left by=\tewadjust,
162 },
163 cod coeden/.style={
164 coeden=#1,
165 minted language=latex,
166 },
167 cod coeden dew/.style={
168 cod coeden=#1,
169 grow to left by=\tewadjust,
170 },
171 coeden float/.style={
172 coeden,
173 boxrule=0.5mm, % 0.5mm default
174 float,
175 floatplacement={!tbp},
176 list entry={\protect\numberline{\thetcbcounter\textbar}#1},
177 title={Box~\thetcbcounter\hskip 1.5em #1},
178 % tcolorbox manual 189
179 skin=enhanced,
180 attach boxed title to top left={xshift=1em,yshift=-\tcboxedtitleheight/2},
181 boxed title style={colback=doc@bg@col,sharpish corners},
182 % default uses 2mm top, 2mm bottom, 4mm left, 4mm right (p 51)
183 top=2mm+\tcboxedtitleheight/2,
184 },
185 coeden dew float/.style={
186 coeden float=#1,
187 grow to left by=\tewadjust,
188 },
189 cod coeden float/.style={
190 coeden float=#1,
191 minted language=latex,
192 },
193 cod coeden dew float/.style={
194 cod coeden float=#1,
195 grow to left by=\tewadjust,
196 },
197 every float=\centering,
198 }
199 \NewTColorBox[auto counter, crefname={box}{boxes}, Crefname={Box}{Boxes}, number within=section]{coeden}{s t{+} O {} +m }
200 {%^^A
201 IfBooleanTF={#2}{
202 IfBooleanTF={#1}{coeden dew=#4}{coeden=#4},
203 }{
204 IfBooleanTF={#1}{coeden dew float=#4}{coeden float=#4},
205 },
206 #3,
207 }
208 \NewTCBListing[use counter from=coeden, crefname={box}{boxes}, Crefname={Box}{Boxes}]{codcoeden}{ s t{+} O {} +m }
209 {%^^A
210 IfBooleanTF={#2}{
211 IfBooleanTF={#1}{cod coeden dew=#4}{cod coeden=#4},
212 }{
213 IfBooleanTF={#1}{cod coeden dew float=#4}{cod coeden float=#4},
214 },
215 listing side text,
216 halign lower=center,
217 #3,
218 }
219 \NewTCBListing{codsiml}{ O {} }
220 {%^^A
221 empty,
222 listing side text,
223 halign lower=center,
224 #1,
225 }
226 % ^^A tcolorbox >>>
227 \newminted {latex}{frame=single,rulecolor=doc@frame@col,}
228 \newminted {xml}{frame=single,rulecolor=doc@frame@col,}
229 \defbibheading{bibliography}[\refname]{%^^A
230 \section*{#1}%^^A
231 \markboth{#1}{}}
232 \errorcontextlines=10
233 \newcommand\orig@xobey@sp{}
234 \newcommand\permissivelines{%
235 \def\@xobeysp{\leavevmode\penalty100\ }%
236 }
237 \newcommand\strictlines{%
238 \let\@xobey@sp\orig@xobey@sp
239 }
240 \AddToHook{begindocument}[forestextdoc]{%
241 \let\orig@xobey@sp\@xobey@sp
242 }
243 \makeatother
244 % ^^A doc DocElement additions <<<
245 % ^^A forest
246 \NewDocElement[%
247 idxtype=autowrapped toks,
248 idxgroup=autowrapped toks,
249 printtype=\textit{auto.\ toks},
250 ]{Awtoks}{autotoks}
251 \NewDocElement[%
252 idxtype=autowrapped toks reg.,
253 idxgroup=autowrapped toks registers,
254 printtype=\textit{auto.\ toks reg.},
255 ]{Awtoksr}{autotoksr}
256 \NewDocElement[%
257 idxtype=bool.,
258 idxgroup=booleans,
259 printtype=\textit{bool.},
260 ]{Boolo}{booleano}
261 \NewDocElement[%
262 idxtype=bool.\ reg.,
263 idxgroup=boolean registers,
264 printtype=\textit{bool.\ reg.},
265 ]{Boolr}{booleanr}
266 \NewDocElement[%
267 printtype=\textit{choice},
268 idxtype=choice key,
269 idxgroup=choice keys,
270 ]{Choice}{choicekey}
271 \NewDocElement[%
272 idxtype=code key,
273 idxgroup=code keys,
274 printtype=\textit{code key},
275 ]{Code}{fcodekey}
276 \NewDocElement[%
277 idxtype=count,
278 idxgroup=counts,
279 printtype=\textit{cnt.},
280 ]{Count}{fcount}
281 \NewDocElement[%
282 idxtype=keylist,
283 idxgroup=keylists,
284 printtype=\textit{keylist},
285 ]{Keylist}{fkeylist}
286 \NewDocElement[%
287 idxtype=keylist register,
288 idxgroup=keylists registers,
289 printtype=\textit{keylist reg.},
290 ]{Keylistr}{fkeylistr}
291 \NewDocElement[%
292 idxtype=lib.,
293 idxgroup=libraries,
294 printtype=\textit{lib.},
295 ]{Lib}{library}
296 \NewDocElement[%
297 idxtype=stage,
298 idxgroup=stages,
299 printtype=\textit{stage},
300 ]{Stage}{fstage}
301 \NewDocElement[%
302 idxtype=step,
303 idxgroup=steps,
304 printtype=\textit{step},
305 ]{Step}{fstep}
306 \NewDocElement[%
307 idxtype=style,
308 idxgroup=styles,
309 printtype=\textit{style},
310 ]{Style}{fstyle}
311 \NewDocElement[%
312 idxtype=toks,
313 idxgroup=toks,
314 printtype=\textit{toks},
315 ]{Toks}{ftoks}
316 \NewDocElement[%
317 idxtype=toks register,
318 idxgroup=toks registers,
319 printtype=\textit{toks reg.},
320 ]{Toksr}{ftoksr}
321 % ^^A forest-ext
322 \NewDocElement[%
323 idxtype=tagging keylist,
324 idxgroup=tagging keylists,
325 printtype=\textit{tag.\ keylist},
326 ]{TagKeylist}{ftagkeylist}
327 % ^^A tex generic
328 \NewDocElement[%
329 idxtype=tex toks,
330 idxgroup=tex toks,
331 printtype=\textit{\TeX{} toks},
332 ]{Ttoks}{textoks}
333 % ^^A latex project
334 \NewDocElement[%
335 idxtype=pkg.,
336 idxgroup=,
337 printtype=\textit{pkg.},
338 ]{Pkg}{package}
339 \NewDocElement[%
340 idxtype=socket,
341 idxgroup=sockets,
342 printtype=\textit{socket},
343 ]{Sock}{socket}
344 \NewDocElement[%
345 idxtype=plug,
346 idxgroup=plugs,
347 printtype=\textit{plug},
348 ]{Plug}{splug}
349 % ^^A doc DocElement additions >>>
350 \newcommand*\is{\texttt{=\,}}
351 \NewDocumentCommand \val { m }
352 {%
353 {\ttfamily =\,}\meta{#1}%
354 }
355 \ExplSyntaxOn
356 \NewDocumentCommand \vals { m }
357 {
358 {
359 \ttfamily = \,
360 \clist_use:nn { #1 } { \textbar }
361 }
362 }
363 \keys_define:nn { forest-ext / doc }
364 {
365 unknown .code:n = {
366 \cs_if_free:cT { \l_keys_key_str }
367 {
368 \tl_gset:cn { \l_keys_key_str } { #1 }
369 }
370 },
371 }
372 \NewDocumentCommand \forestextdocset { +m }
373 {
374 \keys_set:nn { forest-ext / doc } { #1 }
375 }
376 \cs_new_eq:NN \__forestextdoc_cs_orig:n \cs
377 \cs_new_protected:Npn \__forestextdoc_cs_expl:n #1
378 {
379 \exp_args:Ne \__forestextdoc_cs_orig:n {\tl_to_str:n {#1}}
380 }
381 \cs_new_eq:NN \ecs \__forestextdoc_cs_expl:n
382 \ExplSyntaxOff
383 \forestextdocset{%
384 bug={\href{https://codeberg.org/cfr/prooftrees/issues}{\textsc{bugtracker}}},
385 codeberg={\href{https://codeberg.org/cfr/prooftrees}{\textsc{codeberg}}},
386 github={\href{https://github.com/cfr42/prooftrees}{\textsc{github}}},
387 ctan={\href{https://ctan.org/}{\textsc{ctan}}},
388 }
389 % \usepackage{cleveref}
390 \newcommand*{\pgf}{\textsc{pgf}}
391 \newcommand*{\pdfTeX}{\textsc{pdf}\TeX}
392 \newcommand*\TikZ{Ti\emph{k}Z}
393 \newcommand*\pgftikz{\pgf/\TikZ}
394 \newcommand*\texse{\textsc{\TeX{} se}}
395 \newcommand*{\lpack}[1]{\textsf{#1}}
396 \newcommand*{\fgroup}[1]{\textsf{#1}}
397 \newcommand*{\fname}[1]{\textsf{#1}}
398 \newcommand*{\file}[1]{\texttt{#1}}
399 \newcommand*{\env}[1]{\texttt{#1}}
400 \NewDocumentCommand\texseans{O{Based on \texse{} answer:} m o}{%
401 #1 \href{https://tex.stackexchange.com/a/#2}{#2}%
402 \IfValueT{#3}{ by #3}.%
403 }
404 \NewDocumentCommand\texseqn{O{Based on \texse{} question} m o}{%
405 #1 \href{https://tex.stackexchange.com/q/#2}{#2}%
406 \IfValueT{#3}{ by #3}.%
407 }
408 \NewDocumentEnvironment{drop}{+c}{}{}
409 \title{\pkg{\filebase}: A Collection of \pkg{forest} Libraries}
410 \author{Clea F. Rees\thanks{%
411 Bug tracker:
412 \href{https://codeberg.org/cfr/prooftrees/issues}{\url{codeberg.org/cfr/prooftrees/issues}}
413 \textbar{} Code:
414 \href{https://codeberg.org/cfr/prooftrees}{\url{codeberg.org/cfr/prooftrees}}
415 \textbar{} Mirror:
416 \href{https://github.com/cfr42/prooftrees}{\url{github.com/cfr42/prooftrees}}%
417 }}
418 \date{\forestextdocdate}
419 \pagestyle{fancy}
420 \fancyhf{}
421 \fancyhf[lh]{\itshape\forestextdocbase}
422 \fancyhf[rh]{\itshape\thepage~/~\lastpage{}}
423 \ExplSyntaxOn
424 \hook_gput_code:nnn {shipout/lastpage} {.}
425 {
426 \property_record:nn {t:lastpage}{abspage,page,pagenum}
427 }
428 \cs_new_protected_nopar:Npn \lastpage
429 {
430 \property_ref:nn {t:lastpage}{page}
431 }
432 \cs_new_eq:NN \OrigMakePrivateLetters \MakePrivateLetters
433 \ExplSyntaxOff
434 % ^^A >>> preamble
435 \begin{document}
436 \DocInput{\forestextdocname}
437 \end{document}
438 %</driver>
439 % \fi
440 %^^A %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
441 % \maketitle
442 % \thispagestyle{empty}
443 % \bigskip
444 %
445 % \pdfinfo{% ^^A pam mae hyn yma?
446 % /Creator (TeX)
447 % /Producer (pdfTeX)
448 % /Author (Clea F. Rees)
449 % /Title (forest-ext)
450 % /Subject (TeX)
451 % /Keywords (TeX,LaTeX,Clea,Rees)}
452 % \setlength{\parindent}{0pt}
453 % \setlength{\parskip}{0.5em}
454 %
455 % ^^A lua will replace v0.0 and 0000/00/00 when tagging in the non-tagging sense
456 % \changes{v0.1}{2026-01-16}{First public release.}
457 %
458 % \begin{abstract}
459 % \noindent\lpack{forest-ext} consists of various libraries for Sašo Živanović's package \pkg{forest} \autocite*{saso-forest}.
460 % The aim of the libraries is to provide bug fixes or extensions currently unavailable in \pkg{forest} itself.
461 % I hope that this package --- or at least many of its constituents --- will eventually be rendered unnecessary by an updated \pkg{forest} and disappear.
462 % \end{abstract}
463 %
464 % \tableofcontents
465 %
466 % \twmarg
467 % \section{Basic usage}\label{sec:usage}% ^^A <<< usage
468 %
469 % This package currently provides the following libraries:
470 %
471 % \DescribeLib{ext.ling} Experimental elementary support for trees involving multi-dominance, based on \pkg{ext.multi}.
472 % See \cref{sec:ling}.
473 %
474 % \DescribeLib{ext.multi} Experimental elementary support for nodes with multiple parents.
475 % See \cref{sec:multi}.
476 %
477 % \DescribeLib{ext.tagging} Experimental automatic tagging of \lpack{forest} trees.
478 % See \cref{sec:tag}.
479 %
480 % Although this relies only on documented public interfaces provided by \pkg{forest} --- no \pkg{forest} internals are patched or redefined --- the library does change the same \pgf{} internals as the tagging support in \pkg{latex-lab-tikz-testphase} \autocite{latex-project-latex-lab-tikz}.
481 %
482 % \DescribeLib{ext.utils} Bits 'n bobs.
483 % See \cref{sec:utils}.
484 %
485 % For debugging, the following alternative libraries are provided:
486 %
487 % \DescribeLib{ext.ling-debug} \pkg{ext.ling} plus debugging.
488 % See \cref{sec:ling}.
489 %
490 % \DescribeLib{ext.multi-debug} \pkg{ext.multi} plus debugging.
491 % See \cref{sec:multi}.
492 %
493 % \DescribeLib{ext.tagging-debug} \pkg{ext.tagging} plus debugging.
494 % See \cref{sec:tag}.
495 %
496 % \DescribeLib{ext.utils-debug} \pkg{ext.utils} plus debugging.
497 % See \cref{sec:utils}.
498 %
499 % Load the libraries in the same way as standard libraries:
500 % \iffalse
501 %<*verb>
502 % \fi
503 % \begin{minted}{latex}
504 \usepackage[<comma-separated-list of libraries>]{forest}
505 % \end{minted}
506 % \iffalse
507 %</verb>
508 % \fi
509 % or
510 % \iffalse
511 %<*verb>
512 % \fi
513 % \begin{minted}{latex}
514 \usepackage{forest}
515 \useforestlibrary{<comma-separated-list of libraries>}
516 % \end{minted}
517 % \iffalse
518 %</verb>
519 % \fi
520 %
521 % For example, the following line would load \pkg{forest-lib-ext.multi} and apply any defaults globally.
522 % \iffalse
523 %<*verb>
524 % \fi
525 \begin{latexcode}
526 \usepackage[ext.multi]{forest}
527 \end{latexcode}
528 % \iffalse
529 %</verb>
530 % \fi
531 % The following lines would load the same library, but without applying any defaults.
532 % \iffalse
533 %<*verb>
534 % \fi
535 \begin{latexcode}
536 \usepackage{forest}
537 \useforestlibrary{ext.multi}
538 \end{latexcode}
539 % \iffalse
540 %</verb>
541 % \fi
542 % Any default settings can then be applied locally using \cs{forestapplylibrarydefaults}\marg{list of libraries}, if desired.
543 % ^^A >>> usage
544 %
545 % \section[Tagging]{Tagging\footnote{%
546 % For an introduction to support for tagged PDF in \LaTeXe{}, see \textcite{ulrike-tagpdf}.
547 % For gorier details see, for example, \textcite{pdf-assoc-pdf2,pdf-assoc-wtpdf2,pdf-assoc-pdfua2} and related publications.}}\label{sec:tag}% ^^A <<< forestextdoc-tagging{-debug}
548 %
549 % Note that this library requires \pkg{ext.utils}, described in \cref{sec:utils}.
550 %
551 % ^^A <<< syntax
552 %
553 % \DescribeLib{ext.tagging} Experimental semi-automatic tagging of \lpack{forest} trees.
554 %
555 % \DescribeLib{ext.tagging-debug} \pkg{ext.tagging} plus debugging.
556 %
557 % \pkg{forest-lib-ext.tagging} (and \pkg{forest-lib-ext.tagging-debug}) are based on the ‘first-aid’ in \pkg{latex-lab-tikz-testphase} by Ulrike Fischer \autocite{latex-project-latex-lab-tikz}.
558 % Those patches do not work with \pkg{forest} because a \env{forest} tree includes many \env{tikzpicture} environments, some of which may never be typeset and all of which are used only indirectly \emph{via} low-level \TeX{} boxes.
559 % Moreover, the \pkg{latex-lab} code depends on \pgf's ‘remember picture’ feature, which is not compatible with \pkg{forest} with or without tagging.
560 %
561 % In addition to making it possible to tag \env{forest} environments in tagged documents, the library produces an alternative text describing the tree semi-automatically.
562 % This is important because trees are unlike some other images, where relatively short summaries provide a reasonable alternative to the picture.
563 % To provide high quality access to the information contained in a typical tree, it is necessary to describe it in detail.
564 % Both the content of the nodes and their structural relationships must be described, together with any labels and annotations.
565 %
566 % The current implementation does not do all of the work: it does not include information from regular labels or the content of annotations added using regular \TikZ{} or \pgf{} techniques.
567 % However, it does describe the main tree's structure, together with the content of its nodes and edge labels, though you may need to override the generated content for content which includes special characters, in a quite broad sense of ‘special’.
568 %
569 % The support for tagging adds the following \pkg{forest} \emph{stages} which are executed in order, sandwiched between \texttt{compute xy stage} and \texttt{before drawing tree}.
570 %
571 % \textbf{If you redefine (or load code which redefines) the default implementation of \texttt{stages}, you must include or replace the additions from this library.}
572 % For an example of how to do this, see \pkg{prooftrees} \autocite{cfr-prooftrees}, which includes, redefines, supplements or replaces these additions.
573 %
574 % \DescribeKeylist{before tagging nodes} Empty by default.
575 % Analogous to \texttt{before typesetting nodes}, \texttt{before packing} etc.
576 %
577 % \DescribeTagKeylist{tag nodes} Executes code to assign tagging code to each node in the tree.
578 %
579 % Note this is a \emph{\textbf{tagging}} keylist.
580 % See \cref{subsec:utils-tag-props}.
581 %
582 % \DescribeKeylist{before collating tags} Empty by default.
583 % Analogous to \texttt{before typesetting nodes}, \texttt{before packing} etc.
584 %
585 % \DescribeTagKeylist{collate tags} Walks the tree to collate the tags into a single alternative text for the tree.
586 %
587 % Note this is a \emph{\textbf{tagging}} keylist.
588 % See \cref{subsec:utils-tag-props}.
589 %
590 % \DescribeKeylist{before tagging tree} Empty by default.
591 % Analogous to \texttt{before typesetting nodes}, \texttt{before packing} etc.
592 %
593 % \DescribeStage{tag tree stage} Calculates an approximate bounding box for the tree and inserts the collated tagging data into the document's tagging structure using \pkg{tagpdf}.
594 %
595 %
596 % The code inserts a tagged structure analogous to (and heavily derived from) the \texttt{alt} plug provided by \pkg{latex-lab-tikz-testphase}.
597 % However, unlike the \pkg{latex-lab} plug, the library generates the \texttt{alt} text automatically by default.
598 % The result can be configured using a small number of keys.
599 % The keys' scope is the entire tree, except that the scope of \texttt{alt text} is \emph{the current node}.
600 %
601 % \DescribeAwtoks{alt text}\val{tokens}
602 %
603 % Override the automatic generation of alternative text for the current node.
604 %
605 % Internally, the code uses the further key \texttt{node@ttoks}.
606 % In essence, if \texttt{alt text} is empty, \texttt{node@ttoks} is constructed from the node's \texttt{content}, \texttt{edge label} and any applicable structural descriptors, as specified by \texttt{is root}, \texttt{is branch} and so on.
607 % If \texttt{alt text} is not empty, it is used as-is.
608 % The reason for this indirect assignment --- first constructing \texttt{node@ttoks} and only then assigning it to \texttt{alt text} --- is that the value of \texttt{node@ttoks} is constructed incrementally (i.e.~partially by \texttt{delayed} keys) and keeping \texttt{alt text} as-is makes it easy to test during every cycle.
609 %
610 % \texttt{node@ttoks} is intended for purely internal use and should \textbf{NOT} be used outside the library code.
611 % \texttt{alt text} is the public face of this key.
612 %
613 % Note that tagging content is always attached to nodes\footnote{%
614 % I'm not altogether happy with this implementation, so this may change, but I want to keep things relatively simple for now.%
615 % }.
616 % Labels, edge labels and structures are not (currently?) tagged independently.
617 % So, if you specify \texttt{alt text}, you replace not only the \texttt{content} of the node in the corresponding tag, but the content of any \texttt{edge label} and any relevant structural information.
618 % So if you want, say, a branch number prepended or an indication that the node is a `\texttt{child}` or `\texttt{leaf}`, say, or that the tree forks from this node, you must include that information into the \meta{tokens} when specifying \texttt{alt text}.
619 %
620 % \changes{v0.2}{2026-01-21}{Make default structure description slightly less verbose.}
621 % \DescribeAwtoksr{is root}\val{tokens}
622 %
623 % Specify text to insert when describing the root.
624 % Default is empty.
625 %
626 % \DescribeAwtoksr{is child}\val{tokens}
627 %
628 % Specify text to insert when describing a child.
629 % Default is \texttt{child}.
630 %
631 % \DescribeAwtoksr{is leaf}\val{tokens}
632 %
633 % Specify text to insert when describing a leaf node.
634 % Default is empty.
635 %
636 % \DescribeAwtoksr{is edge label}\val{tokens}
637 %
638 % Specify text to insert when describing an edge label.
639 % Default is \texttt{edge label}.
640 %
641 % \DescribeAwtoksr{has branches}\val{tokens}
642 %
643 % Specify text to insert when describing a parent's branches.
644 % Default is \texttt{children}.
645 % A number is inserted before to indicate the number of branches.
646 %
647 % \DescribeAwtoksr{is branch}\val{tokens}
648 %
649 % Specify text to insert when describing node's (and, hence, this subtree's) position in the tree.
650 % Default is empty.
651 % A number is appended to indicate which branch.
652 %
653 % \DescribeAwtoks{alt pre}\val{tokens}
654 %
655 % \DescribeAwtoks{alt post}\val{tokens}
656 %
657 % Default is empty.
658 % These are per-node options intended to allow adding to auto-generated \texttt{alt text}.
659 % They wrap around the content of the node.
660 %
661 % \subsubsection{Customisation}\label{subsubsec:tag-aopts}% ^^A <<<
662 %
663 % Most users will not need the options explained in this section.
664 %
665 % \DescribeBoolr{tagging}
666 %
667 % \texttt{tagging} may be used to make code conditional on the activation status of tagging.
668 % For this reason, it has a public name.
669 % However, it should \textbf{NOT} be changed.
670 %
671 % More generally, you should not suspend, resume, enable or disable tagging inside a \env{forest} environment unless you understand what you are doing with respect to \emph{both} the tagging code \emph{and} \pkg{forest}\footnote{Possibly nobody currently meets both of these requirements.}.
672 %
673 % \DescribeChoice{tag nodes uses}\vals{none,alt text}
674 %
675 % Configures the keylist \texttt{tag nodes}.
676 % \texttt{alt text} installs the default auto-generation code which constructs a value if \texttt{alt text} is unspecified for a (non-phantom) node.
677 %
678 % The order in which nodes are tagged may be set using \texttt{tag nodes processing order}.
679 % The default is \texttt{unique=tree}.
680 %
681 % \DescribeChoice{collate tags uses}\vals{none,alt text}
682 %
683 % Configures the keylist \texttt{collate tags}.
684 % \texttt{alt text} installs code to collate the values of the autowrapped toks option \texttt{alt text}.
685 %
686 % The order of collation may be set using \texttt{collate tags processing order}.
687 % The default is \texttt{unique=tree depth first}.
688 %
689 % \DescribeChoice{tag tree uses}\vals{none,alt text}
690 %
691 % Configures the style \texttt{tag tree}.
692 % \texttt{alt text} installs the default keys used to calculate approximate dimensions for the bounding box and to pass the collated tags to the \emph{plug} responsible for tagging the tree.
693 %
694 % This style is used by the default implementation of \texttt{tag tree stage}:
695 % \iffalse
696 %<*verb>
697 % \fi
698 \begin{latexcode}
699 tag tree stage/.style={for root'=tag tree},
700 \end{latexcode}
701 % \iffalse
702 %</verb>
703 % \fi
704 % ^^A >>> subsubsec:tag-aopts
705 %
706 % \subsubsection{Custom plugs}\label{subsubsec:tag-cp}% ^^A <<<
707 %
708 % By default, everything is \texttt{noop}.
709 % If the user does nothing and tagging is active, the \texttt{alt} plug is used.
710 % If this is not desired, it is sufficient to use \forestset{plug=noop}, which will make everything (remain) \texttt{noop} or \forestset{custom tagging}, which will allow the \pkg{latex-lab} patches to mix explosively with your \pkg{forest} trees.
711 % This is not recommended unless you plan to prevent such encounters yourself.
712 % In the worst cases, the combination will result in fatal compilation errors.
713 % In the best cases, the document will compile, but tagging will almost certainly be broken.
714 %
715 % However, it is possible to strike a middle course and use the infrastructure provided by this library as the basis for custom tagging.
716 % Some approaches were explained in \cref{subsubsec:tag-aopts}.
717 % If those are not sufficient, you may define custom plugs.
718 % This section explains the minimal requirements for such plugs to be used by this library i.e.~without using \texttt{custom tagging}.
719 %
720 % \paragraph{Requirements}
721 % \newcommand\percy{\texttt{Percy}}
722 % Let \percy{} be the name of your custom plug.
723 % Then \pkg{ext.tagging} requires:
724 % \begin{enumerate}
725 % \item a plug named \percy{} for socket \texttt{tagsupport/forest/setup};
726 % \item a plug named \percy{} for socket \texttt{tagsupport/forest/tag}.
727 % \end{enumerate}
728 % If both conditions are satisfied, writing
729 % \iffalse
730 %<*verb>
731 % \fi
732 \begin{latexcode}
733 \forestset{%
734 plug=Percy,
735 }
736 \end{latexcode}
737 % \iffalse
738 %</verb>
739 % \fi
740 % will not result in an immediate error.
741 %
742 % In order to do something useful, of course, \percy{} must do rather more than this, so let's see what \texttt{alt} is used.
743 % \texttt{tagsupport/forest/setup} is used right at the start of the tree.
744 % This happens before any parenthetical argument is processed, before any star is used, before the default preamble and well before any tree-specific preamble\footnote{%
745 % It uses a generic hook to inject code before an internal macro.
746 % This ensures it works for both the environment and command forms without adding an additional \TeX{} group, but is clearly not ideal.%
747 % }.
748 % In particular, the default values of \emph{tagging keylists} may still be manipulated at this point, since the socket is used before they are transformed into regular keylist options.
749 % The \texttt{alt} plug exploits this using the following code:
750 % \iffalse
751 %<*verb>
752 % \fi
753 \begin{latexcode}
754 \socket_new_plug:nnn {tagsupport/forest/setup}{alt}
755 {
756 \forestset{
757 plug=alt,
758 tag nodes uses=alt text,
759 collate tags uses=alt text,
760 tag tree uses=alt,
761 }
762 }
763 \end{latexcode}
764 % \iffalse
765 %</verb>
766 % \fi
767 % Note that it is good practice to set \texttt{plug} here, even if the code is already plug-specific, since the value is used later when calling the \texttt{tagsupport/forest/tag} socket.
768 % The content of the \texttt{alt} \texttt{tagsupport/forest/tag} plug is very similar to the \pkg{latex-lab} patch for \tikz{}.
769 %
770 % So let's assume that \percy{} should use the same code as the \texttt{alt} plug for the \texttt{tagsupport/forest/tag} socket, but something different for \texttt{tagsupport/forest/setup}.
771 %
772 % As noted above, \texttt{tag nodes uses}, \texttt{collate tags uses} and \texttt{tag tree uses} are choice keys.
773 % Given the way \pkg{pgfkeys} implements such keys, \percy{} might do something like this:
774 % \iffalse
775 %<*verb>
776 % \fi
777 \begin{latexcode}
778 \NewSocketPlug {tagsupport/forest/setup}{percy}
779 {%
780 \forestset{%
781 plug=percy,
782 tag nodes uses=percy,
783 collate tags uses=percy,
784 tag tree uses=alt,
785 }%
786 }
787 \forestset{%
788 declare autowrapped toks={percy text}{},
789 tag nodes uses/percy/.style={%
790 redeclare tagging keylist={tag nodes}{%
791 if percy text={}{%
792 percy text/.option=content,
793 +percy text={Percy: },
794 }{%
795 percy text+={: },
796 percy text+/.option=content,
797 },
798 },
799 },
800 collate tags uses/percy/.style={%
801 redeclare tagging keylist={collate tags}{%
802 collate tag/.option=percy text,
803 },
804 },
805 }
806 \NewSocketPlug {tagsupport/forest/tag}{percy}
807 {%
808 \AssignSocketPlug {tagsupport/forest/tag}{alt}%
809 \UseSocket {tagsupport/forest/tag}%
810 }
811 \end{latexcode}
812 % \iffalse
813 %</verb>
814 % \fi
815 % This would result in each node in the tree contributing both its content and a prefix specified by option \texttt{percy text} to the alternative text provided in the tagging structure of the \textsc{pdf}.
816 % No structural information is added here i.e.~there are no descriptions of branching or of the relationships between nodes\footnote{%
817 % For a more realistic implementation, see \cref{sec:imp} for the code used for the \texttt{alt} plug.
818 % For a more elaborate example of customisation, see \textcite{cfr-prooftrees}.%
819 % }.
820 %
821 % ^^A >>> subsubsec:tag-cp
822 %
823 % \subsubsection{Complete control}\label{subsubsec:tag-cc}% ^^A <<<
824 %
825 % \DescribeCode{custom tagging}\vals{true,false}
826 %
827 % \DescribeCode{not custom tagging}
828 %
829 % If true, do not tag following trees in the current \TeX{} group.
830 %
831 % \textbf{This key must be used BEFORE \cs{begin}\texttt{\{forest\}} or \cs{Forest}.}
832 %
833 % If you do not want to use the library's tagging code, you can easily avoid it by simply not using it.
834 % However, you might want to use it for only some trees or you might wish to use the pre-defined stages as a basis for a custom configuration.
835 % In such cases, \texttt{custom tagging} may be used to tell the library that it should not tag trees in the local \TeX{} group even if tagging is active.
836 % In this case, the user (or another package) is entirely responsible for tagging.
837 % The custom tagging code may nonetheless test \texttt{tagging} and use the additional stages, if desired.
838 % For example, it could redefine the stages which generate and concatenate the tags or it could install alternative plugs into appropriate sockets.
839 %
840 % Note that \pkg{latex-lab}'s code is still active in this scenario, so you are responsible for dealing with the patches it applies for \texttt{tikzpicture} environments.
841 % Note also that \texttt{custom tagging} is \emph{not} a boolean register or option --- it is simply designed to emulate one.
842 % It in fact uses the \texttt{.code} handler to set an \pkg{expl3} boolean variable.
843 %
844 % The default \texttt{alt} plug is implemented in modular fashion, so it is possible, with care, to take a pick-'n-mix approach.
845 %
846 % ^^A >>> end subsubsec:tag-cc
847 % ^^A >>> end syntax
848 %
849 % \subsection{Workflow}\label{subsec:tagging-wf}% ^^A <<<
850 %
851 % \pkg{ext.tagging} redefines \pkg{forest}'s \texttt{stages}.
852 % If you just wish to use the library to tag ordinary trees, you can ignore the details of this definition.
853 % However, should you wish to use the library with a custom definition of \texttt{stages}, the details below should enable you to do so.
854 % As with \texttt{forest}'s own definitions, the various steps may be redefined, replaced, removed or extended as required.
855 % The library also follows the \pkg{forest} package's convention in providing \texttt{before} keylists reserved for user use i.e.~all such keylists are empty by default.
856 %
857 % Tagging is initialised and finalised by code added to the hooks \texttt{env/forest/begin} and \texttt{env/forest/end}.
858 % \iffalse
859 %<*verb>
860 % \fi
861 \begin{latexcode}
862 stages/.style={
863 for root'={
864 process keylist register=default preamble,
865 process keylist register=preamble
866 },
867 process keylist=given options,
868 process keylist=before typesetting nodes,
869 typeset nodes stage,
870 process keylist=before packing,
871 pack stage,
872 process keylist=before computing xy,
873 compute xy stage,
874 process keylist=before tagging nodes,
875 process keylist=tag nodes,
876 process keylist=before collating tags,
877 process keylist=collate tags,
878 process keylist=before tagging tree,
879 tag tree stage,
880 process keylist=before drawing tree,
881 draw tree stage
882 },
883 \end{latexcode}
884 % \iffalse
885 %</verb>
886 % \fi
887 % This describes the default implementation with \texttt{setup plug=alt} and \texttt{tag plug=alt}\footnote{%
888 % Strictly speaking, the non-trivial claims in \crefrange{enum:btn}{enum:tts} are almost entirely false as stated.
889 % For example, \texttt{tag nodes} could construct an entirely new branch and put all the tagging information there, \texttt{collate tags} could then collect that information and write it to an external file and \texttt{tag tree stage} could embed or attach that file.
890 % But that is not very useful to know.
891 % The proof of this is simple: if such radical divergence features in your tagging plans, you do not need this package, while, if you do, it shouldn't.
892 % $\textsc{qed}$.
893 % It follows that you should skip this footnote.%
894 % }.
895 % \begin{enumerate}
896 % \item \textcolor{gray}{\texttt{default preamble} \autocite[see][]{saso-forest}}
897 % \item \textcolor{gray}{\texttt{preamble} \autocite[see][]{saso-forest}}
898 % \item \textcolor{gray}{\texttt{given options} \autocite[see][]{saso-forest}}
899 % \item \textcolor{gray}{\texttt{before typesetting nodes} \autocite[see][]{saso-forest}}
900 % \item \textcolor{gray}{\texttt{typeset nodes stage} \autocite[see][]{saso-forest}}
901 % \item \textcolor{gray}{\texttt{before packing} \autocite[see][]{saso-forest}}
902 % \item \textcolor{gray}{\texttt{pack stage} \autocite[see][]{saso-forest}}
903 % \item \textcolor{gray}{\texttt{before computing xy} \autocite[see][]{saso-forest}}
904 % \item \textcolor{gray}{\texttt{compute xy stage} \autocite[see][]{saso-forest}}
905 % \item\label{enum:btn} \texttt{before tagging nodes}
906 % Empty by default.
907 % Use in the same way as \pkg{forest}'s \texttt{before} keylists.
908 % \item \texttt{tag nodes}
909 % A \emph{tagging keylist} which should, when processed, ensure that each node which requires tagging is correctly tagged in whichever way the installed \texttt{tag plug} and associated code requires e.g.~for the default \texttt{alt} configuration, \texttt{alt text}.
910 % \item \texttt{before collating tags}
911 % Empty by default.
912 % Use in the same way as \pkg{forest}'s \texttt{before} keylists.
913 % \item \texttt{collate tags}
914 % A \emph{tagging keylist} which should, when processed, result in the collation of all tags for the tree in the form expected by \texttt{tag tree stage}.
915 % \item \texttt{before tagging tree}
916 % Empty by default.
917 % Use in the same way as \pkg{forest}'s \texttt{before} keylists.
918 % \item\label{enum:tts} \texttt{tag tree stage}
919 % Executes code to actually tag the tree using the data finalised in \texttt{collate tags} (possibly modified by \texttt{before tagging tree}).
920 % \item \textcolor{gray}{\texttt{before drawing tree} \autocite[see][]{saso-forest}}
921 % \item \textcolor{gray}{\texttt{draw tree stage} \autocite[see][]{saso-forest}}
922 % \end{enumerate}
923 % ^^A >>> subsec:tagging-wf
924 %
925 % \twreg
926 % \let\MakePrivateLetters\MyMakePrivateLetters
927 % \subsection{Example}\label{subsec:tagging-eg}% ^^A <<<
928 %
929 % Here is a complete example\footnote{%
930 % Note that the recommended syntax for invoking and using tagging support in \LaTeXe{} changes very frequently.
931 % In particular, the recommended options for \cs{DocumentMetadata} and \cs{tagpdfsetup}, including whether to use the latter at all, are not at all stable.
932 % You should therefore check and use the recommended options at the time your document is written --- there is nothing in the code before \cs{documentclass} which is in any way particular to using the libraries provided by this package.
933 % That is, deviations from documented best practice in the use of \cs{DocumentMetadata} and \cs{tagpdfsetup} are either due to mistakes on my part or the result of updates following the publication of this document.
934 % In either case, you should avoid replicating the deviations in your own code.
935 % }:
936 % \iffalse
937 %<*verb>
938 % \fi
939 \begin{latexcode}
940 \DocumentMetadata{
941 tagging=on,
942 lang=en-GB,
943 pdfversion=2.0,
944 pdfstandard=ua-2,
945 }
946 \tagpdfsetup{
947 math/mathml/structelem,
948 }
949 \documentclass{article}
950 \usepackage[ext.tagging]{forest}
951 \ifcsname directlua\endcsname
952 \usepackage{unicode-math}
953 \else
954 \usepackage[T1]{fontenc}
955 \fi
956 \title{This Test Needs No Title}
957 \begin{document}
958 ABC apple banana pear
959 \begin{forest}
960 % This example is from Jasper Habicht.
961 [VP
962 [DP[John]]
963 [V’, alt text=V prime,
964 [V[sent]]
965 [DP[Mary]]
966 [DP[D[a]][NP[letter]]]
967 ]
968 ]
969 \end{forest}
970 ABC apple banana pear
971 }
972 \end{document}
973 \end{latexcode}
974 % \iffalse
975 %</verb>
976 % \fi
977 % Note the use of \texttt{alt text} to avoid problems due to the use of \verb|'| with \pdfTeX.
978 % If the (\LaTeX{} Project recommended) engine Lua\LaTeX{} is used, you need not be quite so careful, but you should always check the content of the \texttt{alt} text for unpleasant surprises.
979 %
980 % If compiled with pdf\LaTeX, the above example yields the following structure:
981 % \iffalse
982 %<*verb>
983 % \fi
984 % \permissivelines
985 \begin{xmlcode}
986 <PDF>
987 <StructTreeRoot>
988 <Document xmlns="http://iso.org/pdf2/ssn"
989 id="ID.02"
990 >
991 <text-unit xmlns="https://www.latex-project.org/ns/dflt"
992 id="ID.05"
993 rolemaps-to="Part"
994 >
995 <text xmlns="https://www.latex-project.org/ns/dflt"
996 id="ID.06"
997 xmlns:Layout="http://iso.org/pdf/ssn/Layout"
998 Layout:TextAlign="Justify"
999 rolemaps-to="P"
1000 >
1001 <?MarkedContent page="1" ?>ABC apple banana pear
1002 <Figure xmlns="http://iso.org/pdf2/ssn"
1003 id="ID.07"
1004 alt="root VP 2 branches branch 1 DP child John end branch V prime V child sent end branch DP child Mary end branch DP 2 branches branch 1 D child a end branch branch 2 NP child letter end branch "
1005 xmlns:Layout="http://iso.org/pdf/ssn/Layout"
1006 Layout:BBox="{ 259.4641, 542.90266, 407.35223, 667.19801 }"
1007 >
1008 <?MarkedContent page="1" ?>
1009 <?MarkedContent page="1" ?>
1010 <?MarkedContent page="1" ?>
1011 <?MarkedContent page="1" ?>
1012 <?MarkedContent page="1" ?>
1013 <?MarkedContent page="1" ?>
1014 <?MarkedContent page="1" ?>
1015 <?MarkedContent page="1" ?>
1016 <?MarkedContent page="1" ?>
1017 <?MarkedContent page="1" ?>
1018 <?MarkedContent page="1" ?>
1019 <?MarkedContent page="1" ?>
1020 <?MarkedContent page="1" ?>
1021 <?MarkedContent page="1" ?>
1022 </Figure>
1023 <?MarkedContent page="1" ?> ABC apple ba­nana pear
1024 </text>
1025 </text-unit>
1026 </Document>
1027 </StructTreeRoot>
1028 </PDF>
1029 \end{xmlcode}
1030 % \strictlines
1031 % \iffalse
1032 %</verb>
1033 % \fi
1034 % A similar result is obtained with Lua\LaTeX, but the output is a bit longer as it includes many empty \texttt{MarkedContent}s.
1035 % ^^A >>> subsec:example
1036 % \let\MakePrivateLetters\OrigMakePrivateLetters
1037 % ^^A >>> forestextdoc-tagging{-debug}
1038 %
1039 % \twmarg
1040 % \section{Multiple parents}\label{sec:multi}% ^^A <<<
1041 %
1042 % This library provides some basic facilities for formatting trees which are not technically trees in \pkg{forest}'s sense.
1043 % In the (one) strict sense of ‘tree’, every node but one has exactly one parent, while the one has none.
1044 %
1045 % However, in a different/looser sense of ‘tree’, every node but one has at least one parent, while the one has none.
1046 % This library makes it a bit easier to draw such trees with \pkg{forest}.
1047 %
1048 % The library began in response to a query from Alan Munn on \texse{} and initially focused entirely on \emph{multi-dominance} structures in linguistics.
1049 % Support for those structures is available in the \pkg{ext.ling} library, which now uses the more general \pkg{ext.multi}.
1050 %
1051 % The styles in \cref{subsec:multi-new} support drawing connections from a child to additional parents not currently in the tree, while those in \cref{subsec:multi-conn} support adding connections to additional extant parents.
1052 %
1053 % Note that
1054 % \begin{itemize}
1055 % \item styles are always specified for the child node;
1056 % \item the child must have exactly one ‘natural’ parent i.e.~it must be part of the existing tree structure when the style is used.
1057 % \end{itemize}
1058 %
1059 % Load \texttt{ext.multi} or \texttt{ext.multi-debug} as described in \cref{sec:usage}.
1060 %
1061 % {%
1062 % \forestapplylibrarydefaults{ext.multi-debug}%
1063 %
1064 % \subsection{Creating multiple parents}\label{subsec:multi-new}
1065 %
1066 % Note:
1067 % \begin{itemize}
1068 % \item the child should be created as the \emph{child} of its ultimate grandparent;
1069 % \item the child's parents will all be children of the child's grandparent.
1070 % \end{itemize}
1071 %
1072 % For example, consider the tree,
1073 %
1074 % \begin{forest}
1075 % [Grandparent [Child, multi={Parent 1,Parent 2,Parent 3}] ]
1076 % \end{forest}
1077 %
1078 % This structure can be conveniently created using \texttt{multi}, but to translate it into the bracket notation \pkg{forest} uses, all of Child's parents should first be omitted and Child should instead be specified as the child of Grandparent.
1079 % \iffalse
1080 %<*verb>
1081 % \fi
1082 \begin{latexcode}
1083 \begin{forest}
1084 [Grandparent [Child]]
1085 \end{forest}
1086 \end{latexcode}
1087 % \iffalse
1088 %</verb>
1089 % \fi
1090 % Parents 1, 2 and 3 should be specified as an option to Child:
1091 % \iffalse
1092 %<*verb>
1093 % \fi
1094 \begin{latexcode}
1095 \begin{forest}
1096 [Grandparent [Child, multi={Parent 1,Parent 2,Parent 3}]]
1097 \end{forest}
1098 \end{latexcode}
1099 % \iffalse
1100 %</verb>
1101 % \fi
1102 %
1103 % {%
1104 % \forestset{%
1105 % default preamble+={%
1106 % for tree={font=\sffamily\lstyle,},
1107 % },
1108 % }%
1109 %
1110 % \DescribeStyle{multi}\is\marg{content of parent 1, \dots, content of parent $n$} where $n \in \mathbb{N}, n > 1$
1111 %
1112 % For every $i \in \mathbb{N}$ such that $0<i\leq n$, create a new child of the current node's parent with content \meta{content of parent $i$}.
1113 % Then detach the current node from its parent and attach it as the child of its $n$ parents.
1114 % \iffalse
1115 %<*verb>
1116 % \fi
1117 \begin{codcoeden}+{}
1118 \begin{forest}
1119 [A
1120 [D,
1121 multi={B,D}
1122 ]
1123 ]
1124 \end{forest}
1125 \end{codcoeden}
1126 % \iffalse
1127 %</verb>
1128 % \fi
1129 %
1130 % If \texttt{parent anchor} and/or \texttt{child anchor} are set, edges are drawn to/from these points as one would expect.
1131 % \iffalse
1132 %<*verb>
1133 % \fi
1134 \begin{codcoeden}+{}
1135 \begin{forest}
1136 [A
1137 [D, multi={B,C}, ]
1138 [E, parent anchor=children,
1139 [J, multi={F,G,H,I}, ]
1140 ]
1141 [K
1142 [N, multi={L,M}, child anchor=parent, ]
1143 ]
1144 ]
1145 \end{forest}
1146 \end{codcoeden}
1147 % \iffalse
1148 %</verb>
1149 % \fi
1150 % If the \pkg{edges} library is loaded, the \pkg{multi} library loads the \TikZ{} library, \pkg{ext.paths.ortho} and tries to emulate \texttt{forked edge} appropriately\footnote{The alignment seems to me to be close, but not always quite perfect, though I do not know why at the moment.}.
1151 % \iffalse
1152 %<*verb>
1153 % \fi
1154 \begin{codcoeden}+{}
1155 \begin{forest}
1156 forked edges,
1157 [A
1158 [D, multi={B,C} ]
1159 [E
1160 [I, multi={F,G,H} ]
1161 ]
1162 [J
1163 [N, multi={K,L,M} ]
1164 ]
1165 ]
1166 \end{forest}
1167 \end{codcoeden}
1168 % \iffalse
1169 %</verb>
1170 % \fi
1171 % If we apply \texttt{forked edges} to only part of a tree, we can produce the rather ugly, but hopefully informative, structure below.
1172 % \iffalse
1173 %<*verb>
1174 % \fi
1175 \begin{codcoeden}+{}
1176 \begin{forest}
1177 for tree={%
1178 child anchor=parent,
1179 parent anchor=children,
1180 fork sep'=1em,
1181 },
1182 [O
1183 [P
1184 [S, multi={Q,R} ]
1185 ]
1186 [T, forked edges=descendants,
1187 [Z,multi={U,V,W,X,Y} ]
1188 ]
1189 ]
1190 \end{forest}
1191 \end{codcoeden}
1192 % \iffalse
1193 %</verb>
1194 % \fi
1195 % Note that the change to \texttt{fork sep} for the tree in \env{forest}'s preamble affects the edges drawn from and to the nodes inserted by \texttt{multi}.
1196 % This is because the library forwards values given to \texttt{fork sep} and applications of \texttt{forked edge} so that \pkg{forest} keys work in (hopefully) reasonably intuitive ways.
1197 %
1198 % Should you \emph{not} want such keys forwarded, either load the library without defaults (see \cref{sec:usage}) or override the behaviour for the current \TeX{} group with, say,
1199 % \iffalse
1200 %<*verb>
1201 % \fi
1202 \begin{latexcode}
1203 \forestset{%
1204 unautoforward=fork sep,
1205 null/.style={},
1206 forked edge'/.forward to=/forest/null,
1207 }
1208 \end{latexcode}
1209 % \iffalse
1210 %</verb>
1211 % \fi
1212 % The \texttt{phantom style} is needed because, unlike \pkg{forest}'s provision for its own forwarding facilities, \pkg{pgfkeys} provides no easy way to undo the effects of the \texttt{.forward to} handler.
1213 % }
1214 %
1215 % Since the library is currently experimental and implementation is complicated if one wants to avoid avoid using \pkg{forest} internals, configuration options are currently limited.
1216 %
1217 % \DescribeKeylist{every parent}\is\marg{key-value list}
1218 %
1219 % Apply \meta{key-value list} to all the current node's parents.
1220 % If \texttt{multi} is used, these are the parents created as a result; otherwise, it is the current node's singular parent or none, if the node has no parent.
1221 %
1222 % Initial value: empty.
1223 %
1224 % \Cref{box:multi-ep} illustrates usage with a simple example.
1225 %
1226 % \iffalse
1227 %<*verb>
1228 % \fi
1229 \begin{codcoeden}*[label=box:multi-ep]{}
1230 \begin{forest}
1231 [R [Child, multi={P1,P2,P3},every parent=blue,] [Aunt [Cousin 1][Cousin 2]]]
1232 \end{forest}
1233 \end{codcoeden}
1234 % \iffalse
1235 %</verb>
1236 % \fi
1237 %
1238 % \subsection{Connecting multiple parents}\label{subsec:multi-conn}
1239 %
1240 % Sometimes one wants instead to give the current node an additional parent without removing the existing one and one does not wish to add the additional parent, but rather to specify some other extant node in the tree.
1241 %
1242 % This kind of structure cannot be so easily automated, especially if one wants to avoid edges crossing each other or nodes.
1243 % However, it is possible to provide some convenient styles to assist in manually specifying such structures.
1244 %
1245 % \DescribeStyle{also parent}\is\marg{dynamic tree operation}\marg{\meta{extant node}:\meta{keylist}}
1246 %
1247 % \is\marg{dynamic tree operation}\marg{extant node}
1248 %
1249 % \DescribeStyle{+also parent}\is\marg{\meta{extant node}:\meta{keylist}}
1250 %
1251 % \is\marg{extant node}
1252 %
1253 % \DescribeStyle{also parent+}\is\marg{\meta{extant node}:\meta{keylist}}
1254 %
1255 % \is\marg{extant node}
1256 %
1257 % Adds \meta{extant node} as an additional parent of the current node.
1258 % \meta{keylist} specifies a list of key-values for the connecting node (see below).
1259 %
1260 % The current node becomes \meta{extant node}'s \emph{fosterling}, while \meta{extant node} becomes the current node's \emph{foster parent}.
1261 %
1262 % The styles work by creating a new child of \meta{extant node}.
1263 % This node affects the structure of the tree and can be configured in the usual way, but it is not visible.
1264 % One might say it is ‘semi-phantom’: it is not quite \texttt{phantom} because, for instance, it has visible edges which serve to connect the current node with the additional parent.
1265 %
1266 % For an illustration, see the (rather odd-looking) family tree in \cref{box:fam}\footnote{The names are from the children's novels by Cynthia Voigt.}.
1267 %
1268 % \texttt{+also parent} prepends the new child to \meta{extant node}; \texttt{also parent+} appends it.
1269 % These are just shorthand wrappers around \texttt{also parent} using the \texttt{prepend} and \texttt{append} dynamic tree operations.
1270 %
1271 % Note that \meta{dynamic tree operation} should create a new node, though this is not enforced.
1272 %
1273 % \iffalse
1274 %<*verb>
1275 % \fi
1276 \begin{codcoeden}*[label=box:fam,sidebyside=false,text and listing]{}
1277 \begin{forest}
1278 forked edges,
1279 delay={%
1280 for tree={%
1281 +content=\strut,
1282 },
1283 },
1284 [,coordinate,calign primary child=1,calign secondary child=2,calign=midpoint,
1285 [Cilla
1286 [Eunice]
1287 ]
1288 [Abigail Tillerman
1289 [John,also parent={append}{j}]
1290 [Liza, also parent={append}{!r3}, for children={also parent={append}{!un}}
1291 [Dicey]
1292 [James]
1293 [Maybeth]
1294 [Sammy]
1295 ]
1296 [Francis Verricker,no edge]
1297 [Samuel, also parent+={!r3}]
1298 ]
1299 [John, name=j, no edge
1300 ]
1301 ]
1302 \end{forest}
1303 \end{codcoeden}
1304 % \iffalse
1305 %</verb>
1306 % \fi
1307 %
1308 % \DescribeStep{fosterlings} Visit the current node's \emph{fosterlings}.
1309 %
1310 % \DescribeStep{foster parents} Visit the current node's \emph{foster parents}.
1311 %
1312 % \DescribeStep{every fosterling}\is\marg{nodewalk}
1313 %
1314 % Visit every \emph{fosterling} in \meta{nodewalk}.
1315 %
1316 % \DescribeStep{every foster parent}\is\marg{nodewalk}
1317 %
1318 % Visit every \emph{foster parent} in \meta{nodewalk}.
1319 %
1320 % \DescribeStep{c fosterling} Visit the \emph{fosterling} which the current node connects to a \emph{foster parent}.
1321 %
1322 % \DescribeStep{c foster parent} Visit the \emph{foster parent} which the current node connects to a \emph{fosterling}.
1323 %
1324 % This last pair of steps are only really useful if you want to change \texttt{edge path}, since they are only accessible from a constructed, typically invisible node.
1325 %
1326 % \DescribeBoolr{debug multi phantoms}\vals{true,false}
1327 %
1328 % \DescribeBoolr{not debug multi phantoms}
1329 %
1330 % Render the normally invisible nodes created by \texttt{also parent} etc.\ visible for debugging purposes.
1331 % If the nodes have no content, their borders are drawn in red; otherwise, their contents are rendered in red.
1332 % Visible rendering does not change the remainder of the tree e.g.~it does not alter the spacing of nodes or the paths of edges.
1333 % However, if the nodes occur near the tree's boundaries, the bounding box may expand to accommodate them\footnote{%
1334 % It should not be hard to prevent this, but does not seem worth the trouble.%
1335 % }.
1336 %
1337 % \textbf{Requires \pkg{ext.multi-debug}.}
1338 % If the debugging code is not loaded, use of these keys will do nothing but write a warning to the console and log.
1339 %
1340 % For an example, see \cref{box:multi-debug}.
1341 % Note that the content of the \texttt{forest} environment is identical to that in \cref{box:fam}.
1342 % The red squares are the effect of toggling \texttt{debug multi phantoms} beforehand.
1343 % \iffalse
1344 %<*verb>
1345 % \fi
1346 \begin{codcoeden}*[label=box:multi-debug,sidebyside=false,text and listing]{}
1347 {%
1348 \forestset{debug multi phantoms}%
1349 \begin{forest}
1350 forked edges,
1351 delay={%
1352 for tree={%
1353 +content=\strut,
1354 },
1355 },
1356 [,coordinate,calign primary child=1,calign secondary child=2,calign=midpoint,
1357 [Cilla
1358 [Eunice]
1359 ]
1360 [Abigail Tillerman
1361 [John,also parent={append}{j}]
1362 [Liza, also parent={append}{!r3}, for children={also parent={append}{!un}}
1363 [Dicey]
1364 [James]
1365 [Maybeth]
1366 [Sammy]
1367 ]
1368 [Francis Verricker,no edge]
1369 [Samuel, also parent+={!r3}]
1370 ]
1371 [John, name=j, no edge
1372 ]
1373 ]
1374 \end{forest}%
1375 }
1376 \end{codcoeden}
1377 % \iffalse
1378 %</verb>
1379 % \fi
1380 % } % ^^A end apply multi library defaults
1381 % ^^A >>>
1382 %
1383 %
1384 % \section{Linguistics extensions}\label{sec:ling}% ^^A <<<
1385 %
1386 % This library provides some elementary styles for formatting trees involving \emph{multi-dominance}, together with a style for dealing with empty nodes resistant to the \pkg{linguistics} library's \texttt{nice empty nodes}.
1387 % These former were developed in response to a query from Alan Munn on \texse.
1388 %
1389 % See also \cref{sec:multi}, especially for straight connections to multiple parents and dynamic creation of multiple parents as children of a single grandparent.
1390 %
1391 % {%
1392 % \forestapplylibrarydefaults{linguistics,ext.ling-debug,ext.utils-debug}%
1393 %
1394 % \DescribeStyle{pretty nice empty nodes}\is\marg{keylist}
1395 %
1396 % Make empty nodes prettier in cases where \texttt{nice empty nodes} cannot be used.
1397 % \meta{keylist} permits supplementing or overriding what is done for empty nodes.
1398 %
1399 % Note that \texttt{nice empty nodes} is preferable, so should be used where possible.
1400 % For details, see the documentation of \texttt{nice empty nodes} in \textcite{saso-forest}.
1401 %
1402 % For example\footnote{\texseans{717677} \texseqn{717592}[argo]},
1403 % \iffalse
1404 %<*verb>
1405 % \fi
1406 \begin{codcoeden}+[label=box:pretty-nice]{}
1407 \begin{forest}
1408 for tree={
1409 calign angle=60,
1410 align middle child,
1411 },
1412 pretty nice empty nodes={
1413 for current and siblings={anchor=parent},
1414 parent anchor=children,
1415 calign with current edge,
1416 },
1417 [a
1418 [b]
1419 [
1420 [
1421 [d]
1422 [e
1423 [f]
1424 [g]
1425 [h]
1426 ]
1427 ]
1428 [c]
1429 ]
1430 ]
1431 \end{forest}
1432 \end{codcoeden}
1433 % \iffalse
1434 %</verb>
1435 % \fi
1436 %
1437 % \begin{drop}
1438 % \subsection{Multiple dominance}\label{subsec:ling-multidom}% ^^A <<<
1439 %
1440 % The \texttt{multidom} styles are \texseans[based on code posted at]{695602}, which was \texseans[based on code]{695600}[Alan Munn], which was based on my code, which was based on his question, and parameterisation of \texseans[]{249615}.%
1441 % They now depend on the more generic implementation of related styles in \pkg{ext.multi}.
1442 % The basic behaviour of these keys is therefore very similar: only the syntax permits more concise specifications in some cases.
1443 % All examples in this section are shown with equivalent code using only \pkg{ext.multi}.
1444 %
1445 % \DescribeStyle{multidom prepend}\is\marg{x shift}\marg{y shift}\marg{out i}\marg{out ii}\marg{node}
1446 %
1447 % \DescribeStyle{multidom append}\is\marg{x shift}\marg{y shift}\marg{out i}\marg{out ii}\marg{node}
1448 %
1449 % \DescribeStyle{multidom}\is\marg{dynamic tree operation}\marg{x shift}\marg{y shift}\marg{out i}\marg{out ii}\marg{node}
1450 %
1451 % Intuitively, these styles say that the current node has two parents, namely its ‘natural’ parent and \meta{node}.
1452 %
1453 % \texttt{prepend} (\texttt{append}) is intended for cases where \meta{node} is to the right (left) of the current node.
1454 %
1455 % \meta{x shift} and \meta{y shift} shift the current node (and its descendants) by the specified distances in the \texttt{x} and \texttt{y} directions respectively.
1456 %
1457 % The connections from the current node to its two parents are \texttt{to} paths which leave the current node in the directions specified by \meta{out i} (to its original parent) and \meta{out ii} (to \meta{node}).
1458 %
1459 % \Cref{box:multidom-prepend} demonstrates the intended usage.
1460 % {%
1461 % \forestset{default preamble+={for tree={align=center,},},}
1462 % \iffalse
1463 %<*verb>
1464 % \fi
1465 \begin{coeden}*[label=box:multidom-prepend]{}
1466 \begin{codsiml}[minted language=latex]
1467 \newcommand*\1{$'$}
1468 \begin{forest}
1469 [TP,name=TP
1470 [DP,multidom prepend={-.5cm}{-2cm}{north}{east}{VP}
1471 [D\\the ]
1472 [NP\\chimney ]
1473 ]
1474 [T\1
1475 [T ]
1476 [VP,name=VP
1477 [V\1
1478 [V\\smokes ]
1479 ]
1480 ]
1481 ]
1482 ]
1483 \end{forest}
1484 \end{codsiml}
1485 \begin{codsiml}[minted language=latex]
1486 \newcommand*\1{$'$}
1487 \begin{forest}
1488 curved edge/.style args={from (#1.#2) to (#3.#4)}{%
1489 edge path'={(#1.#2) to [looseness=.5, out=#2] (#3.#4)},
1490 },
1491 curve edge/.style={%
1492 curved edge=from (.#1) to (!u.parent anchor),
1493 },
1494 [TP,name=TP
1495 [DP,+also parent={VP:{%
1496 curved edge=from (!{c fosterling}.east) to (!{c foster parent}.parent anchor),
1497 }%
1498 },
1499 before drawing tree={%
1500 for tree={x'-=0.5cm,y'-=2cm,},
1501 },
1502 curve edge=north,
1503 [D\\the ]
1504 [NP\\chimney ]
1505 ]
1506 [T\1
1507 [T ]
1508 [VP,name=VP
1509 [V\1
1510 [V\\smokes ]
1511 ]
1512 ]
1513 ]
1514 ]
1515 \end{forest}
1516 \end{codsiml}
1517 \end{coeden}
1518 % \iffalse
1519 %</verb>
1520 % \fi
1521 %
1522 % \texttt{multidom prepend} and \texttt{multidom append} are wrappers around \texttt{multidom}.
1523 % If \texttt{multidom} is used directly, \textbf{the first argument MUST be a dynamic tree style which creates a new node}.
1524 % Most users should never need to use \texttt{multidom} directly.
1525 % Should you need an operation other than \texttt{prepend} or \texttt{append}, see \textcite{saso-forest} for other possibilities.
1526 % Note, however, that many operations supported by \pkg{forest} simply do not make sense as arguments to \texttt{multidom}.
1527 %
1528 % More precisely, these styles do approximately the following:
1529 % \begin{itemize}
1530 % \item Shift the current node and its descendants by \meta{x shift} horizontally and \meta{y shift} vertically.
1531 % \item Prepend or append a phantom child to \meta{node}.
1532 % (Or, for the generic style, change the nodes of the tree and/or their structural relations according to the specified \pkg{forest} key.
1533 % \item Change the edge path for the current node to a curve in direction \meta{out i} to it's ‘natural’ parent.
1534 % \item Draw a curve leaving the current node in the directions specified \meta{out ii} to \meta{node}.
1535 % \end{itemize}
1536 %
1537 % \DescribeStyle{curve to also parent}\is\marg{dynamic tree operation}\marg{out i}\marg{node}
1538 %
1539 % Connects an additional, extant parent \meta{node} to the current node, drawing a curve between them.
1540 % \meta{out i} specifies the direction of the \texttt{to} path on leaving the current node.
1541 %
1542 % A bit more precisely, \texttt{curve to also parent} alters the nodes in the tree or their structural relationship according to \meta{dynamic tree operation}.
1543 % \textbf{This operation MUST create a new node.}
1544 % The new node is not visible, but its \texttt{edge} constitutes the visible connection between the current node and the additional parent, \meta{node}.
1545 %
1546 % \DescribeStyle{+curve to also parent}\is\marg{out i}\marg{node}
1547 % \DescribeStyle{curve to also parent+}
1548 %
1549 % Equivalent to \texttt{curve to also parent\is\{prepend\textbar append\}}\marg{direction}\marg{node}.
1550 %
1551 % \texttt{curve to also parent}, \texttt{+curve to also parent} and \texttt{curve to also parent+} are wrappers around \texttt{also parent}, \texttt{+also parent} and \texttt{also parent+} from \texttt{ext.multi}.
1552 % They may be used either directly or \emph{via} wrappers such as \texttt{multidom prepend} or by setting a keylist such as \texttt{other multidom parents}.
1553 %
1554 % \DescribeKeylist{other multidom parents}\is\marg{keylist}
1555 %
1556 % This node has additional parents.
1557 % \meta{keylist} should consist of a comma-separated list of additional parents.
1558 % The ‘normal’ \pkg{forest} parent should not be included.
1559 % So if a node has $n$ parents, where $n>1$, \meta{keylist} should consist of $n-1$ elements.
1560 %
1561 % Each element in \meta{keylist} should consist of a \emph{colon}-separated list of elements describing the position and relationship of that additional parent to the current node.
1562 % If a sixth parameter is present, the information is passed to \texttt{multidom}.
1563 % Otherwise, it is passed to \texttt{curve to also parent}.
1564 %
1565 % A complete example\footnote{\texseans[Modified example from Alan Munn]{695600}.} is shown in \cref{box:other-parents}.
1566 % \iffalse
1567 %<*verb>
1568 % \fi
1569 \begin{coeden}*[label=box:other-parents]{}
1570 \begin{codsiml}[minted language=latex]
1571 \newcommand*\1{$'$}
1572 \begin{forest}
1573 [TP,name=TP
1574 [DP,
1575 other multidom parents={%
1576 prepend:-5mm:-2cm:north:east:VP,
1577 prepend:south east:V,
1578 }
1579 [D\\the ]
1580 [NP\\chimney ]
1581 ]
1582 [T\1
1583 [T ]
1584 [VP,name=VP
1585 [V\1,name=V
1586 [V\\smokes ]
1587 ] ] ] ]
1588 \end{forest}
1589 \end{codsiml}
1590 \begin{codsiml}[minted language=latex]
1591 \newcommand*\1{$'$}
1592 \begin{forest}
1593 curved edge/.style args={from (#1.#2) to (#3.#4)}{%
1594 edge path'={(#1.#2) to [looseness=.5, out=#2] (#3.#4)},
1595 },
1596 curve edge/.style={%
1597 curved edge=from (.#1) to (!u.parent anchor),
1598 },
1599 [TP,name=TP
1600 [DP,
1601 +also parent=VP:{%
1602 curved edge=from (!c fosterling.east) to (!c foster parent.parent anchor),
1603 },
1604 +also parent=V:{%
1605 curved edge=from (!c fosterling.south east) to (!c foster parent.parent anchor),
1606 },
1607 curve edge=north,
1608 before drawing tree={%
1609 for tree={x'-=5mm,y'-=2cm,},
1610 },
1611 [D\\the ]
1612 [NP\\chimney ]
1613 ]
1614 [T\1
1615 [T ]
1616 [VP,name=VP
1617 [V\1,name=V
1618 [V\\smokes ]
1619 ] ] ] ]
1620 \end{forest}
1621 \end{codsiml}
1622 \end{coeden}
1623 % \iffalse
1624 %</verb>
1625 % \fi
1626 % \texttt{other multidom parents} here has the value
1627 % \iffalse
1628 %<*verb>
1629 % \fi
1630 \begin{latexcode}
1631 prepend:-5mm:-2cm:north:east:VP,
1632 prepend:south east:V,
1633 \end{latexcode}
1634 % \iffalse
1635 %</verb>
1636 % \fi
1637 % The first element consists of six colon-separated arguments.
1638 % \texttt{prepend} says the additional parent is to the right of the current node.
1639 % The second and third elements say that this node (\texttt{DP}) and its descendants should be shifted \texttt{5cm} left and \texttt{2cm} down.
1640 % \texttt{north} determines the direction in which the curve from the current node (\texttt{DP}) to its ‘natural’ parent (\texttt{TP}) should leave the current node.
1641 % \texttt{east} determines the direction in which the curve from the current node (\texttt{DP}) to its ‘additional’ parent (\texttt{VP}) should leave the current node.
1642 % Finally, \texttt{VP} specifies the additional parent.
1643 %
1644 % The second element consists of three colon-separated arguments.
1645 % \texttt{prepend} again says the additional parent is to the current node's right.
1646 % \texttt{south east} determines the direction of the curve to the additional parent when leaving the current node.
1647 % \texttt{V} specifies the additional parent.
1648 %
1649 % Note that, however long the list of additions, the first element must always specify six arguments and each subsequent element must specify three.
1650 %
1651 % \DescribeBoolr{debug multidom phantoms}\vals{true,false}
1652 %
1653 % \DescribeBoolr{not debug multidom phantoms}
1654 %
1655 % A wrapper around (\texttt{not}) \texttt{debug multi phantoms}.
1656 % \textbf{Requires \pkg{ext.ling-debug}.}
1657 %
1658 % \iffalse
1659 %<*verb>
1660 % \fi
1661 \begin{coeden}*[label=box:other-parents-debug]{}
1662 \begin{codsiml}[minted language=latex]
1663 \newcommand*\1{$'$}%
1664 \forestset{debug multidom phantoms}%
1665 \begin{forest}
1666 [TP,name=TP
1667 [DP,
1668 other multidom parents={%
1669 prepend:-5mm:-2cm:north:east:VP,
1670 prepend:south east:V,
1671 }
1672 [D\\the ]
1673 [NP\\chimney ]
1674 ]
1675 [T\1
1676 [T ]
1677 [VP,name=VP
1678 [V\1,name=V
1679 [V\\smokes ]
1680 ] ] ] ]
1681 \end{forest}
1682 \end{codsiml}
1683 \begin{codsiml}[minted language=latex]
1684 \newcommand*\1{$'$}%
1685 \forestset{debug multi phantoms}%
1686 \begin{forest}
1687 curved edge/.style args={from (#1.#2) to (#3.#4)}{%
1688 edge path'={(#1.#2) to [looseness=.5, out=#2] (#3.#4)},
1689 },
1690 curve edge/.style={%
1691 curved edge=from (.#1) to (!u.parent anchor),
1692 },
1693 [TP,name=TP
1694 [DP,
1695 +also parent=VP:{%
1696 curved edge=from (!c fosterling.east) to (!c foster parent.parent anchor),
1697 },
1698 +also parent=V:{%
1699 curved edge=from (!c fosterling.south east) to (!c foster parent.parent anchor),
1700 },
1701 curve edge=north,
1702 before drawing tree={%
1703 for tree={x'-=5mm,y'-=2cm,},
1704 },
1705 [D\\the ]
1706 [NP\\chimney ]
1707 ]
1708 [T\1
1709 [T ]
1710 [VP,name=VP
1711 [V\1,name=V
1712 [V\\smokes ]
1713 ] ] ] ]
1714 \end{forest}
1715 \end{codsiml}
1716 \end{coeden}
1717 % \iffalse
1718 %</verb>
1719 % \fi
1720 % }
1721 % }
1722 % ^^A >>>
1723 % \end{drop}
1724 % ^^A >>>
1725 %
1726 % \section{Utilities}\label{sec:utils}% ^^A <<<
1727 %
1728 % This library provides \emph{tagging keylists}, together with a few styles which do not really fit anywhere else.
1729 %
1730 %
1731 % \subsection{Alignment}\label{subsec:utils-align}% ^^A <<<
1732 %
1733 % \DescribeStyle{align middle child}\val{option}
1734 %
1735 % If the current node has an odd number of children, sets \texttt{calign child} to the middle child and sets \texttt{calign}\val{option}.
1736 % \meta{option} should, therefore, be a valid value for \texttt{calign}.
1737 %
1738 % If \meta{option} is omitted, a default of \texttt{child edge} is applied.
1739 %
1740 % See \cref{box:pretty-nice} for an example.
1741 %
1742 % \DescribeStyle{align middle children}\val{option}
1743 %
1744 % Sets \texttt{align middle child}\val{option} for the tree.
1745 %
1746 % ^^A >>>
1747 %
1748 % \subsection{Outer labels}\label{subsec:utils-outer}% ^^A <<<
1749 %
1750 % \emph{Outer labels} are nodes added after the tree is drawn, aligned with a boundary of the bounding box of the completed tree and nodes within the tree.
1751 % The idea is to enable the addition of labels such as those shown in \cref{box:prob}.
1752 %
1753 % {\forestapplylibrarydefaults{ext.utils-debug}%
1754 % \iffalse
1755 %<*verb>
1756 % \fi
1757 \begin{codcoeden}*[label=box:prob,sidebyside=false,text and listing]{}
1758 \begin{forest}
1759 for tree={
1760 parent anchor=children,
1761 child anchor=parent,
1762 },
1763 delay={
1764 for descendants={
1765 content/.process={Ow{level}{$\frac{1}{2^{#1}}$}},
1766 },
1767 for nodewalk={
1768 fake=root,
1769 while nodewalk valid={1}{1}%
1770 }{
1771 outer label/.process={Ow{level}{{$n=#1$}:{anchor=west}}}%
1772 },
1773 },
1774 [ [ [ [][] ] [ [][] ] ] [ [ [][] ] [ [][] ] ] ]
1775 \end{forest}
1776 \end{codcoeden}
1777 % \iffalse
1778 %</verb>
1779 % \fi
1780 % }
1781 %
1782 % \DescribeToksr{outer labels at}\val{anchor}
1783 %
1784 % Additional alignment point for any outer labels.
1785 % \meta{anchor} should be a valid anchor for the `current bounding box` when the tree has been drawn, but additional \tikz{} code is not yet executed.
1786 %
1787 % The default is \texttt{east}, which is probably what is wanted for most trees using the \pkg{forest} default value of \texttt{grow} etc.
1788 %
1789 % Note that this is a \emph{register}.
1790 % You cannot use different values for different parts of a tree.
1791 %
1792 % \DescribeKeylistr{outer labels}\is\marg{keylist}
1793 %
1794 % \pgftikz{} key-values applied to all nodes where \texttt{outer label} is set.
1795 % Options passed to \texttt{outer label} are applied later, so may override defaults for the tree.
1796 %
1797 % The default is \texttt{anchor=base west}.
1798 %
1799 % Note that this is a \emph{register}.
1800 % You cannot use different values for different parts of a tree.
1801 %
1802 % \DescribeStyle{outer label}\is\marg{content}
1803 %
1804 % \is\marg{content}\texttt{:}\marg{options}
1805 %
1806 % Create a label aligned with the current node and the additional alignment point specified by \texttt{outer labels at} with content \meta{content}.
1807 % If \meta{options} are given, they are passed to the \tikz{} code responsible for creating the node.
1808 %
1809 % ^^A >>>
1810 %
1811 % \subsection{‘Tagging’ keylists}\label{subsec:utils-tag-props}% ^^A <<<
1812 %
1813 % A ‘tagging keylist’ is very similar to a \pkg{forest} \emph{keylist option}, but its default value can be changed and/or it can be redeclared\footnote{%
1814 % As far as I can tell, this is not possible for regular \pkg{forest} keylist options.
1815 % Once declared, their default values are fixed.%
1816 % }.
1817 % For motivation, see \cref{sec:tag}.
1818 %
1819 % More specifically, \emph{inside} a \env{forest} environment, it behaves exactly like a regular \pkg{forest} keylist option\footnote{%
1820 % This is because it \emph{is} a regular keylist option at this point.%
1821 % }.
1822 % However, \emph{outside} a \env{forest} environment, its default value can be modified and/or replaced.
1823 % Where this is not a requirement, you should use a regular \emph{keylist} option since \emph{tagging keylists} are subject to additional limitations and the implementation is significantly less efficient.
1824 %
1825 % Important:
1826 % \begin{enumerate}
1827 % \item These keys are not really tagging-specific and do not require tagging to be active, despite the names, so may be useful in other contexts.
1828 % \item These keys are only available \emph{outside} \env{forest} environments.
1829 % \item \emph{Tagging keylists} cannot be declared as registers\footnote{%
1830 % This is not a limitation since changing the default value of a \emph{keylist register} is trivial.%
1831 % }.
1832 % Each tagging keylist corresponds to a \emph{keylist option}.
1833 % The option is automatically declared just before every \env{forest} environment in the current \TeX{} group.
1834 % \item An additional \TeX{} group is added to all \env{forest} environments.
1835 % This ensures that the option declaration is properly localised, which in turn allows any tagging keylists' default values to be further manipulated after the current \env{forest} is finished.
1836 % \item \emph{Outside} \env{forest} environments, unlike \pkg{forest} keylists, tagging keylists are \emph{not} ordered and do \emph{not} store more than one instance of any key.
1837 % The underlying implementation uses \pkg{l3prop} property lists.
1838 %
1839 % \emph{Inside} \env{forest} environments, tagging keylists \emph{are} ordered and behave as regular \pkg{forest} keylist options.
1840 % \pkg{l3prop} property lists are \emph{not} used inside \env{forest} environments.
1841 % \item \emph{Outside the \env{forest} environment, they may be manipulated \textbf{only} using the keys defined by this library.}
1842 % \item \emph{Inside the \env{forest} environment, they may be manipulated \textbf{only} using regular \pkg{forest} methods.}
1843 % \end{enumerate}
1844 %
1845 % Note that to actually influence a tree, any tagging keylist must be processed during the construction of that tree.
1846 % Simply declaring a tagging keylist with some set of options will not, in itself, affect the typeset result in anyway.
1847 % This is equally true of regular \pkg{forest} keylists.
1848 % Please see \textcite{saso-forest} for details.
1849 %
1850 % \DescribeCode{declare tagging keylist,redeclare tagging keylist}\is\marg{keylist}\marg{key-value list}
1851 %
1852 % Declares or redeclares a \pkg{forest} \emph{keylist option}.
1853 %
1854 % \textbf{Available only outside \env{forest} environments.}
1855 %
1856 % Since keylists cannot actually be redeclared, what really happens is this:
1857 % \begin{itemize}
1858 % \item An internal property list is defined to hold \meta{default}.
1859 % This may then be manipulated using the various keys explained below.
1860 % \item At the start of each \env{forest} environment (within the current \TeX{} group), a keylist option is declared.
1861 % The default value passed to \texttt{declare keylist} is \emph{not} necessarily \meta{key-value list}.
1862 % It is, rather, a key-value list derived from the contents of the underlying property list at the time.
1863 % Hence, the default may be further manipulated after the keylist option is declared.
1864 % \end{itemize}
1865 %
1866 % Note that if you do not want the default be be manipulable after the keylist is declared, you should use the \pkg{forest} key \texttt{declare keylist}\is\marg{keylist}\marg{key-value list} instead, as this will be far more efficient.
1867 %
1868 % \DescribeCode{tagging keylist put}\is\marg{keylist}\marg{key-value list}
1869 %
1870 % Adds the contents of \meta{key-value list} to a \meta{keylist} declared with \texttt{declare tagging keylist}.
1871 %
1872 % Note that if \meta{key-value list} includes an occurrence of a key already in the list, the key will be replaced, even if the value differs.
1873 %
1874 % \DescribeCode{tagging keylist remove key}\is\marg{keylist}\marg{key}
1875 %
1876 % Removes \meta{key} from \meta{keylist}, where \meta{keylist} was previously declared with \texttt{declare tagging keylist}.
1877 %
1878 % \textbf{Available only outside \env{forest} environments.}
1879 %
1880 % Note this removes the \meta{key} regardless of its current value (if any).
1881 %
1882 % \DescribeCode{tagging keylist remove}\is\marg{keylist}\marg{key-value list}
1883 %
1884 % For each \meta{key} or \meta{key}\is\meta{value} pair in \meta{key-value list}, removes \meta{key} from \meta{keylist} iff it has the specified \meta{value} (if given) or no value (otherwise), where \meta{keylist} was previously declared with \texttt{declare tagging keylist}.
1885 %
1886 % \textbf{Available only outside \env{forest} environments.}
1887 %
1888 % Note that a valueless key is distinct from one with an empty value.
1889 % To remove \meta{key} iff it has no value, use \texttt{\meta{key}}.
1890 % To remove \meta{key} iff it's value is empty, use \texttt{\meta{key}={}} or \texttt{\meta{key}=}.
1891 %
1892 % ^^A >>> subsec:utils-tag-props
1893 %
1894 % ^^A >>>
1895 %
1896 %
1897 % \MaybeStop{%
1898 % \def\glossaryname{Changes}%
1899 % \twreg
1900 % \printbibliography
1901 % \PrintChanges
1902 % \PrintIndex
1903 % }
1904 %
1905 %^^A \twreg
1906 %
1907 % \section{Implementation}\label{sec:imp} % ^^A <<<
1908 %
1909 % A double underscore (\texttt{\_\_}) \emph{or} an ‘at’ (\texttt{@}) indicates an internal macro or key.
1910 % These are liable to change without notice and should not be used elsewhere.
1911 %
1912 % \NewDocumentCommand \libinput {m}{%
1913 % \AddToHookNext{cmd/maketitle/after}{%
1914 % \phantomsection
1915 % \addcontentsline{toc}{section}{ext.#1}%
1916 % \fancyhf[lh]{\itshape forest-lib-ext.#1}%
1917 % }%
1918 % \input{\forestextdocbase -#1.dtx}%
1919 % }
1920 %
1921 % \twmarg
1922 %
1923 % \libinput{ling}
1924 %
1925 % \libinput{multi}
1926 %
1927 % {%
1928 % \let\MakePrivateLetters\MyMakePrivateLetters
1929 % \libinput{tagging}
1930 %
1931 % \libinput{utils}%
1932 % }
1933 %
1934 % \twreg
1935 %
1936 %
1937 % ^^A >>>
1938 %
1939 %^^A doc guards <<<
1940 % \iffalse
1941 %<*doc>
1942 \RequirePackage{svn-prov}
1943 \def\GetFileBaseName#1-#2-#3\nil{#1-#2}
1944 \edef\MyFileBaseName{\expandafter\GetFileBaseName\jobname\nil}
1945 \ProvidesFileSVN[\MyFileBaseName-doc]{$Id: forest-ext.dtx 11668 2026-02-21 02:34:38Z cfrees $}[v0.3 \revinfo]
1946 \DefineFileInfoSVN
1947 \AddToHook{begindocument}{\OnlyDescription}
1948 \input{\MyFileBaseName.dtx}
1949 %</doc>
1950 % \fi
1951 %^^A doc guards >>>
1952 %
1953 %^^A doc-code guards <<<
1954 % \iffalse
1955 %<*doc-code>
1956 \RequirePackage{svn-prov}
1957 \def\GetFileBaseName#1-#2-#3\nil{#1-#2}
1958 \edef\MyFileBaseName{\expandafter\GetFileBaseName\jobname\nil}
1959 \ProvidesFileSVN[\MyFileBaseName-code]{$Id: forest-ext.dtx 11668 2026-02-21 02:34:38Z cfrees $}[v0.3 \revinfo]
1960 \DefineFileInfoSVN
1961 \AddToHook{begindocument}{\AlsoImplementation\setcounter{IndexColumns}{2}}
1962 \input{\MyFileBaseName.dtx}
1963 %</doc-code>
1964 % \fi
1965 %^^A doc-code guards >>>
1966 %
1967 %
1968 %\Finale
1969 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1970 %^^A vim: et:tw=0:sw=2:ts=2:foldmethod=marker:fmr=<<<,>>>: