-
-
Notifications
You must be signed in to change notification settings - Fork 63
Tutorial #330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
evildmp
wants to merge
6
commits into
brechtm:master
Choose a base branch
from
evildmp:tutorial
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Tutorial #330
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ded5f0f
Started a tutorial
evildmp a99289e
Improved the tutorial
evildmp 8eb5344
Fixed error in manual.rst
evildmp 89c4483
Fixed some tutorial errors
evildmp 2c0a8f5
Fixed some issues in the tutorial
evildmp 35154f0
Expanded basic styling chapter in tutorial
evildmp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| Working with the stylesheet | ||
| =========================== | ||
|
|
||
| To recap what we've built so far: | ||
|
|
||
| * a Sphinx project containing some content across multiple sections | ||
| * a PDF version of the output, using rinohtype's Sphinx builder, alongside | ||
| Sphinx's built-in HTML rendering | ||
| * a local template configuration file, ``my-article.rtt``, that is invoked in | ||
| ``conf.py``, and tells rinotype to: | ||
|
evildmp marked this conversation as resolved.
Outdated
|
||
|
|
||
| * use the built-in ``article`` template | ||
| * apply a stylesheet, ``allaboutme.rts``, that extends the built-in | ||
| ``sphinx`` stylesheet | ||
|
|
||
| ---- | ||
|
|
||
| You'll notice that each chapter of your document (*Plans*, *Skills*) starts on | ||
| an odd-numbered page. If necessary, rinohtype will add a page break (a blank | ||
| page, in effect) before each new chapter in order to force this. | ||
|
|
||
| In the :ref:`Sphinx style sheet` you'll find:: | ||
|
|
||
| [chapter] | ||
| page_break=RIGHT | ||
|
|
||
| Just as``emphasis`` and ``strong`` are examples of *elements* that it can | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space before |
||
| target, so is a ``chapter``. This style rule ensures that each ``chapter`` | ||
| starts on a right-hand page. | ||
|
|
||
| Override this behaviour by adding:: | ||
|
|
||
| [chapter] | ||
| page_break=LEFT | ||
|
|
||
| to your ``allaboutme.rts`` file, and rebuild. You'll now find that every | ||
| chapter starts on an even-numbered page instead. | ||
|
|
||
| But in a document this length it seems unnecessary to insert blank pages, so | ||
| change it to ``ANY`` - and now new chapters will start on a new page, on | ||
| either the left or right. | ||
|
|
||
| .. note:: Values in rinohtype stylesheets are case-insensitive. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| Creating content | ||
| ====================== | ||
|
|
||
| Now is an appropriate time to add some content to work with. | ||
|
|
||
| The first page of the project is the ``index.rst`` file. You can replace the | ||
| entire contents of the file with the following (edit the text to your taste):: | ||
|
|
||
| All about me | ||
| ============ | ||
|
|
||
| Write a few paragraphs introducing yourself. | ||
|
|
||
|
|
||
| Basic formatting examples | ||
| ------------------------- | ||
|
|
||
| Basic formatting in reStructuredText includes: | ||
|
|
||
| * *emphasis* | ||
| * **strong emphasis** | ||
| * asterisks for list items | ||
|
|
||
| Good things to include in your introduction would be a note about what you | ||
| do and where you live. | ||
|
|
||
|
|
||
| Some examples of Sphinx elements | ||
| -------------------------------- | ||
|
|
||
| .. epigraph:: | ||
|
|
||
| I'd like to be remembered by my friends and enemies as honest and | ||
| stylish but slightly sinister. But mostly I'd just like to be | ||
| remembered. | ||
|
|
||
| -- Me | ||
|
|
||
|
|
||
| .. note:: Take note! | ||
|
|
||
| Include a ``note`` element, like this one, in order to demonstrate | ||
| how this is handled. | ||
|
|
||
| .. admonition:: An admonition | ||
|
|
||
| An ``admonition`` is a generic kind of note, amongst several other | ||
| kinds that Sphinx has to offer. | ||
|
|
||
| .. toctree:: | ||
| :hidden: | ||
|
|
||
| plans | ||
| skills | ||
|
|
||
|
|
||
| Add a new file, ``plans.rst``, containing:: | ||
|
|
||
|
|
||
| My plans | ||
| ======== | ||
|
|
||
| Say something about your plans. | ||
|
|
||
| Short-term plans | ||
| ---------------- | ||
|
|
||
| Perhaps you have some things that you intend to do in the near future. | ||
|
|
||
| For example, to write some Python code:: | ||
|
|
||
| def plot_file(self, filename="", wait=None, resolution=None, bounds=None): | ||
| """Plots and image encoded as JSON lines in ``filename``. Passes the | ||
| lines in the supplied JSON file to ``plot_lines()``. | ||
| """ | ||
|
|
||
| bounds = bounds or self.bounds | ||
|
|
||
| with open(filename, "r") as line_file: | ||
| lines = json.load(line_file) | ||
|
|
||
| self.plot_lines( | ||
| lines=lines, | ||
| wait=wait, | ||
| resolution=resolution, | ||
| bounds=bounds, | ||
| flip=True | ||
| ) | ||
|
|
||
| And to quote a great mind: | ||
|
|
||
| A good will is not good because of what it effects or accomplishes, | ||
| because of its fitness to attain some proposed end, but only because of | ||
| its volition, that is, it is good in itself and, regarded for itself, | ||
| is to be valued incomparably higher than all that could merely be | ||
| brought about by it in favor of some inclination and indeed, if you | ||
| will, of the sum of all inclinations. | ||
|
|
||
| Long-term plans | ||
| --------------- | ||
|
|
||
| And perhaps you have some that will come later on. | ||
|
|
||
| Include an image. If you want a suitable image file, use `Dürer's | ||
| rhinoceros from Wikipedia | ||
| <https://en.wikipedia.org/wiki/Dürer's_Rhinoceros#/media/File:The_Rhinocero | ||
| s_(N GA_1964.8.697)_enhanced.png>`_. Rename it to ``rhino.png`` and place | ||
| it in the root of your Sphinx project. | ||
|
|
||
| .. figure:: /rhino.png | ||
| :figclass: wider | ||
| :alt: | ||
|
|
||
| Not to be mistaken with rinoh: a rhino. | ||
|
|
||
| And another, ``skills.rst``:: | ||
|
|
||
| Skills | ||
| ====== | ||
|
|
||
| I enjoy learing new skills. | ||
|
|
||
| Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus | ||
| fringilla quis metus id porta. Nullam nibh ligula, mattis at molestie non, | ||
| interdum eu massa. Curabitur id sapien ut purus interdum lacinia. | ||
|
|
||
| Sed congue ligula sit amet porta pulvinar. Etiam magna risus, porttitor | ||
| viverra accumsan vel, rutrum quis eros. Curabitur at nibh lacus. Fusce ex | ||
| massa, pellentesque sed est eu, lacinia sodales nibh. Curabitur volutpat | ||
| justo a tortor bibendum, sed rutrum purus vestibulum. | ||
|
|
||
| Aliquam aliquet neque id erat cursus, vestibulum condimentum erat | ||
| convallis. In tristique, quam lacinia semper pretium, ante arcu blandit | ||
| turpis, non mollis sem magna ac risus. | ||
|
|
||
| Suspendisse pharetra tellus libero, ac aliquet est mattis non. Nunc | ||
| pretium scelerisque erat sit amet rutrum. Aliquam sit amet ornare mi. | ||
|
|
||
| Morbi lacus purus, elementum et leo nec, dictum dictum nulla. Sed | ||
| fringilla at elit venenatis molestie. Cras rhoncus enim sed interdum | ||
| sodales. Proin at sodales quam. Duis auctor libero mattis metus venenatis | ||
| pretium. Etiam bibendum bibendum nisi, quis vulputate nisi commodo ut. | ||
|
|
||
| Duis semper metus id quam venenatis euismod. | ||
|
|
||
|
|
||
| The last thing to do is to add a table of contents to the ``index.rst`` file, | ||
| so it knows how to organise the content you have created. At the end of the | ||
| file, add:: | ||
|
|
||
| .. toctree:: | ||
| :hidden: | ||
|
|
||
| plans | ||
| skills | ||
|
evildmp marked this conversation as resolved.
|
||
|
|
||
| Add additional pages if you wish. | ||
|
|
||
| This isn't the place for a primer on Sphinx and rST, so you should look for | ||
| other resources if you need guidance on more ambitious formatting at this | ||
| stage. | ||
|
|
||
| Run ``make html`` and reload the ``index.html`` page to see the new content as | ||
| HTML; run ``make rinoh`` and re-open ``allaboutme.pdf`` to see the new version | ||
|
evildmp marked this conversation as resolved.
|
||
| of the PDF (if you're lucky, your PDF viewer will reload the changed file for | ||
| your automatically). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| Basic customisation | ||
| ==================== | ||
|
|
||
| HTML | ||
| ---- | ||
|
|
||
| The next step is to manage *how* Sphinx builds the project. It's useful to use | ||
| an HTML theme whose output corresponds better to PDF rendering, so switch to | ||
| Furo; in ``conf.py``, edit the ``html_theme`` setting, to:: | ||
|
evildmp marked this conversation as resolved.
Outdated
|
||
|
|
||
| html_theme = 'furo' | ||
|
|
||
| Rebuild the HTML to see the effect. | ||
|
|
||
|
|
||
| --- | ||
|
|
||
| The PDF customisation is a little more complex. We need to do three things. | ||
|
|
||
| First, apply some rinoh configuration in ``conf.py``:: | ||
|
|
||
| rinoh_documents = [ | ||
| { | ||
| "doc": "index", | ||
| "target": "allaboutme", | ||
| "template": "my-article.rtt" | ||
| } | ||
| ] | ||
|
|
||
| In brief, this means: | ||
|
|
||
| * build a document using the ``index`` file as the root | ||
| * name the output ``allaboutme`` | ||
| * use the template configuration file in ``my-article.rtt``. | ||
|
evildmp marked this conversation as resolved.
|
||
|
|
||
| Next, create the ``my-article.rtt`` template configuration file that this will | ||
| use:: | ||
|
|
||
| [TEMPLATE_CONFIGURATION] | ||
| name = My custom configuration | ||
| template = article | ||
| stylesheet = allaboutme.rts | ||
|
|
||
| ``template = article`` refers to rinohtype's built-in ``article`` template (a | ||
| template is defined in Python). | ||
|
|
||
| ``stylesheet = allaboutme.rts`` tells rinohtype to use a particular | ||
| stylesheet, which we need to create now as our final step:: | ||
|
|
||
| [STYLESHEET] | ||
| name=My custom style sheet | ||
| base=sphinx | ||
|
|
||
| [emphasis] | ||
| font_color=#f00 | ||
|
|
||
| [strong] | ||
| font_color=#0f0 | ||
|
|
||
| Here we told rinohtype to inherit from the built-in ``sphinx`` | ||
| stylesheet, and apply RGB colours to *emphasis* and *strong* elements. | ||
|
|
||
| Rebuild the PDF to check that your changes have taken effect. As well as the | ||
| new colours, you should see that the new PDF is more compact than the previous | ||
| version, with fewer blank pages. This is because we're now using rinohtype's | ||
| ``article`` template, rather than the default ``book`` - ``book`` is more | ||
| suited to much longer material, laid out as a traditional book. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| .. _tutorial: | ||
|
|
||
| Tutorial | ||
| ======== | ||
|
|
||
| This tutorial is intended to provide a practical introduction to using | ||
| rinohtype. | ||
|
|
||
| It uses Sphinx to create a multi-page document, that rinohtype renders | ||
| as a PDF, complete with customised templates and styling. | ||
|
|
||
| Work through the tutorial step-by-step. Each step builds on the previous one, | ||
| and introduces you to a concept, tool or process in rinohtype. | ||
|
|
||
|
|
||
| .. toctree:: | ||
| :maxdepth: 1 | ||
|
|
||
| install | ||
| content | ||
| customisation | ||
| configuring-stylesheet |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.