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