Skip to content
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

Tabsets don't appear in ToC #1336

Open
Romain-B opened this issue May 9, 2018 · 17 comments
Open

Tabsets don't appear in ToC #1336

Romain-B opened this issue May 9, 2018 · 17 comments
Labels
feature a feature request or enhancement theme: tabsets related to tabsets feature in rmarkdown

Comments

@Romain-B
Copy link

Romain-B commented May 9, 2018

It appears that when headers are put in tabset format, they don't appear in the table of contents.
Even stranger : when there are subheaders inside the tabsets, these will appear in the toc, but there will be no separation or distinction between the subheaders of different tabs

---
title: Hello World
output: 
  html_document:
    toc: TRUE
    toc_float: true
    toc_depth: 4
---

# My header {.tabset}

## Tab 1
### subheader1
### subheader2

## Tab 2

### subheader1
### subheader2

image

@rich-iannone rich-iannone self-assigned this May 9, 2018
@rich-iannone rich-iannone added bug an unexpected problem or unintended behavior Difficulty: Intermediate labels Jun 18, 2018
@rich-iannone rich-iannone removed the bug an unexpected problem or unintended behavior label Jul 17, 2018
@pat-s
Copy link

pat-s commented May 9, 2019

Just came across this. Making sure it doesn't get forgotten 🚀

@toothpicky
Copy link

Any solution to this?

@ars17psu
Copy link

I am using rmarkdown v1.16 and knitr v1.25. I am experiencing the same behavior as the above reported question. Have there been any updates to this?

@atusy
Copy link
Collaborator

atusy commented Nov 13, 2019

Here's a tricky workaround

---
title: Hello World
output: 
  html_document:
    toc: TRUE
    toc_float: true
    toc_depth: 4
---

```{css}
.tabset h2 {display: none;}
```

# My header  {.tabset}

<h2>Tab 1</h2>

## Tab 1

### subheader1

### subheader2

<h2>Tab 2</h2>

## Tab 2

### subheader1

### subheader2

image

@cderv
Copy link
Collaborator

cderv commented Nov 13, 2019

@atusy this is great ! However, tabpanel is trickier as I don't think the toc will allow to navigate in the headers that are inside the tabbed panel. In my case it doesn't. Does it work for you ?
I think it would need to activate the correct tab (show) when one of the header in the panel is clicked. I am looking into JS to see if this is possible - that would complete your trick I guess.
From what I saw up to now, it is not so easy to get the TOC to work with tabbed content.

@atusy
Copy link
Collaborator

atusy commented Nov 13, 2019

@cderv You are right. My trick just shows ToC whose links are out of order. We need one (?) more trick by JS! Thanks for your help.

@cderv
Copy link
Collaborator

cderv commented Nov 13, 2019

I also think this should be looked into after #1260 when bootstrap upgrade is done because it will change some things. Maybe bs4 will also help with this.

@dschneiderch
Copy link

the stackoverflow link didn't work for me so i'm definitely still waiting for a solution for this! the previous sort-of workaround without navigation is better than nothing though so thanks @atusy

@atusy
Copy link
Collaborator

atusy commented Jan 10, 2021

I made some hacks. With files below, you can navigate to tabsets from floating ToC.

https://gist.github.com/atusy/4b076cc084d9e920b34d6d25f85e5176

@atusy
Copy link
Collaborator

atusy commented Jan 14, 2021

I think the above trick needs lots more improvements which is still difficult for me.

Alternatively, I implemented the feature in minidown::mini_document.
Install it with remotes::install_github("atusy/minidown") and follow the directions at

https://minidown.atusy.net/#tabset

Feed backs are welcome!

@cderv
Copy link
Collaborator

cderv commented Jan 14, 2021

I think the above trick needs lots more improvements which is still difficult for me.

What are the improvement to be made ? What makes it more difficult to support here than in minidown ?
Do you want to discuss it in a PR ? (as if we were not already late on your previous ones 😅 )

Great package by the way ! There are a lot of great feature in your mini_document ! It is a really nice addition to the ecosystem ! 👍

@atusy
Copy link
Collaborator

atusy commented Jan 14, 2021

@cderv

Tow major difficulties are:

  1. Navigation to the hidden tab from the ToC requires clicking twice. I tried anchor.click(); anchor.click();, but no luck.
  2. Navigation to tabs when their name are not unique. Current implementation navigates to the last tab.

Anyway, let's draft and discuss the PR.

Great package by the way ! There are a lot of great feature in your mini_document ! It is a really nice addition to the ecosystem ! 👍

Thanks a lot! I'm so glad to hear it!!

@januz
Copy link

januz commented Apr 18, 2021

Is it likely that this feature will be implemented? I have a template that builds on bookdown::html_document2() and would like to avoid trying to rewrite it using minidown :)

@atusy
Copy link
Collaborator

atusy commented Apr 18, 2021

Sorry, I have no ideas...

@cderv cderv added feature a feature request or enhancement theme: tabsets related to tabsets feature in rmarkdown labels Jan 12, 2022
@jefferys
Copy link

jefferys commented Nov 8, 2024

Is this likely to ever get fixed given the shift to Quarto by ... Posit? It's pretty old at this point!

It still seems to be relevant, i.e for RMD to html output, when # 1 - Top heading {.tabset} is specified in the RMD document, then sub-headings ## 1.1 - A sub heading tab and ## 1.2 - Another sub heading tab will show as tabs, but unless I'm missing something there is no setting that will get these to also show in a toc: TRUE table of contents. Adding (fragile) html throughout the document is not what I would consider a good workaround.

My desire for this to work is based on being a fan of in-document folding and similar structures. Complex documents are better when they allow complexity hiding. Part of that involves support for hierarchical content and interactive reading. A "tabset" might not be the best way to do that, but I'm not aware of other simple alternatives.

@yihui
Copy link
Member

yihui commented Nov 8, 2024

Sorry, but I'm afraid that this issue looks so complicated that there may not be much hope to get it resolved. It shouldn't have been so complicated if we kept the JS dependencies simple and lightweight from the beginning... Last year, I wrote some simple JS code to generate tabsets: https://yihui.org/en/2023/10/section-tabsets/ In theory, it can be used on any HTML page, but unfortunately, rmarkdown is a hairball to some extent that's hard to untangle (#2084). In particular, currently there's no way to disable tabsets, otherwise you could use my JS code to generate tabsets and the headings should appear in TOC as expected.

I totally understand the value of in-document folding. If you also happen to be a fan of minimalism like myself (which I think is unlikely to most people), you may consider joining my new adventure, namely litedown. Below is a an example:

---
title: Hello World
output: 
  litedown::html_format:
    meta:
      css: ["@default", "@article", "@tabsets"]
      js: ["@tabsets", "@sidenotes"]
    options:
      toc: true
knit: litedown:::knit
---

# My header {.tabset}

## Tab 1

### subheader 1

### subheader 2

## Tab 2

### subheader 3

### subheader 4
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement theme: tabsets related to tabsets feature in rmarkdown
Projects
None yet
Development

No branches or pull requests