Added an emacs function to easily create and remove line blocks.
[docutils.git] / FAQ.txt
blob63ecb258898c829c9ce083a4d1aacdf40728586e
1 .. -*- coding: utf-8 -*-
3 ===========================================
4  Docutils FAQ (Frequently Asked Questions)
5 ===========================================
7 :Date: $Date$
8 :Revision: $Revision$
9 :Web site: http://docutils.sourceforge.net/
10 :Copyright: This document has been placed in the public domain.
12 .. contents::
13 .. sectnum::
16 This is a work in progress.  If you are reading a local copy, the
17 `master copy`_ might be newer.  This document uses are relative links;
18 if they don't work, please use the `master copy`_.
20 Please feel free to ask questions and/or provide answers; send email
21 to the `Docutils-users`_ mailing list.  Project members should feel
22 free to edit the source text file directly.
24 .. _master copy: http://docutils.sourceforge.net/FAQ.html
25 .. _let us know:
26 .. _Docutils-users: docs/user/mailing-lists.html#docutils-users
30 Docutils
31 ========
33 What is Docutils?
34 -----------------
36 Docutils_ is a system for processing plaintext documentation into
37 useful formats, such as HTML, XML, and LaTeX.  It supports multiple
38 types of input, such as standalone files (implemented), inline
39 documentation from Python modules and packages (under development),
40 `PEPs (Python Enhancement Proposals)`_ (implemented), and others as
41 discovered.
43 The Docutils distribution consists of:
45 * a library (the "docutils" package), which `can be used by client
46   code`_;
47 * several `front-end tools`_ (such as ``rst2html.py``, which converts
48   reStructuredText input into HTML output);
49 * a `test suite`_; and
50 * extensive documentation_.
52 For an overview of the Docutils project implementation, see `PEP
53 258`_, "Docutils Design Specification".
55 Docutils is implemented in Python_.
57 .. _Docutils: http://docutils.sourceforge.net/
58 .. _PEPs (Python Enhancement Proposals):
59    http://www.python.org/peps/pep-0012.html
60 .. _can be used by client code: docs/api/publisher.html
61 .. _front-end tools: docs/user/tools.html
62 .. _test suite: docs/dev/testing.html
63 .. _documentation: docs/index.html
64 .. _PEP 258: http://www.python.org/peps/pep-0258.html
65 .. _Python: http://www.python.org/
68 Why is it called "Docutils"?
69 ----------------------------
71 Docutils is short for "Python Documentation Utilities".  The name
72 "Docutils" was inspired by "Distutils", the Python Distribution
73 Utilities architected by Greg Ward, a component of Python's standard
74 library.
76 The earliest known use of the term "docutils" in a Python context was
77 a `fleeting reference`__ in a message by Fred Drake on 1999-12-02 in
78 the Python Doc-SIG mailing list.  It was suggested `as a project
79 name`__ on 2000-11-27 on Doc-SIG, again by Fred Drake, in response to
80 a question from Tony "Tibs" Ibbs: "What do we want to *call* this
81 thing?".  This was shortly after David Goodger first `announced
82 reStructuredText`__ on Doc-SIG.
84 Tibs used the name "Docutils" for `his effort`__ "to document what the
85 Python docutils package should support, with a particular emphasis on
86 documentation strings".  Tibs joined the current project (and its
87 predecessors) and graciously donated the name.
89 For more history of reStructuredText and the Docutils project, see `An
90 Introduction to reStructuredText`_.
92 Please note that the name is "Docutils", not "DocUtils" or "Doc-Utils"
93 or any other variation.  It is pronounced as in "DOCumentation
94 UTILitieS", with emphasis on the first syllable.
96 .. _An Introduction to reStructuredText: docs/ref/rst/introduction.html
97 __ http://mail.python.org/pipermail/doc-sig/1999-December/000878.html
98 __ http://mail.python.org/pipermail/doc-sig/2000-November/001252.html
99 __ http://mail.python.org/pipermail/doc-sig/2000-November/001239.html
100 __ http://homepage.ntlworld.com/tibsnjoan/docutils/STpy.html
103 Is there a GUI authoring environment for Docutils?
104 --------------------------------------------------
106 DocFactory_ is under development.  It uses wxPython and looks very
107 promising.
109 .. _DocFactory:
110    http://docutils.sf.net/sandbox/gschwant/docfactory/doc/
113 What is the status of the Docutils project?
114 -------------------------------------------
116 Although useful and relatively stable, Docutils is experimental code,
117 with APIs and architecture subject to change.
119 Our highest priority is to fix bugs as they are reported.  So the
120 latest code from the repository_ (or the snapshots_) is almost always
121 the most stable (bug-free) as well as the most featureful.
124 What is the Docutils project release policy?
125 --------------------------------------------
127 It's "release early & often".  We also have automatically-generated
128 snapshots_ which always contain the latest code from the repository_.
129 As the project matures, we may formalize on a
130 stable/development-branch scheme, but we're not using anything like
131 that yet.
133 .. _repository: docs/dev/repository.html
134 .. _snapshots: http://docutils.sourceforge.net/#download
137 reStructuredText
138 ================
140 What is reStructuredText?
141 -------------------------
143 reStructuredText_ is an easy-to-read, what-you-see-is-what-you-get
144 plaintext markup syntax and parser system.  The reStructuredText
145 parser is a component of Docutils_.  reStructuredText is a revision
146 and reinterpretation of the StructuredText_ and Setext_ lightweight
147 markup systems.
149 If you are reading this on the web, you can see for yourself.  `The
150 source for this FAQ <FAQ.txt>`_ is written in reStructuredText; open
151 it in another window and compare them side by side.
153 `A ReStructuredText Primer`_ and the `Quick reStructuredText`_ user
154 reference are a good place to start.  The `reStructuredText Markup
155 Specification`_ is a detailed technical specification.
157 .. _A ReStructuredText Primer: docs/user/rst/quickstart.html
158 .. _Quick reStructuredText: docs/user/rst/quickref.html
159 .. _reStructuredText Markup Specification:
160    docs/ref/rst/restructuredtext.html
161 .. _reStructuredText: http://docutils.sourceforge.net/rst.html
162 .. _StructuredText:
163    http://dev.zope.org/Members/jim/StructuredTextWiki/FrontPage/
164 .. _Setext: http://docutils.sourceforge.net/mirror/setext.html
167 Why is it called "reStructuredText"?
168 ------------------------------------
170 The name came from a combination of "StructuredText", one of
171 reStructuredText's predecessors, with "re": "revised", "reworked", and
172 "reinterpreted", and as in the ``re.py`` regular expression module.
173 For a detailed history of reStructuredText and the Docutils project,
174 see `An Introduction to reStructuredText`_.
177 What's the standard abbreviation for "reStructuredText"?
178 --------------------------------------------------------
180 "RST" and "ReST" (or "reST") are both acceptable.  Care should be
181 taken with capitalization, to avoid confusion with "REST__", an
182 acronym for "Representational State Transfer".
184 The abbreviations "reSTX" and "rSTX"/"rstx" should **not** be used;
185 they overemphasize reStructuredText's precedessor, Zope's
186 StructuredText.
188 __ http://en.wikipedia.org/wiki/Representational_State_Transfer
191 What's the standard filename extension for a reStructuredText file?
192 -------------------------------------------------------------------
194 It's ".txt".  Some people would like to use ".rest" or ".rst" or
195 ".restx", but why bother?  ReStructuredText source files are meant to
196 be readable as plaintext, and most operating systems already associate
197 ".txt" with text files.  Using a specialized filename extension would
198 require that users alter their OS settings, which is something that
199 many users will not be willing or able to do.
202 Are there any reStructuredText editor extensions?
203 -------------------------------------------------
205 See `Editor Support for reStructuredText`__.
207 __ tools/editors/README.html
210 How can I indicate the document title?  Subtitle?
211 -------------------------------------------------
213 A uniquely-adorned section title at the beginning of a document is
214 treated specially, as the document title.  Similarly, a
215 uniquely-adorned section title immediately after the document title
216 becomes the document subtitle.  For example::
218     This is the Document Title
219     ==========================
221     This is the Document Subtitle
222     -----------------------------
224     Here's an ordinary paragraph.
226 Counterexample::
228     Here's an ordinary paragraph.
230     This is *not* a Document Title
231     ==============================
233     The "ordinary paragraph" above the section title
234     prevents it from becoming the document title.
236 Another counterexample::
238     This is not the Document Title,  because...
239     ===========================================
241     Here's an ordinary paragraph.
243     ... the title adornment is not unique
244     =====================================
246     Another ordinary paragraph.
249 How can I represent esoteric characters (e.g. character entities) in a document?
250 --------------------------------------------------------------------------------
252 For example, say you want an em-dash (XML character entity &mdash;,
253 Unicode character U+2014) in your document: use a real em-dash.
254 Insert concrete characters (e.g. type a *real* em-dash) into your
255 input file, using whatever encoding suits your application, and tell
256 Docutils the input encoding.  Docutils uses Unicode internally, so the
257 em-dash character is a real em-dash internally.
259 Emacs users should refer to the `Emacs Support for reStructuredText`__
260 document.  Tips for other editors are welcome.
262 __ tools/editors/emacs/README.html
264 ReStructuredText has no character entity subsystem; it doesn't know
265 anything about XML charents.  To Docutils, "&mdash;" in input text is
266 7 discrete characters; no interpretation happens.  When writing HTML,
267 the "&" is converted to "&amp;", so in the raw output you'd see
268 "&amp;mdash;".  There's no difference in interpretation for text
269 inside or outside inline literals or literal blocks -- there's no
270 character entity interpretation in either case.
272 If you can't use a Unicode-compatible encoding and must rely on 7-bit
273 ASCII, there is a workaround.  New in Docutils 0.3.10 is a set of
274 `Standard Substitution Definition Sets`_, which provide equivalents of
275 XML & HTML character entity sets as substitution definitions.  For
276 example, the Japanese yen currency symbol can be used as follows::
278     .. include:: <xhtml1-lat1.txt>
280     |yen| 600 for a complete meal?  That's cheap!
282 For earlier versions of Docutils, equivalent files containing
283 character entity set substitution definitions using the "unicode_"
284 directive `are available`_.  Please read the `description and
285 instructions`_ for use.  Thanks to David Priest for the original idea.
287 If you insist on using XML-style charents, you'll have to implement a
288 pre-processing system to convert to UTF-8 or something.  That
289 introduces complications though; you can no longer *write* about
290 charents naturally; instead of writing "&mdash;" you'd have to write
291 "&amp;mdash;".
293 For the common case of long dashes, you might also want to insert the
294 following substitution definitons into your document (both of them are
295 using the "unicode_" directive)::
297     .. |--| unicode:: U+2013   .. en dash
298     .. |---| unicode:: U+2014  .. em dash, trimming surrounding whitespace
299        :trim:
301 .. |--| unicode:: U+2013   .. en dash
302 .. |---| unicode:: U+2014  .. em dash, trimming surrounding whitespace
303    :trim:
305 Now you can write dashes using pure ASCII: "``foo |--| bar; foo |---|
306 bar``", rendered as "foo |--| bar; foo |---| bar".  (Note that Mozilla
307 and Firefox may render this incorrectly.)  The ``:trim:`` option for
308 the em dash is necessary because you cannot write "``foo|---|bar``";
309 thus you need to add spaces ("``foo |---| bar``") and advise the
310 reStructuredText parser to trim the spaces.
312 .. _Standard Substitution Definition Sets: docs/ref/rst/substitutions.html
313 .. _unicode: docs/ref/rst/directives.html#unicode-character-codes
314 .. _are available: http://docutils.sourceforge.net/tmp/charents/
315 .. _tarball: http://docutils.sourceforge.net/tmp/charents.tgz
316 .. _description and instructions:
317    http://docutils.sourceforge.net/tmp/charents/README.html
318 .. _to-do list: docs/dev/todo.html
321 How can I generate backticks using a Scandinavian keyboard?
322 -----------------------------------------------------------
324 The use of backticks in reStructuredText is a bit awkward with
325 Scandinavian keyboards, where the backtick is a "dead" key.  To get
326 one ` character one must press SHIFT-` + SPACE.
328 Unfortunately, with all the variations out there, there's no way to
329 please everyone.  For Scandinavian programmers and technical writers,
330 this is not limited to reStructuredText but affects many languages and
331 environments.
333 Possible solutions include
335 * If you have to input a lot of backticks, simply type one in the
336   normal/awkward way, select it, copy and then paste the rest (CTRL-V
337   is a lot faster than SHIFT-` + SPACE).
339 * Use keyboard macros.
341 * Remap the keyboard.  The Scandinavian keyboard layout is awkward for
342   other programming/technical characters too; for example, []{}
343   etc. are a bit awkward compared to US keyboards.
345   According to Axel Kollmorgen,
347       Under Windows, you can use the `Microsoft Keyboard Layout Creator
348       <http://www.microsoft.com/globaldev/tools/msklc.mspx>`__ to easily
349       map the backtick key to a real backtick (no dead key). took me
350       five minutes to load my default (german) keyboard layout, untick
351       "Dead Key?" from the backtick key properties ("in all shift
352       states"), "build dll and setup package", install the generated
353       .msi, and add my custom keyboard layout via Control Panel >
354       Regional and Language Options > Languages > Details > Add
355       Keyboard layout (and setting it as default "when you start your
356       computer").
358 * Use a virtual/screen keyboard or character palette, such as:
360   - `Web-based keyboards <http://keyboard.lab.co.il/>`__ (IE only
361     unfortunately).
362   - Windows: `Click-N-Type <http://www.lakefolks.org/cnt/>`__.
363   - Mac OS X: the Character Palette can store a set of favorite
364     characters for easy input.  Open System Preferences,
365     International, Input Menu tab, enable "Show input menu in menu
366     bar", and be sure that Character Palette is enabled in the list.
368 If anyone knows of other/better solutions, please `let us know`_.
371 Are there any tools for HTML/XML-to-reStructuredText?  (Round-tripping)
372 -----------------------------------------------------------------------
374 People have tossed the idea around, and some implementations of
375 reStructuredText-generating tools can be found in the `Docutils Link
376 List`_.
378 There's no reason why reStructuredText should not be round-trippable
379 to/from XML; any technicalities which prevent round-tripping would be
380 considered bugs.  Whitespace would not be identical, but paragraphs
381 shouldn't suffer.  The tricky parts would be the smaller details, like
382 links and IDs and other bookkeeping.
384 For HTML, true round-tripping may not be possible.  Even adding lots
385 of extra "class" attributes may not be enough.  A "simple HTML" to RST
386 filter is possible -- for some definition of "simple HTML" -- but HTML
387 is used as dumb formatting so much that such a filter may not be
388 particularly useful.  An 80/20 approach should work though: build a
389 tool that does 80% of the work automatically, leaving the other 20%
390 for manual tweaks.
392 .. _Docutils Link List: docs/user/links.html
395 Are there any Wikis that use reStructuredText syntax?
396 -----------------------------------------------------
398 There are several, with various degrees of completeness.  With no
399 implied endorsement or recommendation, and in no particular order:
401 * `Webware for Python wiki
402   <http://wiki.webwareforpython.org/thiswiki.html>`__
404 * `Ian Bicking's experimental code
405   <http://docutils.sf.net/sandbox/ianb/wiki/Wiki.py>`__
407 * `MoinMoin <http://moinmoin.wikiwikiweb.de/>`__ has some support;
408   `here's a sample <http://moinmoin.wikiwikiweb.de/RestSample>`__
410 * Zope-based `Zwiki <http://zwiki.org/>`__
412 * Zope3-based Zwiki (in the Zope 3 source tree as
413   ``zope.products.zwiki``)
415 * `StikiWiki <http://mithrandr.moria.org/code/stikiwiki/>`__
417 * `Trac <http://projects.edgewall.com/trac/>`__ `supports using
418   reStructuredText
419   <http://projects.edgewall.com/trac/wiki/WikiRestructuredText>`__ as
420   an alternative to wiki markup. This includes support for `TracLinks
421   <http://projects.edgewall.com/trac/wiki/TracLinks>`__ from within
422   RST text via a custom RST reference-directive or, even easier, an
423   interpreted text role 'trac'
425 * `Vogontia <http://www.ososo.de/vogontia/>`__, a Wiki-like FAQ system
427 Please `let us know`_ of any other reStructuredText Wikis.
429 The example application for the `Web Framework Shootout
430 <http://colorstudy.com/docs/shootout.html>`__ article is a Wiki using
431 reStructuredText.
434 Are there any Weblog (Blog) projects that use reStructuredText syntax?
435 ----------------------------------------------------------------------
437 With no implied endorsement or recommendation, and in no particular
438 order:
440 * `Firedrop <http://www.voidspace.org.uk/python/firedrop2/>`__
441 * `Python Desktop Server <http://pyds.muensterland.org/>`__
442 * `PyBloxsom <http://pyblosxom.sourceforge.net/>`__
443 * `Lino WebMan <http://lino.sourceforge.net/webman.html>`__
445 Please `let us know`_ of any other reStructuredText Blogs.
448 .. _Can lists be indented without generating block quotes?:
450 How should I mark up lists?
451 ---------------------------
453 Bullet_ & enumerated_ list markup is very intuitive but there are 2
454 points that must be noted:
456 .. _bullet: docs/ref/rst/restructuredtext.html#bullet-lists
457 .. _enumerated: docs/ref/rst/restructuredtext.html#enumerated-lists
459 1. Lists should **not** be indented.  This is correct::
461        paragraph
463        * list item 1
465          * nested item 1.1
466          * nested item 1.2
468        * list item 2
470    while this is probably incorrect::
472        paragraph
474          * list item 1
476              * nested item 1.1
477              * nested item 1.2
479          * list item 2
481    The extra indentation (of the list containing items 1.1 and 1.2) is
482    recognized as a block quote.  This is usually not what you mean and
483    it causes the list in the output to be indented too much.
485 2. There **must** be blank lines around list items, except between
486    items of the same level, where blank lines are optional.  The
487    example above shows this.
489 Note that formatting of the *output* is independent of the input, and
490 is decided by the writer and the stylesheet.  For instance, lists
491 *are* indented in HTML output by default.  See `How are lists
492 formatted in HTML?`_ for details.
495 Could lists be indented without generating block quotes?
496 --------------------------------------------------------
498 Some people like to write lists with indentation but don't intend a
499 blockquote context.  There has been a lot of discussion about allowing
500 this in reStructuredText, but there are some issues that would need to
501 be resolved before it could be implemented.  There is a summary of the
502 issues and pointers to the discussions in `the to-do list`__.
504 __ docs/dev/todo.html#indented-lists
507 Could the requirement for blank lines around lists be relaxed?
508 --------------------------------------------------------------
510 Short answer: no.
512 In reStructuredText, it would be impossible to unambigously mark up
513 and parse lists without blank lines before and after.  Deeply nested
514 lists may look ugly with so many blank lines, but it's a price we pay
515 for unambiguous markup.  Some other plaintext markup systems do not
516 require blank lines in nested lists, but they have to compromise
517 somehow, either accepting ambiguity or requiring extra complexity.
518 For example, `Epytext <http://epydoc.sf.net/epytext.html#list>`__ does
519 not require blank lines around lists, but it does require that lists
520 be indented and that ambiguous cases be escaped.
523 How can I include mathematical equations in documents?
524 ------------------------------------------------------
526 There is no elegant built-in way, yet.  There are several ideas, but
527 no obvious winner.  This issue requires a champion to solve the
528 technical and aesthetic issues and implement a generic solution.
529 Here's the `to-do list entry`__.
531 __ docs/dev/todo.html#math-markup
533 There are several quick & dirty ways to include equations in documents.
534 They all presently use LaTeX syntax or dialects of it.
536 * For LaTeX output, nothing beats raw LaTeX math.  A simple way is to
537   use the `raw directive`_::
539       .. raw:: latex
541           \[ x^3 + 3x^2a + 3xa^2 + a^3, \]
543   For inline math you could use substitutions of the raw directive but
544   the recently added `raw role`_ is more convenient.  You must define a
545   custom role based on it once in your document::
547       .. role:: raw-latex(raw)
548           :format: latex
550   and then you can just use the new role in your text::
552       the binomial expansion of :raw-latex:`$(x+a)^3$` is
554   .. _raw directive: docs/ref/rst/directives.html#raw-data-pass-through
555   .. _raw role: docs/ref/rst/roles.html#raw
557 * Jens Jørgen Mortensen has implemented a "latex-math" role and
558   directive, available from `his sandbox`__.
560   __ http://docutils.sourceforge.net/sandbox/jensj/latex_math/
562 * For HTML the "Right" w3c-standard way to include math is MathML_.
563   Unfortunately its rendering is still quite broken (or absent) on many
564   browsers but it's getting better.  Another bad problem is that typing
565   or reading raw MathML by humans is *really* painful, so embedding it
566   in a reST document with the raw directive would defy the goals of
567   readability and editability of reST (see an `example of raw MathML
568   <http://sf.net/mailarchive/message.php?msg_id=2177102>`__).
570   A much less painful way to generate HTML+MathML is to use itex2mml_ to
571   convert a dialect of LaTeX syntax to presentation MathML.  Here is an
572   example of potential `itex math markup
573   <http://article.gmane.org/gmane.text.docutils.user/118>`__.  The
574   simplest way to use it is to add ``html`` to the format lists for the
575   raw directive/role and postprocess the resulting document with
576   itex2mml.  This way you can *generate LaTeX and HTML+MathML from the
577   same source*, but you must limit yourself to the intersection of LaTeX
578   and itex markups for this to work.  Alan G. Isaac wrote a detailed
579   HOWTO_ for this approach.
581   .. _MathML: http://www.w3.org/Math/
582   .. _itex2mml: http://pear.math.pitt.edu/mathzilla/itex2mml.html
583   .. _HOWTO: http://www.american.edu/econ/itex2mml/mathhack.rst
585 * The other way to add math to HTML is to use images of the equations,
586   typically generated by TeX.  This is inferior to MathML in the long
587   term but is perhaps more accessible nowdays.
589   Of course, doing it by hand is too much work.  Beni Cherniavsky has
590   written some `preprocessing scripts`__ for converting the
591   ``texmath`` role/directive into images for HTML output and raw
592   directives/subsitution for LaTeX output.  This way you can *generate
593   LaTeX and HTML+images from the same source*.  `Instructions here`__.
595   __ http://docutils.sourceforge.net/sandbox/cben/rolehack/
596   __ http://docutils.sourceforge.net/sandbox/cben/rolehack/README.html
599 Is nested inline markup possible?
600 ---------------------------------
602 Not currently, no.  It's on the `to-do list`__ (`details here`__), and
603 hopefully will be part of the reStructuredText parser soon.  At that
604 time, markup like this will become possible::
606     Here is some *emphasized text containing a `hyperlink`_ and
607     ``inline literals``*.
609 __ docs/dev/todo.html#nested-inline-markup
610 __ docs/dev/rst/alternatives.html#nested-inline-markup
612 There are workarounds, but they are either convoluted or ugly or both.
613 They are not recommended.
615 * Inline markup can be combined with hyperlinks using `substitution
616   definitions`__ and references__ with the `"replace" directive`__.
617   For example::
619       Here is an |emphasized hyperlink|_.
621       .. |emphasized hyperlink| replace:: *emphasized hyperlink*
622       .. _emphasized hyperlink: http://example.org
624   It is not possible for just a portion of the replacement text to be
625   a hyperlink; it's the entire replacement text or nothing.
627   __ docs/ref/rst/restructuredtext.html#substitution-definitions
628   __ docs/ref/rst/restructuredtext.html#substitution-references
629   __ docs/ref/rst/directives.html#replace
631 * The `"raw" directive`__ can be used to insert raw HTML into HTML
632   output::
634       Here is some |stuff|.
636       .. |stuff| raw:: html
638          <em>emphasized text containing a
639          <a href="http://example.org">hyperlink</a> and
640          <tt>inline literals</tt></em>
642   Raw LaTeX is supported for LaTeX output, etc.
644   __ docs/ref/rst/directives.html#raw
647 How to indicate a line break or a significant newline?
648 ------------------------------------------------------
650 `Line blocks`__ are designed for address blocks, verse, and other
651 cases where line breaks are significant and must be preserved.  Unlike
652 literal blocks, the typeface is not changed, and inline markup is
653 recognized.  For example::
655     | A one, two, a one two three four
656     |
657     | Half a bee, philosophically,
658     |     must, *ipso facto*, half not be.
659     | But half the bee has got to be,
660     |     *vis a vis* its entity.  D'you see?
661     |
662     | But can a bee be said to be
663     |     or not to be an entire bee,
664     |         when half the bee is not a bee,
665     |             due to some ancient injury?
666     |
667     | Singing...
669 __ docs/ref/rst/restructuredtext.html#line-blocks
671 Here's a workaround for manually inserting explicit line breaks in
672 HTML output::
674     .. |br| raw:: html
676        <br />
678     I want to break this line here: |br| this is after the break.
680     If the extra whitespace bothers you, |br|\ backslash-escape it.
683 A URL containing asterisks doesn't work.  What to do?
684 -----------------------------------------------------
686 Asterisks are valid URL characters (see :RFC:`2396`), sometimes used
687 in URLs.  For example::
689     http://cvs.example.org/viewcvs.py/*checkout*/module/file
691 Unfortunately, the parser thinks the asterisks are indicating
692 emphasis.  The slashes serve as delineating punctuation, allowing the
693 asterisks to be recognized as markup.  The example above is separated
694 by the parser into a truncated URL, an emphasized word, and some
695 regular text::
697     http://cvs.example.org/viewcvs.py/
698     *checkout*
699     /module/file
701 To turn off markup recognition, use a backslash to escape at least the
702 first asterisk, like this::
704     http://cvs.example.org/viewcvs.py/\*checkout*/module/file
706 Escaping the second asterisk doesn't hurt, but it isn't necessary.
709 How can I make a literal block with *some* formatting?
710 ------------------------------------------------------
712 Use the `parsed-literal`_ directive.
714 .. _parsed-literal: docs/ref/rst/directives.html#parsed-literal
716 Scenario: a document contains some source code, which calls for a
717 literal block to preserve linebreaks and whitespace.  But part of the
718 source code should be formatted, for example as emphasis or as a
719 hyperlink.  This calls for a *parsed* literal block::
721     .. parsed-literal::
723        print "Hello world!"  # *tricky* code [1]_
725 The emphasis (``*tricky*``) and footnote reference (``[1]_``) will be
726 parsed.
729 Can reStructuredText be used for web or generic templating?
730 -----------------------------------------------------------
732 Docutils and reStructuredText can be used with or as a component of a
733 templating system, but they do not themselves include templating
734 functionality.  Templating should simply be left to dedicated
735 templating systems.  Users can choose a templating system to apply to
736 their reStructuredText documents as best serves their interests.
738 There are many good templating systems for Python (ht2html_, YAPTU_,
739 Quixote_'s PTL, Cheetah_, etc.; see this non-exhaustive list of `some
740 other templating systems`_), and many more for other languages, each
741 with different approaches.  We invite you to try several and find one
742 you like.  If you adapt it to use Docutils/reStructuredText, please
743 consider contributing the code to Docutils or `let us know`_ and we'll
744 keep a list here.
746 One reST-specific web templating system is `rest2web
747 <http://www.voidspace.org.uk/python/rest2web>`_, a tool for
748 automatically building websites, or parts of websites.
750 .. _ht2html: http://ht2html.sourceforge.net/
751 .. _YAPTU:
752    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52305
753 .. _Quixote: http://www.mems-exchange.org/software/quixote/
754 .. _Cheetah: http://www.cheetahtemplate.org/
755 .. _some other templating systems:
756    http://webware.sourceforge.net/Papers/Templates/
759 How can I mark up a FAQ or other list of questions & answers?
760 -------------------------------------------------------------
762 There is no specific syntax for FAQs and Q&A lists.  Here are two
763 options:
765 1. For a FAQ (Frequently Asked Questions, usually with answers), a
766    convenient way to mark up the questions is as section titles, with
767    the answer(s) as section content.  This document is marked up in
768    this way.
770    The advantages of using section titles for questions are: sections
771    can be numbered automatically, and a table of contents can be
772    generated automatically.  One limitation of this format is that
773    questions must fit on one line (section titles may not wrap, in the
774    source text).  For very long questions, the title may be a summary
775    of the question, with the full question in the section body.
777 2. Field lists work well as Q&A lists::
779        :Q: What kind of questions can we
780            put here?
782        :A: Any kind we like!
784    In order to separate questions, lists can be used:
786        1. :Q: What kind of question can we
787               put here?
788           :A: Any kind we like!
790        2. :Q: How many answers can a question have?
791           :A: It can have one,
792           :A: or more.
793           :A3: Answers can be numbered like this.
794           :A: 1. Or like this.
795               2. We're flexible!
797    If you don't want to number or otherwise mark questions, you can
798    use an empty comment between individual field lists to separate
799    them::
801        :Q: First question?
802        :A: Answer.
804        ..
806        :Q: Second question?
807        :A: Answer.
810 HTML Writer
811 ===========
813 What is the status of the HTML Writer?
814 --------------------------------------
816 The HTML Writer module, ``docutils/writers/html4css1.py``, is a
817 proof-of-concept reference implementation.  While it is a complete
818 implementation, some aspects of the HTML it produces may be
819 incompatible with older browsers or specialized applications (such as
820 web templating).  Alternate implementations are welcome.
823 What kind of HTML does it produce?
824 ----------------------------------
826 It produces XHTML compatible with the `XHTML 1.0`_ specification.  A
827 cascading stylesheet is required for proper viewing with a modern
828 graphical browser.  Correct rendering of the HTML produced depends on
829 the CSS support of the browser.  A general-purpose stylesheet,
830 ``html4css1.css`` is provided with the code, and is embedded by
831 default.  It is installed in the "writers/html4css1/" subdirectory
832 within the Docutils package.  Use the ``--help`` command-line option
833 to see the specific location on your machine.
835 .. _XHTML 1.0: http://www.w3.org/TR/xhtml1/
838 What browsers are supported?
839 ----------------------------
841 No specific browser is targeted; all modern graphical browsers should
842 work.  Some older browsers, text-only browsers, and browsers without
843 full CSS support are known to produce inferior results.  Firefox,
844 Safari, Mozilla (version 1.0 and up), and MS Internet Explorer
845 (version 5.0 and up) are known to give good results.  Reports of
846 experiences with other browsers are welcome.
849 Unexpected results from tools/rst2html.py: H1, H1 instead of H1, H2.  Why?
850 --------------------------------------------------------------------------
852 Here's the question in full:
854     I have this text::
856         Heading 1
857         =========
859         All my life, I wanted to be H1.
861         Heading 1.1
862         -----------
864         But along came H1, and so shouldn't I be H2?
865         No!  I'm H1!
867         Heading 1.1.1
868         *************
870         Yeah, imagine me, I'm stuck at H3!  No?!?
872     When I run it through tools/rst2html.py, I get unexpected results
873     (below).  I was expecting H1, H2, then H3; instead, I get H1, H1,
874     H2::
876         ...
877         <html lang="en">
878         <head>
879         ...
880         <title>Heading 1</title>
881         </head>
882         <body>
883         <div class="document" id="heading-1">
884         <h1 class="title">Heading 1</h1>                <-- first H1
885         <p>All my life, I wanted to be H1.</p>
886         <div class="section" id="heading-1-1">
887         <h1><a name="heading-1-1">Heading 1.1</a></h1>        <-- H1
888         <p>But along came H1, and so now I must be H2.</p>
889         <div class="section" id="heading-1-1-1">
890         <h2><a name="heading-1-1-1">Heading 1.1.1</a></h2>
891         <p>Yeah, imagine me, I'm stuck at H3!</p>
892         ...
894     What gives?
896 Check the "class" attribute on the H1 tags, and you will see a
897 difference.  The first H1 is actually ``<h1 class="title">``; this is
898 the document title, and the default stylesheet renders it centered.
899 There can also be an ``<h2 class="subtitle">`` for the document
900 subtitle.
902 If there's only one highest-level section title at the beginning of a
903 document, it is treated specially, as the document title.  (Similarly, a
904 lone second-highest-level section title may become the document
905 subtitle.)  See `How can I indicate the document title?  Subtitle?`_ for
906 details.  Rather than use a plain H1 for the document title, we use ``<h1
907 class="title">`` so that we can use H1 again within the document.  Why
908 do we do this?  HTML only has H1-H6, so by making H1 do double duty, we
909 effectively reserve these tags to provide 6 levels of heading beyond the
910 single document title.
912 HTML is being used for dumb formatting for nothing but final display.
913 A stylesheet *is required*, and one is provided; see `What kind of
914 HTML does it produce?`_ above.  Of course, you're welcome to roll your
915 own.  The default stylesheet provides rules to format ``<h1
916 class="title">`` and ``<h2 class="subtitle">`` differently from
917 ordinary ``<h1>`` and ``<h2>``::
919     h1.title {
920       text-align: center }
922     h2.subtitle {
923       text-align: center }
925 If you don't want the top section heading to be interpreted as a
926 title at all, disable the `doctitle_xform`_ setting
927 (``--no-doc-title`` option).  This will interpret your document
928 differently from the standard settings, which might not be a good
929 idea.  If you don't like the reuse of the H1 in the HTML output, you
930 can tweak the `initial_header_level`_ setting
931 (``--initial-header-level`` option) -- but unless you match its value
932 to your specific document, you might end up with bad HTML (e.g. H3
933 without H2).
935 .. _doctitle_xform: docs/user/config.html#doctitle-xform
936 .. _initial_header_level: docs/user/config.html#initial-header-level
938 (Thanks to Mark McEahern for the question and much of the answer.)
941 How are lists formatted in HTML?
942 --------------------------------
944 If list formatting looks strange, first check that you understand
945 `list markup`__.
947 __ `How should I mark up lists?`_
949 * By default, HTML browsers indent lists relative to their context.
950   This follows a long tradition in browsers (but isn't so established
951   in print).  If you don't like it, you should change the stylesheet.
953   This is different from how lists look in reStructuredText source.
954   Extra indentation in the source indicates a blockquote, resulting in
955   too much indentation in the browser.
957 * A list item can contain multiple paragraphs etc.  In complex cases
958   list items are separated by vertical space.  By default this spacing
959   is omitted in "simple" lists.  A list is simple if every item
960   contains a simple paragraph and/or a "simple" nested list.  For
961   example:
963       * text
965         * simple
967           * simple
968           * simple
970         * simple
972         text after a nested list
974       * multiple
976         paragraphs
978   In this example the nested lists are simple (and should appear
979   compacted) but the outer list is not.
981   If you want all lists to have equal spacing, disable the
982   `compact_lists`_ setting (``--no-compact-lists`` option).  The
983   precise spacing can be controlled in the stylesheet.
985   Note again that this is not exactly WYSIWYG: it partially resembles
986   the rules about blank lines being optional between list items in
987   reStructuredText -- but adding/removing optional blank lines does
988   not affect spacing in the output!  It's a feature, not a bug: you
989   write it as you like but the output is styled consistently.
991   .. _compact_lists: docs/user/config.html#compact-lists
994 Why do enumerated lists only use numbers (no letters or roman numerals)?
995 ------------------------------------------------------------------------
997 The rendering of enumerators (the numbers or letters acting as list
998 markers) is completely governed by the stylesheet, so either the
999 browser can't find the stylesheet (try enabling the
1000 `embed_stylesheet`_ setting [``--embed-stylesheet`` option]), or the
1001 browser can't understand it (try a recent Firefox, Mozilla, Konqueror,
1002 Opera, Safari, or even MSIE).
1004 .. _embed_stylesheet: docs/user/config.html#embed-stylesheet
1007 There appear to be garbage characters in the HTML.  What's up?
1008 --------------------------------------------------------------
1010 What you're seeing is most probably not garbage, but the result of a
1011 mismatch between the actual encoding of the HTML output and the
1012 encoding your browser is expecting.  Your browser is misinterpreting
1013 the HTML data, which is encoded text.  A discussion of text encodings
1014 is beyond the scope of this FAQ; see one or more of these documents
1015 for more info:
1017 * `UTF-8 and Unicode FAQ for Unix/Linux
1018   <http://www.cl.cam.ac.uk/~mgk25/unicode.html>`_
1020 * Chapters 3 and 4 of `Introduction to i18n [Internationalization]
1021   <http://www.debian.org/doc/manuals/intro-i18n/>`_
1023 * `Python Unicode Tutorial
1024   <http://www.reportlab.com/i18n/python_unicode_tutorial.html>`_
1026 * `Python Unicode Objects: Some Observations on Working With Non-ASCII
1027   Character Sets <http://effbot.org/zone/unicode-objects.htm>`_
1029 The common case is with the default output encoding (UTF-8), when
1030 either numbered sections are used (via the "sectnum_" directive) or
1031 symbol-footnotes.  3 non-breaking spaces are inserted in each numbered
1032 section title, between the generated number and the title text.  Most
1033 footnote symbols are not available in ASCII, nor are non-breaking
1034 spaces.  When encoded with UTF-8 and viewed with ordinary ASCII tools,
1035 these characters will appear to be multi-character garbage.
1037 You may have an decoding problem in your browser (or editor, etc.).
1038 The encoding of the output is set to "utf-8", but your browswer isn't
1039 recognizing that.  You can either try to fix your browser (enable
1040 "UTF-8 character set", sometimes called "Unicode"), or choose a
1041 different encoding for the HTML output.  You can also try
1042 ``--output-encoding=ascii:xmlcharrefreplace`` for HTML or XML, but not
1043 applicable to non-XMLish outputs (if using runtime
1044 settings/configuration files, use ``output_encoding=ascii`` and
1045 ``output_encoding_error_handler=xmlcharrefreplace``).
1047 If you're generating document fragments, the "Content-Type" metadata
1048 (between the HTML ``<head>`` and ``</head>`` tags) must agree with the
1049 encoding of the rest of the document.  For UTF-8, it should be::
1051     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1053 Also, Docutils normally generates an XML declaration as the first line
1054 of the output.  It must also match the document encoding.  For UTF-8::
1056     <?xml version="1.0" encoding="utf-8" ?>
1058 .. _sectnum: docs/ref/rst/directives.html#sectnum
1061 How can I retrieve the body of the HTML document?
1062 -------------------------------------------------
1064 (This is usually needed when using Docutils in conjunction with a
1065 templating system.)
1067 You can use the `docutils.core.publish_parts()`_ function, which
1068 returns a dictionary containing an 'html_body_' entry.
1070 .. _docutils.core.publish_parts(): docs/api/publisher.html#publish-parts
1071 .. _html_body: docs/api/publisher.html#html-body
1074 Why is the Docutils XHTML served as "Content-type: text/html"?
1075 --------------------------------------------------------------
1077 Full question:
1079     Docutils' HTML output looks like XHTML and is advertised as such::
1081       <?xml version="1.0" encoding="utf-8" ?>
1082       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1083        "http://www.w3.org/TR/xht ml1/DTD/xhtml1-transitional.dtd">
1085     But this is followed by::
1087       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1089     Shouldn't this be "application/xhtml+xml" instead of "text/html"?
1091 In a perfect web, the Docutils XHTML output would be 100% strict
1092 XHTML.  But it's not a perfect web, and a major source of imperfection
1093 is Internet Explorer.  Despite it's drawbacks, IE still represents the
1094 majority of web browsers, and cannot be ignored.
1096 Short answer: if we didn't serve XHTML as "text/html" (which is a
1097 perfectly valid thing to do), it couldn't be viewed in Internet
1098 Explorer.
1100 Long answer: see the `"Criticisms of Internet Explorer" Wikipedia
1101 entry <http://en.wikipedia.org/wiki/Criticisms_of_Internet_Explorer#XHTML>`__.
1103 However, there's also `Sending XHTML as text/html Considered
1104 Harmful`__.  What to do, what to do?  We're damned no matter what we
1105 do.  So we'll continue to do the practical instead of the pure:
1106 support the browsers that are actually out there, and not fight for
1107 strict standards compliance.
1109 __ http://hixie.ch/advocacy/xhtml
1111 (Thanks to Martin F. Krafft, Robert Kern, Michael Foord, and Alan
1112 G. Isaac.)
1115 Python Source Reader
1116 ====================
1118 Can I use Docutils for Python auto-documentation?
1119 -------------------------------------------------
1121 Yes, in conjunction with other projects.
1123 Docstring extraction functionality from within Docutils is still under
1124 development.  There is most of a source code parsing module in
1125 docutils/readers/python/moduleparser.py.  We do plan to finish it
1126 eventually.  Ian Bicking wrote an initial front end for the
1127 moduleparser.py module, in sandbox/ianb/extractor/extractor.py.  Ian
1128 also did some work on the Python Source Reader
1129 (docutils.readers.python) component at PyCon DC 2004.
1131 Version 2.0 of Ed Loper's `Epydoc <http://epydoc.sourceforge.net/>`_
1132 supports reStructuredText-format docstrings for HTML output.  Docutils
1133 0.3 or newer is required.  Development of a Docutils-specific
1134 auto-documentation tool will continue.  Epydoc works by importing
1135 Python modules to be documented, whereas the Docutils-specific tool,
1136 described above, will parse modules without importing them (as with
1137 `HappyDoc <http://happydoc.sourceforge.net/>`_, which doesn't support
1138 reStructuredText).
1140 The advantages of parsing over importing are security and flexibility;
1141 the disadvantage is complexity/difficulty.
1143 * Security: untrusted code that shouldn't be executed can be parsed;
1144   importing a module executes its top-level code.
1145 * Flexibility: comments and unofficial docstrings (those not supported
1146   by Python syntax) can only be processed by parsing.
1147 * Complexity/difficulty: it's a lot harder to parse and analyze a
1148   module than it is to ``import`` and analyze one.
1150 For more details, please see "Docstring Extraction Rules" in `PEP
1151 258`_, item 3 ("How").
1154 Miscellaneous
1155 =============
1157 Is the Docutils document model based on any existing XML models?
1158 ----------------------------------------------------------------
1160 Not directly, no.  It borrows bits from DocBook, HTML, and others.  I
1161 (David Goodger) have designed several document models over the years,
1162 and have my own biases.  The Docutils document model is designed for
1163 simplicity and extensibility, and has been influenced by the needs of
1164 the reStructuredText markup.
1168    Local Variables:
1169    mode: indented-text
1170    indent-tabs-mode: nil
1171    sentence-end-double-space: t
1172    fill-column: 70
1173    End: