Setting theme options in YAML header for beamer presentation? - rstudio

I am making a beamer presentation in RStudio, using the Metropolis theme. I would like to use some options, say sectionpage = none, but I don't know where to put the option in the YAML header.
I just have the basics:
---
title: "TemplatePresentation"
author: "MightyMauz"
output:
beamer_presentation:
theme: metropolis
---
How can I pass metropolis theme options?

Use header-includes instead to declare what theme you want to use:
---
title: "TemplatePresentation"
author: "MightyMauz"
classoption: "portrait"
output: beamer_presentation
header-includes:
- \usetheme[sectionpage = none]{metropolis}
---

Related

How do I get amsmath to work in RMarkdown when knitting to PDF?

In RMarkdown, I have a document I want to knit to pdf. The document has equations for which I need automatic numbering. I had been using the $$ 1+1=2 \tag{1} $$ convention to write equations, but now want to switch to the \begin{equation} 1+1=2 \eq:this_eq \end{equation} convention so that I can have automatic numbering and easy cross referencing of the equations. The few online resources I've found make it seem like this should be fairly straightforward to do. For example here or here. However, I have run into no end of heartbreak in attempting to do it.
I am using version 3.4.3 with RStudio, the tinytex distribution, and have installed bookdown (which I am still not sure is really necessary to achieve my goal here). Here is a repex:
---
title: This title
author: "This guy"
date: "This date"
header-includes:
- \usepackage{amsmath}
output:
pdf_document:
toc: yes
toc_depth: '4'
df_print: kable
fig_caption: yes
latex_engine: xelatex
mainfont: Calibri Light
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Introduction
blah blah...
\begin{equation}
S = X \bar{P}
(\#eq:signals)
\end{equation}
## Later on
blah blah \#ref(eq:signals)
When I try to "knit to PDF" I am running into the error
! Package mathspec Error: `amsmath' must be loaded earlier than `mathspec'.
which has been reported as a bug and "fixed" here, but I am unable to understand the fix or to follow its instructions. What I'm asking for is a set of really clear steps that will get me to where I can run the repex above without incident.
Some things I've tried:
The same error occurs when I replace pdf_document with bookdown::pdf_document2. Or when I remove
header-includes:
- \usepackage{amsmath}
and instead put
includes:
in_header: preamble.tex
after the line latex_engine: xelatex, where "preamble.tex" is a notepad file containing the line \usepackage{amsmath}
The comments in this other SO post seem to suggest that it is not even necessary to say anything about amsmath in the YAML options, which confuses me even more. When I remove any mention of amsmath from the YAML options, I get errors saying that the mathjax script is not recognized, for example:
! Package amsmath Error: \bar allowed only in math mode.
When I try your example, the equation is not labelled successfully.
Then I replace the output setting as bookdown::pdf_book. It works.
---
title: This title
author: "This guy"
date: "This date"
output:
bookdown::pdf_book
mainfont: Calibri Light
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Introduction
blah blah...
\begin{equation}
S = X \bar{P}
(\#eq:signals)
\end{equation}
## Later on
blah blah \#ref(eq:signals)
For my problem, the solution came down to me just changing my latex engine from xelatex to lualatex. My document knit correctly and numbered my equations. For some reason, everywhere I looked they say one should use xelatex. Also I had header-includes: - \usepackage{amsmath} in the YAML header.
I was facing this issue. Thanks for the suggestions above. Here is what worked for me in the output and header-includes parts of the preamble:
output:
bookdown::pdf_book:
latex_engine: lualatex
header-includes:
- \usepackage{amsmath}

Use custom citation style in markdown using YAML header

I am trying to use a custom citation style in a markdown file, but the citation uses the default (Chicago) style each time I knit. I have tried changing the output format from a JS reveal presentation to an HTML document to a PDF document, but it still does not work. I am using the knitcitations package to cite using the document's DOI, and the bibliography() function to write the bibliography. I have also tried using the apa.csl style found on Zotero, yet the citation is still done in the default styple. The apa.csl file is stored in the same folder as the file that I am trying to use citations in, as is the newbiblio.bib file, in which I have stored the bibliographical information for the item I want to cite.
Below is my markdown code:
---
title: "htmlcitetest"
citation_package: natbib
csl: "apa.csl"
output:
pdf_document:
pandoc_args: ["--natbib"]
biblio-style: unsrt
bibliography: newbiblio.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(bibtex)
library(knitcitations)
options("citation_format" = "pandoc")
library(RefManageR)
cleanbib()
```
## R Markdown
- This is a citation [^1]
[^1]: `r citet("10.1098/rspb.2013.1372")`
```{r, message=FALSE}
bibliography()
```
This link (http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html)
says that I should be able to format my YAML header like this:
---
title: "Sample Document"
output: html_document
bibliography: newbiblio.bib
csl: apa.csl
---
However, when I do that, the file knits to a markdown (.md) file, but it is not processed into the output. I recieve this error:
pandoc-citeproc: 23:3-23:10: Expected end element for: Name {nameLocalName = "category", nameNamespace = Just "http://purl.org/net/xbiblio/csl", namePrefix = Nothing}, but received: EventEndElement (Name {nameLocalName = "info", nameNamespace = Just "http://purl.org/net/xbiblio/csl", namePrefix = Nothing})
pandoc: Error running filter /Applications/RStudio.app/Contents/MacOS/pandoc/pandoc-citeproc
Filter returned error status 1
Error: pandoc document conversion failed with error 83
Execution halted
The contents of my .bib file are:
#Article{Boettiger_2013,
doi = {10.1098/rspb.2013.1372},
url = {http://dx.doi.org/10.1098/rspb.2013.1372},
year = {2013},
month = {jul},
publisher = {The Royal Society},
volume = {280},
number = {1766},
pages = {20131372--20131372},
author = {C. Boettiger and A. Hastings},
title = {No early warning signals for stochastic transitions: insights from large deviation theory},
journal = {Proceedings of the Royal Society B: Biological Sciences},
}
I also do not understand why the biblio-style option in the YAML header does not to do anything. Essentially, all I need is a way to use a custom citation style I have already made with a markdown document. Any help would be greatly appreciated!
Without a reproducible example, it is hard to know exactly what is happening, but it looks like you are mixing two different configurations.
Method 1: Specifying a custom CSL file
The method of using a CSL file only works if you are using pandoc-citeproc. For example, I have downloaded the IEEE style, and saved it in the same directory as my RMarkdown file as ieee.csl. This MWE builds a separate bibliography file:
---
output: pdf_document
bibliography: test.bib
csl: ieee.csl
---
```{r}
knitr::write_bib(x = c("knitr", "rmarkdown") , file = "test.bib")
```
Some ref [#R-knitr]
Some again [#R-knitr]
Another ref [#R-rmarkdown]
# References
Method 2: Specifying styles in Natbib
If you want to use natbib to build the citations and bibliography, you have to use the biblio-style option. This following example should work without downloading anything:
---
output:
pdf_document:
citation_package: natbib
bibliography: test.bib
biblio-style: humannat
---
```{r}
knitr::write_bib(x = c("knitr", "rmarkdown") , file = "test.bib")
```
Some ref [#R-knitr]
Another ref [#R-rmarkdown]
# References
Unless you have a particular reason, I would probably go down the route of using pandoc-citeproc and a csl file. It integrates well with the RMarkdown world. Using Natbib just gets a bit more confusing, and from my experience is more prone to throwing errors.
I was having the same error message you are having (pandoc-citeproc: ParseError {errorContexts = [], errorMessage = "Failed reading: takeWhile1"...). And I discovered the solution conveying information from two other internet forums. Basically, the problem was that I had downloaded my custom citation "csl" file from GitLab in a way that it was an HTML version of the original raw xml file. I had to download the raw xml file instead. When I googled the error, I saw that many people was having the same issue.
Within Git-page, where you downloaded your "csl" file from, instead of clicking in the download button, you should right click in the "open raw" button, and then, "save link as". Then it should work.
In the below image, instead of clicking in button "1", right click in button "2" and save the link as:

How can I get RMarkdown to recognize both fontsize and mainfont when converting to PDF?

An Rmd file with the YAML headers:
---
title: "Untitled"
author: "Me"
date: "September 14, 2015"
output:
pdfdocument:
latexengine: xelatex
fontsize: 12pt
---
Correctly renders in 12 computer modern roman when converted to PDF in RStudio. If I add mainfont:
---
title: "Untitled"
author: "Me"
date: "September 14, 2015"
output:
pdfdocument:
latexengine: xelatex
fontsize: 12pt
mainfont: Helvetica
---
The PDF is rendered in Helvetica, but at 10 point. I can't get PDF output of 12pt non-CMR. Is there any way to do this?
I've also tried setting the YAML to 12pt and putting \usepackage{helvet} in an external .tex file that gets included in_header, but I get 12pt CMR.
I often encounter problems when trying to use Rmarkdown YAML commands to change font specs. For example, for me neither mainfont nor sansfont command worked to render in Helvetica, or maybe I just fail at figuring out the correct indentation in the YAML header. Besides, I guess you would need to give more information about which OS and R(markdown) Version you're using for someone to help you.
A solution that worked for me (64-bit Linux, R 3.1.2, Rmarkdown 0.7) using CTAN helvet package is this one (let me know it it works for you):
---
title: "Untitled"
author: "Me"
date: "September 14, 2015"
header-includes:
- \usepackage{helvet}
- \usepackage[T1]{fontenc}
- \renewcommand\familydefault{\sfdefault}
output:
pdf_document
fontsize: 12pt
---
I derived the solution from this post.

Set highlight-style from Pandoc YAML front-matter

Is it possible to set Pandoc's highlight-style option from the YAML front matter? It can be set via the pandoc command as a flag
--highlight-style=kate
But I don't see any mention of a highlight style digging through the Pandoc LaTeX template. Is this possible?
It looks like this is an open feature request: https://github.com/jgm/pandoc/issues/2925
If you are using Rmarkdown :
---
output:
beamer_presentation:
highlight: zenburn
pdf_document:
highlight: zenburn
---
FYI: I use rmarkdown->master but 1.9 should suffice and pandoc->master (2.1.3)

jekyll not generating _posts

I'm have trouble getting jekyll to convert a post in _posts directory to html. It generates index.md correctly, but doesn't generate anything for posts. When I add 'source: _posts' then it converts the post, but doesn't convert index.md.
As far as I can tell, 'source' should either be not added to _config.yml to should point to '.'
My directory structure is pretty standard:
$ find .|fgrep -v bootstrap
.
./index.md
./_config.yml
./_drafts
./_includes
./_includes/footer.html
./_includes/header.html
./_layouts
./_layouts/default.html
./_posts
./_posts/2013--02-25-test-blog.md
./_site
./_site/index.html
$ cat _config.yml
name: "Developer blog"
description: ""
url: "http://localhost:4000"
source: .
paginate: 10
markdown: rdiscount
permalink: pretty
pygments: true
auto: true
Even when I leave auto off, I see no stack traces.
$ cat _posts/2013--02-25-test-blog.md
---
layout: default
title: Testing a blog
---
#test blog
this is a test
_posts/2013--02-25-test-blog.md
This name is not correct.
Perhaps use this
_posts/2013-02-25-test-blog.md
Notice carefully only 1 hyphen after the year.

Resources