docs: update SGML usage, mention pdf generation
[gtk-doc.git] / help / manual / C / gtk-doc-manual.xml
blob166cd0c072b0e12898000d2afdffca46caf4f10a
1 <?xml version="1.0" standalone="no"?>
2 <?xml-stylesheet type="text/xml" href="params.xsl"?>
3 <!-- vim: set ai tw=80 ts=3 sw=3: -->
4 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "
5               http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
7 <!ENTITY FDL SYSTEM "fdl-appendix.xml">
8 <!ENTITY FDLlink "<link linkend='fdl'>included</link>">
9 ]><!-- =============Document Header ============================= -->
10 <book id="index">
11   <bookinfo>
12     <title>GTK-Doc Manual</title>
13     <edition>1.12</edition>
14     <abstract role="description"><para>User manual for developers with instructions of GTK-Doc usage.</para></abstract>
15     <authorgroup>
16       <author>
17         <firstname>Chris</firstname>
18         <surname>Lyttle</surname>
19         <affiliation>
20           <address>
21             <email>chris@wilddev.net</email>
22           </address>
23         </affiliation>
24       </author>
25       <author>
26         <firstname>Dan</firstname>
27         <surname>Mueth</surname>
28         <affiliation>
29           <address>
30             <email>d-mueth@uchicago.edu</email>
31           </address>
32         </affiliation>
33       </author>
34       <author>
35         <firstname>Stefan</firstname>
36         <surname>Kost</surname>
37         <affiliation>
38           <address>
39             <email>ensonic@users.sf.net</email>
40           </address>
41         </affiliation>
42       </author>
43     </authorgroup>
44     <publisher role="maintainer">
45       <publishername>GTK-Doc project</publishername>
46       <address><email>gtk-doc-list@gnome.org</email></address>
47     </publisher>
48     <copyright>
49       <year>2000, 2005, 2007-2009</year>
50       <holder>Dan Mueth and Chris Lyttle and Stefan Kost</holder>
51     </copyright>
53     <!-- translators: uncomment this:
54     <copyright>
55       <year>2000</year>
56       <holder>ME-THE-TRANSLATOR (Latin translation)</holder>
57     </copyright>
58     -->
60     <legalnotice>
61       <para>
62         Permission is granted to copy, distribute and/or modify this
63         document under the terms of the <citetitle>GNU Free Documentation
64         License</citetitle>, Version 1.1 or any later version published
65         by the Free Software Foundation with no Invariant Sections, no
66         Front-Cover Texts, and no Back-Cover Texts. A copy of the license
67         is &FDLlink;.
68       </para>
69       <para>
70         Many of the names used by companies to distinguish their products and
71         services are claimed as trademarks. Where those names appear in any
72         GNOME documentation, and those trademarks are made aware to the members
73         of the GNOME Documentation Project, the names have been printed in caps
74         or initial caps.
75       </para>
76     </legalnotice>
77     
78     <revhistory>
79       <revision>
80         <revnumber>1.14</revnumber>
81         <date>19 December 2009</date>
82         <authorinitials>sk</authorinitials>
83         <revremark>development version</revremark>
84       </revision>
85       <revision>
86         <revnumber>1.13</revnumber>
87         <date>18 December 2009</date>
88         <authorinitials>sk</authorinitials>
89         <revremark>broken tarball update</revremark>
90       </revision>
91       <revision>
92         <revnumber>1.12</revnumber>
93         <date>18 December 2009</date>
94         <authorinitials>sk</authorinitials>
95         <revremark>new tool features and bugfixes</revremark>
96       </revision>
97       <revision>
98         <revnumber>1.11</revnumber>
99         <date>16 Novemebr 2008</date>
100         <authorinitials>mal</authorinitials>
101         <revremark>GNOME doc-utils migration</revremark>
102       </revision>
103     </revhistory>
105   </bookinfo>
107   <!-- ======== Chapter 1: Introduction ======================== -->
109   <chapter id="introduction">
110     <title>Introduction</title>
112     <para>
113       This chapter introduces GTK-Doc and gives an overview of what it is and
114       how it is used.
115     </para>
117     <sect1 id="whatisgtkdoc">
118       <title>What is GTK-Doc?</title>
120       <para>
121         GTK-Doc is used to document C code. It is typically used to document the public
122         API of libraries, such as the GTK+ and GNOME libraries. But it can also be
123         used to document application code.
124       </para>
125     </sect1>
127     <sect1 id="howdoesgtkdocwork">
128       <title>How Does GTK-Doc Work?</title>
130       <para>
131         GTK-Doc works by using documentation of functions placed inside the source files in
132         specially-formatted comment blocks, or documentation added to the template files
133         which GTK-Doc uses (though note that GTK-Doc will only document functions that
134         are declared in header files; it won't produce output for static functions).
135       </para>
137       <para>
138         GTK-Doc consists of a number of perl scripts, each performing a different step
139         in the process.
140       </para>
142       <para>
143         There are 5 main steps in the process:
144       </para>
146       <orderedlist>
148         <listitem>
149           <para>
150             <guilabel>Writing the documentation.</guilabel>
152             The author fills in the source files with the documentation for each
153             function, macro, union etc. (In the past information was entered in
154             generated template files, which is not recommended anymore).
155           </para>
156         </listitem>
158         <listitem>
159           <para>
160             <guilabel>Gathering information about the code.</guilabel>
162             <application>gtkdoc-scan</application> scans the header files of the
163             code looking for declarations of functions, macros, enums, structs, and unions.
164             It creates the file <filename>&lt;module&gt;-decl-list.txt</filename> containg a list of the
165             declarations, placing them into sections according to which header file they
166             are in. On the first run this file is copied to <filename>&lt;module&gt;-sections.txt</filename>
167             The author can rearrange the sections, and the order of the
168             declarations within them, to produce the final desired order.
169             The second file it generates is <filename>&lt;module&gt;-decl.txt</filename>.
170             This file contains the full declarations found by the scanner. If for
171             some reason one would like some sybols to show up in the docs, where
172             the full declaration cannot be found by th scanner or the declaration
173             should appear differently, one can place enties similar to the ones in
174             <filename>&lt;module&gt;-decl.txt</filename> into <filename>&lt;module&gt;-overrides.txt</filename>.
176             <application>gtkdoc-scanobj</application> can also be used to dynamically query a library about
177             any GtkObject subclasses it exports. It saves information about each
178             object's position in the class hierarchy and about any GTK Args and Signals it
179             provides.
180           </para>
181         </listitem>
183         <listitem>
184           <para>
185             <guilabel>Generating the "template" files.</guilabel>
187             <application>gtkdoc-mktmpl</application> creates a number of files in
188             the <filename class='directory'>tmpl/</filename> subdirectory, using the
189             information gathered in the first step. (Note that this can be run
190             repeatedly. It will try to ensure that no documentation is ever lost.)
191           </para>
192           <note>
193             <para>
194               Since gtk-doc 1.9 the templates can be avoided. We encourage people to keep
195               documentation in the code. <application>gtkdocize</application> supports now
196               a <option>--flavour no-tmpl</option> option that chooses a makefile that
197               skips tmpl usage totally.
198               If you have never changed file in tmpl by hand, please remove the dir once.
199             </para>
200           </note>
201         </listitem>
203         <listitem>
204           <para>
205             <guilabel>Generating the SGML/XML and HTML/PDF.</guilabel>
207             <application>gtkdoc-mkdb</application> turns the template files into
208             SGML or XML files in the <filename class='directory'>sgml/</filename>
209             or <filename class='directory'>xml/</filename> subdirectory.
210             If the source code contains documentation on functions, using the
211             special comment blocks, it gets merged in here. If there are no tmpl files used
212             it only reads takes docs from sources and introspection data.
213           </para>
214           <para>
215             <application>gtkdoc-mkhtml</application> turns the SGML/XML files into HTML
216             files in the <filename class='directory'>html/</filename> subdirectory.
217             Likewise <application>gtkdoc-mkpdf</application> turns the SGML/XML files into a PDF
218             docuemnt called <filename>&lt;package&gt;.pdf</filename>.
219           </para>
220           <para>
221             Files in <filename class='directory'>sgml/</filename> or
222             <filename class='directory'>xml/</filename> and <filename class='directory'>html/</filename>
223             directories are always overwritten. One should never edit them directly.
224           </para>
225         </listitem>
227         <listitem>
228           <para>
229             <guilabel>Fixing up cross-references between documents.</guilabel>
231             After installing the HTML files, <application>gtkdoc-fixxref</application> can be run to fix up any
232             cross-references between separate documents. For example, the GTK+
233             documentation contains many cross-references to types documented in the GLib manual.
235             When creating the source tarball for distribution, <application>gtkdoc-rebase</application>
236             turns all external links into web-links. When installing distributed (pregenerated) docs
237             the same application will try to turn links back to local links
238             (where those docs are installed).
239           </para>
240         </listitem>
241       </orderedlist>
243     </sect1>
245     <sect1 id="gettinggtkdoc">
246       <title>Getting GTK-Doc</title>
248       <sect2 id="requirements">
249         <title>Requirements</title>
250         <para>
251           <guilabel>Perl v5</guilabel> - the main scripts are in Perl.
252         </para>
253         <para>
254           <guilabel>DocBook DTD v3.0</guilabel> - This is the DocBook SGML DTD.
255           <ulink url="http://www.ora.com/davenport" type="http">http://www.ora.com/davenport</ulink>
256         </para>
257         <para>
258           <guilabel>Jade v1.1</guilabel> - This is a DSSSL processor for converting SGML to various formats.
259           <ulink url="http://www.jclark.com/jade" type="http">http://www.jclark.com/jade</ulink>
260         </para>
261         <para>
262           <guilabel>Modular DocBook Stylesheets</guilabel>
263           This is the DSSSL code to convert DocBook to HTML (and a few other
264           formats). It's used together with jade.
265           I've customized the DSSSL code slightly, in gtk-doc.dsl, to colour
266           the program code listings/declarations, and to support global
267           cross-reference indices in the generated HTML.
268           <ulink url="http://nwalsh.com/docbook/dsssl" type="http">http://nwalsh.com/docbook/dsssl</ulink>
269         </para>
270         <para>
271           <guilabel>docbook-to-man</guilabel> - if you want to create man pages from the DocBook.
272           I've customized the 'translation spec' slightly, to capitalise section
273           headings and add the 'GTK Library' title at the top of the pages and the
274           revision date at the bottom.
275           There is a link to this on <ulink url="http://www.ora.com/davenport" type="http">http://www.ora.com/davenport</ulink>
276           NOTE: This does not work yet.
277         </para>
278       </sect2>
280       <sect2 id="installation">
281         <title>Installation</title>
282         <para>
283           There is no standard place where the DocBook Modular Stylesheets are installed.
284         </para>
285         <para>
286           gtk-doc's configure script searches these 3 directories automatically:
287         </para>
288         <para>
289           <filename> /usr/lib/sgml/stylesheets/nwalsh-modular   </filename>     (used by RedHat)
290         </para>
291         <para>
292           <filename>  /usr/lib/dsssl/stylesheets/docbook         </filename>     (used by Debian)
293         </para>
294         <para>
295           <filename>  /usr/share/sgml/docbkdsl                   </filename>     (used by SuSE)
296         </para>
297         <para>
298           If you have the stylesheets installed somewhere else, you need to configure
299           gtk-doc using the option:
300           <command> --with-dsssl-dir=&lt;PATH_TO_TOPLEVEL_STYLESHEETS_DIR&gt; </command>
301         </para>
302       </sect2>
304     </sect1>
306     <!-- not realy worth a section
307     <sect1 id="whentousegtkdoc">
308       <title>When to Use GTK-Doc</title>
310       <para>
311         (What things GTK-Doc should, and shouldn't, be used for.)
312         (- ???)
313         (+ Tutorials)
314       </para>
316     </sect1>
317     -->
319     <sect1 id="aboutgtkdoc">
320       <title>About GTK-Doc</title>
322       <para>
323         (FIXME)
324       </para>
326       <para>
327         (History, authors, web pages, license, future plans,
328         comparison with other similar systems.)
329       </para>
331     </sect1>
333     <sect1 id="aboutthismanual">
334       <title>About this Manual</title>
336       <para>
337         (FIXME)
338       </para>
340       <para>
341         (who it is meant for, where you can get it, license)
342       </para>
344     </sect1>
346   </chapter>
348   <chapter id="settingup">
349     <title>Setting up your project</title>
351     <para>
352       The next sections describe what steps to perform to integrate GTK-Doc into
353       your project. Theses section assume we work on a project called 'meep'.
354       This project contains a library called 'libmeep' and
355       an end-user app called 'meeper'.
356     </para>
358     <sect1 id="settingup_docfiles">
359       <title>Setting up a skeleton documentation</title>
361       <para>
362         Under your top-level project directory create folders called docs/reference
363         (this way you can also have docs/help for end-user documentation).
364         It is recommended to create another subdirectory with the name of the doc-package.
365         For packages with just one library this step is not necessary.
366       </para>
368       <para>
369         This can then look as show below:
370         <example><title>Example directory structure</title>
371           <programlisting>
372 <![CDATA[
373 meep/
374   docs/
375     reference/
376       libmeep/
377       meeper/
378   src/
379     libmeep/
380     meeper/
382           </programlisting>
383         </example>
384       </para>
385     </sect1>
387     <sect1 id="settingup_autoconf">
388       <title>Integration with autoconf</title>
390       <para>
391         Very easy! Just add one line to your <filename>configure.ac</filename> script.
392       </para>
394       <para>
395         <example><title>Integration with autoconf</title>
396           <programlisting>
397 <![CDATA[
398 # check for gtk-doc
399 GTK_DOC_CHECK(1.9)
401           </programlisting>
402         </example>
403       </para>
405       <para>
406         Besides checking for the required Gtk-Doc version, this adds two configure
407         switches:
408       </para>
409       <orderedlist>
410         <listitem><para>--with-html-dir=PATH : path to installed docs</para></listitem>
411         <listitem><para>--enable-gtk-doc : use gtk-doc to build documentation</para></listitem>
412       </orderedlist>
414       <important>
415         <para>
416           Gtk-Doc is disabled by default! Remember to pass the option
417           <option>'--enable-gtk-doc'</option> to the next
418           <filename>configure</filename> run. Otherwise pregenerated documentation is installed
419           (which makes sense for users but not for developers).
420         </para>
421       </important>
423       <para>
424         Furthermore it is recommended that you have the following line inside
425         you <filename>configure.ac</filename> script.
426         This allows <filename>gtkdocize</filename> to automatically copy the
427         macro definition for <function>GTK_DOC_CHECK</function> to your project.
428       </para>
430       <para>
431         <example><title>Preparation for gtkdocize</title>
432           <programlisting>
433 <![CDATA[
434 AC_CONFIG_MACRO_DIR(m4)
436           </programlisting>
437         </example>
438       </para>
439     </sect1>
441     <sect1 id="settingup_automake">
442       <title>Integration with automake</title>
444       <para>
445         First copy the <filename>Makefile.am</filename> from the examples subdirectory of the gtkdoc-sources
446         to your project's API documentation directory (
447         <filename class='directory'>./docs/reference/&lt;package&gt;</filename>).
448         If you have multiple doc-packages repeat this for each one.
449       </para>
451       <para>
452         The next step is to edit the setting inside the <filename>Makefile.am</filename>.
453         All the settings have a comment above that describes their purpose.
454         Most settings are extra flags passed to the respective tools. Every tool
455         has a variable of the form <option>&lt;TOOLNAME&gt;_OPTIONS</option>.
456         All the tools support <option>--help</option> to list the supported
457         parameters.
458       </para>
460       <!-- FIXME: explain options ? -->
462       <para>
463         You may also want to enable gtk-doc for the distcheckmake target. Just
464         add then one-liner show in the next example to you top-level
465         <filename>Makefile.am</filename>:
466       </para>
468       <para>
469         <example><title>Enable gtk-doc during make distcheck</title>
470           <programlisting>
471 <![CDATA[
472 DISTCHECK_CONFIGURE_FLAGS=--enable-gtk-doc
474           </programlisting>
475         </example>
476       </para>
478     </sect1>
480     <sect1 id="settingup_autogen">
481       <title>Integration with autogen</title>
483       <para>
484         Most projects will have an <filename>autogen.sh</filename> script to
485         setup the build infrastructure after a checkout from version control
486         system (such as cvs). Gtk-Doc comes with a tool called
487         <filename>gtkdocize</filename> which can be used in such a script.
488         It should be run before autoheader, automake or autoconf.
489       </para>
491       <para>
492         <example><title>Running gtkdocize from autogen.sh</title>
493           <programlisting>
494 <![CDATA[
495 gtkdocize || exit 1
497           </programlisting>
498         </example>
499       </para>
501       <para>
502         When running <filename>gtkdocize</filename> it copies
503         <filename>gtk-doc.make</filename> to you project root (or any directory
504         specified by the --docdir option). If also check you configure script
505         for the <function>GTK_DOC_CHECK</function> invocation.
506       </para>
508       <para>
509         Historically gtk-doc was gerating template files where developers entered the docs.
510         this turned out to be not so good. Since a few version gtk-doc could also get all
511         the information from source comments.
512         Since gtk-doc 1.9 the templates can be avoided. We encourage people to keep
513         documentation in the code. <application>gtkdocize</application> supports now
514         a <option>--flavour no-tmpl</option> option that chooses a makefile that skips
515         tmpl usage totally.
516         If you have never changed file in tmpl by hand, please remove the dir once.
517       </para>
518     </sect1>
520     <sect1 id="settingup_firstrun">
521       <title>Running the doc build</title>
523       <para>
524         After the previous steps it's time to run the build. First we need to
525         rerun <filename>autogen.sh</filename>. If this script runs configure for
526         you, then give it the <option>--enable-gtk-doc</option> option.
527         Otherwise manually run <filename>configure</filename> with this option
528         afterwards.
529       </para>
530       <para>
531         The first make run generates several additional files in the doc-dirs.
532         The important ones are:
533         <filename>&lt;package&gt;.types</filename>,
534         <filename>&lt;package&gt;-docs.sgml</filename>,
535         <filename>&lt;package&gt;-sections.txt</filename>.
536       </para>
537       <para>
538         <example><title>Running the doc build</title>
539           <programlisting>
540 <![CDATA[
541 ./autogen.sh --enable-gtk-doc
542 make
544           </programlisting>
545         </example>
546       </para>
547       <para>
548         Now you can point your browser to <filename>docs/reference/&lt;package&gt;/index.html</filename>.
549         Yes, it's a bit disappointing still. But hang-on, during the next chapter we
550         tell you how to fill the pages with life.
551       </para>
552     </sect1>
554     <sect1 id="settingup_vcs">
555       <title>Integration with version control systems</title>
557       <para>
558         As a rule of the thumb, it's those files you edit, that should go under
559         version control. For typical projects it's these files:
560         <filename>&lt;package&gt;.types</filename>
561         <filename>&lt;package&gt;-docs.sgml</filename>
562         <filename>&lt;package&gt;-sections.txt</filename>
563         <filename>Makefile.am</filename>
564       </para>
565     </sect1>
567   </chapter>
569   <chapter id="documenting">
570     <title>Documenting the code</title>
572     <para>
573       GTK-Doc uses source code comment with a special syntax for code documentation.
574       Further it retrieves information about your project structure from other
575       sources. During the next section you find all information about the syntax
576       of the comments.
577     </para>
579     <note>
580       <title>Documentation placement</title>
581       <para>
582         In the past most documentation had to be filled into files residing
583         inside the <filename>tmpl</filename> directory. This has the
584         disadvantages that the information is often not updated and also that
585         the file tend to cause conflicts with version control systems.
586       </para>
587       <para>
588         The avoid the aforementioned problems we suggest putting the
589         documentation inside the sources. This manual will only describe this
590         way of documenting code.
591       </para>
592     </note>
594     <!--  -->
596     <sect1 id="documenting_syntax">
597       <title>Documentation comments</title>
599       <para>
600         A multiline comment that starts with an additional '*' marks a
601         documentation block that will be processed by the Gtk-Doc tools.
602         <example><title>Gtk-Doc comment block</title>
603           <programlisting>
604 <![CDATA[
606  * identifier:
607  * documentation ...
608  */
610           </programlisting>
611         </example>
612       </para>
614       <para>
615         The 'identifier' is one line with the name of the item the comment is
616         related to. The syntax differs a little depending on the item.
617         (TODO add table showing identifiers)
618       </para>
620       <para>
621         The 'documentation' block is also different for each symbol type. Symbol
622         types that get parameters such as functions or macros have the parameter
623         description first followed by a blank line (just a '*').
624         Afterwards follows the detailed description. All lines (outside program-
625         listings and CDATA sections) just containing a ' *' (blank-asterisk) are
626         converted to paragraph breaks.
627         If you don't want a paragraph break, change that into ' *  '
628         (blank-asterisk-blank-blank).
629       </para>
631       <para>
632         One advantage of hyper-text over plain-text is the ability to have links
633         in the document. Writing the correct markup for a link can be tedious
634         though. Gtk-Doc comes to help by providing several useful abbreviations.
635         <itemizedlist>
636           <listitem>
637             <para>
638               Use function() to refer to functions or macros which take arguments.
639             </para>
640           </listitem>
641           <listitem>
642             <para>
643               Use @param to refer to parameters. Also use this when referring to
644               parameters of other functions, related to the one being described.
645             </para>
646           </listitem>
647           <listitem>
648             <para>
649               Use %constant to refer to a constant, e.g. %G_TRAVERSE_LEAFS.
650             </para>
651           </listitem>
652           <listitem>
653             <para>
654               Use #symbol to refer to other types of symbol, e.g. structs and
655               enums and macros which don't take arguments.
656             </para>
657           </listitem>
658           <listitem>
659             <para>
660               Use #Object::signal to refer to a GObject signal
661             </para>
662           </listitem>
663           <listitem>
664             <para>
665               Use #Object:property to refer to a GObject property
666             </para>
667           </listitem>
668           <listitem>
669             <para>
670               Use #Struct.field to refer to a field inside a structure.
671             </para>
672           </listitem>
673         </itemizedlist>
674       </para>
676       <tip>
677         <para>
678           If you need to use the special characters '&lt;', '&gt;', '()', '@',
679           '%', or '#' in your documentation without gtk-doc changing them you
680           can use the XML entities "&amp;lt;", "&amp;gt;", "&amp;lpar;",
681           "&amp;rpar;", "&amp;commat;", "&amp;percnt;" and "&amp;num;"
682           respectively or escape them with a backslash '\'.
683         </para>
684       </tip>
686       <para>
687         DocBook can do more that just links. One can also have lists, tables and
688         examples. To enable the usage of SGML/XML tags inside doc-comments you
689         need to have <option>--sgml-mode</option> in the variable
690         <symbol>MKDB_OPTIONS</symbol> inside <filename>Makefile.am</filename>.
691       </para>
693       <tip>
694         <para>
695           As already mentioned earlier Gtk-Doc is for documenting public API. Thus
696           one cannot write documentation for static symbols. Nevertheless it is good
697           to comment those symbols too. This helps other to understand you code.
698           Therefore we recommend to comment these using normal comments (without the
699           2nd '*' in the first line).
700           If later the function needs to be made public, all one needs to do is to
701           add another '*' in the comment block and insert the symbol name at the
702           right place inside the sections file.
703         </para>
704       </tip>
705     </sect1>
707     <sect1 id="documenting_sections">
708       <title>Documenting sections</title>
710       <para>
711         Each section of the documentation contains information about one class
712         or module. To introduce the component one can write a section block.
713         The short description is also used inside the table of contents.
714         All the @fields are optional.
715       </para>
717       <para>
718         <example><title>Section comment block</title>
719           <programlisting>
720 <![CDATA[
722  * SECTION:meepapp
723  * @short_description: the application class
724  * @title: Meep application
725  * @section_id:
726  * @see_also: #MeepSettings
727  * @stability: Stable
728  * @include: meep/app.h
730  * The application class handles ...
731  */
733           </programlisting>
734         </example>
735       </para>
737       <variablelist>
738         <varlistentry>
739           <term>SECTION:&lt;name&gt;</term>
740           <listitem>
741             <para>
742               The name links the section documentation to the respective part in
743               the <filename>&lt;package&gt;-sections.txt</filename> file. The
744               name give here should match the &lt;FILE&gt; tag in the 
745               <filename>&lt;package&gt;-sections.txt</filename> file.
746             </para>
747           </listitem>
748         </varlistentry>
749         <varlistentry>
750           <term>@short_description</term>
751           <listitem>
752             <para>
753               A one line description of the section, that later will appear after
754               the links in the TOC and at the top of the section page.
755             </para>
756           </listitem>
757         </varlistentry>
758         <varlistentry>
759           <term>@title</term>
760           <listitem>
761             <para>
762               The section title defaults to &lt;name&gt; from the SECTION
763               declaration. It can be overridden with the @title field.
764             </para>
765           </listitem>
766         </varlistentry>
767         <varlistentry>
768           <term>@section_id</term>
769           <listitem>
770             <para>
771               Overrides the use of title as a section identifier. For GObjects
772               the &lt;title&gt; is used as a section_id and for other section it
773               is &lt;MODULE&gt;-&lt;title&gt;.
774             </para>
775           </listitem>
776         </varlistentry>
777         <varlistentry>
778           <term>@see_also</term>
779           <listitem>
780             <para>
781               A list of symbols that are related to this section..
782             </para>
783           </listitem>
784         </varlistentry>
785         <varlistentry>
786           <term>@stability</term>
787           <listitem>
788             <para>
789               A informal description of the stability level this API has.
790               We recommend the use of one of these terms:
791               <itemizedlist>
792                 <listitem>
793                   <para>
794                     Stable
795                     - The intention of a Stable interface is to enable arbitrary
796                     third parties to develop applications to these interfaces,
797                     release them, and have confidence that they will run on all
798                     minor releases of the product (after the one in which the
799                     interface was introduced, and within the same major release).
800                     Even at a major release, incompatible changes are expected
801                     to be rare, and to have strong justifications.
802                   </para>
803                 </listitem>
804                 <listitem>
805                   <para>
806                     Unstable
807                     - Unstable interfaces are experimental or transitional.
808                     They are typically used to give outside developers early
809                     access to new or rapidly changing technology, or to provide
810                     an interim solution to a problem where a more general
811                     solution is anticipated.
812                     No claims are made about either source or binary
813                     compatibility from one minor release to the next.
814                   </para>
815                 </listitem>
816                 <listitem>
817                   <para>
818                     Private
819                     - An interface that can be used within the GNOME stack
820                     itself, but that is not documented for end-users. Such
821                     functions should only be used in specified and documented
822                     ways.
823                   </para>
824                 </listitem>
825                 <listitem>
826                   <para>
827                     Internal
828                     - An interface that is internal to a module and does not
829                     require end-user documentation. Functions that are
830                     undocumented are assumed to be Internal.
831                   </para>
832                 </listitem>
833               </itemizedlist>
834             </para>
835           </listitem>
836         </varlistentry>
837         <varlistentry>
838           <term>@include</term>
839           <listitem>
840             <para>
841               The <literal>#include</literal> files to show in the section
842               synopsis (a comma separated list), overriding the global
843               value from the <link linkend="metafiles_sections">section
844               file</link> or command line.  This item is optional.
845             </para>
846           </listitem>
847         </varlistentry>
848       </variablelist>
850       <tip>
851         <para>
852           To avoid unnecessary recompilation after doc-changes put the section
853           docs into the c-source where possible.
854         </para>
855       </tip>
857     </sect1>
859     <sect1 id="documenting_symbols">
860       <title>Documenting symbols</title>
862       <para>
863         Each symbol (function, macro, struct, enum, signal and property) is
864         documented in a separate block. The block is best placed close to the
865         definition of the symbols so that it is easy to keep them in sync.
866         Thus function are usually documented in the c-source and macros, struct
867         and enum in the header file.
868       </para>
870       <para>
871         <example><title>Function comment block</title>
872           <programlisting>
873 <![CDATA[
875  * function_name:
876  * @par1:  description of parameter 1. These can extend over more than
877  * one line.
878  * @par2:  description of parameter 2
880  * The function description goes here. You can use @par1 to refer to parameters
881  * so that they are highlighted in the output. You can also use %constant
882  * for constants, function_name2() for functions and #GtkWidget for links to
883  * other declarations (which may be documented elsewhere).
885  * Returns: an integer.
887  * Since: 2.2
888  * Deprecated: 2.18: Use other_function() instead.
889  */
891           </programlisting>
892         </example>
893       </para>
895       <variablelist>
896         <varlistentry>
897           <term>Returns:</term>
898           <listitem>
899             <para>
900               Paragraph describing the returned result.
901             </para>
902           </listitem>
903         </varlistentry>
904         <varlistentry>
905           <term>Deprecated:</term>
906           <listitem>
907             <para>
908               Paragraph denoting that this function should no be used anymore.
909               The description should point the reader to the new API.
910             </para>
911           </listitem>
912         </varlistentry>
913         <varlistentry>
914           <term>Since:</term>
915           <listitem>
916             <para>
917               Description since which version of the code the API is available.
918             </para>
919           </listitem>
920         </varlistentry>
921       </variablelist>
923       <para>
924         Gtk-doc assumes all symbols (macros, functions) starting with '_' are
925         private. They are treated like static functions.
926       </para>
928       <para>
929         (FIXME)
930         (stability)
931         (glib-enums, ...)
932       </para>
934       <example><title>Property comment block</title>
935         <programlisting>
936 <![CDATA[
938  * SomeWidget:some-property:
940  * Here you can document a property.
941  */
942 g_object_class_install_property (object_class, PROP_SOME_PROPERTY, ...);
943 ]]></programlisting>
944       </example>
946       <example><title>Signal comment block</title>
947         <programlisting>
948 <![CDATA[
950  * FooWidget::foobarized:
951  * @widget: the widget that received the signal
952  * @foo: some foo
953  * @bar: some bar
955  * The ::foobarized signal is emitted each time someone tries to foobarize @widget.
956  */
957 foo_signals[FOOBARIZE] =
958   g_signal_new ("foobarize",
959                 ...
960 ]]></programlisting>
961       </example>
963       <example><title>Struct comment block</title>
964         <programlisting>
965 <![CDATA[
967  * FooWidget:
968  * @bar: some #gboolean
970  * This is the best widget, ever.
971  */
972 typedef struct _FooWidget {
973   /*< private >*/
974   GtkWidget parent;
976   /*< public >*/
977   gboolean bar;
978 } FooWidget;
980         </programlisting>
981         <para>
982           Use <code>/*&lt; private &gt;*/</code> before the private struct fields you
983           you want to hide. Use <code>/*&lt; public &gt;*/</code> for the reverse
984           behavirour.
985         </para>
986       </example>
988       <example><title>Enum comment block</title>
989         <programlisting>
990 <![CDATA[
992  * Something:
993  * @SOMETHING_FOO: something foo
994  * @SOMETHING_BAR: something bar
996  * Enum values used for the thing, to specify the thing.
998  **/
999 typedef enum {
1000   SOMETHING_FOO,
1001   SOMETHING_BAR,
1002 } Something;
1004         </programlisting>
1005       </example>
1007     </sect1>
1009     <sect1 id="documenting_docbook">
1010       <title>Useful DocBook tags</title>
1012       <para>
1013         Here are some DocBook tags which are most useful when documenting the
1014         code.
1015       </para>
1017       <para>
1018         To link to another section in the GTK docs:
1020         <informalexample>
1021           <programlisting>
1022 <![CDATA[
1023 <link linkend="glib-Hash-Tables">Hash Tables</link>
1025           </programlisting>
1026         </informalexample>
1027         The linkend is the SGML/XML id on the top item of the page you want to link to.
1028         For most pages this is currently the part ("gtk", "gdk", "glib") and then
1029         the page title ("Hash Tables"). For widgets it is just the class name.
1030         Spaces and underscores are converted to '-' to conform to SGML/XML.
1031       </para>
1033       <para>
1034         To refer to an external function, e.g. a standard C function:
1035         <informalexample>
1036           <programlisting>
1037 <![CDATA[
1038 <function>...</function>
1040           </programlisting>
1041         </informalexample>
1042       </para>
1044       <para>
1045         To include example code:
1046         <informalexample>
1047           <programlisting>
1048 <![CDATA[
1049 <example>
1050   <title>Using a GHashTable.</title>
1051   <programlisting>
1052       ...
1053   </programlisting>
1054 </example>
1056           </programlisting>
1057         </informalexample>
1058         or possibly this, for very short code fragments which don't need a title:
1059         <informalexample>
1060           <programlisting>
1061 <![CDATA[
1062 <informalexample>
1063   <programlisting>
1064   ...
1065   </programlisting>
1066 </informalexample>
1068           </programlisting>
1069         </informalexample>
1070         For the latter gtk-doc also supports an abbreviation:
1071 <![CDATA[
1073   ...
1076       </para>
1078       <para>
1079         To include bulleted lists:
1080         <informalexample>
1081           <programlisting>
1082 <![CDATA[
1083 <itemizedlist>
1084   <listitem>
1085     <para>
1086       ...
1087     </para>
1088   </listitem>
1089   <listitem>
1090     <para>
1091       ...
1092     </para>
1093   </listitem>
1094 </itemizedlist>
1096           </programlisting>
1097         </informalexample>
1098       </para>
1100       <para>
1101         To include a note which stands out from the text:
1102         <informalexample>
1103           <programlisting>
1104 <![CDATA[
1105 <note>
1106   <para>
1107     Make sure you free the data after use.
1108   </para>
1109 </note>
1111           </programlisting>
1112         </informalexample>
1113       </para>
1115       <para>
1116         To refer to a type:
1117         <informalexample>
1118           <programlisting>
1119 <![CDATA[
1120 <type>unsigned char</type>
1122           </programlisting>
1123         </informalexample>
1124       </para>
1126       <para>
1127         To refer to an external structure (not one described in the GTK docs):
1128         <informalexample>
1129           <programlisting>
1130 <![CDATA[
1131 <structname>XFontStruct</structname>
1133           </programlisting>
1134         </informalexample>
1135       </para>
1137       <para>
1138         To refer to a field of a structure:
1139         <informalexample>
1140           <programlisting>
1141 <![CDATA[
1142 <structfield>len</structfield>
1144           </programlisting>
1145         </informalexample>
1146       </para>
1148       <para>
1149         To refer to a class name, we could possibly use:
1150         <informalexample>
1151           <programlisting>
1152 <![CDATA[
1153 <classname>GtkWidget</classname>
1155           </programlisting>
1156         </informalexample>
1157         but you'll probably be using #GtkWidget instead (to automatically create
1158         a link to the GtkWidget page - see <link linkend="documenting_syntax">the abbreviations</link>).
1159       </para>
1161       <para>
1162         To emphasize text:
1163         <informalexample>
1164           <programlisting>
1165 <![CDATA[
1166 <emphasis>This is important</emphasis>
1168           </programlisting>
1169         </informalexample>
1170       </para>
1172       <para>
1173         For filenames use:
1174         <informalexample>
1175           <programlisting>
1176 <![CDATA[
1177 <filename>/home/user/documents</filename>
1179           </programlisting>
1180         </informalexample>
1181       </para>
1183       <para>
1184         To refer to keys use:
1185         <informalexample>
1186           <programlisting>
1187 <![CDATA[
1188 <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo>
1190           </programlisting>
1191         </informalexample>
1192       </para>
1194     </sect1>
1195   </chapter>
1197   <chapter id="metafiles">
1198     <title>Filling the extra files</title>
1200     <para>
1201       There are a couple of extra files, that need to be maintained along with
1202       the inline source code comments:
1203       <filename>&lt;package&gt;.types</filename>,
1204       <filename>&lt;package&gt;-docs.sgml</filename>,
1205       <filename>&lt;package&gt;-sections.txt</filename>.
1206     </para>
1208     <sect1 id="metafiles_types">
1209       <title>Editing the types file</title>
1211       <para>
1212         If your library or application includes GtkObjects/GObjects, you want
1213         their signals, arguments/parameters and position in the hierarchy to be
1214         shown in the documentation. All you need to do, is to list the
1215         <function>xxx_get_type</function> functions together with their include
1216         inside the <filename>&lt;package&gt;.types</filename> file.
1217       </para>
1219       <para>
1220         <example><title>Example types file snippet</title>
1221           <programlisting>
1222 <![CDATA[
1223 #include <gtk/gtk.h>
1225 gtk_accel_label_get_type
1226 gtk_adjustment_get_type
1227 gtk_alignment_get_type
1228 gtk_arrow_get_type
1230           </programlisting>
1231         </example>
1232       </para>
1234       <para>
1235         Since gtk-doc 1.8 <application>gtkdoc-scan</application> can generate this list for you.
1236         Just add "--rebuild-types" to SCAN_OPTIONS in <filename>Makefile.am</filename>. If you
1237         use this approach you should not dist the types file nor have it under version control.
1238       </para>
1240     </sect1>
1242     <sect1 id="metafiles_master">
1243       <title>Editing the master document</title>
1245       <para>
1246         Gtk-Doc produces documentation in DocBook SGML/XML. When processing the
1247         inline source comments, the Gtk-Doc tools generate one documentation
1248         page per class or module as a separate file. The master document
1249         includes them and place them in a order.
1250       </para>
1252       <para>
1253         While Gtk-Doc creates a template master document for you, later run will
1254         not touch it again. This means that one can freely structure the
1255         documentation. That includes grouping pages and adding extra pages.
1256         Gtk-doc has now a test suite, where also the master-document is recreated from scratch.
1257         Its a good idea to look at this from time to time to see if there are some new goodies
1258         introduced there.
1259       </para>
1261       <tip>
1262         <para>
1263           Do not create tutorials as extra documents. Just write extra chapters.
1264           The benefit of directly embedding the tutorial for your library into
1265           the API documentation is that it is easy to link for the tutorial to
1266           symbol documentation. Apart chances are higher that the tutorial gets
1267           updates along with the library.
1268         </para>
1269       </tip>
1271       <para>
1272         So what are the things to change inside the master document? For a start
1273         is only a little. There are some placeholders (text in square brackets)
1274         there which you should take care of.
1275       </para>
1277       <para>
1278         <example><title>Master document header</title>
1279           <programlisting>
1280 <![CDATA[
1281 <bookinfo>
1282   <title>MODULENAME Reference Manual</title>
1283   <releaseinfo>
1284     for MODULENAME [VERSION]
1285     The latest version of this documentation can be found on-line at
1286     <ulink role="online-location" url="http://[SERVER]/MODULENAME/index.html">http://[SERVER]/MODULENAME/</ulink>.
1287   </releaseinfo>
1288 </bookinfo>
1290 <chapter>
1291   <title>[Insert title here]</title>
1293           </programlisting>
1294         </example>
1295       </para>
1297     </sect1>
1299     <sect1 id="metafiles_sections">
1300       <title>Editing the section file</title>
1302       <para>
1303         The section file is used to organise the documentation output by
1304         Gtk-Doc. Here one specifies which symbol belongs to which module or
1305         class and control the visibility (public or private).
1306       </para>
1308       <para>
1309         The section file is a plain test file with xml like syntax (using tags).
1310         Blank lines are ignored and lines starting with a '#' are treated as
1311         comment lines.
1312       </para>
1314       <para>
1315         The &lt;FILE&gt; ... &lt;/FILE&gt; tag is used to specify the file name,
1316         without any suffix. For example, using '&lt;FILE&gt;gnome-config&lt;/FILE&gt;'
1317         will result in the section declarations being output in the template
1318         file <filename>tmpl/gnome-config.sgml</filename>, which will be
1319         converted into the DocBook SGML/XML file <filename>sgml/gnome-config.sgml</filename>
1320         or .DocBook XML file <filename>xml/gnome-config.xml</filename>.
1321         (The name of the html file is based on the module name and the section
1322         title, or for gobjects it is based on the gobjects class name converted
1323         to lower case).
1324       </para>
1326       <para>
1327         The &lt;TITLE&gt; ... &lt;/TITLE&gt; tag is used to specify the title of
1328         the section. It is only useful before the templates (if used) are
1329         initially created, since the title set in the template file overrides
1330         this. Also if one uses SECTION comment in the sources, this is obsolete.
1331       </para>
1333       <para>
1334         You can group items in the section by using the &lt;SUBSECTION&gt; tag.
1335         Currently it outputs a blank line between subsections in the synopsis
1336         section.
1337         You can also use &lt;SUBSECTION Standard&gt; for standard GObject
1338         declarations (e.g. the functions like g_object_get_type and macros like
1339         G_OBJECT(), G_IS_OBJECT() etc.).
1340         Currently these are left out of the documentation.
1341         You can also use &lt;SUBSECTION Private&gt; for private declarations
1342         which will not be output (It is a handy way to avoid warning messages
1343         about unused declarations.).
1344         If your library contains private types which you don't want to appear in
1345         the object hierarchy and the list of implemented or required interfaces,
1346         add them to a Private subsection.
1347       </para>
1349       <para>
1350         You can also use &lt;INCLUDE&gt; ... &lt;/INCLUDE&gt; to specify the
1351         #include files which are shown in the synopsis sections.
1352         It contains a comma-separate list of #include files, without the angle
1353         brackets. If you set it outside of any sections, it acts for all
1354         sections until the end of the file. If you set it within a section, it
1355         only applies to that section.
1356       </para>
1358     </sect1>
1360   </chapter>
1362   <chapter id="reports">
1363     <title>Controlling the result</title>
1365     <para>
1366       A Gtk-Doc run generates report files inside the documentation directory.
1367       The generated files are named:
1368       <filename>&lt;package&gt;-undocumented.txt</filename>,
1369       <filename>&lt;package&gt;-undeclared.txt</filename> and
1370       <filename>&lt;package&gt;-unused.txt</filename>.
1371       All those are plain text files that can be viewed and postprocessed easily.
1372     </para>
1374     <para>
1375       The <filename>&lt;package&gt;-undocumented.txt</filename> file starts with
1376       the documentation coverage summary. Below are two sections divided by
1377       blank lines. The first section lists undocumented or incomplete symbols.
1378       The second section does the same for section docs. Incomplete entries are
1379       those, which have documentation, but where e.g. a new parameter has been
1380       added.
1381     </para>
1383     <para>
1384       The <filename>&lt;package&gt;-undeclared.txt</filename> file lists symbols
1385       given in the <filename>&lt;package&gt;-sections.txt</filename> but not
1386       found in the sources. Check if they have been removed or if they are
1387       misspelled.
1388     </para>
1390     <para>
1391       The <filename>&lt;package&gt;-unused.txt</filename> file lists symbol
1392       names, where the Gtk-Doc scanner has found documentation, but does not
1393       know where to put it. This means that the symbol has not yet been added to
1394       the <filename>&lt;package&gt;-sections.txt</filename> file.
1395     </para>
1397     <tip>
1398       <para>
1399         Enable or add the <option>TESTS=$(GTKDOC_CHECK)</option> line in Makefile.am.
1400         If at least gtk-doc 1.9 is installed, this will run sanity checks during
1401         <command>make check</command> run.
1402       </para>
1403     </tip>
1404     
1405     <para>
1406       One can also look at the files produced by the source code scanner:
1407       <filename>&lt;package&gt;-decl-list.txt</filename> and
1408       <filename>&lt;package&gt;-decl.txt</filename>. The first and can be
1409       compared with the section file if that is manualy maintained. The second
1410       lists all declarations fromt he headers If a symbol is missing one could
1411       check if this file contains it.
1412     </para>
1414     <para>
1415       If the project is GObject based, one can also look into the files produced
1416       by the object scanner:
1417       <filename>&lt;package&gt;.args.txt</filename>,
1418       <filename>&lt;package&gt;.hierarchy.txt</filename>,
1419       <filename>&lt;package&gt;.interfaces.txt</filename>,
1420       <filename>&lt;package&gt;.prerequisites.txt</filename> and
1421       <filename>&lt;package&gt;.signals.txt</filename>. If there are missing
1422       symbols in any of those, one can ask gtkdoc to keep the intermedia scanner
1423       file for further analysis, but running it as 
1424       <command>GTK_DOC_KEEP_INTERMEDIATE=1 make</command>.
1425     </para>
1426   </chapter>
1428   <chapter id="faq">
1429     <title>Frequently asked question</title>
1431     <segmentedlist>
1432       <?dbhtml list-presentation="list"?>
1433       <segtitle>Question</segtitle>
1434       <segtitle>Answer</segtitle>
1435       <seglistitem>
1436         <seg>No class hierarchy.</seg>
1437         <seg>
1438           The objects <function>xxx_get_type()</function> function has not been
1439           entered into the <filename>&lt;package&gt;.types</filename> file.
1440         </seg>
1441       </seglistitem>
1442       <seglistitem>
1443         <seg>Still no class hierarchy.</seg>
1444         <seg>
1445           Missing or wrong naming in <filename>&lt;package&gt;-sections.txt</filename>
1446           file (see <ulink url="http://mail.gnome.org/archives/gtk-doc-list/2003-October/msg00006.html">explanation</ulink>).
1447         </seg>
1448       </seglistitem>
1449       <seglistitem>
1450         <seg>Damn, I have still no class hierarchy.</seg>
1451         <seg>
1452           Is the object name (name of the instance struct, e.g. <type>GtkWidget</type>)
1453           part of the normal section (don't put this into Standard or Private
1454           subsections).
1455         </seg>
1456       </seglistitem>
1457       <seglistitem>
1458         <seg>No symbol index.</seg>
1459         <seg>
1460           Does the <filename>&lt;package&gt;-docs.{xml,sgml}</filename> contain a
1461           index that xi:includes the generated index?
1462         </seg>
1463       </seglistitem>
1464       <seglistitem>
1465         <seg>Symbols are not linked to their doc-section.</seg>
1466         <seg>
1467           Is the doc-comment using the correct markup (added #,% or ())?
1468           Check if the gtkdoc-fixxref warns about unresolvable xrefs.
1469         </seg>
1470       </seglistitem>
1471       <seglistitem>
1472         <seg>A new class does not appear in the docs.</seg>
1473         <seg>
1474           Is the new page xi:included from 
1475           <filename>&lt;package&gt;-docs.{xml,sgml}</filename>.
1476         </seg>
1477       </seglistitem>
1478       <seglistitem>
1479         <seg>A new symbol does not appear in the docs.</seg>
1480         <seg>
1481           Is the doc-comment properly formatted. Check for spelling mistakes in
1482           the begin of the comment. Check if the gtkdoc-fixxref warns about
1483           unresolvable xrefs. Check if the symbol is correctly listed in the
1484           <filename>&lt;package&gt;-sections.txt</filename> in a public subsection.
1485         </seg>
1486       </seglistitem>
1487       <seglistitem>
1488         <seg>A type is missing from the class hierarchy.</seg>
1489         <seg>
1490           If the type is listed in <filename>&lt;package&gt;.hierarchy</filename>
1491           but not in <filename>xml/tree_index.sgml</filename> then double check
1492           that the type is correctly placed in the <filename>&lt;package&gt;-sections.txt</filename>.
1493           If the type instance (e.g. <type>GtkWidget</type>) is not listed or
1494           incidentialy makred private it will not be shown.
1495         </seg>
1496       </seglistitem>
1497       <seglistitem>
1498         <seg>I get foldoc links for all gobject annotations.</seg>
1499         <seg>
1500           Check that <filename>xml/annotation-glossary.xml</filename> is
1501           xi:included from <filename>&lt;package&gt;-docs.{xml,sgml}</filename>.
1502         </seg>
1503       </seglistitem>
1505       <!-- gtk-doc warnings: -->
1506       <seglistitem>
1507         <seg>Parameter described in source code comment block but does not exist</seg>
1508         <seg>Check if the prototype in the header has different parameter names as in the source.</seg>
1509       </seglistitem>
1511       <!-- docbook warnings: -->
1512       <seglistitem>
1513         <seg>multiple "IDs" for constraint linkend: XYZ</seg>
1514         <seg>Symbol XYZ appears twice in <filename>&lt;package&gt;-sections.txt</filename> file.</seg>
1515       </seglistitem>
1516       <seglistitem>
1517         <seg>Element typename in namespace '' encountered in para, but no template matches.</seg>
1518         <seg />
1519       </seglistitem>
1520     </segmentedlist>
1521   </chapter>
1522     
1523   <!-- ======== Appendix: FDL ================================== -->
1524   &FDL;
1526 </book>