Add or remove "References" in TOC at end of each chapter in bookdown::gitbook - yaml

I am compiling a bookdown::gitbook and want to include a "References" header for each chapter in the TOC.
Currently, I have included a level 2 header titled "References" at the end of each chapter which appears in the TOC, however in-text there are two "References" headers: my level 2 header and a (level 3?) header which gets added once you build the book.
I want a (linked) References header in the TOC, and I only want one header in the text. I assume the options include:
Add the automatically included (level 3?) header to the TOC, or
Remove the level 3 header altogether, and just use my own level 2 header.
Is there a way to achieve either of these 2 points? I think I would prefer a solution to option 2, so that then the name and formatting of the header may be changed (font, colour, size etc) in line with the rest of the level 2 headers in the book.
This is a screenshot of my book. The header underlined in red is the level 2 header I have included, and the one circled in cyan is the level 3(?) one which is automatically added (as you can see it is slightly smaller than the one underlined in red).
I have recreated the issue with the demo book from here https://bookdown.org/yihui/bookdown/get-started.html, and have tried the following:
To include the level 3 header in the TOC
https://stackoverflow.com/a/69545034/13478749
header_includes:
- \usepackage[nottoc,numbib]{tocbibind}
This had no effect.
To include the level 3 header in the TOC
https://stackoverflow.com/a/51575615/13478749
bookdown::render_book("index.Rmd", "bookdown::gitbook", output_options=list(toc_bib = TRUE))
This had no effect.
So I thought I could at least try and change the name of the automatic level 3 header using this in the YAML, but it resulted in an error.
https://stackoverflow.com/a/64276396/13478749
---
reference-section-title: Referencias
---
Error in vapply(idx2, character(1), FUN = function(i) head(nms[idx > i], :
values must be length 1,
but FUN(X[[8]]) result is length 0
Calls: <Anonymous> ... <Anonymous> -> <Anonymous> -> split_chapters -> vapply
Execution halted
Exited with status 1.
But if I include an empty string as the new title, there is no error, but the level 3 "References" header remains (I assume R ignores reference-section-title because it is empty).
---
reference-section-title: ' '
---
And this answer https://stackoverflow.com/a/51494840/13478749 (and the cited bookdown documentation https://bookdown.org/yihui/bookdown/citations.html) refers to the name of the final chapter in the book, which you add in yourself as a level 1 header anyway, rather than the automatically-added level 3 header at the end of each chapter.
if (knitr::is_html_output()) '# Literatur {-}'

Related

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

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?

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

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?

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

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

Resources