title: How can I generate footnote URL links with an R function in bookdown / knitr documents?
body: <p>I try to generate URL links through an R-function. These links are inteded to be included in footnotes primarily.</p>
  
  <p>I generate the links in text references, and this works nicely in html output. In PDF (latex) though, it does not. In the document, I only see the empty (ref:some-text-ref) lines.</p>
  
  <p>I work in RStudio, all packages are up to date.</p>
  
  <p>I looked at <a href="https://stackoverflow.com/questions/49990699/bookdown-add-url-as-footnote">Bookdown add URL as footnote</a>. The proposes solution with redefining href is not satisfactory since I still want to be able to use href in a non-footnote context. Also, the problem here seems to be somewhere else because the links are not included in either html or pdf output.</p>
  
  <p>The following code demonstrates the problem.</p>
  
  <pre><code>---
  author: "Author"
  date: "`r Sys.Date()`"
  title: Testing footnotes
  site: bookdown::bookdown_site
  link-citations: yes
  toc-depth: 2
  always_allow_html: yes
  output:
    bookdown::gitbook:
        lib_dir: assets
        css: style.css
        split_by: section
        highlight: pygments
    bookdown::pdf_book:
        template: null
        latex_engine: xelatex
        keep_tex: yes
        highlight: pygments
  ---
  
  ```{r global-helpers, include=FALSE, results='hide'}
  library(stringr)
  
  github_base_url = "https://github.com/user/repo/tree/master"
  
  make_github_link &lt;- function(..., text = ""){
    subdirs &lt;- list(...)
  
    if (length(subdirs) == 0) {
      directory = ""
    } else {
      directory = paste(...,sep="/")
    }
    url = paste(github_base_url, directory, sep="/")
  
    if (text == ""){
      base = str_match(github_base_url, "(https://)([a-z/.-].*)(tree/master)")[3]
      link_text = paste0(base, directory)
    } else {
      link_text = text
    }
    sprintf("[%s](%s)", link_text, url)
  }
  
  ```
  
  ```{r setup_knitr, include=F, results='hide'}
  
  options(bookdown.clean_book = TRUE)
  options(knitr.graphics.auto_pdf = TRUE)
  
  knitr::opts_chunk$set(error=TRUE,
                        warning=TRUE,
                        message=FALSE,
                        echo=FALSE,
                        cache=TRUE,
                        dpi=300,
                        fig.width=7, # Default figure widths
                        fig.asp=0.618,
                        fig.align="center",
                        fig.path = "./figures/",
                        out.width = "70%",
                        crop = TRUE,
                        tidy=TRUE)
  
  knitr::opts_knit$set(eval.after='fig.cap',
                       verbose=TRUE,
                       digits=2)
  
  
  ## a common hook for messages, warnings and errors
  hook_lst_bf = function(x, options) {
      paste("\\begin{lstlisting}[basicstyle={\\bfseries}]\n", x, 
          "\\end{lstlisting}\n", sep = "")
  }
  
  knitr::knit_hooks$set(source = function(x, options) {
      paste("\\begin{lstlisting}[language=Python,stepnumber=2,basicstyle=\\footnotesize]\n", x, 
          "\\end{lstlisting}\n", sep = "")
  }, output = function(x, options) {
      paste("\\begin{lstlisting}[basicstyle={\\ttfamily},basicstyle=\\footnotesize]\n", x, 
          "\\end{lstlisting}\n", sep = "")
  }, warning = hook_lst_bf, message = hook_lst_bf, error = hook_lst_bf)
  
  
  inline_hook &lt;- function (x) {
    if (is.numeric(x)) {
      res &lt;- ifelse(x == round(x),
        sprintf("%d", x),
        sprintf("%.3f", x)
      )
      paste(res, collapse = ", ")
    }
  }
  
  
  knitr::knit_hooks$set(inline = inline_hook,
                        rgl = rgl::hook_rgl,
                        crop = knitr::hook_pdfcrop,
                        optipng = knitr::hook_optipng)
  
  ```
  
  
  #  Heading
  
  (ref:footnote-link) `r make_github_link("code")`
  
  That's a sentence with a footnote^[(ref:footnote-link)]. The footnote should contain a link.
  
  
  </code></pre>