Pandoc conversion to PDF not providing colored hyptertext links
Asked Answered
P

3

39

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.

Phototopography answered 14/11, 2019 at 21:30 Comment(0)
M
52

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.

Martynne answered 15/11, 2019 at 22:52 Comment(10)
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 templatePhototopography
As for the list of colors without scratching deeper under the surface, choose from CSS/Properties/color/keywords - W3C Wiki. I find blue too striking and opt for teal instead.Hilariohilarious
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?Aixenprovence
@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.Martynne
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.Aixenprovence
@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?Martynne
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.Aixenprovence
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.Aixenprovence
@morpheus: Sorry, I misread the version informaiton you gave as "2.1.9". My fault!Martynne
In case it helps - am on pandoc 3.1.11.1 on Windows, and this solution also did not work. What did work, was adding -f autolink_bare_uris see #70835961Couplet
I
21

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

---
colorlinks: true
---

[Test](https://mcmap.net/q/400800/-pandoc-conversion-to-pdf-not-providing-colored-hyptertext-links)

gives:

enter image description here

Initiation answered 10/3, 2022 at 14:48 Comment(3)
where do you add this? In the md file?Sinkhole
@Sinkhole Yes, in the YAML headerHau
This is documented hereHau
P
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.

Phototopography answered 14/11, 2019 at 21:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.