Hyperref doesn't work in rmarkdown



I'm currently working on my thesis in rmarkdown pdf latex. Last month I made a template that worked as expected, specifically with the package hyperref. Yet, after updating R and R Studio, the feature doesn't work anymore.

I have tried the following:

  1. Put the header-includes option in the YAML
  2. Put the hyperref setting in the document's body specifying it is a latex code and not markdown.
  3. Reinstalled tiny tex

None of the previous options had worked.

I'm out of ideas.

    - \usepackage{hyperref}
    - \definecolor{blue_r}{RGB}{0, 124, 145}
    - \hypersetup{colorlinks = true,  linkcolor = blue_r,  urlcolor  = blue_r, citecolor = blue_r}

Can you share the template ?

If this is a full custom template, then you should include into it anything you need. Is this a full template or just some includes ?

It is possible that a Pandoc update requires an update to your template, but I am really not sure what the issue is really.

What does not work exactly ?

1 Like

It's not a full template, it is an include header, this is the YAML header:

    toc: false
    toc_depth: 4
      in_header: header.tex
      before_body: pre.tex
documentclass: report

Here's the header: header.tex

The hyperref setting is at the bottom.

The issue is that after specifying the colors of the links in with \hypersetup, the pdf output doesn't have the links colored. What is more strange is that I didn't change any of the code in weeks; I just updated R and R studio.

Thank you in advance for the quick response :slight_smile:

It seems definitely something that could be lead to a Pandoc update due to RStudio update.

Can you share rmarkdown::pandoc_version() result ?

This is a change I know about (incompatibilities with hyperref latex package · Issue #5811 · jgm/pandoc · GitHub) which happened in Pandoc 2.18 (Pandoc - Releases)

Move hyperref near end of preamble (#5811). It now comes after header-includes and right before title, author, date, abstract. Note: Users who presuppose hyperref in their header-includes will now have to add \usepackage{hyperref} to their header-includes to make it available there. (The redundant \usepackage will do no harm in this case.)

So adding \usepackage{hyperref} in your header.tex should have fixed the issue.

It is indeed the version of Pandoc 2.18.

Nevertheless, as the header-includes states in the first message, adding \usepackage{hyperref} in header.tex doesn't work.

It is possible that something else changed in Pandoc's template that is impacted your document.
Your header.tex is defining a lots of things, among which some of them are already defined in the Pandoc's template, and you are not leveraging the variables like colorlinks: true Pandoc - Pandoc User’s Guide

You can find the template for 2.18 in pandoc-templates/default.latex at 2.18 · jgm/pandoc-templates · GitHub

You'll see some setup already for hyperref. Maybe this is conflicting with yours ?

It happens after you header includes as mentioned in the changelog above. So possibly what you are doing is overwritten somehow ?

I would leverage the Pandoc's variable more to tweak what can be tweaked.


I'm sorry for not responding as fast as before.

In summary, you were right! I think they wanted us to use the pandoc variables; here's the recipe that worked:

  1. In header-includes write: \usepackage{hyperref}

  2. In the YAML, or at some point in the document, set: colorlinks: true

  3. Specify the colors of your links with latex in header-includes or with pandoc variables:

    • \hypersetup{ urlcolor = blue, citecolor = blue}
    • linkcolor: black
  4. By using pandoc variables in the YAML, the links changed their color. The latex specification of the linkcolordoesn't work

Overall, as @cderv stated, let's leverage pandoc's variables

Thank you so much for your support!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.