Debian Codegraph @

texmf-dist/doc/latex/democodetools/democodetools.tex

raw
1 %%%==============================================================================
2 %% Copyright 2022,2025 by Alceu Frigeri
3 %%
4 %% This work may be distributed and/or modified under the conditions of
5 %%
6 %% * The [LaTeX Project Public License](http://www.latex-project.org/lppl.txt),
7 %% version 1.3c (or later), and/or
8 %% * The [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html),
9 %% version 3 (or later)
10 %%
11 %% This work has the LPPL maintenance status *maintained*.
12 %%
13 %% The Current Maintainer of this work is Alceu Frigeri
14 %%
15 %% This was version 1.0.1beta (2022/09/06) NOW 1.0.2 (2025/10/28)
16 %% Adding a (belated) DEPRECATED note by 2025/10/28
17 %% look, instead, after package codedescribe.
18 %%
19 %% The list of files that compose this work can be found in the README.md file at
20 %% https://ctan.org/pkg/democodetools
21 %%
22 %%%==============================================================================
23 \makeatletter
24 \def\tc@tmp@packname{democodetoolsdoc}
25 \def\tc@tmp@altpackname{democodetoolsdoc}
26 \def\tc@tmp@packdesc{Demo Code Tools Documentantion}
27
28 %%% THIS WAS
29 %\def\tc@tmp@packdate{2022/09/06}
30 %\def\tc@tmp@packversion{1.0.1beta}
31 %%% Adding DEPRECATION note
32 \def\tc@tmp@packdate{2025/10/28}
33 \def\tc@tmp@packversion{1.0.2}
34
35 \let\@exp\expandafter
36 \@exp\edef\csname\tc@tmp@altpackname version\endcsname{\tc@tmp@packversion}
37 \makeatother
38
39 \documentclass[article,nolocal,nogeometry,english]{ufrgscca}
40 \RequirePackage[verbose,a4paper,marginparwidth=27.5mm,top=2.5cm,bottom=1.5cm,hmargin={40mm,20mm},marginparsep=2.5mm,columnsep=10mm,asymmetric]{geometry}
41 \usepackage[T1]{fontenc}
42 \usepackage[utf8]{inputenc}
43 \usepackage{lmodern}
44
45 \usepackage{democodetools}
46
47 \dcTitle{The democodetools and democodelisting \break DEPRECATED}
48 \dcAuthor{Alceu Frigeri}
49 \dcDate{October 2025 \break(September 2022)}
50
51 \begin{document}
52
53 \dcMakeTitle
54
55 \begin{abstract}
56 This has been DEPRECATED in favour of \textbf{codedescribe}. It isn't supported since late 2022. The following documentation is just for the historical record. Loading this will generate an error (package deprecated), IF you really want to use it, you can still use it as \Macro{\usepackage{democodetools-1.0.1}}{}.
57 \end{abstract}
58
59 \begin{dcAbstract}
60 This is `yet another doc/docx/doc3' package. It is designed to be `as class independent as possible', meaning: it makes no assumption about page layout (besides `having a marginpar') or underline macros. Furthermore, it's assumed that \Macro{\maketitle}{} and the \Key{abstract} environment were modified by the underline class, so alternatives (based on the article class) are provided. The main idea is to be able to document a package/class loading it first and then this, so that it is possible not only to document the `syntax' but also to show the end result `as is' when using that other specific class/package.
61
62 \end{dcAbstract}
63
64 \tableofcontents
65
66 \section{Introduction}
67 The packages/classes doc/docx/doc3 (and for that matter doctools) where designed to be used with dtx files, which is handy for package developers, as long as one is fine with the `default article' format (which is true most of the time). This came to be from the willingness of having the `new look and feel' used in doc3, but, instead of having to rely on a standard class, being able to use any class as the base one, which allows to `demonstrate the documented commands with the final layout'.\\
68
69 \Pack{democodelisting} defines a few macros to display and demonstrate \LaTeX~ code verbatim (using \Pack{listings} and \Pack{scontents}), whilst \Pack{democodetools} defines a series of macros to display/enumerate macros and environments (somewhat resembling the \Pack{doc3} style).\\
70 %%\subsection{Current Version}
71 %%This doc regards to \Pack{democodelisting} version \democodelistingversion~ and \Pack{democodetools} version \democodetoolsversion. Those two packages are 'usable' but they haven't been thoroughly tested, nor should anyone consider them stable (they might be considered more or less stable but more due the 'maintainer' lack of time than anything else. Use it at your own risk.)
72
73 \section{democodelisting Package}
74
75 It requires two packages: \Pack{listings} and \Pack{scontents}\\
76 Defines an environment: \Env{stcode} and\\
77 4 commands: \Macro{\DemoCode}{}, \Macro{\DisplayCode}{}, \Macro{\TabbedDisplayCode}{} and \Macro{\setdclisting}{}.
78
79 \subsection{In Memory Code Storage}
80 Thanks to \Pack{scontents} (\Pack{expl3} based) it's possible to store \LaTeX~ code snippets in a \Pack{expl3} key.
81
82 \begin{Envs}{stcode}
83 \begin{Syntax}%
84 \Macro{\begin{stcode}}[keys]{} \Macro{\end{stcode}}{}
85 \end{Syntax}
86 This environment is an alias to \Env{scontents} environment (from \Pack{scontents} package), all \Pack{scontents} keys are valid, with an additional one: \Key{st} which is an alias to the \Key{store-env} key.
87 The environment body is stored verbatim in the \Key{st} named key.
88 \end{Envs}
89
90 \subsection{Code Display/Demo}
91 \begin{Macros}{\DisplayCode,\DemoCode,\TabbedDemoCode}
92 \begin{Syntax}%
93 \Macro{\DisplayCode}[dclisting-keys]{st-name}
94 \Macro{\DemoCode}[dclisting-keys]{st-name}
95 \Macro{\TabbedDemoCode}[dclisting-keys]{st-name}
96 \end{Syntax}
97 \end{Macros}
98 \Macro{\DisplayCode}{} just typesets \Arg{st-name} (the key-name created with \Env{stcode}), in verbatim mode with syntax highlight.\\
99 \Macro{\DemoCode}{} first typesets \Arg{st-name}, as above, then it \emph{executes} said code.
100 Finally \Macro{\TabbedDemoCode}{} does the same, but typesetting it, and executed code, side by side. N.B. Both typeset and executed code are placed inside a \Env{minipage} so that, when \emph{executing} the code, one can have, for instance, 'normal' paragraph indentation.\\
101 For Example:
102
103 \begin{stcode}[st=demostcode]
104 \begin{stcode}[st=stmeta]
105 Some \LaTeX~coding, for example: \ldots.
106 \end{stcode}
107 This will just typesets \Key{stmeta}:
108
109 \DisplayCode{stmeta}
110
111 and this will demonstrate it, side by side with source code:
112
113 \TabbedDemoCode[numbers=left,codeprefix={inner code},resultprefix={inner result}]{stmeta}
114 \end{stcode}
115
116 \DemoCode[emph={DisplayCode,TabbedDemoCode},keywd2={stcode}]{demostcode}
117
118 \begin{Macros}{\setdclisting}
119 \begin{Syntax}%
120 \Macro{\setdclisting}{dclisting-keys}
121 \end{Syntax}
122 Instead of setting/defining \Meta{dclisting-keys} per \Macro{\Demo}{}/\Macro{\Display}{} call, one can set those \emph{globally}, better said, \emph{in the called context group} .\\
123 N.B.: All \Macro{\Display}{}/\Macro{\Demo}{} commands create a local group (\Macro{\begingroup}{}) in which the \Meta{dclisting-keys} are defined, and discarded once said local group is closed. \Macro{\setdclisting}{} defines those keys in the \emph{current} context/group (\Macro{\def}{}, \Macro{\edef}{})
124 \end{Macros}
125
126 \subsubsection{\Meta{dclisting-keys}}
127 Using a \Key{key}\,=\Value{value} syntax, one can fine tune \Pack{listings} syntax highlight.
128 \begin{Args}
129 \DescribeArg{dclisting-keys}
130 \begin{Syntax} %
131 \Keylst{settexcs,settexcs2,settexcs3}
132 \Keylst{texcs,texcs2,texcs3}
133 \Keylst{texcsstyle,texcs2style,texcs3style}
134 \end{Syntax}Those define sets of \LaTeX~commands (csnames), the \Key{set} variants initialize/redefine those sets (an empty list, clears the set), while the others extend those sets. The \Key{style} ones redefines the command display style (an empty \Meta{par} resets the style to it's default).\\
135
136 \begin{Syntax} %
137 \Keylst{setkeywd,setkeywd2,setkeywd3}
138 \Keylst{keywd,keywd2,keywd3}
139 \Keylst{keywdstyle,keywd2style,keywd3style}
140 \end{Syntax}
141 Same for other \emph{keywords} sets.\\
142
143 \begin{Syntax} %
144 \Keylst{setemph,setemph2,setemph3}
145 \Keylst{emph,emph2,emph3}
146 \Keylst{emphstyle,emph2style,emph3style}
147 \end{Syntax}
148 for some extra emphasis sets.\\
149
150 \begin{Syntax} %
151 \Keylst{numbers,numberstyle}
152 \end{Syntax}
153 \Key{numbers} possible values are \Value{none} (default) and \Value{left} (to add tinny numbers to the left of the listing). With \Key{numberstyle} one can redefine the numbering style.\\
154
155 \begin{Syntax} %
156 \Keylst{stringstyle,commentstyle}
157 \end{Syntax}
158 to redefine \Key{strings} and \Key{comments} formatting style.\\
159
160 \begin{Syntax} %
161 \Key{bckgndcolor}
162 \end{Syntax}
163 to change the listing background's color.\\
164
165 \begin{Syntax} %
166 \Keylst{codeprefix,resultprefix}
167 \end{Syntax}
168 those set the \Key{codeprefix} (default: \LaTeX~Code:) and \Key{resultprefix} (default: \LaTeX~Result:)
169 \end{Args}
170
171 \section{democodetools Package}
172
173
174
175
176 \subsection{Environments}
177 \begin{Envs}{Macros,Envs}
178 \begin{Syntax}%
179 \Macro!{\begin{Macros}}{\marg{macrolist}\oarg{space}}
180 \Macro!{\begin{Envs}}{\marg{envlist}\oarg{space}}
181 \end{Syntax}
182 Those are the two main environments to describe \Env{Macros} and \Env{Environments}. Both typeset \Arg{macrolist} (csv list) or \Arg{envlist} (csv list) in the margin. The opcional \Arg{space} is “added” to the left marging length. N.B. Each element of the list gets \Macro{\detokenize}{}
183 \end{Envs}
184
185 \begin{Envs}{Syntax}
186 \begin{Syntax}%
187 \Macro{\begin{Syntax}}{}
188 \end{Syntax}
189 The \Env{Syntax} environment sets the fontsize and activates \Macro{\obeylines}{}, so one can list macros/cmds/keys use, one per line.
190
191 \begin{stcode}[st=demoD]
192 \begin{Envs}{Macros,Envs}
193 \begin{Syntax}%
194 \Macro{\begin{Macros}}{macrolist}
195 \Macro{\begin{Envs}}{envlist}
196 \end{Syntax}
197 Those are the two main ...
198 \end{Envs}
199 \end{stcode}
200 \DisplayCode{demoD}
201
202 \end{Envs}
203
204
205 \begin{Envs}{Args,Keys,Values,Options}
206 \begin{Syntax}%
207 \Macro{\begin{Args}}{}
208 \Macro{\begin{Args+}}{}
209 \Macro{\begin{Keys}}{}
210 \Macro{\begin{Keys+}}{}
211 \Macro{\begin{Values}}{}
212 \Macro{\begin{Values+}}{}
213 \Macro{\begin{Options}}{}
214 \Macro{\begin{Options+}}{}
215 \end{Syntax}
216
217 Those environments are all the same, starting a dedicated \emph{description list}. Together with the many \Macro{\Description...}{} commands, one can list all \Keylst{Options, Args, Keys, Values} as needed. The \Key{+} form are meant to be used with the \Macro{\Description...+}{} forms, for \emph{in text} lists. The non \Key{+} form are meant to have the many \emph{'descriptors'} in the \emph{margin par}.
218 \end{Envs}
219
220 \subsection{Describe Commands}
221 \begin{Macros}{\DescribeMacro}
222 \begin{Syntax}%
223 \Macro!{\DescribeMacro}<*!+>{\marg{csname}\oarg{oarglist}\marg{marglist}}
224 \end{Syntax}
225 \begin{Args+}
226 \DescribeKey+{*} typesets the macro name in bold face.
227 \DescribeKey+{!} \Arg{marglist} is treated as an expandable code, 'as is'.
228 \DescribeKey+{+} the macro name is typeseted in text.
229 \DescribeArg+{csname} macro name (\Macro{\detokenize}{})
230 \DescribeArg+{oarglist} csv list of optional args.
231 \DescribeArg+{marglist} csv list of mandatory args.
232 \end{Args+}
233 \end{Macros}
234
235 \begin{Macros}{\DescribeArg,\DescribeKey,\DescribeValue,\DescribeOption,\DescribePackage,}
236 \begin{Syntax}%
237 \Macro{\DescribeArg}<*+>[type]{arg}
238 \Macro{\DescribeKey}<*+>[type]{arg}
239 \Macro{\DescribeValue}<*+>[type]{arg}
240 \Macro{\DescribeOption}<*+>[type]{arg}
241 \Macro{\DescribePackage}<*+>[type]{arg}
242 \end{Syntax}
243 \begin{Args+}
244 \DescribeKey+{*} typesets it in bold face.
245 \DescribeKey+{+} typesets in text (not in marginpar)
246 \DescribeArg+{type} key/arg/... format
247 \DescribeArg+{arg} key/arg/... name.
248 \end{Args+}
249 \end{Macros}
250
251
252 \subsection{Macros Typeset}
253 \begin{Macros}{\Macro}
254 \begin{Syntax}%
255 \Macro!{\Macro}{\marg{csname}\xarg{embl}\oarg{olist}\marg{mlist}}
256 \Macro!{\Macro}<!>{\marg{csname}\xarg{embl}\marg{par.desc.}}
257 \end{Syntax}
258 When describing a macro \Arg{csname} (Command Sequence, csname) the \Arg{olist} and \Arg{mlist} are comma separated lists (csv) of optional and mandatory arguments. \Arg{embl} are optional, single char, 'embellishment' tokens, like {\bfseries * ! +}. Finally, in the {\bfseries !} form, the \Arg{par.desc.} is any text representing the macro parameter list (for non regular, non usual, cases).
259
260 \begin{stcode}[st=demoB]
261 \Macro
262 {\Macro}<*!>[opt1,opt2]{arg3}
263 \Macro!
264 {\Macro}<!>{\xarg{embl}\marg{par.desc.}}
265 \end{stcode}
266 \TabbedDemoCode{demoB}
267 \end{Macros}
268
269 \subsection{Args Typeset}
270 \begin{Macros}{\oarg,\marg,\parg,\xarg,\Arg,\Meta}
271 \begin{Syntax}%
272 \Macro{\oarg}[type]{arg}
273 \Macro{\marg}[type]{arg}
274 \Macro{\parg}[type]{arg}
275 \Macro{\xarg}[type]{arg}
276 \Macro{\Arg}[type]{arg}
277 \Macro{\Meta}{arg}
278 \end{Syntax}
279 Those are meant to typeset the diverse kinds of 'command's arguments' (mandatory, optional, parenthesis . . .). \Macro{\Meta{arg}}{} typesets \emph{arg} as \Meta{arg}.
280 \begin{Args}
281 \DescribeArg{type} defaults to \Value{Meta} (it's the csname of any valid formatting command, like Meta, textbf, etc.)
282 \DescribeArg{arg} the argument name itself.
283 \end{Args}
284 \begin{stcode}[st=demoA]
285 \oarg{fam}
286 \parg{xtra}
287 \marg[textbf]{text}
288 \xarg{x-text}
289 \end{stcode}
290 \TabbedDemoCode{demoA}
291 \end{Macros}
292
293 \subsection{Keys Typeset}
294 \begin{Macros}{\Key,\Keylst,\KeyUse}
295 \begin{Syntax}%
296 \Macro{\Key}[pre]{key}
297 \Macro{\Keylst}[default]{keylst}
298 \Macro{\KeyUse}{key}{value}
299 \end{Syntax}
300 To typeset a \Arg{Key} or \Arg{keylst} (csv list). \Arg{pre} is just prepended to \Arg{key} whilst \Arg{default} is the default key value. \Macro{\KeyUse}{} is just a short-cut for a, possible, common construction.
301
302 \begin{stcode}[st=demoC]
303 \Key{Akey}
304
305 \Keylst[Bkey]{Akey,Bkey}
306
307 \KeyUse{keyA}{arg}
308 \end{stcode}
309 \TabbedDemoCode{demoC}
310
311 \end{Macros}
312
313 \begin{Macros}{\Env,\Pack,\Value}
314 \begin{Syntax}%
315 \Macro{\Env}[pre]{key}
316 \Macro{\Pack}[pre]{key}
317 \Macro{\Value}[pre]{key}
318 \end{Syntax}
319 Similar to \Macro{\Key}{} above, they will typeset a \Arg{Key}. \Arg{pre} is just prepended to \Arg{key} whilst \Arg{default} is the default key value.
320
321
322 \end{Macros}
323
324
325 \subsection{Others}
326 \begin{Macros}{\MetaFmt}
327 \begin{Syntax}%
328 \Macro{\MetaFmt}<*>[type]{}
329 \end{Syntax}
330 It sets the font size, series, face as defined by \Meta{type}, \Meta{type} being one of \Keylst{Oarg,Marg,Parg,Xarg,Macro,Code,Key,KeyVal,Option,Value,Default}. The star version uses bold.
331 \end{Macros}
332
333
334 \begin{Macros}{\MarginNote}
335 \begin{Syntax}%
336 \Macro{\MarginNote}{text}
337 \end{Syntax}
338 As the name implies, to add small margin notes.
339 \end{Macros}
340
341
342 \begin{Macros}{\dcAuthor,\dcDate,\dcTitle,\dcMakeTitle}
343 \begin{Syntax}%
344 \Macro{\dcAuthor}{name}
345 \Macro{\dcDate}{date}
346 \Macro{\dcTitle}{title}
347 \Macro{\dcMakeTitle}{}
348 \end{Syntax}
349 Those allow one to define (as in standard article, book, report classes) the document \emph{author}, \emph{date} and \emph{date} \Macro{\dcMakeTitle}{} will write a typical title+author heading (as in the article class).
350 \end{Macros}
351
352 \begin{Envs}{dcAbstract}
353 \begin{Syntax}%
354 \Macro{\begin{dcAbstract}}{} \Macro{\end{dcAbstract}}{}
355 \end{Syntax}
356 Same as above, for the abstract.
357 \end{Envs}
358
359
360
361
362 \end{document}