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

header-includes in beamer_presentation() is not working as with pdf_document() #2294

Closed
5 tasks done
samcarter opened this issue Jan 26, 2022 · 10 comments · Fixed by #2299
Closed
5 tasks done

header-includes in beamer_presentation() is not working as with pdf_document() #2294

samcarter opened this issue Jan 26, 2022 · 10 comments · Fixed by #2299
Labels
bug an unexpected problem or unintended behavior next to consider for next release theme: pandoc concerns upstream pandoc

Comments

@samcarter
Copy link

If beamer_presentation is specified as output, macros with an optional argument at the end get incorrectly parsed to tex. Take for example the following example with \setbeamertemplate{footline}[frame number] in the header-includes:

---
title: "**TITLE**"
subtitle: "Subtitle"
author: "Name"
institute: ""
date: January 25, 2022
output:
  beamer_presentation:
    keep_tex: true
header-includes:
  - \setbeamertemplate{footline}[frame number]
---

test

The resulting .tex file will have

\setbeamertemplate{footline}{[}frame number{]}

instead of

\setbeamertemplate{footline}[frame number]

If I change the output to something else, the macro will be parsed correctly:

---
title: "**TITLE**"
subtitle: "Subtitle"
author: "Name"
institute: ""
date: January 25, 2022
output:
  pdf_document:
    keep_tex: true
header-includes:
  - \usepackage{beamerarticle}
  - \setbeamertemplate{footline}[frame number]
---

test

I tested this with the following environment:

R version 4.1.1 (2021-08-10)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Big Sur 11.6.1, RStudio 2021.9.0.351

Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8

Package version:
  base64enc_0.1.3   bslib_0.3.1       digest_0.6.29     evaluate_0.14     fastmap_1.1.0     fs_1.5.2          glue_1.6.1        graphics_4.1.1   
  grDevices_4.1.1   highr_0.9         htmltools_0.5.2   jquerylib_0.1.4   jsonlite_1.7.3    knitr_1.37        magrittr_2.0.1    methods_4.1.1    
  R6_2.5.1          rappdirs_0.3.3    rlang_0.4.12      rmarkdown_2.11.12 sass_0.4.0        stats_4.1.1       stringi_1.7.6     stringr_1.4.0    
  tinytex_0.36      tools_4.1.1       utils_4.1.1       xfun_0.29         yaml_2.2.2       

Pandoc version: 2.17.0.1

Checklist

When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:

  • formatted your issue so it is easier for us to read?

  • included a minimal, self-contained, and reproducible example?

  • pasted the output from xfun::session_info('rmarkdown') in your issue?

  • upgraded all your packages to their latest versions (including your versions of R, the RStudio IDE, and relevant R packages)?

  • installed and tested your bug with the development version of the rmarkdown package using remotes::install_github("rstudio/rmarkdown")?

@cderv
Copy link
Collaborator

cderv commented Jan 26, 2022

I think this is an issue with Pandoc. I need to check with earlier version than 2.17.0.1

However, there should be not issue if you insert in the header by using raw attributes to tell pandoc to not Parse you content

header-includes:
  - | 
    ```{=latex}
    \setbeamertemplate{footline}[frame number]
    ```

An example is show in the Pandoc doc: https://pandoc.org/MANUAL.html#extension-yaml_metadata_block

It is best to write raw latex with this syntax when you can
https://bookdown.org/yihui/rmarkdown-cookbook/raw-latex.html

I'll look for the potential issue in pandoc though 🤔

@cderv cderv added the theme: pandoc concerns upstream pandoc label Jan 26, 2022
@samcarter
Copy link
Author

@cderv Thanks for the tip with the raw code!

(it also failed with pandoc 2.14, but the checklist in the issue templated required updating to the current version, so I moved to 2.17)

@cderv
Copy link
Collaborator

cderv commented Jan 26, 2022

It seems Pandoc will parse this

\setbeamertemplate{footline}[frame number]

as

\setbeamertemplate{footline}{[}frame number{]}

since as long as I can try (pandoc 2.0.3).

I don't think this i really an issue, as one should definitely use raw attribute to prevent any transformation

However, maybe an issue should be open in Pandoc ?

The reprex would be

❯ echo "\setbeamertemplate{footline}[frame number]" | pandoc -t native
[ Para
    [ RawInline (Format "tex") "\\setbeamertemplate{footline}"
    , Str "[frame"
    , Space
    , Str "number]"
    ]
]`

we see that the part in bracket is not parsed as a rawInline. Hence the result.

Using raw attribute makes sure it is

❯ pandoc -t native
`\setbeamertemplate{footline}[frame number]`{=latex}
^Z
[ Para
    [ RawInline
        (Format "latex")
        "\\setbeamertemplate{footline}[frame number]"
    ]
]

If that is ok with you I'll close the issue here, and one could be opened on Pandoc's side if this is really an issue.

@samcarter
Copy link
Author

@cderv Sure, you can close this issue. Thanks for your time in investigating this!

@samcarter
Copy link
Author

I asked this question over at pandoc and the different behaviour seems to be specific to rmarkdown as with pandoc, the macro will always be parsed incorrectly

No idea. With straight pandoc, you'll get the same result for this whether you do -t beamer or -t latex. So it shouldn't make a difference.

(jgm/pandoc#7867 (comment))

@cderv
Copy link
Collaborator

cderv commented Jan 27, 2022

Good catch. I did not pay attention to that in your question.

I have answered there: jgm/pandoc#7867 (comment)

In fact we are doing a different processing

rmarkdown/R/pdf_document.R

Lines 165 to 168 in b53a7ce

# make sure --include-in-header from command line will not completely
# override header-includes in metadata but give the latter lower precedence:
# https://github.com/rstudio/rmarkdown/issues/1359
args <- append_in_header(process_header_includes(metadata))

This was to fix an issue and I think we did not do the same for Beamer. I think we should.

See my comment on the other repo for why this causes the difference you see.

Thanks for getting to the bottom of this !

@samcarter
Copy link
Author

@cderv Thanks for your response! Would be really awesome if you could do the same for beamer.

@cderv cderv changed the title Parsing of macros with optional argument at the end in beamer_presentation header-includes in beamer_presentation() is not working as with pdf_document() Jan 27, 2022
@cderv cderv reopened this Jan 27, 2022
@cderv cderv added bug an unexpected problem or unintended behavior theme: pandoc concerns upstream pandoc next to consider for next release and removed theme: pandoc concerns upstream pandoc labels Jan 27, 2022
@cderv
Copy link
Collaborator

cderv commented Feb 1, 2022

This should work the same on both format now. Thanks !

@samcarter
Copy link
Author

@cderv Thanks a lot!!!

@github-actions
Copy link

github-actions bot commented Aug 2, 2022

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 Aug 2, 2022
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 next to consider for next release theme: pandoc concerns upstream pandoc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants