📜 ⬆️ ⬇️

LaTeX: Package Conflict Options

Translation of the “Option clash for package” page from the UK FAQ  TeXUsers' Group.


I just inserted a line into the document.

\usepackage[draft]{foo} 

and now  LaTeXswears

! LaTeX Error: Option clash for package foo.
( foo)

This error indicates that the package has been downloaded more than once with options.  LaTeXdissatisfied, because he can not independently deal with options. (In the preamble of the document, you can load a package without options several times -  LaTeXwill process only the first download request and ignore the subsequent ones; but you can only specify options when you first download 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} 

then it is definitely worth rewriting as follows:

 \usepackage[dvips,draft]{graphics} 

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

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

Notice that the brackets for the graphics package are enclosed in brackets for the foo package. In the case of the bar class, the message will be exactly the same, only the first line will bar.cls path to the bar.cls file.

If the package that interests us is loaded inside another package, you can ask  LaTeXforward the necessary options. Instead

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

should write

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

Team \PassOptionsToPackage Requests  LaTeXbehave during the final package loading as if its parameters were specified as options during the final package loading. The name of the \PassOptionsToPackage shows that several options can be specified at once.

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

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

insert the \PassOptionsToPackage command before the \documentclass command:

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

It would seem that we are at a standstill if in the foo package or bar class the graphics package is loaded with an option that conflicts with the one we would like to specify.

for example

 \PassOptionsToPackage{draft}{graphics} 

while in a package or classroom it is written

 \usepackage[final]{graphics} 

will cause the final option to be set after the options passed from the outside, and the draft will simply be dropped. In some cases, the package may display an error message (but the graphics not one of those, and the draft option will be dropped without any diagnostics).

In this case, you can independently edit the package / class (in accordance with its license). It will also be useful to contact the author of the package, who can offer alternative ways to solve the problem [3] .



Translator's notes



  1. Sample error message
    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 TeXstudio , the latex -interaction=nonstopmode ... , and you should look for such latex -interaction=nonstopmode ... in the “basement” section of the Log - Log File .
  3. TeX.SX offers a more elegant solution: the \PreventPackageFromLoading command \PreventPackageFromLoading scrlfile .

Source: https://habr.com/ru/post/348774/


All Articles