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

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...

Related

Is there a way to restart figure numbering in Sphinx?

I have a set of three related documents in Sphinx (4.2.0). The top-level table of contents looks like this:
.. toctree::
:maxdepth: 2
Requirements_Specification/index.rst
User_Guide/index.rst
Release_Report/index.rst
In conf.py, I have:
numfig = True
numfig_secnum_depth = 1
This numbers all the figures and tables consecutively across the three documents. For example, if there are 10 figures in each document, then:
the figures in the Requirements Specification doc are numbered 1 to 10
the figures in the User Guide doc are numbered 11 to 20
the figures in the Release Report doc are numbered 21 to 30.
Instead, I would like the numbering to start at 1 in each doc, so in this example each doc would have figures numbered 1 to 10. Is there some way of achieving this?
I've tried putting :numbered: in the toctree directive, but that treats each doc as a chapter (i.e. Requirements Specification is chapter 1, User Guide is chapter 2, Release Report is chapter 3). I need each doc to be able to stand alone. I build the docs both as one set of HTML and also as three separate PDFs.

Reporting Multiple Values & Sorting

Having a bit of an issue and unsure if it's actually possible to do.
I'm working on a file that I will enter target progression vs actual target reporting the % outcome.
PAGE 1
¦NAME ¦TAR 1 %¦TAR 2 %¦TAR 3 %¦TAR 4 %¦OVERALL¦SUB 1¦SUB 2¦SUB 3¦
¦NAME1¦ 114%¦ 121%¦ 100%¦ 250%¦ 146%¦ 2¦ 0¦ 0%¦
¦NAME2¦ 88%¦ 100%¦ 90%¦ 50%¦ 82%¦ 0¦ 1¦ 0%¦
¦NAME3¦ 82%¦ 54%¦ 64%¦ 100%¦ 75%¦ 6¦ 6¦ 15%¦
¦NAME4¦ 103%¦ 64%¦ 56%¦ 43%¦ 67%¦ 4¦ 4¦ 24%¦
¦NAME5¦ 87%¦ 63%¦ 89%¦ 0%¦ 60%¦ 3¦ 2¦ 16%¦
Now I already have it sorting all rows by the Overall % column so I can quickly see at a glance but I am creating a second page that I need to reference points.
So on the second page I would like to somehow sort and reference different columns for example
PAGE 2
TOP TAR 1¦Name of top %¦Top %¦
TOP TAR 2¦Name of top %¦Top %¦
Is something like this possible to do?
Essentially I'm creating an Employee of the Month form that automatically works out who has topped what.
I'm willing to drop a paypal donation for whoever can figure this out for me as I've been doing it manually every month and would appreciate the time saved
I don't think a complicated array formula is necessary for this - I am suggesting a fairly standard Index/Match approach.
First set up the row titles - you can just copy and transpose them from Page 1, or use a formula in A2 of Page 2 like
=transpose('Page 1'!B1:E1)
The use them in an index/match to get the data in the corresponding column of the main sheet and find its maximum (in C2)
=max(index('Page 1'!A:E,0,match(A2,'Page 1'!A$1:E$1,0)))
Finally look up the maximum in the main sheet to find the corresponding name:
=index('Page 1'!A:A,match(C2,index('Page 1'!A:E,0,match(A2,'Page 1'!A$1:E$1,0)),0))
If you think there could be a tie for first place with two or more people getting the same score, you could use a filter to get the different names:
So if the max score is in B8 this time (same formula)
=max(index('Page 1'!A:E,0,match(A8,'Page 1'!A$1:E$1,0)))
the different names could be spread across the corresponding row using transpose (in C8)
=ArrayFormula(TRANSPOSE(filter('Page 1'!A:A,index('Page 1'!A:E,0,match(A8,'Page 1'!A$1:E$1,0))=B8)))
I have changed the test data slightly to show these different scenarios
Results

Access original unmodified user text in custom directive

