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{lmodern} % doesn't load 'color'
\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
.
David has explained this one way, I will take a slightly different tack.
First, what is going on? When e-TeX finds a protected macro, it will not expand it inside an \edef
, \write
and some similar circumstances, which usually exhaustively expand everything. That is to ensure you can see the protected token in the result. For example,
\protected\def\a{}
\typeout{%
\a%
b%
}
will show \a b
, even though there is no space between \a
and b
as far as TeX is concerned. That's because the alternative is \ab
, which as we can't see the tokens would be misleading (does it mean \a
followed by b
or a different macro \ab
?).
You can 'force' expansion of a protected macro by using the fact that they do respect \expandafter
:
\protected\def\a{b}
\edef\test{\expandafter\empty\a}
\show\a
using \empty
as something to expand after which will not result in anything remaining behind.
Second, why do you need protection? Some operations in TeX simply will not work within an \edef
as they use TeX primitives which are not 'expandable'. The classic ones here are assignments (\def
, \let
and so on). If you try
\let\a\undefined
\def\b{a}
\edef\test{\let\a\b}
you will not find that \a
ends up defined to give a
. Instead, you'll get an error: in this case 'Undefined control sequence
'. That is because \let
is not expandable. So TeX simply 'leaves it alone' inside the \edef
, and tries to expand \a
. That's not possible, and so an error arises. Thus in general it is not a good idea to try to expand protected macros.
Best Answer
Staying with the desire of the OP, here is a solution.