So, I've been trying to write a python script that will produce the TikZ/LaTeX source code for one of these filesystem tree / directory structure diagrams:
Preview
Code
LaTeX: TikZ
\documentclass[tikz,border=10]{standalone}
\usetikzlibrary{trees}
\tikzstyle{every node}=[draw=black,thick,anchor=west]
\begin{document}
\begin{tikzpicture}[ %
grow via three points={one child at (0.5,-0.7) and two children at (0.5,-0.7) and (0.5,-1.4)},
edge from parent path={(\tikzparentnode.south)|-(\tikzchildnode.west)}]
\node {/tmp/test}
%
child{node{a}
child{node{1}}
child{node{2}}
child{node{3}}}
child [missing] {} %
child [missing] {} %
child [missing] {} %
%
child{node{b}
child{node{1}}
child{node{2}}}
child [missing] {} %
child [missing] {} %
%
child{node{c}
child{node{1}}}
child [missing] {} %
%
child{node{d}};
%
\end{tikzpicture}
\end{document}
It was supposed to be just a quick little thing, but it turns out programming programs to.. program programs can be bloody confusing. I'd like a way to do it all from within the LaTeX environment (perhaps LuaLaTeX can help?) if possible. Or alternatively some kind of macro or function that takes input in a practical format that can be generated externally and copy/pasted in. Here are a couple of examples of possible ways to generate input that might be suitable (I'm just spitballing here, they won't be perfect, but I can tune them to suit if need be):
Additional Info:
Don't be confused by this section, the question isn't about bash or python or whatever, this is just to demonstrate a few ways to generate input, and also to show it can easily be manipulated to the appropriate format. What I need help with is writing a suitable LaTeX macro that can typeset this information properly.
bash: find
in
find .
out
.
./a
./a/1
./a/2
./a/3
./b
./b/1
./b/2
./c
./c/1
./d
in
printf '{/tmp/test';
find /tmp/test -printf '%P, ';
printf '}\n';
out
{tmp/test, a, a/1, a/2, a/3, b, b/1, b/2, c, c/1, d, }
python: os.walk()
in
import os
for (root,dirs,files) in os.walk('.'):
print(f'{root}\n{dirs}\n{files}')
out
.
['a', 'b', 'c', 'd']
[]
./a
[]
['1', '2', '3']
./b
[]
['1', '2']
./c
[]
['1']
./d
[]
[]
in
print('{/tmp/test',end='')
for (root,dirs,files) in os.walk('.'):
print(f"{root[2:]},[{','.join(dirs+files)}],")
print('}')
out
{/tmp/test,[a,b,c,d],
a,[1,2,3],
b,[1,2],
c,[1],
d,[],
}
forest
with thefolder
option. – user194703 Nov 9 '19 at 2:20tree
utility. But rather than an ascii diagram, I want a full scalable vector SVG or PDF image. – voices Nov 9 '19 at 5:48/tmp/test
). But if that's too tall an order, I can make do with having to specify all the files and subdirectories, especially if it accepts them arguments in a convenient format that I can generate externally. Does that make more sense? – voices Nov 9 '19 at 6:01