Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
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
Project: cocalc-sagemath-dev-slelievre
Views: 4183461<Chapter Label="ch:conv">2<Heading>The Converters and an XML Parser</Heading>34The &GAPDoc; package contains a set of programs which allow us to convert a5&GAPDoc; book into several output versions and to make them available to6&GAP;'s online help.<P/>78Currently the following output formats are provided: text for browsing9inside a terminal running &GAP;, &LaTeX; with <C>hyperref</C>-package for10cross references via hyperlinks and HTML for reading with a Web-browser.<P/>11121314<Section Label="MakeDoc">15<Heading>Producing Documentation from Source Files</Heading>1617Here we explain how to use the functions which are18described in more detail in the following sections. We assume19that we have the main file <F>MyBook.xml</F> of a book20<C>"MyBook"</C> in the directory <F>/my/book/path</F>. This contains21<C><#Include ...></C>-statements as explained in22Chapter <Ref Sect="Distributing"/>. These refer to some other files23as well as pieces of text which are found in the comments of some &GAP;24source files <F>../lib/a.gd</F> and <F>../lib/b.gi</F> (relative to the25path above). A &BibTeX; database <F>MyBook.bib</F> for the citations is26also in the directory given above. We want to produce a text-,27<C>pdf-</C> and HTML-version of the document. (A &LaTeX; version of the28manual is produced, so it is also easy to compile <C>dvi</C>-, and29postscript-versions.)<P/>3031All the commands shown in this Section are collected in the single function32<Ref Func="MakeGAPDocDoc"/>.<P/>3334First we construct the complete XML-document as a string with35<Ref Func="ComposedDocument"/>. This interprets recursively the36<C><#Include ...></C>-statements.3738<Log>39gap> path := Directory("/my/book/path");;40gap> main := "MyBook.xml";;41gap> files := ["../lib/a.gd", "../lib/b.gi"];;42gap> bookname := "MyBook";;43gap> doc := ComposedDocument("GAPDoc", path, main, files, true);;44</Log>4546Now <C>doc</C> is a list with two entries, the first is a string47containing the XML-document, the second gives information from which48files and locations which part of the document was collected. This is49useful in the next step, if there are any errors in the document. <P/>5051Next we parse the document and store its structure in a tree-like data52structure. The commands for this are <Ref Func="ParseTreeXMLString"/> and53<Ref Func="CheckAndCleanGapDocTree"/>.5455<Log>56gap> r := ParseTreeXMLString(doc[1], doc[2]);;57gap> CheckAndCleanGapDocTree(r);58true59</Log>6061We start to produce a text version of the manual, which can be read62in a terminal (window). The command is <Ref Func="GAPDoc2Text"/>.63This produces a record with the actual text and some additional64information. The text can be written chapter-wise into files with65<Ref Func="GAPDoc2TextPrintTextFiles"/>. The names of these files are66<F>chap0.txt</F>, <F>chap1.txt</F> and so on. The text contains some67markup using ANSI escape sequences. This markup is substituted by the68&GAP; help system (user configurable) to show the text with colors69and other attributes. For the bibliography we have to tell <Ref70Func="GAPDoc2Text"/> the location of the &BibTeX; database by specifying71a <C>path</C> as second argument.7273<Log>74gap> t := GAPDoc2Text(r, path);;75gap> GAPDoc2TextPrintTextFiles(t, path);76</Log>7778This command constructs all parts of the document including79table of contents, bibliography and index. The functions <Ref80Func="FormatParagraph"/> for formatting text paragraphs and <Ref81Func="ParseBibFiles"/> for reading &BibTeX; files with &GAP; may be of82independent interest.<P/>8384With the text version we have also produced the information which is85used for searching with &GAP;'s online help. Also, labels are produced86which can be used by links in the HTML- and <C>pdf</C>-versions of the87manual. <P/>8889Next we produce a &LaTeX; version of the document. <Ref90Func="GAPDoc2LaTeX"/> returns a string containing the &LaTeX; source.91The utility function <Ref Func="FileString"/> writes the content of a92string to a file, we choose <F>MyBook.tex</F>.9394<Log>95gap> l := GAPDoc2LaTeX(r);;96gap> FileString(Filename(path, Concatenation(bookname, ".tex")), l);97</Log>9899Assuming that you have a sufficiently good installation of &TeX;100available (see <Ref Func="GAPDoc2LaTeX"/> for details) this can be101processed with a series of commands like in the following example.102103<Log>104cd /my/book/path105pdflatex MyBook106bibtex MyBook107pdflatex MyBook108makeindex MyBook109pdflatex MyBook110mv MyBook.pdf manual.pdf111</Log>112113After this we have a <C>pdf</C>-version of the document in the file114<F>manual.pdf</F>. It contains hyperlink information which can be used115with appropriate browsers for convenient reading of the document on116screen (e.g., <C>xpdf</C> is nice because it allows remote calls to117display named locations of the document). Of course, we could also use118other commands like <C>latex</C> or <C>dvips</C> to process the &LaTeX;119source file.120121Furthermore we have produced a file <F>MyBook.pnr</F> which is122&GAP;-readable and contains the page number information for each123(sub-)section of the document. <P/>124125We can add this page number information to the indexing information126collected by the text converter and then print a <F>manual.six</F> file127which is read by &GAP; when the manual is loaded. This is done with <Ref128Func="AddPageNumbersToSix"/> and <Ref Func="PrintSixFile"/>.129130<Log>131gap> AddPageNumbersToSix(r, Filename(path, "MyBook.pnr"));132gap> PrintSixFile(Filename(path, "manual.six"), r, bookname);133</Log>134135Finally we produce an HTML-version of the document and write it136(chapter-wise) into files <F>chap0.html</F>, <F>chap1.html</F> and137so on. They can be read with any Web-browser. The commands are138<Ref Func="GAPDoc2HTML"/> and <Ref Func="GAPDoc2HTMLPrintHTMLFiles"/>.139We also add a link from <F>manual.html</F> to <F>chap0.html</F>.140You probably want to copy stylesheet files into the same directory,141see <Ref Subsect="StyleSheets"/> for more details. The argument142<C>path</C> of <Ref Func="GAPDoc2HTML"/> specifies the directory143containing the &BibTeX; database files.144145<Log>146gap> h := GAPDoc2HTML(r, path);;147gap> GAPDoc2HTMLPrintHTMLFiles(h, path);148</Log>149150<ManSection >151<Func Arg="path, main, files, bookname[, gaproot]" Name="MakeGAPDocDoc" />152153<Description>154This function collects all the commands for producing a text-,155<C>pdf</C>- and HTML-version of a &GAPDoc; document as described in156Section <Ref Sect="MakeDoc"/>. It checks the <C>.log</C> file from157the call of <C>pdflatex</C> and reports if there are errors, warnings or158overfull boxes.<P/>159160<Emph>Note:</Emph> If this function works for you depends on your161operating system and installed software. It will probably work on most162<C>UNIX</C> systems with a standard &LaTeX; installation. If the163function doesn't work for you look at the source code and adjust it to164your system. <P/>165166Here <A>path</A> must be the directory (as string or directory object)167containing the main file <A>main</A> of the document (given with or168without the <C>.xml</C> extension. The argument <A>files</A> is a list169of (probably source code) files relative to <A>path</A> which contain170pieces of documentation which must be included in the document, see171Chapter <Ref Chap="Distributing"/>. And <A>bookname</A> is the name172of the book used by &GAP;'s online help. The optional argument173<A>gaproot</A> must be a string which gives the relative path from174<A>path</A> to the main &GAP; root directory. If this is given, the HTML175files are produced with relative paths to external books.<P/>176177<Index Key="MathJax" Subkey="in MakeGAPDocDoc"><Package>MathJax</Package>178<Subkey>in <C>MakeGAPDocDoc</C></Subkey></Index>179<Ref Func="MakeGAPDocDoc"/> can be called with additional arguments180<C>"MathJax"</C>, <C>"Tth"</C> and/or <C>"MathML"</C>. If these are181given additional variants of the HTML conversion are called, see <Ref182Func="GAPDoc2HTML"/> for details.<P/>183184It is possible to use &GAPDoc; with other languages than English, see185<Ref Func="SetGapDocLanguage"/> for more details.<P/>186</Description>187</ManSection>188</Section>189190<Section Label="ParseXML">191<Heading>Parsing XML Documents</Heading>192Arbitrary well-formed XML documents can be parsed and browsed by the193following functions.194195<#Include Label="ParseTreeXMLString">196197<#Include Label="StringXMLElement">198199<#Include Label="EntitySubstitution">200201<#Include Label="DisplayXMLStructure">202203<#Include Label="ApplyToNodesParseTree">204205Here are two more utilities which use <Ref206Func="ApplyToNodesParseTree"/>.207208<#Include Label="GetTextXMLTree">209210<#Include Label="XMLElements">211212And here are utilities for processing &GAPDoc; XML documents.213214<#Include Label="CheckAndCleanGapDocTree">215216<#Include Label="AddParagraphNumbersGapDocTree">217218<#Include Label="InfoXMLParser">219220</Section>221222<Section Label="Converters">223<Heading>The Converters</Heading>224Here are more details about the conversion programs for &GAPDoc; XML225documents.226227<#Include Label="GAPDoc2LaTeX">228229<#Include Label="GAPDoc2Text">230231<#Include Label="GAPDoc2TextPrintTextFiles">232233<#Include Label="AddPageNumbersToSix">234235<#Include Label="PrintSixFile">236237<#Include Label="SetGAPDocTextTheme">238239<#Include Label="GAPDoc2HTML">240241<#Include Label="GAPDoc2HTMLPrintHTMLFiles">242243<#Include Label="HTMLStyleSheets">244245<#Include Label="SetGAPDocHTMLStyle">246247<#Include Label="InfoGAPDoc">248249<#Include Label="SetGapDocLanguage">250251</Section>252253<Section Label="Sec:TestExample">254<Index><C>ManualExamples</C></Index>255<Index><C>TestManualExamples</C></Index>256<Heading>Testing Manual Examples</Heading>257We also provide some tools to check and adjust the examples given in258<C><Example></C>-elements. <P/>259Former versions of &GAPDoc; provided functions <C>ManualExamples</C>260and <C>TestManualExamples</C>. These functions are still available,261but no longer documented. Their use is deprecated.262263<#Include Label="ExtractExamples">264265<#Include Label="RunExamples">266267</Section>268269</Chapter>270271272273