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

rmarkdown 内置的 Pandoc Filter 脚本不支持 beamer 幻灯片输出 #1815

Closed
3 tasks done
XiangyunHuang opened this issue May 1, 2020 · 5 comments
Closed
3 tasks done

Comments

@XiangyunHuang
Copy link

XiangyunHuang commented May 1, 2020

问题

rmarkdown 自带的两个 lua 脚本 rmarkdown:::pandoc_lua_filters() 对 html 和 pdf 输出自动加持了,但是对 beamer 幻灯片没有启用,感觉有点奇怪(beamer 的输出也是 pdf 呀),一个暗黑的做法是在输出格式的地方如下传递 Pandoc 的参数

pandoc_args: !expr c("--lua-filter", list.files(rmarkdown:::pandoc_lua_filters(), full.names = T)[1])

但是,是不是可以也自动支持一下?

动机

beamer 主题通常自定了很多 block,有了 Pandoc 的 lua 脚本外挂,不需要额外增加上面那个魔法

可重复的例子

---
title: "R Markdown 制作 beamer 幻灯片"
author: "xx"
date: "`r Sys.Date()`"
documentclass: ctexbeamer
output: 
  bookdown::pdf_book: 
    number_sections: yes
    toc: no
    base_format: rmarkdown::beamer_presentation
    latex_engine: xelatex
    citation_package: natbib
    keep_tex: no # yes for debug
    template: null
    theme: Verona 
    pandoc_args: !expr c("--lua-filter", list.files(rmarkdown:::pandoc_lua_filters(), full.names = T)[1])
themeoptions: 
  - colorblocks
biblio-style: plainnat
link-citations: yes
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

## 设置主题 {#sec:setup-verona}
 
Ivan Valbusa 开发了 [Verona 主题的 Beamer 模版](https://bitbucket.org/rivanvx/beamer),
目前 CTAN 上的版本是 0.2,文档说明见 <https://www.ctan.org/pkg/beamer-verona>
这个主题的宏包依赖很少!我很喜欢!

```r
tinytex::tlmgr_install('beamer-verona')
```


## 自定义的块 {#sec:custom-blocks}

::: {.exampleblock data-latex="{提示}"}
提示
:::

::: {.alertblock data-latex="{警告}"}
警告
:::

::: {.block data-latex="{注意}"}
请读者注意
:::

运行环境

xfun::session_info(c('rmarkdown','tinytex','knitr'))
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 8 (Core), RStudio 1.2.5033

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.25    evaluate_0.14    glue_1.4.0       graphics_3.6.3   grDevices_3.6.3  highr_0.8        htmltools_0.4.0  jsonlite_1.6.1  
  knitr_1.28.5     magrittr_1.5     markdown_1.1     methods_3.6.3    mime_0.9         Rcpp_1.0.4.10    rlang_0.4.5.9000 rmarkdown_2.1.3  stats_3.6.3     
  stringi_1.4.6    stringr_1.4.0    tinytex_0.22.2   tools_3.6.3      utils_3.6.3      xfun_0.13        yaml_2.2.1      

Pandoc version: 2.9.2

我想对运行环境应该没什么特殊要求,不一定要上面的开发版

运行输出

输出是一个 PDF 文件,见

beamer-verona.pdf


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.

@yihui yihui closed this as completed in 75bbbcc May 28, 2020
@yihui
Copy link
Member

yihui commented May 28, 2020

之前忘记加了。现在已经加上。谢谢!

@yihui
Copy link
Member

yihui commented May 30, 2020

我撤销了这个,因为我发现 Pandoc 自己有一些特殊环境,如 https://pandoc.org/MANUAL.html#incremental-lists 这些不能翻译为 LaTeX 环境(::: incremental 不能翻译为 \begin{incremental})。

如果你的幻灯片中不存在 Pandoc 默认支持的那些幻灯片环境(如 incremental/notes 等),那你可以自己启用我们的支持,不过你的语法不太对:

    pandoc_args: !expr c("--lua-filter", list.files(rmarkdown:::pandoc_lua_filters(), full.names = T)[1])

应该是:

    pandoc_args: !expr rmarkdown:::pandoc_lua_filters("latex-div.lua")

@XiangyunHuang
Copy link
Author

@yihui 确实,你的解决方案更好

yihui added a commit that referenced this issue Jun 29, 2020
…eamer_presentation

this should be safe with b2cff70 now, because Pandoc's built-in Div's for beamer won't be affected---our Div's require the data-latex attribute
@yihui
Copy link
Member

yihui commented Jun 29, 2020

我又重新加上了,但要注意 ::: {} 里面 data-latex 属性是必需的(你的例子里都有了),这样 rmarkdown 的 Lua 过滤器才不会干涉 Pandoc 的内置环境。

jonathan-g added a commit to jonathan-g/rmarkdown that referenced this issue Jul 7, 2020
* rstudio/master: (61 commits)
  make metadata available before running pre_knit (rstudio#1855)
  fix rstudio#1815: apply the lua filters pagebreak.lua and latex-div.lua to beamer_presentation
  require the data-latex attribute on fenced Div's again: rstudio#1779 (comment)
  start the next version
  CRAN release v2.3
  fold any code blocks with the class `foldable` for html_document output (rstudio#1835)
  fix rstudio#1828: add aria-hidden = "true" to empty <a> tags in highlighted code blocks generated by Pandoc to improve screen reader accessibility (rstudio#1833)
  add a news item for rstudio#1832
  roxygenize
  no need to turn on --file-scope or actually write the split content into files if the split content is of length < 2
  eliminate renumber_footnotes option
  only test two pandoc versions (devel and RStudio version) and upgrade default to 2.7.3 (rstudio#1846)
  close rstudio#1838: test more R versions on Travis (rstudio#1845)
  renumber_footnotes output format option
  add the <div class="kable-table"> only when the output format is HTML, otherwise the div will be converted to a LaTeX environment, leading to the bug https://stackoverflow.com/q/62340425/559676
  change name of file_scope argument to references_scope
  re-roxygenize
  Add `publish_site()` function for "one-button" publishing of R Markdown websites.
  Enable use of pandoc --file-scope for input files originating from multiple Rmds (rstudio#1837)
  Added missing lang attribute to ioslides_presentation template (rstudio#1841)
  ...
@github-actions
Copy link

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 Dec 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants