5. reStructuredText Markup

Chinese proverb

Making full preparation will not delay your job but quicken the process. – old Chinese proverb

5.1. reStructuredText Primer

I would refer the reader to [Sphinx2019] and [Georg2018] for more details.

5.1.1. Sections

Sections are identified through their titles, which are marked up with adornment: “underlines” below the title text, or underlines and matching “overlines” above the title. More details can be found at: http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#sections

reStructuredText:

===============
 Section Title
===============

Subsection Title
++++++++++++++++

Subsubection Title
------------------

5.1.2. Paragraphs

The paragraph is the most basic block in a reST document. Paragraphs are simply chunks of text separated by one or more blank lines. As in Python, indentation is significant in reST, so all lines of the same paragraph must be left-aligned to the same level of indentation. More details can be found at: http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#paragraphs

  1. General Paragraphs

reStructuredText:

This is the first demo paragraph. The blank line above
the first line is required; The blank line below the last
line is required.

This is the second demo paragraph. The blank line above
the first line is required; The blank line below the last
line is required.

Syntax diagram:

+------------------------------+
| paragraph                    |
|                              |
+------------------------------+

+------------------------------+
| paragraph                    |
|                              |
+------------------------------+

Result:

This is the first demo paragraph. The blank line above the first line is required; The blank line below the last line is required.

This is the second demo paragraph. The blank line above the first line is required; The blank line below the last line is required.

  1. Bullet Lists Paragraphs

reStructuredText:

- This is the first bullet list item.  The blank line above the
  first list item is required; blank lines between list items
  (such as below this paragraph) are optional.

- This is the first paragraph in the second item in the list.

  This is the second paragraph in the second item in the list.
  The blank line above this paragraph is required.  The left edge
  of this paragraph lines up with the paragraph above, both
  indented relative to the bullet.

  - This is a sublist.  The bullet lines up with the left edge of
    the text blocks above.  A sublist is a new list so requires a
    blank line above and below.

  - This is a sublist.  The bullet lines up with the left edge of
the text blocks above.  A sublist is a new list so requires a
blank line above and below.

- This is the third item of the main list.

This paragraph is not part of the list.

Syntax diagram:

+------+-----------------------+
| "- " | list item             |
+------| (body elements)+      |
       +-----------------------+

Result:

  • This is the first bullet list item. The blank line above the first list item is required; blank lines between list items (such as below this paragraph) are optional.

  • This is the first paragraph in the second item in the list.

    This is the second paragraph in the second item in the list. The blank line above this paragraph is required. The left edge of this paragraph lines up with the paragraph above, both indented relative to the bullet.

    • This is a sublist. The bullet lines up with the left edge of the text blocks above. A sublist is a new list so requires a blank line above and below.
    • This is a sublist. The bullet lines up with the left edge of the text blocks above. A sublist is a new list so requires a blank line above and below.
  • This is the third item of the main list.

This paragraph is not part of the list.

  1. Bullet Lists Paragraphs

reStructuredText:

1. This is the first bullet list item.  The blank line above the
   first list item is required; blank lines between list items
   (such as below this paragraph) are optional.

2. This is the first paragraph in the second item in the list.

   This is the second paragraph in the second item in the list.
   The blank line above this paragraph is required.  The left edge
   of this paragraph lines up with the paragraph above, both
   indented relative to the bullet.

   a. This is a sublist.  The bullet lines up with the left edge of
      the text blocks above.  A sublist is a new list so requires a
      blank line above and below.

   b. This is a sublist.  The bullet lines up with the left edge of
      the text blocks above.  A sublist is a new list so requires a
      blank line above and below.


3. This is the third item of the main list.

