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
<Chapter Label="ch:conv">
3
<Heading>The Converters and an XML Parser</Heading>
4
5
The &GAPDoc; package contains a set of programs which allow us to convert a
6
&GAPDoc; book into several output versions and to make them available to
7
&GAP;'s online help.<P/>
8
9
Currently the following output formats are provided: text for browsing
10
inside a terminal running &GAP;, &LaTeX; with <C>hyperref</C>-package for
11
cross references via hyperlinks and HTML for reading with a Web-browser.<P/>
12
13
14
15
<Section Label="MakeDoc">
16
<Heading>Producing Documentation from Source Files</Heading>
17
18
Here we explain how to use the functions which are
19
described in more detail in the following sections. We assume
20
that we have the main file <F>MyBook.xml</F> of a book
21
<C>"MyBook"</C> in the directory <F>/my/book/path</F>. This contains
22
<C>&lt;#Include ...></C>-statements as explained in
23
Chapter&nbsp;<Ref Sect="Distributing"/>. These refer to some other files
24
as well as pieces of text which are found in the comments of some &GAP;
25
source files <F>../lib/a.gd</F> and <F>../lib/b.gi</F> (relative to the
26
path above). A &BibTeX; database <F>MyBook.bib</F> for the citations is
27
also in the directory given above. We want to produce a text-,
28
<C>pdf-</C> and HTML-version of the document. (A &LaTeX; version of the
29
manual is produced, so it is also easy to compile <C>dvi</C>-, and
30
postscript-versions.)<P/>
31
32
All the commands shown in this Section are collected in the single function
33
<Ref Func="MakeGAPDocDoc"/>.<P/>
34
35
First we construct the complete XML-document as a string with
36
<Ref Func="ComposedDocument"/>. This interprets recursively the
37
<C>&lt;#Include ...></C>-statements.
38
39
<Log>
40
gap> path := Directory("/my/book/path");;
41
gap> main := "MyBook.xml";;
42
gap> files := ["../lib/a.gd", "../lib/b.gi"];;
43
gap> bookname := "MyBook";;
44
gap> doc := ComposedDocument("GAPDoc", path, main, files, true);;
45
</Log>
46
47
Now <C>doc</C> is a list with two entries, the first is a string
48
containing the XML-document, the second gives information from which
49
files and locations which part of the document was collected. This is
50
useful in the next step, if there are any errors in the document. <P/>
51
52
Next we parse the document and store its structure in a tree-like data
53
structure. The commands for this are <Ref Func="ParseTreeXMLString"/> and
54
<Ref Func="CheckAndCleanGapDocTree"/>.
55
56
<Log>
57
gap> r := ParseTreeXMLString(doc[1], doc[2]);;
58
gap> CheckAndCleanGapDocTree(r);
59
true
60
</Log>
61
62
We start to produce a text version of the manual, which can be read
63
in a terminal (window). The command is <Ref Func="GAPDoc2Text"/>.
64
This produces a record with the actual text and some additional
65
information. The text can be written chapter-wise into files with
66
<Ref Func="GAPDoc2TextPrintTextFiles"/>. The names of these files are
67
<F>chap0.txt</F>, <F>chap1.txt</F> and so on. The text contains some
68
markup using ANSI escape sequences. This markup is substituted by the
69
&GAP; help system (user configurable) to show the text with colors
70
and other attributes. For the bibliography we have to tell <Ref
71
Func="GAPDoc2Text"/> the location of the &BibTeX; database by specifying
72
a <C>path</C> as second argument.
73
74
<Log>
75
gap> t := GAPDoc2Text(r, path);;
76
gap> GAPDoc2TextPrintTextFiles(t, path);
77
</Log>
78
79
This command constructs all parts of the document including
80
table of contents, bibliography and index. The functions <Ref
81
Func="FormatParagraph"/> for formatting text paragraphs and <Ref
82
Func="ParseBibFiles"/> for reading &BibTeX; files with &GAP; may be of
83
independent interest.<P/>
84
85
With the text version we have also produced the information which is
86
used for searching with &GAP;'s online help. Also, labels are produced
87
which can be used by links in the HTML- and <C>pdf</C>-versions of the
88
manual. <P/>
89
90
Next we produce a &LaTeX; version of the document. <Ref
91
Func="GAPDoc2LaTeX"/> returns a string containing the &LaTeX; source.
92
The utility function <Ref Func="FileString"/> writes the content of a
93
string to a file, we choose <F>MyBook.tex</F>.
94
95
<Log>
96
gap> l := GAPDoc2LaTeX(r);;
97
gap> FileString(Filename(path, Concatenation(bookname, ".tex")), l);
98
</Log>
99
100
Assuming that you have a sufficiently good installation of &TeX;
101
available (see <Ref Func="GAPDoc2LaTeX"/> for details) this can be
102
processed with a series of commands like in the following example.
103
104
<Log>
105
cd /my/book/path
106
pdflatex MyBook
107
bibtex MyBook
108
pdflatex MyBook
109
makeindex MyBook
110
pdflatex MyBook
111
mv MyBook.pdf manual.pdf
112
</Log>
113
114
After this we have a <C>pdf</C>-version of the document in the file
115
<F>manual.pdf</F>. It contains hyperlink information which can be used
116
with appropriate browsers for convenient reading of the document on
117
screen (e.g., <C>xpdf</C> is nice because it allows remote calls to
118
display named locations of the document). Of course, we could also use
119
other commands like <C>latex</C> or <C>dvips</C> to process the &LaTeX;
120
source file.
121
122
Furthermore we have produced a file <F>MyBook.pnr</F> which is
123
&GAP;-readable and contains the page number information for each
124
(sub-)section of the document. <P/>
125
126
We can add this page number information to the indexing information
127
collected by the text converter and then print a <F>manual.six</F> file
128
which is read by &GAP; when the manual is loaded. This is done with <Ref
129
Func="AddPageNumbersToSix"/> and <Ref Func="PrintSixFile"/>.
130
131
<Log>
132
gap> AddPageNumbersToSix(r, Filename(path, "MyBook.pnr"));
133
gap> PrintSixFile(Filename(path, "manual.six"), r, bookname);
134
</Log>
135
136
Finally we produce an HTML-version of the document and write it
137
(chapter-wise) into files <F>chap0.html</F>, <F>chap1.html</F> and
138
so on. They can be read with any Web-browser. The commands are
139
<Ref Func="GAPDoc2HTML"/> and <Ref Func="GAPDoc2HTMLPrintHTMLFiles"/>.
140
We also add a link from <F>manual.html</F> to <F>chap0.html</F>.
141
You probably want to copy stylesheet files into the same directory,
142
see <Ref Subsect="StyleSheets"/> for more details. The argument
143
<C>path</C> of <Ref Func="GAPDoc2HTML"/> specifies the directory
144
containing the &BibTeX; database files.
145
146
<Log>
147
gap> h := GAPDoc2HTML(r, path);;
148
gap> GAPDoc2HTMLPrintHTMLFiles(h, path);
149
</Log>
150
151
<ManSection >
152
<Func Arg="path, main, files, bookname[, gaproot]" Name="MakeGAPDocDoc" />
153
154
<Description>
155
This function collects all the commands for producing a text-,
156
<C>pdf</C>- and HTML-version of a &GAPDoc; document as described in
157
Section&nbsp;<Ref Sect="MakeDoc"/>. It checks the <C>.log</C> file from
158
the call of <C>pdflatex</C> and reports if there are errors, warnings or
159
overfull boxes.<P/>
160
161
<Emph>Note:</Emph> If this function works for you depends on your
162
operating system and installed software. It will probably work on most
163
<C>UNIX</C> systems with a standard &LaTeX; installation. If the
164
function doesn't work for you look at the source code and adjust it to
165
your system. <P/>
166
167
Here <A>path</A> must be the directory (as string or directory object)
168
containing the main file <A>main</A> of the document (given with or
169
without the <C>.xml</C> extension. The argument <A>files</A> is a list
170
of (probably source code) files relative to <A>path</A> which contain
171
pieces of documentation which must be included in the document, see
172
Chapter&nbsp;<Ref Chap="Distributing"/>. And <A>bookname</A> is the name
173
of the book used by &GAP;'s online help. The optional argument
174
<A>gaproot</A> must be a string which gives the relative path from
175
<A>path</A> to the main &GAP; root directory. If this is given, the HTML
176
files are produced with relative paths to external books.<P/>
177
178
<Index Key="MathJax" Subkey="in MakeGAPDocDoc"><Package>MathJax</Package>
179
<Subkey>in <C>MakeGAPDocDoc</C></Subkey></Index>
180
<Ref Func="MakeGAPDocDoc"/> can be called with additional arguments
181
<C>"MathJax"</C>, <C>"Tth"</C> and/or <C>"MathML"</C>. If these are
182
given additional variants of the HTML conversion are called, see <Ref
183
Func="GAPDoc2HTML"/> for details.<P/>
184
185
It is possible to use &GAPDoc; with other languages than English, see
186
<Ref Func="SetGapDocLanguage"/> for more details.<P/>
187
</Description>
188
</ManSection>
189
</Section>
190
191
<Section Label="ParseXML">
192
<Heading>Parsing XML Documents</Heading>
193
Arbitrary well-formed XML documents can be parsed and browsed by the
194
following functions.
195
196
<#Include Label="ParseTreeXMLString">
197
198
<#Include Label="StringXMLElement">
199
200
<#Include Label="EntitySubstitution">
201
202
<#Include Label="DisplayXMLStructure">
203
204
<#Include Label="ApplyToNodesParseTree">
205
206
Here are two more utilities which use <Ref
207
Func="ApplyToNodesParseTree"/>.
208
209
<#Include Label="GetTextXMLTree">
210
211
<#Include Label="XMLElements">
212
213
And here are utilities for processing &GAPDoc; XML documents.
214
215
<#Include Label="CheckAndCleanGapDocTree">
216
217
<#Include Label="AddParagraphNumbersGapDocTree">
218
219
<#Include Label="InfoXMLParser">
220
221
</Section>
222
223
<Section Label="Converters">
224
<Heading>The Converters</Heading>
225
Here are more details about the conversion programs for &GAPDoc; XML
226
documents.
227
228
<#Include Label="GAPDoc2LaTeX">
229
230
<#Include Label="GAPDoc2Text">
231
232
<#Include Label="GAPDoc2TextPrintTextFiles">
233
234
<#Include Label="AddPageNumbersToSix">
235
236
<#Include Label="PrintSixFile">
237
238
<#Include Label="SetGAPDocTextTheme">
239
240
<#Include Label="GAPDoc2HTML">
241
242
<#Include Label="GAPDoc2HTMLPrintHTMLFiles">
243
244
<#Include Label="HTMLStyleSheets">
245
246
<#Include Label="SetGAPDocHTMLStyle">
247
248
<#Include Label="InfoGAPDoc">
249
250
<#Include Label="SetGapDocLanguage">
251
252
</Section>
253
254
<Section Label="Sec:TestExample">
255
<Index><C>ManualExamples</C></Index>
256
<Index><C>TestManualExamples</C></Index>
257
<Heading>Testing Manual Examples</Heading>
258
We also provide some tools to check and adjust the examples given in
259
<C>&lt;Example></C>-elements. <P/>
260
Former versions of &GAPDoc; provided functions <C>ManualExamples</C>
261
and <C>TestManualExamples</C>. These functions are still available,
262
but no longer documented. Their use is deprecated.
263
264
<#Include Label="ExtractExamples">
265
266
<#Include Label="RunExamples">
267
268
</Section>
269
270
</Chapter>
271
272
273