Can a list in Restructured Text (reST) extend section numbers? - python-sphinx

I have an RST document like this:
Introduction
------------
Some intro text.
Next Level Stuff
----------------
1. The first list item
2. The second list item
3. The third list item
I'm trying either a :numbered: toctree or .. sectnum:: to number the sections of my document, and have the numbered list inherit the section number. I'm trying to get a result like this:
1. Introduction
2. Next Level Stuff
2.1 The first list item
2.2 The second list item
2.3 The thirst list item
Is this structure supported in RST?

Related

how to select 2nd set of <ol> list with xpath

I'm trying to scrape the tips sections of these exercises but a lot of the pages are different resulting in a blank field.
The only thing they all have in common is that the tips are always in the 2nd oldered list. The 1st ordered list is the instructions. 2nd ordered list are the tips.
Here are some of the xpath that I have tried:
//ol (this selects both ordered lists)
//ol[2] (this doesn't work at all for some reason)
//h3[contains(text(),'​Exercise Tips:')]/following::ol (some of the pages it didn't pick up tips section)
//DIV[#class="field field-name-body field-type-text-with-summary field-label-hidden"]/DIV[1]/DIV[1]/OL[2] (again some of the pages it returned blank)
Link to the some of the exercises that the page are different:
https://www.muscleandstrength.com/exercises/one-arm-kettlebell-floor-press
https://www.muscleandstrength.com/exercises/overhead-tricep-extension.html
I would try //div[contains(#class, "exercise-tips")]//li/text().
Based on your example xpaths, you could use //div[contains(#class, "exercise-tips")]//ol if you truly want to select the ol element and not the text of the tips.
//ol[2] doesn't select any nodes because both ol nodes are the first ol child of their respective parents, not the second. (//ol)[2] does work, however. See https://stackoverflow.com/a/52166328/5225301 for more details.

asciidoc: source block aligned into nested list item

I'm trying to arrange tabulation.
I need a source block is nested block inside a nested list item:
list:
. Restore buckups
* List logical names:
+
RESTORE FILELISTONLY from DISK = '/var/opt/mssql/backup/xxxx.bak'
+
Sample output:
[source,options="nowrap"]
----
include::doc/samples/logical_names.out[]
----
* Another nested list element...
Currently, it appears as:
I need source block is arranged at the same level of nested list item.
Any ideas.
In your example source, the source block terminates the Sample output: paragraph. Since there is no continuation included, it also terminates the list item, and the list, because a source block is not a list item (by itself).
The solution is to include a continuation between the two elements:
Sample output:
+
[source,options="nowrap"]
Note that you'll need to add a blank line between the source block and the next list item, to provide a clear separation between the two.

Summing XML Data in MSWord Mail Merge

