Debian Codegraph @

texmf-dist/doc/latex/concepts/packagedoc.cls

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % %
3 % Copyright (C) 2012 by Michiel Helvensteijn - www.mhelvens.net %
4 % %
5 % This work may be distributed and/or modified under the %
6 % conditions of the LaTeX Project Public License, either %
7 % version 1.3 of this license or (at your option) any later %
8 % version. The latest version of this license is in %
9 % http://www.latex-project.org/lppl.txt %
10 % and version 1.3 or later is part of all distributions of %
11 % LaTeX version 2005/12/01 or later. %
12 % %
13 % This work has the LPPL maintenance status `author-maintained'. %
14 % %
15 % The Current Maintainer of this work is Michiel Helvensteijn. %
16 % %
17 % This work consists of the file packagedoc.cls. %
18 % %
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20
21 \let\packagename\jobname
22
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24 % Document Class %
25 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26
27 \LoadClassWithOptions{ltxdoc}
28
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 % Importing The Relevant Package %
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32
33 \RequirePackage{\packagename}
34
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 % Importing Other Packages %
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38
39 \RequirePackage{etoolbox}
40 \RequirePackage[xcolor]{mdframed}
41 \RequirePackage{marginnote}
42 \RequirePackage{listings}
43 \RequirePackage{textcomp}
44 \RequirePackage[pdftex,colorlinks=true]{hyperref}
45 \RequirePackage{dry}
46 \RequirePackage{needspace}
47
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 % Documentation Options %
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51
52 \EnableCrossrefs
53 \CodelineIndex
54 \RecordChanges
55
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 % File Info %
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59
60 \GetFileInfo{\packagename.sty}
61
62 \title{The \textsf{\packagename} package\thanks{%
63 This document corresponds to \textsf{\packagename}~\fileversion,
64 dated \filedate.%
65 }}
66
67 \author{
68 Michiel Helvensteijn\\
69 \href{mailto:[email protected]}{[email protected]}
70 }
71
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 % Development Info %
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75
76 \newmdenv[
77 leftline = false,
78 rightline = false
79 ]{bannerframe}
80
81 \apptocmd{\maketitle}{
82 \begin{bannerframe}
83 \small
84 \begin{center}
85 Development of this package is organized at
86 \href{http://latex-\packagename.googlecode.com}
87 {latex-\packagename.googlecode.com}.\\
88 I am happy to receive feedback there!
89 \end{center}
90 \end{bannerframe}
91 }{}{}
92
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 % Skipping Paragraph Indentation After Specific Stuff %
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96
97 \let\packagedoc@old@par\par
98
99 \newcommand*{\noindentnext}{%
100 \def\par{%
101 \packagedoc@old@par%
102 \noindent%
103 \let\par\packagedoc@old@par%
104 }%
105 }
106
107 \newcommand*{\noindentafterenv}[1]{
108 \AfterEndEnvironment{#1}{\noindentnext}
109 }
110
111 \newcommand*{\noindentaftercmd}[1]{
112 \apptocmd{#1}{\noindentnext}{}{
113 \ClassError{packagedoc}
114 {Could not patch \protect#1\space command.}
115 {Oops! I tried to auto-skip any indentation after the
116 \protect#1\space command, but I failed somehow.}
117 }
118 }
119
120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 % Example Environment Setup %
122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123
124 %%% Extra keywords for LaTeX
125 %
126 \newcommand{\moretexcs}[1]{
127 \lstdefinelanguage{latex}{
128 language=[LaTeX]tex,
129 moretexcs={ExplSyntaxOn,ExplSyntaxOff,lstinputlisting,detokenize,#1}
130 }
131 }
132
133 %%% Code formatting
134 %
135 \lstdefinestyle{examplecode}{%
136 language=latex,%
137 basicstyle=\ttfamily\small,%
138 texcsstyle=*\bfseries,%
139 upquote=true%
140 }
141
142
143
144 %%% Setting up example code block
145 %
146 \definecolor{examplecodelinecolor}{rgb}{0,0,0}
147 \definecolor{examplecodebackgroundcolor}{rgb}{.9,.9,.9}
148 \newmdenv[
149 linecolor = examplecodelinecolor,
150 backgroundcolor = examplecodebackgroundcolor,
151 skipabove = 0px,
152 skipbelow = 0px,
153 innertopmargin = -3px,
154 innerrightmargin = 4px,
155 innerbottommargin = -3px,
156 innerleftmargin = 4px
157 ]{examplecodeframe}
158
159 %%% Defining example output block
160 %
161 \definecolor{exampleoutputbackgroundcolor}{rgb}{1,1,1}
162 \newmdenv[
163 linecolor = examplecodelinecolor,
164 backgroundcolor = exampleoutputbackgroundcolor,
165 skipabove = 0px,
166 skipbelow = 0px,
167 innertopmargin = 4px,
168 innerrightmargin = 4px,
169 innerbottommargin = 4px,
170 innerleftmargin = 4px
171 ]{exampleoutputframe}
172
173 %%% Macros for counting lines in file, adapted from
174 %%% http://andreas.scherbaum.la/blog/archives/
175 %%% 670-Read-number-lines-in-a-file-in-LaTeX.html
176 %
177 \RequirePackage{ifthen}
178 \newboolean{packagedoc@restfile}
179 \newcommand*{\packagedoc@fileline}{}
180 \newread\packagedoc@file
181 \newcommand*{\packagedoc@readnextline}[1]{%
182 \ifthenelse{\boolean{packagedoc@restfile}}{%
183 \read#1 to \packagedoc@fileline%
184 \ifeof#1\setboolean{packagedoc@restfile}{false}%
185 \else\fi%
186 }{}%
187 }
188 \newcommand*{\countlinesinfile}[2]{%
189 \setboolean{packagedoc@restfile}{true}%
190 \setcounter{packagedoc@linecount}{0}%
191 \openin\packagedoc@file=#1%
192 \whiledo{\boolean{packagedoc@restfile}}{%
193 \packagedoc@readnextline{\packagedoc@file}%
194 \ifthenelse{\boolean{packagedoc@restfile}}{%
195 \stepcounter{packagedoc@linecount}%
196 }{}%
197 }%
198 \closein\packagedoc@file%
199 \edef#2{\thepackagedoc@linecount}%
200 }
201
202 \newcounter{packagedoc@linecount}
203 \newlength{\packagedoc@spacetoreserve}
204
205 %%% DRYer without output
206 %
207 \NewDRYer{latex-example}{%
208 \addvspace{4px}%
209 {%
210 \ttfamily\small%
211 \countlinesinfile{#1}{\countedlines}%
212 \setlength{\packagedoc@spacetoreserve}{\countedlines\baselineskip}%
213 \addtolength{\packagedoc@spacetoreserve}{-4px}%
214 \needspace{\packagedoc@spacetoreserve}%
215 }%
216 \begin{examplecodeframe}%
217 \renewcommand{\ttdefault}{pcr}%
218 \lstinputlisting[style=examplecode]{#1}%
219 \end{examplecodeframe}%
220 #2%
221 \noindentnext%
222 \addvspace{4px}%
223 }
224
225 %%% DRYer WITH output but WITHOUT side-effects
226 %
227 \NewDRYer{latex-example-show}{%
228 \addvspace{4px}%
229 {%
230 \ttfamily\small%
231 \countlinesinfile{#1}{\countedlines}%
232 \setlength{\packagedoc@spacetoreserve}{\countedlines\baselineskip}%
233 \addtolength{\packagedoc@spacetoreserve}{\baselineskip}%
234 \needspace{\packagedoc@spacetoreserve}%
235 }%
236 \begin{examplecodeframe}%
237 \renewcommand{\ttdefault}{pcr}%
238 \lstinputlisting[style=examplecode]{#1}%
239 \end{examplecodeframe}\vspace{-4px}%
240 \begin{exampleoutputframe}%
241 #2%
242 \end{exampleoutputframe}%
243 \noindentnext%
244 \addvspace{4px}%
245 }
246
247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 % Implementation Code Box Setup %
249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250
251 %%% Saving old implementation code block font
252 %
253 \AtBeginDocument{\let\old@macro@font\macro@font}
254
255 %%% Setup for 'interesting' implementation code blocks
256 %
257 \definecolor{interestingcodebackgroundcolor}{rgb}{.9,.9,.9}
258 \definecolor{interestingcodelinecolor}{rgb}{0,0,0}
259 \mdfdefinestyle{interestingcode}{
260 linecolor = interestingcodelinecolor,
261 backgroundcolor = interestingcodebackgroundcolor
262 }
263 \newcommand*{\interesting}{%
264 \def\codestyle{interestingcode}%
265 \def\codeskipabove{5px}%
266 \let\macro@font\old@macro@font%
267 }
268
269 %%% Setup for 'UNinteresting' implementation code blocks
270 %
271 \definecolor{uninterestingcodebackgroundcolor}{rgb}{.97,.97,.97}
272 \definecolor{uninterestingcodelinecolor}{rgb}{.5,.5,.5}
273 \definecolor{uninterestingcodecolor}{rgb}{.4,.4,.4}
274 \mdfdefinestyle{uninterestingcode}{
275 linecolor = uninterestingcodelinecolor,
276 backgroundcolor = uninterestingcodebackgroundcolor,
277 }
278 \newcommand*{\uninteresting}{%
279 \def\codestyle{uninterestingcode}%
280 \def\codeskipabove{-5px}%
281 \def\macro@font{\color{uninterestingcodecolor}\old@macro@font}%
282 }
283
284 %%% Actually surround 'macrocode' with the frame
285 %
286 \surroundwithmdframed[
287 style = \codestyle,
288 skipabove = \codeskipabove,
289 skipbelow = 5px,
290 splittopskip = 10px,
291 splitbottomskip = 4px,
292 innertopmargin = 4px,
293 innerrightmargin = 4px,
294 innerbottommargin = 4px,
295 innerleftmargin = 4px
296 ]{macrocode}
297
298 \noindentafterenv{macrocode}
299
300 %%% Start out with 'interesting' code status and
301 %%% always go back to it after one code block
302 %
303 \interesting
304 \AfterEndEnvironment{macrocode}{\interesting}
305
306 %%% No indentation after macrocode block
307 %
308 \noindentafterenv{macrocode}
309
310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311 % Argument Specifiers and such %
312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313
314 \newcommand*{\movarg}[1]{[ \texttt{#1} ]}
315 \newcommand*{\momarg}[1]{[ \meta{#1} ]}
316
317 \newcommand{\describemacro}[2]{%
318 \needspace{3\baselineskip}%
319 \noindent\\\DescribeMacro{#1} #2\\\noindentnext%
320 }
321
322 \newcommand{\describemetamacro}[2]{%
323 \needspace{3\baselineskip}%
324 \noindent\\\marginnote{\meta{#1}} #2\\\noindentnext%
325 }
326
327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328 % Other Stuff %
329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
330
331 \noindentafterenv{description}
332 \noindentafterenv{itemize}
333 \noindentafterenv{enumerate}
334
335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336 % Automatic Implementation Docs %
337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338
339 \AtEndDocument{
340 \pagebreak
341
342 \section{Implementation}
343
344 \StopEventually {\PrintChanges}
345
346 We now show and explain the entire implementation from \texttt{\packagename.sty}.
347
348 \DocInput{\packagename.sty}
349
350 \Finale
351
352 \PrintIndex
353 }