Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
    \usepackage{amsmath}
    \usepackage{array}
    \usepackage{booktabs}
    \usepackage[draft]{pgf}
    \usepackage{listings}
    \usepackage[usenames,dvipsnames]{xcolor}

I want to use a color called 'Bittersweet' but I get this error

share|improve this question

1 Answer 1

up vote 15 down vote accepted

Package listings does not load xcolor, but package pgf does. In LaTeX you can load a package many times, but the option list of each package loading must be a subset of the options given at the first loading (exception is package fontenc).

All options at first package loading

The problem is solved, if the first package loading contains all options:

\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[draft]{pgf}
\usepackage{listings}

\PassOptionsToPackage

However somtimes packages might be loaded in the document class already, or there are constraints in the package order that prevents the reordering of the packages. Then \PassOptionsToPackage helps. It can even be loaded before \documentclass. It gives the specified options to the package without loading the package:

\PassOptionsToPackage{usenames,dvipsnames}{xcolor}
...
\usepackage[draft]{pgf}
% pgf can now load the package xcolor and loads it with
% options "usenames,dvipsnames".
\usepackage{listings}
\usepackage{xcolor}
% or \usepackage[usenames,dvipsnames]{xcolor}

Global options

BTW, the help text of the error message (press h at the interactive prompt or check the .log file) for the option clash shows the options that need to be specified at the first loading of the package.

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

l.5 \begin
          {document}
The package xcolor has already been loaded with options:
  []
There has now been an attempt to load it with options
  [usenames,dvipsnames]
Adding the global options:
  ,usenames,dvipsnames
to your \documentclass declaration may fix this.
Try typing  <return>  to proceed.

Adding the options to the global options can also be used, but it is not the best strategy IMHO, because also other unrelated packages see that options. Unknown global options are ignored by packages, but known are then executed with unintended side effects.

share|improve this answer
    
With packages like xcolor, hyperref etc. that are often loaded by other packages and classes, I definitely vote for \PassOptionsToPackage before \documentclass, it saves lots of troubles. –  yo' Feb 20 '13 at 9:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.