Rmarkdown Latex citation (Harvard style) within footnote - latex

I am writing my thesis in Rmarkdown and Latex with a seperate literature.bib file that contains the bibtex sources. I now have a footnote and I would like to have a citation like in the normal text, but within the footnote. Is there any package to achieve that? When i just try it, like I would have a citation in the normal text, the footnote stops beeing a footnote when i render to pdf. The citation style I use is the Harvard citation style, so only something like this appears and should appear in the footnote:
The rest of information is than provided under the heading References at the end of the document. Thanks in advance! I appreciate any help...!
Here a minimal reproducable example:
--> This is the code for the main .rmd file
---
output:
bookdown::pdf_document2:
toc: no
papersize: a4
geometry: margin = 1in
fontsize: 11pt
bibliography: literatur.bib
---
#TEST
This is just an example #test.\footnote{I would also like to have a citation here in this footnote!!}
\newpage
# References
<div id="refs"></div>
-->This is the code for the literatur.bib file
#online{test,
author = {PACER},
title = {Service Center},
url = {https://pcl.uscourts.gov},
urldate = {2021-09-10}
}
Hope that is helpful?!

If you use markdown syntax for the footnote, you can also insert the citation via markdown syntax:
---
output:
bookdown::pdf_document2:
toc: no
papersize: a4
geometry: margin = 1in
fontsize: 11pt
bibliography: literatur.bib
---
#TEST
This is just an example #test.^[I would also like to have a citation here in this footnote!! See [#test]]
\newpage
# References
<div id="refs"></div>

Related

Place bibliography before Appendix when using natbib