Result:

  1. This is the first bullet list item. The blank line above the first list item is required; blank lines between list items (such as below this paragraph) are optional.

  2. This is the first paragraph in the second item in the list.

    This is the second paragraph in the second item in the list. The blank line above this paragraph is required. The left edge of this paragraph lines up with the paragraph above, both indented relative to the bullet.

    1. This is a sublist. The bullet lines up with the left edge of
      the text blocks above. A sublist is a new list so requires a blank line above and below.
    2. This is a sublist. The bullet lines up with the left edge of
      the text blocks above. A sublist is a new list so requires a blank line above and below.
  3. This is the third item of the main list.

Syntax diagram:

+-------+----------------------+
| "1. " | list item            |
+-------| (body elements)+     |
        +----------------------+

Result:

  1. This is the first bullet list item. The blank line above the first list item is required; blank lines between list items (such as below this paragraph) are optional.

  2. This is the first paragraph in the second item in the list.

    This is the second paragraph in the second item in the list. The blank line above this paragraph is required. The left edge of this paragraph lines up with the paragraph above, both indented relative to the bullet.

    1. This is a sublist. The bullet lines up with the left edge of the text blocks above. A sublist is a new list so requires a blank line above and below.
    2. This is a sublist. The bullet lines up with the left edge of the text blocks above. A sublist is a new list so requires a blank line above and below.
  3. This is the third item of the main list.

  4. Blocked Paragraphs

  1. Line Blocks

reStructuredText:

Take it away, Eric the Orchestra Leader!

    | A one, two, a one two three four
    |
    | Half a bee, philosophically,
    |     must, *ipso facto*, half not be.
    | But half the bee has got to be,
    |     *vis a vis* its entity.  D'you see?
    |
    | But can a bee be said to be
    |     or not to be an entire bee,
    |         when half the bee is not a bee,
    |             due to some ancient injury?
    |
    | Singing...

Syntax diagram:

+------+-----------------------+
| "| " | line                  |
+------| continuation line     |
       +-----------------------+

Result:

Take it away, Eric the Orchestra Leader!

A one, two, a one two three four

Half a bee, philosophically,
must, ipso facto, half not be.
But half the bee has got to be,
vis a vis its entity. D’you see?

But can a bee be said to be
or not to be an entire bee,
when half the bee is not a bee,
due to some ancient injury?

Singing…
  1. Doctest Blocks

reStructuredText:

This is an ordinary paragraph.

>>> print 'this is a Doctest block'
this is a Doctest block

The following is a literal block::

    >>> This is not recognized as a doctest block by
    reStructuredText.  It *will* be recognized by the doctest
    module, though!

Result:

This is an ordinary paragraph.

>>> print 'this is a Doctest block'
this is a Doctest block

The following is a literal block:

>>> This is not recognized as a doctest block by
reStructuredText.  It *will* be recognized by the doctest
module, though!
  1. Field Lists

reStructuredText:

:Date: 2001-08-16
:Version: 1
:Authors: - Me
          - Myself
          - I
:Indentation: Since the field marker may be quite long, the second
   and subsequent lines of the field body do not have to line up
   with the first line, but they must be indented relative to the
   field name marker, and they must line up with each other.
:Parameter i: integer

Result:

Date:

2001-08-16

Version:

1

Authors:
  • Me
  • Myself
  • I
Indentation:

Since the field marker may be quite long, the second and subsequent lines of the field body do not have to line up with the first line, but they must be indented relative to the field name marker, and they must line up with each other.

Parameter i:

integer

5.1.3. Table

More details can be found at: http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#grid-tables

  1. Grid Tables

reStructuredText:

+------------------------+------------+----------+----------+
| Header row, column 1   | Header 2   | Header 3 | Header 4 |
| (header rows optional) |            |          |          |
+========================+============+==========+==========+
| body row 1, column 1   | column 2   | column 3 | column 4 |
+------------------------+------------+----------+----------+
| body row 2             | Cells may span columns.          |
+------------------------+------------+---------------------+
| body row 3             | Cells may  | - Table cells       |
+------------------------+ span rows. | - contain           |
| body row 4             |            | - body elements.    |
+------------------------+------------+---------------------+

