41

How do I specify color in RGB using \hypersetup in hyperref?

I know that this is the right way to do it with color names:

\hypersetup{colorlinks,breaklinks,
            urlcolor=Maroon,
            linkcolor=Maroon}

But I want Teal, which hyperref doesn't recognize. I know Teal = {0 128 128} in RGB, but the following code won't compile:

\hypersetup{colorlinks,breaklinks,
            urlcolor={0 128 128},
            linkcolor={0 128 128}}

I have tried it with comma separators, proportional values (e.g. 0 < x < 1), but to no avail. What is the right way to do it? Also mention the correct texdoc that I should read for further info.

Kit
  • 16,430

2 Answers2

46

If you'd really prefer to specify RGB colours in \hypersetup without loading the (x)color package, you can always type them in directly like this:

\hypersetup{colorlinks,breaklinks,
            urlcolor=[RGB]{0,0.5,0.5},
            linkcolor=[RGB]{0,0.5,0.5}}

Still, as Ulrike mentioned, loading xcolor is usually the more comfortable way to go. Although probably a little overkill for your problem, this is how I generally proceed:

\usepackage[dvipsnames,svgnames,x11names,hyperref]{xcolor}

Note that you can specify multiple colour name spaces so long as you're not too concerned about name clashes (otherwise read the rules about this in the xcolor manual). Since you're loading xcolor to fit in with hyperref, don't forget to include the [hyperref] option as you go.

BanAnanas
  • 115
  • 1
    I wonder why there is no mention of the [rgb] option in texdoc hyperref? Do you happen to know where it is documented? – Kit Oct 25 '10 at 01:09
  • 3
    @Kit, like many things in TeX/LaTeX, the ultimate documentation is the source code itself. I just stuck my nose into hyperref.sty (and child packages that it loads) to figure out how it does things. Classic case of "no pain, no gain", wot? :) – Geoffrey Jones Oct 25 '10 at 06:20
  • More like slowly but surely for me :) And also, the sooner I accept that source code is the best documentation, the better. And to be able to read source code, I'll need the TeXbook, right? – Kit Oct 25 '10 at 13:27
13

You must define the name of color first. In the case of Teal it is not necessary as it is defines in svgnam.def, so you can use the svgnames option.

 \documentclass{book}
 \usepackage[svgnames]{xcolor}
 %\definecolor{Teal}{RGB}{0,128,128}
 \usepackage{hyperref}
 \hypersetup{colorlinks,breaklinks,
             urlcolor=Teal,
             linkcolor=Teal}
 \begin{document}
 \url{abc}
 \end{document}
Ulrike Fischer
  • 327,261
  • I got ! Illegal unit of measure (pt inserted). error for ...{0 128 128} and had to change it to {0,128,128}. Not sure if space separated form is wrong, so not editing the answer. – xaizek Oct 26 '15 at 08:17
  • 1
    @xaizek: I don't get an error with my code (with the color definition activated), imho both syntax (with space and with commas) should work, but commas are the official one, so I edited the code. – Ulrike Fischer Oct 26 '15 at 08:35