CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418346
1
<Chapter Label="Tutorials">
2
<Heading>Getting started using &AutoDoc;</Heading>
3
4
&AutoDoc; is a &GAP; package which is meant to aid &GAP; package
5
authors in creating and maintaining the documentation of their packages.
6
In this capacity it builds upon &GAPDoc;, and is not a replacement
7
for &GAPDoc;, but rather complements it.<P/>
8
9
In this chapter we describe how to get started using &AutoDoc; for your
10
package. First, we explain in Section <Ref Sect="Tut:Scratch"/> how to write a
11
new package manual from scratch.<P/>
12
13
Then we show in Section <Ref Sect="Tut:IntegrateExisting"/> how you might
14
benefit from &AutoDoc; even if you already have a complete manual written
15
using &GAPDoc;.<P/>
16
17
In Section <Ref Sect="Tut:Scaffolds"/>, we explain how you may use &AutoDoc;
18
to generate a title page and the main XML file for your manual.
19
<P/>
20
21
Finally, Section <Ref Sect="Tut:AutoDocWorksheet"/>, explains what
22
&AutoDoc; worksheets are and how to use them.
23
<P/>
24
25
<Section Label="Tut:Scratch">
26
<Heading>Creating a package manual from scratch</Heading>
27
28
Suppose your package is already up and running, but so far has no
29
manual. Then you can rapidly generate a <Q>scaffold</Q> for a package manual
30
using the <Ref Func="AutoDoc"/> command like this,
31
while running &GAP; from within your package's directory (the
32
one containing the <F>PackageInfo.g</F> file):
33
<Listing>
34
LoadPackage( "AutoDoc" );
35
AutoDoc( rec( scaffold := true ) );
36
</Listing>
37
This first reads the <F>PackageInfo.g</F> file from the current
38
directory. It extracts information about package from it
39
(such as its name and version, see Section <Ref Sect="Tut:Scaffolds:Title"/>).
40
It then creates two XML files <F>doc/NAME_OF_YOUR_PACKAGE.xml</F> and
41
<F>doc/title.xml</F> insider the package directory. Finally, it runs
42
&GAPDoc; on them to produce a nice initial PDF and HTML version of your
43
fresh manual.
44
<P/>
45
46
To ensure that the &GAP; help system picks up your package manual, you
47
should also add something like the following to your
48
<F>PackageInfo.g</F>:
49
<Listing>
50
PackageDoc := rec(
51
BookName := ~.PackageName,
52
ArchiveURLSubset := ["doc"],
53
HTMLStart := "doc/chap0.html",
54
PDFFile := "doc/manual.pdf",
55
SixFile := "doc/manual.six",
56
LongTitle := ~.Subtitle,
57
),
58
</Listing>
59
60
Congratulations, your package now has a minimal working manual. Of
61
course it will be mostly empty for now, but it already should contain
62
some useful information, based on the data in your <F>PackageInfo.g</F>.
63
This includes your package's name, version and description as well as
64
information about its authors. And if you ever change the package data,
65
(e.g. because your email address changed), just re-run the above command
66
to regenerate the two main XML files with the latest information.
67
<P/>
68
69
Next of course you need to provide actual content (unfortunately, we were
70
not yet able to automate <E>that</E> for you, more research on artificial intelligence
71
is required).
72
To add more content, you have several options: You could add further &GAPDoc;
73
XML files containing extra chapters, sections and so on. Or you could use classic &GAPDoc;
74
source comments (in either case, see Section <Ref Sect="Tut:IntegrateExisting"/> on
75
how to teach the <Ref Func="AutoDoc"/> command to include this extra documentation).
76
Or you could use the special documentation facilities &AutoDoc; provides (see Section
77
<Ref Sect="Tut:AdvancedAutoDoc"/>).
78
<P/>
79
80
You will probably want to re-run the <Ref Func="AutoDoc"/> command
81
frequently, e.g. whenever you modified your documentation or your
82
<F>PackageInfo.g</F>. To make this more convenient and reproducible, we
83
recommend putting its invocation into a file <F>makedoc.g</F> in your package
84
<Index Key="makedoc.g"><F>makedoc.g</F></Index>
85
directory, with content based on the following example:
86
<Listing>
87
LoadPackage( "AutoDoc" );
88
AutoDoc( rec( autodoc := true ) );
89
QUIT;
90
</Listing>
91
Then you can regenerate the package manual from the command line with the
92
following command, executed from within in the package directory:
93
<Listing>
94
gap makedoc.g
95
</Listing>
96
97
</Section>
98
99
100
<Section Label="Tut:AdvancedAutoDoc">
101
<Heading>Documenting code with &AutoDoc;</Heading>
102
103
To get one of your global functions, operations, attributes
104
etc. to appear in the package manual, simply insert an &AutoDoc; comment
105
of the form <C>#!</C> directly in front of it. For example:
106
<Listing>
107
#!
108
DeclareOperation( "ToricVariety", [ IsConvexObject ] );
109
</Listing>
110
111
This tiny change is already sufficient to ensure that the operation
112
appears in the manual. In general, you will want to add further
113
information about the operation, such as in the following example:
114
115
<Listing><![CDATA[
116
#! @Arguments conv
117
#! @Returns a toric variety
118
#! @Description
119
#! Creates a toric variety out
120
#! of the convex object <A>conv</A>.
121
DeclareOperation( "ToricVariety", [ IsConvexObject ] );
122
]]></Listing>
123
124
For a thorough description of what you can do with &AutoDoc;
125
documentation comments, please refer to chapter <Ref Chap="Comments"/>.
126
<P/>
127
128
<!--
129
Once we switched AutoDoc itself to use AutoDoc comments,
130
mention that, i.e. point out that all operations and functions
131
documented in this manual are documented exactly like
132
described here, and that one can hence use that as examples.
133
-->
134
135
<!--
136
137
# <#GAPDoc Label="ToricVarietyConst">
138
# <ManSection>
139
# <Oper Arg="conv" Name="ToricVariety"
140
# Label="for IsConvexObject"/>
141
# <Returns>a toric variety</Returns>
142
# <Description>
143
# Creates a toric variety out
144
# of the convex object <A>conv</A>.
145
# </Description>
146
# </ManSection>
147
# <#/GAPDoc>
148
DeclareOperation( "ToricVariety",
149
[ IsConvexObject ] );
150
-->
151
152
153
Suppose you have not been using &GAPDoc; before but instead used the process
154
described in section <Ref Sect="Tut:Scratch"/> to create your manual.
155
Then the following &GAP; command will regenerate the manual and automatically
156
include all newly documented functions, operations etc.:
157
158
<Listing>
159
LoadPackage( "AutoDoc" );
160
AutoDoc( rec( scaffold := true,
161
autodoc := true ) );
162
</Listing>
163
164
If you are not using the scaffolding feature, e.g. because you already
165
have an existing &GAPDoc; based manual, then you can still use &AutoDoc;
166
documentation comments. Just make sure to first edit the main XML
167
file of your documentation, and insert the line
168
<Listing>
169
#Include SYSTEM "_AutoDocMainFile.xml"
170
</Listing>
171
in a suitable place. This means that you can mix &AutoDoc; documentation
172
comment freely with your existing documentation; you can even still make
173
use of any existing &GAPDoc; documentation comments in your code.
174
175
The following command should be useful for you in this case; it
176
still scans the package code for &AutoDoc; documentation comments
177
and the runs &GAPDoc; to produce HTML and PDF output, but does not
178
touch your documentation XML files otherwise.
179
<Listing>
180
LoadPackage( "AutoDoc" );
181
AutoDoc( rec( autodoc := true ) );
182
</Listing>
183
184
185
</Section>
186
187
188
<Section Label="Tut:IntegrateExisting">
189
<Heading>Using &AutoDoc; in an existing &GAPDoc; manual</Heading>
190
191
Even if you already have an existing &GAPDoc; manual, it might be
192
interesting for you to use &AutoDoc; for two purposes:
193
<P/>
194
195
First off, with &AutoDoc; is very convenient to regenerate your
196
documentation.
197
<P/>
198
199
Secondly, the scaffolding feature which generates a title package
200
with all the metadata of your package in a uniform way is very
201
handy. The somewhat tedious process of keeping your title page in
202
sync with your <F>PackageInfo.g</F> is fully automated this way
203
(including the correct version, release data, author information
204
and so on).
205
<P/>
206
207
There are various examples of packages using &AutoDoc; for only
208
this purpose, e.g. <Package>IO</Package> and <Package>orb</Package>.
209
<P/>
210
211
<Subsection Label="Tut:IntegrateExisting:EverythingThere">
212
<Heading>Using &AutoDoc; on a complete &GAPDoc; manual</Heading>
213
214
Suppose you already have a complete XML manual, with some main and title
215
XML files and some documentation for operations distributed over
216
all your <F>.g</F>, <F>.gd</F>, and <F>.gi</F> files.
217
Suppose the main XML file is named <F>PACKAGENAME.xml</F> and is in the
218
<F>/doc</F> subfolder of your package. Then you can rebuild your manual
219
by executing the following two GAP commands from a GAP sessions started
220
started in the root directory of your package:
221
<Listing>
222
LoadPackage( "AutoDoc" );
223
AutoDoc( );
224
</Listing>
225
In contrast, the <Package>RingsForHomalg</Package> currently uses
226
essentially the following code in its <F>makedoc.g</F> file to achieve the same result
227
<Listing>
228
LoadPackage( "GAPDoc" );
229
SetGapDocLaTeXOptions( "utf8" );
230
bib := ParseBibFiles( "doc/RingsForHomalg.bib" );
231
WriteBibXMLextFile( "doc/RingsForHomalgBib.xml", bib );
232
list := [
233
"../gap/RingsForHomalg.gd",
234
"../gap/RingsForHomalg.gi",
235
"../gap/Singular.gi",
236
"../gap/SingularBasic.gi",
237
"../examples/RingConstructionsExternalGAP.g",
238
"../examples/RingConstructionsSingular.g",
239
"../examples/RingConstructionsMAGMA.g",
240
"../examples/RingConstructionsMacaulay2.g",
241
"../examples/RingConstructionsSage.g",
242
"../examples/RingConstructionsMaple.g",
243
];
244
MakeGAPDocDoc( "doc", "RingsForHomalg", list, "RingsForHomalg" );
245
GAPDocManualLab( "RingsForHomalg" );
246
</Listing>
247
Note that in particular, you do not have to worry about keeping a list of your
248
implementation files up-to-date.
249
<P/>
250
But there is more. &AutoDoc; can create a <F>maketest.g</F> file, which uses the
251
examples in your manual to test your package. This can be achieved via
252
<Listing>
253
LoadPackage( "AutoDoc" );
254
AutoDoc( rec( maketest := true ) );
255
</Listing>
256
Now the file <F>maketest.g</F> appears in your package directory, and
257
<Listing>
258
gap maketest.g
259
</Listing>
260
test the examples from your manual.
261
</Subsection>
262
263
<Subsection Label="Tut:IntegrateExisting:GapDocOptions">
264
<Heading>Setting different &GAPDoc; options</Heading>
265
266
Sometimes, the default values for the &GAPDoc; command used by &AutoDoc;
267
may not be suitable for your manual.
268
<P/>
269
Suppose your main XML file is <E>not</E> named <F>PACKAGENAME.xml</F>, but rather something else, e.g. <F>main.xml</F>.
270
Then you can tell &AutoDoc; to use this file as the main XML file via
271
<Listing>
272
LoadPackage( "AutoDoc" );
273
AutoDoc( rec( gapdoc := rec( main := "main" ) ) );
274
</Listing>
275
<P/>
276
As explained above, by default &AutoDoc; scans all <F>.g</F>, <F>.gd</F> and <F>.gi</F> files
277
it can find inside of your package root directory, and in the subdirectories <F>gap</F>,
278
<F>lib</F>, <F>examples</F> and <F>examples/doc</F> as well.
279
If you keep source files with documentation in other directories,
280
you can adjust the list of directories AutoDoc scans via the <C>scan_dirs</C> option.
281
The following example illustrates this by instructing &AutoDoc; to only search in the subdirectory <F>package_sources</F>
282
of the packages root directory.
283
<Listing>
284
LoadPackage( "AutoDoc" );
285
AutoDoc( rec( gapdoc := rec( scan_dirs := [ "package_source" ] ) ) );
286
</Listing>
287
You can also specify an explicit list of files containing documentation,
288
which will be searched in addition to any files located within the scan directories:
289
<Listing>
290
LoadPackage( "AutoDoc" );
291
AutoDoc( rec( gapdoc := rec( files := [ "path/to/some/hidden/file.gds" ] ) ) );
292
</Listing>
293
Giving such a file does not prevent the standard <C>scan_dirs</C> from being scanned for
294
other files.
295
<P/>
296
Next, &GAPDoc; supports the documentation to be built with relative paths.
297
This means, links to manuals of other packages or the &GAP; library will
298
not be absolute, but relative from your documentation. This can be particularly useful
299
if you want to build a release tarball or move your &GAP; installation around later.
300
Suppose you are starting &GAP; in the root path of your package as always,
301
and the standard call of <Ref Func="AutoDoc"/> will then build the documentation in the <F>doc</F> subfolder of your package.
302
From this folder, the gap root directory has the relative path <F>../../..</F>.
303
Then you can enable the relative paths by
304
<Listing>
305
LoadPackage( "AutoDoc" );
306
AutoDoc( rec( gapdoc := rec( gap_root_relative_path := "../../.." ) ) );
307
</Listing>
308
or, since <F>../../..</F> is the standard option for <C>gap_root_relative_path</C>, by
309
<Listing>
310
LoadPackage( "AutoDoc" );
311
AutoDoc( rec( gapdoc := rec( gap_root_relative_path := true ) ) );
312
</Listing>
313
314
</Subsection>
315
316
</Section>
317
318
<Section Label="Tut:Scaffolds">
319
<Heading>Scaffolds</Heading>
320
321
<!-- TODO: insert an introduction here -->
322
323
<Subsection Label="Tut:Scaffolds:Title">
324
<Heading>Generating a title page</Heading>
325
326
For most (if not all) &GAP; packages, the title page of the package manual
327
lists information such as the release date, version, names and contact details
328
of the authors, and so on.
329
330
All this data is also contained in your <F>PackageInfo.g</F>, and whenever
331
you make a change to that file, there is a risk that you forget to update
332
your manual to match. And even if you don't forget it, you of course
333
have to spend some time to adjust the manual. &GAPDoc; can help to a degree with
334
this via entities. Thus, you will sometimes see code like this in <F>PackageInfo.g</F>
335
files:
336
<Listing><![CDATA[
337
Version := "1.2.3",
338
Date := "20/01/2015",
339
## <#GAPDoc Label="PKGVERSIONDATA">
340
## <!ENTITY VERSION "1.2.3">
341
## <!ENTITY RELEASEDATE "20 January 2015">
342
## <!ENTITY RELEASEYEAR "2015">
343
## <#/GAPDoc>
344
]]></Listing>
345
However, it is still easy to forget both of these versions. And it doesn't
346
solve the problem of updating package authors addresses. Neither of these is a
347
big issue, of course, but there have been plenty examples in the past where
348
people forget either of these two things, and it can be slightly embarrassing.
349
It may even require you to make a new release just to fix the issue, which in
350
our opinion is a sad waste of your valuable time. <P/>
351
352
So instead of worrying about manually synchronising these things, you can
353
instruct &AutoDoc; to generate a title page for your manual based on the
354
information in your <F>PackageInfo.g</F>. The following commands do just that
355
(in addition to building your manual), by generating a file called
356
<F>doc/title.xml</F>.
357
<Listing>
358
LoadPackage( "AutoDoc" );
359
AutoDoc( rec( scaffold := rec( MainPage := false ) ) );
360
</Listing>
361
Note that this only outputs <F>doc/title.xml</F> but does not
362
touch any other files of your documentation. In particular, you need
363
to explicitly include <F>doc/title.xml</F> from your main XML file.<P/>
364
365
However, you can also tell &AutoDoc; to maintain the main XML file for you,
366
in which case this is automatic. In fact, this is the default if you
367
enabling scaffolding; the above example command explicitly told &AutoDoc;
368
not to generate a main page. More o
369
370
</Subsection>
371
372
<Subsection Label="Tut:Scaffolds:Main">
373
<Heading>Generating the main XML file</Heading>
374
375
The following generates a main XML file for your documentation in
376
addition to the title page. The main XML file includes
377
the title page by default, as well as any documentation generated
378
from &AutoDoc; documentation comments.
379
<Listing>
380
LoadPackage( "AutoDoc" );
381
AutoDoc( rec( scaffold := true ) );
382
</Listing>
383
384
You can instruct &AutoDoc; to include additional XML files by giving it
385
a list of filenames, as in the following example:
386
<Listing>
387
LoadPackage( "AutoDoc" );
388
AutoDoc(rec(
389
scaffold := rec(
390
includes := [ "somefile.xml", "anotherfile.xml" ]
391
)
392
));
393
</Listing>
394
395
For more information, please consult the documentation
396
of the <Ref Func="AutoDoc"/> function.
397
398
399
</Subsection>
400
401
402
<Subsection Label="Tut:PackageInfo">
403
<Heading>What data is extracted from <F>PackageInfo.g</F>?</Heading>
404
405
&AutoDoc; can extract data from <F>PackageInfo.g</F> in order to
406
generate a title page. Specifically, the following components
407
of the package info record are looked at:
408
409
<List>
410
411
<Mark>Version</Mark><Item>
412
This is used to set the <C>&lt;Version></C> element of the
413
title page, with the string <Q>Version </Q> prepended.
414
</Item>
415
416
<Mark>Date</Mark><Item>
417
This is used to set the <C>&lt;Date></C> element of the
418
title page.
419
</Item>
420
421
<Mark>Subtitle</Mark><Item>
422
This is used to set the <C>&lt;Subtitle></C> element of the
423
title page (the <C>&lt;Title></C> is set to the package name).
424
</Item>
425
426
<Mark>Persons</Mark><Item>
427
This is used to generate <C>&lt;Author></C> elements in the
428
generated title page.
429
</Item>
430
431
<Mark>PackageDoc</Mark><Item>
432
This is a record (or a list of records) which is used to tell the
433
&GAP; help system about the package manual. Currently &AutoDoc;
434
extracts the value of the <C>PackageDoc.BookName</C> component
435
and then passes that on to &GAPDoc; when creating the HTML, PDF
436
and text versions of the manual.
437
</Item>
438
439
<Mark>AutoDoc</Mark><Item>
440
This is a record which can be used to control the scaffolding performed by
441
&AutoDoc;, specifically to provide extra information for the title page. For
442
example, you can set <C>AutoDoc.TitlePage.Copyright</C> to a string which will
443
then be inserted on the generated title page. Using this method you can
444
customize the following title page elements: <C>TitleComment</C>,
445
<C>Abstract</C>, <C>Copyright</C>, <C>Acknowledgements</C> and <C>Colophon</C>.
446
447
<P/>
448
Note that <C>AutoDoc.TitlePage</C> behaves exactly the same
449
as the <C>scaffold.TitlePage</C> parameter of the <Ref Func="AutoDoc"/>
450
function.
451
</Item>
452
453
</List>
454
455
</Subsection>
456
457
</Section>
458
459
<Section Label="Tut:AutoDocWorksheet">
460
<Heading>AutoDoc worksheets</Heading>
461
&AutoDoc; worksheets can be used to create HTML and PDF documents using AutoDoc syntax and possibly
462
including &GAP; examples and implementations without having them associated to a package.
463
A file for a worksheet could look like this:
464
<Listing>
465
#! @Title My first worksheet
466
#! @Author Charlie Brown
467
468
#! @Chapter Some groups
469
470
#! @BeginExample
471
S3 := SymmetricGroup( 3 );;
472
S4 := SymmetricGroup( 4 );;
473
#! @EndExample
474
</Listing>
475
Now, one can create a PDF and HTML document, like a package documentation out of it. Suppose the document above
476
is saved as <F>worksheet.g</F>. Then, when GAP is started in the folder of this file, the command
477
<Listing>
478
AutoDocWorksheet( "worksheet.g" );
479
</Listing>
480
will create a subfolder called <F>doc</F> of the current directory in which it will create the documentation.
481
There are several options to configure the output of the worksheet command, which are identical to the
482
options of the <Ref Func="AutoDoc"/> command. It is even possible to test the examples in the worksheet using the maketest option
483
from the AutoDoc command.
484
<P/>
485
Since the worksheets do not have a <F>PackageInfo.g</F> to extract information, all possible tags that &GAPDoc; supports for
486
the title page can be set into the document. A fully typed title page can look like this:
487
<Listing>
488
#! @Title My first worksheet
489
#! @Subtitle Some small examples
490
#! @Author Charlie Brown
491
492
#! @Version 0.1
493
#! @TitleComment Some worksheet
494
#! @Date 01/01/2016
495
#! @Address TU Kaiserslautern
496
#! @Abstract
497
#! A worksheet showing some small examples about groups.
498
#! @Copyright 2016 Charlie Brown
499
#! @Acknowledgements Woodstock
500
#! @Colophon Some colophon
501
502
#! @Chapter Some groups
503
504
#! @BeginExample
505
S3 := SymmetricGroup( 3 );;
506
S4 := SymmetricGroup( 4 );;
507
#! @EndExample
508
</Listing>
509
</Section>
510
</Chapter>
511
512