Skip to content

Commit a99289e

Browse files
committed
Improved the tutorial
1 parent ded5f0f commit a99289e

6 files changed

+168
-32
lines changed

CHANGES.rst

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ Fixed:
8484
and importlib_metadata 3.6)
8585
* Handle deprecation of distutils in Python 3.10 (use the packaging package)
8686

87+
Documentation:
88+
89+
* Started a new Tutorial section.
90+
* Rewrote the first four paragraphs of the home page, to say: what rinohtype
91+
is, what it does, what problem it solves and whose needs it meets.
8792

8893
Release 0.5.3 (2021-06-16)
8994
~~~~~~~~~~~~~~~~~~~~~~~~~~
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Working with the stylesheet
2+
===========================
3+
4+
To recap what we've built so far:
5+
6+
* a Sphinx project containing some content across multiple sections
7+
* a PDF version of the output, using rinohtype's Sphinx builder, alongside
8+
Sphinx's built-in HTML rendering
9+
* a local template configuration file, ``my-article.rtt``, that is invoked in
10+
``conf.py``, and tells rinotype to:
11+
12+
* use the built-in ``article`` template
13+
* apply a stylesheet, ``allaboutme.rts``, that extends the built-in
14+
``sphinx`` stylesheet
15+
16+
----
17+
18+
You'll notice that each chapter of your document (*Plans*, *Skills*) starts on
19+
an odd-numbered page. If necessary, rinohtype will add a page break (a blank
20+
page, in effect) before each new chapter in order to force this.
21+
22+
In the :ref:`Sphinx style sheet` you'll find::
23+
24+
[chapter]
25+
page_break=RIGHT
26+
27+
Just as``emphasis`` and ``strong`` are examples of *elements* that it can
28+
target, so is a ``chapter``. This style rule ensures that each ``chapter``
29+
starts on a right-hand page.
30+
31+
Override this behaviour by adding::
32+
33+
[chapter]
34+
page_break=LEFT
35+
36+
to your ``allaboutme.rts`` file, and rebuild. You'll now find that every
37+
chapter starts on an even-numbered page instead.
38+
39+
But in a document this length it seems unnecessary to insert blank pages, so
40+
change it to ``ANY`` - and now new chapters will start on a new page, on
41+
either the left or right.
42+
43+
.. note:: Values in rinohtype stylesheets are case-insensitive.

doc/tutorial/content.rst

+109-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ entire contents of the file with the following (edit the text to your taste)::
1111

1212
Write a few paragraphs introducing yourself.
1313

14+
15+
Basic formatting examples
16+
-------------------------
17+
1418
Basic formatting in reStructuredText includes:
1519

1620
* *emphasis*
@@ -20,8 +24,39 @@ entire contents of the file with the following (edit the text to your taste)::
2024
Good things to include in your introduction would be a note about what you
2125
do and where you live.
2226

27+
28+
Some examples of Sphinx elements
29+
--------------------------------
30+
31+
.. epigraph::
32+
33+
I'd like to be remembered by my friends and enemies as honest and
34+
stylish but slightly sinister. But mostly I'd just like to be
35+
remembered.
36+
37+
-- Me
38+
39+
40+
.. note:: Take note!
41+
42+
Include a ``note`` element, like this one, in order to demonstrate
43+
how this is handled.
44+
45+
.. admonition:: An admonition
46+
47+
An ``admonition`` is a generic kind of note, amongst several other
48+
kinds that Sphinx has to offer.
49+
50+
.. toctree::
51+
:hidden:
52+
53+
plans
54+
skills
55+
56+
2357
Add a new file, ``plans.rst``, containing::
2458

59+
2560
My plans
2661
========
2762

@@ -32,11 +67,83 @@ Add a new file, ``plans.rst``, containing::
3267

3368
Perhaps you have some things that you intend to do in the near future.
3469

70+
For example, to write some Python code::
71+
72+
def plot_file(self, filename="", wait=None, resolution=None, bounds=None):
73+
"""Plots and image encoded as JSON lines in ``filename``. Passes the
74+
lines in the supplied JSON file to ``plot_lines()``.
75+
"""
76+
77+
bounds = bounds or self.bounds
78+
79+
with open(filename, "r") as line_file:
80+
lines = json.load(line_file)
81+
82+
self.plot_lines(
83+
lines=lines,
84+
wait=wait,
85+
resolution=resolution,
86+
bounds=bounds,
87+
flip=True
88+
)
89+
90+
And to quote a great mind:
91+
92+
A good will is not good because of what it effects or accomplishes,
93+
because of its fitness to attain some proposed end, but only because of
94+
its volition, that is, it is good in itself and, regarded for itself,
95+
is to be valued incomparably higher than all that could merely be
96+
brought about by it in favor of some inclination and indeed, if you
97+
will, of the sum of all inclinations.
98+
3599
Long-term plans
36100
---------------
37101

