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
5 The Converters and an XML Parser
3
4
The GAPDoc package contains a set of programs which allow us to convert a
5
GAPDoc book into several output versions and to make them available to GAP's
6
online help.
7
8
Currently the following output formats are provided: text for browsing
9
inside a terminal running GAP, LaTeX with hyperref-package for cross
10
references via hyperlinks and HTML for reading with a Web-browser.
11
12
13
5.1 Producing Documentation from Source Files
14
15
Here we explain how to use the functions which are described in more detail
16
in the following sections. We assume that we have the main file MyBook.xml
17
of a book "MyBook" in the directory /my/book/path. This contains <#Include
18
...>-statements as explained in Chapter 4. These refer to some other files
19
as well as pieces of text which are found in the comments of some GAP source
20
files ../lib/a.gd and ../lib/b.gi (relative to the path above). A BibTeX
21
database MyBook.bib for the citations is also in the directory given above.
22
We want to produce a text-, pdf- and HTML-version of the document. (A LaTeX
23
version of the manual is produced, so it is also easy to compile dvi-, and
24
postscript-versions.)
25
26
All the commands shown in this Section are collected in the single function
27
MakeGAPDocDoc (5.1-1).
28
29
First we construct the complete XML-document as a string with
30
ComposedDocument (4.2-1). This interprets recursively the <#Include
31
...>-statements.
32
33
 Example 
34
gap> path := Directory("/my/book/path");;
35
gap> main := "MyBook.xml";;
36
gap> files := ["../lib/a.gd", "../lib/b.gi"];;
37
gap> bookname := "MyBook";;
38
gap> doc := ComposedDocument("GAPDoc", path, main, files, true);;
39

40
41
Now doc is a list with two entries, the first is a string containing the
42
XML-document, the second gives information from which files and locations
43
which part of the document was collected. This is useful in the next step,
44
if there are any errors in the document.
45
46
Next we parse the document and store its structure in a tree-like data
47
structure. The commands for this are ParseTreeXMLString (5.2-1) and
48
CheckAndCleanGapDocTree (5.2-8).
49
50
 Example 
51
gap> r := ParseTreeXMLString(doc[1], doc[2]);;
52
gap> CheckAndCleanGapDocTree(r);
53
true
54

55
56
We start to produce a text version of the manual, which can be read in a
57
terminal (window). The command is GAPDoc2Text (5.3-2). This produces a
58
record with the actual text and some additional information. The text can be
59
written chapter-wise into files with GAPDoc2TextPrintTextFiles (5.3-3). The
60
names of these files are chap0.txt, chap1.txt and so on. The text contains
61
some markup using ANSI escape sequences. This markup is substituted by the
62
GAP help system (user configurable) to show the text with colors and other
63
attributes. For the bibliography we have to tell GAPDoc2Text (5.3-2) the
64
location of the BibTeX database by specifying a path as second argument.
65
66
 Example 
67
gap> t := GAPDoc2Text(r, path);;
68
gap> GAPDoc2TextPrintTextFiles(t, path);
69

70
71
This command constructs all parts of the document including table of
72
contents, bibliography and index. The functions FormatParagraph (6.1-4) for
73
formatting text paragraphs and ParseBibFiles (7.1-1) for reading BibTeX
74
files with GAP may be of independent interest.
75
76
With the text version we have also produced the information which is used
77
for searching with GAP's online help. Also, labels are produced which can be
78
used by links in the HTML- and pdf-versions of the manual.
79
80
Next we produce a LaTeX version of the document. GAPDoc2LaTeX (5.3-1)
81
returns a string containing the LaTeX source. The utility function
82
FileString (6.3-5) writes the content of a string to a file, we choose
83
MyBook.tex.
84
85
 Example 
86
gap> l := GAPDoc2LaTeX(r);;
87
gap> FileString(Filename(path, Concatenation(bookname, ".tex")), l);
88

89
90
Assuming that you have a sufficiently good installation of TeX available
91
(see GAPDoc2LaTeX (5.3-1) for details) this can be processed with a series
92
of commands like in the following example.
93
94
 Example 
95
cd /my/book/path
96
pdflatex MyBook
97
bibtex MyBook
98
pdflatex MyBook
99
makeindex MyBook
100
pdflatex MyBook
101
mv MyBook.pdf manual.pdf
102

103
104
After this we have a pdf-version of the document in the file manual.pdf. It
105
contains hyperlink information which can be used with appropriate browsers
106
for convenient reading of the document on screen (e.g., xpdf is nice because
107
it allows remote calls to display named locations of the document). Of
108
course, we could also use other commands like latex or dvips to process the
109
LaTeX source file. Furthermore we have produced a file MyBook.pnr which is
110
GAP-readable and contains the page number information for each (sub-)section
111
of the document.
112
113
We can add this page number information to the indexing information
114
collected by the text converter and then print a manual.six file which is
115
read by GAP when the manual is loaded. This is done with AddPageNumbersToSix
116
(5.3-4) and PrintSixFile (5.3-5).
117
118
 Example 
