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

raw_attribute in header-includes #1729

Closed
3 tasks done
rstub opened this issue Dec 9, 2019 · 4 comments
Closed
3 tasks done

raw_attribute in header-includes #1729

rstub opened this issue Dec 9, 2019 · 4 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@rstub
Copy link
Member

rstub commented Dec 9, 2019

With rmarkdown version 1.18 the one can no longer use the raw_attribute extension when specifying a header-includes:

---
output: 
  pdf_document:
    keep_tex: yes
header-includes:
- |
  ```{=latex}
  \newcommand{\foobar}[1]{Foo#1Bar}
  ```    
---

```{=latex}
\foobar{Baz}
```

The ccontent of header-includes is copied verbatim to the TeX file which leads to a

! LaTeX Error: Missing \begin{document}.

It works when one uses the more conventional

header-includes:
- \newcommand{\foobar}[1]{Foo#1Bar}

However, the pandoc manual actually advertises the use of raw-headers in the meta data block.

Note: This is motivated by trying to answer https://stackoverflow.com/questions/59245638/latex-error-environment-threeparttable-undefined. It seems the papaja package uses raw-headers.

xfun::session_info('rmarkdown')
#> R version 3.6.1 (2019-07-05)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Debian GNU/Linux bullseye/sid
#> 
#> Locale:
#>   LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>   LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>   LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>   LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>   LC_ADDRESS=C               LC_TELEPHONE=C            
#>   LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> Package version:
#>   base64enc_0.1.3  digest_0.6.23    evaluate_0.14    glue_1.3.1      
#>   graphics_3.6.1   grDevices_3.6.1  highr_0.8        htmltools_0.4.0 
#>   jsonlite_1.6     knitr_1.26       magrittr_1.5     markdown_1.1    
#>   methods_3.6.1    mime_0.7         Rcpp_1.0.3       rlang_0.4.2     
#>   rmarkdown_1.18.5 stats_3.6.1      stringi_1.4.3    stringr_1.4.0   
#>   tinytex_0.17     tools_3.6.1      utils_3.6.1      xfun_0.11       
#>   yaml_2.2.0      
#> 
#> Pandoc version: 2.5

Created on 2019-12-09 by the reprex package (v0.3.0)


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('rmarkdown'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/rmarkdown').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@cderv
Copy link
Collaborator

cderv commented Dec 9, 2019

I think this relates to the change in 5499ec6 to fix #1359 regarding how header-includes is processed.
it seems with this change, we loose the raw-attribute feature for header-includes...
Indeed papaja is using raw attributes in headers
https://github.com/crsh/papaja/blob/29e6cb0437f96d571943bdd27df2eb18b6a50e47/R/apa6_formats.R#L506

papaja could also adapt to the new rmarkdown header processing as header-includes is now processed as verbatim by rmarkdown but I am not sure it is a good idea to override pandoc feature through rmarkdown. here header-includes yaml field is no longer processed by pandoc, but process by rmarkdown to be included as command line argument instead.

not sure what is the best choices here... 🤔

If I may @crsh, I add you to this discussion as you are the author of papaja and also the one who opend issue #1359 in the first place.

@yihui
Copy link
Member

yihui commented Dec 9, 2019

I became aware of this problem while working on another issue (rstudio/rticles#257) last week. I think I'm in a dilemma now. Comparing this issue with #1359, I feel the latter is worse and harder to fix, so I tend to say that we'll have to drop the support for raw blocks in header-includes.

I'll think more about it. Thanks for the report!

@yihui yihui added the bug an unexpected problem or unintended behavior label Dec 11, 2019
@yihui yihui closed this as completed in 61fe2f8 Dec 11, 2019
@yihui
Copy link
Member

yihui commented Dec 11, 2019

I just pushed a fix for this problem (by removing ```{=latex} before writing the header content into a file). Thanks for the report!

yihui added a commit that referenced this issue Dec 11, 2019
@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

3 participants