2009-02-12 05:50:42 -06:00
|
|
|
|
.. _faq:
|
|
|
|
|
|
|
|
|
|
Sphinx FAQ
|
|
|
|
|
==========
|
|
|
|
|
|
|
|
|
|
This is a list of Frequently Asked Questions about Sphinx. Feel free to
|
|
|
|
|
suggest new entries!
|
|
|
|
|
|
|
|
|
|
How do I...
|
|
|
|
|
-----------
|
|
|
|
|
|
2009-11-08 11:20:53 -06:00
|
|
|
|
... create PDF files without LaTeX?
|
2009-11-08 09:54:06 -06:00
|
|
|
|
You can use `rst2pdf <http://rst2pdf.googlecode.com>`_ version 0.12 or greater
|
|
|
|
|
which comes with built-in Sphinx integration. See the :ref:`builders`
|
|
|
|
|
section for details.
|
|
|
|
|
|
2009-02-22 08:22:23 -06:00
|
|
|
|
... get section numbers?
|
|
|
|
|
They are automatic in LaTeX output; for HTML, give a ``:numbered:`` option to
|
2010-04-17 03:39:51 -05:00
|
|
|
|
the :rst:dir:`toctree` directive where you want to start numbering.
|
2009-02-22 08:22:23 -06:00
|
|
|
|
|
2009-02-17 17:10:32 -06:00
|
|
|
|
... customize the look of the built HTML files?
|
|
|
|
|
Use themes, see :doc:`theming`.
|
|
|
|
|
|
2009-02-22 08:22:23 -06:00
|
|
|
|
... add global substitutions or includes?
|
2009-02-12 05:50:42 -06:00
|
|
|
|
Add them in the :confval:`rst_epilog` config value.
|
|
|
|
|
|
2009-09-09 08:43:58 -05:00
|
|
|
|
... display the whole TOC tree in the sidebar?
|
|
|
|
|
Use the :data:`toctree` callable in a custom layout template, probably in the
|
|
|
|
|
``sidebartoc`` block.
|
|
|
|
|
|
2009-02-17 17:10:32 -06:00
|
|
|
|
... write my own extension?
|
|
|
|
|
See the :ref:`extension tutorial <exttut>`.
|
2009-02-19 16:31:34 -06:00
|
|
|
|
|
2009-05-13 02:15:29 -05:00
|
|
|
|
... convert from my existing docs using MoinMoin markup?
|
|
|
|
|
The easiest way is to convert to xhtml, then convert `xhtml to reST`_. You'll
|
|
|
|
|
still need to mark up classes and such, but the headings and code examples
|
|
|
|
|
come through cleanly.
|
|
|
|
|
|
|
|
|
|
|
2010-02-28 15:00:22 -06:00
|
|
|
|
.. _usingwith:
|
|
|
|
|
|
2009-05-13 02:15:29 -05:00
|
|
|
|
Using Sphinx with...
|
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
|
|
Epydoc
|
2009-02-12 05:50:42 -06:00
|
|
|
|
There's a third-party extension providing an `api role`_ which refers to
|
|
|
|
|
Epydoc's API docs for a given identifier.
|
|
|
|
|
|
2009-05-13 02:15:29 -05:00
|
|
|
|
Doxygen
|
|
|
|
|
Michael Jones is developing a reST/Sphinx bridge to doxygen called `breathe
|
|
|
|
|
<http://github.com/michaeljones/breathe/tree/master>`_.
|
|
|
|
|
|
|
|
|
|
SCons
|
2009-03-15 17:43:09 -05:00
|
|
|
|
Glenn Hutchings has written a SCons build script to build Sphinx
|
|
|
|
|
documentation; it is hosted here: http://bitbucket.org/zondo/sphinx-scons
|
2009-03-31 16:50:09 -05:00
|
|
|
|
|
2009-09-09 04:00:54 -05:00
|
|
|
|
PyPI
|
|
|
|
|
Jannis Leidel wrote a `setuptools command
|
|
|
|
|
<http://pypi.python.org/pypi/Sphinx-PyPI-upload>`_ that automatically uploads
|
|
|
|
|
Sphinx documentation to the PyPI package documentation area at
|
|
|
|
|
http://packages.python.org/.
|
|
|
|
|
|
2009-05-13 02:15:29 -05:00
|
|
|
|
github pages
|
|
|
|
|
You can use `Michael Jones' sphinx-to-github tool
|
|
|
|
|
<http://github.com/michaeljones/sphinx-to-github/tree/master>`_ to prepare
|
|
|
|
|
Sphinx HTML output.
|
2009-03-31 16:50:09 -05:00
|
|
|
|
|
2010-01-07 08:33:47 -06:00
|
|
|
|
Google Analytics
|
|
|
|
|
You can use a custom ``layout.html`` template, like this:
|
|
|
|
|
|
|
|
|
|
.. code-block:: html+django
|
|
|
|
|
|
|
|
|
|
{% extends "!layout.html" %}
|
|
|
|
|
|
|
|
|
|
{%- block extrahead %}
|
|
|
|
|
{{ super() }}
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
var _gaq = _gaq || [];
|
|
|
|
|
_gaq.push(['_setAccount', 'XXX account number XXX']);
|
|
|
|
|
_gaq.push(['_trackPageview']);
|
|
|
|
|
</script>
|
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
|
|
{% block footer %}
|
|
|
|
|
{{ super() }}
|
|
|
|
|
<div class="footer">This page uses <a href="http://analytics.google.com/">
|
|
|
|
|
Google Analytics</a> to collect statistics. You can disable it by blocking
|
|
|
|
|
the JavaScript coming from www.google-analytics.com.
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
(function() {
|
|
|
|
|
var ga = document.createElement('script');
|
|
|
|
|
ga.src = ('https:' == document.location.protocol ?
|
|
|
|
|
'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
|
|
|
|
ga.setAttribute('async', 'true');
|
|
|
|
|
document.documentElement.firstChild.appendChild(ga);
|
|
|
|
|
})();
|
|
|
|
|
</script>
|
|
|
|
|
</div>
|
|
|
|
|
{% endblock %}
|
|
|
|
|
|
2009-02-12 05:50:42 -06:00
|
|
|
|
|
|
|
|
|
.. _api role: http://git.savannah.gnu.org/cgit/kenozooid.git/tree/doc/extapi.py
|
2009-03-31 16:50:09 -05:00
|
|
|
|
.. _xhtml to reST: http://docutils.sourceforge.net/sandbox/xhtml2rest/xhtml2rest.py
|
2009-12-29 05:32:42 -06:00
|
|
|
|
|
|
|
|
|
|
2009-12-29 05:41:35 -06:00
|
|
|
|
.. _epub-faq:
|
|
|
|
|
|
|
|
|
|
Epub info
|
|
|
|
|
---------
|
2009-12-28 10:09:09 -06:00
|
|
|
|
|
2009-12-29 05:32:42 -06:00
|
|
|
|
The epub builder is currently in an experimental stage. It has only been tested
|
|
|
|
|
with the Sphinx documentation itself. If you want to create epubs, here are
|
|
|
|
|
some notes:
|
2009-12-28 10:09:09 -06:00
|
|
|
|
|
2009-12-29 05:32:42 -06:00
|
|
|
|
* Split the text into several files. The longer the individual HTML files are,
|
|
|
|
|
the longer it takes the ebook reader to render them. In extreme cases, the
|
|
|
|
|
rendering can take up to one minute.
|
2009-12-28 10:09:09 -06:00
|
|
|
|
|
2009-12-29 05:32:42 -06:00
|
|
|
|
* Try to minimize the markup. This also pays in rendering time.
|
2009-12-28 10:09:09 -06:00
|
|
|
|
|
2009-12-29 05:32:42 -06:00
|
|
|
|
* For some readers you can use embedded or external fonts using the CSS
|
|
|
|
|
``@font-face`` directive. This is *extremely* useful for code listings which
|
|
|
|
|
are often cut at the right margin. The default Courier font (or variant) is
|
|
|
|
|
quite wide and you can only display up to 60 characters on a line. If you
|
|
|
|
|
replace it with a narrower font, you can get more characters on a line. You
|
|
|
|
|
may even use `FontForge <http://fontforge.sourceforge.net/>`_ and create
|
|
|
|
|
narrow variants of some free font. In my case I get up to 70 characters on a
|
|
|
|
|
line.
|
2009-12-28 10:09:09 -06:00
|
|
|
|
|
|
|
|
|
You may have to experiment a little until you get reasonable results.
|
|
|
|
|
|
2009-12-29 05:32:42 -06:00
|
|
|
|
* Test the created epubs. You can use several alternatives. The ones I am aware
|
|
|
|
|
of are Epubcheck_, Calibre_, FBreader_ (although it does not render the CSS),
|
|
|
|
|
and Bookworm_. For bookworm you can download the source from
|
|
|
|
|
http://code.google.com/p/threepress/ and run your own local server.
|
2009-12-28 10:09:09 -06:00
|
|
|
|
|
2010-06-03 08:57:38 -05:00
|
|
|
|
* Large floating divs are not displayed properly.
|
|
|
|
|
If they cover more than one page, the div is only shown on the first page.
|
|
|
|
|
In that case you can copy the :file:`epub.css` from the
|
|
|
|
|
``sphinx/themes/epub/static/`` directory to your local ``_static/``
|
|
|
|
|
directory and remove the float settings.
|
|
|
|
|
|
2010-06-07 15:27:13 -05:00
|
|
|
|
* Files that are inserted outside of the ``toctree`` directive must be manually
|
|
|
|
|
included. This sometimes applies to appendixes, e.g. the glossary or
|
|
|
|
|
the indices. You can add them with the :confval:`epub_post_files` option.
|
|
|
|
|
|
2009-12-29 05:32:42 -06:00
|
|
|
|
.. _Epubcheck: http://code.google.com/p/epubcheck/
|
|
|
|
|
.. _Calibre: http://calibre-ebook.com/
|
|
|
|
|
.. _FBreader: http://www.fbreader.org/
|
|
|
|
|
.. _Bookworm: http://bookworm.oreilly.com/
|
2010-09-16 02:16:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _texinfo-faq:
|
|
|
|
|
|
|
|
|
|
Texinfo info
|
|
|
|
|
------------
|
|
|
|
|
|
2010-10-22 03:17:35 -05:00
|
|
|
|
The Texinfo builder is currently in an experimental stage but has successfully
|
|
|
|
|
been used to build the documentation for both Sphinx and Python. The intended
|
|
|
|
|
use of this builder is to generate Texinfo that is then processed into Info
|
|
|
|
|
files.
|
|
|
|
|
|
|
|
|
|
There are two main programs for reading Info files, ``info`` and GNU Emacs. The
|
|
|
|
|
``info`` program has less features but is available in most Unix environments
|
|
|
|
|
and can be quickly accessed from the terminal. Emacs provides better font and
|
|
|
|
|
color display and supports extensive customization (of course).
|
2010-09-16 02:16:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _texinfo-links:
|
|
|
|
|
|
|
|
|
|
Displaying Links
|
|
|
|
|
~~~~~~~~~~~~~~~~
|
|
|
|
|
|
2010-10-22 03:17:35 -05:00
|
|
|
|
One noticeable problem you may encounter with the generated Info files is how
|
|
|
|
|
references are displayed. If you read the source of an Info file, a reference
|
|
|
|
|
to this section would look like::
|
2010-09-16 02:16:27 -05:00
|
|
|
|
|
|
|
|
|
* note Displaying Links: target-id
|
|
|
|
|
|
2010-10-22 03:17:35 -05:00
|
|
|
|
In the stand-alone reader, ``info``, references are displayed just as they
|
|
|
|
|
appear in the source. Emacs, on the other-hand, will by default replace
|
|
|
|
|
``\*note:`` with ``see`` and hide the ``target-id``. For example:
|
2010-09-16 02:16:27 -05:00
|
|
|
|
|
|
|
|
|
:ref:`texinfo-links`
|
|
|
|
|
|
2010-10-22 03:17:35 -05:00
|
|
|
|
The exact behavior of how Emacs displays references is dependent on the variable
|
|
|
|
|
``Info-hide-note-references``. If set to the value of ``hide``, Emacs will hide
|
|
|
|
|
both the ``\*note:`` part and the ``target-id``. This is generally the best way
|
|
|
|
|
to view Sphinx-based documents since they often make frequent use of links and
|
|
|
|
|
do not take this limitation into account. However, changing this variable
|
|
|
|
|
affects how all Info documents are displayed and most due take this behavior
|
2010-09-16 02:16:27 -05:00
|
|
|
|
into account.
|
|
|
|
|
|
2010-10-22 03:17:35 -05:00
|
|
|
|
If you want Emacs to display Info files produced by Sphinx using the value
|
|
|
|
|
``hide`` for ``Info-hide-note-references`` and the default value for all other
|
|
|
|
|
Info files, try adding the following Emacs Lisp code to your start-up file,
|
|
|
|
|
``~/.emacs.d/init.el``.
|
2010-09-16 02:16:27 -05:00
|
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
2010-10-22 03:17:35 -05:00
|
|
|
|
(defadvice info-insert-file-contents (after
|
|
|
|
|
sphinx-info-insert-file-contents
|
|
|
|
|
activate)
|
|
|
|
|
"Hack to make `Info-hide-note-references' buffer-local and
|
|
|
|
|
automatically set to `hide' iff it can be determined that this file
|
|
|
|
|
was created from a Texinfo file generated by Docutils or Sphinx."
|
|
|
|
|
(set (make-local-variable 'Info-hide-note-references)
|
|
|
|
|
(default-value 'Info-hide-note-references))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(save-restriction
|
|
|
|
|
(widen) (goto-char (point-min))
|
|
|
|
|
(when (re-search-forward
|
|
|
|
|
"^Generated by \\(Sphinx\\|Docutils\\)"
|
|
|
|
|
(save-excursion (search-forward "" nil t)) t)
|
|
|
|
|
(set (make-local-variable 'Info-hide-note-references)
|
|
|
|
|
'hide)))))
|
2010-09-16 02:16:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Notes
|
|
|
|
|
~~~~~
|
|
|
|
|
|
2010-10-22 03:17:35 -05:00
|
|
|
|
The following notes may be helpful if you want to create Texinfo files:
|
2010-09-16 02:16:27 -05:00
|
|
|
|
|
|
|
|
|
- Each section corresponds to a different ``node`` in the Info file.
|
|
|
|
|
|
2010-10-22 03:17:35 -05:00
|
|
|
|
- Some characters cannot be properly escaped in menu entries and xrefs. The
|
|
|
|
|
following characters are replaced by spaces in these contexts: ``@``, ``{``,
|
|
|
|
|
``}``, ``.``, ``,``, and ``:``.
|
2010-09-16 02:16:27 -05:00
|
|
|
|
|
2010-10-22 03:17:35 -05:00
|
|
|
|
- In the HTML and Tex output, the word ``see`` is automatically inserted before
|
|
|
|
|
all xrefs.
|
2010-09-16 02:16:27 -05:00
|
|
|
|
|
2010-10-22 03:17:35 -05:00
|
|
|
|
- Links to external Info files can be created using the somewhat official URI
|
|
|
|
|
scheme ``info``. For example::
|
2010-09-16 02:16:27 -05:00
|
|
|
|
|
2010-10-22 03:17:35 -05:00
|
|
|
|
info:Texinfo#makeinfo_options
|
2010-09-16 02:16:27 -05:00
|
|
|
|
|
|
|
|
|
which produces:
|
|
|
|
|
|
2010-10-22 03:17:35 -05:00
|
|
|
|
info:Texinfo#makeinfo_options
|
2010-09-16 02:16:27 -05:00
|
|
|
|
|
|
|
|
|
- Inline markup appears as follows in Info:
|
|
|
|
|
|
|
|
|
|
* strong -- \*strong\*
|
|
|
|
|
* emphasis -- _emphasis_
|
|
|
|
|
* literal -- \`literal'
|
|
|
|
|
|
|
|
|
|
It is possible to change this behavior using the Texinfo command
|
2010-10-22 03:17:35 -05:00
|
|
|
|
``@definfoenclose``. For example, to make inline markup more closely resemble
|
|
|
|
|
reST, add the following to your :file:`conf.py`::
|
|
|
|
|
|
|
|
|
|
texinfo_elements = {'preamble': """\
|
|
|
|
|
@definfoenclose strong,**,**
|
|
|
|
|
@definfoenclose emph,*,*
|
|
|
|
|
@definfoenclose code,`@w{}`,`@w{}`
|
|
|
|
|
"""}
|