Documentation is written in reStructuredText format.
The Agda documentation is shipped together with the main Agda
repository in the
doc/user-manual subdirectory. The content of
this directory is automatically published to https://agda.readthedocs.io.
Rendering documentation locally¶
To build the user manual locally, you need to install the following dependencies:
pip install --user -r doc/user-manual/requirements.txt
Note that the
--useroption puts the Sphinx binaries in
ImageMagick with SVG and PNG support; check output of
convert -list format
To see the list of available targets, execute
doc/user-manual. E.g., call
make htmlto build the documentation in html format.
Type-checking code examples¶
You can include code examples in your documentation.
If your give the documentation file the extension
.lagda.rst, Agda will
recognise it as an Agda file and type-check it.
If you edit
.lagda.rst documentation files in Emacs, you can use Agda’s interactive
mode to write your code examples. Run
M-x agda2-mode to switch to Agda
M-x rst-mode to switch back to rST mode.
You can check that all the examples in the manual are type-correct by
make user-manual-test from the root directory. This check
will be run as part of the continuous integration build.
Remember to run
fix-agda-whitespace to remove trailing whitespace
before submitting the documentation to the repository.
Syntax for code examples¶
The syntax for embedding code examples depends on:
Whether the code example should be visible to the reader of the documentation.
Whether the code example contains valid Agda code (which should be type-checked).
Visible, checked code examples¶
This is code that the user will see, and that will be also checked for correctness by Agda. Ideally, all code in the documentation should be of this form: both visible and valid.
It can appear stand-alone: :: data Bool : Set where true false : Bool Or at the end of a paragraph:: data Bool : Set where true false : Bool Here ends the code fragment.
It can appear stand-alone:data Bool : Set where true false : Bool
Or at the end of a paragraph:data Bool : Set where true false : Bool
Here ends the code fragment.
Remember to always leave a blank like after the
Otherwise, the code will be checked by Agda, but it will appear
as regular paragraph text in the documentation.
Visible, unchecked code examples¶
This is code that the reader will see, but will not be checked by Agda. It is useful for examples of incorrect code, program output, or code in languages different from Agda.
.. code-block:: agda -- This is not a valid definition ω : ∀ a → a ω x = x .. code-block:: haskell -- This is haskell code data Bool = True | False
-- This is not a valid definition ω : ∀ a → a ω x = x-- This is haskell code data Bool = True | False
Invisible, checked code examples¶
This is code that is not shown to the reader, but which is used to typecheck the code that is actually displayed.
This might be definitions that are well known enough that do not need to be shown again.
.. :: data Nat : Set where zero : Nat suc : Nat → Nat :: add : Nat → Nat → Nat add zero y = y add (suc x) y = suc (add x y)
add : Nat → Nat → Nat add zero y = y add (suc x) y = suc (add x y)
Documentation literate files (.lagda.*) are type-checked as whole Agda files, as if all literate text was replaced by whitespace. Thus, indentation is interpreted globally.
In the documentation, files are typechecked starting from the doc/user-manual/ root. For example, the file doc/user-manual/language/data-types.lagda.rst should start with a hidden code block declaring the name of the module as language.data-types:
.. :: module language.data-types where
Sometimes you will want to use the same name in different places in the same documentation file. You can do this by using hidden module declarations to isolate the definitions from the rest of the file.
.. :: module scoped-1 where :: foo : Nat foo = 42 .. :: module scoped-2 where :: foo : Nat foo = 66
foo : Nat foo = 42