30

Consider the following snippet of a PDF generated from pandoc by way of latex.

Were you able to identify the hypertext links in there? Neither was I... It turns out that the second Kaplan Meier has a fully functional link to an external site. But how do we divine that?

Note that the following option is already in place in the pandoc preamble - without which the hyperlink would not work at all:

link-citations: true

Short of a "real" solution I'll need to hack something to make hints for the links - possibly via font manipulations.

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560

3 Answers3

39

If you use a recent version of Pandoc (latest is v2.7.3), just add (for example) these to the commandline:

-V colorlinks=true \
-V linkcolor=blue \
-V urlcolor=red \
-V toccolor=gray

No need to fiddle with the preamble!

You can investigate the built-in LaTeX template shipping with your own Pandoc by this command:

pandoc -D latex | less

Then search for link, url, color etc. to see which variables are pre-defined there. Or:

pandoc -D latex | grep --color -E '(links|color|url|file)'

will give you an idea what other "links" you may want to manipulate.

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
  • Nice! links were never happy being _red_ anyways (as in the defaults that can be seen in my answer below) .. well at least not until they were given a little attention/love . This is a nice complement to my answer - though I'll prefer adding to the preamble or to a `pandoc` template – WestCoastProjects Nov 15 '19 at 23:08
  • As for the list of colors without scratching deeper under the surface, choose from [CSS/Properties/color/keywords - W3C Wiki](https://www.w3.org/wiki/CSS/Properties/color/keywords). I find blue too striking and opt for teal instead. – pavol.kutaj Jan 13 '22 at 13:13
  • this has lot of upvotes so I assume it works but it did not for me. I am converting from markdown. anyone else run into this? – morpheus Sep 07 '22 at 00:31
  • @morpheus: You did not specify which specific steps of the answer you followed, and what were the exact results of these so I assume you did not follow them. – Kurt Pfeifle Sep 07 '22 at 07:28
  • Sorry if I was not clear. I added all the -V flags as the answer suggests. I did not do anything with the preamble as the answer suggests. SO I have a markdown file with no pandoc preamble. I run pandoc on it and use all the flags given. I use the xelatex pdf-engine. There is no error. A pdf is generated but the hyperlinks are not red or any other color for that matter. They just appear as normal text. They do work in the sense that I can click on them. lmk if anything else you need. – morpheus Sep 07 '22 at 15:39
  • @morpheus: So you checked your Pandoc version? Which is it? You also checked the LaTeX template your Pandoc uses for "url|color|file|links" occurences? – Kurt Pfeifle Sep 22 '22 at 09:05
  • this has to do with the version of pandoc I am using - 2.19. I asked in the mailing list and they helped me. Its a bug in that version fixed in next release. – morpheus Sep 22 '22 at 15:39
  • dude, the version of pandoc i am using is more recent than the version mentioned in your answer (2.7.3). hard to believe how vain some people can be. – morpheus Sep 24 '22 at 16:33
  • @morpheus: Sorry, I misread the version informaiton you gave as "2.1.9". My fault! – Kurt Pfeifle Sep 27 '22 at 15:40
17

You can also add to the meta-data colorlinks: true.

---
colorlinks: true
---

[Test](https://stackoverflow.com/a/71426117/2657549)

gives:

enter image description here

Clément
  • 2,358
  • 28
  • 32
3

Found an answer on tex site that covers this: add the following to the preamble https://tex.stackexchange.com/a/319463/45938:

 - \hypersetup{colorlinks=true}

enter image description here

Now I see there were actually two links.

WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560