Debian Codegraph @

texmf-dist/doc/latex/dirtreex/README.md

raw symbols SCIP
1 # dirtreex
2
3 A self-contained LaTeX package for rendering directory trees inside an optionally breakable, fully styleable frame. Built directly on TikZ and `zref` — no `tcolorbox` or classic `dirtree` underneath.
4
5 ## Features
6
7 - **Auto-tracked depth.** Nest `\dir` and `\file` as deeply as you want; the package derives the depth from the nesting — no per-entry depth argument.
8 - **Sharp or rounded elbows**, configurable per tree or per entry via a single `elbow radius` key (`0pt` = sharp, any positive length = rounded arc).
9 - **Per-entry overrides** for line colour, line width, and elbow radius.
10 - **Breakable frame.** The border, background fill, and every pending `│` column continue seamlessly across page boundaries.
11 - **CJK-friendly.** Works out of the box with `ctex` + LuaLaTeX.
12 - **Zero shell-escape, no external tools, no Python helpers.**
13
14 ---
15
16 ## Table of contents
17
18 1. [Requirements](#1-requirements)
19 2. [Installation](#2-installation)
20 3. [Quick start](#3-quick-start)
21 4. [Entries: `\dir` and `\file`](#4-entries-dir-and-file)
22 5. [Environment options](#5-environment-options)
23 - 5.1 [Top-level keys](#51-top-level-keys)
24 - 5.2 [The `box` family](#52-the-box-family)
25 - 5.3 [The `pagebreak` family](#53-the-pagebreak-family)
26 - 5.4 [Per-entry overrides](#54-per-entry-overrides)
27 6. [Cross-page behaviour](#6-cross-page-behaviour)
28 7. [Example gallery](#7-example-gallery)
29 8. [Compilation](#8-compilation)
30 9. [Troubleshooting](#9-troubleshooting)
31 10. [Limitations](#10-limitations)
32 11. [Project files](#11-project-files)
33 12. [Contact](#12-contact)
34 13. [License](#13-license)
35
36 ---
37
38 ## 1. Requirements
39
40 | Component | Notes |
41 | :--- | :--- |
42 | LuaLaTeX *or* pdfLaTeX | LuaLaTeX is required if your tree contains CJK or any non-Latin-1 text. |
43 | e-TeX extensions (`\numexpr`, `\dimexpr`, `\ifcsname`) | Present in every modern TeX engine (pdfTeX, XeTeX, LuaTeX). The package checks at load time and refuses to load with a single clear error if they are missing. |
44 | TikZ 3.x | The `backgrounds` library is loaded automatically. |
45 | `xcolor` | Both `color!mix!color` and `HTML` colour models are accepted. |
46 | `pgfkeys` | Option parsing. |
47 | `zref-abspage` | Cross-page anchoring. |
48 | `environ` | Environment body capture (required for two-pass rendering). |
49 | `xparse` | Argument parsing for `\dir` / `\file`. Bundled into LaTeX2e formats from 2020-10-01 onward, so the package's `\RequirePackage{xparse}` is a no-op on every modern engine; older formats fall back to the standalone `xparse` package. |
50
51 No `-shell-escape`, no external tools, no Python helper.
52
53 ---
54
55 ## 2. Installation
56
57 1. Copy `dirtreex.sty` into the same directory as your document, **or** install it under `texmf-local/tex/latex/dirtreex/` and run `mktexlsr` (TeX Live) / the MiKTeX equivalent.
58 2. In your preamble:
59
60 ```latex
61 \usepackage{dirtreex}
62 ```
63
64 ---
65
66 ## 3. Quick start
67
68 The smallest possible document:
69
70 ```latex
71 \documentclass{article}
72 \usepackage{dirtreex}
73
74 \begin{document}
75 \begin{dirtreex}
76 \dir{project}{root}{
77 \dir{src}{source}{
78 \file{main.py}{entry point}
79 \file{util.py}{helpers}
80 }
81 \file{README.md}{documentation}
82 }
83 \end{dirtreex}
84 \end{document}
85 ```
86
87 This produces a framed tree where each line is `<name> … <comment>` joined with a dot-leader, directory names receive a trailing `/`, and the elbow connectors (`├`, `└`, `│`) are laid out automatically.
88
89 ---
90
91 ## 4. Entries: `\dir` and `\file`
92
93 ```latex
94 \dir[<entry options>]{<name>}{<comment>}{<children>}
95 \file[<entry options>]{<name>}{<comment>}
96 ```
97
98 - **`<name>`** is typeset in `\ttfamily`. For `\dir`, a trailing `/` is appended automatically — write `src`, not `src/`.
99 - **`<comment>`** is typeset in `\rmfamily` and joined to `<name>` with a dot leader. Pass `{}` for no comment (the dot leader also disappears).
100 - **`<children>`** is a run of further `\dir` / `\file` calls. You do **not** supply the depth — the package tracks it from the nesting.
101 - **`<entry options>`** are optional and described in §5.4.
102
103 ### 4.1 Multi-line comments
104
105 A comment may contain line breaks; the whole block is packed so its combined height stays rectangular, keeping the connector column straight:
106
107 ```latex
108 \file[line color=purple]{Makefile}{
109 build script\\
110 (multi-line comment, stays aligned)
111 }
112 ```
113
114 ### 4.2 Empty subtrees and empty comments
115
116 Both are legal:
117
118 ```latex
119 \dir{empty-dir}{}{} % no comment, no children
120 \dir{has-comment}{with comment}{} % comment but no children
121 ```
122
123 ### 4.3 Multiple trees on one page
124
125 Simply place several `dirtreex` environments back-to-back. Each environment has its own `zref` namespace, so their cross-page bookkeeping never collides.
126
127 ### 4.4 Customising entry-name typesetting (`\DirtreexFormatName`)
128
129 `\DirtreexFormatName` is a public hook that controls how each entry name is typeset. The default expansion is just the stored name plus a trailing `/` for directories — exactly what every example above produces.
130
131 Override it with `\renewcommand` to inject icons, prefixes, or styling. The hook receives the 1-based entry index as `#1`; two stable accessors read the fields you usually need:
132
133 - `\dte@eget{#1}{n}` — the entry name (the second mandatory argument of `\dir` / `\file`).
134 - `\dte@eget{#1}{t}` — `1` for directories, `0` for files.
135
136 Because both identifiers contain `@`, the override has to sit between `\makeatletter` / `\makeatother` (or live inside another package).
137
138 **Example — tag every directory with a `[DIR]` prefix:**
139
140 ```latex
141 \makeatletter
142 \renewcommand{\DirtreexFormatName}[1]{%
143 \ifnum\dte@eget{#1}{t}=1 [DIR]\fi
144 \dte@eget{#1}{n}%
145 \ifnum\dte@eget{#1}{t}=1 /\fi
146 }
147 \makeatother
148 ```
149
150 **Constraints.** The replacement runs inside the row's name vbox under the body's font. It must respect the row's `\hsize` and leave the caller's `\strut` intact; anything that adds vertical material (for example a `\parbox` with its own depth) will pull the entry's connector out of alignment.
151
152 **Stability.** `\DirtreexFormatName`'s argument convention (a single 1-based index) and the two accessors `\dte@eget{#1}{n}` / `\dte@eget{#1}{t}` are committed public surfaces — overrides built around them keep compiling across minor versions. Other internal slot names exist but are not part of the public surface and may change.
153
154 ---
155
156 ## 5. Environment options
157
158 Options go inside `[...]` on `\begin{dirtreex}` and are parsed with `pgfkeys`. Spaces around `=` are allowed.
159
160 ### 5.1 Top-level keys
161
162 | Key | Default | Meaning |
163 | :--- | :--- | :--- |
164 | `fontsize` | `\small` | Size command applied to the tree body. Use any length-free size macro: `\tiny`, `\small`, `\normalsize`, …, `\Large`. |
165 | `line color` | `black` | Default colour for connectors and cross-page extensions. Accepts any `xcolor` expression. |
166 | `line width` | `0.4pt` | Default rule width for all connectors. |
167 | `elbow radius` | `0pt` | Elbow geometry. `0pt` (the default) gives sharp `└`/`├` right angles; any positive length gives rounded arcs of that radius. Clamped against `0.5\baselineskip` and against `line width` for legibility. |
168 | `box` | see §5.2 | Frame settings. |
169 | `pagebreak` | see §5.3 | Page-break settings. |
170
171 ### 5.2 The `box` family
172
173 Pass as a sub-list: `box = { … }`.
174
175 | Subkey | Default | Meaning |
176 | :--- | :--- | :--- |
177 | `true` / `false` | `true` | Draw the frame at all. `box=false` leaves the tree bare. |
178 | `corners` | `0pt` | Corner radius. A single value applies to all four corners; a four-value list is TL, TR, BR, BL. |
179 | `border color` | `black` | |
180 | `border width` | `0.4pt` | |
181 | `background color` | `white` | Named colour, `color!mix!color`, or `HTML`. |
182 | `margin` | `6pt` | Padding between the border and the tree content. Single value = uniform; a four-value list is T, R, B, L (asymmetric padding is supported in both single and breakable output). |
183
184 Example:
185
186 ```latex
187 \begin{dirtreex}[
188 box = {
189 true, corners = 6pt, border color = purple,
190 border width = 1pt, background color = purple!5,
191 margin = {2pt, 20pt, 10pt, 4pt}
192 }
193 ]
194 ```
195
196 ### 5.3 The `pagebreak` family
197
198 | Subkey | Default | Meaning |
199 | :--- | :--- | :--- |
200 | `true` / `false` | `true` | Allow the frame to break across pages. When `false`, tall trees spill past the page; they are **not** truncated. |
201 | `box break at` | `0pt` | Vertical gap between the frame's torn edge and the page boundary. Single value applies to both sides of every break; two values = `first-piece-bottom, next-piece-top`. |
202 | `tree break at` | `1em` (`0pt` when `box=false`) | Same, but applied to the tree's extension rules rather than to the border itself. Useful when the frame should reach the page edge while the internal tree lines pull back. |
203
204 ### 5.4 Per-entry overrides
205
206 Any `\dir` or `\file` can take the same `line color`, `line width`, and `elbow radius` keys. They override the environment-level defaults **for that entry's connector only**:
207
208 ```latex
209 \dir[line color = blue]{src}{source}{
210 \file[line color = red, line width = 1.5pt]{old.py}{deprecated}
211 \file[line color = green!60!black, elbow radius = 0pt]{new.py}{sharp}
212 }
213 ```
214
215 Each entry owns its own `└`-shape. The vertical line continuing **down** from that entry's arm toward the next sibling carries the **next sibling's** colour — so two siblings with different colours share a column that changes colour at arm level (sharp) or at arc-top (rounded).
216
217 ---
218
219 ## 6. Cross-page behaviour
220
221 When the finished tree is taller than the space left on the current page, `dirtreex` cuts it into pieces and emits them on consecutive pages. Each piece is drawn as a self-contained TikZ `\node`, so the border, background, and all active `│` columns continue across the break.
222
223 Two compile passes are required the **first** time the break structure settles (or any time it shifts). The initial pass records absolute page numbers via `zref-abspage`; the second pass reads them so that the connector of each piece-1 entry knows it is not actually anchored to whatever sits above it in the entry list.
224
225 Concretely:
226
227 - Every piece after the first starts with a `0.5\baselineskip` leader of empty space, so the first visible entry shows a `│` above its elbow matching the inter-sibling spacing used on a single page.
228 - Bottom extensions of every active column continue down to the first piece's bottom edge.
229 - Top extensions re-appear in the second (and any subsequent) piece, matching the column colours and widths the previous piece ended with.
230 - The closing piece always spans the configured content width, even when the final `\vsplit` leaves a void remainder (so the bottom border never collapses to a corner sliver).
231
232 ---
233
234 ## 7. Example gallery
235
236 The snippets below are self-contained: drop any of them into a document with `\usepackage{dirtreex}` and they compile. For a much broader set of worked examples — every option, every combination, every edge case — see `dirtreex_examples.tex` in the repository root.
237
238 ### 7.1 Defaults
239
240 ```latex
241 \begin{dirtreex}
242 \dir{project}{default settings}{
243 \file{a.txt}{file A}
244 \file{b.txt}{file B}
245 \dir{sub}{subdirectory}{
246 \file{c.txt}{file C}
247 }
248 }
249 \end{dirtreex}
250 ```
251
252 ### 7.2 Rounded elbows
253
254 ```latex
255 \begin{dirtreex}[elbow radius = 3pt]
256 \dir{round3}{rounded 3pt}{
257 \file{a.txt}{}
258 \dir{sub1}{subdir 1}{
259 \file{b.txt}{}
260 \dir{sub2}{subdir 2}{\file{c.txt}{}}
261 }
262 \file{d.txt}{}
263 }
264 \end{dirtreex}
265 ```
266
267 ### 7.3 Per-branch colours
268
269 ```latex
270 \begin{dirtreex}[
271 elbow radius = 3pt,
272 box = {
273 true, border color = black,
274 background color = white, margin = 6pt
275 }]
276 \dir{project}{}{
277 \dir[line color = blue]{src}{blue: source code}{
278 \file[line color = red]{old.py}{red: deprecated}
279 \file[line color = green!60!black]{new.py}{green: new}
280 }
281 \dir[line color = orange]{docs}{orange: documentation}{
282 \file{api.md}{}
283 }
284 \file[line color = purple]{Makefile}{purple}
285 }
286 \end{dirtreex}
287 ```
288
289 ### 7.4 Thick lines
290
291 ```latex
292 \begin{dirtreex}[
293 line color = red!70!black, line width = 1pt,
294 box = {
295 true, border color = red!80!black,
296 border width = 2pt, background color = red!5
297 }]
298 \dir{bold}{thick-line test}{
299 \file{a.txt}{}
300 \dir{sub}{}{\file{b.txt}{}}
301 }
302 \end{dirtreex}
303 ```
304
305 ### 7.5 A tree that pages across
306
307 ```latex
308 \begin{dirtreex}[
309 elbow radius = 3pt,
310 box = {
311 true, border color = black,
312 background color = white, margin = 6pt
313 }]
314 \dir{cross-page}{long tree}{
315 \dir[line color = red]{red-branch}{}{
316 \file{r1.txt}{}
317 % ... add enough files to overflow
318 }
319 \dir[line color = blue]{blue-branch}{}{file{b1.txt}{}}
320 }
321 \end{dirtreex}
322 ```
323
324 The border, background, and all active `│` columns continue onto the next page; the first visible entry on that page shows a full `│` stem above its elbow. Colours are carried across the page break seamlessly.
325
326 ### 7.6 Asymmetric margin
327
328 ```latex
329 \begin{dirtreex}[
330 box = {margin = {2pt, 20pt, 10pt, 4pt}, % T, R, B, L
331 border color = teal, background color = teal!5}]
332 \dir{root}{}{
333 \file{a}{}
334 \file{b}{}
335 }
336 \end{dirtreex}
337 ```
338
339 ---
340
341 ## 8. Compilation
342
343 ```bash
344 lualatex -interaction=nonstopmode yourdoc.tex
345 lualatex -interaction=nonstopmode yourdoc.tex # 2nd pass for zref
346 ```
347
348 - The first pass records the absolute page number of every entry via `zref-abspage`.
349 - The second pass reads those labels so the first entry of each piece can distinguish "I follow an entry on the same page" (draw a long connector) from "I start a new piece" (draw a short stub and rely on the top extension to fill the column).
350
351 If you have not changed anything that moves a break point, a single pass is enough. For a fresh document, run two.
352
353 `latexmk` works: the package emits a `Package dirtreex Warning: Rerun LaTeX...` at `\end{document}` whenever any `zref` lookup was still unresolved, and `latexmk`'s default rerun detector picks that up automatically.
354
355 ---
356
357 ## 9. Troubleshooting
358
359 | Symptom | Likely cause | Fix |
360 | :--- | :--- | :--- |
361 | First entry on a continuation page has no `│` above its elbow | Only one compile pass has run so far | Run LaTeX again. The `Rerun LaTeX...` warning at `\end{document}` is already asking you to. |
362 | Vertical columns stop halfway down the last piece | Same cause — `zref` has not seen the break yet | Run LaTeX again. |
363 | CJK characters render as `□` or are missing | Wrong engine | Compile with LuaLaTeX (plus `ctex`). |
364 | `! Package dirtreex Error: e-TeX primitives required` at `\usepackage` time | Running a non-e-TeX engine | Use pdfTeX, XeTeX, or LuaTeX. All modern distributions default to e-TeX. |
365 | `! Package dirtreex Error: \dir used outside dirtreex environment` (same for `\file`) | A stray `\dir` or `\file` that is not inside `\begin{dirtreex}…\end{dirtreex}` | Wrap the call in a `dirtreex` environment. |
366 | `! Package dirtreex Error: parsefour expects 1 or 4 comma-separated values` (or `parsetwo expects 1 or 2 …`) | `corners`, `margin`, `box break at`, or `tree break at` given with the wrong arity | Pass either a single value or the full set (four for `corners`/`margin`, two for the break-at keys). Remember the enclosing braces: `margin = {2pt, 4pt, 6pt, 8pt}`, not `margin = 2pt, 4pt, 6pt, 8pt`. |
367
368 ---
369
370 ## 10. Limitations
371
372 - Extremely small `box.margin` combined with a very large `elbow radius` crowds the corner; the internal clamp (`connE ≤ 0.5\baselineskip`) keeps things legible but will not rescue pathological values.
373 - The anchor search compares `zref` page numbers as digit strings. Safe today; be aware if a future `zref` change makes that field non-numeric.
374 - No built-in numbering or hyperlinks. The package focuses on connector geometry; for icons or other entry-name decoration use the `\DirtreexFormatName` hook (§4.4), and wrap the tree in a `minipage` if you need decoration around the whole frame.
375
376 ---
377
378 ## 11. Project files
379
380 | Path | What it is |
381 | :--- | :--- |
382 | `dirtreex.sty` | The package — a single self-contained file. |
383 | `dirtreex_examples.tex` | Worked examples covering the full feature surface. Compile with `lualatex dirtreex_examples.tex` (twice, for `zref` to settle) to see every option in action. |
384 | `README.md` | This documentation. |
385 | `LICENSE` | The LaTeX Project Public License 1.3c. |
386
387 ---
388
389 ## 12. Contact
390
391 - **Maintainer:** CloudCauldron
392 - **Email:** <[email protected]>
393 - **Repository / issues:** <https://github.com/CloudCauldron/dirtreex>
394
395 Bug reports, feature suggestions, and patches are welcome via either channel.
396
397 ---
398
399 ## 13. License
400
401 Released under the [LaTeX Project Public License, version 1.3c](https://www.latex-project.org/lppl.txt) (`LPPL-1.3c`); see [`LICENSE`](LICENSE) for the full text. Maintenance status is `author-maintained`; the Current Maintainer is CloudCauldron (<[email protected]>).
402
403 ---
404
405 ## 14. About the Development
406
407 This project includes code generated with the assistance of AI tools. All such code has been reviewed and integrated by the maintainer.