Conflict between color, graphicx and libertine

Compiling the following with pdflatex (TeXLive 2009/Debian on Ubuntu 10.04 "Lucid Lynx")

\documentclass{article}
\usepackage{ifpdf}
\ifpdf
\usepackage[T1]{fontenc}
\usepackage{libertine} % Linux Libertine. This gives an error
%\usepackage{lmodern} % this works fine
\usepackage[pdftex,usenames,dvipsnames]{color}
\usepackage[pdftex]{graphicx}
\else
\bye
\fi
\begin{document}
Hello, world!
\end{document}


I get this error:

! LaTeX Error: Option clash for package color.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H   for immediate help.
...

l.8     \usepackage
[pdftex]{graphicx}


Can anyone explain this? I can't for the life of me understand why a font package would mess with color and graphicx.

-

These option clashes happen when a package is requested to be loaded on two different positions, like by you and inside another package, but with different options. The package is loaded by the first \usepackage (or its twin \RequirePackage); it isn't loaded again when it is requested again. It simply can't be loaded a second time. Therefore the new options can be activated and previous options might conflict with the second usage. So LaTeX creates an error to report this issue to you.

The way to fix this is to declare the options beforehand using \PassOptionsToPackage{<options>}{<package>}. Then they are used wherever the package is loaded.

\documentclass{article}
\usepackage{ifpdf}
\ifpdf
\PassOptionsToPackage{pdftex,usenames,dvipsnames}{color}
\usepackage[T1]{fontenc}
\usepackage{libertine} % most likely loads 'color' itself
\usepackage{color}
\usepackage[pdftex]{graphicx}
\else
%\bye
\fi
\begin{document}
Hello, world!
\end{document}


I can't test it by myself, because I don't have the libertine package installed.

PS:

I don't think you need to set pdftex manually. Normally packages do a good job recognizing the driver by themselves. Also you might want to use the extended xcolor package instead of color.

-
\bye is undefined in LaTeX. –  Leo Liu Feb 19 '11 at 12:08
@Leo: that's just copied from the OP's code. Didn't paid attention to that part. –  Martin Scharrer Feb 19 '11 at 12:09
I just noticed that a minute ago. BTW, the OP's code works fine for me (TeX Live 2010), it seems a bug of libertine.sty(or some other package). –  Leo Liu Feb 19 '11 at 12:14
@Leo: Yes, see also Herbert's answer. But anyway, I think the answer is a good example how to resolve option clashes. –  Martin Scharrer Feb 19 '11 at 12:20
Yes it is. Another way is to use a global option for class, like pdftex here. –  Leo Liu Feb 19 '11 at 13:13

you should update your libertine package then you do not get an error.

*File List*
libertine.sty    2010/08/30 - 4.8.7: Font libertine - (License GPL) Michael Nie
dermair

-
three questions: 1) how to check if libertine.sty is installed? 2) if yes, how to check which version? 3) ways to update? –  nutty about natty Jul 9 '13 at 13:18