Derek Sonderegger
Derek Sonderegger

Reputation: 901

Creating R Bookdown book with duplicate sub-section names - Works but ToC always links to first instance

I have created several books using bookdown and each chapter has an "Exercises" sub-section. Previously, bookdown would append a '-1' or '-2' to the duplicate section labels, but the resulting output would only show the "Exercises" and the link would work correctly.

Now, the webpage ToC links all the repeated labels to the first chapter with an "Exercises" sub-section.

I know there is is a

options(knitr.duplicate.label = "allow")

that will allow duplicate chunk names, but I can't find a way to allow for duplicate section labels.

I know I can fix this by just renaming each chapter exercises to something unique, but I'd like to avoid that.

Upvotes: 1

Views: 158

Answers (1)

Derek Sonderegger
Derek Sonderegger

Reputation: 901

A solution I found was to modify the label as follows

## Exercises {#A-Unique-Label-Exercises}

This allows me to have the reader just see Exercises, but I add a unique label that can be as long and annoying as I want.


An addendum from the bookdown developer:

This is a bug introduced in the last version of bookdown, which has been fixed in the current development version. You may try:

remotes::install_github('rstudio/bookdown')

Upvotes: 3

Related Questions