Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 91213ddcfbe7f54821d42c2d9e091326 > files > 55

gap-system-packages-4.4.12-5mdv2010.0.i586.rpm

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>GAP (GAPDoc) - Chapter 5: The Converters and an XML Parser</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content="GAPDoc2HTML" />
<link rel="stylesheet" type="text/css" href="manual.css" />
</head>
<body>


<div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chapA.html">A</a>  <a href="chapB.html">B</a>  <a href="chapC.html">C</a>  <a href="chapBib.html">Bib</a>  <a href="chapInd.html">Ind</a>  </div>

<div class="chlinkprevnexttop">&nbsp;<a href="chap0.html">Top of Book</a>&nbsp;  &nbsp;<a href="chap4.html">Previous Chapter</a>&nbsp;  &nbsp;<a href="chap6.html">Next Chapter</a>&nbsp;  </div>

<p><a id="X845E7FDC7C082CC4" name="X845E7FDC7C082CC4"></a></p>
<div class="ChapSects"><a href="chap5.html#X845E7FDC7C082CC4">5 <span class="Heading">The Converters and an XML Parser</span></a>
<div class="ContSect"><span class="nocss">&nbsp;</span><a href="chap5.html#X7D1BB5867C13FA14">5.1 <span class="Heading">Producing Documentation from Source Files</span></a>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X826F530686F4D052">5.1-1 MakeGAPDocDoc</a></span>
</div>
<div class="ContSect"><span class="nocss">&nbsp;</span><a href="chap5.html#X7FE2AF49838D9034">5.2 <span class="Heading">Parsing XML Documents</span></a>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X847EB8498151D443">5.2-1 ParseTreeXMLString</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X835887057D0B4DA8">5.2-2 StringXMLElement</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X786827BF793191B3">5.2-3 EntitySubstitution</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X86589C5C859ACE38">5.2-4 DisplayXMLStructure</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X7A7B223A83E38B40">5.2-5 ApplyToNodesParseTree</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X7F76D4A27C7FB946">5.2-6 GetTextXMLTree</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X8466F74C80442F7D">5.2-7 XMLElements</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X84CFF72484B19C0D">5.2-8 CheckAndCleanGapDocTree</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X84062CD67B286FF0">5.2-9 AddParagraphNumbersGapDocTree</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X78A22C58841E5D0B">5.2-10 InfoXMLParser</a></span>
</div>
<div class="ContSect"><span class="nocss">&nbsp;</span><a href="chap5.html#X8560E1A2845EC2C1">5.3 <span class="Heading">The Converters</span></a>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X85BE6DF178423EF5">5.3-1 GAPDoc2LaTeX</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X86CD0B197CD58D2A">5.3-2 GAPDoc2Text</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X7DFCE7357D6032A2">5.3-3 GAPDoc2TextPrintTextFiles</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X7EB5E86F87A09F94">5.3-4 AddPageNumbersToSix</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X7D42CFED7885BC00">5.3-5 PrintSixFile</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X7DEB37417BBD8941">5.3-6 SetGAPDocTextTheme</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X84F22EEB78845CFD">5.3-7 GAPDoc2HTML</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X84A7007778073E7A">5.3-8 GAPDoc2HTMLPrintHTMLFiles</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X864A528B81C661A2">5.3-9 InfoGAPDoc</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X82AB468887ED0DBB">5.3-10 SetGapDocLanguage</a></span>
</div>
<div class="ContSect"><span class="nocss">&nbsp;</span><a href="chap5.html#X800299827B88ABBE">5.4 <span class="Heading">Testing Manual Examples</span></a>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X7AD38E77784572A1">5.4-1 ManualExamples</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X7F2555E07C499554">5.4-2 ReadTestExamplesString</a></span>
</div>
</div>

<h3>5 <span class="Heading">The Converters and an XML Parser</span></h3>

<p>The <strong class="pkg">GAPDoc</strong> package contains a set of programs which allow us to convert a <strong class="pkg">GAPDoc</strong> book into several output versions and to make them available to <strong class="pkg">GAP</strong>'s online help.</p>

<p>Currently the following output formats are provided: text for browsing inside a terminal running <strong class="pkg">GAP</strong>, LaTeX with <code class="code">hyperref</code>-package for cross references via hyperlinks and HTML for reading with a Web-browser.</p>

<p><a id="X7D1BB5867C13FA14" name="X7D1BB5867C13FA14"></a></p>

<h4>5.1 <span class="Heading">Producing Documentation from Source Files</span></h4>

<p>Here we explain how to use the functions which are described in more detail in the following sections. We assume that we have the main file <code class="file">MyBook.xml</code> of a book <code class="code">"MyBook"</code> in the directory <code class="file">/my/book/path</code>. This contains <code class="code">&lt;#Include ...&gt;</code>-statements as explained in Chapter <a href="chap4.html#X7A3355C07F57C280"><b>4</b></a>. These refer to some other files as well as pieces of text which are found in the comments of some <strong class="pkg">GAP</strong> source files <code class="file">../lib/a.gd</code> and <code class="file">../lib/b.gi</code> (relative to the path above). A BibTeX database <code class="file">MyBook.bib</code> for the citations is also in the directory given above. We want to produce a text-, <code class="code">pdf-</code> and HTML-version of the document. (A LaTeX version of the manual is produced, so it is also easy to compile <code class="code">dvi</code>-, and postscript-versions.)</p>

<p>All the commands shown in this Section are collected in the single function <code class="func">MakeGAPDocDoc</code> (<a href="chap5.html#X826F530686F4D052"><b>5.1-1</b></a>).</p>

<p>First we construct the complete XML-document as a string with <code class="func">ComposedDocument</code> (<a href="chap4.html#X857D77557D12559D"><b>4.2-1</b></a>). This interprets recursively the <code class="code">&lt;#Include ...&gt;</code>-statements.</p>


<table class="example">
<tr><td><pre>
gap&gt; path := Directory("/my/book/path");;
gap&gt; main := "MyBook.xml";;
gap&gt; files := ["../lib/a.gd", "../lib/b.gi"];;
gap&gt; bookname := "MyBook";;
gap&gt; doc := ComposedDocument("GAPDoc", path, main, files, true);;
</pre></td></tr></table>

<p>Now <code class="code">doc</code> is a list with two entries, the first is a string containing the XML-document, the second gives information from which files and locations which part of the document was collected. This is useful in the next step, if there are any errors in the document.</p>

<p>Next we parse the document and store its structure in a tree-like data structure. The commands for this are <code class="func">ParseTreeXMLString</code> (<a href="chap5.html#X847EB8498151D443"><b>5.2-1</b></a>) and <code class="func">CheckAndCleanGapDocTree</code> (<a href="chap5.html#X84CFF72484B19C0D"><b>5.2-8</b></a>).</p>


<table class="example">
<tr><td><pre>
gap&gt; r := ParseTreeXMLString(doc[1], doc[2]);;
gap&gt; CheckAndCleanGapDocTree(r);
true
</pre></td></tr></table>

<p>We start to produce a text version of the manual, which can be read in a terminal (window). The command is <code class="func">GAPDoc2Text</code> (<a href="chap5.html#X86CD0B197CD58D2A"><b>5.3-2</b></a>). This produces a record with the actual text and some additional information. The text can be written chapter-wise into files with <code class="func">GAPDoc2TextPrintTextFiles</code> (<a href="chap5.html#X7DFCE7357D6032A2"><b>5.3-3</b></a>). The names of these files are <code class="file">chap0.txt</code>, <code class="file">chap1.txt</code> and so on. The text contains some markup using ANSI escape sequences. This markup is substituted by the <strong class="pkg">GAP</strong> help system (user configurable) to show the text with colors and other attributes. For the bibliography we have to tell <code class="func">GAPDoc2Text</code> (<a href="chap5.html#X86CD0B197CD58D2A"><b>5.3-2</b></a>) the location of the BibTeX database by specifying a <code class="code">path</code> as second argument.</p>