Result:

Header row, column 1 (header rows optional) Header 2 Header 3 Header 4
body row 1, column 1 column 2 column 3 column 4
body row 2 Cells may span columns.
body row 3 Cells may span rows.
  • Table cells
  • contain
  • body elements.
body row 4
  1. Simple Tables

reStructuredText:

=====  =====  =======
  A      B    A and B
=====  =====  =======
False  False  False
True   False  False
False  True   False
True   True   True
=====  =====  =======

Result:

A B A and B
False False False
True False False
False True False
True True True

reStructuredText:

=====  =====
col 1  col 2
=====  =====
1      Second column of row 1.
2      Second column of row 2.
       Second line of paragraph.
3      - Second column of row 3.

       - Second item in bullet
         list (row 3, column 2).
\      Row 4; column 1 will be empty.
=====  =====

Result:

col 1 col 2
1 Second column of row 1.
2 Second column of row 2. Second line of paragraph.
3
  • Second column of row 3.
  • Second item in bullet list (row 3, column 2).
Row 4; column 1 will be empty.
  1. CSV Tables

reStructuredText:

.. csv-table:: Frozen Delights!
   :header: "Treat", "Quantity", "Description"
   :widths: 15, 10, 30

   "Albatross", 2.99, "On a stick!"
   "Crunchy Frog", 1.49, "If we took the bones out, it wouldn't be
   crunchy, now would it?"
   "Gannet Ripple", 1.99, "On a stick!"
Frozen Delights!
Treat Quantity Description
Albatross 2.99 On a stick!
Crunchy Frog 1.49 If we took the bones out, it wouldn’t be crunchy, now would it?
Gannet Ripple 1.99 On a stick!
  1. List Tables

reStructuredText:

.. list-table:: Frozen Delights!
   :widths: 15 10 30
   :header-rows: 1

   * - Treat
     - Quantity
     - Description
   * - Albatross
     - 2.99
     - On a stick!
   * - Crunchy Frog
     - 1.49
     - If we took the bones out, it wouldn't be
       crunchy, now would it?
   * - Gannet Ripple
     - 1.99
     - On a stick!
Frozen Delights!
Treat Quantity Description
Albatross 2.99 On a stick!
Crunchy Frog 1.49 If we took the bones out, it wouldn’t be crunchy, now would it?
Gannet Ripple 1.99 On a stick!

5.1.4. Images and Figures

There are two image directives: imag and figure. More details can be found at: http://docutils.sourceforge.net/docs/ref/rst/directives.html#image.

  1. Simple import

reStructuredText:

.. image:: images/boxp.png
_images/boxp.png

reStructuredText:

.. figure:: images/avg_rating_mon.png
   :scale: 50 %
   :alt: map to buried treasure

   This is the caption of the figure (a simple paragraph).
map to buried treasure

This is the caption of the figure (a simple paragraph).

  1. Complex import

reStructuredText:

.. figure:: images/boxp.png
   :height: 400 px
   :width: 800 px
   :scale: 50 %
   :alt: alternate text
   :align: right

   This is the caption of the figure (a simple paragraph).

Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures
Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures
Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures
Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures

.. figure:: images/boxp.png
   :height: 400 px
   :width: 800 px
   :scale: 50 %
   :alt: alternate text
   :align: center

   This is the caption of the figure (a simple paragraph).

Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures
Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures
Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures
Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures


.. figure:: images/boxp.png
   :height: 400 px
   :width: 800 px
   :scale: 50 %
   :alt: alternate text
   :align: left

   This is the caption of the figure (a simple paragraph).

Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures
Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures
Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures
Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures

Result:

alternate text

This is the caption of the figure (a simple paragraph).

Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures

alternate text

This is the caption of the figure (a simple paragraph).

Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures

alternate text