38102
And perhaps you have some that will come later on.
39103

104+
Include an image. If you want a suitable image file, use `Dürer's
105+
rhinoceros from Wikipedia
106+
<https://en.wikipedia.org/wiki/Dürer's_Rhinoceros#/media/File:The_Rhinocero
107+
s_(N GA_1964.8.697)_enhanced.png>`_. Rename it to ``rhino.png`` and place
108+
it in the root of your Sphinx project.
109+
110+
.. figure:: /rhino.png
111+
:figclass: wider
112+
:alt:
113+
114+
Not to be mistaken with rinoh: a rhino.
115+
116+
And another, ``skills.rst``::
117+
118+
Skills
119+
======
120+
121+
I enjoy learing new skills.
122+
123+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus
124+
fringilla quis metus id porta. Nullam nibh ligula, mattis at molestie non,
125+
interdum eu massa. Curabitur id sapien ut purus interdum lacinia.
126+
127+
Sed congue ligula sit amet porta pulvinar. Etiam magna risus, porttitor
128+
viverra accumsan vel, rutrum quis eros. Curabitur at nibh lacus. Fusce ex
129+
massa, pellentesque sed est eu, lacinia sodales nibh. Curabitur volutpat
130+
justo a tortor bibendum, sed rutrum purus vestibulum.
131+
132+
Aliquam aliquet neque id erat cursus, vestibulum condimentum erat
133+
convallis. In tristique, quam lacinia semper pretium, ante arcu blandit
134+
turpis, non mollis sem magna ac risus.
135+
136+
Suspendisse pharetra tellus libero, ac aliquet est mattis non. Nunc
137+
pretium scelerisque erat sit amet rutrum. Aliquam sit amet ornare mi.
138+
139+
Morbi lacus purus, elementum et leo nec, dictum dictum nulla. Sed
140+
fringilla at elit venenatis molestie. Cras rhoncus enim sed interdum
141+
sodales. Proin at sodales quam. Duis auctor libero mattis metus venenatis
142+
pretium. Etiam bibendum bibendum nisi, quis vulputate nisi commodo ut.
143+
144+
Duis semper metus id quam venenatis euismod.
145+
146+
40147
The last thing to do is to add a table of contents to the ``index.rst`` file,
41148
so it knows how to organise the content you have created. At the end of the
42149
file, add::
@@ -45,11 +152,9 @@ file, add::
45152
:hidden:
46153

47154
plans
155+
skills
48156

49-
You can add additional pages if you wish. For example, if you added
50-
``my-family.rst``, you would need to add ``my-family`` below ``plans`` in the
51-
``toctree`` (or indeed above it, if you wanted those sections in a different
52-
order).
157+
Add additional pages if you wish.
53158

54159
This isn't the place for a primer on Sphinx and rST, so you should look for
55160
other resources if you need guidance on more ambitious formatting at this

doc/tutorial/custom-template.rst

-18
This file was deleted.

doc/tutorial/customisation.rst

+8-9
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ use::
4545
``template = article`` refers to rinohtype's built-in ``article`` template (a
4646
template is defined in Python).
4747

48-
``stylesheet = allaboutme.rts`` tells
49-
rinohtype to use a particular stylesheet, which we need to create now as our
50-
final step::
48+
``stylesheet = allaboutme.rts`` tells rinohtype to use a particular
49+
stylesheet, which we need to create now as our final step::
5150

5251
[STYLESHEET]
5352
name=My custom style sheet
@@ -60,10 +59,10 @@ final step::
6059
font_color=#0f0
6160

6261
Here we told rinohtype to inherit from the built-in ``sphinx``
63-
stylesheet, and apply colors to *emphasis* and *strong* elements.
62+
stylesheet, and apply RGB colours to *emphasis* and *strong* elements.
6463

65-
Rebuild the PDF to check that your changes have taken effect. You should
66-
notice that the new PDF is more compact than the previous version, with fewer
67-
blank pages. This is because we're now using rinohtype's ``article`` template,
68-
rather than the default ``book`` - ``book`` is more suited to much longer
69-
material, laid out as a traditional book.
64+
Rebuild the PDF to check that your changes have taken effect. As well as the
65+
new colours, you should see that the new PDF is more compact than the previous
66+
version, with fewer blank pages. This is because we're now using rinohtype's
67+
``article`` template, rather than the default ``book`` - ``book`` is more
68+
suited to much longer material, laid out as a traditional book.

doc/tutorial/index.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _tutorial:
2+
13
Tutorial
24
========
35

@@ -17,4 +19,4 @@ and introduces you to a concept, tool or process in rinohtype.
1719
install
1820
content
1921
customisation
20-
custom-template
22+
configuring-stylesheet

0 commit comments

Comments
 (0)