Debian Codegraph @

texmf-dist/doc/latex/dtxgallery/dtxgallery.dtx

raw
1 %
2 % Part of Will Robertson's DTXGALLERY bundle, version 1.
3 %
4 \documentclass{ltxdoc}
5 \EnableCrossrefs
6 \CodelineIndex
7 \RecordChanges
8 %\OnlyDescription
9
10 \usepackage{fancyvrb}
11 \usepackage[T1]{fontenc}
12 \usepackage[osf,sc]{mathpazo}
13 \renewcommand\sfdefault{lmsf}
14 \renewcommand\ttdefault{lmtt}
15 \usepackage{microtype}
16 \linespread{1.1}
17
18 \usepackage{xcolor}
19 \usepackage{textcomp}
20 \usepackage{rearrange}
21 \usepackage[small,it,center]{titlesec}
22 \usepackage{enumitem}
23 \setdescription{font=\itshape,style=nextline}
24
25 \makeatletter
26 \def\@part[#1]#2{%
27 \refstepcounter{part}%
28 \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
29 {\parindent \z@ \raggedright
30 \interlinepenalty \@M
31 \centering\normalfont\scshape
32 \MakeLowercase{\large\partname\nobreakspace\thepart~---~#2}%
33 \markboth{}{}\par}%
34 \nobreak
35 \vskip 3ex
36 \@afterheading}
37 \makeatother
38
39 \def\dtx{\textsc{dtx}}
40 \def\ins{\textsc{ins}}
41 \def\pdf{\textsc{pdf}}
42 \def\ctan{\textsc{ctan}}
43 \def\pkg#1{\texttt{#1}}
44 \def\LaTeX{\textsc{Latex}}
45
46 \begin{document}
47
48 \title{A gallery of \dtx\ files}
49 \author{Will Robertson}
50 \maketitle
51
52 \section{Introduction}
53
54 This work is a collection of files that demonstrate
55 simple things that are possible with the flexible
56 and under-appreciated docstrip file format.
57 It is intended as a companion to Scott Pakin's
58 excellent and influential `dtxtut' example of producing
59 LaTeX packages in this way.
60
61 \section{Files in the gallery}
62
63 The \dtx\ examples in this gallery are listed below in
64 approximate order of both relevance and complexity.
65
66 \begin{description}
67 \item[single-source.dtx]
68
69 This is an example of both the .sty and .ins
70 files being extracted from the .dtx file. This
71 allows maintenance of a single source file
72 but still produces a `standard-behaviour' \dtx/\ins\
73 pair for upload to \ctan.
74
75 \item[conditional-code.dtx]
76 This example shows conditional extraction of code into multiple files,
77 allowing the easy generation of `debug' versions of package, for example.
78
79 \item[rearrange.dtx]
80
81 This example demonstrates how source code may
82 be written and documented in a different logical
83 order than in which it is required to execute.
84
85 This can be useful, for example, when default
86 values are provided at the last stage of the package
87 loading, but you wish to describe them first in the
88 main body of the (non-technical) documentation.
89
90 \item[dtxgallery.dtx]
91
92 This very document is an example of a \dtx\ file that is itself the compilation of multiple, external, \dtx\ files. It is useful for generating a single documentation file for a large software collection (e.g., the \LaTeX\ sources themselves).
93 \end{description}
94
95 \section{How to use this gallery}
96 It will be clearest to now stop reading this document and take a look at the individual \dtx\ files (and their compiled \pdf\ files) mentioned above. The rest of this file contains a compilation of the \dtx\ files in the gallery, which is an example in itself. Read about it later on in File~\ref{part:gallery} on page~\pageref{part:gallery}.
97
98 \section{Interlude: eliminating guards}
99 While I'm in a position to comment on some things, I may as well put in a few tips that I use when writing \dtx\ files.
100
101 `Guards' are what delimit code sections in \dtx\ files. Many packages will have no need for anything fancy in this regard, and it will be quite common to see things like:
102 \begin{Verbatim}[commandchars=|\[\],frame=single]
103 % [|color[blue]...]
104 % \begin{macrocode}
105 %<*package>
106 |meta[|color[blue]|rmfamily[]The entire, commented, package code]
107 %</package>
108 % \end{macrocode}
109 % [|color[blue]...]
110 \end{Verbatim}
111 with other guards used to section off things like the driver code in the beginning and possibly other bits and pieces. In such cases, it is not necessary to include the guards in the typeset documentation (if we're trying to make things as simple as possible for the reader), so I like to write instead:
112 \begin{Verbatim}[commandchars=|\[\],frame=single]
113 % [|color[blue]...]
114 % \iffalse
115 %<*package>
116 % \fi
117 % \begin{macrocode}
118 |meta[|color[blue]|rmfamily[]The entire, commented, package code]
119 % \end{macrocode}
120 % \iffalse
121 %</package>
122 % \fi
123 % [|color[blue]...]
124 \end{Verbatim}
125 This is also useful when logical part/section markup is used to separate the files in the \dtx\ anyway.
126
127 \clearpage
128 \part{Extracting the \ins\ file from the \dtx}
129 \DocInput{single-source.dtx}
130
131 \clearpage
132 \part{Conditionally extracting code}
133 \DocInput{conditional-code.dtx}
134
135 \clearpage
136 \part{Rearranging the code from logical to linear}
137 \DocInput{rearrange.dtx}
138
139 \clearpage
140 \part{The \dtx\ gallery}
141 \label{part:gallery}
142 This very file, \pkg{dtxgallery.dtx}, is an example of a \dtx\ file that contains no code of its own but which loads \emph{other} \dtx\ files.
143
144 Note that code could be included in this file like any other \dtx\ file and typeset along with the following examples, but I've chosen to strip this particular \dtx\ file as far back as possible simply to demonstrate that I can. Therefore, it generates no files, and provides no code. It simply documents other \dtx\ files.
145
146 Note that this file draws into relief the difference between the two locations that `documentation sources' can be placed in a \dtx\ file:
147 \begin{Verbatim}[commandchars=|\[\],label=example.dtx,frame=single]
148 % \iffalse
149 % [|color[blue]...]
150 %<*driver>
151 \documentclass{ltxdoc}
152 [|color[blue]...]
153 \begin{document}
154 |meta[|color[blue]|rmfamily[]Documentation source |textemdash specific]
155 \DocInput{example.dtx}
156 \end{document}
157 %</driver>
158 % \fi
159 % |meta[|color[blue]|rmfamily[]Documentation source |textemdash general]
160 % [|color[blue]...]
161 \end{Verbatim}
162 The `specific' documentation source is used when compiling only that \dtx\ file, whereas \emph{only} the `general' documentation source appears when input via \cmd\DocInclude. In the case of a compilation of \dtx\ files (which is what the document you're reading demonstrates), \cmd\DocInclude\ is referring to the hypothetical \pkg{example.dtx} in a completely different file, so the specific part of the code is invisible.
163
164 Therefore, it is a good idea to define formatting and document metadata (such as \cmd\title\ and \cmd\maketitle) in the `specific' location, and include only the body of the documentation in the `general' area.
165
166 This file is an example of how formatting code in the `specific' area here changes the fonts and layout used only in the \dtx\ gallery itself.
167
168 \end{document}