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: 418346<Chapter Label="Tutorials">1<Heading>Getting started using &AutoDoc;</Heading>23&AutoDoc; is a &GAP; package which is meant to aid &GAP; package4authors in creating and maintaining the documentation of their packages.5In this capacity it builds upon &GAPDoc;, and is not a replacement6for &GAPDoc;, but rather complements it.<P/>78In this chapter we describe how to get started using &AutoDoc; for your9package. First, we explain in Section <Ref Sect="Tut:Scratch"/> how to write a10new package manual from scratch.<P/>1112Then we show in Section <Ref Sect="Tut:IntegrateExisting"/> how you might13benefit from &AutoDoc; even if you already have a complete manual written14using &GAPDoc;.<P/>1516In Section <Ref Sect="Tut:Scaffolds"/>, we explain how you may use &AutoDoc;17to generate a title page and the main XML file for your manual.18<P/>1920Finally, Section <Ref Sect="Tut:AutoDocWorksheet"/>, explains what21&AutoDoc; worksheets are and how to use them.22<P/>2324<Section Label="Tut:Scratch">25<Heading>Creating a package manual from scratch</Heading>2627Suppose your package is already up and running, but so far has no28manual. Then you can rapidly generate a <Q>scaffold</Q> for a package manual29using the <Ref Func="AutoDoc"/> command like this,30while running &GAP; from within your package's directory (the31one containing the <F>PackageInfo.g</F> file):32<Listing>33LoadPackage( "AutoDoc" );34AutoDoc( rec( scaffold := true ) );35</Listing>36This first reads the <F>PackageInfo.g</F> file from the current37directory. It extracts information about package from it38(such as its name and version, see Section <Ref Sect="Tut:Scaffolds:Title"/>).39It then creates two XML files <F>doc/NAME_OF_YOUR_PACKAGE.xml</F> and40<F>doc/title.xml</F> insider the package directory. Finally, it runs41&GAPDoc; on them to produce a nice initial PDF and HTML version of your42fresh manual.43<P/>4445To ensure that the &GAP; help system picks up your package manual, you46should also add something like the following to your47<F>PackageInfo.g</F>:48<Listing>49PackageDoc := rec(50BookName := ~.PackageName,51ArchiveURLSubset := ["doc"],52HTMLStart := "doc/chap0.html",53PDFFile := "doc/manual.pdf",54SixFile := "doc/manual.six",55LongTitle := ~.Subtitle,56),57</Listing>5859Congratulations, your package now has a minimal working manual. Of60course it will be mostly empty for now, but it already should contain61some useful information, based on the data in your <F>PackageInfo.g</F>.62This includes your package's name, version and description as well as63information about its authors. And if you ever change the package data,64(e.g. because your email address changed), just re-run the above command65to regenerate the two main XML files with the latest information.66<P/>6768Next of course you need to provide actual content (unfortunately, we were69not yet able to automate <E>that</E> for you, more research on artificial intelligence70is required).71To add more content, you have several options: You could add further &GAPDoc;72XML files containing extra chapters, sections and so on. Or you could use classic &GAPDoc;73source comments (in either case, see Section <Ref Sect="Tut:IntegrateExisting"/> on74how to teach the <Ref Func="AutoDoc"/> command to include this extra documentation).75Or you could use the special documentation facilities &AutoDoc; provides (see Section76<Ref Sect="Tut:AdvancedAutoDoc"/>).77<P/>7879You will probably want to re-run the <Ref Func="AutoDoc"/> command80frequently, e.g. whenever you modified your documentation or your81<F>PackageInfo.g</F>. To make this more convenient and reproducible, we82recommend putting its invocation into a file <F>makedoc.g</F> in your package83<Index Key="makedoc.g"><F>makedoc.g</F></Index>84directory, with content based on the following example:85<Listing>86LoadPackage( "AutoDoc" );87AutoDoc( rec( autodoc := true ) );88QUIT;89</Listing>90Then you can regenerate the package manual from the command line with the91following command, executed from within in the package directory:92<Listing>93gap makedoc.g94</Listing>9596</Section>979899<Section Label="Tut:AdvancedAutoDoc">100<Heading>Documenting code with &AutoDoc;</Heading>101102To get one of your global functions, operations, attributes103etc. to appear in the package manual, simply insert an &AutoDoc; comment104of the form <C>#!</C> directly in front of it. For example:105<Listing>106#!107DeclareOperation( "ToricVariety", [ IsConvexObject ] );108</Listing>109110This tiny change is already sufficient to ensure that the operation111appears in the manual. In general, you will want to add further112information about the operation, such as in the following example:113114<Listing><![CDATA[115#! @Arguments conv116#! @Returns a toric variety117#! @Description118#! Creates a toric variety out119#! of the convex object <A>conv</A>.120DeclareOperation( "ToricVariety", [ IsConvexObject ] );121]]></Listing>122123For a thorough description of what you can do with &AutoDoc;124documentation comments, please refer to chapter <Ref Chap="Comments"/>.125<P/>126127<!--128Once we switched AutoDoc itself to use AutoDoc comments,129mention that, i.e. point out that all operations and functions130documented in this manual are documented exactly like131described here, and that one can hence use that as examples.132-->133134<!--135136# <#GAPDoc Label="ToricVarietyConst">137# <ManSection>138# <Oper Arg="conv" Name="ToricVariety"139# Label="for IsConvexObject"/>140# <Returns>a toric variety</Returns>141# <Description>142# Creates a toric variety out143# of the convex object <A>conv</A>.144# </Description>145# </ManSection>146# <#/GAPDoc>147DeclareOperation( "ToricVariety",148[ IsConvexObject ] );149-->150151152Suppose you have not been using &GAPDoc; before but instead used the process153described in section <Ref Sect="Tut:Scratch"/> to create your manual.154Then the following &GAP; command will regenerate the manual and automatically155include all newly documented functions, operations etc.:156157<Listing>158LoadPackage( "AutoDoc" );159AutoDoc( rec( scaffold := true,160autodoc := true ) );161</Listing>162163If you are not using the scaffolding feature, e.g. because you already164have an existing &GAPDoc; based manual, then you can still use &AutoDoc;165documentation comments. Just make sure to first edit the main XML166file of your documentation, and insert the line167<Listing>168#Include SYSTEM "_AutoDocMainFile.xml"169</Listing>170in a suitable place. This means that you can mix &AutoDoc; documentation171comment freely with your existing documentation; you can even still make172use of any existing &GAPDoc; documentation comments in your code.173174The following command should be useful for you in this case; it175still scans the package code for &AutoDoc; documentation comments176and the runs &GAPDoc; to produce HTML and PDF output, but does not177touch your documentation XML files otherwise.178<Listing>179LoadPackage( "AutoDoc" );180AutoDoc( rec( autodoc := true ) );181</Listing>182183184</Section>185186187<Section Label="Tut:IntegrateExisting">188<Heading>Using &AutoDoc; in an existing &GAPDoc; manual</Heading>189190Even if you already have an existing &GAPDoc; manual, it might be191interesting for you to use &AutoDoc; for two purposes:192<P/>193194First off, with &AutoDoc; is very convenient to regenerate your195documentation.196<P/>197198Secondly, the scaffolding feature which generates a title package199with all the metadata of your package in a uniform way is very200handy. The somewhat tedious process of keeping your title page in201sync with your <F>PackageInfo.g</F> is fully automated this way202(including the correct version, release data, author information203and so on).204<P/>205206There are various examples of packages using &AutoDoc; for only207this purpose, e.g. <Package>IO</Package> and <Package>orb</Package>.208<P/>209210<Subsection Label="Tut:IntegrateExisting:EverythingThere">211<Heading>Using &AutoDoc; on a complete &GAPDoc; manual</Heading>212213Suppose you already have a complete XML manual, with some main and title214XML files and some documentation for operations distributed over215all your <F>.g</F>, <F>.gd</F>, and <F>.gi</F> files.216Suppose the main XML file is named <F>PACKAGENAME.xml</F> and is in the217<F>/doc</F> subfolder of your package. Then you can rebuild your manual218by executing the following two GAP commands from a GAP sessions started219started in the root directory of your package:220<Listing>221LoadPackage( "AutoDoc" );222AutoDoc( );223</Listing>224In contrast, the <Package>RingsForHomalg</Package> currently uses225essentially the following code in its <F>makedoc.g</F> file to achieve the same result226<Listing>227LoadPackage( "GAPDoc" );228SetGapDocLaTeXOptions( "utf8" );229bib := ParseBibFiles( "doc/RingsForHomalg.bib" );230WriteBibXMLextFile( "doc/RingsForHomalgBib.xml", bib );231list := [232"../gap/RingsForHomalg.gd",233"../gap/RingsForHomalg.gi",234"../gap/Singular.gi",235"../gap/SingularBasic.gi",236"../examples/RingConstructionsExternalGAP.g",237"../examples/RingConstructionsSingular.g",238"../examples/RingConstructionsMAGMA.g",239"../examples/RingConstructionsMacaulay2.g",240"../examples/RingConstructionsSage.g",241"../examples/RingConstructionsMaple.g",242];243MakeGAPDocDoc( "doc", "RingsForHomalg", list, "RingsForHomalg" );244GAPDocManualLab( "RingsForHomalg" );245</Listing>246Note that in particular, you do not have to worry about keeping a list of your247implementation files up-to-date.248<P/>249But there is more. &AutoDoc; can create a <F>maketest.g</F> file, which uses the250examples in your manual to test your package. This can be achieved via251<Listing>252LoadPackage( "AutoDoc" );253AutoDoc( rec( maketest := true ) );254</Listing>255Now the file <F>maketest.g</F> appears in your package directory, and256<Listing>257gap maketest.g258</Listing>259test the examples from your manual.260</Subsection>261262<Subsection Label="Tut:IntegrateExisting:GapDocOptions">263<Heading>Setting different &GAPDoc; options</Heading>264265Sometimes, the default values for the &GAPDoc; command used by &AutoDoc;266may not be suitable for your manual.267<P/>268Suppose your main XML file is <E>not</E> named <F>PACKAGENAME.xml</F>, but rather something else, e.g. <F>main.xml</F>.269Then you can tell &AutoDoc; to use this file as the main XML file via270<Listing>271LoadPackage( "AutoDoc" );272AutoDoc( rec( gapdoc := rec( main := "main" ) ) );273</Listing>274<P/>275As explained above, by default &AutoDoc; scans all <F>.g</F>, <F>.gd</F> and <F>.gi</F> files276it can find inside of your package root directory, and in the subdirectories <F>gap</F>,277<F>lib</F>, <F>examples</F> and <F>examples/doc</F> as well.278If you keep source files with documentation in other directories,279you can adjust the list of directories AutoDoc scans via the <C>scan_dirs</C> option.280The following example illustrates this by instructing &AutoDoc; to only search in the subdirectory <F>package_sources</F>281of the packages root directory.282<Listing>283LoadPackage( "AutoDoc" );284AutoDoc( rec( gapdoc := rec( scan_dirs := [ "package_source" ] ) ) );285</Listing>286You can also specify an explicit list of files containing documentation,287which will be searched in addition to any files located within the scan directories:288<Listing>289LoadPackage( "AutoDoc" );290AutoDoc( rec( gapdoc := rec( files := [ "path/to/some/hidden/file.gds" ] ) ) );291</Listing>292Giving such a file does not prevent the standard <C>scan_dirs</C> from being scanned for293other files.294<P/>295Next, &GAPDoc; supports the documentation to be built with relative paths.296This means, links to manuals of other packages or the &GAP; library will297not be absolute, but relative from your documentation. This can be particularly useful298if you want to build a release tarball or move your &GAP; installation around later.299Suppose you are starting &GAP; in the root path of your package as always,300and the standard call of <Ref Func="AutoDoc"/> will then build the documentation in the <F>doc</F> subfolder of your package.301From this folder, the gap root directory has the relative path <F>../../..</F>.302Then you can enable the relative paths by303<Listing>304LoadPackage( "AutoDoc" );305AutoDoc( rec( gapdoc := rec( gap_root_relative_path := "../../.." ) ) );306</Listing>307or, since <F>../../..</F> is the standard option for <C>gap_root_relative_path</C>, by308<Listing>309LoadPackage( "AutoDoc" );310AutoDoc( rec( gapdoc := rec( gap_root_relative_path := true ) ) );311</Listing>312313</Subsection>314315</Section>316317<Section Label="Tut:Scaffolds">318<Heading>Scaffolds</Heading>319320<!-- TODO: insert an introduction here -->321322<Subsection Label="Tut:Scaffolds:Title">323<Heading>Generating a title page</Heading>324325For most (if not all) &GAP; packages, the title page of the package manual326lists information such as the release date, version, names and contact details327of the authors, and so on.328329All this data is also contained in your <F>PackageInfo.g</F>, and whenever330you make a change to that file, there is a risk that you forget to update331your manual to match. And even if you don't forget it, you of course332have to spend some time to adjust the manual. &GAPDoc; can help to a degree with333this via entities. Thus, you will sometimes see code like this in <F>PackageInfo.g</F>334files:335<Listing><![CDATA[336Version := "1.2.3",337Date := "20/01/2015",338## <#GAPDoc Label="PKGVERSIONDATA">339## <!ENTITY VERSION "1.2.3">340## <!ENTITY RELEASEDATE "20 January 2015">341## <!ENTITY RELEASEYEAR "2015">342## <#/GAPDoc>343]]></Listing>344However, it is still easy to forget both of these versions. And it doesn't345solve the problem of updating package authors addresses. Neither of these is a346big issue, of course, but there have been plenty examples in the past where347people forget either of these two things, and it can be slightly embarrassing.348It may even require you to make a new release just to fix the issue, which in349our opinion is a sad waste of your valuable time. <P/>350351So instead of worrying about manually synchronising these things, you can352instruct &AutoDoc; to generate a title page for your manual based on the353information in your <F>PackageInfo.g</F>. The following commands do just that354(in addition to building your manual), by generating a file called355<F>doc/title.xml</F>.356<Listing>357LoadPackage( "AutoDoc" );358AutoDoc( rec( scaffold := rec( MainPage := false ) ) );359</Listing>360Note that this only outputs <F>doc/title.xml</F> but does not361touch any other files of your documentation. In particular, you need362to explicitly include <F>doc/title.xml</F> from your main XML file.<P/>363364However, you can also tell &AutoDoc; to maintain the main XML file for you,365in which case this is automatic. In fact, this is the default if you366enabling scaffolding; the above example command explicitly told &AutoDoc;367not to generate a main page. More o368369</Subsection>370371<Subsection Label="Tut:Scaffolds:Main">372<Heading>Generating the main XML file</Heading>373374The following generates a main XML file for your documentation in375addition to the title page. The main XML file includes376the title page by default, as well as any documentation generated377from &AutoDoc; documentation comments.378<Listing>379LoadPackage( "AutoDoc" );380AutoDoc( rec( scaffold := true ) );381</Listing>382383You can instruct &AutoDoc; to include additional XML files by giving it384a list of filenames, as in the following example:385<Listing>386LoadPackage( "AutoDoc" );387AutoDoc(rec(388scaffold := rec(389includes := [ "somefile.xml", "anotherfile.xml" ]390)391));392</Listing>393394For more information, please consult the documentation395of the <Ref Func="AutoDoc"/> function.396397398</Subsection>399400401<Subsection Label="Tut:PackageInfo">402<Heading>What data is extracted from <F>PackageInfo.g</F>?</Heading>403404&AutoDoc; can extract data from <F>PackageInfo.g</F> in order to405generate a title page. Specifically, the following components406of the package info record are looked at:407408<List>409410<Mark>Version</Mark><Item>411This is used to set the <C><Version></C> element of the412title page, with the string <Q>Version </Q> prepended.413</Item>414415<Mark>Date</Mark><Item>416This is used to set the <C><Date></C> element of the417title page.418</Item>419420<Mark>Subtitle</Mark><Item>421This is used to set the <C><Subtitle></C> element of the422title page (the <C><Title></C> is set to the package name).423</Item>424425<Mark>Persons</Mark><Item>426This is used to generate <C><Author></C> elements in the427generated title page.428</Item>429430<Mark>PackageDoc</Mark><Item>431This is a record (or a list of records) which is used to tell the432&GAP; help system about the package manual. Currently &AutoDoc;433extracts the value of the <C>PackageDoc.BookName</C> component434and then passes that on to &GAPDoc; when creating the HTML, PDF435and text versions of the manual.436</Item>437438<Mark>AutoDoc</Mark><Item>439This is a record which can be used to control the scaffolding performed by440&AutoDoc;, specifically to provide extra information for the title page. For441example, you can set <C>AutoDoc.TitlePage.Copyright</C> to a string which will442then be inserted on the generated title page. Using this method you can443customize the following title page elements: <C>TitleComment</C>,444<C>Abstract</C>, <C>Copyright</C>, <C>Acknowledgements</C> and <C>Colophon</C>.445446<P/>447Note that <C>AutoDoc.TitlePage</C> behaves exactly the same448as the <C>scaffold.TitlePage</C> parameter of the <Ref Func="AutoDoc"/>449function.450</Item>451452</List>453454</Subsection>455456</Section>457458<Section Label="Tut:AutoDocWorksheet">459<Heading>AutoDoc worksheets</Heading>460&AutoDoc; worksheets can be used to create HTML and PDF documents using AutoDoc syntax and possibly461including &GAP; examples and implementations without having them associated to a package.462A file for a worksheet could look like this:463<Listing>464#! @Title My first worksheet465#! @Author Charlie Brown466467#! @Chapter Some groups468469#! @BeginExample470S3 := SymmetricGroup( 3 );;471S4 := SymmetricGroup( 4 );;472#! @EndExample473</Listing>474Now, one can create a PDF and HTML document, like a package documentation out of it. Suppose the document above475is saved as <F>worksheet.g</F>. Then, when GAP is started in the folder of this file, the command476<Listing>477AutoDocWorksheet( "worksheet.g" );478</Listing>479will create a subfolder called <F>doc</F> of the current directory in which it will create the documentation.480There are several options to configure the output of the worksheet command, which are identical to the481options of the <Ref Func="AutoDoc"/> command. It is even possible to test the examples in the worksheet using the maketest option482from the AutoDoc command.483<P/>484Since the worksheets do not have a <F>PackageInfo.g</F> to extract information, all possible tags that &GAPDoc; supports for485the title page can be set into the document. A fully typed title page can look like this:486<Listing>487#! @Title My first worksheet488#! @Subtitle Some small examples489#! @Author Charlie Brown490491#! @Version 0.1492#! @TitleComment Some worksheet493#! @Date 01/01/2016494#! @Address TU Kaiserslautern495#! @Abstract496#! A worksheet showing some small examples about groups.497#! @Copyright 2016 Charlie Brown498#! @Acknowledgements Woodstock499#! @Colophon Some colophon500501#! @Chapter Some groups502503#! @BeginExample504S3 := SymmetricGroup( 3 );;505S4 := SymmetricGroup( 4 );;506#! @EndExample507</Listing>508</Section>509</Chapter>510511512