1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
%% forest-doc.sty
%%
%% `forest-doc.sty` is an auxiliary package needed to compile the documentation of package
%% `forest`. (It is not needed to use the package.)
%%
%% Copyright (c) 2012-2017 Saso Zivanovic
%% (Sa\v{s}o \v{Z}ivanovi\'{c})
%% saso.zivanovic@guest.arnes.si
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%
%% http://www.latex-project.org/lppl.txt
%%
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `author-maintained'.
%%
%% This file is a part of package `forest'. For the list of files
%% constituting the package see main source file of the package,
%% `forest.dtx', or the derived `forest.sty'.
%%
\ProvidesPackage{forest-doc}
\RequirePackage{lstdoc}
\RequirePackage{pgfkeys}
\RequirePackage{forest-index}
% if you want index support, load package "forest-index", but later
\lstset{language={[LaTeX]TeX},tabsize=4,gobble=2,%
basicstyle=\small\ttfamily,basewidth=0.51em,boxpos=c,pointstyle=\pstyle,moredelim=[is][\pstyle]{~}{~}}
%\lst@InstallKeywords{p}{point}{pointstyle}\relax{keywordstyle}{}ld
\def\pstyle{\color{darkgreen}}
\newcommand\itemnosep[1][0pt]{\vspace{\the\dimexpr-1.4ex+#1}}
\lstset{
rangebeginprefix=\ \ \%\%\%\ begin\ listing\ region:\ ,
rangebeginsuffix=,
rangeendprefix=\ \ \%\%\%\ end\ listing\ region:\ ,
rangeendsuffix=,
includerangemarker=false,
keepspaces=true,
}
\newcommand\lstinputregion[3][]{\lstinputlisting[linerange=#3-#3,#1]{#2}}
\def\lst@outputspace{{\ifx\lst@bkgcolor\empty\color{white}\else\lst@bkgcolor\fi\lst@visiblespace}}% this works for acroread, but not for atril :-(
\lstnewenvironment{forestexample}[1][]{%
\PackageWarning{forest-doc}{Compiling example}{}%
\global\let\lst@intname\@empty
\gdef\lst@sample{}%
\def\forestexample@layout{tree on left}%
\def\forestexample@treebin{box}%
\pgfqkeys{/forestexample}{label format,#1}%
\pgfkeysgetvalue{/forestexample/counter}\forestexample@temp
\ifdefempty\forestexample@temp{}{\addtocounter{\forestexample@temp}{1}}%
\setbox\lst@samplebox=\hbox\bgroup
\pgfkeysvalueof{/forestexample/tree prefix}%
\lst@BeginAlsoWriteFile{\jobname.tmp}%
}{%
\lst@EndWriteFile
\pgfkeysvalueof{/forestexample/tree suffix}%
\egroup
\global\setbox\codebox=\box\lst@samplebox
\global\setbox
\treebox
\csname forestexample@treebin@\forestexample@treebin\endcsname
\pgfkeys{/forestexample/do layout/.expanded=\forestexample@layout}%
}
\pgfqkeys{/forestexample}{%
.unknown/.code={\lstset{\pgfkeyscurrentname={#1}}},
index/.code={\indexex[not print]{#1}},
index>/.code={\indexex[not print]>{#1}},
code prefix/.code={\gdef\lst@sample{#1}},
tree prefix/.initial={},
tree suffix/.initial={},
counter/.initial=lstlisting,
no label/.style={counter={}},
label format/.store in=\@currentlabel,
label format/.default={\arabic{\pgfkeysvalueof{/forestexample/counter}}},
tree width/.initial={\dimexpr\linewidth-\wd\codebox-
\glueexpr\pgfkeysvalueof{/forestexample/center skip}\relax\relax},
layout/.store in=\forestexample@layout,
tree bin/.store in=\forestexample@treebin,
do layout/.is choice,
do layout/export/.code={%
\pgfkeysgetvalue{/forestexample/counter}\forestexample@temp
\ifdefempty\forestexample@temp{}{\addtocounter{\forestexample@temp}{-1}}%
},
left skip/.initial={\glueexpr 0pt plus .4\linewidth minus \marginparsep + 0pt minus \@totalleftmargin + 0pt minus .75\marginparwidth},
center skip/.initial={3em plus 0.1\linewidth minus 2em},
right skip/.initial={0pt plus .4\linewidth},
tree left skip/.initial=0pt,
tree right skip/.initial=0pt,
code left skip/.initial=0pt,
code right skip/.initial=0pt,
label y offset/.initial={\height-1ex}, % looks better to me this way
do layout/tree on left/.code={%
\begin{list}{}{\leftmargin 0pt}
\item
\@tempdima=\ifdim\totalht\treebox>\totalht\codebox
\dimexpr0.5 \totalht\treebox\relax
\else
\dimexpr0.5 \totalht\codebox\relax
\fi
\mbox{%
\mbox{\hbox to \linewidth{%
\hskip\pgfkeysvalueof{/forestexample/left skip}\relax
\textvcenter{\box\treebox}%
\hskip\pgfkeysvalueof{/forestexample/center skip}\relax
\hbox{\hskip-\@totalleftmargin\box\codebox\hskip\@totalleftmargin}%
\hskip\pgfkeysvalueof{/forestexample/right skip}\relax
}}%
\forestexample@label
}%
\end{list}
},
v sep/.initial={1ex},
align/.initial=center,
do layout/tree on top/.code={%
\begin{list}{}{\leftmargin 0pt \parsep 0pt \itemsep \pgfkeysvalueof{/forestexample/v sep}\relax}
\item \forestexample@align{tree}\forestexample@label
\item \forestexample@align{code}
\end{list}
},
do layout/tree on bottom/.code={%
\begin{list}{}{\leftmargin 0pt \parsep 0pt \itemsep \pgfkeysvalueof{/forestexample/v sep}\relax}
\item \forestexample@align{code}\forestexample@label
\item \forestexample@align{tree}
\end{list}
},
do layout/only tree/.code={%
\forestexample@align{tree}\forestexample@label
},
do layout/only code/.code={%
\forestexample@align{code}\forestexample@label
},
}
\newbox\treebox
\newbox\codebox
\def\forestexample@treebin@box{%
\hbox{\lst@sampleInput}%
}
\def\forestexample@treebin@minipage{%
\hbox{%
\begin{minipage}{\pgfkeysvalueof{/forestexample/tree width}}%
\lst@sampleInput
\end{minipage}%
}%
}
\def\forestexample@label{%
\pgfkeysgetvalue{/forestexample/counter}\forestexample@temp
\ifdefempty\forestexample@temp{}{%
\makebox[0pt][l]{%
\hskip-\linewidth
\hskip-\@totalleftmargin
\hskip\textwidth
\hskip\marginparsep
\raisebox
{\dimexpr\@tempdima+\depth-\pgfkeysvalueof{/forestexample/label y offset}}%
{\hbox to 0pt{\scriptsize(\@currentlabel)}}%
}%
}%
}
\def\forestexample@align#1{%
\pgfkeysgetvalue{/forestexample/align}\forestexample@temp
\mbox{\hbox to \linewidth{%
\csname forestexample@align@left@\forestexample@temp\endcsname
\hspace*{\pgfkeysvalueof{/forestexample/#1 left skip}}%
\mbox{\expandafter\box\csname #1box\endcsname}%
\hspace*{\pgfkeysvalueof{/forestexample/#1 right skip}}%
\csname forestexample@align@right@\forestexample@temp\endcsname
}}%
}
\def\forestexample@align@left@left{}
\def\forestexample@align@right@left{}
\def\forestexample@align@left@right{\hfill}
\def\forestexample@align@right@right{}
\def\forestexample@align@left@center{\hfill}
\def\forestexample@align@right@center{\hfill}
\newcommand\forestexampleimport[1][]{%
\def\forestexample@layout{tree on left}%
\pgfkeysgetvalue{/forestexample/counter}\forestexample@temp
\ifdefempty\forestexample@temp{}{\addtocounter{\forestexample@temp}{1}}%
\pgfqkeys{/forestexample}{%
label format,
do layout/.expanded=\forestexample@layout
}%
}
\def\totalht#1{\dimexpr\ht#1 + \dp#1\relax}
\def\textvcenter#1{\raisebox{\dimexpr .5\depth-.5\height}{#1}}
% For some reason, lstdoc's version kills all spaces in defaults ...
\def\lst@syntaxlabel@#1>#2\relax
%{\edef\lst@temp{\zap@space#2 \@empty}}
{\edef\lst@temp{#2}}
\def\getforestversion#1/#2/#3 v#4 #5\getforestversion{v#4}
\edef\forestversion{%
\expandafter\expandafter\expandafter\getforestversion
\csname ver@forest.sty\endcsname\getforestversion}
\def\settodayfromforestdateA#1/#2/#3 v#4 #5\settodayfromforestdateA{\def\year{#1}\def\month{#2}\def\day{#3}}
\def\settodayfromforestdate{\expandafter\expandafter\expandafter\settodayfromforestdateA\csname ver@forest.sty\endcsname\settodayfromforestdateA}
\def\TikZ;{{\rm Ti\emph{k}Z}}
\def\PGF;{\textsc{pgf}}
\def\foRest;{\textsc{Forest}}
\def\FoRest;{\textsc{Forest}}
\let\keyname\texttt
\newcommand\cmdname[1]{\texttt{\char\escapechar#1}}
\gdef\greaterthan{>}
\def\gobbleone#1{}
\newcommand{\Repeat}[1]{% from tex.se http://tex.stackexchange.com/a/16194/16819
\expandafter\@Repeat\expandafter{\the\numexpr #1\relax}%
}
\def\@Repeat#1{%
\ifnum#1>0
\expandafter\@@Repeat\expandafter{\the\numexpr #1-1\expandafter\relax\expandafter}%
\else
\expandafter\@gobble
\fi
}
\def\@@Repeat#1#2{%
\@Repeat{#1}{#2}#2%
}
\def\spaces#1{\Repeat{#1}\space}
\RequirePackage{dingbat}
%%% Local Variables:
%%% mode: latex
%%% fill-column: 100
%%% TeX-command-default: "Make PDF"
%%% TeX-master: "forest-doc"
%%% End:
|