| 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 |
|
| 40 |
\RequirePackage[hyphens]{url} |
| 41 |
|
| 42 |
\RequirePackage{etoolbox} |
| 43 |
\RequirePackage[xcolor]{mdframed} |
| 44 |
\RequirePackage{marginnote} |
| 45 |
\RequirePackage{listings} |
| 46 |
\RequirePackage{textcomp} |
| 47 |
\RequirePackage[pdftex,colorlinks=true]{hyperref} |
| 48 |
\RequirePackage{dry} |
| 49 |
\RequirePackage{needspace} |
| 50 |
|
| 51 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 52 |
% Documentation Options % |
| 53 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 54 |
|
| 55 |
\EnableCrossrefs |
| 56 |
\CodelineIndex |
| 57 |
\RecordChanges |
| 58 |
|
| 59 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 60 |
% File Info % |
| 61 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 62 |
|
| 63 |
\GetFileInfo{\packagename.sty} |
| 64 |
|
| 65 |
\title{The \textsf{\packagename} package\thanks{% |
| 66 |
This document corresponds to \textsf{\packagename}~\fileversion, |
| 67 |
dated \filedate.% |
| 68 |
}} |
| 69 |
|
| 70 |
\author{ |
| 71 |
Michiel Helvensteijn\\ |
| 72 |
\href{mailto:[email protected]}{[email protected]} |
| 73 |
} |
| 74 |
|
| 75 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 76 |
% Development Info % |
| 77 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 78 |
|
| 79 |
\newmdenv[ |
| 80 |
leftline = false, |
| 81 |
rightline = false |
| 82 |
]{bannerframe} |
| 83 |
|
| 84 |
\apptocmd{\maketitle}{ |
| 85 |
\begin{bannerframe} |
| 86 |
\small |
| 87 |
\begin{center} |
| 88 |
Development of this package is organized at |
| 89 |
\href{http://latex-\packagename.googlecode.com} |
| 90 |
{latex-\packagename.googlecode.com}.\\ |
| 91 |
I am happy to receive feedback there! |
| 92 |
\end{center} |
| 93 |
\end{bannerframe} |
| 94 |
}{}{} |
| 95 |
|
| 96 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 97 |
% Example Environment Setup % |
| 98 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 99 |
|
| 100 |
%%% Extra keywords for LaTeX |
| 101 |
% |
| 102 |
\newcommand{\moretexcs}[1]{ |
| 103 |
\lstdefinelanguage{latex}{ |
| 104 |
language=[LaTeX]tex, |
| 105 |
alsoletter={\[,\],\$}, |
| 106 |
moretexcs={ExplSyntaxOn,ExplSyntaxOff,lstinputlisting,detokenize,[,],#1}, |
| 107 |
keywords={\$} |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
%%% Code formatting |
| 112 |
% |
| 113 |
\lstdefinestyle{examplecode}{% |
| 114 |
language=latex,% |
| 115 |
basicstyle=\ttfamily\small,% |
| 116 |
texcsstyle=*\bfseries,% |
| 117 |
keywordstyle=*\bfseries,% |
| 118 |
upquote=true% |
| 119 |
} |
| 120 |
|
| 121 |
%%% Setting up example code block |
| 122 |
% |
| 123 |
\definecolor{examplecodelinecolor}{rgb}{0,0,0} |
| 124 |
\definecolor{examplecodebackgroundcolor}{rgb}{.9,.9,.9} |
| 125 |
\newmdenv[ |
| 126 |
linecolor = examplecodelinecolor, |
| 127 |
backgroundcolor = examplecodebackgroundcolor, |
| 128 |
skipabove = 0px, |
| 129 |
skipbelow = 0px, |
| 130 |
innertopmargin = -3px, |
| 131 |
innerrightmargin = 4px, |
| 132 |
innerbottommargin = -3px, |
| 133 |
innerleftmargin = 4px |
| 134 |
]{examplecodeframe} |
| 135 |
|
| 136 |
%%% Defining example output block |
| 137 |
% |
| 138 |
\definecolor{exampleoutputbackgroundcolor}{rgb}{1,1,1} |
| 139 |
\newmdenv[ |
| 140 |
linecolor = examplecodelinecolor, |
| 141 |
backgroundcolor = exampleoutputbackgroundcolor, |
| 142 |
skipabove = 0px, |
| 143 |
skipbelow = 0px, |
| 144 |
innertopmargin = 4px, |
| 145 |
innerrightmargin = 4px, |
| 146 |
innerbottommargin = 4px, |
| 147 |
innerleftmargin = 4px, |
| 148 |
nobreak = true |
| 149 |
]{exampleoutputframe} |
| 150 |
|
| 151 |
%%% Macros for counting lines in file, adapted from |
| 152 |
%%% http://andreas.scherbaum.la/blog/archives/ |
| 153 |
%%% 670-Read-number-lines-in-a-file-in-LaTeX.html |
| 154 |
% |
| 155 |
\RequirePackage{ifthen} |
| 156 |
\newboolean{packagedoc@restfile} |
| 157 |
\newcommand*{\packagedoc@fileline}{} |
| 158 |
\newread\packagedoc@file |
| 159 |
\newcommand*{\packagedoc@readnextline}[1]{% |
| 160 |
\ifthenelse{\boolean{packagedoc@restfile}}{% |
| 161 |
\read#1 to \packagedoc@fileline% |
| 162 |
\ifeof#1\setboolean{packagedoc@restfile}{false}% |
| 163 |
\else\fi% |
| 164 |
}{}% |
| 165 |
} |
| 166 |
\newcommand*{\countlinesinfile}[2]{% |
| 167 |
\setboolean{packagedoc@restfile}{true}% |
| 168 |
\setcounter{packagedoc@linecount}{0}% |
| 169 |
\openin\packagedoc@file=#1% |
| 170 |
\whiledo{\boolean{packagedoc@restfile}}{% |
| 171 |
\packagedoc@readnextline{\packagedoc@file}% |
| 172 |
\ifthenelse{\boolean{packagedoc@restfile}}{% |
| 173 |
\stepcounter{packagedoc@linecount}% |
| 174 |
}{}% |
| 175 |
}% |
| 176 |
\closein\packagedoc@file% |
| 177 |
\edef#2{\thepackagedoc@linecount}% |
| 178 |
} |
| 179 |
|
| 180 |
\newcounter{packagedoc@linecount} |
| 181 |
\newlength{\packagedoc@spacetoreserve} |
| 182 |
|
| 183 |
%%% DRYer without output |
| 184 |
% |
| 185 |
\NewDRYer{latex-example}{% |
| 186 |
\addvspace{6px}% |
| 187 |
{% |
| 188 |
\ttfamily\small% |
| 189 |
\countlinesinfile{#1}{\countedlines}% |
| 190 |
\setlength{\packagedoc@spacetoreserve}{\countedlines\baselineskip}% |
| 191 |
\addtolength{\packagedoc@spacetoreserve}{-4px}% |
| 192 |
\needspace{\packagedoc@spacetoreserve}% |
| 193 |
}% |
| 194 |
\begin{examplecodeframe}% |
| 195 |
\renewcommand{\ttdefault}{pcr}% |
| 196 |
\lstinputlisting[style=examplecode]{#1}% |
| 197 |
\end{examplecodeframe}% |
| 198 |
#2% |
| 199 |
\addvspace{6px}% |
| 200 |
} |
| 201 |
|
| 202 |
%%% DRYer WITH output but WITHOUT side-effects |
| 203 |
% |
| 204 |
\NewDRYer{latex-example-show}{% |
| 205 |
\addvspace{6px}% |
| 206 |
{% |
| 207 |
\ttfamily\small% |
| 208 |
\countlinesinfile{#1}{\countedlines}% |
| 209 |
\setlength{\packagedoc@spacetoreserve}{\countedlines\baselineskip}% |
| 210 |
\addtolength{\packagedoc@spacetoreserve}{\baselineskip}% |
| 211 |
\needspace{\packagedoc@spacetoreserve}% |
| 212 |
}% |
| 213 |
\begin{examplecodeframe}% |
| 214 |
\renewcommand{\ttdefault}{pcr}% |
| 215 |
\lstinputlisting[style=examplecode]{#1}% |
| 216 |
\end{examplecodeframe}\vspace{-4px}% |
| 217 |
\begin{exampleoutputframe}% |
| 218 |
#2% |
| 219 |
\end{exampleoutputframe}% |
| 220 |
\addvspace{6px}% |
| 221 |
} |
| 222 |
|
| 223 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 224 |
% Implementation Code Box Setup % |
| 225 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 226 |
|
| 227 |
%%% Saving old implementation code block font |
| 228 |
% |
| 229 |
\AtBeginDocument{\let\old@macro@font\macro@font} |
| 230 |
|
| 231 |
%%% Setup for 'interesting' implementation code blocks |
| 232 |
% |
| 233 |
\definecolor{interestingcodebackgroundcolor}{rgb}{.9,.9,.9} |
| 234 |
\definecolor{interestingcodelinecolor}{rgb}{0,0,0} |
| 235 |
\mdfdefinestyle{interestingcode}{ |
| 236 |
linecolor = interestingcodelinecolor, |
| 237 |
backgroundcolor = interestingcodebackgroundcolor |
| 238 |
} |
| 239 |
\newcommand*{\interesting}{% |
| 240 |
\def\codestyle{interestingcode}% |
| 241 |
\def\codeskipabove{5px}% |
| 242 |
\let\macro@font\old@macro@font% |
| 243 |
} |
| 244 |
|
| 245 |
%%% Setup for 'UNinteresting' implementation code blocks |
| 246 |
% |
| 247 |
\definecolor{uninterestingcodebackgroundcolor}{rgb}{.97,.97,.97} |
| 248 |
\definecolor{uninterestingcodelinecolor}{rgb}{.5,.5,.5} |
| 249 |
\definecolor{uninterestingcodecolor}{rgb}{.4,.4,.4} |
| 250 |
\mdfdefinestyle{uninterestingcode}{ |
| 251 |
linecolor = uninterestingcodelinecolor, |
| 252 |
backgroundcolor = uninterestingcodebackgroundcolor, |
| 253 |
} |
| 254 |
\newcommand*{\uninteresting}{% |
| 255 |
\def\codestyle{uninterestingcode}% |
| 256 |
\def\codeskipabove{-5px}% |
| 257 |
\def\macro@font{\color{uninterestingcodecolor}\old@macro@font}% |
| 258 |
} |
| 259 |
|
| 260 |
%%% Actually surround 'macrocode' with the frame |
| 261 |
% |
| 262 |
\surroundwithmdframed[ |
| 263 |
style = \codestyle, |
| 264 |
skipabove = \codeskipabove, |
| 265 |
skipbelow = 5px, |
| 266 |
splittopskip = 10px, |
| 267 |
splitbottomskip = 4px, |
| 268 |
innertopmargin = 4px, |
| 269 |
innerrightmargin = 4px, |
| 270 |
innerbottommargin = 4px, |
| 271 |
innerleftmargin = 4px |
| 272 |
]{macrocode} |
| 273 |
|
| 274 |
%%% Start out with 'interesting' code status and |
| 275 |
%%% always go back to it after one code block |
| 276 |
% |
| 277 |
\interesting |
| 278 |
\AfterEndEnvironment{macrocode}{\interesting} |
| 279 |
|
| 280 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 281 |
% Argument Specifiers and such % |
| 282 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 283 |
|
| 284 |
\newcommand*{\movarg}[1]{[ \texttt{#1} ]} |
| 285 |
\newcommand*{\momarg}[1]{[ \meta{#1} ]} |
| 286 |
|
| 287 |
\newcommand{\describemacro}[2]{% |
| 288 |
\needspace{3\baselineskip}% |
| 289 |
\noindent\\\DescribeMacro{#1} #2\\% |
| 290 |
} |
| 291 |
|
| 292 |
\newcommand{\describemetamacro}[2]{% |
| 293 |
\needspace{3\baselineskip}% |
| 294 |
\noindent\\\marginnote{\meta{#1}} #2\\% |
| 295 |
} |
| 296 |
|
| 297 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 298 |
% Automatic Implementation Docs % |
| 299 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 300 |
|
| 301 |
\AtEndDocument{ |
| 302 |
\pagebreak |
| 303 |
|
| 304 |
\section{Implementation} |
| 305 |
|
| 306 |
\StopEventually {\PrintChanges} |
| 307 |
|
| 308 |
We now show and explain the entire implementation from \texttt{\packagename.sty}. |
| 309 |
|
| 310 |
\DocInput{\packagename.sty} |
| 311 |
|
| 312 |
\Finale |
| 313 |
|
| 314 |
\PrintIndex |
| 315 |
} |