summaryrefslogtreecommitdiff
path: root/advanced_python/rst.rst
blob: fcbd98660304eb1d80bf41ddcb8c5f625f4031b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
ReST
----

----------------------------
The Pythonic way to Document
----------------------------

.. author: FOSSEE
.. date: 2010-07-22 Thu


What is ReST?
-------------

  + Sage Docs - Linear Algebra | Sources
  + ReST is a lightweight markup language. 
  + Developed by the Python community 
  + Heavily used in documentation of Python code 

Why ReST?
---------

  + Highly readable source format. 
  + Easy to learn and write. 
  + Simple yet Powerful markup that can produce html/LaTeX output. 

Tools used
----------

  + You will need python-docutils to compile your ReST documents
::

    sudo apt-get install python-docutils

  + To build websites, look at Sphinx, rest2web, etc. 
  + rst2html doesn't support math. We shall use Sphinx to see how math works
::

    sudo apt-get install python-sphinx

Generating output
-----------------

  + html::

      rst2html source.rst destination.html

  + LaTeX ::

      rst2latex source.rst destination.tex

  + Slide shows ::

      rst2s5 source.rst destination.html

Paragraph
---------

  + The most basic structural element 
  + Just a chunk of text separated by blank lines. 
  + Must begin at the left edge margin. 
  + Indented paragraphs are output as quoted text. 
  + Example ::

      Sage provides standard constructions from linear algebra,
      e.g., the characteristic polynomial, echelon form, trace, 
      decomposition, etc., of a matrix.

Section Headings
----------------

  + Single line of text with adornment 
  + Adornment is underline alone or an over- and underline 
  + ``- = ` :  ' " ~  ^ _ *  + # <  >`` can be used for adornment 
  + All headings with same adornment are at same level 
  + **NOTE**- The over/under line should be at least as long as the heading
    ::

      Linear Algebra
      ==============
  
      Matrix spaces
      -------------
  
      Sparse Linear Algebra
      ---------------------


Text Styles
-----------

     =======================    ====================
      Markup text                Resulting text    
     =======================    ====================
      ``*italics*``              *italics*     
      ``**strong**``             **strong**          
      ````inline literal````     ``inline literal``  
     =======================    ====================



Code Samples
------------

  + To include code, end the prior paragraph with =::= 
  + Code needs to be indented one level 
  + The code block ends, when text falls back to the previous indentation 
  + For instance ::

      For example, each of the following is legal ::

        plot(x, y)         # plot x and y using default line style and color
        plot(x, y, 'bo')   # plot x and y using blue circle markers
        plot(y)            # plot y using x as index array 0..N-1
        plot(y, 'r+')      # ditto, but with red plusses

Math
----

  + ReST in itself doesn't support math 
  + Sphinx has support for math using ~jsmath~ or ~pngmath~ 
      ::

       :math: `3 \times 3`
  
       .. math:: 
  
       \sum_{n=0}^N x_n = y

Lists
-----

  + Three flavors - Enumerated, Bulleted, Definition 
  + Always start as a new paragraph --- preceeded by a new line 
  + Enumerated 

      Number or Letter followed by a =.=,  =)= or surrounded by =( )=.

    ::

      1) Numbers
      #) auto numbered 
      A. Upper case letters
      a) lower case letters
      i) roman numerals
      (I) more roman numerals


Lists ...
---------

  + Bulleted lists

      Start a line with -, + or *

  ::

    * a bullet point using "*"
  
      - a sub-list using "-"
  
        + yet another sub-list
  
      - another item

Lists ...
---------

  + Definition Lists 

    * Consist of Term, and it's definition. 
    * Term is one line phrase; Definition is one or more paragraphs 
    * Definition is indented relative to the term 
    * Blank lines are not allowed between term and it's definition 
  
  what
    Definition lists associate a term with a definition.

Tables
------

  + Simple Tables 

    * Each line is a row. 
    * The table ends with ~=~ 
    * Column Header is specified by using ~=~ 
    * Cells may span columns; ~-~ is used to specify cells spanning columns. 

::
  
  ============ ============ =========== 
   Header 1     Header 2     Header 3   
  ============ ============ =========== 
   body row 1   column 2     column 3   
   body row 2   Cells may span columns. 
  ------------ ------------------------ 
   body row 3   column 2     column 3    
  ============ ============ ===========
  

Tables...
---------

Grid Tables
-----------

::

  +------------+------------+-----------+
  | Header 1   | Header 2   | Header 3  |
  +============+============+===========+
    body row 1   column 2     column 3   
  +------------+------------+-----------+
    body row 2   Cells may span columns. 
  +------------+------------+-----------+
    body row 3   Cells may    - Cells    
  +------------+ span rows.   - contain  
    body row 4                - blocks.  
  +------------+------------+-----------+

Links
-----

  + External links 
  
    Python_ is my favorite programming language. 
  
.. _Python: http://www.python.org/

  + Internal links 

    * To generate a link target, add a label to the location 
  
.. _example:
    * Titles & Section headings automatically produce link targets (in ReST) 
    * Linking to Target 
      + in ReST ::
      
          This is an example_ link.
          A Title
          =======
    
          `A Title`_ automatically generates hyperlink targets.

      + in Sphinx ::
    
         :ref: `This is an example <example>` link.
         This is an :ref: `example` link.
            

Footnotes
---------
::

  This[#]_ gives auto-numbered[#]_ footnotes. 
  
  This[*]_ gives auto-symbol footnotes[*]_.
  
  .. [#] First auto numbered footnote
  .. [#] Second auto numbered footnote
  .. [*] First auto symbol footnote
  .. [*] Second auto symbol footnote



References
----------

    + An Introduction to reStructured Text -- David Goodger
    + Quick reStructuredText
    + reStructuredText-- Bits and Pieces -- Christoph Reller


.. `An Introduction to reStructured Text`: http://docutils.sourceforge.net/docs/ref/rst/introduction.html
.. `Quick reStructuredText`: http://docutils.sourceforge.net/docs/user/rst/quickref.html
.. `reStructuredText-- Bits and Pieces`: http://people.ee.ethz.ch/~creller/web/tricks/reST.html