6 The following examples illustrate use cases for "literate programming with
9 Generally, the literate source will not substitute a user guide, but can
10 serve as base documentation as well as reference.
12 The text parts can be used to structure the document, for additional
13 explanations, documentation of variants and discussion why a specific
29 Typically, most of a Python module's documentation is in docstrings.
30 Currently, docstrings are treated as code parts by PyLit.
32 However, literate comments can be used to add structure and documentation
33 that is not intended for the end user of a module but for people trying to
34 maintain or extend it (including the original author).
46 Python's `doctest`_ module runs tests on usage examples.
47 However, running ``doctest`` on the code source will only run doctests
48 within docstrings. In contrast, ``pylit --doctest`` will detect all
49 doctests, in docstrings as well as in text blocks.
51 This way, the docstrings can be kept concise while comprehensive tests can
52 be placed in the code file without taking up precious resources and loading
53 time (as they will be stripped from the byte-compiled module).
62 .. _doctest: http://docs.python.org/library/doctest.html
67 Test suites are a good example for the advantages of literate programming.
68 Documenting the rationale and design as well as test considerations can help
69 a lot when maintaining and extending the tests.
71 The following unit test modules are tested using the nose_ unit
72 test discovery & execution framework. (They should be compatible to
75 .. _nose: http://somethingaboutorange.com/mrl/projects/nose/
76 .. _py.test: http://codespeak.net/py/dist/doc/test.html
84 iterqueue_speed_test.py
87 Articles and Tutorials
88 ----------------------
90 This survey over the various options and attempts to extend an iterator with
91 methods for `peek`, `pushback` or `test of emptiness` is also a Python
92 module defining several examples of such rich iterators.
100 A tutorial is clearly more of a text document than a program. But usually, a
101 lot of example code gets included. Converting the text source to commented
102 code, it is easier to copy or paste code examples to and from scripts or an
103 interactive program session. Re-converting indents the code snippets
104 correctly so they will be literal blocks in the pretty print.
106 In Python, code examples can be given as both, code blocks and doctest_
107 blocks. With a 'usage' example that imports the code source as module,
108 doctest blocks can also test examples from literal code blocks.
110 * `swiginac_tutorial`_
112 + An adaption of the `GiNaC tutorial`_ for doing Computer algebra with
113 GiNaC_ and the Python programming language using the swiginac_ wrapper
114 package. (incomplete.)
116 + The most current version and sources are in the `documentation folder`_
117 of the swiginac SVN repository.
119 .. _swiginac_tutorial:
120 http://swiginac.berlios.de/ginac-tutorial.py.html
121 .. _documentation folder:
122 http://svn.berlios.de/svnroot/repos/swiginac/trunk/doc/
123 .. _GiNaC tutorial: http://www.ginac.de/tutorial/
124 .. _GiNaC: http://www.ginac.de
125 .. _swiginac: http://swiginac.berlios.de
131 The "orthogonal" syntax of reStructuredText and LaTeX makes the documentation
132 of a LaTeX package in the source document far more readable than using LaTeX
138 listings-python-options.sty
139 listings-tex-options.sty
140 palatino-helvetica-courier.sty
142 * isomath_ (PDF__): Math for scientists
144 + LaTeX package for typesetting math according to International
145 Standard ISO 31 `Quantities and units`.
147 __ ftp://dante.ctan.org/tex-archive/macros/latex/contrib/isomath/isomath.sty.pdf
151 * listings-python-options.sty_, listings-tex-options.sty_,
152 palatino-helvetica-courier.sty_
153 * isomath.sty_, isomath.sty.txt_.
155 .. _listings-python-options.sty:
156 http://docutils.sf.net/sandbox/stylesheets/listings-python-options.sty
157 .. _listings-tex-options.sty:
158 http://docutils.sf.net/sandbox/stylesheets/listings-tex-options.sty
159 .. _palatino-helvetica-courier.sty:
160 http://docutils.sf.net/sandbox/stylesheets/palatino-helvetica-courier.sty
162 http://dante.ctan.org/CTAN/macros/latex/contrib/isomath/isomath.sty.html
164 ftp://dante.ctan.org/tex-archive/macros/latex/contrib/isomath/isomath.sty
166 ftp://dante.ctan.org/tex-archive/macros/latex/contrib/isomath/isomath.sty.txt
171 Also cascading style sheets can gain from being made literate documents.
182 Generating a template as well as user documentation from the same
183 source helps to keep them synchronised: