The Sage Manuals

This chapter describes how to modify the Sage manuals. Sage’s manuals are written in ReST, otherwise known as reStructuredText. To edit them, you just need to edit the appropriate file. The documentation builder is called Sphinx.

Here is a list of the Sage manuals and the corresponding files to edit:

  • The Sage tutorial: SAGE_ROOT/src/doc/en/tutorial
  • The Sage developer’s guide: SAGE_ROOT/src/doc/en/developer
  • Constructions in Sage: SAGE_ROOT/src/doc/en/constructions
  • The Sage installation guide: SAGE_ROOT/src/doc/en/installation
  • The Sage reference manual: some of this is contained in the file SAGE_ROOT/src/doc/en/reference, but most of it is automatically generated from the Sage source code.
  • Additional, more specialized manuals can be found under SAGE_ROOT/src/doc/en as well.


You can edit manuals that have been translated into another language by replacing the en/ above with the appropriate two letter language code. For example, the French tutorial is located in SAGE_ROOT/src/doc/fr/tutorial

Editing the Manuals

If, for example, you want to change the Sage tutorial, then you should start by modifying the files in SAGE_ROOT/src/doc/en/tutorial/. Then to build a PDF file with your changes, type:

sage --docbuild tutorial pdf

You will get a file tutorial.pdf in SAGE_ROOT/src/doc/output/pdf/en/tutorial which you should inspect. You can build the HTML version of the tutorial by typing:

sage --docbuild tutorial html

Once you have done this, you can access the new HTML version from the notebook interface to Sage by clicking the Help link, or you can open the file SAGE_ROOT/src/doc/output/html/en/tutorial/index.html in your web browser. For more detailed information about building the documentation, see Building the Manuals.

You should also run:

sage -tp SAGE_ROOT/src/doc/en/tutorial/

to test all of the examples in the tutorial, see Running Automated Tests for more details.

As noted above, the reference manual is mostly autogenerated from Sage source code. To build it, type:

sage -b <repo-name>
sage --docbuild reference <format>

where <repo-name> is the name of the repository you are using, and <format> is html, pdf, or any other supported format (as listed when you run sage --docbuild --formats).

Adding a New File

If you write a new file, say, sage/combinat/, and you want your documentation to be added to the standard documentation, you have to add your file to the relevant index.rst file usually located in the tree:


For this example, you would need to add to the file:


the following line:


 .. toctree::
    :maxdepth: 2

+   ../sage/combinat/family

Building the Manuals

All of the Sage manuals are built using the sage --docbuild script. The content of the sage --docbuild script is defined in SAGE_ROOT/src/doc/common/ It is a thin wrapper around the sphinx-build script which does all of the real work. It is designed to be a replacement for the default Makefiles generated by the sphinx-quickstart script. The general form of the command is:

sage --docbuild <document-name> <format>

as explained below. For more information, there are two help commands which give plenty of documentation for the sage --docbuild script:

sage --docbuild --help

(or -h) gives a basic listing of options and further help commands, while:

sage --docbuild --help-all

(or -H) shows a somewhat more comprehensive help message.

Document Names

The <document-name> has the form:


where lang is a two-letter language code, and name is the descriptive name of the document. If the language is not specified, then it defaults to English (en). The following two commands do the exact same thing:

sage --docbuild tutorial html
sage --docbuild en/tutorial html

To specify the French version of the tutorial, you would simply run:

sage --docbuild fr/tutorial html

Output Formats

The Sage documentation build system currently supports all of the output formats that Sphinx does. For more detailed information, see the documentation on builders at

Syntax Highlighting Cython Code

If you need to put Cython code in a ReST file, you can either precede the code block by .. code-block:: cython instead of the usual :: if you want to highlight one block of code in Cython, or you can use .. highlight:: cython for a whole file.

The following example was generated by .. code-block:: cython:

cdef extern from "descrobject.h":
    ctypedef struct PyMethodDef:
        void *ml_meth
    ctypedef struct PyMethodDescrObject:
        PyMethodDef *d_method
    void* PyCFunction_GET_FUNCTION(object)
    bint PyCFunction_Check(object)