GTK-Doc Manual

Author:

Chris Lyttle

Author:

Dan Mueth

Author:

Stefan Sauer (Kost)

Introduction

This chapter introduces GTK-Doc and gives an overview of what it is and how it is used.

What is GTK-Doc?

GTK-Doc is used to document C code. It is typically used to document the public API of libraries, such as the GTK and GNOME libraries. But it can also be used to document application code.

How Does GTK-Doc Work?

GTK-Doc works by using documentation of functions placed inside the source files in specially-formatted comment blocks, or documentation added to the template files which GTK-Doc uses (though note that GTK-Doc will only document functions that are declared in header files; it won’t produce output for static functions).

GTK-Doc consists of a number of python scripts, each performing a different step in the process.

There are 4 main steps in the process:

  1. Writing the documentation. The author fills in the source files with the documentation for each function, macro, structs or unions, etc.

  2. Gathering information about the code. gtkdoc-scan scans the header files of the code looking for declarations of functions, macros, enums, structs, and unions. It creates the file <module>-decl-list.txt containing a list of the declarations, placing them into sections according to which header file they are in. On the first run this file is copied to <module>-sections.txt. The author can rearrange the sections, and the order of the declarations within them, to produce the final desired order. The second file it generates is <module>-decl.txt. This file contains the full declarations found by the scanner. If for some reason one would like some symbols to show up in the docs, where the full declaration cannot be found by the scanner or the declaration should appear differently, one can place entities similar to the ones in <module>-decl.txt into <module>-overrides.txt.

    gtkdoc-scangobj can also be used to dynamically query a library about any GObject subclasses it exports. It saves information about each object’s position in the class hierarchy and about any GObject properties and signals it provides.

  3. Generating the XML and HTML/PDF. For each section, gtkdoc-mkdb generates an XML file in the xml/ subdirectory. It merges in the symbol documentation obtained from the sources, using special comment blocks, and from introspection data.

    gtkdoc-mkhtml turns the XML files into HTML files in the html/ subdirectory. Likewise gtkdoc-mkpdf turns the XML files into a PDF document called <package>.pdf.

    Files in xml/ and html/ directories are always overwritten. One should never edit them directly.

  4. Fixing up cross-references between documents. After installing the HTML files, gtkdoc-fixxref can be run to fix up any cross-references between separate documents. For example, the GTK documentation contains many cross-references to types documented in the GLib manual. When creating the source tarball for distribution, gtkdoc-rebase turns all external links into web-links. When installing distributed (pregenerated) docs the same application will try to turn links back to local links (where those docs are installed).

Getting GTK-Doc

Requirements

python 2/3 - the main scripts are written in python.

xsltproc - the xslt processor from libxslt xmlsoft.org/XSLT/

docbook-xsl - the DocBook XSL stylesheets sourceforge.net/projects/docbook/files/docbook-xsl

One of source-highlight, highlight or vim - optional - used for syntax highlighting of examples

About GTK-Doc

Historically GTK-Doc was used to generate template files from the sources code. These template files could be used by developers to enter the API documentation. This approach was rather inconvenient because it required to keep the generated files under version control. Since GTK-Doc 1.9 it became possible to place all API information into source comments, which made the template support obsolete. In version 1.26 template support has been removed.

(FIXME)

(authors, web pages, mailing list, license, future plans, comparison with other similar systems.)

About this Manual

(FIXME)

(who it is meant for, where you can get it, license)

Project Setup

This Chapter describes the steps that are necessary to integrate GTK-Doc into your project. The integration of GTK-Doc into a project includes the following steps:

The following sections assume we work on a project called meep. This project contains two packages (or modules), a library called libmeep and an end-user app called meeper.

Setting up a skeleton documentation

A common convention is to place documentation into a folder called docs inside your top-level project directory. We usually distinguish between reference documentation intended for developers and an user manual intended for end-users. Again the convention is to have separate folders for both. We usually place the reference documentation in a folder named reference and the end-user manual in a folder named help as. According to the above convention the documentation for our libmeep package would be placed into: docs/reference/libmeep. For packages with just one library or application the documentation could also be placed directly into docs/reference. It is not mandatory to use the above convention, but if you choose to use a different directory structure you must adjust your build system configuration to match your directory structure.

In the following sections we will assume a directory structure for our meep project that uses the above conventions.

meep/
  docs/
    reference/  # reference documentation
      libmeep/
      meeper/
    help/       # optional: user manual
      meeper/
  src/
    libmeep/
    meeper/

Integration with Autotools

Integration of GTK-Doc into an autotools-based build system requires the following steps:

  • Ensure that gtkdocize is run once before the configure script. If an autogen.sh script is present, adjust it to check for GTK-Doc and add a call to gtkdocize.

    The main purpose of gtkdocize is to make the gtk-doc.make Makefile and the gtk-doc.m4 macro definition file available to the build system, either by copying or linking it into the project.

  • Add the necessary autoconf macros to configure.ac to enable GTK-Doc in your build system to allow configuration of GTK-Doc via the generated configure script.

    Among others with registers the --enable-gtk-doc option with the configure script.

  • Create an automake script for each application or library in your project. In the example used in this documentation this step applies to both meeper and libmeep.

In the following sections, we will perform the above steps in reverse order. We start with the automake scripts and work our way up to configure.ac and autogen.sh. Then we show how enable Gtk-Doc in the build system and how to build the documentation.

Integration with automake

First copy the Makefile.am from the examples sub-directory of the gtkdoc-sources to your project’s reference documentation directory (e.g. docs/reference/<package>). A local copy should be available under e.g. /usr/share/doc/gtk-doc-tools/examples/Makefile.am. If you have multiple packages repeat this for each one.

Note

Do not forget to add each Makefile.am to the AC_CONFIG_FILES macro in configure.ac. For docs/reference/libmeep/Makefile.am you will need to add the entry docs/reference/libmeep/Makefile to AC_CONFIG_FILES.

meep/
  docs/
    reference/  # reference documentation
      libmeep/
        Makefile.am
      meeper/
        Makefile.am
    help/       # optional: user manual
      meeper/
  src/
    libmeep/
    meeper/

Next, you need to customize the copied Makefiles and provide values for the various parameters in each Makefile.am. All settings have a comment above them that describes their purpose and how to customize the setting. Most settings are used to supply extra flags to the respective tools to which they apply. Every tool has a variable of the form <TOOLNAME>_OPTIONS (e.g. the tool gtkdoc-mkhtml has an option named MKHTML_OPTIONS). All the tools support --help to list the supported options.

The following list explains the most relevant options. Check the example Makefile.am for additional options.

  • DOC_MODULE is used to provide the name of the package that is being documentated (e.g. meeper, or libmeep).

  • DOC_SOURCE_DIR is used to specify the location of source directory which GTK-Doc searches for your API documentation. This will usually be DOC_SOURCE_DIR=$(top_srcdir)/src or a sub-directory of that directory.

  • HFILE_GLOB and CFILE_GLOB are used for dependencies. Each option take a file-glob (e.g. HFILE_GLOB=$(top_srcdir)/src/*.c). The documentation will be rebuilt if any of the matched files change.

  • EXTRA_HFILES allows to specify extra header files to include when scanning for API documentation, which are not found under DOC_SOURCE_DIR (e.g. EXTRA_HFILES=$(top_srcdir}/contrib/extra.h).

  • IGNORE_HFILES allows to specify header files or directories to ignore when scanning for API documentation. Use the basename of the file or directory (e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h private_code_folder).

  • HTML_IMAGES allows to specify images files which will be copied into the html/ directory of the generated documentation. If your API documentation includes any images they need to be added to this option (e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png).

  • content_files allows to specify extra files that are included by $(DOC_MAIN_SGML_FILE) (e.g. content_files=running.xml building.xml changes-2.0.xml).

  • expand_content_files allows to specify files where GTK-Doc abbreviations such as #GtkWidget are expanded (e.g. expand_content_files=running.xml).

Integration with autoconf

Integration with autoconf is very simple and includes one required step and an additional optional (but recommended) step. The first step is to add the GTK_DOC_CHECK macro to your configure.ac script. This registers several configure options to enable GTK-Doc and allows you to set default arguments for gtkdocize.

Warning

Make sure that the GTK_DOC_CHECK macro is not indented. The macro must start at the beginning of the line and should not start with whitespace.

The second step is to add the AC_CONFIG_MACRO_DIR(m4) to your configure.ac. This is not required but helps gtkdocize to automatically copy the macro definition (e.g gtk-doc.m4) which contains the GTK_DOC_CHECK macro to your project’s macro directory. Without this, the GTK_DOC_CHECK macro might not be found and you would need to explicitly tell the aclocal tool where to find the macro definition file.

# recommended: set m4 directory
AC_CONFIG_MACRO_DIR(m4)
# optional: register GTK-Doc in configure
GTK_DOC_CHECK([1.28])

The above example works, but will require all developers to have GTK-Doc installed. A better way is to make building the documentation optional as shown in the next example:

m4_ifdef([GTK_DOC_CHECK], [
# recommended: set m4 directory
AC_CONFIG_MACRO_DIR(m4)
# optional: register GTK-Doc in configure
GTK_DOC_CHECK([1.28])
],[
AM_CONDITIONAL([ENABLE_GTK_DOC], false)
])

The first argument is used to check for the Gtk-Doc version at configure time. The 2nd, optional argument is used by gtkdocize. The GTK_DOC_CHECK macro also adds several configure switches:

  1. –with-html-dir=PATH : path to installed docs

  2. –enable-gtk-doc : use GTK-Doc to build documentation [default=no]

  3. –enable-gtk-doc-html : build documentation in html format [default=yes]

  4. –enable-gtk-doc-pdf : build documentation in PDF format [default=no]

Important

GTK-Doc is disabled by default! Remember to pass the option '--enable-gtk-doc' to the next configure run. Otherwise pregenerated documentation is installed (which makes sense for users but not for developers).

After all changes to configure.ac are made, update the configure file. This can be done by re-running autogen.sh.

Integration with autogen

Most projects will have an autogen.sh script to setup the build infrastructure after the project was checked out from a version control system (such as Git or Subversion). GTK-Doc comes with a script called gtkdocize which can be used to copy the necessary files needed by Gtk-Doc to the source directory.

It should be run before autoreconf, autoheader, automake or autoconf.

gtkdocize || exit 1
GTKDOCIZE=$(which gtkdocize 2>/dev/null)
if test $? -ne 0; then
  echo "No gtk-doc support found. You can't build the docs."
else
  $GTKDOCIZE || exit 1
fi

When running gtkdocize it copies gtk-doc.make to your project root (or any directory specified by the --docdir option).

gtkdocize checks your configure.ac script for the GTK_DOC_CHECK macro. The GTK_DOC_CHECK macro can be used to pass extra arguments to the gtkdocize script. the 2nd parameter in the GTK_DOC_CHECK macro.

Alternatively, additional arguments can also be passed to gtkdocize via the GTKDOCIZE_FLAGS environment variable, or by directly specifying them to gtkdocize in autogen.sh.

Executing GTK-Doc from the Build System

After the previous steps it’s time to run the build. First we need to rerun autogen.sh. If this script runs configure for you, then give it the --enable-gtk-doc option. Otherwise manually run configure with this option afterwards.

The first make run generates several additional files in the doc-directories. The important ones are: <package>.types, <package>-docs.xml, <package>-sections.txt.

./autogen.sh --enable-gtk-doc
make

Now you can point your browser to docs/reference/<package>/index.html. With this initial setup you will only see a very simple document. The next chapter will teach you how to add API documentation to your code via special comment blocks. The Chapter afterwards introduces additional files and shows how to edit the master template to add additional chapters and sections to your documentation files.

Integration with CMake build systems

GTK-Doc now provides a GtkDocConfig.cmake module (and the corresponding GtkDocConfigVersion.cmake module). This provides a gtk_doc_add_module command that you can set in your CMakeLists.txt file.

The following example shows how to use this command.

find_package(GtkDoc 1.25 REQUIRED)

# Create the doc-libmeep target.
gtk_doc_add_module(
   libmeep ${CMAKE_SOURCE_DIR}/libmeep
      XML meep-docs.xml
      LIBRARIES libmeep
)

# Build doc-libmeep as part of the default target. Without this, you would
# have to explicitly run something like `make doc-libmeep` to build the docs.
add_custom_target(documentation ALL DEPENDS doc-libmeep)

# Install the docs. (This assumes you're using the GNUInstallDirs CMake module
# to set the CMAKE_INSTALL_DOCDIR variable correctly).
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libmeep/html
        DESTINATION ${CMAKE_INSTALL_DOCDIR})

Integration with plain makefiles or other build systems

In the case one does not want to use automake and therefore gtk-doc.make one will need to call the gtkdoc tools in the right order in own makefiles (or other build tools).

DOC_MODULE=meep
// sources have changed
gtkdoc-scan --module=$(DOC_MODULE) <source-dir>
gtkdoc-scangobj --module=$(DOC_MODULE)
gtkdoc-mkdb --module=$(DOC_MODULE) --output-format=xml --source-dir=<source-dir>
// XML files have changed
mkdir html
cd html && gtkdoc-mkhtml $(DOC_MODULE) ../meep-docs.xml
gtkdoc-fixxref --module=$(DOC_MODULE) --module-dir=html

One will need to look at the Makefile.am and gtk-doc.make to pick the extra options needed.

Integration with version control systems

As a rule of thumb, it’s the files you edit which should go under version control. For typical projects it’s these files: <package>.types, <package>-docs.xml, <package>-sections.txt, Makefile.am.

Files in the xml/ and html/ directories should not go under version control. Neither should any of the .stamp files.

Documenting the code

GTK-Doc uses source code comment with a special syntax for code documentation. During the next section you will find all information about the syntax of the comments.

The GTK-Doc scanner can handle the majority of C headers fine. In the case of receiving warnings from the scanner that look like a special case, one can hint GTK-Doc to skip over them.

#ifndef __GTK_DOC_IGNORE__
/* unparseable code here */
#endif

Warning

GTK-Doc’s supports:

#ifndef(__GTK_DOC_IGNORE__)

but not:

#if !defined(__GTK_DOC_IGNORE__)

or other combinations.

Documentation comments

A multiline comment that starts with an additional “*” marks a documentation block that will be processed by GTK-Doc tools.

/**
 * identifier:
 * documentation ...
 */

The identifier is one line with the name of the item the comment is related to. The syntax differs a little depending on the item.

The documentation block is also different for each symbol type. Symbol types that get parameters such as functions or macros have the parameter description first followed by a blank line (just a “*”). Afterwards follows the detailed description. All lines (outside program listings and CDATA sections) just containing a “␣*” (blank-asterisk) are converted to paragraph breaks. If you don’t want a paragraph break, change that into “␣*␣” (blank-asterisk-blank-blank). This is useful in preformatted text (code listings).

If you include C-style comments in your program listings you may need to take special care to avoid confusing the preprocessor with comment strings. The easiest way to do this is with single-line comments:

* |[
* // Theme labels that are descendants of a window
* GtkWindow GtkLabel {
*     background-color: #898989
* }

Tip

When documenting code, describe two aspects:

  • What it is: The name for a class or function can sometimes be misleading for people coming from a different background.

  • What it does: Tell about common uses. Put it in relation with the other API.

Tip

GTK-Doc is for documenting public API. Thus one cannot write documentation for static symbols. Nevertheless it is good to comment those symbols too. This helps other developers to understand your code. Therefore we recommend to comment these using normal comments (without the second “*” in the first line). If later the function needs to be made public, all one needs to do is to add another “*“ in the comment block and insert the symbol name at the right place inside the sections file.

Documenting sections

Each section of the documentation contains information about one class or module. To introduce the component one can write a section block. The short description is also used inside the table of contents. All the “@” fields are optional.

/**
 * SECTION:meepapp
 * @short_description: the application class
 * @title: Meep application
 * @section_id:
 * @see_also: #MeepSettings
 * @stability: Stable
 * @include: meep/app.h
 * @image: application.png
 *
 * The application class handles ...
 */
SECTION: <NAME>

The name links the section documentation to the respective part in the PACKAGE-sections.txt file. The name given here should match the <FILE> tag in the PACKAGE-sections.txt file.

@short_description

A one line description of the section, that later will appear after the links in the TOC and at the top of the section page.

@title

The section title defaults to <NAME> from the SECTION declaration. It can be overridden with the @title field.

@section_id

Overrides the use of title as a section identifier. For GObjects the <title> is used and for other sections it is <MODULE>-<title>.

@see_also

A list of symbols that are related to this section.

@stability

An informal description of the stability level this API has. We recommend the use of one of these terms:

Stable

The intention of a Stable interface is to enable arbitrary third parties to develop applications to these interfaces, release them, and have confidence that they will run on all minor releases of the product (after the one in which the interface was introduced, and within the same major release). Even at a major release, incompatible changes are expected to be rare, and to have strong justifications.

Unstable

Unstable interfaces are experimental or transitional. They are typically used to give outside developers early access to new or rapidly changing technology, or to provide an interim solution to a problem where a more general solution is anticipated. No claims are made about either source or binary compatibility from one minor release to the next.

Private

An interface that can be used within the GNOME stack itself, but that is not documented for end-users. Such functions should only be used in specified and documented ways.

Internal

An interface that is internal to a module and does not require end-user documentation. Functions that are undocumented are assumed to be Internal.

@include

The #include files to show in the section synopsis (a comma separated list), overriding the global value from the section file or command line. This item is optional.

@image

The image to display at the top of the reference page for this section. This will often be some sort of a diagram to illustrate the visual appearance of a class or a diagram of its relationship to other classes. This item is optional.

Tip

To avoid unnecessary recompilation after changing the documentation put the section docs into the C-source where possible.

Documenting symbols

Each symbol (function, macro, struct, enum, signal and property) is documented in a separate block. The block is best placed close to the definition of the symbols so that it is easy to keep them in sync. Thus functions are usually documented in the C-source and macros, structs and enums in the header file.

General tags

You can add versioning information to all documentation elements to tell when an API was introduced, or when it was deprecated.

Since

Description since which version of the code the API is available.

Deprecated

Paragraph denoting that this function should no be used anymore. The description should point the reader to the new API.

You can also add stability information to all documentation elements to indicate whether API stability is guaranteed for them for all future minor releases of the project.

The default stability level for all documentation elements can be set by passing the --default-stability argument to gtkdoc-mkdb with one of the values below.

Stable

Mark the element as stable. This is for public APIs which are guaranteed to remain stable for all future minor releases of the project.

Unstable

Mark the element as unstable. This is for public APIs which are released as a preview before being stabilised.

Private

Mark the element as private. This is for interfaces which can be used by tightly coupled modules, but not by arbitrary third parties.

/**
 * foo_get_bar:
 * @foo: some foo
 *
 * Retrieves @foo's bar.
 *
 * Returns: @foo's bar
 *
 * Since: 2.6
 * Deprecated: 2.12: Use foo_baz_get_bar() instead.
 */
Bar *
foo_get_bar(Foo *foo)
{
...

Annotations

Documentation blocks can contain annotation tags. They are used by GObject Introspection to generate language bindings. They will be rendered as-is with tooltips describing their meaning. More information about annotations be found in “GObject Introspection/Annotations”.

/**
 * foo_get_pool:
 * @name: (nullable): a pool's name
 *
 * Gets a pool given its name.
 *
 * Returns: (element-type Foo) (transfer container): the corresponding pool.
 */
GList *foo_get_pool(char *name);

Function comment block

Please remember to:

  • Document whether returned objects, lists, strings, etc, should be freed/unrefed/released.

  • Document whether parameters can be null, and what happens if they are.

  • Mention interesting pre-conditions and post-conditions where appropriate.

Gtk-doc assumes all symbols (macros, functions) starting an underscore (“_”) are private. They are treated like static functions.

/**
 * function_name:
 * @par1:  description of parameter 1. These can extend over more than
 * one line.
 * @par2:  description of parameter 2
 * @...: a %NULL-terminated list of bars
 *
 * The function description goes here. You can use @par1 to refer to parameters
 * so that they are highlighted in the output. You can also use %constant
 * for constants, function_name2() for functions and #GtkWidget for links to
 * other declarations (which may be documented elsewhere).
 *
 * Returns: an integer.
 *
 * Since: 2.2
 * Deprecated: 2.18: Use other_function() instead.
 */
Returns

Paragraph describing the returned result.

@…

In case the function has variadic arguments, you should use this tag. By legacy, @Varargs also works.

Property comment block

/**
 * SomeWidget:some-property:
 *
 * Here you can document a property.
 */
g_object_class_install_property (object_class, PROP_SOME_PROPERTY, ...);

Signal comment block

Please remember to:

  • Document when the signal is emitted and whether it is emitted before or after other signals.

  • Document what an application might do in the signal handler.

/**
 * FooWidget::foobarized:
 * @widget: the widget that received the signal
 * @foo: some foo
 * @bar: some bar
 *
 * The ::foobarized signal is emitted each time someone tries to foobarize @widget.
 */
foo_signals[FOOBARIZED] =
  g_signal_new ("foobarized",
                ...

Struct comment block

/**
 * FooWidget:
 * @bar: some #gboolean
 *
 * This is the best widget, ever.
 */
typedef struct _FooWidget {
  GtkWidget parent_instance;

  gboolean bar;
} FooWidget;

Use /*< private >*/ before the private struct fields you want to hide. Use /*< public >*/ for the reverse behaviour.

If the first field is g_iface, parent_instance or parent_class it will be considered private automatically and doesn’t need to be mentioned in the comment block.

Struct comment blocks can also be used for GObjects and GObjectClasses. It is usually a good idea to add a comment block for a class, if it has virtual methods (as this is how they can be documented). For the GObject itself one can use the related section docs, having a separate block for the instance struct would be useful if the instance has public fields. One disadvantage here is that this creates two index entries of the same name (the structure and the section).

Enum comment block

/**
 * Something:
 * @SOMETHING_FOO: something foo
 * @SOMETHING_BAR: something bar
 *
 * Enum values used for the thing, to specify the thing.
 */
typedef enum {
  SOMETHING_FOO,
  SOMETHING_BAR,
  /*< private >*/
  SOMETHING_COUNT
} Something;

Use /*< private >*/ before the private enum values you want to hide. Use /*< public >*/ for the reverse behaviour.

Documenting programs

You can document programs and their command line interface using inline documentation.

PROGRAM

Defines the start of a program documentation.

@short_description

Defines a short description of the program. (Optional)

@synopsis

Defines the arguments, or list of arguments that the program can take. (Optional)

@see_also

See Also manual page section. (Optional)

@arg

Argument(s) passed to the program and their description. (Optional)

Description

A longer description of the program.

Returns

Specify what value(s) the program returns. (Optional)

/**
 * PROGRAM:test-program
 * @short_description: A test program
 * @synopsis: test-program [*OPTIONS*...] --arg1 *arg* *FILE*
 * @see_also: test(1)
 * @--arg1 *arg*: set arg1 to *arg*
 * @--arg2 *arg*: set arg2 to *arg*
 * @-v, --version: Print the version number
 * @-h, --help: Print the help message
 *
 * Long description of program.
 *
 * Returns: Zero on success, non-zero on failure
 */
int main(int argc, char *argv[]) {
  return 0;
}

Formatting

To permit structuring and stylization of the documentation, GTK-DOC parses most of the content of comment blocks as Markdown.

GTK-Doc implements its own Markdown parser because no Python Markdown parser producing DocBook was found. It is inspired by the design of ParseDown.

MarkDown

Markdown markup is comprised entirely of punctuation characters with an attempt to make them look like what they mean.

If you need to use markup characters in your documentation without GTK-Doc interpreting them you can escape them with a backslash (“”).

/**
 * identifier:
 *
 * documentation paragraph ...
 *
 * # Sub Heading #
 *
 * ## Second Sub Heading
 *
 * # Sub Heading With a Link Anchor # {#heading-two}
 *
 * more documentation:
 *
 * - list item 1
 *
 *   Paragraph inside a list item.
 *
 * - list item 2
 *
 * 1. numbered list item
 * 2. another numbered list item
 *
 * Another paragraph. [A Link to the GNOME Website](http://www.gnome.org/)
 *
 * ![an inline image](plot-result.png)
 *
 * [A link to the heading anchor above][heading-two]
 *
 * A C-language example:
 * |[<!-- language="C" -->
 * GtkWidget *label = gtk_label_new ("Gorgeous!");
 * ]|
 */
Differences from traditional Markdown

The differences from typical Markdown are either extensions to the syntax, different behavior of the standard syntax, or unimplemented features.

Extensions to the syntax
|[

At the start of a line starts a program listing block.

|[<!-- language="…" -->

At the start of a line starts a program listing block for the given language.

]|

At the start of a line ends a program listing block.

# Heading 1 # {#anchor}

Headings may include optional anchor identifiers.

Inside of a fenced code block (|[…]|), the text is left unmodified except that, by legacy, some entities (such as &commat;, &percnt;, etc.) are converted back to the actual characters.

Different behavior

Only two levels of heading are supported. See Generated files for an explanation.

Reference links are treated somewhat differently. [text][label] gets converted to a Docbook <link/> element that can be used to link to any XML ID, not just those defined with Markdown anchors.

Unimplemented features

The following are not supported and likely never will be:

  • Backtick fenced code blocks. |[…]| syntax is used instead.

  • Thematic breaks (horizontal rules)

  • Link reference definitions

  • Reference links for images

  • shortcut reference link ([foo][])

Not supported at this time but may be in the future:

  • Optional link titles

  • Emphasis

Typical Markdown
Paragraphs

Paragraphs are one or more lines of consecutive text followed by a blank line.

This is one paragraph.

And this is another.
Headings

Two levels of heading are supported. They can be created by adding one “#” mark before a first level heading or “##” before a second level heading. Optional anchor identifiers may be included at the end of the line.

# Heading 1

## Heading 2

## Heading 3 with anchor ## {#anchor-id}
Block quotes

One or more lines of text may be inset by starting the line with “>”.

> This is an inset block.
> That can continue on another line.
Lists

Unordered lists may be created by starting a line with a “-” character. Each list item may contain multiple lines of text followed by a blank line. Each subsequent line be indented by 2 or more spaces. Additional paragraphs may be used by including a blank line.

- This is a first list item
  This is a continuation of the same item.

  This is another paragraph.

- This is a second list item.

Ordered lists may be created by using a number followed by a period in the manner described above. The number value used does not matter. However, to aid readability of the source it is recommended to keep a natural order.

1. First item

2. Second item.
Images

Images may be included using a variation of the link syntax. The alternate text of the image should be placed in square brackets preceded by a “!” character and the image file name should follow in square brackets.

![a plot of the result][plot-result.png]

DocBook

When Markdown is not enough, one can embed DocBook as Markdown HTML blocks (block) or Raw HTML (inline). Notable examples are tables and emphasis; they are missing from GTK-Doc Markdown. To prevent what looks like a DocBook element to be interpreted as such, use the backslash (“”) as in: \<sbr/>.

The Markdown parser reproduces embedded DocBook as-is, without parsing. So, DocBook can be used within Markdown but not Markdown within DocBook.

GTK-Doc still uses DocBook 4, but a transition to Docbook 5 is planned.

/**
 * SECTION: docbook
 * @short_description: DocBook in GTK-Doc comment block
 *
 * <table frame="all">
 *   <title>Foo tokens</title>
 *   <tgroup cols="2" align="left" colsep="1" rowsep="1">
 *     <thead>
 *       <row><entry>ID</entry><entry>Literal</entry></row>
 *     </thead>
 *     <tbody>
 *       <row><entry>0001</entry><entry>FOO_INT</entry></row>
 *       <row><entry>0002</entry><entry>FOO_CHAR</entry></row>
 *     </tbody>
 *   </tgroup>
 * </table>
 *
 * <caution>
 *   <para>Make sure you free the data after use.</para>
 * </caution>
 *
 * This is <emphasis>important</emphasis>!
 */

Abbreviations

One advantage of hyper-text over plain-text is the ability to have links in the document. Writing the correct markup for a link can be tedious though. GTK-Doc comes to help by providing several useful abbreviations. Abbreviation expansion occurs after Markdown parsing, once text has been transformed into DocBook.

  • Use function() to refer to functions or macros which take arguments.

  • Use @param to refer to parameters. Also use this when referring to parameters of other functions, related to the one being described.

  • Use %constant to refer to a constant.

  • Use #symbol to refer to other types of symbol, e.g. structs and enums and macros which don’t take arguments.

  • Use #Object::signal to refer to a GObject signal.

  • Use #Object:property to refer to a GObject property.

Still, the backslash (“”) is used to avoid expansion.

/**
 * foo_init:
 * @automatic: if %TRUE memory is managed
 *
 * #Foo subsystem must be initialized before use.
 * If @automatic parameter is %FALSE, memory is not managed.
 *
 * New #Foo<!-- -->s (plural) are created with foo_new().
 *
 * #Foo:label is a read-only property.
 *
 * #Foo::changed signal is fired whenever the foo is modified.
 *
 * #Foo.references_count field can be read but no written.
 *
 * \#Foo and foo_init\() do not expand.
 */
void foo_init(gboolean automatic);

Generated files

GTK-Doc generates DocBook files essentially. The documentation is afterward transformed into HTML, PDF, man pages, DevHelp, etc. DocBook is a rich semantic markup language for technical documentation. It is an XML language; comprehensive toolkits for manipulation and processing are available. Information about DocBook can be found in “DocBook: The Definitive Guide”.

Each GTK-Doc section gives a DocBook <refentry/> document. Within, GTK-Doc subsections (description, functions, signals, etc.) go in a <refsect1/>. Within, symbols go in a <refsect2/>. Some symbols needs more refinement. Functions have parameters, for example. Those go in a <refsect3/>.

This use of DocBook explain, for example, the limitation on Markdown headings. A heading starts a DocBook <refentry/> subsection. Numbered section (unlike recursive ones) are limited to three. So GTK-Doc section descriptions can have only two heading levels, symbols only one, and the rest none.

GTK-Doc generates other DocBook documents: an index of all symbols (<indexdiv/> document), few indexes for new symbols, few others for deprecated symbols, an annotation glossary (<glossary/> document), a GObject index (<informaltable/> document), GObjects hierarchy (<screen/> document), etc.

All these documents are included (XML <xi:include/>) in a master document which is a Docbook <book/> document. The master document gets generated if the user doesn’t provide one. The master document can also include user provided DocBook documents. Abbreviations inside these content files can be expanded by using the --expand-content-files option of gtkdoc-mkdb. See Editing the master document for more information about the master document.

Filling the extra files

There are a couple of extra files, that need to be maintained along with the inline source code comments: <package>.types, <package>-docs.xml, <package>-sections.txt.

Editing the types file

If your library or application includes GObjects, you want their signals, arguments/parameters and position in the hierarchy to be shown in the documentation. All you need to do, is to list the xxx_get_type functions together with their include inside the <package>.types file.

#include <gtk/gtk.h>

gtk_accel_label_get_type
gtk_adjustment_get_type
gtk_alignment_get_type
gtk_arrow_get_type

Since GTK-Doc 1.8 gtkdoc-scan can generate this list for you. Just add “–rebuild-types” to SCAN_OPTIONS in Makefile.am. If you use this approach you should not dist the types file nor have it under version control.

Editing the master document

GTK-Doc produces documentation in DocBook XML. When processing the inline source comments, the GTK-Doc tools generate one documentation page per class or module as a separate file. The master document includes them and place them in an order.

While GTK-Doc creates a template master document for you, later runs will not touch it again. This means that one can freely structure the documentation. That includes grouping pages and adding extra pages. GTK-Doc has now a test suite, where also the master-document is recreated from scratch. Its a good idea to look at this from time to time to see if there are some new goodies introduced there.

Tip

Do not create tutorials as extra documents. Just write extra chapters. The benefit of directly embedding the tutorial for your library into the API documentation is that it is easy to link for the tutorial to symbol documentation. Apart chances are higher that the tutorial gets updates along with the library.

So what are the things to change inside the master document? For a start is only a little. There are some placeholders (text in square brackets) there which you should take care of.

<bookinfo>
  <title>MODULENAME Reference Manual</title>
  <releaseinfo>
    for MODULENAME [VERSION]
    The latest version of this documentation can be found on-line at
    <ulink role="online-location" url="http://[SERVER]/MODULENAME/index.html">http://[SERVER]/MODULENAME/</ulink>.
  </releaseinfo>
</bookinfo>

<chapter>
  <title>[Insert title here]</title>

In addition a few option elements are created in commented form. You can review these and enable them as you like.

<!-- enable this when you use GObject introspection annotations
<xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
-->

Finally you need to add new section whenever you introduce one. The `gtkdoc-check <#gtk-doc-1-16>`__ tool will remind you of newly generated XML files that are not yet included into the doc.

<chapter>
  <title>my library</title>
    <xi:include href="xml/object.xml"/>
    ...

Editing the section file

The section file is used to organise the documentation output by GTK-Doc. Here one specifies which symbol belongs to which module or class and control the visibility (public or private).

The section file is a plain text file with tags delimiting sections. Blank lines are ignored and lines starting with a ‘#’ are treated as comment lines.

Note

While the tags make the file look like XML, it is not. Please do not close tags like <SUBSECTION>.

<INCLUDE>libmeep/meep.h</INCLUDE>

<SECTION>
<FILE>meepapp</FILE>
<TITLE>MeepApp</TITLE>
MeepApp
<SUBSECTION Standard>
MEEP_APP
...
MeepAppClass
meep_app_get_type
</SECTION>

The <FILE> … </FILE> tag is used to specify the file name, without any suffix. For example, using ‘<FILE>gnome-config</FILE>’ will result in the section declarations being output in the DocBook XML file xml/gnome-config.xml. (The name of the HTML file is based on the module name and the section title, or for GObjects it is based on the GObjects class name converted to lower case).

The <TITLE> … </TITLE> tag is used to specify the title of the section. It is only useful before the templates (if used) are initially created, since the title set in the template file overrides this. Also if one uses SECTION comment in the sources, this is obsolete.

You can group items in the section by using the <SUBSECTION> tag. Currently it outputs a blank line between subsections in the synopsis section. You can also use <SUBSECTION Standard> for standard GObject declarations (e.g. the functions like g_object_get_type and macros like G_OBJECT(), G_IS_OBJECT() etc.). Currently these are left out of the documentation. You can also use <SUBSECTION Private> for private declarations which will not be output (it is a handy way to avoid warning messages about unused declarations). If your library contains private types which you don’t want to appear in the object hierarchy and the list of implemented or required interfaces, add them to a Private subsection. Whether you would place GObject and GObjectClass like structs in public or Standard section depends if they have public entries (variables, vmethods).

You can also use <INCLUDE> … </INCLUDE> to specify the #include files which are shown in the synopsis sections. It contains a comma-separate list of #include files, without the angle brackets. If you set it outside of any sections, it acts for all sections until the end of the file. If you set it within a section, it only applies to that section.

Controlling the result

A GTK-Doc run generates report files inside the documentation directory. The generated files are named: <package>-undocumented.txt, <package>-undeclared.txt and <package>-unused.txt. All those are plain text files that can be viewed and postprocessed easily.

The <package>-undocumented.txt file starts with the documentation coverage summary. Below are two sections divided by blank lines. The first section lists undocumented or incomplete symbols. The second section does the same for section docs. Incomplete entries are those, which have documentation, but where e.g. a new parameter has been added.

The <package>-undeclared.txt file lists symbols given in the <package>-sections.txt but not found in the sources. Check if they have been removed or if they are misspelled.

The <package>-unused.txt file lists symbol names, where the GTK-Doc scanner has found documentation, but does not know where to put it. This means that the symbol has not yet been added to the <package>-sections.txt file.

Tip

Enable or add the TESTS=$(GTKDOC_CHECK) line in Makefile.am. If at least GTK-Doc 1.9 is installed, this will run sanity checks during make check run.

One can also look at the files produced by the source code scanner: <package>-decl-list.txt and <package>-decl.txt. The first one can be compared with the section file if that is manually maintained. The second lists all declarations from the headers. If a symbol is missing one could check if this file contains it.

If the project is GObject based, one can also look into the files produced by the object scanner: <package>.args.txt, <package>.hierarchy.txt, <package>.interfaces.txt, <package>.prerequisites.txt and <package>.signals.txt. If there are missing symbols in any of those, one can ask GTK-Doc to keep the intermediate scanner file for further analysis, by running it as GTK_DOC_KEEP_INTERMEDIATE=1 make.

Command line interface

GTK-Doc workflow

../_images/gtk-doc-workflow.png

Environment variables

All the commands access:

  • GTKDOC_TRACE, and

  • PYTHONIOENCODING.

gtkdoc-check has a poor interface, it gets its parameters from the environment:

  • DOC_MAIN_SGML_FILE,

  • DOC_MODULE, and

  • DOC_MODULE_DIR.

gtkdoc-scangobj accesses:

  • GTK_DOC_KEEP_INTERMEDIATE,

  • CC,

  • CFLAGS,

  • LD,

  • LDFLAGS, and

  • RUN.

gtkdoc-mkhtml accesses:

  • GTKDOC_PROFILE.

gtkdoc-check

$ gtkdoc-check --help
usage: gtkdoc-check [-h] [--version]

gtkdoc-check version 1.34.1 - run documentation unit tests

options:
  -h, --help  show this help message and exit
  --version   show program's version number and exit

gtkdoc-depscan

$ gtkdoc-depscan --help
Usage: gtkdoc-depscan [options]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -b BOOKS, --book=BOOKS
                        name of a devhelp book to consider
  -d PATH, --html-dir=PATH
                        path of additional folders with devhelp books
  -s, --summarize       print only a brief summary
  -u, --list-unknown    list symbols not found in any book
  -v, --verbose         print additional information

gtkdoc-fixxref

$ gtkdoc-fixxref --help
usage: gtkdoc-fixxref [-h] [--version] --module MODULE
                      [--module-dir MODULE_DIR] [--html-dir HTML_DIR]
                      [--extra-dir EXTRA_DIR] [--src-lang SRC_LANG]

gtkdoc-fixxref version 1.34.1 - fix cross references in html files

options:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --module MODULE       Name of the doc module being processed.
  --module-dir MODULE_DIR
                        The directory which contains the generated HTML.
  --html-dir HTML_DIR   The directory where gtk-doc generated documentation is
                        installed.
  --extra-dir EXTRA_DIR
                        Directories to recursively scan for indices
                        (*.devhelp2) in addition to HTML_DIR
  --src-lang SRC_LANG   Programing language used for syntax highlighting. The
                        available languages depend on the source highlighter
                        you use.

gtkdoc-mkdb

$ gtkdoc-mkdb --help
usage: gtkdoc-mkdb [-h] [--version] --module MODULE [--source-dir SOURCE_DIR]
                   [--source-suffixes SOURCE_SUFFIXES]
                   [--ignore-files IGNORE_FILES] [--output-dir OUTPUT_DIR]
                   [--tmpl-dir TMPL_DIR] [--main-sgml-file MAIN_SGML_FILE]
                   [--expand-content-files EXPAND_CONTENT_FILES]
                   [--sgml-mode | --xml-mode]
                   [--default-stability {,Stable,Private,Unstable}]
                   [--default-includes DEFAULT_INCLUDES]
                   [--output-format OUTPUT_FORMAT] [--name-space NAME_SPACE]
                   [--outputallsymbols] [--outputsymbolswithoutsince]

options:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --module MODULE       Name of the doc module being parsed
  --source-dir SOURCE_DIR
  --source-suffixes SOURCE_SUFFIXES
  --ignore-files IGNORE_FILES
  --output-dir OUTPUT_DIR
  --tmpl-dir TMPL_DIR   DEPRECATED
  --main-sgml-file MAIN_SGML_FILE
  --expand-content-files EXPAND_CONTENT_FILES
  --sgml-mode
  --xml-mode
  --default-stability {,Stable,Private,Unstable}
  --default-includes DEFAULT_INCLUDES
  --output-format OUTPUT_FORMAT
  --name-space NAME_SPACE
  --outputallsymbols
  --outputsymbolswithoutsince

gtkdoc-mkhtml

$ gtkdoc-mkhtml --help
usage: gtkdoc-mkhtml [-h] [--version] [--verbose] [--path PATH]
                     [--uninstalled]
                     [args ...]

gtkdoc-mkhtml version 1.34.1 - generate documentation in html format

positional arguments:
  args           MODULE DRIVER_FILE

options:
  -h, --help     show this help message and exit
  --version      show program's version number and exit
  --verbose      Print extra output while processing
  --path PATH    Extra source directories
  --uninstalled  ???

gtkdoc-mkhtml2

$ gtkdoc-mkhtml2 --help
usage: gtkdoc-mkhtml2 [-h] [--version] [--output-dir OUTPUT_DIR] [--path PATH]
                      [--extra-dir EXTRA_DIR] [--src-lang SRC_LANG]
                      [--uninstalled]
                      [args ...]

gtkdoc-mkhtml version 1.34.1 - generate documentation in html format

positional arguments:
  args                  MODULE DRIVER_FILE

options:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --output-dir OUTPUT_DIR
                        The directory where the results are stored
  --path PATH           Extra source directories
  --extra-dir EXTRA_DIR
                        Directories to recursively scan for indices
                        (*.devhelp2)in addition to HTML_DIR
  --src-lang SRC_LANG   Programing language used for syntax highlighting.
                        Thiscan be any language pygments supports.
  --uninstalled         ???

gtkdoc-mkman

$ gtkdoc-mkman --help
usage: gtkdoc-mkman [-h] [--version] [--verbose] [--path PATH] [--uninstalled]
                    args args

gtkdoc-mkman version 1.34.1 - generate documentation in man format

positional arguments:
  args           MODULE DRIVER_FILE

options:
  -h, --help     show this help message and exit
  --version      show program's version number and exit
  --verbose      Print extra output while processing
  --path PATH    Extra source directories
  --uninstalled  ???

gtkdoc-mkpdf

$ gtkdoc-mkpdf --help
usage: gtkdoc-mkpdf [-h] [--version] [--verbose] [--path PATH]
                    [--imgdir IMGDIR] [--uninstalled]
                    args args

gtkdoc-mkpdf version 1.34.1 - generate documentation in pdf format

positional arguments:
  args             MODULE DRIVER_FILE

options:
  -h, --help       show this help message and exit
  --version        show program's version number and exit
  --verbose        Print extra output while processing.
  --path PATH      Extra source directories.
  --imgdir IMGDIR  Extra image directories.
  --uninstalled    ???

gtkdoc-rebase

$ gtkdoc-rebase --help
usage: gtkdoc-rebase [-h] [--version] --html-dir HTML_DIR
                     [--other-dir OTHER_DIR] [--dest-dir DEST_DIR]
                     [--aggressive] [--verbose] [--online] [--relative]

gtkdoc-rebase version 1.34.1 - rewrite links in html docs

options:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --html-dir HTML_DIR   The directory which contains the installed HTML
  --other-dir OTHER_DIR
                        Directories to recursively scan for indices
                        (*.devhelp2).May be used more than once for multiple
                        directories.
  --dest-dir DEST_DIR   Staging area virtual root, this prefix will be
                        removedfrom HTML_DIR for relative link calculation.
  --aggressive          Rebase links to all files that are under a directory
                        matching a package name.
  --verbose             Print extra output while processing
  --online              Prefer cross-references to online documents
  --relative            Prefer relative cross-references

gtkdoc-scan

$ gtkdoc-scan --help
usage: gtkdoc-scan [-h] [--version] --module MODULE [--source-dir SOURCE_DIR]
                   [--ignore-headers IGNORE_HEADERS] [--output-dir OUTPUT_DIR]
                   [--deprecated-guards DEPRECATED_GUARDS]
                   [--ignore-decorators IGNORE_DECORATORS]
                   [--rebuild-sections] [--rebuild-types]
                   [headers ...]

gtkdoc-scan version 1.34.1 - scan header files for public symbols

positional arguments:
  headers

options:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --module MODULE       Name of the doc module being processed.
  --source-dir SOURCE_DIR
                        Directories containing the source files to scan
  --ignore-headers IGNORE_HEADERS
                        A space-separated list of header files/dirs not to
                        scan
  --output-dir OUTPUT_DIR
                        The directory where the results are stored
  --deprecated-guards DEPRECATED_GUARDS
                        A |-separated list of symbols used as deprecation
                        guards
  --ignore-decorators IGNORE_DECORATORS
                        A |-separated list of additional decorators
                        indeclarations that should be ignored
  --rebuild-sections    Rebuild (overwrite) the MODULE-sections.txt file
  --rebuild-types       Automatically recreate the MODULE.types file usingall
                        the *_get_type() functions found

gtkdoc-scangobj

$ gtkdoc-scangobj --help
usage: gtkdoc-scangobj [-h] [--version] --module MODULE [--types TYPES]
                       [--type-init-func TYPE_INIT_FUNC]
                       [--query-child-properties QUERY_CHILD_PROPERTIES]
                       [--output-dir OUTPUT_DIR] [--cc CC] [--ld LD]
                       [--cflags CFLAGS] [--ldflags LDFLAGS] [--run RUN]
                       [--verbose]

gtkdoc-rebase version 1.34.1 - introspect g-objects

options:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --module MODULE       Name of the doc module being parsed
  --types TYPES         The name of the file to store the types in
  --type-init-func TYPE_INIT_FUNC
                        The init function(s) to call instead of g_type_init()
  --query-child-properties QUERY_CHILD_PROPERTIES
                        A function that returns a list of child properties for
                        a class
  --output-dir OUTPUT_DIR
                        The directory where the results are stored
  --cc CC               The compiler to use
  --ld LD               The linker to use
  --cflags CFLAGS       Compiler flags
  --ldflags LDFLAGS     Linker flags
  --run RUN             Command for running the scanner
  --verbose             Print extra output while processing

gtkdocize

$ gtkdocize --help
usage: gtkdocize [ --copy ] [ --docdir DIR ] [ --flavour {legacy|legacy-flat|no-tmpl|no-tmpl-flat|no-xslt|no-xslt-flat} ] [ --srcdir DIR ]

Modernizing the documentation

GTK-Doc has been around for quite some time. In this section we list new features together with the version since when it is available.

GTK-Doc 1.9

When using XML instead of SGML, one can actually name the master document <package>-docs.xml.

This version supports SCAN_OPTIONS=--rebuild-sections in Makefile.am. When this is enabled, the <package>-sections.txt is autogenerated and can be removed from the vcs. This only works nicely for projects that have a very regular structure (e.g. each .{c,h} pair will create new section). If one organize a project close to that updating a manually maintained section file can be as simple as running meld <package>-decl-list.txt <package>-sections.txt.

Version 1.8 already introduced the syntax for documenting sections in the sources instead of the separate files under tmpl. This version adds options to switch the whole doc module to not use the extra tmpl build step at all, by using --flavour no-tmpl in configure.ac. If you don’t have a tmpl checked into your source control system and haven’t yet switched, just add the flag to configure.ac and you are done.

GTK-Doc 1.10

This version supports SCAN_OPTIONS=--rebuild-types in Makefile.am. When this is enabled, the <package>.types is autogenerated and can be removed from the vcs. When using this feature it is important to also setup the IGNORE_HFILES in Makefile.am for code that is build conditionally.

GTK-Doc 1.16

This version includes a new tool called gtkdoc-check. This tool can run a set of sanity checks on your documentation. It is enabled by adding these lines to the end of Makefile.am.

if ENABLE_GTK_DOC
TESTS_ENVIRONMENT = \
  DOC_MODULE=$(DOC_MODULE) DOC_MAIN_SGML_FILE=$(DOC_MAIN_SGML_FILE) \
  SRCDIR=$(abs_srcdir) BUILDDIR=$(abs_builddir)
TESTS = $(GTKDOC_CHECK)
endif

GTK-Doc 1.20

Version 1.18 brought some initial Markdown support. Using Markdown in doc comments is less intrusive than writing DocBook XML. This version improves a lot on this and add a lot more styles. The section that explains the comment syntax has all the details.

GTK-Doc 1.25

The makefiles shipped with this version generate an entity file at xml/gtkdocentities.ent, containing entities for e.g. package_name and package_version. You can use this e.g. in the main XML file to avoid hardcoding the version number. Below is an example that shows how the entity file is included in the master template and how the entities are used. The entities can also be used in all generated files, GTK-Doc will use the same XML header in generated XML files.

<?xml version="1.0"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
               "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
[
  <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
  <!ENTITY % gtkdocentities SYSTEM "xml/gtkdocentities.ent">
  %gtkdocentities;
]>
<book id="index" xmlns:xi="http://www.w3.org/2003/XInclude">
  <bookinfo>
    <title>&package_name; Reference Manual</title>
    <releaseinfo>
      for &package_string;.
      The latest version of this documentation can be found on-line at
      <ulink role="online-location" url="http://[SERVER]/&package_name;/index.html">http://[SERVER]/&package_name;/</ulink>.
    </releaseinfo>
  </bookinfo>

Documenting other interfaces

So far we have been using GTK-Doc to document the API of code. The next sections contain suggestions how the tools can be used to document other interfaces too.

Command line options and man pages

As one can generate man pages for a DocBook refentry as well, it sounds like a good idea to use it for that purpose. This way the interface is part of the reference and one gets the man-page for free.

Document the tool

Create one refentry file per tool. Following our example we would call it meep/docs/reference/meeper/meep.xml. For the XML tags that should be used and can look at generated file in the xml subdirectory as well as examples e.g. in GLib.

Adding the extra configure check

AC_ARG_ENABLE(man,
              [AC_HELP_STRING([--enable-man],
                              [regenerate man pages from Docbook [default=no]])],enable_man=yes,
              enable_man=no)

AC_PATH_PROG([XSLTPROC], [xsltproc])
AM_CONDITIONAL(ENABLE_MAN, test x$enable_man != xno)

Adding the extra makefile rules

man_MANS = \
       meeper.1

if ENABLE_GTK_DOC
if ENABLE_MAN

%.1 : %.xml
        @XSLTPROC@ -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<

endif
endif

BUILT_EXTRA_DIST = $(man_MANS)
EXTRA_DIST += meep.xml

DBus interfaces

(FIXME: http://hal.freedesktop.org/docs/DeviceKit/DeviceKit.html, http://cgit.freedesktop.org/DeviceKit/DeviceKit/tree/doc/dbus)

Frequently Asked Questions

Q: No class hierarchy.

A: The objects xxx_get_type() function has not been entered into the <package>.types file.

Q: Still no class hierarchy.

A: Missing or wrong naming in <package>-sections.txt file (see explanation).

Q: Damn, I have still no class hierarchy.

A: Is the object name (name of the instance struct, e.g. GtkWidget) part of the normal section (don’t put this into Standard or Private subsections).

Q: No symbol index.

A: Does the <package>-docs.xml contain a index that xi:includes the generated index?

Q: Symbols are not linked to their doc-section.

A: Is the doc-comment using the correct markup (added #,% or ())? Check if the gtkdoc-fixxref warns about unresolvable xrefs.

Q: A new class does not appear in the docs.

A: Is the new page xi:included from <package>-docs.xml.

Q: A new symbol does not appear in the docs.

A: Is the doc-comment properly formatted. Check for spelling mistakes in the begin of the comment. Check if the gtkdoc-fixxref warns about unresolvable xrefs. Check if the symbol is correctly listed in the <package>-sections.txt in a public subsection.

Q: A type is missing from the class hierarchy.

A: If the type is listed in <package>.hierarchy but not in xml/tree_index.sgml then double check that the type is correctly placed in the <package>-sections.txt. If the type instance (e.g. GtkWidget) is not listed or incidentally marked private it will not be shown.

Q: I get foldoc links for all GObject annotations.

A: Check that xml/annotation-glossary.xml is xi:included from <package>-docs.xml.

Q: Parameter described in source code comment block but does not exist

A: Check if the prototype in the header has different parameter names as in the source.

Q: multiple “IDs” for constraint linkend: XYZ

A: Symbol XYZ appears twice in <package>-sections.txt file.

Q: Element typename in namespace ‘’ encountered in para, but no template matches.

GNU Free Documentation License

0. PREAMBLE

The purpose of this License is to make a manual, textbook, or other written document “free” in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others.

This License is a kind of “copyleft”, which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software.

We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference.

1. APPLICABILITY AND DEFINITIONS

This License applies to any manual or other work that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. The “Document”, below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as “you”.

A “Modified Version” of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language.

A “Secondary Section” is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document’s overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (For example, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them.

The “Invariant Sections” are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License.

The “Cover Texts” are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License.

A “Transparent” copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, whose contents can be viewed and edited directly and straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup has been designed to thwart or discourage subsequent modification by readers is not Transparent. A copy that is not “Transparent” is called “Opaque”.

Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML designed for human modification. Opaque formats include PostScript, PDF, proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML produced by some word processors for output purposes only.

The “Title Page” means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, “Title Page” means the text near the most prominent appearance of the work’s title, preceding the beginning of the body of the text.

2. VERBATIM COPYING

You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3.

You may also lend copies, under the same conditions stated above, and you may publicly display copies.

3. COPYING IN QUANTITY

If you publish printed copies of the Document numbering more than 100, and the Document’s license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects.

If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages.

If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a publicly-accessible computer-network location containing a complete Transparent copy of the Document, free of added material, which the general network-using public has access to download anonymously at no charge using public-standard network protocols. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public.

It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document.

4. MODIFICATIONS

You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version:

  • A

    Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission.

  • B

    List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has less than five).

  • C

    State on the Title Page the name of the publisher of the Modified Version, as the publisher.

  • D

    Preserve all the copyright notices of the Document.

  • E

    Add an appropriate copyright notice for your modifications adjacent to the other copyright notices.

  • F

    Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below.

  • G

    Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document’s license notice.

  • H

    Include an unaltered copy of this License.

  • I

    Preserve the section entitled “History”, and its title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section entitled “History” in the Document, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence.

  • J

    Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the “History” section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission.

  • K

    In any section entitled “Acknowledgements” or “Dedications”, preserve the section’s title, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein.

  • L

    Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles.

  • M

    Delete any section entitled “Endorsements”. Such a section may not be included in the Modified Version.

  • N

    Do not retitle any existing section as “Endorsements” or to conflict in title with any Invariant Section.

If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version’s license notice. These titles must be distinct from any other section titles.

You may add a section entitled “Endorsements”, provided it contains nothing but endorsements of your Modified Version by various parties–for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard.

You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one.

The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version.

5. COMBINING DOCUMENTS

You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice.

The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work.

In the combination, you must combine any sections entitled “History” in the various original documents, forming one section entitled “History”; likewise combine any sections entitled “Acknowledgements”, and any sections entitled “Dedications”. You must delete all sections entitled “Endorsements.”

6. COLLECTIONS OF DOCUMENTS

You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects.

You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document.

7. AGGREGATION WITH INDEPENDENT WORKS

A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, does not as a whole count as a Modified Version of the Document, provided no compilation copyright is claimed for the compilation. Such a compilation is called an “aggregate”, and this License does not apply to the other self-contained works thus compiled with the Document , on account of their being thus compiled, if they are not themselves derivative works of the Document. If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one quarter of the entire aggregate, the Document’s Cover Texts may be placed on covers that surround only the Document within the aggregate. Otherwise they must appear on covers around the whole aggregate.

8. TRANSLATION

Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License provided that you also include the original English version of this License. In case of a disagreement between the translation and the original English version of this License, the original English version will prevail.

9. TERMINATION

You may not copy, modify, sublicense, or distribute the Document except as expressly provided for under this License. Any other attempt to copy, modify, sublicense or distribute the Document is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.

10. FUTURE REVISIONS OF THIS LICENSE

The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/.

Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License “or any later version” applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation.

Addendum

To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page:

Copyright YEAR YOUR NAME.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the Invariant Sections being LIST THEIR TITLES, with the Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. A copy of the license is included in the section entitled “GNU Free Documentation License”.

If you have no Invariant Sections, write “with no Invariant Sections” instead of saying which ones are invariant. If you have no Front-Cover Texts, write “no Front-Cover Texts” instead of “Front-Cover Texts being LIST”; likewise for Back-Cover Texts.

If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software.