Debian Codegraph @

texmf-dist/source/latex/apptools/apptools.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: apptools.dtx
4 % Version: 2012/11/28 v1.0
5 % Info: Tools for customizing appendices
6 %
7 % Copyright (c) 2012 Sebastian Kuhnert <mail at sebastian-kuhnert.de>
8 %
9 % This work may be distributed and/or modified under the conditions of the LaTeX
10 % Project Public License, either version 1.3c of this license or (at your
11 % option) any later version. The latest version of this license is available at
12 % http://www.latex-project.org/lppl.txt and version 1.3c or later is part of all
13 % distributions of LaTeX version 2008/05/04 or later.
14 %
15 % This work has the LPPL maintenance status `maintained', the Current Maintainer
16 % of this work is Sebastian Kuhnert.
17 %
18 % This work consists of the main source file apptools.dtx and the derived files
19 % apptools.sty, apptools.pdf, apptools.ins, apptools.drv, apptools-test.tex
20 %
21 % Distribution:
22 % CTAN:macros/latex/contrib/apptools/apptools.dtx
23 % CTAN:macros/latex/contrib/apptools/apptools.ins
24 % CTAN:macros/latex/contrib/apptools/apptools.pdf
25 %
26 % Unpacking:
27 % (a) If apptools.ins is present:
28 % tex apptools.ins
29 % (b) Without apptools.ins:
30 % tex apptools.dtx
31 %
32 % Documentation:
33 % (a) If apptools.drv is present:
34 % pdflatex apptools.drv
35 % (b) Without apptools.drv:
36 % pdflatex apptools.dtx; ...
37 %
38 % Installation:
39 % TDS:tex/latex/apptools/apptools.sty
40 % TDS:doc/latex/apptools/apptools.pdf
41 % TDS:doc/latex/apptools/apptools-test.tex
42 % TDS:source/latex/apptools/apptools.dtx
43 %
44 %<*ignore>
45 \begingroup
46 \catcode123=1 %
47 \catcode125=2 %
48 \def\x{LaTeX2e}%
49 \expandafter\endgroup
50 \ifcase 0\expandafter
51 \ifx\csname processbatchFile\endcsname\relax\else1\fi
52 \ifx\fmtname\x\else 1\fi\relax
53 \else\csname fi\endcsname
54 %</ignore>
55 %<*install>
56 \input docstrip.tex
57 \Msg{************************************************************************}
58 \Msg{* Installation}
59 \Msg{* Package: apptools 2012/11/28 v1.0 Tools for customizing appendices}
60 \Msg{************************************************************************}
61
62 \keepsilent
63 \askforoverwritefalse
64
65 \let\MetaPrefix\relax
66 \preamble
67
68 This is a generated file.
69
70 Project: apptools
71 Version: 2012/11/28 v1.0
72
73 Copyright (c) 2012 by Sebastian Kuhnert <mail at sebastian-kuhnert.de>
74
75 This work may be distributed and/or modified under the conditions of the LaTeX
76 Project Public License, either version 1.3c of this license or (at your
77 option) any later version. The latest version of this license is available at
78 http://www.latex-project.org/lppl.txt and version 1.3c or later is part of all
79 distributions of LaTeX version 2008/05/04 or later.
80
81 This work has the LPPL maintenance status `maintained', the Current Maintainer
82 of this work is Sebastian Kuhnert.
83
84 This work consists of the main source file apptools.dtx and the derived files
85 apptools.sty, apptools.pdf, apptools.ins, apptools.drv, apptools-test.tex.
86
87 \endpreamble
88 \let\MetaPrefix\DoubleperCent
89
90 \generate{%
91 \file{apptools.ins}{\from{apptools.dtx}{install}}%
92 \file{apptools.drv}{\from{apptools.dtx}{driver}}%
93 \usedir{tex/latex/apptools}%
94 \file{apptools.sty}{\from{apptools.dtx}{package}}%
95 \usedir{doc/latex/apptools}%
96 \file{apptools-test.tex}{\from{apptools.dtx}{test}}%
97 }
98
99 \catcode32=13\relax% active space
100 \let =\space%
101 \Msg{************************************************************************}
102 \Msg{*}
103 \Msg{* To finish the installation you have to move the following}
104 \Msg{* files into a directory searched by TeX:}
105 \Msg{*}
106 \Msg{* apptools.sty}
107 \Msg{*}
108 \Msg{* To produce the documentation run:}
109 \Msg{*}
110 \Msg{* pdflatex apptools.drv}
111 \Msg{*}
112 \Msg{* Happy TeXing!}
113 \Msg{*}
114 \Msg{************************************************************************}
115
116 \endbatchfile
117 %</install>
118 %<*ignore>
119 \fi
120 %</ignore>
121 %<*driver>
122 \NeedsTeXFormat{LaTeX2e}
123 \ProvidesFile{apptools.drv}%
124 [2012/11/28 v1.0 Tools for customizing appendices]%
125 \documentclass{ltxdoc}
126 \usepackage{hypdoc}
127 \usepackage[openlevel=2]{bookmark}
128 \usepackage{array}
129
130 \usepackage[T1]{fontenc}
131 \usepackage{textcomp}
132 \usepackage[scaled]{berasans}
133 \usepackage[scaled]{beramono}
134 \usepackage[bitstream-charter]{mathdesign}
135 \usepackage[activate]{microtype}
136
137 \usepackage{xcolor}
138 \hypersetup{linkcolor=red!50!black,
139 urlcolor=purple!50!black}
140 \urlstyle{sf}
141
142 \usepackage[utf8]{inputenc}
143
144 \usepackage{etoolbox}
145
146 \usepackage[british,iso]{isodate}
147
148 \usepackage{embedfile}
149 \embedfile[desc={LaTeX docstrip source file for package `apptools'},
150 mimetype={text/x-tex}]{apptools.dtx}
151
152 \newcommand{\CTAN}[1]{\href{http://mirror.ctan.org/#1}{CTAN:\nolinkurl{#1}}}
153 \newcommand{\TDS}[1]{TDS:\nolinkurl{#1}}
154 \newcommand{\file}[1]{\nolinkurl{#1}}
155
156 \makeatletter
157 \renewcommand{\DescribeMacro}[1]{%
158 \DescribeMACRO #1\@empty\@empty\@empty
159 }
160 \def\DescribeMACRO#1#2\@empty{%
161 \addvspace{1em}\noindent
162 \phantomsection
163 \label{macrodesc:\expandafter\@gobble\string #1\@empty}%
164 \addcontentsline{toc}{subsection}{%
165 \texttt{\textbackslash\expandafter\@gobble\string #1\@empty}}%
166 \SpecialUsageIndex{#1}%
167 \begingroup
168 \togglefalse{linktodesc}%
169 \hspace{-4em}\texttt{\color{blue!50!black}%
170 \expandafter\cs\expandafter{\expandafter\@gobble\string #1\@empty}#2}%
171 \endgroup
172 \par\smallskip\noindent\ignorespaces
173 }
174 \renewcommand{\PrintMacroName}[1]{%
175 \phantomsection\label{macrodef:\expandafter\@gobble\string#1\@empty}%
176 \raisebox{\baselineskip}{\hypertarget{macrodef:\expandafter\@gobble\string
177 #1\@empty}{}}%
178 \bookmark[dest={macrodef:\expandafter\@gobble\string
179 #1\@empty},level=4]{\textbackslash #1}%
180 \begingroup
181 \toggletrue{linktodesc}%
182 \strut\MacroFont\expandafter\cs\expandafter{\expandafter\@gobble\string
183 #1\@empty}%
184 \endgroup
185 }
186 \renewcommand{\meta@font@select}{%
187 \rmfamily\itshape
188 }
189 \renewcommand{\@hangfrom}[1]{%
190 \setbox\@tempboxa\hbox{\llap{#1}}%
191 \hangindent\wd\@tempboxa
192 \noindent\box\@tempboxa
193 }
194 \makeatother
195
196 \newtoggle{linktodesc}
197 \toggletrue{linktodesc}
198 \csdef{cs }#1{%
199 \iftoggle{linktodesc}{%
200 \ifcsdef{r@macrodesc:#1}{%
201 \hyperref[macrodesc:#1]{\texttt{\color{blue!50!black}\char `\\#1}}%
202 }{%
203 \texttt{\color{blue!50!black}\char `\\ #1}%
204 }%
205 }{%
206 \ifcsdef{r@macrodef:#1}{%
207 \hyperref[macrodef:#1]{\texttt{\color{blue!50!black}\char `\\#1}}%
208 }{%
209 \texttt{\color{blue!50!black}\char `\\#1}%
210 }%
211 }%
212 }
213
214 \EnableCrossrefs
215 \CodelineIndex
216
217 \begin{document}
218 \DocInput{apptools.dtx}
219 \end{document}
220 %</driver>
221 % \fi
222 %
223 % \CheckSum{89}
224 %
225 % \CharacterTable
226 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
227 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
228 % Digits \0\1\2\3\4\5\6\7\8\9
229 % Exclamation \! Double quote \" Hash (number) \#
230 % Dollar \$ Percent \% Ampersand \&
231 % Acute accent \' Left paren \( Right paren \)
232 % Asterisk \* Plus \+ Comma \,
233 % Minus \- Point \. Solidus \/
234 % Colon \: Semicolon \; Less than \<
235 % Equals \= Greater than \> Question mark \?
236 % Commercial at \@ Left bracket \[ Backslash \\
237 % Right bracket \] Circumflex \^ Underscore \_
238 % Grave accent \` Left brace \{ Vertical bar \|
239 % Right brace \} Tilde \~}
240 %
241 % \GetFileInfo{apptools.drv}
242 %
243 % \title{The \texttt{apptools} package}
244 % \author{Sebastian Kuhnert\\\texttt{mail at sebastian-kuhnert.de}}
245 % \date{Documentation for version \csname @gobble\endcsname v1.0
246 % (\printdateTeX{2011/11/21})}
247 %
248 % \maketitle
249 %
250 % \begin{abstract}
251 % The \texttt{apptools} package provides tools to customize appendices. It
252 % provides an \cs{AtAppendix} command to add code to a hook that is executed
253 % when \cs{appendix} is called by the user. Additionally, a \TeX{} conditional
254 % \cs{ifappendix} and a \LaTeX-style conditional \cs{IfAppendix} are provided
255 % to check if \cs{appendix} has already been called.
256 % \end{abstract}
257 %
258 % \tableofcontents
259 %
260 %
261 % \section{Introduction}
262 %
263 % Sometimes it is useful to execute some code at the start of the appendix in an
264 % automated way.
265 % \textsf{KOMA-Script}\footnote{\CTAN{macros/latex/contrib/koma-script/}} classes
266 % provide a hook for this purpose. Relatedly, the
267 % |apa|\footnote{\CTAN{macros/latex/contrib/apa/}} and
268 % |apa6|\footnote{\CTAN{macros/latex/contrib/apa6/}} classes provide a
269 % \TeX\ conditional \cs{ifappendix} to check if \cs{appendix} has been
270 % called already. This package provides an interface to both these features that
271 % is independent of the document class.
272 %
273 %
274 % \subsection{License}
275 %
276 % Copyright \copyright{} 2012 Sebastian Kuhnert. Permission is granted to copy,
277 % distribute and/or modify this software under the terms of the \LaTeX{} Project
278 % Public Licence, version 1.3c or later.\footnote{The latest version of this
279 % license is available at \url{http://www.latex-project.org/lppl/lppl.txt}; it
280 % should also be included in your \TeX{} distribution, usually at
281 % \TDS{doc/latex/base/lppl.pdf}} This package is maintained, the Current
282 % Maintainer is Sebastian Kuhnert.
283 %
284 % \section{User Interface}
285 %
286 % \DescribeMacro{\AtAppendix\marg{code}}%
287 % Add \meta{code} to the hook that is executed when \cs{appendix} is given.
288 %
289 % \DescribeMacro{\IfAppendix\marg{then}\marg{else}}%
290 % Expands to \meta{else} before \cs{appendix} is executed, and to \meta{then}
291 % afterwards.
292 %
293 % \DescribeMacro{\ifappendix}%
294 % Calling \cs{ifappendix} \meta{then}\cs{else} \meta{else}\cs{fi} expands to
295 % \meta{else} before \cs{appendix} is executed, and to \meta{then} afterwards.
296 %
297 % \StopEventually{
298 % }
299 %
300 % \section{Implementation}
301 % \togglefalse{linktodesc}
302 % \begin{macrocode}
303 %<*package>
304 \NeedsTeXFormat{LaTeX2e}
305 \ProvidesPackage{apptools}
306 [2012/11/28 v1.0 Tools for customizing appendices]%
307 % \end{macrocode}
308 %
309 % \begin{macro}{\apptools@hook}
310 % The hook that will be called when \cs{appendix} is executed. By default it
311 % just calls \cs{appendixtrue} to make \cs{ifappendix} and \cs{IfAppendix}
312 % work correctly.
313 % \begin{macrocode}
314 \def\apptools@hook{\appendixtrue}
315 % \end{macrocode}
316 % \end{macro}
317 %
318 % \begin{macro}{\AtAppendix}
319 % Extend \cs{apptools@hook}.
320 % \begin{macrocode}
321 \newcommand{\AtAppendix}{%
322 \g@addto@macro\apptools@hook
323 }
324 % \end{macrocode}
325 % \end{macro}
326 %
327 % \begin{macro}{\apptools@origappendix}
328 % \begin{macro}{\appendix}
329 % Call the hook \cs{apptools@hook} in \cs{appendix}.
330 % \begin{macrocode}
331 \let\apptools@origappendix\appendix
332 \def\appendix{%
333 \apptools@hook \apptools@origappendix
334 }
335 % \end{macrocode}
336 % \end{macro}
337 % \end{macro}
338 %
339 % \begin{macro}{\ifappendix}
340 % The \TeX\ conditional behind \cs{IfAppendix}. The classes |apa| and |apa6|
341 % already define \cs{ifappendix} as \TeX\ conditional, so the \LaTeX\ version
342 % has to be called differently. A second \cs{newif} call for the same
343 % conditional only has the effect of setting it to false, which is
344 % unproblematic in this case.
345 % \begin{macrocode}
346 \newif\ifappendix
347 % \end{macrocode}
348 % \end{macro}
349 %
350 % \begin{macro}{\IfAppendix}
351 % The \LaTeX{} style conditional provided by this package.
352 % \begin{macrocode}
353 \newcommand*{\IfAppendix}{%
354 \ifappendix
355 \expandafter\@firstoftwo
356 \else
357 \expandafter\@secondoftwo
358 \fi
359 }
360 % \end{macrocode}
361 % \end{macro}
362 %
363 %
364 % \begin{macrocode}
365 %</package>
366 % \end{macrocode}
367 %
368 %
369 % \section{Test}
370 %
371 % The file \file{apptools-test.tex} performs some simple tests that the commands
372 % provided by this package actually work.
373 %
374 % \begin{macrocode}
375 %<*test>
376 \NeedsTeXFormat{LaTeX2e}
377 \nofiles
378 \documentclass{article}
379 \usepackage{apptools}[2012/11/28]
380 \usepackage{qstest}
381 \IncludeTests{*}
382 \LogTests{log}{*}{*}
383
384 \begin{document}
385 \makeatletter
386
387 \begin{qstest}{AtAppendix}{AtAppendix}
388 \def\defaulthook{\appendixtrue}
389 \Expect*{\meaning\defaulthook}*{\meaning\apptools@hook}
390 \g@addto@macro\defaulthook{\def\fooafterappendix{foo}}
391 \AtAppendix{\def\fooafterappendix{foo}}
392 \Expect*{\meaning\defaulthook}*{\meaning\apptools@hook}
393 \Expect*{\meaning\fooafterappendix}{undefined}
394 \end{qstest}
395
396 \begin{qstest}{ifbefore}{ifbefore}
397 \Expect{else}*{\ifappendix then\else else\fi}
398 \Expect{else}*{\IfAppendix{then}{else}}
399 \end{qstest}
400
401 \appendix
402
403 \begin{qstest}{ifafter}{ifafter}
404 \Expect{then}*{\ifappendix then\else else\fi}
405 \Expect{then}*{\IfAppendix{then}{else}}
406 \end{qstest}
407
408 \begin{qstest}{hook}{hook}
409 \def\expected{foo}
410 \Expect*{\meaning\fooafterappendix}*{\meaning\expected}
411 \end{qstest}
412
413 \end{document}
414 \@@end
415 %</test>
416 % \end{macrocode}
417 %
418 % \section{Installation}
419 %
420 % \subsection{Obtaining the package}
421 % The package source is attached to this PDF file and can be extracted with many
422 % recent PDF viewers. Alternatively, it can be obtained from
423 % \CTAN{macros/latex/contrib/apptools/apptools.dtx}.
424 %
425 % \subsection{Unpacking the package}
426 % The \file{.dtx} file is a self-extracting \textsf{docstrip} archive. The files are
427 % extracted by running the \file{.dtx} through plain \TeX:
428 % \begin{quote}
429 % |tex apptools.dtx|
430 % \end{quote}
431 % If the \file{.ins} file is already present, you can run \TeX\
432 % alternatively on the \file{.ins} file.
433 %
434 % \subsection{Generating the package documentation}
435 % Running the \file{.dtx} file through pdf\LaTeX{} generates the package
436 % documentation:
437 % \begin{quote}
438 % |pdflatex apptools.dtx|
439 % \end{quote}
440 % Multiple passes will be necessary to get the cross references right. The index
441 % will be generated automatically if |makeindex| is allowed for \cs{write18};
442 % otherwise the following command is needed before the last pdf\LaTeX{}
443 % pass:
444 % \begin{quote}
445 % |makeindex -s gind.ist apptools.idx|
446 % \end{quote}
447 %
448 % \subsection{Moving the files}
449 % To finish the installation, the generated files need to be moved to an
450 % appropriate place in your local \TeX\ Directory Structure (TDS) tree, also
451 % known as |texmf| tree. The suggested locations are:
452 % \begin{quote}
453 % \begin{tabular}{@{}>{\sffamily}l@{\quad$\mapsto$\quad}>{TDS:\sffamily}l@{}}
454 % apptools.sty & tex/latex/apptools/apptools.sty\\
455 % apptools.pdf & doc/latex/apptools/apptools.pdf\\
456 % apptools-test.tex & doc/latex/apptools/apptools-test.tex\\
457 % apptools.dtx & source/latex/apptools/apptools.dtx\\
458 % \end{tabular}
459 % \end{quote}
460 %
461 % \appendix
462 % \section*{Revision History}
463 % \addcontentsline{toc}{section}{Revision History}
464 %
465 % \newcommand{\version}[2]{^^A
466 % \hypertarget{version.#1}{}^^A
467 % \subsection*{\llap{v#1\quad}#2}^^A
468 % \bookmark[dest=version.#1,level=subsection]{v#1, #2}^^A
469 % \ignorespaces
470 % }
471 %
472 % \version{1.0}{2012-11-28}
473 % Initial release.
474 %
475 % \makeatletter
476 % \immediate\closeout\@indexfile
477 % \makeatother
478 % \immediate\write18{makeindex -s gind.ist \jobname.idx}
479 % \IndexPrologue{
480 % \section*{Index}\addcontentsline{toc}{section}{Index}
481 % Most index entries refer to code line numbers; the definition of a command is
482 % marked by underlining this number. Numbers in italics are an exception: They
483 % give the page on which the command is described.
484 % }
485 % \PrintIndex
486 %
487 % \Finale
488 \endinput