I have an issue with YAML datablock. Given the following pandoc document:
---
papersize: a4
geometry: "left=1.5cm,right=1.5cm,top=3cm,bottom=3cm"
fontsize: 12pt
# https://stackoverflow.com/a/43659664/2069099
subparagraph: yes
#documentclass: extarticle
header-includes:
- \usepackage[explicit]{titlesec}
- \titleformat{\section}[hang] {\filleft\huge\sc} {label}{20pt}{#1}
---
Hello World
===========
Lorem ipsum
I correctly get my title aligned on the right. Now, suppose I need a full-width ruler below the title, as stated in https://tex.stackexchange.com/a/84062, one need to modify \titleformat statement as:
---
papersize: a4
geometry: "left=1.5cm,right=1.5cm,top=3cm,bottom=3cm"
fontsize: 12pt
# https://stackoverflow.com/a/43659664/2069099
subparagraph: yes
#documentclass: extarticle
header-includes:
- \usepackage[explicit]{titlesec}
- \titleformat{\section}[hang] {\filleft\huge\sc} {label}{20pt}{#1}[\titlerule\vspace*{4pt}]
---
Hello World
===========
Lorem ipsum
but this leads to the following error:
Error producing PDF.
! LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.49 {[
and, indeed, the tex file shows weird code:
...
\usepackage[explicit]{titlesec}
\titleformat{\section}[hang] {\filleft\huge\sc} {label}{20pt}{#1}
{[}\titlerule\vspace*{4pt}{]}
\date{}
\begin{document}
...
OK, passing plain Latex in YAML block solved the issue:
--
papersize: a4
geometry: "left=1.5cm,right=1.5cm,top=3cm,bottom=3cm"
fontsize: 12pt
# https://stackoverflow.com/a/43659664/2069099
subparagraph: yes
#documentclass: extarticle
header-includes:
- \usepackage[explicit]{titlesec}
- |
```{=latex}
\titleformat{\section}[hang] {\filleft\huge\sc} {label}{20pt}{#1}[\titlerule\vspace*{4pt}]
```
---
Hello World
===========
Lorem ipsum
Pandoc parses part of that line as Markdown. So when the line is written as LaTeX, special characters are escaped to ensure that is produces the same text as the input. This is undesired here, and the best solution is to explicitly mark the line as LaTeX:
header-includes:
- \usepackage[explicit]{titlesec}
- `\titleformat{\section}[hang] {\filleft\huge\sc} {label}{20pt}{#1}`{=latex}
One could also mark the whole header includes like so:
header-includes: |
```{=latex}
\usepackage[explicit]{titlesec}
\titleformat{\section}[hang] {\filleft\huge\sc} {label}{20pt}{#1}
```
Related
I'm trying to combine both adding subtitles to beamer frames and rendering citations inside them in Rmarkdown. In LaTeX I've been able to do this with the following code:
\begin{frame}{Kontrastive Analyse: Russisch-Deutsch}
\framesubtitle{Phonetik und Phonologie kontrastiv: Russisch und Deutsch \parencite{kuemmelPhonetikundPhonologieRussischundDeutsch2017}}
...
\end{frame}
However, I'm having a hard time doing the same in Rmarkdown, where I have the bibliography defined in the YAML on the one hand and on the other hand also defined in the custom tex header.
So far, I've explicitly written the frame subtitle as LaTeX code (because I currently don't know how subtitles can be made in Rmarkdown beamer format; pipe character doesn't seem to work) and within the subtitle code use biblatex's \parencite{}, as follows
\framesubtitle{with a subtitle \parencite{kuemmelPhonetikundPhonologieRussischundDeutsch2017}}
So while the rest of citations written in markdown format (i.e. [#citekey]) are rendered without problem, citations within subtitles aren't. How can I solve this?
Here's the code so far:
---
title: "Presentation Title"
subtitle: "Subtitle"
author: |
| [Name]
| \scriptsize [Email]
institute: |
| [Institution]
| [Faculty]
| [Institute/Department]
| [Seminar]
| [Professor]
| [Semester]
date: \today
output:
beamer_presentation:
latex_engine: xelatex
keep_tex: TRUE
slide_level: 3
includes:
in_header: "myacademic-preamble.tex"
classoption: aspectratio=169
link-citations: true
bibliography: '/Users/marco-andres/Documents/Zotero+Pandoc/MyLibrary.bib'
csl: '/Users/marco-andres/Documents/Zotero+Pandoc/institut-slawistik-hu-berlin.csl'
---
\frametitle{Table of Contents}
\tableofcontents
# This is a dividing slide
## This is another dividing slide (subsection shown in TOC)
### Here's an individual slide
\framesubtitle{with a subtitle (Kümmel 2017)}
# Bibliography
\printbibliography
The custom .tex relevant for LaTeX-style bibliography is:
%Bibliography and language
\usepackage[english]{babel} %section and bibliography langauge
\usepackage{csquotes}
\usepackage[style=authoryear, sorting=nyt]{biblatex} %bibliography style
\addbibresource{MyLibrary.bib} %bib file
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}
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>
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.
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}
```