I'm creating a document using bookdown. The primary target is printer pdf output so I want to get hyperlinks as footnotes. To do this I added the following lines to the YAML header in index.Rmd.
header-includes:
- \let\oldhref\href
- \renewcommand{\href}[2]{#2\footnote{\url{#1}}}
This has absolutely no effect. If instead I add the following to the preamble.tex file in the project directory I get the behaviour I want.
\let\oldhref\href
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
I have the same problem attempting to include packages using the header-includes as well. They just don't seen to get used and I get errors in the document build. Again, adding the \usepackage into preamble.tex works.
So I'm obviously missing something where header-includes is concerned but I don't know what it is.
Any suggestions?
Edit:
To reproduce this (at least the \usepackage version of the problem) using the latest version of RStudio on Windows with the latest version of bookdown from CRAN create a new Bookdown project using RStudio and make sure you have the package placeins installed in your LaTex environment then edit the supplied header in index.Rmd to give this:
---
title: "A Minimal Book Example"
author: "Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
header-includes:
- \usepackage{placeins}
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
description: "This is a minimal example of using the bookdown package to write a book. The output format for this example is bookdown::gitbook."
---
In the file 01-intro.Rmd add this immediately after the code to produce the Figure:
\FloatBarrier
Use The Build Book tab to build a PDF book and you will see the error:
! Undefined control sequence.
l.179 \FloatBarrier
Placing the \usepackage statement in preamble.tex removes the error.