119
gap> AddPageNumbersToSix(r, Filename(path, "MyBook.pnr"));
120
gap> PrintSixFile(Filename(path, "manual.six"), r, bookname);
121

122
123
Finally we produce an HTML-version of the document and write it
124
(chapter-wise) into files chap0.html, chap1.html and so on. They can be read
125
with any Web-browser. The commands are GAPDoc2HTML (5.3-7) and
126
GAPDoc2HTMLPrintHTMLFiles (5.3-8). We also add a link from manual.html to
127
chap0.html. You probably want to copy stylesheet files into the same
128
directory, see 5.3-9 for more details. The argument path of GAPDoc2HTML
129
(5.3-7) specifies the directory containing the BibTeX database files.
130
131
 Example 
132
gap> h := GAPDoc2HTML(r, path);;
133
gap> GAPDoc2HTMLPrintHTMLFiles(h, path);
134

135
136
5.1-1 MakeGAPDocDoc
137
138
MakeGAPDocDoc( path, main, files, bookname[, gaproot] )  function
139
140
This function collects all the commands for producing a text-, pdf- and
141
HTML-version of a GAPDoc document as described in Section 5.1. It checks the
142
.log file from the call of pdflatex and reports if there are errors,
143
warnings or overfull boxes.
144
145
Note: If this function works for you depends on your operating system and
146
installed software. It will probably work on most UNIX systems with a
147
standard LaTeX installation. If the function doesn't work for you look at
148
the source code and adjust it to your system.
149
150
Here path must be the directory (as string or directory object) containing
151
the main file main of the document (given with or without the .xml
152
extension. The argument files is a list of (probably source code) files
153
relative to path which contain pieces of documentation which must be
154
included in the document, see Chapter 4. And bookname is the name of the
155
book used by GAP's online help. The optional argument gaproot must be a
156
string which gives the relative path from path to the main GAP root
157
directory. If this is given, the HTML files are produced with relative paths
158
to external books.
159
160
MakeGAPDocDoc can be called with additional arguments "MathJax", "Tth"
161
and/or "MathML". If these are given additional variants of the HTML
162
conversion are called, see GAPDoc2HTML (5.3-7) for details.
163
164
It is possible to use GAPDoc with other languages than English, see
165
SetGapDocLanguage (5.3-13) for more details.
166
167
168
5.2 Parsing XML Documents
169
170
Arbitrary well-formed XML documents can be parsed and browsed by the
171
following functions.
172
173
5.2-1 ParseTreeXMLString
174
175
ParseTreeXMLString( str[, srcinfo][, entitydict] )  function
176
ParseTreeXMLFile( fname[, entitydict] )  function
177
Returns: a record which is root of a tree structure
178
179
The first function parses an XML-document stored in string str and returns
180
the document in form of a tree.
181
182
The optional argument srcinfo must have the same format as in
183
OriginalPositionDocument (4.2-2). If it is given then error messages refer
184
to the original source of the text with the problem.
185
186
With the optional argument entitydict named entities can be given to the
187
parser, for example entities which are defined in the .dtd-file (which is
188
not read by this parser). The standard XML-entities do not need to be
189
provided, and for GAPDoc documents the entity definitions from gapdoc.dtd
190
are automatically provided. Entities in the document's <!DOCTYPE declaration
191
are parsed and also need not to be provided here. The argument entitydict
192
must be a record where each component name is an entity name (without the
193
surrounding & and ;) to which is assigned its substitution string.
194
195
The second function is just a shortcut for ParseTreeXMLString(
196
StringFile(fname), ... ), see StringFile (6.3-5).
197
198
After these functions return the list of named entities which were known
199
during the parsing can be found in the record ENTITYDICT.
200
201
A node in the result tree corresponds to an XML element, or to some parsed
202
character data. In the first case it looks as follows:
203
204
 Example Node 
205
rec( name := "Book",
206
 attributes := rec( Name := "EDIM" ),
207
 content := [ ... list of nodes for content ...],
208
 start := 312,
209
 stop := 15610,
210
 next := 15611 )
211

212
213
This means that str{[312..15610]} looks like <Book Name="EDIM"> ... content
214
... </Book>.
215
216
The leaves of the tree encode parsed character data as in the following
217
example:
218
219
 Example Node 
220
rec( name := "PCDATA", 
221
 content := "text without markup " )
222

223
224
This function checks whether the XML document is well formed, see 2.1-14 for
225
an explanation. If an error in the XML structure is found, a break loop is
226
entered and the text around the position where the problem starts is shown.
227
With Show(); one can browse the original input in the Pager (Reference:
228
Pager), starting with the line where the error occurred. All entities are
229
resolved when they are either entities defined in the GAPDoc package (in
230
particular the standard XML entities) or if their definition is included in
231
the <!DOCTYPE ..> tag of the document.
232
233
Note that ParseTreeXMLString does not parse and interpret the corresponding
234
document type definition (the .dtd-file given in the <!DOCTYPE ..> tag).
235
Hence it also does not check the validity of the document (i.e., it is no
236
validating XML parser).
237
238
If you are using this function to parse a GAPDoc document you can use
239
CheckAndCleanGapDocTree (5.2-8) for some validation and additional checking
240
of the document structure.
241
242
5.2-2 StringXMLElement
243
244
StringXMLElement( tree )  function
245
Returns: a list [string, positions]
246
247
The argument tree must have a format of a node in the parse tree of an XML
248
document as returned by ParseTreeXMLString (5.2-1) (including the root node
249
representing the full document). This function computes a pair [string,
250
positions] where string contains XML code which is equivalent to the code
251
which was parsed to get tree. And positions is a list of lists of four
252
numbers [eltb, elte, contb, conte]. There is one such list for each XML
253
element occuring in string, where eltb and elte are the begin and end
254
position of this element in string and where contb and conte are begin and
255
end position of the content of this element, or both are 0 if there is no
256
content.
257
258
Note that parsing XML code is an irreversible task, we can only expect to
259
get equivalent XML code from this function. But parsing the resulting string
260
again and applying StringXMLElement again gives the same result. See the
261
function EntitySubstitution (5.2-3) for back-substitutions of entities in
262
the result.
263
264
5.2-3 EntitySubstitution
265
266
EntitySubstitution( xmlstring, entities )  function
267
Returns: a string
268
269
The argument xmlstring must be a string containing XML code or a pair
270
[string, positions] as returned by StringXMLElement (5.2-2). The argument
271
entities specifies entity names (without the surrounding & and ;) and their
272
substitution strings, either a list of pairs of strings or as a record with
273
the names as components and the substitutions as values.
274
275
This function tries to substitute non-intersecting parts of string by the
276
given entities. If the positions information is given then only parts of the
277
document which allow a valid substitution by an entity are considered.
278
Otherwise a simple text substitution without further check is done.
279
280
Note that in general the entity resolution in XML documents is a complicated
281
and non-reversible task. But nevertheless this utility may be useful in not
282
too complicated situations.
283
284
5.2-4 DisplayXMLStructure
285
286
DisplayXMLStructure( tree )  function
287
288
This utility displays the tree structure of an XML document as it is
289
returned by ParseTreeXMLString (5.2-1) (without the PCDATA leaves).
290
291
Since this is usually quite long the result is shown using the Pager
292
(Reference: Pager).
293
294
5.2-5 ApplyToNodesParseTree
295
296
ApplyToNodesParseTree( tree, fun )  function
297
AddRootParseTree( tree )  function
298
RemoveRootParseTree( tree )  function
299
300
The function ApplyToNodesParseTree applies a function fun to all nodes of
301
the parse tree tree of an XML document returned by ParseTreeXMLString
302
(5.2-1).
303
304
The function AddRootParseTree is an application of this. It adds to all
305
nodes a component .root to which the top node tree tree is assigned. These
306
components can be removed afterwards with RemoveRootParseTree.
307
308
Here are two more utilities which use ApplyToNodesParseTree.
309
310
5.2-6 GetTextXMLTree
311
312
GetTextXMLTree( tree )  function
313
Returns: a string
314
315
The argument tree must be a node of a parse tree of some XML document, see
316
ParseTreeXMLFile (5.2-1). This function collects the content of this and all
317
included elements recursively into a string.
318
319
5.2-7 XMLElements
320
321
XMLElements( tree, eltnames )  function
322
Returns: a list of nodes
323
324
The argument tree must be a node of a parse tree of some XML document, see
325
ParseTreeXMLFile (5.2-1). This function returns a list of all subnodes of
326
tree (possibly including tree) of elements with name given in the list of
327
strings eltnames. Use "PCDATA" as name for leave nodes which contain the
328
actual text of the document. As an abbreviation eltnames can also be a
329
string which is then put in a one element list.
330
331
And here are utilities for processing GAPDoc XML documents.
332
333
5.2-8 CheckAndCleanGapDocTree
334
335
CheckAndCleanGapDocTree( tree )  function
336
Returns: nothing
337
338
The argument tree of this function is a parse tree from ParseTreeXMLString
339
(5.2-1) of some GAPDoc document. This function does an (incomplete) validity
340
check of the document according to the document type declaration in
341
gapdoc.dtd. It also does some additional checks which cannot be described in
342
the DTD (like checking whether chapters and sections have a heading). For
343
elements with element content the whitespace between these elements is
344
removed.
345
346
In case of an error the break loop is entered and the position of the error
347
in the original XML document is printed. With Show(); one can browse the
348
original input in the Pager (Reference: Pager).
349
350
5.2-9 AddParagraphNumbersGapDocTree
351
352
AddParagraphNumbersGapDocTree( tree )  function
353
Returns: nothing
354
355
The argument tree must be an XML tree returned by ParseTreeXMLString (5.2-1)
356
applied to a GAPDoc document. This function adds to each node of the tree a
357
component .count which is of form [Chapter[, Section[, Subsection,
358
Paragraph] ] ]. Here the first three numbers should be the same as produced
359
by the LaTeX version of the document. Text before the first chapter is
360
counted as chapter 0 and similarly for sections and subsections. Some
361
elements are always considered to start a new paragraph.
362
363
5.2-10 InfoXMLParser
364
365
InfoXMLParser info class
366
367
The default level of this info class is 1. Functions like ParseTreeXMLString
368
(5.2-1) are then printing some information, in particular in case of errors.
369
You can suppress it by setting the level of InfoXMLParser to 0. With level 2
370
there may be some more information for debugging purposes.
371
372
373
5.3 The Converters
374
375
Here are more details about the conversion programs for GAPDoc XML
376
documents.
377
378
5.3-1 GAPDoc2LaTeX
379
380
GAPDoc2LaTeX( tree )  function
381
Returns: LaTeX document as string
382
383
SetGapDocLaTeXOptions( [...] )  function
384
Returns: Nothing
385
386
The argument tree for this function is a tree describing a GAPDoc XML
387
document as returned by ParseTreeXMLString (5.2-1) (probably also checked
388
with CheckAndCleanGapDocTree (5.2-8)). The output is a string containing a
389
version of the document which can be written to a file and processed with
390
LaTeX or pdfLaTeX (and probably BibTeX and makeindex).
391
392
The output uses the report document class and needs the following LaTeX
393
packages: a4wide, amssymb, inputenc, makeidx, color, fancyvrb, psnfss,
394
pslatex, enumitem and hyperref. These are for example provided by the
395
teTeX-1.0 or texlive distributions of TeX (which in turn are used for most
396
TeX packages of current Linux distributions); see http://www.tug.org/tetex/.
397
398
In particular, the resulting pdf-output (and dvi-output) contains (internal
399
and external) hyperlinks which can be very useful for onscreen browsing of
400
the document.
401
402
The LaTeX processing also produces a file with extension .pnr which is GAP
403
readable and contains the page numbers for all (sub)sections of the
404
document. This can be used by GAP's online help; see AddPageNumbersToSix
405
(5.3-4). Non-ASCII characters in the GAPDoc document are translated to LaTeX
406
input in ASCII-encoding with the help of Encode (6.2-2) and the option
407
"LaTeX". See the documentation of Encode (6.2-2) for how to proceed if you
408
have a character which is not handled (yet).
409
410
This function works by running recursively through the document tree and
411
calling a handler function for each GAPDoc XML element. Many of these
412
handler functions (usually in GAPDoc2LaTeXProcs.<ElementName>) are not
413
difficult to understand (the greatest complications are some commands for
414
index entries, labels or the output of page number information). So it
415
should be easy to adjust layout details to your own taste by slight
416
modifications of the program.
417
418
Former versions of GAPDoc supported some XML processing instructions to add
419
some extra lines to the preamble of the LaTeX document. Its use is now
420
deprecated, use the much more flexible SetGapDocLaTeXOptions instead: The
421
default layout of the resulting documents can be changed with
422
SetGapDocLaTeXOptions. This changes parts of the header of the LaTeX file
423
produced by GAPDoc. You can see the header with some placeholders by
424
Page(GAPDoc2LaTeXProcs.Head);. The placeholders are filled with components
425
from the record GAPDoc2LaTeXProcs.DefaultOptions. The arguments of
426
SetGapDocLaTeXOptions can be records with the same structure (or parts of
427
it) with different values. As abbreviations there are also three strings
428
supported as arguments. These are "nocolor" for switching all colors to
429
black; then "nopslatex" to use standard LaTeX fonts instead of postscript
430
fonts; and finally "utf8" to choose UTF-8 as input encoding for the LaTeX
431
document.
432
433
5.3-2 GAPDoc2Text
434
435
GAPDoc2Text( tree[, bibpath][, width] )  function
436
Returns: record containing text files as strings and other information
437
438
The argument tree for this function is a tree describing a GAPDoc XML
439
document as returned by ParseTreeXMLString (5.2-1) (probably also checked
440
with CheckAndCleanGapDocTree (5.2-8)). This function produces a text version
441
of the document which can be used with GAP's online help (with the "screen"
442
viewer, see SetHelpViewer (Reference: SetHelpViewer)). It includes title
443
page, bibliography and index. The bibliography is made from BibXMLext or
444
BibTeX databases, see 7. Their location must be given with the argument
445
bibpath (as string or directory object).
446
447
The output is a record with one component for each chapter (with names "0",
448
"1", ..., "Bib" and "Ind"). Each such component is again a record with the
449
following components:
450
451
text
452
the text of the whole chapter as a string
453
454
ssnr
455
list of subsection numbers in this chapter (like [3, 2, 1] for
456
chapter 3, section 2, subsection 1)
457
458
linenr
459
corresponding list of line numbers where the subsections start
460
461
len
462
number of lines of this chapter
463
464
The result can be written into files with the command
465
GAPDoc2TextPrintTextFiles (5.3-3).
466
467
As a side effect this function also produces the manual.six information
468
which is used for searching in GAP's online help. This is stored in tree.six
469
and can be printed into a manual.six file with PrintSixFile (5.3-5)
470
(preferably after producing a LaTeX version of the document as well and
471
adding the page number information to tree.six, see GAPDoc2LaTeX (5.3-1) and
472
AddPageNumbersToSix (5.3-4)).
473
474
The text produced by this function contains some markup via ANSI escape
475
sequences. The sequences used here are usually ignored by terminals. But the
476
GAP help system will substitute them by interpreted color and attribute
477
sequences (see TextAttr (6.1-2)) before displaying them. There is a default
478
markup used for this but it can also be configured by the user, see
479
SetGAPDocTextTheme (5.3-6). Furthermore, the text produced is in UTF-8
480
encoding. The encoding is also translated on the fly, if
481
GAPInfo.TermEncoding is set to some encoding supported by Encode (6.2-2),
482
e.g., "ISO-8859-1" or "latin1".
483
484
With the optional argument width a different length of the output text lines
485
can be chosen. The default is 76 and all lines in the resulting text start
486
with two spaces. This looks good on a terminal with a standard width of 80
487
characters and you probably don't want to use this argument.
488
489
5.3-3 GAPDoc2TextPrintTextFiles
490
491
GAPDoc2TextPrintTextFiles( t[, path] )  function
492
Returns: nothing
493
494
The first argument must be a result returned by GAPDoc2Text (5.3-2). The
495
second argument is a path for the files to write, it can be given as string
496
or directory object. The text of each chapter is written into a separate
497
file with name chap0.txt, chap1.txt, ..., chapBib.txt, and chapInd.txt.
498
499
If you want to make your document accessible via the GAP online help you
500
must put at least these files for the text version into a directory,
501
together with the file manual.six, see PrintSixFile (5.3-5). Then specify
502
the path to the manual.six file in the packages PackageInfo.g file, see
503
'Reference: The PackageInfo.g File'.
504
505
Optionally you can add the dvi- and pdf-versions of the document which are
506
produced with GAPDoc2LaTeX (5.3-1) to this directory. The files must have
507
the names manual.dvi and manual.pdf, respectively. Also you can add the
508
files of the HTML version produced with GAPDoc2HTML (5.3-7) to this
509
directory, see GAPDoc2HTMLPrintHTMLFiles (5.3-8). The handler functions in
510
GAP for this help format detect automatically which of the optional formats
511
of a book are actually available.
512
513
5.3-4 AddPageNumbersToSix
514
515
AddPageNumbersToSix( tree, pnrfile )  function
516
Returns: nothing
517
518
Here tree must be the XML tree of a GAPDoc document, returned by
519
ParseTreeXMLString (5.2-1). Running latex on the result of
520
GAPDoc2LaTeX(tree) produces a file pnrfile (with extension .pnr). The
521
command GAPDoc2Text(tree) creates a component tree.six which contains all
522
information about the document for the GAP online help, except the page
523
numbers in the .dvi, .ps, .pdf versions of the document. This command adds
524
the missing page number information to tree.six.
525
526
5.3-5 PrintSixFile
527
528
PrintSixFile( tree, bookname, fname )  function
529
Returns: nothing
530
531
This function prints the .six file fname for a GAPDoc document stored in
532
tree with name bookname. Such a file contains all information about the book
533
which is needed by the GAP online help. This information must first be
534
created by calls of GAPDoc2Text (5.3-2) and AddPageNumbersToSix (5.3-4).
535
536
5.3-6 SetGAPDocTextTheme
537
538
SetGAPDocTextTheme( [optrec1[, optrec2], ...] )  function
539
Returns: nothing
540
541
This utility function is for readers of the screen version of GAP manuals
542
which are generated by the GAPDoc package. It allows to configure the color
543
and attribute layout of the displayed text. There is a default which can be
544
reset by calling this function without argument.
545
546
As an abbreviation the arguments optrec1 and so on can be strings for the
547
known name of a theme. Information about valid names is shown with
548
SetGAPDocTextTheme("");.
549
550
Otherwise, optrec1 and so on must be a record. Its entries overwrite the
551
corresponding entries in the default and in previous arguments. To construct
552
valid markup you can use TextAttr (6.1-2). Entries must be either pairs of
553
strings, which are put before and after the corresponding text, or as an
554
abbreviation it can be a single string. In the latter case, the second
555
string is implied; if the string contains an escape sequence the second
556
string is TextAttr.reset, otherwise the given string is used. The following
557
components are recognized:
558
559
flush
560
"both" for left-right justified paragraphs, and "left" for ragged
561
right ones
562
563
Heading
564
chapter and (sub-)section headings
565
566
Func
567
function, operation, ... names
568
569
Arg
570
argument names in descriptions
571
572
Example
573
example code
574
575
Package
576
package names
577
578
Returns
579
Returns-line in descriptions
580
581
URL
582
URLs
583
584
Mark
585
Marks in description lists
586
587
K
588
GAP keywords
589
590
C
591
code or text to type
592
593
F
594
file names
595
596
B
597
buttons
598
599
M
600
simplified math elements
601
602
Math
603
normal math elements
604
605
Display
606
displayed math elements
607
608
Emph
609
emphasized text
610
611
Q
612
quoted text
613
614
Ref
615
reference text
616
617
Prompt
618
GAP prompt in examples
619
620
BrkPrompt
621
GAP break prompt in examples
622
623
GAPInput
624
GAP input in examples
625
626
reset
627
reset to default, don't change this
628
629
BibAuthor
630
author names in bibliography
631
632
BibTitle
633
titles in bibliography
634
635
BibJournal
636
journal names in bibliography
637
638
BibVolume
639
volume number in bibliography
640
641
BibLabel
642
labels for bibliography entries
643
644
BibReset
645
reset for bibliography, don't change
646
647
ListBullet
648
bullet for simple lists (2 visible characters long)
649
650
EnumMarks
651
one visible character before and after the number in enumerated lists
652
653
DefLineMarker
654
marker before function and variable definitions (2 visible characters
655
long)
656
657
FillString
658
for filling in definitions and example separator lines
659
660
 Example 