I have the following document.
---
title: "What comes after the bibliography?"
bibliography: refs.bib
header-includes:
- \usepackage{natbib}
- \setcitestyle{numbers}
- \setcitestyle{square}
output:
pdf_document:
citation_package: natbib
latex_engine: lualatex
keep_tex: yes
---
# A
This document may use knitr[#pKnitr].
# References
<div id="refs"></div>
# Appendix
`1+1` evaluates in R to `r 1+1` (for more information, see [#pRmarkdown])
I used citation() to create the bibtex references in refs.bib.
#InCollection{pKnitr,
booktitle = {{Implementing Reproducible Computational Research}},
editor = {Victoria Stodden and Friedrich Leisch and Roger D. Peng},
title = {knitr: A Comprehensive Tool for Reproducible Research in {R}},
author = {Yihui Xie},
publisher = {Chapman and Hall/CRC},
year = {2014},
note = {ISBN 978-1466561595},
url = {http://www.crcpress.com/product/isbn/9781466561595}
}
#Book{pRmarkdown,
title = {{R Markdown Cookbook}},
author = {Yihui Xie and Christophe Dervieux and Emily Riederer},
publisher = {Chapman and Hall/CRC},
address = {Boca Raton, Florida},
year = {2020},
note = {ISBN 9780367563837},
url = {https://bookdown.org/yihui/rmarkdown-cookbook}
}
I want to place my bibliography before the Appendix. So far I've tried the following, unfortunately with no luck.
Add <div id="refs"></div> (see example above)
Using \AtEndDocument{} - its contents won't transpile to LaTeX
\printbibliography does not work with natbib
\bibliography{refs} kinda works, but I have to manually delete the bibliography macro created by md / Rmd
For the last point, if I have the following in my Rmd file...
<!-- ... -->
# References
\bibliography{refs}
# Appendix
`1+1` evaluates in R to `r 1+1` (for more information, see [#pRmarkdown])
... it produces the following LaTeX file.
% ...
\section{A}\label{a}}
This document may use knitr\citep{pKnitr}.
\hypertarget{references}{%
\section{References}\label{references}}
\bibliography{refs.bib}
\hypertarget{appendix}{%
\section{Appendix}\label{appendix}}
\texttt{1+1} evaluates in R to 2 (for more information, see
\citep{pRmarkdown})
\bibliography{refs.bib}
\end{document}
So \bibliography{refs.bib} is now added twice, causing a Citations multiply defined error.
How can I add the bibliography before my Appendix using natbib?
If you use remove all the interference from markdown, you are more flexible with the placement of the bibliography:
---
title: "What comes after the bibliography?"
header-includes:
- \usepackage{natbib}
- \bibliographystyle{plainnat}
- \setcitestyle{numbers}
- \setcitestyle{square}
output:
pdf_document:
latex_engine: lualatex
keep_tex: yes
---
# A
This document may use knitr \cite{pKnitr}.
\bibliography{refs}
# Appendix
`1+1` evaluates in R to `r 1+1` (for more information, see \cite{pRmarkdown})

how to include pdfpages in rmarkdown for beamer output

I am creating pdf slides using rmarkdown and beamer. When using latex instead of rmarkdown, I can include arbitrary pages from pdf files into my slides with
\usepackage{pdfpages}
...
\includepdf[pages={1-10}]{another_file.pdf}
Is it possible to achieve this with rmarkdown? Note that when just issuing the \includepdf command, intended to be located between slides, pandoc wraps it between \begin{frame} and \end{frame}.
Not a perfect solution but it works (adapted from https://tex.stackexchange.com/questions/11458/error-when-inserting-a-pdf-page-into-a-beamer-presentation?newreg=10fd6a4a46c642118eb4ec905cf87303): use \includegraphics instead of includepdf. This works inside of frames but you have to manyally create a frame for each page you want to insert as it only allows to insert a single page at time.
---
title: "Foo"
output:
beamer_presentation:
---
# Stolen image
---
\includegraphics[page=1,width=\paperwidth]{lecture-1-terminal.pdf}
# My own work
## My slide 1
Great stuff!
In rmarkdown you can use pdfpages like this:
---
output:
beamer_presentation:
keep_tex: true
header-includes:
- \usepackage{pdfpages}
- \setbeamercolor{background canvas}{bg=}
- \makeatletter\beamer#ignorenonframefalse\makeatother
---
test
``` {=latex}
\end{frame}
\includepdf[pages=1-10]{example-image-duck}
\begin{frame}
```
test
(the line \setbeamercolor{background canvas}{bg=} is necessary for beamer versions < 3.64, a patch has been added in 9e3bb9)
As you mentioned, you can inlcude raw TeX in Pandoc Markdown. For me the following works:
$ pandoc -t beamer
foo
\includepdf[pages={1-10}]{another_file.pdf}
bar
^D
which results in:
\begin{frame}
foo
\includepdf[pages={1-10}]{another_file.pdf}
bar
\end{frame}
Maybe you need to update your pandoc version? (I'm currenlty using 2.0 from pandoc nightlies)

Remove unwanted latex code from final document.

I made a file in rmarkdown to submit to a journal, but when I went to actually upload the file, they want raw latex. Okay, part of my YAML is.
output:
pdf_document:
keep_tex: true
header-includes:
- \usepackage{color}
- \usepackage{lineno}
- \linenumbers
The preview of the document looks great, except it starts out like this (just text not, in code format:
[]article lmodern amssymb,amsmath ifxetex,ifluatex fixltx2e =0 [T1]fontenc
[utf8]inputenc fontspec Ligatures=TeX,Scale=MatchLowercase upquote microtype
[protrusion]basicmath [margin=1in]geometry hyperref graphicx,grffile parskip
titling
color lineno
followed by everything I want. Where do I look to get rid of this?

Left aligning a LaTex equation

Below is an rmarkdown document with a LaTex equation. The default for these equations is centre. How do I left-align this equation? I have searched the similar answers but none of the suggestions work on this simple problem.
---
title: "Untitled"
author: "Llew Mills"
date: "1 May 2016"
output: pdf_document
---
## R Markdown
\begingroup\Large
\begin{equation*}
\Delta PsuedoR^2_{\zeta_{0}} = \frac {0.488 - 0.624}{0.488} = -0.219
\end{equation*}
\endgroup
This latex solution on tex.SE gives an answer that we can adapt to knitr. To have all equation of the document aligned on the left, you can use classoption fleqn and write equation in regular pandoc latex-math style (surrounded with $$):
---
classoption: fleqn
header-includes:
- \setlength{\mathindent}{0pt}
---
$$\Delta PsuedoR^2_{\zeta_{0}} = \frac {0.488 - 0.624}{0.488} = -0.219$$
Note that you don't have to add \usepackage{amsmath} because the default latex template already includes it.

How can I insert page number to rmarkdown beamer slides?

How can I show page numbers (preferably like 4/10, 5/10 etc.) on an rmarkdown beamer presentation?
In the front matter of the document, you can include a .tex file with extra commands as shown in RStudio's documentation here.
I created a new .tex file that I called "header_pagenrs.tex" which only includes the top 2 lines from #user4281727's answer:
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}[page number]
Then I referenced this file at the top of my .Rmd file:
---
title: "Things and Stuff"
author: "Me"
output:
beamer_presentation:
includes:
in_header: header_pagenrs.tex
---
If this still gives you errors, you might also be missing some required TeX packages (a separate problem from RStudio and rmarkdown).
Here's another option that worked for me. Didn't need to add a .tex file to my folder. Just included the following (based on above code from #civilstat) at the top of my Markdown doc.
---
title: 'Your Title'
author: "Your Name"
date: "July 4, 1776"
output:
beamer_presentation(keep_tex = TRUE): default
header-includes:
- \setbeamertemplate{navigation symbols}{}
- \setbeamertemplate{footline}[page number]
---
If your beamer version is reasonable up to date (>= v3.48), you can adjust the format of the frame numbers while keeping the footline of your chosen beamer theme unchanged otherwise.
---
output:
beamer_presentation:
theme: "Berlin"
keep_tex: true
header-includes:
- \setbeamertemplate{page number in head/foot}[totalframenumber]
---
test
Try to put the lines below into the template
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}[page number]
~/Library/R/3.1/library/rmarkdown/rmd/beamer/default.tex

Resources