Python 2.5 compatibility: dynamic exception matching
[docutils.git] / FAQ.txt
blob2ffc06fda9202c62d1f1a540c0d433ca941ee09b
1 .. -*- coding: utf-8 -*-
4 .. NOTE TO MAINTAINERS: Please add new questions to the end of their
5    sections, so section/question numbers remain stable.
8 ===========================================
9  Docutils FAQ (Frequently Asked Questions)
10 ===========================================
12 :Date: $Date$
13 :Revision: $Revision$
14 :Web site: http://docutils.sourceforge.net/
15 :Copyright: This document has been placed in the public domain.
17 .. contents::
18 .. sectnum::
21 This is a work in progress.  If you are reading a local copy, the
22 `master copy`_ might be newer.  This document uses are relative links;
23 if they don't work, please use the `master copy`_.
25 Please feel free to ask questions and/or provide answers; send email
26 to the `Docutils-users`_ mailing list.  Project members should feel
27 free to edit the source text file directly.
29 .. _master copy: http://docutils.sourceforge.net/FAQ.html
30 .. _let us know:
31 .. _Docutils-users: docs/user/mailing-lists.html#docutils-users
35 Docutils
36 ========
38 What is Docutils?
39 -----------------
41 Docutils_ is a system for processing plaintext documentation into
42 useful formats, such as HTML, XML, and LaTeX.  It supports multiple
43 types of input, such as standalone files (implemented), inline
44 documentation from Python modules and packages (under development),
45 `PEPs (Python Enhancement Proposals)`_ (implemented), and others as
46 discovered.
48 The Docutils distribution consists of:
50 * a library (the "docutils" package), which `can be used by client
51   code`_;
52 * several `front-end tools`_ (such as ``rst2html.py``, which converts
53   reStructuredText input into HTML output);
54 * a `test suite`_; and
55 * extensive documentation_.
57 For an overview of the Docutils project implementation, see `PEP
58 258`_, "Docutils Design Specification".
60 Docutils is implemented in Python_.
62 .. _Docutils: http://docutils.sourceforge.net/
63 .. _PEPs (Python Enhancement Proposals):
64    http://www.python.org/peps/pep-0012.html
65 .. _can be used by client code: docs/api/publisher.html
66 .. _front-end tools: docs/user/tools.html
67 .. _test suite: docs/dev/testing.html
68 .. _documentation: docs/index.html
69 .. _PEP 258: http://www.python.org/peps/pep-0258.html
70 .. _Python: http://www.python.org/
73 Why is it called "Docutils"?
74 ----------------------------
76 Docutils is short for "Python Documentation Utilities".  The name
77 "Docutils" was inspired by "Distutils", the Python Distribution
78 Utilities architected by Greg Ward, a component of Python's standard
79 library.
81 The earliest known use of the term "docutils" in a Python context was
82 a `fleeting reference`__ in a message by Fred Drake on 1999-12-02 in
83 the Python Doc-SIG mailing list.  It was suggested `as a project
84 name`__ on 2000-11-27 on Doc-SIG, again by Fred Drake, in response to
85 a question from Tony "Tibs" Ibbs: "What do we want to *call* this
86 thing?".  This was shortly after David Goodger first `announced
87 reStructuredText`__ on Doc-SIG.
89 Tibs used the name "Docutils" for `his effort`__ "to document what the
90 Python docutils package should support, with a particular emphasis on
91 documentation strings".  Tibs joined the current project (and its
92 predecessors) and graciously donated the name.
94 For more history of reStructuredText and the Docutils project, see `An
95 Introduction to reStructuredText`_.
97 Please note that the name is "Docutils", not "DocUtils" or "Doc-Utils"
98 or any other variation.  It is pronounced as in "DOCumentation
99 UTILitieS", with emphasis on the first syllable.
101 .. _An Introduction to reStructuredText: docs/ref/rst/introduction.html
102 __ http://mail.python.org/pipermail/doc-sig/1999-December/000878.html
103 __ http://mail.python.org/pipermail/doc-sig/2000-November/001252.html
104 __ http://mail.python.org/pipermail/doc-sig/2000-November/001239.html
105 __ http://homepage.ntlworld.com/tibsnjoan/docutils/STpy.html
108 Is there a GUI authoring environment for Docutils?
109 --------------------------------------------------
111 DocFactory_ is under development.  It uses wxPython and looks very
112 promising.
114 .. _DocFactory:
115    http://docutils.sf.net/sandbox/gschwant/docfactory/doc/
118 What is the status of the Docutils project?
119 -------------------------------------------
121 Although useful and relatively stable, Docutils is experimental code,
122 with APIs and architecture subject to change.
124 Our highest priority is to fix bugs as they are reported.  So the
125 latest code from the repository_ (or the snapshots_) is almost always
126 the most stable (bug-free) as well as the most featureful.
129 What is the Docutils project release policy?
130 --------------------------------------------
132 It's "release early & often".  We also have automatically-generated
133 snapshots_ which always contain the latest code from the repository_.
134 As the project matures, we may formalize on a
135 stable/development-branch scheme, but we're not using anything like
136 that yet.
138 .. _repository: docs/dev/repository.html
139 .. _snapshots: http://docutils.sourceforge.net/#download
142 reStructuredText
143 ================
145 What is reStructuredText?
146 -------------------------
148 reStructuredText_ is an easy-to-read, what-you-see-is-what-you-get
149 plaintext markup syntax and parser system.  The reStructuredText
150 parser is a component of Docutils_.  reStructuredText is a revision
151 and reinterpretation of the StructuredText_ and Setext_ lightweight
152 markup systems.
154 If you are reading this on the web, you can see for yourself.  `The
155 source for this FAQ <FAQ.txt>`_ is written in reStructuredText; open
156 it in another window and compare them side by side.
158 `A ReStructuredText Primer`_ and the `Quick reStructuredText`_ user
159 reference are a good place to start.  The `reStructuredText Markup
160 Specification`_ is a detailed technical specification.
162 .. _A ReStructuredText Primer: docs/user/rst/quickstart.html
163 .. _Quick reStructuredText: docs/user/rst/quickref.html
164 .. _reStructuredText Markup Specification:
165    docs/ref/rst/restructuredtext.html
166 .. _reStructuredText: http://docutils.sourceforge.net/rst.html
167 .. _StructuredText:
168    http://dev.zope.org/Members/jim/StructuredTextWiki/FrontPage/
169 .. _Setext: http://docutils.sourceforge.net/mirror/setext.html
172 Why is it called "reStructuredText"?
173 ------------------------------------
175 The name came from a combination of "StructuredText", one of
176 reStructuredText's predecessors, with "re": "revised", "reworked", and
177 "reinterpreted", and as in the ``re.py`` regular expression module.
178 For a detailed history of reStructuredText and the Docutils project,
179 see `An Introduction to reStructuredText`_.
182 What's the standard abbreviation for "reStructuredText"?
183 --------------------------------------------------------
185 "RST" and "ReST" (or "reST") are both acceptable.  Care should be
186 taken with capitalization, to avoid confusion with "REST__", an
187 acronym for "Representational State Transfer".
189 The abbreviations "reSTX" and "rSTX"/"rstx" should **not** be used;
190 they overemphasize reStructuredText's precedessor, Zope's
191 StructuredText.
193 __ http://en.wikipedia.org/wiki/Representational_State_Transfer
196 What's the standard filename extension for a reStructuredText file?
197 -------------------------------------------------------------------
199 It's ".txt".  Some people would like to use ".rest" or ".rst" or
200 ".restx", but why bother?  ReStructuredText source files are meant to
201 be readable as plaintext, and most operating systems already associate
202 ".txt" with text files.  Using a specialized filename extension would
203 require that users alter their OS settings, which is something that
204 many users will not be willing or able to do.
207 Are there any reStructuredText editor extensions?
208 -------------------------------------------------
210 See `Editor Support for reStructuredText`__.
212 __ tools/editors/README.html
215 How can I indicate the document title?  Subtitle?
216 -------------------------------------------------
218 A uniquely-adorned section title at the beginning of a document is
219 treated specially, as the document title.  Similarly, a
220 uniquely-adorned section title immediately after the document title
221 becomes the document subtitle.  For example::
223     This is the Document Title
224     ==========================
226     This is the Document Subtitle
227     -----------------------------
229     Here's an ordinary paragraph.
231 Counterexample::
233     Here's an ordinary paragraph.
235     This is *not* a Document Title
236     ==============================
238     The "ordinary paragraph" above the section title
239     prevents it from becoming the document title.
241 Another counterexample::
243     This is not the Document Title,  because...
244     ===========================================
246     Here's an ordinary paragraph.
248     ... the title adornment is not unique
249     =====================================
251     Another ordinary paragraph.
254 How can I represent esoteric characters (e.g. character entities) in a document?
255 --------------------------------------------------------------------------------
257 For example, say you want an em-dash (XML character entity &mdash;,
258 Unicode character U+2014) in your document: use a real em-dash.
259 Insert concrete characters (e.g. type a *real* em-dash) into your
260 input file, using whatever encoding suits your application, and tell
261 Docutils the input encoding.  Docutils uses Unicode internally, so the
262 em-dash character is a real em-dash internally.
264 Emacs users should refer to the `Emacs Support for reStructuredText`__
265 document.  Tips for other editors are welcome.
267 __ tools/editors/emacs/README.html
269 ReStructuredText has no character entity subsystem; it doesn't know
270 anything about XML charents.  To Docutils, "&mdash;" in input text is
271 7 discrete characters; no interpretation happens.  When writing HTML,
272 the "&" is converted to "&amp;", so in the raw output you'd see
273 "&amp;mdash;".  There's no difference in interpretation for text
274 inside or outside inline literals or literal blocks -- there's no
275 character entity interpretation in either case.
277 If you can't use a Unicode-compatible encoding and must rely on 7-bit
278 ASCII, there is a workaround.  New in Docutils 0.3.10 is a set of
279 `Standard Substitution Definition Sets`_, which provide equivalents of
280 XML & HTML character entity sets as substitution definitions.  For
281 example, the Japanese yen currency symbol can be used as follows::
283     .. include:: <xhtml1-lat1.txt>
285     |yen| 600 for a complete meal?  That's cheap!
287 For earlier versions of Docutils, equivalent files containing
288 character entity set substitution definitions using the "unicode_"
289 directive `are available`_.  Please read the `description and
290 instructions`_ for use.  Thanks to David Priest for the original idea.
292 If you insist on using XML-style charents, you'll have to implement a
293 pre-processing system to convert to UTF-8 or something.  That
294 introduces complications though; you can no longer *write* about
295 charents naturally; instead of writing "&mdash;" you'd have to write
296 "&amp;mdash;".
298 For the common case of long dashes, you might also want to insert the
299 following substitution definitons into your document (both of them are
300 using the "unicode_" directive)::
302     .. |--| unicode:: U+2013   .. en dash
303     .. |---| unicode:: U+2014  .. em dash, trimming surrounding whitespace
304        :trim:
306 .. |--| unicode:: U+2013   .. en dash
307 .. |---| unicode:: U+2014  .. em dash, trimming surrounding whitespace
308    :trim:
310 Now you can write dashes using pure ASCII: "``foo |--| bar; foo |---|
311 bar``", rendered as "foo |--| bar; foo |---| bar".  (Note that Mozilla
312 and Firefox may render this incorrectly.)  The ``:trim:`` option for
313 the em dash is necessary because you cannot write "``foo|---|bar``";
314 thus you need to add spaces ("``foo |---| bar``") and advise the
315 reStructuredText parser to trim the spaces.
317 .. _Standard Substitution Definition Sets: docs/ref/rst/substitutions.html
318 .. _unicode: docs/ref/rst/directives.html#unicode-character-codes
319 .. _are available: http://docutils.sourceforge.net/tmp/charents/
320 .. _tarball: http://docutils.sourceforge.net/tmp/charents.tgz
321 .. _description and instructions:
322    http://docutils.sourceforge.net/tmp/charents/README.html
323 .. _to-do list: docs/dev/todo.html
326 How can I generate backticks using a Scandinavian keyboard?
327 -----------------------------------------------------------
329 The use of backticks in reStructuredText is a bit awkward with
330 Scandinavian keyboards, where the backtick is a "dead" key.  To get
331 one ` character one must press SHIFT-` + SPACE.
333 Unfortunately, with all the variations out there, there's no way to
334 please everyone.  For Scandinavian programmers and technical writers,
335 this is not limited to reStructuredText but affects many languages and
336 environments.
338 Possible solutions include
340 * If you have to input a lot of backticks, simply type one in the
341   normal/awkward way, select it, copy and then paste the rest (CTRL-V
342   is a lot faster than SHIFT-` + SPACE).
344 * Use keyboard macros.
346 * Remap the keyboard.  The Scandinavian keyboard layout is awkward for
347   other programming/technical characters too; for example, []{}
348   etc. are a bit awkward compared to US keyboards.
350   According to Axel Kollmorgen,
352       Under Windows, you can use the `Microsoft Keyboard Layout Creator
353       <http://www.microsoft.com/globaldev/tools/msklc.mspx>`__ to easily
354       map the backtick key to a real backtick (no dead key). took me
355       five minutes to load my default (german) keyboard layout, untick
356       "Dead Key?" from the backtick key properties ("in all shift
357       states"), "build dll and setup package", install the generated
358       .msi, and add my custom keyboard layout via Control Panel >
359       Regional and Language Options > Languages > Details > Add
360       Keyboard layout (and setting it as default "when you start your
361       computer").
363 * Use a virtual/screen keyboard or character palette, such as:
365   - `Web-based keyboards <http://keyboard.lab.co.il/>`__ (IE only
366     unfortunately).
367   - Windows: `Click-N-Type <http://www.lakefolks.org/cnt/>`__.
368   - Mac OS X: the Character Palette can store a set of favorite
369     characters for easy input.  Open System Preferences,
370     International, Input Menu tab, enable "Show input menu in menu
371     bar", and be sure that Character Palette is enabled in the list.
373 If anyone knows of other/better solutions, please `let us know`_.
376 Are there any tools for HTML/XML-to-reStructuredText?  (Round-tripping)
377 -----------------------------------------------------------------------
379 People have tossed the idea around, and some implementations of
380 reStructuredText-generating tools can be found in the `Docutils Link
381 List`_.
383 There's no reason why reStructuredText should not be round-trippable
384 to/from XML; any technicalities which prevent round-tripping would be
385 considered bugs.  Whitespace would not be identical, but paragraphs
386 shouldn't suffer.  The tricky parts would be the smaller details, like
387 links and IDs and other bookkeeping.
389 For HTML, true round-tripping may not be possible.  Even adding lots
390 of extra "class" attributes may not be enough.  A "simple HTML" to RST
391 filter is possible -- for some definition of "simple HTML" -- but HTML
392 is used as dumb formatting so much that such a filter may not be
393 particularly useful.  An 80/20 approach should work though: build a
394 tool that does 80% of the work automatically, leaving the other 20%
395 for manual tweaks.
397 .. _Docutils Link List: docs/user/links.html
400 Are there any Wikis that use reStructuredText syntax?
401 -----------------------------------------------------
403 There are several, with various degrees of completeness.  With no
404 implied endorsement or recommendation, and in no particular order:
406 * `Webware for Python wiki
407   <http://wiki.webwareforpython.org/thiswiki.html>`__
409 * `Ian Bicking's experimental code
410   <http://docutils.sf.net/sandbox/ianb/wiki/Wiki.py>`__
412 * `MoinMoin <http://moinmoin.wikiwikiweb.de/>`__ has some support;
413   `here's a sample <http://moinmoin.wikiwikiweb.de/RestSample>`__
415 * Zope-based `Zwiki <http://zwiki.org/>`__
417 * Zope3-based Zwiki (in the Zope 3 source tree as
418   ``zope.products.zwiki``)
420 * `StikiWiki <http://mithrandr.moria.org/code/stikiwiki/>`__
422 * `Trac <http://projects.edgewall.com/trac/>`__ `supports using
423   reStructuredText
424   <http://projects.edgewall.com/trac/wiki/WikiRestructuredText>`__ as
425   an alternative to wiki markup. This includes support for `TracLinks
426   <http://projects.edgewall.com/trac/wiki/TracLinks>`__ from within
427   RST text via a custom RST reference-directive or, even easier, an
428   interpreted text role 'trac'
430 * `Vogontia <http://www.ososo.de/vogontia/>`__, a Wiki-like FAQ system
432 Please `let us know`_ of any other reStructuredText Wikis.
434 The example application for the `Web Framework Shootout
435 <http://colorstudy.com/docs/shootout.html>`__ article is a Wiki using
436 reStructuredText.
439 Are there any Weblog (Blog) projects that use reStructuredText syntax?
440 ----------------------------------------------------------------------
442 With no implied endorsement or recommendation, and in no particular
443 order:
445 * `Firedrop <http://www.voidspace.org.uk/python/firedrop2/>`__
446 * `Python Desktop Server <http://pyds.muensterland.org/>`__
447 * `PyBloxsom <http://pyblosxom.sourceforge.net/>`__
448 * `Lino WebMan <http://lino.sourceforge.net/webman.html>`__
450 Please `let us know`_ of any other reStructuredText Blogs.
453 .. _Can lists be indented without generating block quotes?:
455 How should I mark up lists?
456 ---------------------------
458 Bullet_ & enumerated_ list markup is very intuitive but there are 2
459 points that must be noted:
461 .. _bullet: docs/ref/rst/restructuredtext.html#bullet-lists
462 .. _enumerated: docs/ref/rst/restructuredtext.html#enumerated-lists
464 1. Lists should **not** be indented.  This is correct::
466        paragraph
468        * list item 1
470          * nested item 1.1
471          * nested item 1.2
473        * list item 2
475    while this is probably incorrect::
477        paragraph
479          * list item 1
481              * nested item 1.1
482              * nested item 1.2
484          * list item 2
486    The extra indentation (of the list containing items 1.1 and 1.2) is
487    recognized as a block quote.  This is usually not what you mean and
488    it causes the list in the output to be indented too much.
490 2. There **must** be blank lines around list items, except between
491    items of the same level, where blank lines are optional.  The
492    example above shows this.
494 Note that formatting of the *output* is independent of the input, and
495 is decided by the writer and the stylesheet.  For instance, lists
496 *are* indented in HTML output by default.  See `How are lists
497 formatted in HTML?`_ for details.
500 Could lists be indented without generating block quotes?
501 --------------------------------------------------------
503 Some people like to write lists with indentation but don't intend a
504 blockquote context.  There has been a lot of discussion about allowing
505 this in reStructuredText, but there are some issues that would need to
506 be resolved before it could be implemented.  There is a summary of the
507 issues and pointers to the discussions in `the to-do list`__.
509 __ docs/dev/todo.html#indented-lists
512 Could the requirement for blank lines around lists be relaxed?
513 --------------------------------------------------------------
515 Short answer: no.
517 In reStructuredText, it would be impossible to unambigously mark up
518 and parse lists without blank lines before and after.  Deeply nested
519 lists may look ugly with so many blank lines, but it's a price we pay
520 for unambiguous markup.  Some other plaintext markup systems do not
521 require blank lines in nested lists, but they have to compromise
522 somehow, either accepting ambiguity or requiring extra complexity.
523 For example, `Epytext <http://epydoc.sf.net/epytext.html#list>`__ does
524 not require blank lines around lists, but it does require that lists
525 be indented and that ambiguous cases be escaped.
528 How can I include mathematical equations in documents?
529 ------------------------------------------------------
531 There is no elegant built-in way, yet.  There are several ideas, but
532 no obvious winner.  This issue requires a champion to solve the
533 technical and aesthetic issues and implement a generic solution.
534 Here's the `to-do list entry`__.
536 __ docs/dev/todo.html#math-markup
538 There are several quick & dirty ways to include equations in documents.
539 They all presently use LaTeX syntax or dialects of it.
541 * For LaTeX output, nothing beats raw LaTeX math.  A simple way is to
542   use the `raw directive`_::
544       .. raw:: latex
546           \[ x^3 + 3x^2a + 3xa^2 + a^3, \]
548   For inline math you could use substitutions of the raw directive but
549   the recently added `raw role`_ is more convenient.  You must define a
550   custom role based on it once in your document::
552       .. role:: raw-latex(raw)
553           :format: latex
555   and then you can just use the new role in your text::
557       the binomial expansion of :raw-latex:`$(x+a)^3$` is
559   .. _raw directive: docs/ref/rst/directives.html#raw-data-pass-through
560   .. _raw role: docs/ref/rst/roles.html#raw
562 * Jens Jørgen Mortensen has implemented a "latex-math" role and
563   directive, available from `his sandbox`__.
565   __ http://docutils.sourceforge.net/sandbox/jensj/latex_math/
567 * For HTML the "Right" w3c-standard way to include math is MathML_.
568   Unfortunately its rendering is still quite broken (or absent) on many
569   browsers but it's getting better.  Another bad problem is that typing
570   or reading raw MathML by humans is *really* painful, so embedding it
571   in a reST document with the raw directive would defy the goals of
572   readability and editability of reST (see an `example of raw MathML
573   <http://sf.net/mailarchive/message.php?msg_id=2177102>`__).
575   A much less painful way to generate HTML+MathML is to use itex2mml_ to
576   convert a dialect of LaTeX syntax to presentation MathML.  Here is an
577   example of potential `itex math markup
578   <http://article.gmane.org/gmane.text.docutils.user/118>`__.  The
579   simplest way to use it is to add ``html`` to the format lists for the
580   raw directive/role and postprocess the resulting document with
581   itex2mml.  This way you can *generate LaTeX and HTML+MathML from the
582   same source*, but you must limit yourself to the intersection of LaTeX
583   and itex markups for this to work.  Alan G. Isaac wrote a detailed
584   HOWTO_ for this approach.
586   .. _MathML: http://www.w3.org/Math/
587   .. _itex2mml: http://pear.math.pitt.edu/mathzilla/itex2mml.html
588   .. _HOWTO: http://www.american.edu/econ/itex2mml/mathhack.rst
590 * The other way to add math to HTML is to use images of the equations,
591   typically generated by TeX.  This is inferior to MathML in the long
592   term but is perhaps more accessible nowdays.
594   Of course, doing it by hand is too much work.  Beni Cherniavsky has
595   written some `preprocessing scripts`__ for converting the
596   ``texmath`` role/directive into images for HTML output and raw
597   directives/subsitution for LaTeX output.  This way you can *generate
598   LaTeX and HTML+images from the same source*.  `Instructions here`__.
600   __ http://docutils.sourceforge.net/sandbox/cben/rolehack/
601   __ http://docutils.sourceforge.net/sandbox/cben/rolehack/README.html
604 Is nested inline markup possible?
605 ---------------------------------
607 Not currently, no.  It's on the `to-do list`__ (`details here`__), and
608 hopefully will be part of the reStructuredText parser soon.  At that
609 time, markup like this will become possible::
611     Here is some *emphasized text containing a `hyperlink`_ and
612     ``inline literals``*.
614 __ docs/dev/todo.html#nested-inline-markup
615 __ docs/dev/rst/alternatives.html#nested-inline-markup
617 There are workarounds, but they are either convoluted or ugly or both.
618 They are not recommended.
620 * Inline markup can be combined with hyperlinks using `substitution
621   definitions`__ and references__ with the `"replace" directive`__.
622   For example::
624       Here is an |emphasized hyperlink|_.
626       .. |emphasized hyperlink| replace:: *emphasized hyperlink*
627       .. _emphasized hyperlink: http://example.org
629   It is not possible for just a portion of the replacement text to be
630   a hyperlink; it's the entire replacement text or nothing.
632   __ docs/ref/rst/restructuredtext.html#substitution-definitions
633   __ docs/ref/rst/restructuredtext.html#substitution-references
634   __ docs/ref/rst/directives.html#replace
636 * The `"raw" directive`__ can be used to insert raw HTML into HTML
637   output::
639       Here is some |stuff|.
641       .. |stuff| raw:: html
643          <em>emphasized text containing a
644          <a href="http://example.org">hyperlink</a> and
645          <tt>inline literals</tt></em>
647   Raw LaTeX is supported for LaTeX output, etc.
649   __ docs/ref/rst/directives.html#raw
652 How to indicate a line break or a significant newline?
653 ------------------------------------------------------
655 `Line blocks`__ are designed for address blocks, verse, and other
656 cases where line breaks are significant and must be preserved.  Unlike
657 literal blocks, the typeface is not changed, and inline markup is
658 recognized.  For example::
660     | A one, two, a one two three four
661     |
662     | Half a bee, philosophically,
663     |     must, *ipso facto*, half not be.
664     | But half the bee has got to be,
665     |     *vis a vis* its entity.  D'you see?
666     |
667     | But can a bee be said to be
668     |     or not to be an entire bee,
669     |         when half the bee is not a bee,
670     |             due to some ancient injury?
671     |
672     | Singing...
674 __ docs/ref/rst/restructuredtext.html#line-blocks
676 Here's a workaround for manually inserting explicit line breaks in
677 HTML output::
679     .. |br| raw:: html
681        <br />
683     I want to break this line here: |br| this is after the break.
685     If the extra whitespace bothers you, |br|\ backslash-escape it.
688 A URL containing asterisks doesn't work.  What to do?
689 -----------------------------------------------------
691 Asterisks are valid URL characters (see :RFC:`2396`), sometimes used
692 in URLs.  For example::
694     http://cvs.example.org/viewcvs.py/*checkout*/module/file
696 Unfortunately, the parser thinks the asterisks are indicating
697 emphasis.  The slashes serve as delineating punctuation, allowing the
698 asterisks to be recognized as markup.  The example above is separated
699 by the parser into a truncated URL, an emphasized word, and some
700 regular text::
702     http://cvs.example.org/viewcvs.py/
703     *checkout*
704     /module/file
706 To turn off markup recognition, use a backslash to escape at least the
707 first asterisk, like this::
709     http://cvs.example.org/viewcvs.py/\*checkout*/module/file
711 Escaping the second asterisk doesn't hurt, but it isn't necessary.
714 How can I make a literal block with *some* formatting?
715 ------------------------------------------------------
717 Use the `parsed-literal`_ directive.
719 .. _parsed-literal: docs/ref/rst/directives.html#parsed-literal
721 Scenario: a document contains some source code, which calls for a
722 literal block to preserve linebreaks and whitespace.  But part of the
723 source code should be formatted, for example as emphasis or as a
724 hyperlink.  This calls for a *parsed* literal block::
726     .. parsed-literal::
728        print "Hello world!"  # *tricky* code [1]_
730 The emphasis (``*tricky*``) and footnote reference (``[1]_``) will be
731 parsed.
734 Can reStructuredText be used for web or generic templating?
735 -----------------------------------------------------------
737 Docutils and reStructuredText can be used with or as a component of a
738 templating system, but they do not themselves include templating
739 functionality.  Templating should simply be left to dedicated
740 templating systems.  Users can choose a templating system to apply to
741 their reStructuredText documents as best serves their interests.
743 There are many good templating systems for Python (ht2html_, YAPTU_,
744 Quixote_'s PTL, Cheetah_, etc.; see this non-exhaustive list of `some
745 other templating systems`_), and many more for other languages, each
746 with different approaches.  We invite you to try several and find one
747 you like.  If you adapt it to use Docutils/reStructuredText, please
748 consider contributing the code to Docutils or `let us know`_ and we'll
749 keep a list here.
751 One reST-specific web templating system is `rest2web
752 <http://www.voidspace.org.uk/python/rest2web>`_, a tool for
753 automatically building websites, or parts of websites.
755 .. _ht2html: http://ht2html.sourceforge.net/
756 .. _YAPTU:
757    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52305
758 .. _Quixote: http://www.mems-exchange.org/software/quixote/
759 .. _Cheetah: http://www.cheetahtemplate.org/
760 .. _some other templating systems:
761    http://webware.sourceforge.net/Papers/Templates/
764 How can I mark up a FAQ or other list of questions & answers?
765 -------------------------------------------------------------
767 There is no specific syntax for FAQs and Q&A lists.  Here are two
768 options:
770 1. For a FAQ (Frequently Asked Questions, usually with answers), a
771    convenient way to mark up the questions is as section titles, with
772    the answer(s) as section content.  This document is marked up in
773    this way.
775    The advantages of using section titles for questions are: sections
776    can be numbered automatically, and a table of contents can be
777    generated automatically.  One limitation of this format is that
778    questions must fit on one line (section titles may not wrap, in the
779    source text).  For very long questions, the title may be a summary
780    of the question, with the full question in the section body.
782 2. Field lists work well as Q&A lists::
784        :Q: What kind of questions can we
785            put here?
787        :A: Any kind we like!
789    In order to separate questions, lists can be used:
791        1. :Q: What kind of question can we
792               put here?
793           :A: Any kind we like!
795        2. :Q: How many answers can a question have?
796           :A: It can have one,
797           :A: or more.
798           :A3: Answers can be numbered like this.
799           :A: 1. Or like this.
800               2. We're flexible!
802    If you don't want to number or otherwise mark questions, you can
803    use an empty comment between individual field lists to separate
804    them::
806        :Q: First question?
807        :A: Answer.
809        ..
811        :Q: Second question?
812        :A: Answer.
815 .. _bidi:
817 Can I produce documents in right-to-left languages?
818 ---------------------------------------------------
820 Languages written from right to left, such as Arabic and Hebrew, must
821 be reordered according to the `Unicode Bidi Algorithm`_.  This
822 requires support from the editor and special markup in the output
823 format.
825 The source format of reStructuredText is relatively bidi-friendly:
826 most constructs are denoted by punctuation without intrusion of
827 English and when you must write in English, it's usually on a separate
828 line.  So any editor that auto-detects direction per-line (like gedit
829 or geresh_) will suffice.
831 Moreover, it's possible to translate_ all reStructuredText keywords.
832 This was not yet done for any RTL language, but when it is, it will be
833 possible to write an RTL document with vitually no English.  This will
834 allow reasonable use of editors limited to a single base direction for
835 the whole document (like Notepad, Vim and text boxes in Firefox).
837 .. _Unicode Bidi Algorithm: http://www.unicode.org/reports/tr9/
838 .. _geresh: http://www.typo.co.il/~mooffie/geresh/
839 .. _translate: docs/howto/i18n.html
841 The second problem is bidi markup of the output.  There is an almost
842 transparent implicit solution for HTML:
844 * Grab http://cben-hacks.sourceforge.net/bidi/hibidi.py and
845   http://cben-hacks.sourceforge.net/bidi/rst2html_hibidi.py.
846   Put them both in the same directory and make them executable.
847   
848 * Use ``rst2html_hibidi.py`` instead of ``rst2html.py``.
850 * It infers dir attributes in the HTML from the text.  It does it
851   hierachically, giving much better results than usual.  You can still
852   use LRM/RLM and LRE/RLE/PDF control codes to help it.
854   * If you want the gory details: See the full theory_, and note the
855     incomplete practice_ (this is still a partial implementation - but
856     sufficient for most needs).
858     .. _theory: http://cben-hacks.sf.net/bidi/hibidi.html
859     .. _practice: http://cben-hacks.sf.net/bidi/hibidi.html#practice
861 There is also an explicit way to set directions through CSS and
862 classes in the HTML:
864 * Copy ``default.css`` to a new file and add relevant parts of the
865   following::
867       /* Use these two if the main document direction is RTL */
868       body { direction: rtl; }
869       div.sidebar { float: left !important; }
871       /* The next 3 rules are very useful in documents containing pieces
872       of code in english */
873       /* Use this if you all your literal blocks (::) are LTR */
874       pre {direction: ltr; unicode-bidi: embed; }
875       /* Use this if you all your inline literals (``) are LTR */
876       tt {direction: ltr; unicode-bidi: embed; }
877       /* Use this if you all your interpretted text (`) is LTR */
878       cite {direction: ltr; unicode-bidi: embed; }
880       /* Allow manual direction override by class directive and roles */
881       .rtl { direction: rtl; }
882       .ltr { direction: ltr; }
884 * Select this new stylesheet with ``--stylesheet=<file>`` or the
885   stylesheet_ setting.
886   
887 * Now if you need to override the direction of some element (from a
888   paragraph to a whole section), write::
890       .. class:: rtl
892   or::
894       .. class:: ltr
896   before it (see the class_ directive for details).
898 * To change the direction of some inline text fragment, you can use
899   RLE/LRE/PDF control characters, or write ``:rtl:`RTL text``` /
900   ``:ltr:`RTL text```.  To use the latter syntax, you must write this
901   once at the beginning of your document::
903       .. role:: ltr
904       .. role:: rtl
906 .. _stylesheet: docs/user/config.html#stylesheet
907 .. _class: docs/ref/rst/directives.txt#class
909 LaTeX is quite hard to implement (it doesn't support the bidi
910 algorithm, so all direction changes - even numbers in RTL text - must
911 be explicitly marked).  Other formats are more-or-less easy.
913 If you have any questions/problems/bugs related to bidi with docutils,
914 ask `Beni Cherniavsky`__ directly or the `Docutils-users`_ mailing
915 list.
917 __ mailto:cben@users.sf.net
920 HTML Writer
921 ===========
923 What is the status of the HTML Writer?
924 --------------------------------------
926 The HTML Writer module, ``docutils/writers/html4css1.py``, is a
927 proof-of-concept reference implementation.  While it is a complete
928 implementation, some aspects of the HTML it produces may be
929 incompatible with older browsers or specialized applications (such as
930 web templating).  Alternate implementations are welcome.
933 What kind of HTML does it produce?
934 ----------------------------------
936 It produces XHTML compatible with the `XHTML 1.0`_ specification.  A
937 cascading stylesheet is required for proper viewing with a modern
938 graphical browser.  Correct rendering of the HTML produced depends on
939 the CSS support of the browser.  A general-purpose stylesheet,
940 ``html4css1.css`` is provided with the code, and is embedded by
941 default.  It is installed in the "writers/html4css1/" subdirectory
942 within the Docutils package.  Use the ``--help`` command-line option
943 to see the specific location on your machine.
945 .. _XHTML 1.0: http://www.w3.org/TR/xhtml1/
948 What browsers are supported?
949 ----------------------------
951 No specific browser is targeted; all modern graphical browsers should
952 work.  Some older browsers, text-only browsers, and browsers without
953 full CSS support are known to produce inferior results.  Firefox,
954 Safari, Mozilla (version 1.0 and up), and MS Internet Explorer
955 (version 5.0 and up) are known to give good results.  Reports of
956 experiences with other browsers are welcome.
959 Unexpected results from tools/rst2html.py: H1, H1 instead of H1, H2.  Why?
960 --------------------------------------------------------------------------
962 Here's the question in full:
964     I have this text::
966         Heading 1
967         =========
969         All my life, I wanted to be H1.
971         Heading 1.1
972         -----------
974         But along came H1, and so shouldn't I be H2?
975         No!  I'm H1!
977         Heading 1.1.1
978         *************
980         Yeah, imagine me, I'm stuck at H3!  No?!?
982     When I run it through tools/rst2html.py, I get unexpected results
983     (below).  I was expecting H1, H2, then H3; instead, I get H1, H1,
984     H2::
986         ...
987         <html lang="en">
988         <head>
989         ...
990         <title>Heading 1</title>
991         </head>
992         <body>
993         <div class="document" id="heading-1">
994         <h1 class="title">Heading 1</h1>                <-- first H1
995         <p>All my life, I wanted to be H1.</p>
996         <div class="section" id="heading-1-1">
997         <h1><a name="heading-1-1">Heading 1.1</a></h1>        <-- H1
998         <p>But along came H1, and so now I must be H2.</p>
999         <div class="section" id="heading-1-1-1">
1000         <h2><a name="heading-1-1-1">Heading 1.1.1</a></h2>
1001         <p>Yeah, imagine me, I'm stuck at H3!</p>
1002         ...
1004     What gives?
1006 Check the "class" attribute on the H1 tags, and you will see a
1007 difference.  The first H1 is actually ``<h1 class="title">``; this is
1008 the document title, and the default stylesheet renders it centered.
1009 There can also be an ``<h2 class="subtitle">`` for the document
1010 subtitle.
1012 If there's only one highest-level section title at the beginning of a
1013 document, it is treated specially, as the document title.  (Similarly, a
1014 lone second-highest-level section title may become the document
1015 subtitle.)  See `How can I indicate the document title?  Subtitle?`_ for
1016 details.  Rather than use a plain H1 for the document title, we use ``<h1
1017 class="title">`` so that we can use H1 again within the document.  Why
1018 do we do this?  HTML only has H1-H6, so by making H1 do double duty, we
1019 effectively reserve these tags to provide 6 levels of heading beyond the
1020 single document title.
1022 HTML is being used for dumb formatting for nothing but final display.
1023 A stylesheet *is required*, and one is provided; see `What kind of
1024 HTML does it produce?`_ above.  Of course, you're welcome to roll your
1025 own.  The default stylesheet provides rules to format ``<h1
1026 class="title">`` and ``<h2 class="subtitle">`` differently from
1027 ordinary ``<h1>`` and ``<h2>``::
1029     h1.title {
1030       text-align: center }
1032     h2.subtitle {
1033       text-align: center }
1035 If you don't want the top section heading to be interpreted as a
1036 title at all, disable the `doctitle_xform`_ setting
1037 (``--no-doc-title`` option).  This will interpret your document
1038 differently from the standard settings, which might not be a good
1039 idea.  If you don't like the reuse of the H1 in the HTML output, you
1040 can tweak the `initial_header_level`_ setting
1041 (``--initial-header-level`` option) -- but unless you match its value
1042 to your specific document, you might end up with bad HTML (e.g. H3
1043 without H2).
1045 .. _doctitle_xform: docs/user/config.html#doctitle-xform
1046 .. _initial_header_level: docs/user/config.html#initial-header-level
1048 (Thanks to Mark McEahern for the question and much of the answer.)
1051 How are lists formatted in HTML?
1052 --------------------------------
1054 If list formatting looks strange, first check that you understand
1055 `list markup`__.
1057 __ `How should I mark up lists?`_
1059 * By default, HTML browsers indent lists relative to their context.
1060   This follows a long tradition in browsers (but isn't so established
1061   in print).  If you don't like it, you should change the stylesheet.
1063   This is different from how lists look in reStructuredText source.
1064   Extra indentation in the source indicates a blockquote, resulting in
1065   too much indentation in the browser.
1067 * A list item can contain multiple paragraphs etc.  In complex cases
1068   list items are separated by vertical space.  By default this spacing
1069   is omitted in "simple" lists.  A list is simple if every item
1070   contains a simple paragraph and/or a "simple" nested list.  For
1071   example:
1073       * text
1075         * simple
1077           * simple
1078           * simple
1080         * simple
1082         text after a nested list
1084       * multiple
1086         paragraphs
1088   In this example the nested lists are simple (and should appear
1089   compacted) but the outer list is not.
1091   If you want all lists to have equal spacing, disable the
1092   `compact_lists`_ setting (``--no-compact-lists`` option).  The
1093   precise spacing can be controlled in the stylesheet.
1095   Note again that this is not exactly WYSIWYG: it partially resembles
1096   the rules about blank lines being optional between list items in
1097   reStructuredText -- but adding/removing optional blank lines does
1098   not affect spacing in the output!  It's a feature, not a bug: you
1099   write it as you like but the output is styled consistently.
1101   .. _compact_lists: docs/user/config.html#compact-lists
1104 Why do enumerated lists only use numbers (no letters or roman numerals)?
1105 ------------------------------------------------------------------------
1107 The rendering of enumerators (the numbers or letters acting as list
1108 markers) is completely governed by the stylesheet, so either the
1109 browser can't find the stylesheet (try enabling the
1110 `embed_stylesheet`_ setting [``--embed-stylesheet`` option]), or the
1111 browser can't understand it (try a recent Firefox, Mozilla, Konqueror,
1112 Opera, Safari, or even MSIE).
1114 .. _embed_stylesheet: docs/user/config.html#embed-stylesheet
1117 There appear to be garbage characters in the HTML.  What's up?
1118 --------------------------------------------------------------
1120 What you're seeing is most probably not garbage, but the result of a
1121 mismatch between the actual encoding of the HTML output and the
1122 encoding your browser is expecting.  Your browser is misinterpreting
1123 the HTML data, which is encoded text.  A discussion of text encodings
1124 is beyond the scope of this FAQ; see one or more of these documents
1125 for more info:
1127 * `UTF-8 and Unicode FAQ for Unix/Linux
1128   <http://www.cl.cam.ac.uk/~mgk25/unicode.html>`_
1130 * Chapters 3 and 4 of `Introduction to i18n [Internationalization]
1131   <http://www.debian.org/doc/manuals/intro-i18n/>`_
1133 * `Python Unicode Tutorial
1134   <http://www.reportlab.com/i18n/python_unicode_tutorial.html>`_
1136 * `Python Unicode Objects: Some Observations on Working With Non-ASCII
1137   Character Sets <http://effbot.org/zone/unicode-objects.htm>`_
1139 The common case is with the default output encoding (UTF-8), when
1140 either numbered sections are used (via the "sectnum_" directive) or
1141 symbol-footnotes.  3 non-breaking spaces are inserted in each numbered
1142 section title, between the generated number and the title text.  Most
1143 footnote symbols are not available in ASCII, nor are non-breaking
1144 spaces.  When encoded with UTF-8 and viewed with ordinary ASCII tools,
1145 these characters will appear to be multi-character garbage.
1147 You may have an decoding problem in your browser (or editor, etc.).
1148 The encoding of the output is set to "utf-8", but your browswer isn't
1149 recognizing that.  You can either try to fix your browser (enable
1150 "UTF-8 character set", sometimes called "Unicode"), or choose a
1151 different encoding for the HTML output.  You can also try
1152 ``--output-encoding=ascii:xmlcharrefreplace`` for HTML or XML, but not
1153 applicable to non-XMLish outputs (if using runtime
1154 settings/configuration files, use ``output_encoding=ascii`` and
1155 ``output_encoding_error_handler=xmlcharrefreplace``).
1157 If you're generating document fragments, the "Content-Type" metadata
1158 (between the HTML ``<head>`` and ``</head>`` tags) must agree with the
1159 encoding of the rest of the document.  For UTF-8, it should be::
1161     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1163 Also, Docutils normally generates an XML declaration as the first line
1164 of the output.  It must also match the document encoding.  For UTF-8::
1166     <?xml version="1.0" encoding="utf-8" ?>
1168 .. _sectnum: docs/ref/rst/directives.html#sectnum
1171 How can I retrieve the body of the HTML document?
1172 -------------------------------------------------
1174 (This is usually needed when using Docutils in conjunction with a
1175 templating system.)
1177 You can use the `docutils.core.publish_parts()`_ function, which
1178 returns a dictionary containing an 'html_body_' entry.
1180 .. _docutils.core.publish_parts(): docs/api/publisher.html#publish-parts
1181 .. _html_body: docs/api/publisher.html#html-body
1184 Why is the Docutils XHTML served as "Content-type: text/html"?
1185 --------------------------------------------------------------
1187 Full question:
1189     Docutils' HTML output looks like XHTML and is advertised as such::
1191       <?xml version="1.0" encoding="utf-8" ?>
1192       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1193        "http://www.w3.org/TR/xht ml1/DTD/xhtml1-transitional.dtd">
1195     But this is followed by::
1197       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1199     Shouldn't this be "application/xhtml+xml" instead of "text/html"?
1201 In a perfect web, the Docutils XHTML output would be 100% strict
1202 XHTML.  But it's not a perfect web, and a major source of imperfection
1203 is Internet Explorer.  Despite it's drawbacks, IE still represents the
1204 majority of web browsers, and cannot be ignored.
1206 Short answer: if we didn't serve XHTML as "text/html" (which is a
1207 perfectly valid thing to do), it couldn't be viewed in Internet
1208 Explorer.
1210 Long answer: see the `"Criticisms of Internet Explorer" Wikipedia
1211 entry <http://en.wikipedia.org/wiki/Criticisms_of_Internet_Explorer#XHTML>`__.
1213 However, there's also `Sending XHTML as text/html Considered
1214 Harmful`__.  What to do, what to do?  We're damned no matter what we
1215 do.  So we'll continue to do the practical instead of the pure:
1216 support the browsers that are actually out there, and not fight for
1217 strict standards compliance.
1219 __ http://hixie.ch/advocacy/xhtml
1221 (Thanks to Martin F. Krafft, Robert Kern, Michael Foord, and Alan
1222 G. Isaac.)
1225 Python Source Reader
1226 ====================
1228 Can I use Docutils for Python auto-documentation?
1229 -------------------------------------------------
1231 Yes, in conjunction with other projects.
1233 Docstring extraction functionality from within Docutils is still under
1234 development.  There is most of a source code parsing module in
1235 docutils/readers/python/moduleparser.py.  We do plan to finish it
1236 eventually.  Ian Bicking wrote an initial front end for the
1237 moduleparser.py module, in sandbox/ianb/extractor/extractor.py.  Ian
1238 also did some work on the Python Source Reader
1239 (docutils.readers.python) component at PyCon DC 2004.
1241 Version 2.0 of Ed Loper's `Epydoc <http://epydoc.sourceforge.net/>`_
1242 supports reStructuredText-format docstrings for HTML output.  Docutils
1243 0.3 or newer is required.  Development of a Docutils-specific
1244 auto-documentation tool will continue.  Epydoc works by importing
1245 Python modules to be documented, whereas the Docutils-specific tool,
1246 described above, will parse modules without importing them (as with
1247 `HappyDoc <http://happydoc.sourceforge.net/>`_, which doesn't support
1248 reStructuredText).
1250 The advantages of parsing over importing are security and flexibility;
1251 the disadvantage is complexity/difficulty.
1253 * Security: untrusted code that shouldn't be executed can be parsed;
1254   importing a module executes its top-level code.
1255 * Flexibility: comments and unofficial docstrings (those not supported
1256   by Python syntax) can only be processed by parsing.
1257 * Complexity/difficulty: it's a lot harder to parse and analyze a
1258   module than it is to ``import`` and analyze one.
1260 For more details, please see "Docstring Extraction Rules" in `PEP
1261 258`_, item 3 ("How").
1264 Miscellaneous
1265 =============
1267 Is the Docutils document model based on any existing XML models?
1268 ----------------------------------------------------------------
1270 Not directly, no.  It borrows bits from DocBook, HTML, and others.  I
1271 (David Goodger) have designed several document models over the years,
1272 and have my own biases.  The Docutils document model is designed for
1273 simplicity and extensibility, and has been influenced by the needs of
1274 the reStructuredText markup.
1278    Local Variables:
1279    mode: indented-text
1280    indent-tabs-mode: nil
1281    sentence-end-double-space: t
1282    fill-column: 70
1283    End: