Sphinx
Sphinx is widely used to generate python document. Here is a brief tutorial to generate your own doc
Quick Start
1.
sphinx-quickstart, inside "S4" folder,
sphinx-quickstart doc, if on Linux system
- Root paht for the documentation [.]: doc
- Separate source and build directories (y/n) [n], press "Enter"
- Name prefix for templates and static dir [_], press "Enter"
- Project name: yourProjectName
- Author Name: yourName
- Project version []: yourProjectVersion
- Project release [0.1], press "Enter"
- Project language [en], press "Enter"
- Source file suffix [.rst], press "Enter"
- Name of your master document (without suffix) [index], press "Enter"
- Do you want to use the epub builder (y/n) [n], press "Enter"
- autodoc: automatically insert docstrings from modules (y/n) [n]: y
- doctest: automatically test code snippets in doctest blocks (y/n) [n]: y
- intersphinx: link between Sphinx documentation of different projects (y/n) [n], press "Enter"
- todo: write "todo" entries that can be shown or hidden on build (y/n) [n], press "Enter"
- coverage: checks for documentation coverage (y/n) [n], press "Enter"
- imgmath: include math, rendered as PNG or SVG images (y/n) [n], press "Enter"
- mathjax: include math, rendered in the browser by MathJax (y/n) [n]: y
- ifconfig: conditional inclusion of content based on config values (y/n) [n], press "Enter"
- viewcode: include links to the source code of documented Python objects (y/n) [n]: y
- githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n], press "Enter"
- Create Makefile? (y/n) [y], press "Enter"
- Create Windows command file? (y/n) [y], press "Enter"
Generate _build (to save html files), _static (to save the css files), _templates (to save the layout template), conf.py, index.rst
2.
sphinx-apidoc -o doc . inside "S4" folder, generate a rst file for each py file or each package under "S4" folder, and save them to "doc" folder
3. edit conf.py in "doc" folder, define where to search the source code
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
4. edit index.rst in "doc" folder, add rst files for the modules and packages that will be shown in index.html, use reStructuredText to edit the file, rst files are initial documentation files
.. toctree::
:maxdepth: 2
:caption: Contents:
:glob:
---Blank Line---
convert.rst
format.rst
modules.rst
5. make html in "doc" folder, save the generated html doc to _build
Change theme
1. edit conf.py in "doc" folder
html_theme = 'classic'
2.
make html, in "doc" folder
Add logo
1. edit conf.py in "doc" folder
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
html_logo = '../img/logo.jpg'
2.
make html, in "doc" folder
Generate pdf doc
Mac OS
- Install Manport
- sudo port install texlive texlive-latex-extra, install latex
- make latexpdf, create latex files and a pdf file in _build/latex
Ubuntu
- sudo apt-get install texlive-base texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended texlive-fonts-extra texlive-latex-base texlive-font-utils
- sudo apt-get install latexmk
- make latexpdf, create latex files and a pdf file in _build/latex
Reference