I am trying to convert a R markdown document to PDF. However, it fails to compile and gives me the following error message: ! Package calc Error: `\let ' invalid at this point.
My document consists of many child documents and I can compile all of the child documents separately without an error occuring. I did not load the calc package in my YAML header and can't figure out where the error comes from.
I am new to latex and R markdown and would really appreciate any tips on how I can solve this!
Here is my R markdown code:
---
output:
pdf_document:
fig_caption: yes
number_sections: yes
bibliography: library.bib
csl: chicago-author-date.csl
urlcolor: black
linkcolor: black
fontsize: 12pt
geometry: margin = 1.2in
header-includes:
- \usepackage{placeins}
- \usepackage{fancyhdr}
- \usepackage{setspace}
- \usepackage{chngcntr}
- \usepackage{microtype}
- \usepackage{mathtools}
- \usepackage{amsmath,amssymb,bm}
- \usepackage{dsfont}
- \usepackage{pdflscape}
- \usepackage{booktabs}
- \usepackage{caption}
- \usepackage{subfig}
- \onehalfspacing
- \counterwithin{figure}{section}
- \counterwithin{table}{section}
---
---
nocite: |
@Beck2001, @Piketty2014, @Nickell2006, @LaPorta1997, @Quinn2008
...
```{r global_options, include=FALSE}
knitr::opts_chunk$set(fig.path = 'figures/',
echo = FALSE, warning = FALSE, message = FALSE)
```
\pagenumbering{gobble}
```{r child = 'B.2-title_page.Rmd'}
```
\newpage
```{r child = 'B.3-declaration.Rmd'}
```
\newpage
\pagestyle{fancy}
\fancyhead[LE,RO]{}
\fancyhead[LO,RE]{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
\pagenumbering{roman}
\fancyhead[CO,CE]{Abstract}
\section*{Abstract}
\addcontentsline{toc}{section}{Abstract}
```{r child = 'B.4-abstract.Rmd'}
```
\newpage
\fancyhead[CO,CE]{Table of Contents}
\setcounter{tocdepth}{2}
\tableofcontents
\newpage
\pagenumbering{arabic}
\newpage
\fancyhead[CO,CE]{Introduction}
```{r child = 'B.5-introduction.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{Financial Deregulation and the 'Big Bangs'}
```{r child = 'B.6-big_bang.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{Methodology and Data}
```{r child = 'B.7-methodology.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{Main Results}
```{r child = 'B.8-main_results.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{Conclusion}
```{r child = 'B.9-conclusion.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{List of Figures}
\addcontentsline{toc}{section}{List of Figures}
\listoffigures
\newpage
\fancyhead[CO,CE]{List of Tables}
\addcontentsline{toc}{section}{List of Tables}
\listoftables
\newpage
\fancyhead[CO,CE]{Appendix}
```{r child = 'B.10-appendix.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{References}
# References
Update
So this is the .tex version of my markdown document that fails to convert to PDF. Rendering the document Example.Rmd by itself works fine. But included as a child document it produces the above error. Since I am an absolut beginner in markdown and Latex, maybe I'm not supposed to use \onehalfspacing
the way I did?
\documentclass[]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\else % if luatex or xelatex
\ifxetex
\usepackage{mathspec}
\else
\usepackage{fontspec}
\fi
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\fi
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage[margin=1in]{geometry}
\usepackage{hyperref}
\hypersetup{unicode=true,
pdfborder={0 0 0},
breaklinks=true}
\urlstyle{same} % don't use monospace font for urls
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{0}
% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
%%% Use protect on footnotes to avoid problems with footnotes in titles
\let\rmarkdownfootnote\footnote%
\def\footnote{\protect\rmarkdownfootnote}
%%% Change title format to be more compact
\usepackage{titling}
% Create subtitle command for use in maketitle
\newcommand{\subtitle}[1]{
\posttitle{
\begin{center}\large#1\end{center}
}
}
\setlength{\droptitle}{-2em}
\title{}
\pretitle{\vspace{\droptitle}}
\posttitle{}
\author{}
\preauthor{}\postauthor{}
\date{}
\predate{}\postdate{}
\usepackage{setspace}
\usepackage{mathtools}
\begin{document}
\noindent\parbox[t]{0.6\textwidth\large}{\raggedright Hello world \\ Hello world \\ Hello world}\hfill
\parbox[t]{0.3\textwidth\large\onehalfspacing}{\raggedright Hello world \\ Hello world}
\end{document}
.tex
file that is compiled with TeX?\let
TeX is complaining about might be hidden somewhere else. Can you try to reproduce the problem in a document that is as small as possible and show us the entire (cut-down).tex
file, please (see also tex.meta.stackexchange.com/q/228/35864)