<table class="example">
<tr><td><pre>
gap&gt; t := GAPDoc2Text(r, path);;
gap&gt; GAPDoc2TextPrintTextFiles(t, path);
</pre></td></tr></table>

<p>This command constructs all parts of the document including table of contents, bibliography and index. The functions <code class="func">FormatParagraph</code> (<a href="chap6.html#X812058CE7C8E9022"><b>6.1-4</b></a>) for formatting text paragraphs and <code class="func">ParseBibFiles</code> (<a href="chap7.html#X82555C307FDC1817"><b>7.1-1</b></a>) for reading BibTeX files with <strong class="pkg">GAP</strong> may be of independent interest.</p>

<p>With the text version we have also produced the information which is used for searching with <strong class="pkg">GAP</strong>'s online help. Also, labels are produced which can be used by links in the HTML- and <code class="code">pdf</code>-versions of the manual.</p>

<p>Next we produce a LaTeX version of the document. <code class="func">GAPDoc2LaTeX</code> (<a href="chap5.html#X85BE6DF178423EF5"><b>5.3-1</b></a>) returns a string containing the LaTeX source. The utility function <code class="func">FileString</code> (<a href="chap6.html#X7E14D32181FBC3C3"><b>6.3-5</b></a>) writes the content of a string to a file, we choose <code class="file">MyBook.tex</code>.</p>


<table class="example">
<tr><td><pre>
gap&gt; l := GAPDoc2LaTeX(r);;
gap&gt; FileString(Filename(path, Concatenation(bookname, ".tex")), l);
</pre></td></tr></table>

<p>Assuming that you have a sufficiently good installation of TeX available (see <code class="func">GAPDoc2LaTeX</code> (<a href="chap5.html#X85BE6DF178423EF5"><b>5.3-1</b></a>) for details) this can be processed with a series of commands like in the following example.</p>


<table class="example">
<tr><td><pre>
cd /my/book/path
pdflatex MyBook
bibtex MyBook
pdflatex MyBook
makeindex MyBook
pdflatex MyBook
mv MyBook.pdf manual.pdf
</pre></td></tr></table>

<p>After this we have a <code class="code">pdf</code>-version of the document in the file <code class="file">manual.pdf</code>. It contains hyperlink information which can be used with appropriate browsers for convenient reading of the document on screen (e.g., <code class="code">xpdf</code> is nice because it allows remote calls to display named locations of the document). Of course, we could also use other commands like <code class="code">latex</code> or <code class="code">dvips</code> to process the LaTeX source file. Furthermore we have produced a file <code class="file">MyBook.pnr</code> which is <strong class="pkg">GAP</strong>-readable and contains the page number information for each (sub-)section of the document.</p>

<p>We can add this page number information to the indexing information collected by the text converter and then print a <code class="file">manual.six</code> file which is read by <strong class="pkg">GAP</strong> when the manual is loaded. This is done with <code class="func">AddPageNumbersToSix</code> (<a href="chap5.html#X7EB5E86F87A09F94"><b>5.3-4</b></a>) and <code class="func">PrintSixFile</code> (<a href="chap5.html#X7D42CFED7885BC00"><b>5.3-5</b></a>).</p>


<table class="example">
<tr><td><pre>
gap&gt; AddPageNumbersToSix(r, Filename(path, "MyBook.pnr"));
gap&gt; PrintSixFile(Filename(path, "manual.six"), r, bookname);
</pre></td></tr></table>

<p>Finally we produce an HTML-version of the document and write it (chapter-wise) into files <code class="file">chap0.html</code>, <code class="file">chap1.html</code> and so on. They can be read with any Web-browser. The commands are <code class="func">GAPDoc2HTML</code> (<a href="chap5.html#X84F22EEB78845CFD"><b>5.3-7</b></a>) and <code class="func">GAPDoc2HTMLPrintHTMLFiles</code> (<a href="chap5.html#X84A7007778073E7A"><b>5.3-8</b></a>). We also add a link from <code class="file">manual.html</code> to <code class="file">chap0.html</code>. You probably want to add a file <code class="file">manual.css</code>, see <code class="func">GAPDoc2HTMLPrintHTMLFiles</code> (<a href="chap5.html#X84A7007778073E7A"><b>5.3-8</b></a>) for more details. The argument <code class="code">path</code> of <code class="func">GAPDoc2HTML</code> (<a href="chap5.html#X84F22EEB78845CFD"><b>5.3-7</b></a>) specifies the directory containing the BibTeX database files.</p>


<table class="example">
<tr><td><pre>
gap&gt; h := GAPDoc2HTML(r, path);;
gap&gt; GAPDoc2HTMLPrintHTMLFiles(h, path);
</pre></td></tr></table>

<p><a id="X826F530686F4D052" name="X826F530686F4D052"></a></p>

