Debian Codegraph @

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

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