Sphinx Cheat Sheet



  • Code blocks
  1. Sphinx Cheat Sheet
  2. Sphinx Cheat Sheet Pdf

Welcome to Sphinx Cheat Sheet¶ Add code extract: ¶. Code-block:: Code must be one indent more that the code-block tag, and separated by a blank line. WxPython Classes Cheat Sheet. A wikipage to help you write scripts which was generated by a script attatched to the wikipage. NB: Think of this page as a collection of shortcuts to the docs. It is not comprehensive in any way. There are many more classes in the wx library than listed here, and most classes have many more methods. Rst Cheatsheet ¶ The rst Cheatsheet covers a wide range of rst markup. It and its contents are CC licensed. Inline Markup ¶ Inline markup allows words and phrases within text to have character styles (like italics and boldface) and functionality (like hyperlinks).

Welcome! This Sphinx reference file shows reStructured Text (rst) code followedby its html output.

Paragraphs that spread acrossmultiple lines in the source filewill display on one line in thebuilt html file.

The source file uses two line breaksto indicate a paragraph break.

a italic b bold c literal d

a emphasis b strong c literald subscript e superscript ftitle-reference g

character escaping with backslashes: thisis*one*word displays as thisisoneword

escaping backslashes: oo/o displays as oo/o

Sphinx automatically converts double dashes to unicode dashes, and quotes to smart quotes.

To add the registered trademark symbol ® or (R) with a space before and after the symbol,first insert this line at the bottom of the file:

Then in the text where you want the symbol to display, use |reg| like this:

abc–def ® ghi “jkl” ‘mno’

To show the symbol without a space before the symbol, which is the correct way to do it,use an “escaped space” by typing a backslash and then a space (word|reg|).

EXAMPLE: Anaconda®

To add the copyright symbol © or (C) with a space before and after the symbol,first insert this line at the bottom of the file:

Then in the text where you want the symbol to display, use |copy| like this:

abc–def © ghi “jkl” ‘mno’

To show the symbol without a space before the symbol, use an escaped space by typinga backslash and then a space (Copyright|copy|).

EXAMPLE: Copyright© 2017, Anaconda, Inc.

If any further unicode symbols are needed, refer to this list:http://docutils.sourceforge.net/docutils/parsers/rst/include/xhtml1-lat1.txt

  • bullet list
  • with a very long second itemon two lines.
  1. numbered
  2. list
  1. another numbered
  2. list
  • bullet
  • list
    • with
    • nesting
  • which then continues

This is a paragraph split acrosstwo lines.

This is an indented paragraph below it. On the docs site these display withbig blue quote marks, so we usually avoid them.

Here is another left justified paragraph.

has line breaks in the html output

Now out of the comment.

This example shows more complex indentation for nested lists and embedded codeblocks.

Sphinx likes sub-items under a list item to be even with the first text in theitem. So an item in an unordered (bullet) list might begin with “* One”, anda sub-item under that would begin with two spaces, while an item in an ordered(numbered) list might begin with “1. One” or “#. One”, and a sub-item under thatwould begin with three spaces.

Command blocks after a double colon should be indented four spaces past thestart of the text in the line above.

  1. Item 1.

  2. Item 2.

    More text.

    1. Part A:

      OR:

    2. Part B.

  3. Item 3. This item can have a long paragraph across multiple lines. One twothree four five six seven eight nine ten eleven twelve thirteen fourteenfifteen sixteen seventeen eighteen nineteen twenty.

    • Option A:

    • Option B:

    NOTE: Further information can go here. One two three four five six seveneight nine ten.

  4. Item 4.

Next we’ll show how we’re displaying these blocks of rst code:

If no other type applies, use “none”. It can be useful forobscure languages or mixtures of languages like this mix ofbash and python.

Now in Sphinx 1.3, captions can be added to code blocks as well:

Grid table with header:

abc
northwestnorthnortheast
westcentereast

south

west

south

south

east

Note that line breaks in the south west and south east boxes are preserved andline breaks in the north west and north east boxes are not.

Grid table without header:

northwestnorthnortheast
westcentereast
southwestsouthsoutheast

“Simple tables” are easier to write, but must havemore than one row, and the first column cannot contain multiple lines:

ABA and B
FalseFalseFalse
TrueFalseFalse
FalseTrueFalse
TrueTrueTrue

