Footnotes and logo in Rmarkdown generated PDF - latex

I am trying to integrate footnotes AND a logo on the frontpage of a Rmarkdown generated PDF.
I try this:
---
title : "My report"
date : November 4th, 2022
author: "Author 1[^note1]"
documentclass : report
keep_tex : true
header-includes:
- \usepackage{titling}
- \pretitle{\begin{center}
\includegraphics[width=2in,height=2in]{logo.png}\LARGE\\}
- \posttitle{\end{center}}
output : pdf_document
---
[^note1]: Writing, Research, Editing
Inspired by this procedure to integrate the logo:
https://bookdown.org/yihui/rmarkdown-cookbook/latex-logo.html
And this for the footnotes:
https://stackoverflow.com/a/62514739/12398676
However, I am getting this error:
! Argument of \reserved#a has an extra }.
<inserted text>
\par
l.69 ...or 1\footnote{Writing, Research, Editing}}
Error: LaTeX failed to compile logo_footnote.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See logo_footnote.log for more info.
Execution halted
Anyone has an idea of what is going wrong?
EDIT: the solution provided by samcarter_is_at_topanswers.xyz
... is one step closer to the solution but not quite there.
I now have a logo and author name, but the author name is overlayed with the date
EDIT2: In the solution provided by samcarter_is_at_topanswers.xyz I get a similar display problem even without a logo
---
title : "My report"
date : November 4th, 2022
documentclass : report
keep_tex : true
header-includes:
- \AtBeginDocument{\author{Author 1\protect\footnote{Writing, Research, Editing}}}
output :
pdf_document:
keep_tex: true
---
test

You can work around the problem like this:
---
title : "My report"
date : November 4th, 2022
documentclass : report
keep_tex : true
header-includes:
- \AtBeginDocument{\author{Author 1\protect\footnote{Writing, Research, Editing}}}
- \usepackage{titling}
- \pretitle{\begin{center}
\includegraphics[width=2in,height=2in]{example-image-duck}\LARGE\par}
- \posttitle{\end{center}}
output :
pdf_document:
keep_tex: true
---
test

Related

Include by \input an header-includes: preamble in a markdown file

