RMarkdown ! Undefined control sequence - latex

I am writing my PhD thesis in RMarkdown. Everything was rendering fine yesterday, today I added a few pieces of text with one reference (deleting it does not change the error message) and now, I get this error message:
! Undefined control sequence. ...9}\selectfont {\global
\setmainfont
{DejaVu Sans}{}} l.3593 ...nt{\global\setmainfont{DejaVu Sans}{}}}}
& \multicolumn{3}{!{\colo...
The document consists of several child documents. I managed to track the error to one of the child documents by switching the individual child chunks off and on in the main document. BUT the line the error refers to seems to be from A DIFFERENT child document. All of the child documents knit OK when I try them separately.
I can get rid of the error when I use xelatex as the pdf engine but I would prefer to stick with pdflatex because of compatibility with some R packages.
My YAML:
title: ''
output:
pdf_document:
latex_engine: pdflatex
number_sections: TRUE
pandoc_args: ['--lua-filter=section-bibliographies.lua']
always_allow_html: true
geometry: "left = 4cm, right = 2cm, top = 2cm, bottom = 2cm"
fontsize: 11pt
header-includes:
- \usepackage{float}
- \usepackage{sectsty}
- \usepackage{paralist}
- \usepackage{setspace}\spacing{1.5}
- \usepackage{fancyhdr}
- \usepackage{lastpage}
- \usepackage{dcolumn}
- \usepackage{natbib}
- \usepackage[nottoc, numbib]{tocbibind}
- \usepackage{ragged2e}
- \usepackage{pdflscape}
- \usepackage{textgreek}
- \usepackage{graphicx}
- \usepackage{titlesec}
classoption: twoside
bibliography: library.bib
reference-section-title: References
section-bibs-level: 2
citation_package: biblatex
csl: journal-of-ecology.csl
Any suggestion will be much appreciated!

Related

Error running filter multiple-bibliographies.lua

I am trying to run a Lua filter for multiple bibliographies to create a separate list of references for each chapter of my thesis.
This is my YAML header:
title: ''
output:
pdf_document:
latex_engine: pdflatex
number_sections: TRUE
pandoc_args: --lua-filter=multiple-bibliographies.lua
always_allow_html: true
geometry: "left = 4cm, right = 2cm, top = 2cm, bottom = 2cm"
fontsize: 11pt
header-includes:
- \usepackage{float}
- \usepackage{sectsty}
- \usepackage{paralist}
- \usepackage{setspace}\spacing{1.5}
- \usepackage{fancyhdr}
- \usepackage{lastpage}
- \usepackage{dcolumn}
- \usepackage{natbib}
- \usepackage[nottoc, numbib]{tocbibind}
- \usepackage{ragged2e}
- \usepackage{pdflscape}
- \usepackage{textgreek}
- \usepackage{graphicx}
classoption: twoside
bibliography_Intro: Intro.bib
bibliopgraphy_ch1: Endozoochory.bib
bibliopgraphy_ch2: Vysevovy_clanek.bib
bibliopgraphy_ch3: Seeds.bib
bibliopgraphy_ch4: Landscape.bib
citation_package: biblatex
csl: journal-of-ecology.csl
At the end of each chapter I have:
## References
::: {#refs_Intro}
:::
I am not very experienced with pandoc and LaTeX so this might be a simple error on my side. However, when I try to knit the document, it gives me an error:
Error running filter multiple-bibliographies.lua: PandocFilterError
"pandoc" "Could not find executable pandoc" stack traceback:
multiple-bibliographies.lua:50: in upvalue 'run_citeproc'
multiple-bibliographies.lua:82: in function
<multiple-bibliographies.lua:68> Error: pandoc document conversion
failed with error 83
I've been struggling with the bibliographies for several days and I think this is the last option but I am open to other possibilities in RMarkdown.
I am running this on Ubuntu 20, pandoc version 2.19.2, rmarkdown_2.18, R version 4.2.2
The problem is that the filter tries to call pandoc, but cannot find it, as it does not check the environment variables set by RStudio. This is fixed in the updated version of this filter, multibib, which uses some newer pandoc features to work around this. The new version can also be installed as a Quarto extension.
Note, however, the slightly changed syntax used in multibib, as everything must now be nested below the bibliography key:
---
bibliography:
Intro: Intro.bib
ch1: Endozoochory.bib
ch2: Vysevovy_clanek.bib
ch3: Seeds.bib
ch4: Landscape.bib
---
Please also try the section-bibliographies filter, which might be a better fit for your use-case.

Latex in document referencing via Varioref is not working in Rmarkdown

I've been using vanilla latex documents for a long time and have recently switched over to Rmarkdown. I'm struggling to get varioref to work, or any in-document referencing for that matter. See below example Rmarkdown file contents. I've tried to make it a minimally reproducible example.
---
title: "vref"
output:
pdf_document:
keep_tex: true
latex_engine: pdflatex
header-includes: \usepackage{varioref}
---
Please see \vref{section}
\newpage
\section{This is a section} \label{section}
It seems like the reference is being created with a clickable link, but there is no reference to the section being created..
Rmarkdown producing unnumbered sections has nothing to do with varioref. You can make them numbered like this:
---
title: "vref"
output:
pdf_document:
keep_tex: true
latex_engine: pdflatex
header-includes:
- \usepackage{varioref}
- \setcounter{secnumdepth}{4}
---
Please see \vref{section}
\newpage
\section{This is a section} \label{section}

Fancyhead for unnumbered appendix in R Markdown knit to pdf

A question about fancyhdr in R Markdown knitting to pdf.
Can anyone help me to fix the header for the appendix? I have numbered sections in the document, and the fancyhead for pages with the numbered sections is oke. But for the unnumbered appendix, it keeps showing the last numbered section, where I just want the title of the current unnumbered appendix to be shown. Code example below. Thanks!
---
title: "Example"
output:
pdf_document:
number_sections: true
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
---
\newpage
# Chapter
\newpage
# Appendix {-}
You can adjust the header like this:
---
title: "Example"
output:
pdf_document:
number_sections: true
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
---
\newpage
# Chapter
\newpage
# Appendix {-}
\markboth{something here}{something there}

Modify footline in Beamer - R Markdown

I'm actually using the CambridgeUS theme for my Beamer using RMarkdown.
output:
beamer_presentation:
theme: "CambridgeUS"
header-includes:
- \usepackage{color}
- \usepackage{amsmath}
- \setbeamertemplate{navigation symbols}{}
I wanna know how to delete the date in the footline and how to change the value taken as the full name (author) to only take last name.
It's possible using only tex as here but I don't succeed using RMarkdown.
Do you already face this issue ?
To remove the date from the footline, you could specify en empty optional argument in \date[]{\today}.
To show only the last name in the footline, define a short version for the author: \author[Smith]{Jack Smith}
\documentclass{beamer}
\usetheme{CambridgeUS}
\date[]{\today}
\author[Smith]{Jack Smith}
\begin{document}
\begin{frame}
abc
\end{frame}
\end{document}
The identical code also works in rmarkdown:
---
output:
beamer_presentation:
theme: "CambridgeUS"
header-includes:
- \setbeamertemplate{navigation symbols}{}
- \date[]{\today}
- \author[Smith]{Jack Smith}
---
test

Incorrect conversion from R Markdown to LaTeX

Why does the following R Markdown minimal (non)-working example not compile to PDF?
---
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \lhead{}
- \chead{}
- \rhead{The performance of new graduates}
- \lfoot{From: K. Grant}
- \cfoot{To: Dean A. Smith}
output:
pdf_document:
keep_tex: yes
latex_engine: xelatex
---
# Test
In particular, the problematic conversion happens to -\lfoot{From: K. Grant} and -\cfoot{To: Dean A. Smith}, as seen in the output .tex file:
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{The performance of new graduates}
true
true
For some reason, both of these lines are converted to true causing
LaTeX error: Missing \begin{document}
thereby preventing the document from compiling to PDF.
Changing \lfoot and \cfoot to just about anything else seems to lead to them being converted correctly. So what's going on here? I take it that there must be a problem with either knitr or pandoc in the conversion process.
NB: I'm not too familiar with R Markdown, and this is a follow-up question to Headers and footers created in Fancyhead not shown in PDF on TeX.SX on Tom's behalf.
The : character is the problem. pandoc seems to be trying to parse the header-includes content as if it were variables, and : is used to separate variables and values. It compiles if you quote the lines in question (don't forget, then, to escape the leading backslash)
---
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \lhead{}
- \chead{}
- \rhead{The performance of new graduates}
- "\\lfoot{From: K. Grant}"
- "\\cfoot{To: Dean A. Smith}"
output:
pdf_document:
keep_tex: yes
latex_engine: xelatex
---
# Test
Stitching the answer here with trial and error, I found that only by deleting the title key and using YAML pipe-denoted multiline string syntax would it compile:
---
output:
pdf_document:
keep_tex: yes
latex_engine: xelatex
header-includes: |
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\lhead{My Title}
\rhead{My Note}
\lfoot{\today}\rfoot{Page \thepage}
---
I recommend using pandoc's raw_attribute feature (enabled by default) to mark the raw LaTeX section as such. This is the most robust solution.
header-includes: |
```{=latex}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\lhead{My Title}
\rhead{My Note}
\lfoot{\today}\rfoot{Page \thepage}
```

Resources