<h5>5.1-1 MakeGAPDocDoc</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; MakeGAPDocDoc</code>( <var class="Arg">path, main, files, bookname[, gaproot]</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function collects all the commands for producing a text-, <code class="code">pdf</code>- and HTML-version of a <strong class="pkg">GAPDoc</strong> document as described in Section <a href="chap5.html#X7D1BB5867C13FA14"><b>5.1</b></a>. It checks the <code class="code">.log</code> file from the call of <code class="code">pdflatex</code> and reports if there are errors, warnings or overfull boxes.</p>

<p><em>Note:</em> If this function works for you depends on your operating system and installed software. It will probably work on most <code class="code">UNIX</code> systems with a standard LaTeX installation. If the function doesn't work for you look at the source code and adjust it to your system.</p>

<p>Here <var class="Arg">path</var> must be the directory (as string or directory object) containing the main file <var class="Arg">main</var> of the document (given with or without the <code class="code">.xml</code> extension. The argument <var class="Arg">files</var> is a list of (probably source code) files relative to <var class="Arg">path</var> which contain pieces of documentation which must be included in the document, see Chapter <a href="chap4.html#X7A3355C07F57C280"><b>4</b></a>. And <var class="Arg">bookname</var> is the name of the book used by <strong class="pkg">GAP</strong>'s online help. The optional argument <var class="Arg">gaproot</var> must be a string which gives the relative path from <var class="Arg">path</var> to the main <strong class="pkg">GAP</strong> root directory. If this is given, the HTML files are produced with relative paths to external books.</p>

<p>Experimental: <code class="func">MakeGAPDocDoc</code> can be called with additional arguments <code class="code">"Tth"</code> and/or <code class="code">"MathML"</code>. If these are given additional variants of the HTML conversion are called, see <code class="func">GAPDoc2HTML</code> (<a href="chap5.html#X84F22EEB78845CFD"><b>5.3-7</b></a>) for details.</p>

<p>It is possible to use <strong class="pkg">GAPDoc</strong> with other languages than English, see <code class="func">SetGapDocLanguage</code> (<a href="chap5.html#X82AB468887ED0DBB"><b>5.3-10</b></a>) for more details.</p>

<p><a id="X7FE2AF49838D9034" name="X7FE2AF49838D9034"></a></p>

<h4>5.2 <span class="Heading">Parsing XML Documents</span></h4>

<p>Arbitrary well-formed XML documents can be parsed and browsed by the following functions.</p>

<p><a id="X847EB8498151D443" name="X847EB8498151D443"></a></p>

<h5>5.2-1 ParseTreeXMLString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ParseTreeXMLString</code>( <var class="Arg">str[, srcinfo][, entitydict]</var> )</td><td class="tdright">( function )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ParseTreeXMLFile</code>( <var class="Arg">fname[, entitydict]</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>a record which is root of a tree structure</p>

<p>The first function parses an XML-document stored in string <var class="Arg">str</var> and returns the document in form of a tree.</p>

<p>The optional argument <var class="Arg">srcinfo</var> must have the same format as in <code class="func">OriginalPositionDocument</code> (<a href="chap4.html#X86D1141E7EDCAAC8"><b>4.2-2</b></a>). If it is given then error messages refer to the original source of the text with the problem.</p>

<p>With the optional argument <var class="Arg">entitydict</var> named entities can be given to the parser, for example entities which are defined in the <code class="code">.dtd</code>-file (which is not read by this parser). The standard XML-entities do not need to be provided, and for <strong class="pkg">GAPDoc</strong> documents the entity definitions from <code class="code">gapdoc.dtd</code> are automatically provided. Entities in the document's <code class="code">&lt;!DOCTYPE</code> declaration are parsed and also need not to be provided here. The argument <var class="Arg">entitydict</var> must be a record where each component name is an entity name (without the surrounding &amp; and ;) to which is assigned its substitution string.</p>

<p>The second function is just a shortcut for <code class="code">ParseTreeXMLString( StringFile(</code><var class="Arg">fname</var><code class="code">), ... )</code>, see <code class="func">StringFile</code> (<a href="chap6.html#X7E14D32181FBC3C3"><b>6.3-5</b></a>).</p>

<p>After these functions return the list of named entities which were known during the parsing can be found in the record <code class="code">ENTITYDICT</code>.</p>

<p>A node in the result tree corresponds to an XML element, or to some parsed character data. In the first case it looks as follows:</p>


<table class="example">
<tr><td><pre>
rec( name := "Book",
     attributes := rec( Name := "EDIM" ),
     content := [ ... list of nodes for content ...],
     start := 312,
     stop := 15610,
     next := 15611     )
</pre></td></tr></table>

<p>This means that <code class="code"><var class="Arg">str</var>{[312..15610]}</code> looks like <code class="code">&lt;Book Name="EDIM"&gt; ... content ... &lt;/Book&gt;</code>.</p>

<p>The leaves of the tree encode parsed character data as in the following example:</p>


<table class="example">
<tr><td><pre>
rec( name := "PCDATA", 
     content := "text without markup "     )
</pre></td></tr></table>

<p>This function checks whether the XML document is <em>well formed</em>, see <a href="chap2.html#X8561F07A81CABDD6"><b>2.1-14</b></a> for an explanation. If an error in the XML structure is found, a break loop is entered and the text around the position where the problem starts is shown. With <code class="code">Show();</code> one can browse the original input in the <code class="func">Pager</code> (<a href="../../../doc/htm/ref/CHAP002.htm#SECT004"><b>Reference: Pager</b></a>), starting with the line where the error occurred. All entities are resolved when they are either entities defined in the <strong class="pkg">GAPDoc</strong> package (in particular the standard XML entities) or if their definition is included in the <code class="code">&lt;!DOCTYPE ..&gt;</code> tag of the document.</p>

<p>Note that <code class="func">ParseTreeXMLString</code> does not parse and interpret the corresponding document type definition (the <code class="code">.dtd</code>-file given in the <code class="code">&lt;!DOCTYPE ..&gt;</code> tag). Hence it also does not check the <em>validity</em> of the document (i.e., it is no <em>validating XML parser</em>).</p>

<p>If you are using this function to parse a <strong class="pkg">GAPDoc</strong> document you can use <code class="func">CheckAndCleanGapDocTree</code> (<a href="chap5.html#X84CFF72484B19C0D"><b>5.2-8</b></a>) for some validation and additional checking of the document structure.</p>

<p><a id="X835887057D0B4DA8" name="X835887057D0B4DA8"></a></p>

<h5>5.2-2 StringXMLElement</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; StringXMLElement</code>( <var class="Arg">tree</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>a list <code class="code">[string, positions]</code></p>

<p>The argument <var class="Arg">tree</var> must have a format of a node in the parse tree of an XML document as returned by <code class="func">ParseTreeXMLString</code> (<a href="chap5.html#X847EB8498151D443"><b>5.2-1</b></a>) (including the root node representing the full document). This function computes a pair <code class="code">[string, positions]</code> where <code class="code">string</code> contains XML code which is equivalent to the code which was parsed to get <var class="Arg">tree</var>. And <code class="code">positions</code> is a list of lists of four numbers <code class="code">[eltb, elte, contb, conte]</code>. There is one such list for each XML element occuring in <code class="code">string</code>, where <code class="code">eltb</code> and <code class="code">elte</code> are the begin and end position of this element in <code class="code">string</code> and where <code class="code">contb</code> and <code class="code">conte</code> are begin and end position of the content of this element, or both are <code class="code">0</code> if there is no content.</p>

<p>Note that parsing XML code is an irreversible task, we can only expect to get equivalent XML code from this function. But parsing the resulting <code class="code">string</code> again and applying <code class="func">StringXMLElement</code> again gives the same result. See the function <code class="func">EntitySubstitution</code> (<a href="chap5.html#X786827BF793191B3"><b>5.2-3</b></a>) for back-substitutions of entities in the result.</p>

<p><a id="X786827BF793191B3" name="X786827BF793191B3"></a></p>

<h5>5.2-3 EntitySubstitution</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; EntitySubstitution</code>( <var class="Arg">xmlstring, entities</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>a string</p>

<p>The argument <var class="Arg">xmlstring</var> must be a string containing XML code or a pair <code class="code">[string, positions]</code> as returned by <code class="func">StringXMLElement</code> (<a href="chap5.html#X835887057D0B4DA8"><b>5.2-2</b></a>). The argument <var class="Arg">entities</var> specifies entity names (without the surrounding <var class="Arg">&amp;</var> and <code class="code">;</code>) and their substitution strings, either a list of pairs of strings or as a record with the names as components and the substitutions as values.</p>

<p>This function tries to substitute non-intersecting parts of <code class="code">string</code> by the given entities. If the <code class="code">positions</code> information is given then only parts of the document which allow a valid substitution by an entity are considered. Otherwise a simple text substitution without further check is done.</p>

<p>Note that in general the entity resolution in XML documents is a complicated and non-reversible task. But nevertheless this utility may be useful in not too complicated situations.</p>

<p><a id="X86589C5C859ACE38" name="X86589C5C859ACE38"></a></p>

<h5>5.2-4 DisplayXMLStructure</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; DisplayXMLStructure</code>( <var class="Arg">tree</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This utility displays the tree structure of an XML document as it is returned by <code class="func">ParseTreeXMLString</code> (<a href="chap5.html#X847EB8498151D443"><b>5.2-1</b></a>) (without the <code class="code">PCDATA</code> leaves).</p>

<p>Since this is usually quite long the result is shown using the <code class="func">Pager</code> (<a href="../../../doc/htm/ref/CHAP002.htm#SECT004"><b>Reference: Pager</b></a>).</p>

<p><a id="X7A7B223A83E38B40" name="X7A7B223A83E38B40"></a></p>

<h5>5.2-5 ApplyToNodesParseTree</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ApplyToNodesParseTree</code>( <var class="Arg">tree, fun</var> )</td><td class="tdright">( function )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; AddRootParseTree</code>( <var class="Arg">tree</var> )</td><td class="tdright">( function )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; RemoveRootParseTree</code>( <var class="Arg">tree</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>The function <code class="func">ApplyToNodesParseTree</code> applies a function <var class="Arg">fun</var> to all nodes of the parse tree <var class="Arg">tree</var> of an XML document returned by <code class="func">ParseTreeXMLString</code> (<a href="chap5.html#X847EB8498151D443"><b>5.2-1</b></a>).</p>

<p>The function <code class="func">AddRootParseTree</code> is an application of this. It adds to all nodes a component <code class="code">.root</code> to which the top node tree <var class="Arg">tree</var> is assigned. These components can be removed afterwards with <code class="func">RemoveRootParseTree</code>.</p>

<p>Here are two more utilities which use <code class="func">ApplyToNodesParseTree</code>.</p>

<p><a id="X7F76D4A27C7FB946" name="X7F76D4A27C7FB946"></a></p>

<h5>5.2-6 GetTextXMLTree</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; GetTextXMLTree</code>( <var class="Arg">tree</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>a string</p>

<p>The argument <var class="Arg">tree</var> must be a node of a parse tree of some XML document, see <code class="func">ParseTreeXMLFile</code> (<a href="chap5.html#X847EB8498151D443"><b>5.2-1</b></a>). This function collects the content of this and all included elements recursively into a string.</p>

<p><a id="X8466F74C80442F7D" name="X8466F74C80442F7D"></a></p>

<h5>5.2-7 XMLElements</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; XMLElements</code>( <var class="Arg">tree, eltnames</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>a list of nodes</p>

<p>The argument <var class="Arg">tree</var> must be a node of a parse tree of some XML document, see <code class="func">ParseTreeXMLFile</code> (<a href="chap5.html#X847EB8498151D443"><b>5.2-1</b></a>). This function returns a list of all subnodes of <var class="Arg">tree</var> (possibly including <var class="Arg">tree</var>) of elements with name given in the list of strings <var class="Arg">eltnames</var>. Use <code class="code">"PCDATA"</code> as name for leave nodes which contain the actual text of the document. As an abbreviation <var class="Arg">eltnames</var> can also be a string which is then put in a one element list.</p>

<p>And here are utilities for processing <strong class="pkg">GAPDoc</strong> XML documents.</p>

<p><a id="X84CFF72484B19C0D" name="X84CFF72484B19C0D"></a></p>

<h5>5.2-8 CheckAndCleanGapDocTree</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; CheckAndCleanGapDocTree</code>( <var class="Arg">tree</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>nothing</p>

<p>The argument <var class="Arg">tree</var> of this function is a parse tree from <code class="func">ParseTreeXMLString</code> (<a href="chap5.html#X847EB8498151D443"><b>5.2-1</b></a>) of some <strong class="pkg">GAPDoc</strong> document. This function does an (incomplete) validity check of the document according to the document type declaration in <code class="file">gapdoc.dtd</code>. It also does some additional checks which cannot be described in the DTD (like checking whether chapters and sections have a heading). For elements with element content the whitespace between these elements is removed.</p>

<p>In case of an error the break loop is entered and the position of the error in the original XML document is printed. With <code class="code">Show();</code> one can browse the original input in the <code class="func">Pager</code> (<a href="../../../doc/htm/ref/CHAP002.htm#SECT004"><b>Reference: Pager</b></a>).</p>

<p><a id="X84062CD67B286FF0" name="X84062CD67B286FF0"></a></p>

<h5>5.2-9 AddParagraphNumbersGapDocTree</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; AddParagraphNumbersGapDocTree</code>( <var class="Arg">tree</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>nothing</p>

<p>The argument <var class="Arg">tree</var> must be an XML tree returned by <code class="func">ParseTreeXMLString</code> (<a href="chap5.html#X847EB8498151D443"><b>5.2-1</b></a>) applied to a <strong class="pkg">GAPDoc</strong> document. This function adds to each node of the tree a component <code class="code">.count</code> which is of form <code class="code">[Chapter[, Section[, Subsection, Paragraph] ] ]</code>. Here the first three numbers should be the same as produced by the LaTeX version of the document. Text before the first chapter is counted as chapter <code class="code">0</code> and similarly for sections and subsections. Some elements are always considered to start a new paragraph.</p>

<p><a id="X78A22C58841E5D0B" name="X78A22C58841E5D0B"></a></p>

<h5>5.2-10 InfoXMLParser</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; InfoXMLParser</code></td><td class="tdright">( info class )</td></tr></table></div>
<p>The default level of this info class is 1. Functions like <code class="func">ParseTreeXMLString</code> (<a href="chap5.html#X847EB8498151D443"><b>5.2-1</b></a>) are then printing some information, in particular in case of errors. You can suppress it by setting the level of <code class="func">InfoXMLParser</code> to 0. With level 2 there may be some more information for debugging purposes.</p>

<p><a id="X8560E1A2845EC2C1" name="X8560E1A2845EC2C1"></a></p>

<h4>5.3 <span class="Heading">The Converters</span></h4>

<p>Here are more details about the conversion programs for <strong class="pkg">GAPDoc</strong> XML documents.</p>

<p><a id="X85BE6DF178423EF5" name="X85BE6DF178423EF5"></a></p>

<h5>5.3-1 GAPDoc2LaTeX</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; GAPDoc2LaTeX</code>( <var class="Arg">tree</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>LaTeX document as string</p>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; SetGapDocLaTeXOptions</code>( <var class="Arg">[...]</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>Nothing</p>

<p>The argument <var class="Arg">tree</var> for this function is a tree describing a <strong class="pkg">GAPDoc</strong> XML document as returned by <code class="func">ParseTreeXMLString</code> (<a href="chap5.html#X847EB8498151D443"><b>5.2-1</b></a>) (probably also checked with <code class="func">CheckAndCleanGapDocTree</code> (<a href="chap5.html#X84CFF72484B19C0D"><b>5.2-8</b></a>)). The output is a string containing a version of the document which can be written to a file and processed with LaTeX or pdfLaTeX (and probably BibTeX and <code class="code">makeindex</code>).</p>

<p>The output uses the <code class="code">report</code> document class and needs the following LaTeX packages: <code class="code">a4wide</code>, <code class="code">amssymb</code>, <code class="code">inputenc</code>, <code class="code">makeidx</code>, <code class="code">color</code>, <code class="code">fancyvrb</code>, <code class="code">pslatex</code> and <code class="code">hyperref</code>. These are for example provided by the <strong class="pkg">teTeX-1.0</strong> or <strong class="pkg">texlive</strong> distributions of TeX (which in turn are used for most TeX packages of current Linux distributions); see <span class="URL"><a href="http://www.tug.org/tetex/">http://www.tug.org/tetex/</a></span>.</p>

<p>In particular, the resulting <code class="code">pdf</code>-output (and <code class="code">dvi</code>-output) contains (internal and external) hyperlinks which can be very useful for online browsing of the document.</p>

<p>The LaTeX processing also produces a file with extension <code class="code">.pnr</code> which is <strong class="pkg">GAP</strong> readable and contains the page numbers for all (sub)sections of the document. This can be used by <strong class="pkg">GAP</strong>'s online help; see <code class="func">AddPageNumbersToSix</code> (<a href="chap5.html#X7EB5E86F87A09F94"><b>5.3-4</b></a>). There is support for two types of XML processing instructions which allow to change the options used for the document class or to add some extra lines to the preamble of the LaTeX document. They can be specified as in the following examples:</p>


<table class="example">
<tr><td><pre>
&lt;?LaTeX Options="12pt"?&gt;
&lt;?LaTeX ExtraPreamble="\usepackage{blabla}
\newcommand{\bla}{blabla}
"?&gt;
</pre></td></tr></table>

<p>Non-ASCII characters in the <strong class="pkg">GAPDoc</strong> document are translated to LaTeX input in ASCII-encoding with the help of <code class="func">Encode</code> (<a href="chap6.html#X818A31567EB30A39"><b>6.2-2</b></a>) and the option <code class="code">"LaTeX"</code>. See the documentation of <code class="func">Encode</code> (<a href="chap6.html#X818A31567EB30A39"><b>6.2-2</b></a>) for how to proceed if you have a character which is not handled (yet).</p>

<p>A hint for large documents: In many TeX installations one can easily reach some memory limitations with documents which contain many (cross-)references. In <strong class="pkg">teTeX</strong> you can look for a file <code class="file">texmf.cnf</code> which allows to enlarge certain memory sizes.</p>

<p>This function works by running recursively through the document tree and calling a handler function for each <strong class="pkg">GAPDoc</strong> XML element. Many of these handler functions (usually in <code class="code">GAPDoc2LaTeXProcs.&lt;ElementName&gt;</code>) are not difficult to understand (the greatest complications are some commands for index entries, labels or the output of page number information). So it should be easy to adjust layout details to your own taste by slight modifications of the program.</p>

<p>A few settings can be adjusted by the function <code class="func">SetGapDocLaTeXOptions</code>. It takes strings as arguments. If the arguments contain one of the strings <code class="code">"pdf"</code>, <code class="code">"dvi"</code> or <code class="code">"ps"</code> then LaTeXs <code class="code">hyperref</code> package is configured for optimized output of the given format (default is <code class="code">"pdf"</code>). If <code class="code">"color"</code> or <code class="code">"nocolor"</code> is in the argument list then colors are used or not used, respectively. The default is to use colors but <code class="code">"nocolor"</code> can be useful for a printable version of a manual (but who wants to print such manuals?). If "utf8" is an argument then the package <code class="code">inputenc</code> is used with <code class="code">UTF-8</code> encoding, instead of the default <code class="code">latin1</code>. If <code class="code">"nopslatex"</code> is an argument then the package <code class="code">pslatex</code> is not used, otherwise it is.</p>

<p><a id="X86CD0B197CD58D2A" name="X86CD0B197CD58D2A"></a></p>

<h5>5.3-2 GAPDoc2Text</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; GAPDoc2Text</code>( <var class="Arg">tree[, bibpath][, width]</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>record containing text files as strings and other information</p>

<p>The argument <var class="Arg">tree</var> for this function is a tree describing a <strong class="pkg">GAPDoc</strong> XML document as returned by <code class="func">ParseTreeXMLString</code> (<a href="chap5.html#X847EB8498151D443"><b>5.2-1</b></a>) (probably also checked with <code class="func">CheckAndCleanGapDocTree</code> (<a href="chap5.html#X84CFF72484B19C0D"><b>5.2-8</b></a>)). This function produces a text version of the document which can be used with <strong class="pkg">GAP</strong>'s online help (with the <code class="code">"screen"</code> viewer, see <code class="func">SetHelpViewer</code> (<a href="../../../doc/htm/ref/CHAP002.htm#SECT003"><b>Reference: SetHelpViewer</b></a>)). It includes title page, bibliography and index. The bibliography is made from BibXMLext or BibTeX databases, see <a href="chap7.html#X7EB94CE97ABF7192"><b>7</b></a>. Their location must be given with the argument <var class="Arg">bibpath</var> (as string or directory object).</p>

<p>The output is a record with one component for each chapter (with names <code class="code">"0"</code>, <code class="code">"1"</code>, ..., <code class="code">"Bib"</code> and <code class="code">"Ind"</code>). Each such component is again a record with the following components:</p>


<dl>
<dt><strong class="Mark"><code class="code">text</code></strong></dt>
<dd><p>the text of the whole chapter as a string</p>

</dd>
<dt><strong class="Mark"><code class="code">ssnr</code></strong></dt>
<dd><p>list of subsection numbers in this chapter (like <code class="code">[3, 2, 1]</code> for chapter 3, section 2, subsection 1)</p>

</dd>
<dt><strong class="Mark"><code class="code">linenr</code></strong></dt>
<dd><p>corresponding list of line numbers where the subsections start</p>

</dd>
<dt><strong class="Mark"><code class="code">len</code></strong></dt>
<dd><p>number of lines of this chapter</p>

</dd>
</dl>
<p>The result can be written into files with the command <code class="func">GAPDoc2TextPrintTextFiles</code> (<a href="chap5.html#X7DFCE7357D6032A2"><b>5.3-3</b></a>).</p>

<p>As a side effect this function also produces the <code class="file">manual.six</code> information which is used for searching in <strong class="pkg">GAP</strong>'s online help. This is stored in <code class="code"><var class="Arg">tree</var>.six</code> and can be printed into a <code class="file">manual.six</code> file with <code class="func">PrintSixFile</code> (<a href="chap5.html#X7D42CFED7885BC00"><b>5.3-5</b></a>) (preferably after producing a LaTeX version of the document as well and adding the page number information to <code class="code"><var class="Arg">tree</var>.six</code>, see <code class="func">GAPDoc2LaTeX</code> (<a href="chap5.html#X85BE6DF178423EF5"><b>5.3-1</b></a>) and <code class="func">AddPageNumbersToSix</code> (<a href="chap5.html#X7EB5E86F87A09F94"><b>5.3-4</b></a>)).</p>

<p>The text produced by this function contains some markup via ANSI escape sequences. The sequences used here are usually ignored by terminals. But the <strong class="pkg">GAP</strong> help system will substitute them by interpreted color and attribute sequences (see <code class="func">TextAttr</code> (<a href="chap6.html#X785F61E77899580E"><b>6.1-2</b></a>)) before displaying them. There is a default markup used for this but it can also be configured by the user, see <code class="func">SetGAPDocTextTheme</code> (<a href="chap5.html#X7DEB37417BBD8941"><b>5.3-6</b></a>). Furthermore, the text produced is in UTF-8 encoding. The encoding is also translated on the fly, if <code class="code">GAPInfo.TermEncoding</code> is set to some encoding supported by <code class="func">Encode</code> (<a href="chap6.html#X818A31567EB30A39"><b>6.2-2</b></a>), e.g., <code class="code">"ISO-8859-1"</code> or <code class="code">"latin1"</code>.</p>

<p>With the optional argument <var class="Arg">width</var> a different length of the output text lines can be chosen. The default is 76 and all lines in the resulting text start with two spaces. This looks good on a terminal with a standard width of 80 characters and you probably don't want to use this argument.</p>

<p><a id="X7DFCE7357D6032A2" name="X7DFCE7357D6032A2"></a></p>

<h5>5.3-3 GAPDoc2TextPrintTextFiles</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; GAPDoc2TextPrintTextFiles</code>( <var class="Arg">t[, path]</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>nothing</p>

<p>The first argument must be a result returned by <code class="func">GAPDoc2Text</code> (<a href="chap5.html#X86CD0B197CD58D2A"><b>5.3-2</b></a>). The second argument is a path for the files to write, it can be given as string or directory object. The text of each chapter is written into a separate file with name <code class="file">chap0.txt</code>, <code class="file">chap1.txt</code>, ..., <code class="file">chapBib.txt</code>, and <code class="file">chapInd.txt</code>.</p>

<p>If you want to make your document accessible via the <strong class="pkg">GAP</strong> online help you must put at least these files for the text version into a directory, together with the file <code class="file">manual.six</code>, see <code class="func">PrintSixFile</code> (<a href="chap5.html#X7D42CFED7885BC00"><b>5.3-5</b></a>). Then specify the path to the <code class="file">manual.six</code> file in the packages <code class="file">PackageInfo.g</code> file, see <a href="../../../doc/htm/ext/CHAP004.htm#SECT005"><b>Extending: The PackageInfo.g File</b></a>.</p>

<p>Optionally you can add the <code class="code">dvi</code>- and <code class="code">pdf</code>-versions of the document which are produced with <code class="func">GAPDoc2LaTeX</code> (<a href="chap5.html#X85BE6DF178423EF5"><b>5.3-1</b></a>) to this directory. The files must have the names <code class="file">manual.dvi</code> and <code class="file">manual.pdf</code>, respectively. Also you can add the files of the HTML version produced with <code class="func">GAPDoc2HTML</code> (<a href="chap5.html#X84F22EEB78845CFD"><b>5.3-7</b></a>) to this directory, see <code class="func">GAPDoc2HTMLPrintHTMLFiles</code> (<a href="chap5.html#X84A7007778073E7A"><b>5.3-8</b></a>). The handler functions in <strong class="pkg">GAP</strong> for this help format detect automatically which of the optional formats of a book are actually available.</p>

<p><a id="X7EB5E86F87A09F94" name="X7EB5E86F87A09F94"></a></p>

<h5>5.3-4 AddPageNumbersToSix</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; AddPageNumbersToSix</code>( <var class="Arg">tree, pnrfile</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>nothing</p>

<p>Here <var class="Arg">tree</var> must be the XML tree of a <strong class="pkg">GAPDoc</strong> document, returned by <code class="func">ParseTreeXMLString</code> (<a href="chap5.html#X847EB8498151D443"><b>5.2-1</b></a>). Running <code class="code">latex</code> on the result of <code class="func">GAPDoc2LaTeX</code> (<a href="chap5.html#X85BE6DF178423EF5"><b>5.3-1</b></a>)<code class="code">(<var class="Arg">tree</var>)</code> produces a file <var class="Arg">pnrfile</var> (with extension <code class="code">.pnr</code>). The command <code class="func">GAPDoc2Text</code> (<a href="chap5.html#X86CD0B197CD58D2A"><b>5.3-2</b></a>)<code class="code">(<var class="Arg">tree</var>)</code> creates a component <code class="code"><var class="Arg">tree</var>.six</code> which contains all information about the document for the <strong class="pkg">GAP</strong> online help, except the page numbers in the <code class="code">.dvi, .ps, .pdf</code> versions of the document. This command adds the missing page number information to <code class="code"><var class="Arg">tree</var>.six</code>.</p>

<p><a id="X7D42CFED7885BC00" name="X7D42CFED7885BC00"></a></p>

<h5>5.3-5 PrintSixFile</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; PrintSixFile</code>( <var class="Arg">tree, bookname, fname</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>nothing</p>

<p>This function prints the <code class="code">.six</code> file <var class="Arg">fname</var> for a <strong class="pkg">GAPDoc</strong> document stored in <var class="Arg">tree</var> with name <var class="Arg">bookname</var>. Such a file contains all information about the book which is needed by the <strong class="pkg">GAP</strong> online help. This information must first be created by calls of <code class="func">GAPDoc2Text</code> (<a href="chap5.html#X86CD0B197CD58D2A"><b>5.3-2</b></a>) and <code class="func">AddPageNumbersToSix</code> (<a href="chap5.html#X7EB5E86F87A09F94"><b>5.3-4</b></a>).</p>

<p><a id="X7DEB37417BBD8941" name="X7DEB37417BBD8941"></a></p>

<h5>5.3-6 SetGAPDocTextTheme</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; SetGAPDocTextTheme</code>( <var class="Arg">[optrec]</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>nothing</p>

<p>With this function can readers of the screen version of <strong class="pkg">GAP</strong> manuals which are generated by the <strong class="pkg">GAPDoc</strong> package configure the color and attribute layout of the displayed text. There is a default which can be reset by calling this function without argument.</p>

<p>As an abbreviation the argument <var class="Arg">optrec</var> can be a string for the known name of a theme. Currently, there is only <code class="code">"none"</code> which displays just the plain text without any markup.</p>

<p>Otherwise, <var class="Arg">optrec</var> must be a record. Its entries overwrite the corresponding entries in the default. To construct valid markup you can use <code class="func">TextAttr</code> (<a href="chap6.html#X785F61E77899580E"><b>6.1-2</b></a>). The following components are recognized:</p>


<dl>
<dt><strong class="Mark"><code class="code">reset</code></strong></dt>
<dd><p>reset to default, don't change this</p>

</dd>
<dt><strong class="Mark"><code class="code">Heading</code></strong></dt>
<dd><p>chapter and (sub-)section headings</p>

</dd>
<dt><strong class="Mark"><code class="code">Func</code></strong></dt>
<dd><p>function, operation, ... names</p>

</dd>
<dt><strong class="Mark"><code class="code">Arg</code></strong></dt>
<dd><p>argument names in descriptions</p>

</dd>
<dt><strong class="Mark"><code class="code">Example</code></strong></dt>
<dd><p>example code</p>

</dd>
<dt><strong class="Mark"><code class="code">Package</code></strong></dt>
<dd><p>package names</p>

</dd>
<dt><strong class="Mark"><code class="code">Returns</code></strong></dt>
<dd><p>Returns-line in descriptions</p>

</dd>
<dt><strong class="Mark"><code class="code">URL</code></strong></dt>
<dd><p>URLs</p>

</dd>
<dt><strong class="Mark"><code class="code">Mark</code></strong></dt>
<dd><p>Marks in description lists</p>

</dd>
<dt><strong class="Mark"><code class="code">K</code></strong></dt>
<dd><p><strong class="pkg">GAP</strong> keywords</p>

</dd>
<dt><strong class="Mark"><code class="code">C</code></strong></dt>
<dd><p>code or text to type</p>

</dd>
<dt><strong class="Mark"><code class="code">F</code></strong></dt>
<dd><p>file names</p>

</dd>
<dt><strong class="Mark"><code class="code">B</code></strong></dt>
<dd><p>buttons</p>

</dd>
<dt><strong class="Mark"><code class="code">Emph</code></strong></dt>
<dd><p>emphasized text</p>

</dd>
<dt><strong class="Mark"><code class="code">Ref</code></strong></dt>
<dd><p>reference text</p>

</dd>
<dt><strong class="Mark"><code class="code">BibReset</code></strong></dt>
<dd><p>reset for bibliography, don't change</p>

</dd>
<dt><strong class="Mark"><code class="code">BibAuthor</code></strong></dt>
<dd><p>author names in bibliography</p>

</dd>
<dt><strong class="Mark"><code class="code">BibTitle</code></strong></dt>
<dd><p>titles in bibliography</p>

</dd>
<dt><strong class="Mark"><code class="code">BibJournal</code></strong></dt>
<dd><p>journal names in bibliography</p>

</dd>
<dt><strong class="Mark"><code class="code">BibVolume</code></strong></dt>
<dd><p>volume number in bibliography</p>

</dd>
<dt><strong class="Mark"><code class="code">BibLabel</code></strong></dt>
<dd><p>labels for bibliography entries</p>

</dd>
</dl>

<table class="example">
<tr><td><pre>
gap&gt; # change display of headings to bold green
gap&gt; SetGAPDocTextTheme(rec(
&gt;              Heading:=Concatenation(TextAttr.bold, TextAttr.2)));
</pre></td></tr></table>

<p><a id="X84F22EEB78845CFD" name="X84F22EEB78845CFD"></a></p>

<h5>5.3-7 GAPDoc2HTML</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; GAPDoc2HTML</code>( <var class="Arg">tree[, bibpath[, gaproot]][, mtrans]</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>record containing HTML files as strings and other information</p>

<p>The argument <var class="Arg">tree</var> for this function is a tree describing a <strong class="pkg">GAPDoc</strong> XML document as returned by <code class="func">ParseTreeXMLString</code> (<a href="chap5.html#X847EB8498151D443"><b>5.2-1</b></a>) (probably also checked with <code class="func">CheckAndCleanGapDocTree</code> (<a href="chap5.html#X84CFF72484B19C0D"><b>5.2-8</b></a>)). Without an <var class="Arg">mtrans</var> argument this function produces an HTML version of the document which can be read with any Web-browser and also be used with <strong class="pkg">GAP</strong>'s online help (see <code class="func">SetHelpViewer</code> (<a href="../../../doc/htm/ref/CHAP002.htm#SECT003"><b>Reference: SetHelpViewer</b></a>)). It includes title page, bibliography, and index. The bibliography is made from BibTeX databases. Their location must be given with the argument <var class="Arg">bibpath</var> (as string or directory object, if not given the current directory is used). If the third argument <var class="Arg">gaproot</var> is given and is a string then this string is interpreted as relative path to <strong class="pkg">GAP</strong>'s main root directory. Reference-URLs to external HTML-books which begin with the <strong class="pkg">GAP</strong> root path are then rewritten to start with the given relative path. This makes the HTML-documentation portable provided a package is installed in some standard location below the <strong class="pkg">GAP</strong> root.</p>

<p>The output is a record with one component for each chapter (with names <code class="code">"0"</code>, <code class="code">"1"</code>, ..., <code class="code">"Bib"</code>, and <code class="code">"Ind"</code>). Each such component is again a record with the following components:</p>


<dl>
<dt><strong class="Mark"><code class="code">text</code></strong></dt>
<dd><p>the text of an HTML file containing the whole chapter (as a string)</p>

</dd>
<dt><strong class="Mark"><code class="code">ssnr</code></strong></dt>
<dd><p>list of subsection numbers in this chapter (like <code class="code">[3, 2, 1]</code> for chapter 3, section 2, subsection 1)</p>

</dd>
</dl>
<p><em>Standard output format without</em> <var class="Arg">mtrans</var> <em>argument</em></p>

<p>The HTML code produced with this converter conforms to the W3C specification "XHTML 1.0 strict", see <span class="URL"><a href="http://www.w3.org/TR/xhtml1">http://www.w3.org/TR/xhtml1</a></span>. First, this means that the HTML files are valid XML files. Secondly, the extension "strict" says in particular that the code doesn't contain any explicit font or color information.</p>

<p>Mathematical formulae are handled as in the text converter <code class="func">GAPDoc2Text</code> (<a href="chap5.html#X86CD0B197CD58D2A"><b>5.3-2</b></a>). We don't want to assume that the browser can use symbol fonts. Some <strong class="pkg">GAP</strong> users like to browse the online help with <code class="code">lynx</code>, see <code class="func">SetHelpViewer</code> (<a href="../../../doc/htm/ref/CHAP002.htm#SECT003"><b>Reference: SetHelpViewer</b></a>), which runs inside the same terminal windows as <strong class="pkg">GAP</strong>.</p>

<p><em>Using a stylesheet file</em></p>

<p>The layout information for a browser should be specified in a cascading style sheet (CSS) file. The <strong class="pkg">GAPDoc</strong> package contains an example of such a style sheet, see the file <code class="file">gapdoc.css</code> in the root directory of the package. This file conforms to the W3C specification CSS 2.0, see <span class="URL"><a href="http://www.w3.org/TR/REC-CSS2">http://www.w3.org/TR/REC-CSS2</a></span>. You may just copy that file as <code class="file">manual.css</code> into the directory which contains the HTML version of your documentation. But, of course, you are free to adjust it for your package, e.g., change colors or other layout details, add a background image, ... Each of the HTML files produced by the converters contains a link to this local style sheet file called <code class="file">manual.css</code>.</p>

<p><em>Output format with</em> <var class="Arg">mtrans</var> argument</p>

<p>Currently, there are two experimental variants of this converter available which handle mathematical formulae differently. They are accessed via the optional last <var class="Arg">mtrans</var> argument.</p>

<p>If this argument is set to <code class="code">"Tth"</code> it is assumed that you have installed the LaTeX to HTML translation program <code class="code">tth</code>. This is used to translate the contents of the <code class="code">M</code>, <code class="code">Math</code> and <code class="code">Display</code> elements into HTML code. Note that the resulting code is not compliant with any standard. Formally it is "XHTML 1.0 Transitional", it contains explicit font specifications and the characters of mathematical symbols are included via their position in a "Symbol" font. Some graphical browsers can be configured to display this in a useful manner, check <span class="URL"><a href="http://hutchinson.belmont.ma.us/tth/">the Tth homepage</a></span> for more details.</p>

<p>If the <var class="Arg">mtrans</var> argument is set to <code class="code">"MathML"</code> it is assumed that you have installed the translation program <code class="code">ttm</code>, see also <span class="URL"><a href="http://hutchinson.belmont.ma.us/tth/">the Tth homepage</a></span>). This is used to translate the contents of the <code class="code">M</code>, <code class="code">Math</code> and <code class="code">Display</code> elements to MathML 2.0 markup. The resulting files should conform to the "XHTML 1.1 plus MathML 2.0" standard, see <span class="URL"><a href="http://www.w3.org/TR/MathML2/">the W3C information</a></span> for more details. It is expected that the next generation of graphical browsers will be able to render such files (try for example <code class="code">Mozilla</code>, at least 0.9.9). You must copy the <code class="code">.xsl</code> and <code class="code">.css</code> files from <strong class="pkg">GAPDoc</strong>s <code class="file">mathml</code> directory to the directory containing the output files. The translation with <code class="code">ttm</code> is still experimental. The output of this converter variant is garbage for browsers which don't support MathML.</p>

<p>This function works by running recursively through the document tree and calling a handler function for each <strong class="pkg">GAPDoc</strong> XML element. Many of these handler functions (usually in <code class="code">GAPDoc2TextProcs.&lt;ElementName&gt;</code>) are not difficult to understand (the greatest complications are some commands for index entries, labels or the output of page number information). So it should be easy to adjust certain details to your own taste by slight modifications of the program.</p>

<p>The result of this converter can be written to files with the command <code class="func">GAPDoc2HTMLPrintHTMLFiles</code> (<a href="chap5.html#X84A7007778073E7A"><b>5.3-8</b></a>).</p>

<p><a id="X84A7007778073E7A" name="X84A7007778073E7A"></a></p>

<h5>5.3-8 GAPDoc2HTMLPrintHTMLFiles</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; GAPDoc2HTMLPrintHTMLFiles</code>( <var class="Arg">t[, path]</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>nothing</p>

<p>The first argument must be a result returned by <code class="func">GAPDoc2HTML</code> (<a href="chap5.html#X84F22EEB78845CFD"><b>5.3-7</b></a>). The second argument is a path for the files to write, it can be given as string or directory object. The text of each chapter is written into a separate file with name <code class="file">chap0.html</code>, <code class="file">chap1.html</code>, ..., <code class="file">chapBib.html</code>, and <code class="file">chapInd.html</code>.</p>

<p>The experimental versions which are produced with <code class="code">tth</code> or <code class="code">ttm</code> use different names for the files, namely <code class="file">chap0_sym.html</code>, and so on for files which need symbol fonts and <code class="file">chap0_mml.xml</code> for files with MathML translations.</p>

<p>You may also want to place a style sheet file <code class="file">manual.css</code> into the same directory as the HTML files. You can copy for example the file <code class="file">gapdoc.css</code> in the root directory of the <strong class="pkg">GAPDoc</strong> package (<code class="code">Filename( Directory( PackageInfo( "gapdoc" )[1].InstallationPath), "gapdoc.css");</code>).</p>

<p><a id="X864A528B81C661A2" name="X864A528B81C661A2"></a></p>

<h5>5.3-9 InfoGAPDoc</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; InfoGAPDoc</code></td><td class="tdright">( info class )</td></tr></table></div>
<p>The default level of this info class is 1. The converter functions for <strong class="pkg">GAPDoc</strong> documents are then printing some information. You can suppress this by setting the level of <code class="func">InfoGAPDoc</code> to 0. With level 2 there may be some more information for debugging purposes.</p>

<p><a id="X82AB468887ED0DBB" name="X82AB468887ED0DBB"></a></p>

<h5>5.3-10 SetGapDocLanguage</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; SetGapDocLanguage</code>( <var class="Arg">[lang]</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>nothing</p>

<p>The <strong class="pkg">GAPDoc</strong> converter programs sometimes produce text which is not explicit in the document, e.g., headers like "Abstract", "Appendix", links to "Next Chapter", variable types "function" and so on.</p>

<p>With <code class="func">SetGapDocLanguage</code> the language for these texts can be changed. The argument <var class="Arg">lang</var> must be a string. Calling without argument or with a language name for which no translations are available is the same as using the default <code class="code">"english"</code>.</p>

<p>If your language <var class="Arg">lang</var> is not yet available, look at the record <code class="code">GAPDocTexts.english</code> and translate all the strings to <var class="Arg">lang</var>. Then assign this record to <code class="code">GAPDocTexts.(<var class="Arg">lang</var>)</code> and send it to the <strong class="pkg">GAPDoc</strong> authors for inclusion in future versions of <strong class="pkg">GAPDoc</strong>. (Currently, there are translations for <code class="code">english</code>, <code class="code">german</code>, <code class="code">russian</code> and <code class="code">ukrainian</code>.)</p>

<p><em>Further hints:</em> To get strings produced by LaTeX right you will probably use the <code class="code">babel</code> package with option <var class="Arg">lang</var>, see the information on <code class="code">ExtraPreamble</code> in <code class="func">GAPDoc2LaTeX</code> (<a href="chap5.html#X85BE6DF178423EF5"><b>5.3-1</b></a>). If <var class="Arg">lang</var> cannot be encoded in <code class="code">latin1</code> encoding you can consider the use of <code class="code">"utf8"</code> with <code class="func">SetGapDocLaTeXOptions</code> (<a href="chap5.html#X85BE6DF178423EF5"><b>5.3-1</b></a>).</p>

<p><a id="X800299827B88ABBE" name="X800299827B88ABBE"></a></p>

<h4>5.4 <span class="Heading">Testing Manual Examples</span></h4>

<p>We also provide some tools to check the examples given in <code class="code">&lt;Example&gt;</code>-elements.</p>

<p><a id="X7AD38E77784572A1" name="X7AD38E77784572A1"></a></p>

<h5>5.4-1 ManualExamples</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ManualExamples</code>( <var class="Arg">path, main, files, units</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>a list of strings</p>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ManualExamplesXMLTree</code>( <var class="Arg">tree, units</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>a list of strings</p>

<p>The argument <var class="Arg">tree</var> must be a parse tree of a <strong class="pkg">GAPDoc</strong> document, see <code class="func">ParseTreeXMLFile</code> (<a href="chap5.html#X847EB8498151D443"><b>5.2-1</b></a>). The function <code class="func">ManualExamplesXMLTree</code> returns a list of strings containing the content of <code class="code">&lt;Example&gt;</code> elements. For each example there is a comment line showing the paragraph number and (if available) the original location of this example with file and line number. Depending on the argument <var class="Arg">units</var> several examples are colleected in one string. Recognized values for <var class="Arg">units</var> are <code class="code">"Chapter"</code>, <code class="code">"Section"</code>, <code class="code">"Subsection"</code> or <code class="code">"Single"</code>. The latter means that each example is in a separate string. For all other value of <var class="Arg">units</var> just one string with all examples is returned.</p>

<p>The arguments <var class="Arg">path</var>, <var class="Arg">main</var> and <var class="Arg">files</var> of <code class="func">ManualExamples</code> are the same as for <code class="func">ComposedDocument</code> (<a href="chap4.html#X857D77557D12559D"><b>4.2-1</b></a>). This function first contructs and parses the <strong class="pkg">GAPDoc</strong> document and then applies <code class="func">ManualExamplesXMLTree</code>.</p>

<p><a id="X7F2555E07C499554" name="X7F2555E07C499554"></a></p>

<h5>5.4-2 ReadTestExamplesString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ReadTestExamplesString</code>( <var class="Arg">str</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b><code class="keyw">true</code> or <code class="keyw">false</code></p>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; TestExamplesString</code>( <var class="Arg">str[, print]</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b><code class="keyw">true</code> or a list of records</p>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; TestManualExamples</code>( <var class="Arg">[tree, ][path, main, files]</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b><code class="keyw">true</code> or a list of records</p>

<p>The argument <var class="Arg">str</var> must be a string containing lines for the test mode of <strong class="pkg">GAP</strong>. The function <code class="func">ReadTestExamplesString</code> just runs <code class="func">ReadTest</code> (<a href="../../../doc/htm/ref/CHAP007.htm#SECT009"><b>Reference: ReadTest</b></a>) on this code.</p>

<p>The function <code class="func">TestExamplesString</code> returns <code class="keyw">true</code> if <code class="func">ReadTest</code> (<a href="../../../doc/htm/ref/CHAP007.htm#SECT009"><b>Reference: ReadTest</b></a>) does not find differences. In the other case it returns a list of records, where each record describes one difference. The records have fields <code class="code">.line</code> with the line number of the relevant input line of <var class="Arg">str</var>, <code class="code">.input</code> with the input line and <code class="code">.diff</code> with the differences as displayed by <code class="func">ReadTest</code> (<a href="../../../doc/htm/ref/CHAP007.htm#SECT009"><b>Reference: ReadTest</b></a>). If the optional argument <var class="Arg">print</var> is given and set to <code class="keyw">true</code> then the differences are also printed before the function returns.</p>

<p>The arguments of the function <code class="func">TestManualExamples</code> is either a parse tree of a <strong class="pkg">GAPDoc</strong> document or the information to build and parse such a document. The function extracts all examples in <code class="code">"Single"</code> units and applies <code class="func">TestExamplesString</code> to them.</p>


<table class="example">
<tr><td><pre>
gap&gt; TestExamplesString("gap&gt; 1+1;\n2\n");
true
gap&gt; TestExamplesString("gap&gt; 1+1;\n2\ngap&gt; 2+3;\n4\n");
[ rec( line := 3, input := "gap&gt; 2+3;", diff := "+ 5\n- 4\n" ) ]
gap&gt; TestExamplesString("gap&gt; 1+1;\n2\ngap&gt; 2+3;\n4\n", true);
-----------  bad example --------
line: 3
input: gap&gt; 2+3;
differences:
+ 5
- 4
[ rec( line := 3, input := "gap&gt; 2+3;", diff := "+ 5\n- 4\n" ) ]
</pre></td></tr></table>


<div class="chlinkprevnextbot">&nbsp;<a href="chap0.html">Top of Book</a>&nbsp;  &nbsp;<a href="chap4.html">Previous Chapter</a>&nbsp;  &nbsp;<a href="chap6.html">Next Chapter</a>&nbsp;  </div>


<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chapA.html">A</a>  <a href="chapB.html">B</a>  <a href="chapC.html">C</a>  <a href="chapBib.html">Bib</a>  <a href="chapInd.html">Ind</a>  </div>

<hr />
<p class="foot">generated by <a href="http://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>