Sphinx Cheat Sheet

This paragraph links to the yahoo site.

Contents

  • Detailed reStructuredText and Sphinx example file
    • Code blocks

Adding the :local: option removes the page title “Detailed reStructuredTextand Sphinx example file” and the table of contents title “Contents”. You can seehow it displays at the top of this file.

Sphinx cheat sheet

Another file might use this table of contents:

The title “Table of Contents” overrides the default title “Contents”. The depthoption specifies that only the two top levels of headers should be displayedin the table of contents.

Instead of using the contents directive to show a table of its own contents,the index file uses the toctree directive to show a table of other files.All files in the archive should be reachable from the toctrees in the index. Filescan also contain toctrees of their own, which can lead to other files not referenceddirectly by the index. Toctrees may be hidden, in which case they will be usedto build the left navigation column but not appear in the main page text.

Images can use either the “image” directive or the “figure”directive: http://docutils.sourceforge.net/docs/ref/rst/directives.html#images

The “figure” directive supports captions, legends, numbering, and a figureclass assignment, and is preferred to the “image” directive.

Remote linking an image like this is allowed in rst in general, but produces a‘nonlocal image’ warning in Sphinx:

Warnings in a local build will cause Travis CI to fail. So, make sure your imagesare local images. It might also be possible to embed a nonlocal image similarly toembedding a YouTube video, as explained below, but embedding nonlocal images isprobably best avoided anyway. Here’s a local image.

To be sure there is enough space between an image and the text after it, inserta “pipe” or “vertical bar” character (“|”) after each image. These may also beinserted anywhere else to add extra space.

Caption goes here.

Text after the image goes here.

To insert a figure with no caption, replace the caption with an empty comment (“..”):

Text after the image goes here.

To insert an inline image:

Click the download button to download the file.

The “width” line is optional.

When using a full-size screenshot, constrain the width to 50% so it does not appear oversized:

Downloadable files can be anywhere in the directory structure. It’s usuallyeasiest to keep them in the same directory as the .rst file that refers to them.

If there are multiple downloadable files with the same name, Sphinx will renamethem and the links to them in the html. For example, if a graphics project hastwo different files named points/example.py and lines/example.py and a mathproject has one file named example.py, the _downloads directory will havefiles named example.py, example1.py, and example2.py. If you wish to preventthis, check the directory for these renamed files, and change the filenames sothey do not overlap. In this case the files could be changed tographics-example-points.py, graphics-example-lines.py, and math-example.py.

Note

This is a note admonition.This is the second line of the first paragraph.

  • The note contains all indented body elementsfollowing.
  • It includes this bullet list.

On YouTube you can click “share” and then “embed”, and it will show iframe code like this.

intro to sphinx http://docs.writethedocs.org/tools/sphinx/

rst primer http://sphinx-doc.org/rest.html

first steps w sphinx http://sphinx-doc.org/tutorial.html

links http://sphinx-doc.org/markup/inline.html#ref-role

downloads http://sphinx-doc.org/markup/inline.html#referencing-downloadable-files

RST cheat sheet http://openalea.gforge.inria.fr/doc/openalea/doc/_build/html/source/sphinx/rest_syntax.html

There are several ways to write tables. Use standard reStructuredText tables as explained here. They work fine in HTML output, however, there are some gotchas when using tables for LaTeX output.

simple table:

Simple tables can be written as follows:

which gives:

1

2

3

complex table:

gives:

Header 1

Header 2

Header 3

body row 1

column 2

column 3

body row 2

Cells may span columns.

body row 3

Cells mayspan rows.

  • Cells
  • contain
  • blocks.

body row 4

another way:

gives:

Inputs

Output

A

B

A or B

False

False

False

True

False

True

Note

table and latex documents are not yet compatible in sphinx, and you should therefore precede them with the a special directive (.. htmlonly::)

The previous examples work fine in HTML output, however there are some gotchas when using tables in LaTeX: the column width is hard to determine correctly automatically. For this reason, the following directive exists:

This directive gives a “column spec” for the next table occurring in the source file. It can have values like:

Sphinx Cheat Sheet Pdf

which means three left-adjusted (LaTeX syntax). By default, Sphinx uses a table layout with L for every column. This code:

gives

title
simple text23