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
2
4 Distributing a Document into Several Files
3
4
In GAPDoc there are facilities to distribute a single document over several
5
files. This is for example interesting, if one wants to store the
6
documentation of some code in the same file as the code itself. Or, if one
7
just wants to store chapters of a document in separate files. There is a set
8
of conventions how this is done and some tools to collect the text for
9
further processing.
10
11
The technique can also be used to distribute and collect other types of
12
documents into respectively from several files (e.g., source code,
13
examples).
14
15
16
4.1 The Conventions
17
18
In this description we use the string GAPDoc for marking pieces of a
19
document to collect.
20
21
Pieces of documentation that shall be incorporated into another document are
22
marked as follows:
23
24
 Example 
25
## <#GAPDoc Label="MyPiece">
26
## <E>This</E> is the piece.
27
## The hash characters are removed.
28
## <#/GAPDoc>
29

30
31
This piece is then included into another file by a statement like: <#Include
32
Label="MyPiece"> Here are the exact rules, how pieces are gathered:
33
34
 All lines up to a line containing the character sequence
35
<#GAPDoc Label=" (exactly one space character) are ignored. The
36
characters on the same line before this sequence are stored as prefix.
37
The characters after the sequence up to the next double quotes
38
character (which should not contain whitespace) are stored as label.
39
All other characters in the line are ignored.
40
41
 The following lines up to a line containing the character sequence
42
<#/GAPDoc> are stored under the label. These lines are processed as
43
follows: The longest possible substring from the beginning of the line
44
that equals the corresponding substring of the prefix is removed.
45
46
Having stored a list of labels and pieces of text gathered as above this can
47
be used as follows.
48
49
 In GAPDoc documentation files all statements of the form <#Include
50
Label="Key"> are replaced by the sequence of lines stored under the
51
label Key.
52
53
 Additionally, every occurrence of a statement of the form <#Include
54
SYSTEM "Filename"> is replaced by the whole file stored under the name
55
Filename in the file system.
56
57
 These substitutions are done recursively (although one should probably
58
avoid to use this extensively).
59
60
Here is another example:
61
62
 Example 
63
# # <#GAPDoc Label="AnotherPiece"> some characters
64
# # This text is not indented.
65
# This text is indented by one blank.
66
#Not indented.
67
#<#/GAPDoc>
68

69
70
replaces <#Include Label="AnotherPiece"> by
71
72
 Example 
73
This text is not indented.
74
 This text is indented by one blank. 
75
Not indented.
76

77
78
Since these rules are very simple it is quite easy to write a program in
79
almost any programming language which does this gathering of text pieces and
80
the substitutions. In GAPDoc there is the GAP function ComposedDocument
81
(4.2-1) which does this.
82
83
Note that the XML-tag-like markup we have used here is not a legal XML
84
markup, since the hash character is not allowed in element names. The
85
mechanism described here is a preprocessing step which composes a document.
86
87
88
4.2 A Tool for Collecting a Document
89
90
4.2-1 ComposedDocument
91
92
ComposedDocument( tagname, path, main, source[, info] )  function
93
ComposedXMLString( path, main, source[, info] )  function
94
Returns: a document as string, or a list with this string and information
95
about the source positions
96
97
The argument tagname is the string used for the pseudo elements which mark
98
the pieces of a document to collect. (In 4.1 we used GAPDoc as tagname. The
99
second function ComposedXMLString( ... ) is an abbreviation for
100
ComposedDocument("GAPDoc", ... ).
101
102
The argument path must be a path to some directory (as string or directory
103
object), main the name of a file and source a list of file names. These file
104
names are relative to path, except they start with "/" to specify an
105
absolute path or they start with "gap://" to specify a file relative to the
106
GAP roots (see FilenameGAP (4.2-3)). The document is constructed via the
107
mechanism described in Section 4.1.
108
109
First the files given in source are scanned for chunks of the document
110
marked by <#tagname Label="..."> and </#tagname> pairs. Then the file main
111
is read and all <#Include ... >-tags are substituted recursively by other
112
files or chunks of documentation found in the first step, respectively.
113
114
If the optional argument info is given and set to true this function returns
115
a list [str, origin], where str is a string containing the composed document
116
and origin is a sorted list of entries of the form [pos, filename, line].
117
Here pos runs through all character positions of starting lines or text
118
pieces from different files in str. The filename and line describe the
119
origin of this part of the collected document.
120
121
Without the fourth argument only the string str is returned.
122
123
By default ComposedDocument runs into an error if an <#Include ...>-tag
124
cannot be substituted (because a file or chunk is missing). This behaviour
125
can be changed by setting DOCCOMPOSEERROR := false;. Then the missing parts
126
are substituted by a short note about what is missing. Of course, this
127
feature is only useful if the resulting document is a valid XML document
128
(e.g., when the missing pieces are complete paragraphs or sections).
129
130
 Example 
131
gap> doc := ComposedDocument("GAPDoc", "/my/dir", "manual.xml", 
132
> ["../lib/func.gd", "../lib/func.gi"], true);;
133

134
135
4.2-2 OriginalPositionDocument
136
137
OriginalPositionDocument( srcinfo, pos )  function
138
Returns: A pair [filename, linenumber].
139
140
Here srcinfo must be a data structure as returned as second entry by
141
ComposedDocument (4.2-1) called with info=true. It returns for a given
142
position pos in the composed document the file name and line number from
143
which that text was collected.
144
145
4.2-3 FilenameGAP
146
147
FilenameGAP( fname )  function
148
Returns: file name as string or fail
149
150
This functions returns the full path of a file with name fname relative to a
151
GAP root path, or fail if such a file does not exist. The argument fname can
152
optionally start with the prefix "gap://" which will be removed.
153
154
 Example 
155
gap> FilenameGAP("hsdkfhs.g");
156
fail
157
gap> FilenameGAP("lib/system.g");
158
"/usr/local/gap4/lib/system.g"
159
gap> FilenameGAP("gap://lib/system.g");
160
"/usr/local/gap4/lib/system.g"
161

162
163
164