This is the caption of the figure (a simple paragraph).

Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures Images and Figures

  1. Figures in table

reStructuredText:

+------------------------------+-----------------------+
| Figures                      | Description           |
+==============================+=======================+
| .. figure:: images/corr.png  | Figure 1: test        |
|    :scale: 20 %              |                       |
+------------------------------+-----------------------+
| .. image:: images/corr.png   | Figure 2: test        |
|    :scale: 20 %              |                       |
+------------------------------+-----------------------+
| .. image:: images/corr.png   | Figure 3: test        |
|    :scale: 20 %              |                       |
+------------------------------+-----------------------+

Result:

Figures Description
_images/corr.png
Figure 1: test
_images/corr.png Figure 2: test
_images/corr.png Figure 3: test

5.1.5. Math

The math role marks its content as mathematical notation (inline formula). More details can be found at: http://www.sphinx-doc.org/es/stable/ext/math.html.

The input language for mathematics is LaTeX markup. I will not do a LaTex tutorial as here.

  1. Inline formula

reStructuredText:

The area of a circle is :math:`A_\text{c} = (\pi/4) d^2`.

RFesult:

The area of a circle is A_\text{c} = (\pi/4) d^2.

  1. Equations

reStructuredText:

    .. math::
       :label: eq_lin_cost_func

       \min _{\beta\in \mathbb {R} ^{p}}{\frac {1}{n}}\|{\hat {X}}\beta-{\hat {Y}}\|^{2}

The equation :eq:`eq_lin_cost_func` is the cost function for linear regression.

Result:

(1)\min _{\beta\in \mathbb {R} ^{p}}{\frac {1}{n}}\|{\hat {X}}\beta-{\hat {Y}}\|^{2}

The equation (1) is the cost function for linear regression.

  1. User defined symbol and equation

Add your definitions to the latex_elements['preamble'] and imgmath_latex_preamble, then you can apply your own notations for symbol and equtions.

my definitions for \B symbol and \euler equation:

'\\def\\B{{\\bf \\mathcal B}}\n'+ \
'\\def\\euler{\ e^{i\pi} + 1 = 0}\n'

reStructuredText:

The is a test for the user defined math symbol: :math:`\B`.

The is a test for the user defined math equation:

.. math::

        \euler

The is a test for the user defined math symbol: \B.

The is a test for the user defined math equation:

\euler

  1. More examples

reStructuredText:

.. math::

        f(x)
        =
        \Biggl \lbrace
        {
        0,\text{ if }
           { x >0}
        \atop
        1 \text{ otherwise }
        }

.. math::

   (a + b)^2  &=  (a + b)(a + b) \\
              &=  a^2 + 2ab + b^2

.. math::
   :nowrap:

   \begin{eqnarray}
      y    & = & ax^2 + bx + c \nonumber\\
      f(x) & = & x^2 + 2xy + y^2\nonumber
   \end{eqnarray}

.. math:: e^{i\pi} + 1 = 0
   :label: euler

Result:

f(x)
=
\Biggl \lbrace
{
0,\text{ if }
   { x >0}
\atop
1 \text{ otherwise }
}

(a + b)^2  &=  (a + b)(a + b) \\
           &=  a^2 + 2ab + b^2

\begin{eqnarray}
   y    & = & ax^2 + bx + c \nonumber\\
   f(x) & = & x^2 + 2xy + y^2\nonumber
\end{eqnarray}

(2)e^{i\pi} + 1 = 0

5.1.6. Source Codes

  1. Source code block

reStructuredText:

.. code-block:: python

        '''
        This is a source Python code demo for Sphinx.
        @date:  Apr 25, 2016
        @author: Wenqiang Feng
        '''
        import pandas as pd
        import numpy as np
        import matplotlib.pyplot as plt
        from pandas.tools.plotting import scatter_matrix
        from docutils.parsers.rst.directives import path


        if __name__ == '__main__':

            print("This is a source Python code demo for Sphinx.")

Result:

'''
This is a source Python code demo for Sphinx.
@date:  Apr 25, 2016
@author: Wenqiang Feng
'''
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from pandas.tools.plotting import scatter_matrix
from docutils.parsers.rst.directives import path


if __name__ == '__main__':

    print("This is a source Python code demo for Sphinx.")

reStructuredText:

.. code-block:: r

        '''
        This is a source R code demo for Sphinx.
        @date:  Apr 25, 2016
        @author: Wenqiang Feng
        '''

        library(reshape2)
        library(ggplot2)

        # import data
        d <- melt(diamonds[,-c(2:4)])
        # plot histogram
        ggplot(d,aes(x = value)) +
          facet_wrap(~variable,scales = "free_x") +
          geom_histogram()

        print("This is a source R code demo for Sphinx.")
'''
This is a source R code demo for Sphinx.
@date:  Apr 25, 2016
@author: Wenqiang Feng
'''

library(reshape2)
library(ggplot2)

# import data
d <- melt(diamonds[,-c(2:4)])
# plot histogram
ggplot(d,aes(x = value)) +
  facet_wrap(~variable,scales = "free_x") +
  geom_histogram()

print("This is a source R code demo for Sphinx.")
  1. Source code import
  • Python Source code

reStructuredText:

.. literalinclude:: code/sourceCodePy.py
     :language: python

Result:

'''
This is a source Python code demo for Sphinx.
@date:  Apr 25, 2016
@author: Wenqiang Feng 
'''
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from pandas.tools.plotting import scatter_matrix
from docutils.parsers.rst.directives import path


if __name__ == '__main__':

    print("This is a source Python code demo for Sphinx.")
  • R Source code

reStructuredText:

.. literalinclude:: code/sourceCodeR.R
     :language: r

Result:

'''
This is a source R code demo for Sphinx.
@date:  Apr 25, 2016
@author: Wenqiang Feng 
'''

library(reshape2)
library(ggplot2)

# import data 
d <- melt(diamonds[,-c(2:4)])
# plot histogram
ggplot(d,aes(x = value)) + 
  facet_wrap(~variable,scales = "free_x") + 
  geom_histogram()

print("This is a source R code demo for Sphinx.")

5.1.7. Reference

  1. Paper reference

reStructuredText:

.. [Ref] Book or article reference, URL or whatever.

Lorem ipsum [Ref]_ dolor sit amet.

Result:

[Ref]Book or article reference, URL or whatever.

Lorem ipsum [Ref] dolor sit amet.

I would refer the reader to [Sphinx2019] for more details.

  1. Equation reference

reStructuredText:

.. math::
   :label: eq_condition

        f(x)
        =
        \Biggl \lbrace
        {
        0,\text{ if }
           { x >0}
        \atop
        1 \text{ otherwise }
        }

The Equation :eq:`eq_condition` is the definition of :math:`f(x)`.

Result:

(3)f(x)
     =
     \Biggl \lbrace
     {
     0,\text{ if }
        { x >0}
     \atop
     1 \text{ otherwise }
     }

The Equation (3) is the definition of f(x).

  1. Figure reference

reStructuredText:

.. _fig_hist_demo:
.. figure:: images/avg_rating_mon.png
   :scale: 50 %
   :alt: map to buried treasure

   The histogram of the gouped dataset

The Figure. :ref:`fig_hist_demo` is the histogram of the gouped dataset.

Result:

map to buried treasure

The histogram of the gouped dataset

The Figure. The histogram of the gouped dataset is the histogram of the gouped dataset.

  1. Table reference

reStructuredText:

