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

No toc generated with output: md_document #1216

Closed
stla opened this issue Dec 12, 2017 · 10 comments
Closed

No toc generated with output: md_document #1216

stla opened this issue Dec 12, 2017 · 10 comments
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@stla
Copy link

stla commented Dec 12, 2017

Hello,

I've tried the latest CRAN version and the dev version. While setting toc: true for a md_document, the table of contents is not generated.

---
title: "No toc"
author: "Stéphane Laurent"
date: "12 décembre 2017"
output:
  md_document:
    toc: true
    variant: markdown
    preserve_yaml: true
---


# Part 1

This is an R Markdown document. 

# Part 2

You can also embed plots.
@stla
Copy link
Author

stla commented Dec 12, 2017

I can get the toc by doing
render("myfile.Rmd", md_document(variant="markdown", toc=TRUE, preserve_yaml = TRUE, pandoc_args="--template=toctemplate.txt"))
with the toctemplate.txt file

$toc$

$body$

@yihui yihui added this to the v1.9 milestone Dec 12, 2017
@yihui
Copy link
Member

yihui commented Dec 12, 2017

Did this work before but stopped working recently? If not, please see #1211. We cannot support it unless Pandoc supports it.

@yihui yihui closed this as completed Dec 12, 2017
@stla
Copy link
Author

stla commented Dec 12, 2017

Yes, this worked before. This is what I always used for my Hakyll blog.
Pandoc supports it, it suffices to have the template I posted.

@stla
Copy link
Author

stla commented Dec 12, 2017

I've looked at #1211
This is not the problem here:

> rmarkdown::pandoc_version()
[1] ‘1.19.2.1’

@stla
Copy link
Author

stla commented Dec 12, 2017

I've tried with the default variant.
This generates a TOC:

output:
  md_document:
    toc: true

But this doesn't generate a TOC:

output:
  md_document:
    toc: true
    preserve_yaml: true

There's something abnormal.

@stla
Copy link
Author

stla commented Dec 12, 2017

The smoking gun is here, in the md_document function:

  # base pandoc options for all markdown output
  args <- c(if (variant != "markdown" && !preserve_yaml) "--standalone")

Looks like Pandoc does not generate the TOC if there isn't the option --standalone.

@stla
Copy link
Author

stla commented Dec 12, 2017

I've tried to understand why you remove --standalone.

This generates the TOC:
render("bugtocmd.Rmd", md_document("markdown", preserve_yaml=TRUE, toc=TRUE, pandoc_args="--standalone")) but the YAML block is duplicated.

This generates the TOC and the YAML block is not duplicated:
render("bugtocmd.Rmd", md_document("markdown", preserve_yaml=FALSE, toc=TRUE, pandoc_args="--standalone"))

Thus, when variant=markdown, the YAML block is preserved if there is the option --standalone.

Therefore I would propose this solution, but I have not seriously tested it:

# base pandoc options for all markdown output
args <- if (variant != "markdown" || preserve_yaml) "--standalone"
.......
# add post_processor for yaml preservation
  if (preserve_yaml && variant != "markdown") {
    ......

yihui added a commit that referenced this issue Dec 12, 2017
@yihui
Copy link
Member

yihui commented Dec 12, 2017

Okay, I'll take a look at your proposal soon.

@yihui yihui reopened this Dec 12, 2017
@yihui yihui added the bug an unexpected problem or unintended behavior label Dec 13, 2017
@yihui yihui closed this as completed in 08c7567 Dec 13, 2017
@yihui
Copy link
Member

yihui commented Dec 13, 2017

Should be fixed now. Thanks for the report and investigation!

@github-actions
Copy link

github-actions bot commented Nov 3, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants