LaTeX: Options Conflict for a Package

Original author: Robin Fairbairns
  • Transfer

Translating the “Option clash for package” page from the FAQ UK $ \ TeX $ Users' Group.


I just inserted a line in the document

\usepackage[draft]{foo}

and now $ \ LaTeX $swears This error indicates that the package has been downloaded more than once with options.

! LaTeX Error: Option clash for package foo.
(Конфликт опций для пакета foo)

$ \ LaTeX $dissatisfied, because he can not independently deal with options. (In the preamble of the document, you can download the package without options several times -$ \ LaTeX $It will only process the first download request and ignore subsequent ones; but you can specify options only at the first download of the package).

It seems that not everything is as simple as it seemed at the beginning. If the error is caused by the following code

\usepackage[dvips]{graphics}
\usepackage[draft]{graphics} 

it should definitely be rewritten as follows:

\usepackage[dvips,draft]{graphics} 

What to do when the cause of the error is not so obvious (even if such downloads are spaced across several lines, they are easy to detect with the naked eye)? It may turn out that the package we are interested in has already been downloaded somewhere else. But where exactly? If you press the h key after an error message, you can see the list of options with which the package downloads [1] [2] were called. If the response message looks different, then you will have to use the tips from the article How to approach errors . The main thing to remember is that the process of downloading a package in the log is surrounded by brackets, so if the package is graphicsloaded in the package foo, the log will look something like this

(/foo.sty ...
...
(/graphics.sty ...
...)
...
)

Please note that the brackets related to the package graphicsare enclosed in brackets related to the package foo. In the case of a class bar, the message will be exactly the same, only the first line will show the path to the file bar.cls.

If the package of interest to us is loaded inside another package, then you can ask$ \ LaTeX $to forward the necessary options. Instead

\usepackage{foo}
\usepackage[draft]{graphics} 

should write

\PassOptionsToPackage{draft}{graphics}
\usepackage{foo} 

Team \PassOptionsToPackageasks$ \ LaTeX $behave during the final download of the package as if its parameters were specified as options during the final download of the package. The name of the command \PassOptionsToPackageshows that you can specify several options at once.

The matter is somewhat complicated if the options need to be passed to the package, which is loaded in the document class. In this case, instead

\documentclass[...]{bar}
\usepackage[draft]{graphics} 

you should insert the command \PassOptionsToPackagebefore the command \documentclass:

\PassOptionsToPackage{draft}{graphics}
\documentclass[...]{bar} 

It might seem that we are stuck if a package fooor class loads a barpackage graphicswith an option that conflicts with the one we would like to specify.

for instance

\PassOptionsToPackage{draft}{graphics} 

while the package or class says

\usepackage[final]{graphics} 

will lead to the fact that the option finalwill be installed after the options passed from the outside, and draftwill be simply discarded. In some cases, the package may display an error message (but graphicsnot one of them, and the option draftwill be discarded without any diagnostics).

In this case, you can edit the package / class yourself (in accordance with its license). It will also be useful to contact the author of the package, which may offer alternative methods of solving the problem [3] .



Translator Notes



  1. Error message example
    Hidden text
    %clash.tex
    \documentclass{article}
    \usepackage[dvips]{graphics}
    \usepackage[draft]{graphics} 
    \begin{document}
    \end{document}
    

    $ latex clash.tex
    ...
    ! LaTeX Error: Option clash for package graphics.

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

    l.5

    ? h
    The package graphics has already been loaded with options:
    [dvips]
    There has now been an attempt to load it with options
    [draft]
    Adding the global options:
    dvips,draft
    to your \documentclass declaration may fix this.
    Try typing to proceed.
  2. In my TeXstudiocommand is executed latex -interaction=nonstopmode ..., and similar results need to be searched in the "basement" in the section Log - Log File.
  3. On TeX.SX offer a more elegant solution: a command \PreventPackageFromLoadingpacket scrlfile.

Also popular now: