42

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.

1
  • 6
    To specify colors as RGB byte triplets as in your example, replace rbg with RGB in Geoffrey Jones answer below. E.g. urlcolor = [RGB]{0 128 128}.
    – ntc2
    Commented Jan 27, 2014 at 8:49

2 Answers 2

47

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.

3
  • 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
    Commented Oct 25, 2010 at 1: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? :) Commented Oct 25, 2010 at 6: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
    Commented Oct 25, 2010 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}
2
  • 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
    Commented Oct 26, 2015 at 8: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. Commented Oct 26, 2015 at 8:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .