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="Distributing">
2
<Heading>Distributing a Document into Several Files</Heading>
3
4
In &GAPDoc; there are facilities to distribute a single document over
5
several 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
8
a set of conventions how this is done and some tools to collect the text
9
for further processing. <P/>
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, examples).
13
<P/>
14
15
<Section Label="DistrConv">
16
<Index Key="Include"><C>&lt;#Include></C></Index>
17
<Index Key="GAPDoc"><C>&lt;#GAPDoc></C></Index>
18
19
<Heading>The Conventions</Heading>
20
21
In this description we use the string <C>GAPDoc</C> for marking pieces
22
of a document to collect.
23
<P/>
24
25
Pieces of documentation that shall be incorporated into another document
26
are marked as follows:
27
28
<Listing Type="Example">
29
<![CDATA[## <#GAPDoc Label="MyPiece">
30
## <E>This</E> is the piece.
31
## The hash characters are removed.
32
## <#/GAPDoc>]]>
33
</Listing>
34
35
This piece is then included into another file by a statement like:
36
<!-- <Listing Type="Example"> -->
37
<C>&lt;#Include Label="MyPiece"></C>
38
<!--</Listing> -->
39
40
Here are the exact rules, how pieces are gathered:
41
42
<List>
43
<Item>
44
All lines up to a line containing the character sequence
45
<Q><C>&lt;#GAPDoc&nbsp;Label="</C></Q> (exactly one space
46
character) are ignored. The characters
47
on the same line before this sequence are stored as <Q>prefix</Q>.
48
The characters after the sequence up to the next double quotes character
49
(which should not contain whitespace) are stored as <Q>label</Q>.
50
All other characters in the line are ignored.
51
</Item>
52
53
<Item>
54
The following lines up to a line containing the character sequence
55
<Q><C>&lt;#/GAPDoc></C></Q> are stored under the label.
56
These lines are processed as follows: The longest possible
57
substring from the beginning of the line that equals the corresponding
58
substring of the prefix is removed.
59
</Item>
60
</List>
61
62
Having stored a list of labels and pieces of text gathered as above this can
63
be used as follows.
64
65
<List>
66
<Item>
67
In &GAPDoc; documentation files all statements
68
of the form <Q><C>&lt;#Include Label="Key"></C></Q> are
69
replaced by the
70
sequence of lines stored under the label <C>Key</C>.
71
</Item>
72
73
<Item>
74
Additionally, every occurrence of a statement of the form
75
<Q><C>&lt;#Include SYSTEM "Filename"></C></Q> is replaced by the
76
whole file stored under the name <C>Filename</C> in the file system.
77
</Item>
78
79
<Item>
80
These substitutions are done recursively (although one should probably avoid to use this extensively).
81
</Item>
82
</List>
83
84
Here is another example:
85
86
<Listing Type="Example">
87
<![CDATA[# # <#GAPDoc Label="AnotherPiece"> some characters
88
# # This text is not indented.
89
# This text is indented by one blank.
90
#Not indented.
91
#<#/GAPDoc>]]>
92
</Listing>
93
94
replaces <C>&lt;#Include Label="AnotherPiece"></C> by
95
96
<Listing Type="Example">
97
<![CDATA[This text is not indented.
98
This text is indented by one blank.
99
Not indented.]]>
100
</Listing>
101
102
Since these rules are very simple it is quite easy to write a program in
103
almost any programming language which does this gathering of text pieces
104
and the substitutions. In &GAPDoc; there is the &GAP; function <Ref
105
Func="ComposedDocument"/> which does this.<P/>
106
107
Note that the XML-tag-like markup we have used here is not a legal XML
108
markup, since the hash character is not allowed in element names. The
109
mechanism described here is a preprocessing step which composes a
110
document.
111
112
</Section>
113
114
<Section >
115
<Heading>A Tool for Collecting a Document</Heading>
116
117
<#Include Label="ComposedDocument">
118
119
<#Include Label="OriginalPositionDocument">
120
121
<#Include Label="FilenameGAP">
122
123
</Section>
124
125
</Chapter>
126
127
128