I have a report card written in Word that uses an XML file for its input. In the XML file, if a student remains in the same section all three trimesters there will be one node for that class; if they change sections at the trimester they'll have one node for each section. The nodes look something like this (greatly simplified):
<ReportCardSectionFB Abs1="2" Abs2="11" CourseID="ELMATH1" CourseTitle="Math" PeriodStart="3" TeacherName="Jones, Jennifer" TermCode="Year" SectionID="ELMATH1-4" />
<ReportCardSectionFB Abs1="1.50" Abs2="6" CourseID="ELMATH1" CourseTitle="Math" PeriodStart="3" TeacherName="Smith, Tina" TermCode="Year" SectionID="ELMATH1-3" />
There is no indicator within the XML as to which trimester the node belongs to.
In the Word document, we're pulling the absence data with the following mail merge command:
{MERGEFIELD "ReportCardSectionFB[#PeriodStart='3']/ #Abs1" \# 0.# \* MERGEFORMAT }
That's not working in this situation: it only gets the absence data from the first node it comes across, i.e.: 2.0. Is there a way to get the sum of #Abs1 for all period 3 classes, i.e.: 3.5? If not, is there a way to only get the last #Abs1 for period 3, i.e.: 1.5?
I recommend you to use this 3rd party product, which can use xml as input and is capable of merging it with MS Word template. I is also much more powerful than the built-in Word's mail merge. You can see some examples here.
You could also try summing the absences in Synergy - there's a new checkbox under AttDef1, 2, etc. that adds up all the absences for the data range - Include all day data for the entire date range regardless of section enrollment or section timeframe. That way the absences should be the same for each section, if that works for your district.
You can also try the SET function in Word to nest the MERGEFIELDS as bookmarks and use the Word operator functions to then add the bookmarks.

Can Sphinx Section Numbering Skip Certain Sections (like a title)?

I am making a series of design documents in Sphinx and I would like to include them together in a toctree and have the sections within the documents numbered. I know that I can use .. sectnum:: to number all sections in the child pages. However, Sphinx/rst numbers the title of the page (which is really just the first section) and the table of contents ends up looking like:
Table of Contents
1 Design the First
2 Design the Second
and each child page looks like:
1 Design the First
1.1 First Section
1.2 Second Section
What I want is a table of contents on my index page that just lists the title
Table of Contents
Design The First
Design the Second
and child page that look like
Design the First
1 First Section
2 Second Section
Is there a way to have a title that shows up in the TOC as well as on the top of a child page which does not end up being a numbered section?
I don't know what you ended up doing, but I wanted to do the exact same thing! I had the following setup:
index.rst
.. toctree::
assignment
library_api
I only wanted the assignment part to have numbers, so either could have done two separate toctree with one using :numbered:, or put at the top of the file
.. sectnum::
:start: 0
Giving of course the exact problem you mention -- my top-level title was Assignment Writeup, so that was 0 and everything below it in subsections was 0.x e.g.
Assignment Writeup
==================
First Task
----------
Second Task
-----------
gives
0. Assignment Writeup
0.1 First Task
0.2 Second Task
as it turns out, there's an easy hack you can do. It makes things more modular than probably desired, but "add a layer of indirection".
So now I have assignment.rst and assignment_writeup.rst. assignment.rst just basically has a title and a toctree:
Assignment Writeup
==================
.. toctree::
:maxdepth: 4
assignment_writeup
then take all sub-sections and put them in assignment_writeup and "upcast" their heading level. So I now take all subsections and make them sections, and subsub and make them sub.
.. sectnum::
:start: 0
First Task
==========
^^^ === instead of --- now
Second Task
===========
and we now finally have
Assignment Writeup
0. First Task
1. Second Task
kind of dubious, but this was the only way I could achieve it x0 I wonder what you did between asking this and now? Hopefully somebody will see this and benefit one day!
Note: this has undesireable side-effects. The Assignment Writeup shows up on its own page, with just Links to the indirect document. Not sure which is worse honestly...

Sphinx section numbering for more than level 3 headings: .. sectnum::

I am using Sphinx to generate pdf files from rst files. Sphinx automatically generates section numbers up to level 3 headings, as well as Table of Content up to this level. However, I want the headings at all levels being numbered and be in the TOC. In order to do that, I am trying to use .. sectnum:: (http://docutils.sourceforge.net/docs/ref/rst/directives.html#table-of-contents). The result is not exactly what I expected:
There is a number 1. being added in front of all section numbers in both TOC and text, that is, instead of 1, it's 1.1, instead of 2, it's 1.2.
In both TOC and text up to the third-level heading, the section numbers sort of get repeated, i.e. there is a section number (a correct one) in front of the wrong one (with 1. added in the front).
Here is my sample rst file:
.. sectnum::
level 1: the first party
========================
level 1 desc: this document is about xyz
level 2
-------
level 2 desc
level 3
~~~~~~~~
level 3 content
level 4
^^^^^^^^
level 4 content
level 5
''''''''
level 5 content jflkasjfslkajf
asdfsafs
level 1: the second part
========================
fjsdafjskalfjslkafjksaljflksaj
fasdhfkjsahfjkhdsf
level 2
-------
level 2 desc
level 3
~~~~~~~~
level 3 content
level 4
^^^^^^^^
level 4 content
level 5
''''''''
level 5 content jflkasjfslkajf
asdfsafs
Here is the result of TOC:
(I took a shot of my pdf file to show the result, but I just found out that I couldn't post images because I need 10 reputation for that, this is my first time posting anything)
1 1.1 level 1: the first party
1.1 1.1.1 level 2
2 1.2 level 1: the second part
2.1 1.2.1 level 2
Here is the result of the text:
1.1 LEVEL 1: THE FIRST PARTY
level 1 desc: this document is about xyz
1.1 1.1.1 level 2
level 2 desc
1.1.1 1.1.1.1 level 3
level 3 content
1.1.1.1.1 level 4
level 4 content
1.1.1.1.1.1 level 5
level 5 content jflkasjfslkajf asdfsafs
As you can see, there is 1. added to the section number, and there is a repeated part for the headings up to level 3.
Sphinx seems to take the view that the whole project is one document, and every .rst file is one chapter of it; you can indicate the order of the files in your main .. toctree:: . I guess that's why you get the numbers. I'm guessing it's a pretty common use case not to want .rst files numbered, though, so maybe someone should propose that.
By the way, note that Sphinx explicitly does not support sectnum. Instead, they recommend you use the :numbered: parameter in the top-level .. toctree::. (http://sphinx-doc.org/rest.html)
I try your code rendered to HTML and it works fine.
maybe you can consider HTML format.
In addition,
.. sectnum::
and
.. toctree::
:numbered:
I think they aren't different, depends on your design to choose.
just want subsection to be numbered: sectnum
entire project's heading with numbered (it will auto contain sub toctree) choose: toctree:: :number:
Learn more > toctree number

Resources