I want to create a beamer pdf presentation from a RMarkdown file.
I would like to add speaker notes to some slides and set options for these notes (to be printed or not when you print the presentation).
These speaker notes typically show on the speaker's computer when he is presenting on a screen but never show on the slides.
Is that possible? How can I do that?
Possible workaround, but unfortunately not purely markdown
Adapted from DanielEWeeks's GitHub.
01. Add the following to the YAML section
header-includes:
- \setbeameroption{show notes}
02. and add notes as
## This is a slide
this is (markdown) text in slide
\note{
this is a note (does not understand markdown and
and wont work in other outputs formats (such
as ioslides or Slidy
}
## Next Slide
Notes will look like:
03. you would then have to knit the document twice, changing the YAML header-includes to
header-includes:
- \setbeameroption{hide notes}
in order to create the pdf without notes.
By default, Rmarkdown will overwrite the previously created document, so you might need to:
create notes pdf-document.
change name of notes pdf-document.
change YAML section.
create presentation pdf-document.
Hopefully there is a better way that I don't know about.
I was wondering how to do this when using a pptx output. This is how:
::: notes
This is a speaker note.
- Use basic Markdown
- like this list
- *and inline formatting*
:::
Reproduced from here.
Related
I guess my question is a potential if not probable duplicate of How to use inline R code in a bookdown theorem or example environment. It's been nearly 3 years since this question was asked, so a refresh might be welcome in any case, all the more given #YiHui's comment: "That is not possible with bookdown (at least for now)"?
Background: I am trying to use #YiHui bookdown package to produce a book with lecture slides (see creating accompanying slides for bookdown project). A key feature for this purpose is to be able to use conditional formatting, such as eval = (out_type=="beamer"). The issue I am facing is therefore to be able to add code chunks or inline R code inside bookdown custom environments (see https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#theorems and https://bookdown.org/yihui/bookdown/custom-blocks.html). I would love to get the following to compile properly. Is there a solution? Would a hook work (see https://yihui.org/knitr/hooks/)? There is a hack that works for forcing pandoc to parse inside a latex environment, but i do no think it applies here. Would a lua filter work (I have no idea how to use this)?
En passant, I am also surprised to see $\digamma$ showing up properly in the html output, but not in the pdf output, though it is parsed correctly in the tex file. The amssymb package is loaded and it's supposedly defined in there - what am I missing?
Much appreciated any help on this. Here is a MWE - I just edited chapter 4 from the default bookdown project. You can simply replace the contents of the file 03-method.Rmd with the following:
# Methods
We describe our methods in this chapter.
So here is a theorem to prove 1+1 = `r 1+1`.
```{theorem, echo=TRUE}
we want to show that in R, 1+1 = 2.
We also wonder why `$\digamma$` ($\digamma$) not showing.
Shows in the html output only, not pdf.
But when I recompile the tex file produced by bookdown - shows up just fine!!
Indeed, is defined correctly from `\usepackage{amssymb}`.
```
```{proof, echo=TRUE}
- If I am not mistaken, I cannot get an Rmarkdown style list to work either in the proof environment.
- Well, this is where i would like to be able to use inline code.
- we use r to compute 1+1: `r 1+1`.
- Does not work.
- Just shows verbatim inline code.
```
With the current development version of bookdown:
remotes::install_github('rstudio/bookdown')
you can write theorems in Pandoc's fenced Divs, e.g.,
# Methods
We describe our methods in this chapter.
So here is a theorem to prove 1+1 = `r 1+1`.
::: {.theorem}
we want to show that in R, 1+1 = 2.
We also wonder why `$\digamma$` ($\digamma$) not showing.
Shows in the html output only, not pdf.
But when I recompile the tex file produced by bookdown - shows up just fine!!
Indeed, is defined correctly from `\usepackage{amssymb}`.
:::
::: {.proof}
- If I am not mistaken, I cannot get an Rmarkdown style list to work either in the proof environment.
- Well, this is where i would like to be able to use inline code.
- we use r to compute 1+1: `r 1+1`.
- Does not work.
- Just shows verbatim inline code.
:::
However, please note that this new syntax is not supported for beamer output yet.
Is there any way to take a Bookdown project, and build it as Markdown instead of HTML or TeX?
I ask because I need to post-process the final Markdown output from Bookdown, in order to extract R and Python notebooks for download.
In more detail, I am using Bookdown to build a textbook that embeds notebooks to download, where the notebooks contain subsets of the code and text in the bookdown .Rmd files. For example, a single chapter could contain more than one notebook.
In order to do this, I put start and end comment markers in the RMarkdown input text to identify the section that will be a notebook, and then post-process the generated Markdown files to extract the notebook section. As in something like:
<!--- notebook: first_section.Rmd
-->
Some explanation, maybe using Bookdown extra markup such as #a_citation.
```{r}
a <- 1
a
```
<!--- end of notebook
-->
More markdown.
```{r}
# More code not in notebook.
b <- 2
```
Obviously I could use the input RMarkdown pages, but this would be ugly, because all the extended Bookdown markup such as citations, cross-references and so on, would appear in raw and ugly form in the generated notebook. So I'd really like to be able to get the final output Markdown, after merging, resolving of citations and cross references. Is there any way of doing that?
My question is similar to this as-yet unanswered question, but adds my motivation for an official solution to this problem.
With the latest version of bookdown on CRAN, you can use the output format bookdown::markdown_document2, e.g.,
output:
bookdown::markdown_document2:
base_format: rmarkdown::md_document
variant: gfm
I want to divide my Rmarkdown document like in picture. One column for the first section then two columns in the other sections.
used \onecolumn and \twocolumn but each section is created in a single page. Is there a solution to fix it?
This article has been published in a journal of the AMS. Fortunately, the rticle package supports the AMS journals. I use the standard template as generated by RStudio, change layout in the YAML header and use fancyhdr to redefine the pagestyle:
layout: twocol
header-includes:
- \usepackage{fancyhdr}
- '`\fancypagestyle{plain}{\fancyhf{}\fancyfoot[C]{\thepage}\renewcommand{\headrulewidth}{0pt}}`{=latex}'
I then get the following result:
As an alternative, you could try to adapt the revtex LaTeX class as used by the APS.
Note: I am using a quite recent version of pandoc, which makes the quoting of LaTeX complicated. With older versions of pandoc you might get away without the quoting.
I writing a Word document with R markdown in R Studio. I can get many things, but at the moment I am not figuring out how can I get a page break. I have found solutions but only for rendered latex / pdf document that it is not my case.
Added: To insert a page break, please use \newpage for formats including LaTeX, HTML, Word, and ODT.
https://bookdown.org/yihui/rmarkdown-cookbook/pagebreaks.html
Paragraph before page break.
\newpage
First paragraph on a new page.
Previously: There is a way by using a fifth-level header block (#####) and a docx template defined in YAML.
After creating headingfive.docx in Microsoft Word, you select Modify Style of the Heading 5, and then select Page break before in the Line and Page Breaks tab and save the headingfive.docx file.
---
title: 'Making page break using fifth-level header block'
output:
word_document:
reference_docx: headingfive.docx
---
In your Rmd document, you define reference_docx in the YAML header, and now you can use the page-breaking #####.
Please see below.
https://www.r-bloggers.com/r-markdown-how-to-insert-page-breaks-in-a-ms-word-document/
With the help of John MacFarlane and others on the pandoc google group, I put together a filter that does this. Please see:
https://groups.google.com/forum/#!topic/pandoc-discuss/FzLrhk0vVbU
In short, the filter needs to look for something to replace with the openxml for pagebreak. In this case
\newpage
is being replaced with
<w:p><w:r><w:br w:type=\"page\"/></w:r></w:p>
This allows for a single latex markup to be interpreted for both pdf and word output.
Joel
What you are trying to do is force a "page break" or "new page" in a word document generated with Pandoc. I have found a way to do this in my environment but I'm not sure it will work in every environment.
My environment:
* R-studio / Pandoc / MS-WORD starting with an "*.Rmd" file and generating a DOCX file.
In my RMD file the key idea is that i've created what acts like a TEMPLATE document (MyFormattingDocument.docx) and in that word document I tweak the STYLES for things like "Heading 1" and/or "Heading 2" and or "footnote" or whatever other predefined styles I want to tweak.
(SEE THIS: http://rmarkdown.rstudio.com/word_document_format.html#style-reference ) for explanation of style reference and how to set the header information in your RMD file to specify a reference document.
SOOOO in my case... i tweak the "Heading 1" style in WORD to include a forced "Page Break Before" in the Paragraph formatting for "Heading 1". Exactly how you force every "Heading 1" to always "Page Break" is different in different versions of Microsoft WORD but if you follow the WORD documentation and modify the "Heading 1" style THEN every "Heading 1" will always have a pagebreak before it.
THEN... you save this template file in the some directory you're working from with the RMD file... and it is USED AS a template. THE CONTENTS of the file are ignored.... so don't worry... you can put sample text in this file and test that the formatting all works.... THE CONTENTS ARE IGNORED but the STYLES are USED in the new word document which will be built by the RMD file so.... then every "Heading 1" will have a break before it.
NOTE: You could obviously do the same with ANY style that has a one-to-one mapping from PANDOC MARKUP so you could instead just make all "Heading 3" or whatever.... just look at see in your RMD created DOCX what "STYLE" is being applied and then tweak that style even if you need to insert some "fake" lines with essentially blank content just for the purpose of forcing a style to appear in the DOCX
Here is an R script that can be used as a pandoc filter to replace LaTeX breaks (\pagebreak) with word breaks, per #JAllen's answer above. With this you don't need to compile a pandoc script. Since you are working in R Markdown I assume one has R available in the system.
#!/usr/bin/env Rscript
json_in <- file('stdin', 'r')
lat_newp <- '{"t":"RawBlock","c":["latex","\\\\newpage"]}'
doc_newp <- '{"t":"RawBlock","c":["openxml","<w:p><w:r><w:br w:type=\\"page\\"/></w:r></w:p>"]}'
ast <- paste(readLines(json_in, warn=FALSE), collapse="\n")
ast <- gsub(lat_newp, doc_newp, ast, fixed=TRUE)
write(ast, "")
Save this as page-break-filter.R or something like that and make it executable by running chmod +x page-break-filter.R in the terminal.
Then include this filter the R Markdown YAML like so:
---
title: "Title
author: "Author"
output:
word_document:
pandoc_args: [
"--filter", "/path/to/page-break-filter.R"
]
---
You can use the R package worded. This avoids the need for a template word file. See https://github.com/davidgohel/worded.
The output parameter needs to be set to worded::rdocx_document and you need to call library(worded).
---
date: "2018-03-27"
author: "David Gohel"
title: "Document title"
output:
worded::rdocx_document
---
```{r setup, include=FALSE}
library(worded)
```
You can then add <!---CHUNK_PAGEBREAK---> to your document whenever you want a page break.
The package allows various word formatting options using a similar mechanism.
When updating to R 4.0.0, the <!---CHUNK_PAGEBREAK---> solution was not working any more for me.
Instead I could use the run_pagebreak() function from the officer package, still in combination with the officedown package:
---
output: word_document
---
```{r settings}
library(officedown)
library(officer)
```
Hello world on page 1
`r run_pagebreak()`
Hello world on page 2
R Markdown 1.16 introduced a new feature which allows to insert a page break by adding a paragraph that contains only the commands \pagebreak or \newpage:
Paragraph before page break.
\pagebreak
First paragraph on a new page.
See also the pagebreaks section in the R Markdown cookbook.
It is not an automated solution. But I have been adding the text '#####page break' to my markdown document. Then in MS Word using find-replace to replace the text "page break" with "^m" (manual page break).
Sungpil's article was close, but didn't quite work. This was the best solution I found for this:
https://scriptsandstatistics.wordpress.com/2015/12/18/rmarkdown-how-to-inserts-page-breaks-in-a-ms-word-document/
Even better, the author included the Word template to make this work. The R-blogger's link to his template is broken, and the header is formatted wrong. Some notes I took:
1) You might need to include the whole path to the word template in your Rmd header, like so:
output:
word_document:
reference_docx: C:/workspace/myproject/mystyles.docx
2) The template at the link above changed some of the default style settings so you'll need to change them back
My solution is not very robust but can work for some of us.
Assuming you need a page break before each level 1 title in your word document, I defined this in the format template used in the yaml field reference_docx: .
In this document you modify the Heading 1 format (or equivalent) to insert a page break before the Title. Do not forget to start your template with the first docx rendered with knitr (pandoc) in RStudio.
Ok, I found this in the markdown docs.
Horizontal Rule / Page Break
Three or more asterisks *** or dashes ---.
I'm trying to come up with a good system for generating slides and accompanying handouts. The ideal system would have the following properties:
beautiful in both presentation (PDF/HTML) and handout (PDF) layouts (handouts should have room for taking notes)
embedded R chunks, figures, other JPG/PNG pictures, etc.
easy to compose
build using command-line tools
bibliography support
pandoc slide separator format (automatically generate a new slide after headers of a specified level) is preferred
I can live with a little bit of additional processing (e.g. via sed), but would prefer not to write a huge infrastructure
two-column layouts: there is a SO post on how to get multi-column slides from pandoc, but it is LaTeX- rather than HTML-oriented.
ability to adjust sizes of embedded images (other than R-generated figures) and column widths on the fly
Here's what I've discovered so far about the various options:
Slidify:
doesn't do pandoc slide separator format, although there is a workaround
the suggestion for creating handouts is to print to PDF; I'd like to leave room for notes etc. (I could probably figure out a way to do that using something like PDFtk or psnup ...)
RStudio presentations (.Rpres files):
does lots of things nicely, including multi-columns with specified widths
doesn't support pandoc slide separator format
I can't figure out what's going on under the hood. There is RStudio documentation that describes the translation process for regular HTML, but it doesn't seem to cover the R presentation format (which isn't quite the same). (I have previously invested some effort in figuring out how to get RStudio-like output via pandoc ...), which means I can't generate slides etc. from the command line.
RStudio's Development Version (as of March 2014) comes bundled with Pandoc and version 2 of rmarkdown. It addresses many of the above issues with the .Rpres format.
pandoc: may be the only markdown-translator that has features such as footnotes, bibliography support, etc.. I can also use pandoc to generate LaTeX using the tufte-handout class, which meets my criteria of beauty.
Unfortunately, it seems not to have built-in two-column format support. Yihui Xie's HTML5 example doesn't show any two-column examples, and it claims (on slide 5) that clicking the "Knit HTML" button in RStudio is equivalent to pandoc -s -S -i -t dzslides --mathjax knitr-slides.md -o knitr-slides.html, but it doesn't seem to be ...
LaTeX/beamer: I could simply compose in Rnw (knitr-dialect Sweave) rather than R markdown to begin with. This would give me ultimate flexibility ...
despite many years of LaTeX use I do find LaTeX composition more of a pain than markdown composition.
After all that, my specific question is: what's the best (easiest) way to generate a two-column layout for HTML output?
Any other advice will also be appreciated.
This is an old Q, but I was recently plagued by a similar question, here's what I found:
Using the RPres format, two columns can be specified like so (details). Note that RPres can only be converted to HTML by clicking a button in RStudio, there doesn't seem to be any command line method, which is a bit annoying. Despite, that I'd say it is currently the simplest and most flexible method for getting slide columns with markdown:
===
Two Column Layout
===
This slide has two columns
***
```{r, echo=FALSE}
plot(cars)
```
Some flexibility is afforded by adjusting the column proportions:
===
Two Column Layout
===
left: 30%
This slide has two columns
***
```{r, echo=FALSE}
plot(cars)
```
With rmarkdown we can get two columns, but with no control over where the break is, which is a bit of a problem:
---
output: ioslides_presentation
---
## Two Column Layout {.columns-2}
This slide has two columns
```{r, echo=FALSE}
plot(cars)
```
We can also mix markdown and LaTeX in an Rmd file using the beamer_presentation format in RStudio to get two columns like this, but can't run any code in either column, which is a limitation:
---
output: beamer_presentation
---
Two Column Layout
-------
\begin{columns}
\begin{column}{0.48\textwidth}
This slide has two columns
\end{column}
\begin{column}{0.48\textwidth}
If I put any code in here I get an error, see
https://support.rstudio.com/hc/communities/public/questions/202717656-Can-we-have-columns-in-rmarkdown-beamer-presentations-
\end{column}
\end{columns}
Seems like a regular Rnw LaTeX doc is the best way to get columns if you want to use LaTex, not this markdown hybrid (cf. two column beamer/sweave slide with grid graphic)
In all of the above an image can be placed in an column.
The slidify website has instructions on making two columns here: http://slidify.org/customize.html but it's not clear what has to go into the assets/layouts folder to make it work
You can use fenced_divs notation or ::: to create columns or `Two Content layout'. See also this page to know more about the notation.
## Slide With Image Left
::: columns
:::: column
left
::::
:::: column
right
```{r your-chunk-name, echo=FALSE, fig.cap="your-caption-name"}
knitr::include_graphics("your/figure/path/to/the-image.pdf")
#The figure will appear on the right side of the slide...
```
::::
:::
Since pandoc 2+, which supports the notation, was implemented in RStudio v1.2+, you may need to install RStudio v1.2+ first. The installation is easy enough (at least in my case); just download and install RStudio v1.2+. In the way of installation, the former version of RStudio on your computer will be replaced with the new one without uninstalling it manually.
The ::: notation can be used even when you knit .Rmd files with beamer_presentation option, as well as when you create HTML slides. So we don't have to neither mix markdown and LaTeX notation in one file, nor add additional codes any longer: just knit the file as you knit other .Rmd with other options.
I now have what I think is a reasonable solution that should apply at least to ioslides-based solutions, and maybe (?) to other HTML5-based formats. Starting here, I added
<style>
div#before-column p.forceBreak {
break-before: column;
}
div#after-column p.forceBreak {
break-after: column;
}
</style>
to the beginning of my document; then putting <p class="forceBreak"></p> within a slide with {.columns-2} breaks the column at that point, e.g.
## Latin hypercube sampling {.columns-2}
- sample evenly, randomly across (potentially many) uncertain parameters
<p class="forceBreak"></p>
![](LHScrop.png)
[User:Saittam, Wikipedia](https://commons.wikimedia.org/wiki/File:LHSsampling.png#/media/File:LHSsampling.png)
There may be an even better way, but this isn't too painful.
#ChrisMerkord points out in comments that
.forceBreak { -webkit-column-break-after: always; break-after: column; }
worked instead (I haven't tested ...)
I got an idea from HERE, the basic solutions was:
### Function *inner_join*
. . .
`<div style="float: left; width: 50%;">`
``` {r, echo = FALSE, results = 'markup', eval = TRUE}
kable(cbind(A,B))
```
`</div>`
`<div style="float: right; width: 50%;">`
```{r, echo = TRUE, results = 'markup', eval = TRUE}
inner_join(A,B, by="C")
```
`</div>`
There is a workaround for beamer error.
In short: Error is related to pandoc conversion engine, which treats everything between \begin{...} and \end{...} as TeX. It can be avoided by giving new definition for begin{column} and end{column} in yaml header.
Create mystyle.tex and write there:
\def\begincols{\begin{columns}}
\def\begincol{\begin{column}}
\def\endcol{\end{column}}
\def\endcols{\end{columns}}
In the Rmd file use these new definitions
---
output:
beamer_presentation:
includes:
in_header: mystyle.tex
---
Two Column Layout
-------
\begincols
\begincol{.48\textwidth}
This slide has two columns.
\endcol
\begincol{.48\textwidth}
```{r}
#No error here i can run any r code
plot(cars)
```
\endcol
\endcols
And you get:
So far I haven't been able to do better than hacking my own little bit of markup on top of the rmd format: I call my source file rmd0 and run a script including this sed tidbit to translate it to rmd before calling knit:
sed -e 's/BEGIN2COLS\(.*\)/<table><tr><td style="vertical-align:top; width=50%" \1>/' \
-e 's/SWITCH2COLS/<\/td><td style="vertical-align:top">/' \
-e 's/END2COLS/<\/td><\/tr><\/table>/' ...
There are a few reasons I don't like this. (1) It's ugly and special-purpose, and I don't have a particularly good way to allow optional arguments (e.g. relative widths of columns, alignment, etc.). (2) It has to be tweaked for each output format (e.g. if I wanted LaTeX/beamer output I would need to substitute \begin{columns}\begin{column}{5cm} ... \end{column}\begin{column}{5cm} ... \end{column}\end{columns} instead (as it turns out I want to ignore the two-column formatting when I make LaTeX-format handouts, so it's a little easier, but it's still ugly).
Slidify may yet be the answer.
Not a direct solution, but Yihui's Xaringan package https://github.com/yihui/xaringan/ works for me. It's based on remark.js. In the default template, you can use .pull-left[] and .pull-right[] . Example: https://slides.yihui.name/xaringan/#15. You only need a minimum tweak on the existing .rmd files.