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
.
Classically (La)TeX has no knowledge of the physical paper size, it just sets up a text block area of a give width and height. The "page margins" were just an artifact of where the dvi driver positioned that text block on the page.
PDF and pdftex change that a bit as pdftex is essentially its own driver so needs to be concerned with that aspect and the pdf format itself has a notion of the intrinsic size of each page, which is used by pdf viewers to clip the view or size the window.
The latex format mostly uses \textwidth
and \textheight
(the area of the text block) but LaTeX2e introduces \paperheight
and \paperwidth
which are typically set by options such as a4paper
. They are not used much although the standard classes use them in some initial calculations to set \textwidth
and \@oddsidemargin
.
The graphics package uses several different back ends (dvips
, pdftex
, etc) and if it detects that it is running under pdftex then it sets the pdftex primitives \pdfpagewidth
and \pdfpageheight
to the values of \paperwidth
and \paperheight
respectively) This has the effect of specifying latex's idea of the physical page size in the pdf output and the viewer uses that as you noticed. (Several other packages now do the same, notably geometry
). This isn't strictly to do with graphics inclusion but the idea back then was that all driver-specific code would be in one customisable file dvips.def
, pdftex.def
, ... and this same file is loaded by graphics
and color
and any other package that needed back end driver support, so it seemed a natural place to add this setting.
For reasons to do with historical compatibility, the default paper size in LaTeX is US letter, however the default page size in your pdf viewer is probably A4 if you are not in the USA. This means that the default behaviour is to typeset the document for US letter but display it in a viewer clipped to A4, which sort of works but is sub-optimal.
The effect of the graphics package making things match is that you noticed:-) Especially as it made them align the wrong way, as latex's default page size was communicated to the pdf browser. By adding [a4paper]
you not only tell the pdf browser that you want that size, so it doesn't clip the bottom, latex actually formats the document for A4 rather than US Letter, to match the physical page dimensions.
Best Answer
graphicx
(and some other packages likehyperref
andgeometry
) actually corrects a problem. Without it it can happen that the pdf size shown by the pdf viewer is not equal to the internal\paperwidth
and\paperheight
.graphicx
sets\pdfpagewidth
and\pdfpageheight
to avoid this problem. If you are getting the wrong page size, make sure that the option of the class actually reflects the page size you want: