4. Distributing a Document into Several Files

In GAPDoc there are facilities to distribute a document into several files. This is for example interesting, if one wants to store the documentation of some code in the same file as the code itself. Or, if one just wants to store chapters of a document in separate files. Basically, there is only a set of conventions how this is done and some tools to collect the text for further processing.

4.1 The Conventions

Pieces of documentation that shall be incorporated into another document are marked as follows:


##  <#GAPDoc Label="MyPiece">
##  <E>This</E> is the piece.
##  The hash characters are removed.
##  <#/GAPDoc>

This piece is then included into another file by a statement like: <#Include Label="MyPiece"> Here are the exact rules, how pieces are gathered:

Having stored a list of labels and pieces of text gathered as above this can be used as follows.

Here is another example:


# # <#GAPDoc Label="AnotherPiece">  some characters
# # This text is not indented.
#  This text is indented by one blank.
#Not indented.
#<#/GAPDoc>

replaces <#Include Label="AnotherPiece"> by


This text is not indented.
 This text is indented by one blank. 
Not indented.

Since these rules are very simple it is quite easy to write a program in almost any programming language which does this gathering of text pieces and the substitutions. In GAPDoc there is the GAP function ComposedXMLString (4.2-1) which does this.

Note that the XML-tag-like markup we have used here is not a legal XML markup, since the hash character is not allowed in element names. The mechanism described here is a preprocessing step which composes an XML document.

4.2 A Tool for Collecting a Document

4.2-1 ComposedXMLString
> ComposedXMLString( path, main, source )( function )

Returns: XML document as string

This function returns a string containing a GAPDoc XML document constructed from several source files.

Here path must be a path to some directory (as string or directory object), main the name of a file in this directory and source a list of file names, all of these relative to path. The document is constructed via the mechanism described in Section 4.1.

First the files given in source are scanned for chunks of GAPDoc-documentation marked by <#GAPDoc Label="..."> and pairs. Then the file main is read and all <#Include ... >-tags are substituted recursively by other files or chunks of documentation found in the first step, respectively.


gap> doc := ComposedXMLString("/my/dir", "manual.xml", 
> ["../lib/func.gd", "../lib/func.gi"]);;




generated by GAPDoc2HTML