Goto Chapter: Top 1 2 3 4 Bib Ind
 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 

3 AutoDoc documentation comments
 3.1 Documenting declarations
 3.2 Other documentation comments
 3.3 Title page commands
 3.4 Plain text files
 3.5 Grouping
 3.6 Markdown-like formatting of text in AutoDoc
 3.7 Deprecated commands

3 AutoDoc documentation comments

You can document declarations of global functions and variables, operations, attributes etc. by inserting AutoDoc comments into your sources before these declarations. An AutoDoc comment always starts with #!. This is also the smallest possible AutoDoc command. If you want your declaration documented, just write #! at the line before the documentation. For example:

#!
DeclareOperation( "AnOperation",
                  [ IsList ] );

This will produce a manual entry for the operation AnOperation.

For declaration documentation, the associated declaration must appear immediately after the AutoDoc comment block. In particular, do not insert other code (such as if false then or assignments) between the comment block and the Declare... statement.

This also works for InstallMethod and InstallOtherMethod. In that case, AutoDoc uses the installed method's name and filter list to create a manual entry for the implemented item.

Inside of AutoDoc comments, AutoDoc commands starting with @ can be used to control the output AutoDoc produces. Any comment line that does not start with an AutoDoc command is treated as regular documentation text and may contain (almost) arbitrary GAPDoc XML markup, such as <Ref>, <A>, <List>, and similar tags. This lets you use the normal GAPDoc formatting toolbox directly inside AutoDoc comments.

For example:

#! @Description
#!  See <Ref Chap="Chapter_Tutorials"/> for setup details.
#!  The argument <A>obj</A> must satisfy <K>IsObject</K>.

As explained in chapter 1, you can combine AutoDoc comments with hand-written XML and classic GAPDoc comments. For practical setup and migration workflows, see chapter 2.

3.1 Documenting declarations

In the bare form above, the manual entry for AnOperation will not contain much more than the name of the operation. In order to change this, there are several commands you can put into the AutoDoc comment before the declaration. Currently, the following commands are provided:

3.1-1 @Description descr

Adds the text in the following lines of the AutoDoc to the description of the declaration in the manual. Lines are until the next AutoDoc command or until the declaration is reached.

3.1-2 @Returns ret val

The string ret_val is added to the documentation, with the text Returns: put in front of it. This should usually give a brief hint about the type or meaning of the value returned by the documented function.

3.1-3 @Arguments args

The string args contains a description of the arguments the function expects, including optional parts, which are denoted by square brackets. The argument names can be separated by whitespace, commas or square brackets for the optional arguments, like grp[, elm] or xx[y[z] ]. If GAP options are used, this can be followed by a colon : and one or more assignments, like n[, r]: tries := 100.

For DeclareGlobalName, using @Arguments or @Returns also makes AutoDoc document the item as a function. This is useful because DeclareGlobalName itself does not reveal whether the name denotes a function or a variable.

3.1-4 @ItemType kind

Overrides the kind of manual item created for the following declaration or installed method. The supported values are Attr, Cat, Coll, Constr, Fam, Filt, Func, InfoClass, Meth, Oper, Prop, Repr, and Var.

The values Cat, Coll, and Repr are AutoDoc-specific aliases. They emit Filt entries with the corresponding GAPDoc filter type.

This is useful when the source code alone does not determine which manual item kind should be emitted. For many declarations such as DeclareAttribute or DeclareProperty, AutoDoc already knows the intended type from the declaration itself.

It is useful for DeclareGlobalName, because that declaration can refer to either a function or a variable. AutoDoc defaults such entries to Var, but switches to Func as soon as @Arguments or @Returns indicates function-style documentation. You can still use @ItemType to override this explicitly.

It is useful for DeclareSynonym, because that declaration can document a function synonym or one of several filter-like synonyms. Use @ItemType Filt, Cat, Coll, or Repr to control which kind of filter entry should be emitted.

For example:

#! @ItemType Repr
DeclareSynonym( "IsSomethingRep", IsComponentObjectRep );

This makes AutoDoc emit a <Filt Type="Representation" .../> manual entry.

3.1-5 @Group grpname

Adds the following method to a group with the given name. See section 3.5 for more information about groups.

3.1-6 @Label label

Adds label to the function as label.

If this is not specified, then for declarations that involve a list of input filters (as is the case for DeclareOperation, DeclareAttribute, etc.), a default label is generated from this filter list.

#! @Label testlabel
DeclareProperty( "AProperty",
                 IsObject );

leads to this:

<ManSection>
  <Prop Arg="arg" Name="AProperty" Label="testlabel"/>
 <Returns> <K>true</K> or <K>false</K>
</Returns>
 <Description>
 </Description>
</ManSection>

while

#!
DeclareProperty( "AProperty",
                 IsObject );

leads to this:

<ManSection>
  <Prop Arg="arg" Name="AProperty" Label="for IsObject"/>
 <Returns> <K>true</K> or <K>false</K>
</Returns>
 <Description>
 </Description>
</ManSection>

3.1-7 @ChapterInfo chapter, section

Adds the entry to the given chapter and section. Here, chapter and section are the respective titles. As an example, a full AutoDoc comment with all options could look like this:

#! @Description
#! Computes the list of lists of degrees of ordinary characters
#! associated to the $p$-blocks of the group $G$
#! with $p$-modular character table <A>modtbl</A>
#! and underlying ordinary character table `ordtbl`.
#! @Returns a list
#! @Arguments modtbl
#! @Group CharacterDegreesOfBlocks
#! @Label chardegblocks
#! @ChapterInfo Blocks, Attributes
DeclareAttribute( "CharacterDegreesOfBlocks",
        IsBrauerTable );

3.2 Other documentation comments

There are also some commands which can be used in AutoDoc comments that are not associated to any declaration. This is useful for additional text in your documentation, examples, mathematical chapters, etc.

3.2-1 @Chapter name

Sets the active chapter, all subsequent functions which do not have an explicit chapter declared in their AutoDoc comment via @ChapterInfo will be added to this chapter. Also all text comments, i.e. lines that begin with #! without a command, and which do not follow after @Description, will be added to the chapter as regular text. Additionally, the chapters label will be set to Chapter_name.

Example:

#! @Chapter My chapter
#!  This is my chapter.
#!  I document my stuff in it.

The @ChapterLabel label command can be used to set the label of the chapter to Chapter_label instead of Chapter_name.

Additionally, the chapter will be stored as _Chapter_label.xml.

The @ChapterTitle title command can be used to set a heading for the chapter that is different from name. Note that the title does not affect the label.

If you use all three commands, i.e.,

#! @Chapter name
#! @ChapterLabel label
#! @ChapterTitle title

title is used for the headline, label for cross-referencing, and name for setting the same chapter as active chapter again.

3.2-2 @Appendix name

This is analogous to @Chapter, but generates Appendix elements instead of Chapter elements. When scaffolding generates the main XML file, appendices created this way are included automatically after any files listed in scaffold.appendix.

Example:

@Appendix Supplementary material

@Section Additional tables

3.2-3 @Section name

Sets an active section like @Chapter sets an active chapter. The section automatically ends with the next @Section or @Chapter command.

#! @Section My first manual section
#!  In this section I am going to document my first method.

The @SectionLabel label command can be used to set the label of the section to Section_label instead of Chapter_chaptername_Section_name.

The @SectionTitle title command can be used to set a heading for the section that is different from name.

3.2-4 @Subsection name

Sets an active subsection like @Section sets an active section. The subsection automatically ends with the next @Subsection, @Section or @Chapter command. It also ends with the next documented function. Indeed, internally each function manpage is treated like a subsection.

#! @Subsection My first manual subsection
#!  In this subsection I am going to document my first example.

The @SubsectionLabel label command can be used to set the label of the subsection to Subsection_label instead of Chapter_chaptername_Section_sectionname_Subsection_name.

The @SubsectionTitle title command can be used to set a heading for the subsection that is different from name.

3.2-5 @BeginGroup [grpname]

Starts a group. All following documented declarations without an explicit @Group command are grouped together in the same group with the given name. If no name is given, then a new nameless group is generated. The effect of this command is ended when an @EndGroup command is reached.

See section 3.5 for more information about groups.

3.2-6 @EndGroup

Ends the current group.

#! @BeginGroup MyGroup
#!
DeclareAttribute( "GroupedAttribute",
                  IsList );

DeclareOperation( "NonGroupedOperation",
                  [ IsObject ] );

#!
DeclareOperation( "GroupedOperation",
                  [ IsList, IsRubbish ] );
#! @EndGroup

3.2-7 @GroupTitle title

Sets the subsection heading for the current group to title. In the absence of any @GroupTitle command, the heading will be the name of the first entry in the group. See 3.5 for more information.

3.2-8 @BeginExample and @EndExample

@BeginExample marks the start of an example to be put into the manual. It differs from GAPDoc's <Example> (see GAPDoc: Log), in that it expects actual code (not in a comment) interspersed with comments, to allow for examples files that can be both executed by GAP, and parsed by AutoDoc. To achieve this, GAP commands are not preceded by a comment, while output has to be preceded by an AutoDoc comment. The gap> prompt for the display in the manual is added by AutoDoc. @EndExample ends the example block.

To illustrate this command, consider this input:

#! @BeginExample
S5 := SymmetricGroup(5);
#! Sym( [ 1 .. 5 ] )
Order(S5);
#! 120
#! @EndExample

This results in the following output:

gap> S5 := SymmetricGroup(5);
Sym( [ 1 .. 5 ] )
gap> Order(S5);
120

The AutoDoc command @Example is an alias of @BeginExample. If you enable extract_examples := true when calling AutoDoc (4.2-1), these examples can also be turned into .tst files (see Section 2.4-1).

3.2-9 @BeginExampleSession and @EndExampleSession

@BeginExampleSession marks the start of an example to be put into the manual, while @EndExampleSession ends the example block. It is the direct analog of GAPDoc's <Example> (see GAPDoc: Log).

To illustrate this command, consider this input:

#! @BeginExampleSession
#! gap> S5 := SymmetricGroup(5);
#! Sym( [ 1 .. 5 ] )
#! gap> Order(S5);
#! 120
#! @EndExampleSession

This results in the following output:

gap> S5 := SymmetricGroup(5);
Sym( [ 1 .. 5 ] )
gap> Order(S5);
120

It inserts an example into the manual just as @Example would do, but all lines are commented and therefore not executed when the file is read. All lines that should be part of the example displayed in the manual have to start with an AutoDoc comment (#!). The comment will be removed, and, if the following character is a space, this space will also be removed. There is never more than one space removed. To ensure examples are correctly colored in the manual, there should be exactly one space between #! and the gap> prompt. The AutoDoc command @ExampleSession is an alias of @BeginExampleSession.

3.2-10 @BeginLog and @EndLog

Works just like the @BeginExample command, but the example will not be tested. See the GAPDoc manual for more information. The AutoDoc command @Log is an alias of @BeginLog.

3.2-11 @BeginLogSession and @EndLogSession

Works just like the @BeginExampleSession command, but the example will not be tested if manual examples are run. It is the direct analog of GAPDoc's <Log> (see GAPDoc: Log). The AutoDoc command @LogSession is an alias of @BeginLogSession.

3.2-12 @DoNotReadRestOfFile

Prevents the rest of the file from being read by the parser. Useful for unfinished or temporary files.

#! This will appear in the manual

#! @DoNotReadRestOfFile

#! This will not appear in the manual.

3.2-13 @BeginChunk name, @EndChunk, and @InsertChunk name

Text inside a @BeginChunk / @EndChunk part will not be inserted into the final documentation directly. Instead, the text is stored in an internal buffer.

That chunk of text can then later on be inserted in any other place by using the @InsertChunk name command.

If you do not provide an @EndChunk, the chunk ends at the end of the file.

#! @BeginChunk MyChunk
#! Hello, world.
#! @EndChunk

#! @InsertChunk MyChunk
## The text "Hello, world." is inserted right before this.

You can use this to define an example like this in one file:

#! @BeginChunk Example_Symmetric_Group
#! @BeginExample
S5 := SymmetricGroup(5);
#! Sym( [ 1 .. 5 ] )
Order(S5);
#! 120
#! @EndExample
#! @EndChunk

And then later, insert the example in a different file, like this:

#! @InsertChunk Example_Symmetric_Group

3.2-14 @BeginCode name, @EndCode, and @InsertCode name

Inserts the text between @BeginCode and @EndCode verbatim at the point where @InsertCode is called. This is useful to insert code excerpts directly into the manual.

#! @BeginCode Increment
i := i + 1;
#! @EndCode

#! @InsertCode Increment
## Code is inserted here.

3.2-15 @LatexOnly text, @BeginLatexOnly, and @EndLatexOnly

Code inserted between @BeginLatexOnly and @EndLatexOnly or after @LatexOnly is only inserted in the PDF version of the manual or worksheet. It can hold arbitrary LaTeX-commands.

#! @BeginLatexOnly
#! \include{picture.tex}
#! @EndLatexOnly

#! @LatexOnly \include{picture.tex}

3.2-16 @NotLatex text, @BeginNotLatex, and @EndNotLatex

Code inserted between @BeginNotLatex and @EndNotLatex or after @NotLatex is inserted in the HTML and text versions of the manual or worksheet, but not in the PDF version.

#! @BeginNotLatex
#! For further information see the PDF version of this manual.
#! @EndNotLatex

#! @NotLatex For further information see the PDF version of this manual.

3.2-17 @Index key [entry text]

Adds an index entry to the current documentation text. The command @Index key entry text generates <Index Key="key">entry text</Index>. If no entry text is provided, then the entry text is empty. To use keys containing spaces, wrap the key in double quotes, e.g. @Index "my key" entry text. The entry text is processed like normal documentation text, so markdown-like inline code such as true is supported.

3.3 Title page commands

The following commands can be used to add corresponding parts to the title page of a document generated by AutoDoc.

Many of these values can (and for package manuals typically should) be extracted from PackageInfo.g. If you set them explicitly in comments, they override extracted or scaffold-defined values. This is usually most useful for worksheets created with AutoDocWorksheet (4.1-1), since worksheets do not have a PackageInfo.g file from which this information could be extracted.

3.4 Plain text files

Files that have the suffix .autodoc and are listed in the autodoc.files option of AutoDoc (4.2-1), resp. are contained in one of the directories listed in autodoc.scan_dirs or one of their subdirectories, are treated as standalone AutoDoc input files. They are meant for manual text that does not belong next to a single declaration: chapters, sections, tutorials, worked examples, index entries, chunks, title-page metadata, and similar prose-heavy material.

Conceptually, a .autodoc file uses the same parser as AutoDoc comments, but without the comment marker. In a .autodoc file, lines do not need to start with #! and in fact usually should not. This makes .autodoc files one convenient way to replace hand-written XML chapters when you prefer AutoDoc's command syntax and Markdown-like text features. However, it is not the only supported style: chapter and section commands inside source comments remain fully supported, and AutoDoc itself still uses that style in files such as gap/Magic.gd. For the surrounding workflow, see Chapter 2.

The most important difference from declaration comments is that a plain text file does not document a declaration by adjacency. There is no following Declare... or InstallMethod statement for AutoDoc to inspect. So commands whose meaning depends on such a declaration only make sense in source comments immediately before that declaration.

In practice, this gives the following rule of thumb.

As a concrete example, the following file can serve as a complete chapter written in .autodoc format.

@Chapter Test
@Section First Section
@Subsection First Subsection

This text belongs directly to the manual chapter.
It can use XML tags such as <A>arg</A> or <Ref .../>.

@BeginExampleSession
gap> S5 := SymmetricGroup(5);
Sym( [ 1 .. 5 ] )
gap> Size(S5);
120
@EndExampleSession

@Index "Worksheet Autoplain" Plain worksheet index entry with `true`

This is essentially the style used in the worksheet fixture tst/worksheets/autoplain.sheet/plain.autodoc.

The same structural commands can also be used inside source comments, for example:

#! @Chapter Reference
#! @Section The AutoDoc() function
#! Some introductory text for this section.

This source-comment style is still fully supported and is used in gap/Magic.gd.

The mixed-workflow case is equally common. Suppose an existing manual still has a hand-written main XML file and perhaps some hand-written XML chapters. Then you can keep those files, include _AutoDocMainFile.xml from the main XML file as described in Chapter 2, and add one or more .autodoc files via autodoc.files or autodoc.scan_dirs. Those files can provide tutorial chapters or appendices, while declaration documentation continues to live in source comments and older XML chapters remain unchanged.

One caveat is worth keeping in mind. If you want a standalone .autodoc file to pause and resume around declaration documentation that is written in source comments, the current workaround is to use chunks. That interleaving workflow is currently limited; see issue #60 in the AutoDoc issue tracker.

So, while .autodoc files and source comments share most of the same text syntax, they can be combined freely. The main distinction is simply that declaration-bound commands attach metadata to a following declaration, while standalone manual text can live wherever you find it most convenient.

3.5 Grouping

In GAPDoc, it is possible to make groups of manual items, i.e., when documenting a function, operation, etc., it is possible to group them into suitable chunks. This can be particularly useful if there are several definitions of an operation with several different argument types, all doing more or less the same to the arguments. Then their manual items can be grouped, sharing the same description and return type information. You can give a heading to the group in the manual with the @GroupTitle command; if that is not supplied, then the heading of the first manual item in the group will be used as the heading.

Note that group names are globally unique throughout the whole manual. That is, groups with the same name are in fact merged into a single group, even if they were declared in different source files. Thus you can have multiple @BeginGroup / @EndGroup pairs using the same group name, in different places, and these all will refer to the same group.

Moreover, this means that you can add items to a group via the @Group command in the AutoDoc comment of an arbitrary declaration, at any time.

The following code

#! @BeginGroup Group1
#! @GroupTitle A family of operations

#! @Description
#!  First sentence.
DeclareOperation( "FirstOperation", [ IsInt ] );

#! @Description
#!  Second sentence.
DeclareOperation( "SecondOperation", [ IsInt, IsGroup ] );

#! @EndGroup

## .. Stuff ..

#! @Description
#!  Third sentence.
#! @Group Group1
KeyDependentOperation( "ThirdOperation", IsGroup, IsInt, "prime );

produces the following:

<ManSection Label="Group1">
<Heading>A family of operations</Heading>
  <Oper Arg="arg" Name="FirstOperation" Label="for IsInt"/>
  <Oper Arg="arg1,arg2" Name="SecondOperation" Label="for IsInt, IsGroup"/>
  <Oper Arg="arg1,arg2" Name="ThirdOperation" Label="for IsGroup, IsInt"/>
 <Description>
First sentence.
Second sentence.
Third sentence.
 </Description>
</ManSection>

3.6 Markdown-like formatting of text in AutoDoc

AutoDoc has some convenient ways to insert special format into text, like math formulas and lists. The syntax for them are inspired by Markdown and LaTeX, but do not follow them strictly. Neither are all features of the Markdown language supported. The following subsections describe what is possible.

3.6-1 Lists

One can create lists of items by beginning a new line with *, +, -, followed by one space. The first item starts the list. When items are longer than one line, the following lines have to be indented by at least two spaces. The list ends when a line which does not start a new item is not indented by two spaces. Of course lists can be nested. Here is an example:

#! The list starts in the next line
#! * item 1
#! * item 2
#!   which is a bit longer
#!   * and also contains a nested list
#!   * with two items
#! * item 3 of the outer list
#! This does not belong to the list anymore.

This is the output:
The list starts in the next line

This does not belong to the list anymore.

The *, -, and + are fully interchangeable and can even be used mixed, but this is not recommended.

3.6-2 Math modes

One can start an inline formula with a $, and also end it with $, just like in LaTeX. This will translate into GAPDocs inline math environment. For display mode one can use $$, also like LaTeX.

#! This is an inline formula: $1+1 = 2$.
#! This is a display formula:
#! $$ \sum_{i=1}^n i. $$

produces the following output:
This is an inline formula: \(1+1 = 2\). This is a display formula:

\[ \sum_{i=1}^n i. \]

3.6-3 Emphasize

One can emphasize text by using two asterisks (**) or two underscores (__) at the beginning and the end of the text which should be emphasized. Example:

#! **This** is very important.
#! This is __also important__.
#! **Naturally, more than one line
#! can be important.**

This produces the following output:
This is very important. This is also important. Naturally, more than one line can be important.

3.6-4 Inline code

One can mark inline code snippets by using backticks (`) at the beginning and the end of the text which should be marked as code. Example:

#! Call function `foobar()` at the start.

This produces the following output:
Call function foobar() at the start.

3.6-5 Fenced code blocks

One can insert verbatim code blocks by placing the code between lines containing at least three backticks or at least three tildes. The opening fence may optionally be followed by an info string. The values @listing, @example, and @log select the corresponding GAPDoc element; any other value is currently ignored. If nothing is specified the default is to generate <Listing>. Example:

#! ```@listing
#! if x = 2 then
#!   Print("1 + 1 = 2 holds, all is good\n");
#! fi;
#! ```
#! ~~~@example
#! gap> [ 1 .. 3 ] ^ 2;
#! [ 1, 4, 9 ]
#! ~~~
#! ```@log
#! #I  some log message
#! ```

This produces the following output:

if x = 2 then
  Print("1 + 1 = 2 holds, all is good\n");
fi;
gap> [ 1 .. 3 ] ^ 2;
[ 1, 4, 9 ]
#I  some log message

3.7 Deprecated commands

The following commands used to be supported, but are not supported anymore.

@EndSection

You can simply remove any use of this, AutoDoc ends sections automatically at the start of any new section or chapter.

@EndSubsection

You can simply remove any use of this, AutoDoc ends subsections automatically at the start of any new subsection, section or chapter.

@BeginAutoDoc and @EndAutoDoc

It suffices to prepend each declaration that is meant to appear in the manual with a minimal AutoDoc comment #!.

@BeginSystem name, @EndSystem, and @InsertSystem name

Please use the chunk commands from subsection 3.2-13 instead.

@AutoDocPlainText and @EndAutoDocPlainText

Use .autodoc files or AutoDoc comments instead.

 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 
Goto Chapter: Top 1 2 3 4 Bib Ind

generated by GAPDoc2HTML