.. _table_demo:
.. table:: The general table demo

        +------------------------+------------+----------+----------+
        | Header row, column 1   | Header 2   | Header 3 | Header 4 |
        | (header rows optional) |            |          |          |
        +========================+============+==========+==========+
        | body row 1, column 1   | column 2   | column 3 | column 4 |
        +------------------------+------------+----------+----------+
        | body row 2             | Cells may span columns.          |
        +------------------------+------------+---------------------+
        | body row 3             | Cells may  | - Table cells       |
        +------------------------+ span rows. | - contain           |
        | body row 4             |            | - body elements.    |
        +------------------------+------------+---------------------+

Please see the above Table. :ref:`table_demo`.

Result:

The general table demo
Header row, column 1 (header rows optional) Header 2 Header 3 Header 4
body row 1, column 1 column 2 column 3 column 4
body row 2 Cells may span columns.
body row 3 Cells may span rows.
  • Table cells
  • contain
  • body elements.
body row 4

Please see the above Table. The general table demo.

  1. Footnotes

reStructuredText:

Lorem ipsum [#f1]_ dolor sit amet ... [#f2]_

.. rubric:: Footnotes

.. [#f1] Text of the first footnote.
.. [#f2] Text of the second footnote.

Result:

Lorem ipsum [1] dolor sit amet … [2]

Footnotes

[1]Text of the first footnote.
[2]Text of the second footnote.
  1. Hyperlinks
  • General hyperlink

reStructuredText:

You are more than welcome to visit my personal webpage: `Feng Website`_.

.. _Feng Website: http://web.utk.edu/~wfeng1/

Result:

You are more than welcome to visit my personal webpage: Feng Website.

  • Embeded Youtube link:

reStructuredText:

.. raw:: html

    <iframe width="700" height="315"
    src="https://www.youtube.com/embed/mrEee4bhc7Y"
    frameborder="0" allowfullscreen></iframe>

Result:

Warning

You have to use the hyperlink: https://www.youtube.com/embed/ + name.

5.2. Roles

A role or “custom interpreted text role” is an inline piece of explicit markup. It signifies that that the enclosed text should be interpreted in a specific way. Sphinx uses this to provide semantic markup and cross-referencing of identifiers, as described in the appropriate section. More details can be found at: http://docutils.sourceforge.net/docs/ref/rst/roles.html#customization

5.2.1. Standard Roles

  • Line markup

reStructuredText:

* emphasis – equivalent of *emphasis*

* strong – equivalent of **strong**

* literal – equivalent of ``literal``

* subscript – H\ :sub:`2`\ O

* superscript – E = mc\ :sup:`2`

* title-reference – for titles of books, periodicals, and other materials

Result:

  • emphasis – equivalent of emphasis
  • strong – equivalent of strong
  • literal – equivalent of literal
  • subscript – H2O
  • superscript – E = mc2
  • title-reference – for titles of books, periodicals, and other materials

5.2.2. Specialized Roles

  • raw

reStructuredText:

.. raw:: html

    <iframe width="700" height="315"
    src="https://www.youtube.com/embed/2Mg8QD0F1dQ"
    frameborder="0" allowfullscreen></iframe>

Result:

reStructuredText:

.. role:: raw-html(raw)
   :format: html

If there just *has* to be a line break here,
:raw-html:`<br />`
it can be accomplished with a "raw"-derived role.
But the line block syntax should be considered first.

Result:

If there just has to be a line break here,
it can be accomplished with a “raw”-derived role. But the line block syntax should be considered first.

  • replace

reStructuredText:

.. |sphx| replace:: Sphinx
.. |reST| replace:: reStructuredText

|reST| is awesome!

Sphinx and reStructuredText are awesome!

5.3. Directives

A directive is a generic block of explicit markup. Along with roles, it is one of the extension mechanisms of reST, and Sphinx makes heavy use of it.

5.3.1. Admonitions

Admonitions: attention, caution, danger, error, hint, important, note, tip, warning

  • attention

reStructuredText:

.. attention::

   You neen to pay attention at here!

Result:

Attention

You neen to pay attention at here!

  • caution

reStructuredText:

.. caution::

   This is a caution alert!

Restlut:

Caution

This is a caution alert!

  • important

reStructuredText:

.. important::

        This is important!

Result:

Important

This is important!

  • User defined admonition

reStructuredText:

.. admonition:: User defined name

   You can make up your own admonition too.

Result:

User defined name

You can make up your own admonition too.

  • seealso

reStructuredText:

.. seealso::

   The authoritative `reStructuredText User Documentation
   <http://docutils.sourceforge.net/rst.html>`_.  The "ref" links in this
   document link to the description of the individual constructs in the reST
   reference.

Result:

See also

The authoritative reStructuredText User Documentation. The “ref” links in this document link to the description of the individual constructs in the reST reference.

See more details at Admonitions.

5.3.2. Hiddencode

reference: https://sphinxcontrib-contentui.readthedocs.io/en/latest/index.html

reStructuredText:

.. toggle-header::
    :header: Example 1 **Show/Hide Code**

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
    incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
    nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
    fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
    culpa qui officia deserunt mollit anim id est laborum

Example 1 Show/Hide Code

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum

5.3.3. Options

reStructuredText:

.. content-tabs::

    .. tab-container:: ex1
        :title: Example 1

        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
        incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
        nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
        Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
        fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
        culpa qui officia deserunt mollit anim id est laborum

    .. tab-container:: ex2
        :title: Example 2

        Sed ut perspiciatis, unde omnis iste natus error sit voluptatem
        accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae
        ab illo inventore veritatis et quasi architecto beatae vitae dicta
        sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit,
        aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos,
        qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui
        dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit, sed
        quia non numquam eius modi tempora incidunt, ut labore et dolore magnam
        aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum
        exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex
        ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in
        ea voluptate velit esse, quam nihil molestiae consequatur, vel illum,
        qui dolorem eum fugiat, quo voluptas nulla pariatur? At vero eos et
        accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium
        voluptatum deleniti atque corrupti, quos dolores et quas molestias
        excepturi sint, obcaecati cupiditate non provident, similique sunt in
        culpa, qui officia deserunt mollitia animi, id est laborum et dolorum
        fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam
        libero tempore, cum soluta nobis est eligendi optio, cumque nihil
        impedit, quo minus id, quod maxime placeat, facere possimus, omnis
        voluptas assumenda est, omnis dolor repellendus. Temporibus autem
        quibusdam et aut officiis debitis aut rerum necessitatibus saepe
        eveniet, ut et voluptates repudiandae sint et molestiae non recusandae.
        Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis
        voluptatibus maiores alias consequatur aut perferendis doloribus
        asperiores repellat.

Example 1

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum

Example 2

Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt, ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur? At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio, cumque nihil impedit, quo minus id, quod maxime placeat, facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet, ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

reStructuredText:

.. content-tabs::


    .. tab-container:: python
        :title: Python

        .. rubric:: Description for Python

    .. tab-container:: php
        :title: PHP

        .. rubric:: Description for PHP

Python

Description for Python

PHP

Description for PHP

reStructuredText:

.. container:: content-tabs right-col

    .. tab-container:: python
        :title: Python

        .. rubric:: import library

        .. code-block:: python

            import xgboost as xgb

        .. rubric:: Example request

        .. code-block:: python

            bst = xgb.train(param, dtrain, num_round, evallist)

    .. tab-container:: r
        :title: r

        .. rubric:: import library

        .. code-block:: r

            require(xgboost)

        .. rubric:: Example request

        .. code-block:: r

            bstSparse <- xgboost(data = train$data, label = train$label, max.depth = 2, eta = 1)

Python

Import library

import xgboost as xgb

Train model

bst = xgb.train(param, dtrain, num_round, evallist)

r

Import library

require(xgboost)

Train model

bstSparse <- xgboost(data = train$data, label = train$label, max.depth = 2, eta = 1)