# [Tex/LaTex] Conflict between color, graphicx and libertine

colorfontsgraphicspdftex

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.