661
gap> # use no colors for GAP examples and 
662
gap> # change display of headings to bold green
663
gap> SetGAPDocTextTheme("noColorPrompt", 
664
>  rec(Heading:=Concatenation(TextAttr.bold, TextAttr.2)));
665

666
667
5.3-7 GAPDoc2HTML
668
669
GAPDoc2HTML( tree[, bibpath[, gaproot]][, mtrans] )  function
670
Returns: record containing HTML files as strings and other information
671
672
The argument tree for this function is a tree describing a GAPDoc XML
673
document as returned by ParseTreeXMLString (5.2-1) (probably also checked
674
with CheckAndCleanGapDocTree (5.2-8)). Without an mtrans argument this
675
function produces an HTML version of the document which can be read with any
676
Web-browser and also be used with GAP's online help (see SetHelpViewer
677
(Reference: SetHelpViewer)). It includes title page, bibliography, and
678
index. The bibliography is made from BibTeX databases. Their location must
679
be given with the argument bibpath (as string or directory object, if not
680
given the current directory is used). If the third argument gaproot is given
681
and is a string then this string is interpreted as relative path to GAP's
682
main root directory. Reference-URLs to external HTML-books which begin with
683
the GAP root path are then rewritten to start with the given relative path.
684
This makes the HTML-documentation portable provided a package is installed
685
in some standard location below the GAP root.
686
687
The output is a record with one component for each chapter (with names "0",
688
"1", ..., "Bib", and "Ind"). Each such component is again a record with the
689
following components:
690
691
text
692
the text of an HTML file containing the whole chapter (as a string)
693
694
ssnr
695
list of subsection numbers in this chapter (like [3, 2, 1] for
696
chapter 3, section 2, subsection 1)
697
698
Standard output format without mtrans argument
699
700
The HTML code produced with this converter conforms to the W3C specification
701
XHTML 1.0 strict, see http://www.w3.org/TR/xhtml1. First, this means that
702
the HTML files are valid XML files. Secondly, the extension strict says in
703
particular that the code doesn't contain any explicit font or color
704
information.
705
706
Mathematical formulae are handled as in the text converter GAPDoc2Text
707
(5.3-2). We don't want to assume that the browser can use symbol fonts. Some
708
GAP users like to browse the online help with lynx, see SetHelpViewer
709
(Reference: SetHelpViewer), which runs inside the same terminal windows as
710
GAP.
711
712
To view the generated files in graphical browsers, stylesheet files with
713
layout configuration should be copied into the directory with the generated
714
HTML files, see 5.3-9.
715
716
Output format with mtrans argument
717
718
Currently, there are three variants of this converter available which handle
719
mathematical formulae differently. They are accessed via the optional last
720
mtrans argument.
721
722
If mtrans is set to "MathJax" the formulae are essentially translated as for
723
LaTeX documents (there is no processing of <M> elements as decribed in
724
3.8-2). Inline formulae are delimited by \( and \) and displayed formulae by
725
\[ and \]. With MathJax webpages can contain nicely formatted scalable and
726
searchable formulae. The resulting files link by default to
727
http://cdn.mathjax.org to get the MathJax script and fonts. This means that
728
they can only be used on computers with internet access. An alternative URL
729
can be set by overwriting GAPDoc2HTMLProcs.MathJaxURL before building the
730
HTML version of a manual. This way a local installation of MathJax could be
731
used. See http://www.mathjax.org/ for more details.
732
733
The following possibilities for mtrans are still supported, but since the
734
MathJax approach seems much better, their use is deprecated.
735
736
If the argument mtrans is set to "Tth" it is assumed that you have installed
737
the LaTeX to HTML translation program tth. This is used to translate the
738
contents of the M, Math and Display elements into HTML code. Note that the
739
resulting code is not compliant with any standard. Formally it is XHTML 1.0
740
Transitional, it contains explicit font specifications and the characters of
741
mathematical symbols are included via their position in a Symbol font. Some
742
graphical browsers can be configured to display this in a useful manner,
743
check the Tth homepage (http://hutchinson.belmont.ma.us/tth/) for more
744
details.
745
746
This function works by running recursively through the document tree and
747
calling a handler function for each GAPDoc XML element. Many of these
748
handler functions (usually in GAPDoc2TextProcs.<ElementName>) are not
749
difficult to understand (the greatest complications are some commands for
750
index entries, labels or the output of page number information). So it
751
should be easy to adjust certain details to your own taste by slight
752
modifications of the program.
753
754
The result of this converter can be written to files with the command
755
GAPDoc2HTMLPrintHTMLFiles (5.3-8).
756
757
There are two user preferences for reading the HTML manuals produced by
758
GAPDoc. A user can choose among several style files which determine the
759
appearance of the manual pages with SetUserPreference("GAPDoc", "HTMLStyle",
760
[...]); where the list in the third argument are arguments for
761
SetGAPDocHTMLStyle (5.3-11). The second preference is set by
762
SetUserPreference("GAPDoc", "UseMathJax", ...); where the third argument is
763
true or false (default). If this is set to true, the GAP help system
764
displays the MathJax version of the HTML manuals.
765
766
5.3-8 GAPDoc2HTMLPrintHTMLFiles
767
768
GAPDoc2HTMLPrintHTMLFiles( t[, path] )  function
769
Returns: nothing
770
771
The first argument must be a result returned by GAPDoc2HTML (5.3-7). The
772
second argument is a path for the files to write, it can be given as string
773
or directory object. The text of each chapter is written into a separate
774
file with name chap0.html, chap1.html, ..., chapBib.html, and chapInd.html.
775
776
The MathJax versions are written to files chap0_mj.html, ...,
777
chapInd_mj.html.
778
779
The experimental version which is produced with tth uses different names for
780
the files, namely chap0_sym.html, and so on for files which need symbol
781
fonts.
782
783
You should also add stylesheet files to the directory with the HTML files,
784
see 5.3-9.
785
786
787
5.3-9 Stylesheet files
788
789
For graphical browsers the layout of the generated HTML manuals can be
790
highly configured by cascading stylesheet (CSS) and javascript files. Such
791
files are provided in the styles directory of the GAPDoc package.
792
793
We recommend that these files are copied into each manual directory (such
794
that each of them is selfcontained). There is a utility function
795
CopyHTMLStyleFiles (5.3-10) which does this. Of course, these files may be
796
changed or new styles may be added. New styles may also be sent to the
797
GAPDoc authors for possible inclusion in future versions.
798
799
The generated HTML files refer to the file manual.css which conforms to the
800
W3C specification CSS 2.0, see http://www.w3.org/TR/REC-CSS2, and the
801
javascript file manual.js (only in browsers which support CSS or javascript,
802
respectively; but the HTML files are also readable without any of them). To
803
add a style mystyle one or both of mystyle.css and mystyle.js must be
804
provided; these can overwrite default settings and add new javascript
805
functions. For more details see the comments in manual.js.
806
807
5.3-10 CopyHTMLStyleFiles
808
809
CopyHTMLStyleFiles( dir )  function
810
Returns: nothing
811
812
This utility function copies the *.css and *.js files from the styles
813
directory of the GAPDoc package into the directory dir.
814
815
5.3-11 SetGAPDocHTMLStyle
816
817
SetGAPDocHTMLStyle( [style1[, style2], ...] )  function
818
Returns: nothing
819
820
This utility function is for readers of the HTML version of GAP manuals
821
which are generated by the GAPDoc package. It allows to configure the
822
display style of the manuals. This will only have an effect if you are using
823
a browser that supports javascript. There is a default which can be reset by
824
calling this function without argument.
825
826
The arguments style1 and so on must be strings. You can find out about the
827
valid strings by following the [Style] link on top of any manual page.
828
(Going back to the original page, its address has a setting for GAPDocStyle
829
which is the list of strings, separated by commas, you want to use here.)
830
831
 Example 
832
gap> # show/hide subsections in tables on contents only after click,
833
gap> # and don't use colors in GAP examples
834
gap> SetGAPDocHTMLStyle("toggless", "nocolorprompt");
835

836
837
5.3-12 InfoGAPDoc
838
839
InfoGAPDoc info class
840
841
The default level of this info class is 1. The converter functions for
842
GAPDoc documents are then printing some information. You can suppress this
843
by setting the level of InfoGAPDoc to 0. With level 2 there may be some more
844
information for debugging purposes.
845
846
5.3-13 SetGapDocLanguage
847
848
SetGapDocLanguage( [lang] )  function
849
Returns: nothing
850
851
The GAPDoc converter programs sometimes produce text which is not explicit
852
in the document, e.g., headers like Abstract, Appendix, links to Next
853
Chapter, variable types function and so on.
854
855
With SetGapDocLanguage the language for these texts can be changed. The
856
argument lang must be a string. Calling without argument or with a language
857
name for which no translations are available is the same as using the
858
default "english".
859
860
If your language lang is not yet available, look at the record
861
GAPDocTexts.english and translate all the strings to lang. Then assign this
862
record to GAPDocTexts.(lang) and send it to the GAPDoc authors for inclusion
863
in future versions of GAPDoc. (Currently, there are translations for
864
english, german, russian and ukrainian.)
865
866
Further hints: To get strings produced by LaTeX right you will probably use
867
the babel package with option lang, see SetGapDocLaTeXOptions (5.3-1). If
868
lang cannot be encoded in latin1 encoding you can consider the use of "utf8"
869
with SetGapDocLaTeXOptions (5.3-1).
870
871
872
5.4 Testing Manual Examples
873
874
We also provide some tools to check and adjust the examples given in
875
<Example>-elements.
876
877
Former versions of GAPDoc provided functions ManualExamples and
878
TestManualExamples. These functions are still available, but no longer
879
documented. Their use is deprecated.
880
881
5.4-1 ExtractExamples
882
883
ExtractExamples( path, main, files, units )  function
884
Returns: a list of lists
885
886
ExtractExamplesXMLTree( tree, units )  function
887
Returns: a list of lists
888
889
The argument tree must be a parse tree of a GAPDoc document, see
890
ParseTreeXMLFile (5.2-1). The function ExtractExamplesXMLTree returns a data
891
structure representing the <Example> elements of the document. The return
892
value can be used with RunExamples (5.4-2) to check and optionally update
893
the examples of the document.
894
895
Depending on the argument units several examples are collected in one list.
896
Recognized values for units are "Chapter", "Section", "Subsection" or
897
"Single". The latter means that each example is in a separate list. For all
898
other value of units just one list with all examples is returned.
899
900
The arguments path, main and files of ExtractExamples are the same as for
901
ComposedDocument (4.2-1). This function first contructs and parses the
902
GAPDoc document and then applies ExtractExamplesXMLTree.
903
904
5.4-2 RunExamples
905
906
RunExamples( exmpls[, optrec] )  function
907
Returns: true or false
908
909
The argument exmpls must be the output of a call to ExtractExamples (5.4-1)
910
or ExtractExamplesXMLTree (5.4-1). The optional argument optrec must be a
911
record, its components can change the default behaviour of this function.
912
913
By default this function runs the GAP input of all examples and compares the
914
actual output with the output given in the examples. If differences occur
915
these are displayed together with information on the location of the source
916
code of that example. Before running the examples in each unit (entry of
917
exmpls) the function START_TEST (Reference: START_TEST) is called and the
918
screen width is set to 72 characters.
919
920
This function returns true if no differences are found and false otherwise.
921
922
If the argument optrec is given, the following components are recognized:
923
924
showDiffs
925
The default value is true, if set to something else found differences
926
in the examples are not displayed.
927
928
width
929
The value must be a positive integer which is used as screen width
930
when running the examples. As mentioned above, the default is 72 which
931
is a sensible value for the text version of the GAPDoc document used
932
in a 80 character wide terminal.
933
934
ignoreComments
935
The default is false.
936
If set to true comments in the input will be ignored (as in the
937
default behaviour of the Test (Reference: Test) function).
938
939
changeSources
940
If this is set to true then the source code of all manual examples
941
which show differences is adjusted to the current outputs. The default
942
is false.
943
Use this feature with care. Note that sometimes differences can
944
indicate a bug, and in such a case it is more appropriate to fix the
945
bug instead of changing the example output.
946
947
compareFunction
948
The function used to compare the output shown in the example and the
949
current output. See Test (Reference: Test) for more details.
950
951
checkWidth
952
If this option is a positive integer n the function prints warnings if
953
an example contains any line with more than n characters (input and
954
output lines are considered). By default this option is set to false.
955
956
957