I have plenty of markdown files starting with a rather long header-includes, followed by some included directives:
---
header-includes:
- \usepackage{fvextra}
- \usepackage{tcolorbox}
- \DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,breakanywhere,breaksymbol=,breakanywheresymbolpre=,commandchars=\\\{\}}
- \usepackage[margins=raggedright]{floatrow}
title: "Mathématiques \n55. Les dérivées"
subtitle: ""
author: Marc Le Bihan
geometry: margin=2cm
fontsize: 12pt
output: pdf
classoption: fleqn
urlcolor: blue
---
\input{apprentissage-include}
where apprentissage-include.tex has such definitions:
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,breakanywhere,breaksymbol=,breakanywheresymbolpre=,commandchars=\\\{\}}
\newcommand{\donnee}[1]{\textbf{\textcolor{Purple}{#1}}}
\newcommand{\definition}[1]{\textbf{\textcolor{blue}{#1}}}
[...]
I would like to include the header-includes preamble too, to change its content more easily when updates are needed.
I've created an header-include.tex containing:
---
header-includes:
- \usepackage{fvextra}
[...]
---
But whatever I've tried :
\input{header-include}
\input{apprentissage-include}
or
---
\input{header-include}
---
\input{apprentissage-include}
I'm receiving the message :
! LaTeX Error: Can be used only in preamble.
Do I have a way to succeed?
As you are loading packages in the header-include.tex file it needs to go into the header. To get access to the latex syntax of \input{...}, you have to put it into the header includes:
markdown file:
---
output:
pdf_document:
keep_tex: true
header-includes:
- \input{header-include}
- \input{apprentissage-include}
title: "Mathématiques \n55. Les dérivées"
subtitle: ""
author: Marc Le Bihan
geometry: margin=2cm
fontsize: 12pt
classoption: fleqn
urlcolor: blue
---
test
The header-include.tex file needs to use latex syntax, so no - or any other markdown syntax
header-include.tex:
\usepackage{fvextra}
The apprentissage-include.tex file is the same as in your question
apprentissage-include.tex
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,breakanywhere,breaksymbol=,breakanywheresymbolpre=,commandchars=\\\{\}}
\newcommand{\donnee}[1]{\textbf{\textcolor{Purple}{#1}}}
\newcommand{\definition}[1]{\textbf{\textcolor{blue}{#1}}}

Repeat Title and Date R Markdown PDF

I am struggling what what is likely a trivial markdown matter. I am hoping to avoid YAML and additional header templates and such if I can. So my question is straightforward and I welcome your feedback. For an R Markdown knitted as a PDF, how can I repeat the title and date on each printed page?
Alternatively I am happy to use headers using the '#' syntax. But if I can use the title parameters that would be preferred.
The Header thus far:
---
title: "Dashboard"
date: '`r paste(Sys.Date(), " to ", Sys.Date()+14)`'
output:
pdf_document:
latex_engine: xelatex
mainfont: Calibri
geometry: margin=1cm
classoption: landscape
params:
set_title: !r test_title
header-includes:
- \usepackage{titling}
- \pretitle{\begin{flushleft}\huge}
- \posttitle{\end{flushleft}}
- \preauthor{\begin{flushleft}}
- \postauthor{\end{flushleft}}
- \predate{\begin{flushleft}\large}
- \postdate{\end{flushleft}}
---
From the rmarkdown cookbook:
When a Rmd document is compiled, all of its metadata in the YAML section
will be stored in the list object rmarkdown::metadata. You can use this object
in your R code. For example, rmarkdown::metadata$title gives you the title
of the document.

Apply knitr option function in "before_body" when using Rmarkdown to compile PDF

As question, I am using knitr option (i.e. include=temp.switch) to compile multiple reports based on the value given to a "switch" (i.e. temp.switch), this are working well for the content, but I would like to use similar function to modify the cover page of the report, which is stored in the tex file read in yaml, like the one below:
---
output:
pdf_document:
# template: template.tex
number_sections: true
keep_tex: true
includes:
in_header: preamble.tex
before_body: doc-prefix.tex
papersize: a4
editor_options:
chunk_output_type: console
---
Can anyone tell me how to make the doc-prefix.tex "conditional" based on the value of the "switch"? Thanks!

Pictures as headers in R-markdown

I want to add an image as a header on the upper right corner of every page of my word document, using r-markdown with R-Studio.
I found a solution accepted by community here, but there is only the proper command in Latex described, there is no working example. For me the offered solution did not work.
Therefore I provide my sample code:
---
title: "2014 Report"
author: "My Name"
date: "Monday, October 06, 2014"
output:
word_document:
fontsize: 10pt
header-includes:
- \usepackage{wallpaper}
abstract: This is my abstract
---
Test
\ThisURCornerWallPaper{0.1}{header.png}
Here is some text.
That code produced the following output:
As one can see, there is no picture included in the document. Can somebody provide me with an actually working example (other ideas that do the job are also welcome)?

How can I use latex packages in R markdown beamer?

I want to include latex packages in R markdown pdf and beamer.
Could you help me in including usepackage command in rmarkdown beamer file?
Thanks a lot.
A simple solution would be to have your header setup like this:
---
title: "Document title"
author: "Author's name"
date: "Document date"
output: beamer_presentation
header-includes:
- \usepackage[brazil]{babel}
- \usepackage{graphicx}
- \usepackage[a4paper]{geometry}
---
The YAML header of the Rmd would look like:
---
title: "Habits"
output:
pdf_document:
includes:
in_header: header.tex
---
Then, in the file header.tex, include any usepackage statements you need, eg. \usepackage{pdflscape}
See http://rmarkdown.rstudio.com/pdf_document_format.html for more information.

Resources