I'd like to use a custom directive to wrap certain table cells in a preformatted block.
For example, suppose I want to write documentation for my exciting new calculator:
.. Calculator-Operations:: sign examples
You'll love how great this awesome calculator is.
Check out these exciting innovations!
========= ==========
you type result
========= ==========
+ 1 1
- 1 -1
* 1 ERROR!
/ 1 ERROR!
I can retrieve each table cell node in my directive's implementation, but the node has already been processed by Sphinx (of course), so the first three cells are treated as bulleted lists.
I'd like the generated document to behave as if I had surrounded each "you type" cell with double backticks. I could accomplish this if I could retrieve the raw text of the node or if I could prevent Sphinx from transforming this particular node. (I could also accomplish this by parsing the entire block's content myself, but that sounds unpleasant.)
What is the best way of transforming the original, untransformed user input in these cells?

Formula for calculating dynamic UITableView sections

Greetings StackOverflow.
I have a scenario, in which I have a UITableView with a dynamic amount of sections.
This means that the table may have 1 section, 5 sections, 100 sections, whatever.
The problem is, each section is handled and displayed in a different manner.
Section 0, for example, contains say a list of purple cells, while section 1 contains yellow cells.
Thus, I need to be able to calculate the index that each section type will end up as.
By this, I mean, assuming the priority of the sections is as follows:
Magenta, Yellow, Green, White
Then when all sections are filled, they will be in that order, M=0, Y=1, G=2, W=3.
However, when one section is missing, say Yellow, the result is as follows:
M=0, Y=-1, G=1, W=3
Thereby removing yellow from the list, and bumping down the indices for the section.
I have already built something that accomplishes this for small section sizes by using tertiary statements, but as it defines each section type manually it quickly blows out of proportion:
// Here be some dragons.
// Each macro identifies a section
#define SectionMagenta (([self shouldDisplaySection:0])?0:-1) // 1 tertiary statements
#define SectionYellow (([self shouldDisplaySection:1])?((SectionMagenta==-1)?0:1):-1) // 3 tertiary statements
#define SectionGreen (([self shouldDisplaySection:2])?((SectionMagenta==-1)?((SectionYellow==-1)?0:1):((SectionYellow==-1)?1:2)):-1) // 11 tertiary statements
#define SectionWhite (([self shouldDisplaySection:3])?((SectionMagenta==-1)?((SectionYellow==-1)?((SectionGreen==-1)?0:1):((SectionGreen==-1)?1:2)):((SectionYellow==-1)?((SectionGreen==-1)?1:2):((SectionGreen==-1)?2:3))):-1) // 63 tertiary statements
There is a pattern here. A very complex one, yes, but a pattern none the less.
My question to you all, is if you can simply this pattern into a small, probably recursive function, that I pass in the priority of the section, and it calculates the destination index.
OR
if you can create a much simpler method of achieving what I need.
For the latter, simply setting the amount of rows displayed to 0 is not sufficient, as the padding for the section is still existent.
I've provided a helper function–as can be seen in the copypasta code above-to check if a section should be displayed: [self shouldDisplaySection:n]
That may very well provide all you need.
Sounds like you actually want to use an Ordered Dictionary and just push the values you're wanting onto it, then read them off in order with the numeric indexes as your section order.
A fairly good example of an ordered dictionary implemented in Obj-C is at http://cocoawithlove.com/2008/12/ordereddictionary-subclassing-cocoa.html

Is there a name for this type of page navigation?

Just out of curiosity, is there a name for the kind of navigation I've been working on?
It looks like this:
<<first <previous 1 2 3 4 5 [...] 20 next> last>>
i.e. navigation where you've got x pages, but you don't want to show x links, you want to limit the amount of space taken up, so you show y links at a time, and indicate the existence of the other pages with an elision.
At some point in the middle, it would look like this:
<<first <previous [...] 8 9 10 11 12 [...] 20 next> last>>
with elisions on both sides.
Answering to just clear up this question. I hereby declare that it has no official name.
I also hereby make up the name 'elided pagination' for it.
It's called web pagination, search result pagination.
thresholded navigation pager?
Not sure what the ordinary version of this pagination scheme is called (if anything).
However, I came up with an advanced version of it capable of handling very large numbers of pages (where ellipses (...) skip successively larger blocks of pages as you get further away from either the current page or the endpoints).
I called my scheme "Logarithmic pagination" or "Logarithmic page navigation".
You can find it (with implementation) on stackoverflow here.

Resources