Wednesday, June 06, 2007

Pdflatex and graphicx

I've always loved LaTeX as a typesetting environment and I'm still sure it's better than any WYSIWYG editor out there.

However, sometimes, you get stuck with some errors... well that's life ;-)

In particular I was struggling with a problem when including a diagram generated with MetaUML into a pdf file. Its documentation suggests this way of including the graphicx package, which is quite recurrent:

% The following is needed in order to make the code compatible
% with both latex/dvips and pdflatex.
\ifx\pdftexversion\undefined
\usepackage[dvips]{graphicx}
\else
\usepackage[pdftex]{graphicx}
\DeclareGraphicsRule{*}{mps}{*}{}
\fi

I was getting this error:
*hyperref using default driver hpdftex*
(/usr/share/texmf-texlive/tex/latex/hyperref/hpdftex.def))

! LaTeX Error: Option clash for package graphicx.
Actually, this time it wasn't hard to figure out where the problem was: the package hpdftex already uses graphicx with its options, so the easy way out is simply to correct the above inclusion of the package by removing the option in case of pdf compilation:

% The following is needed in order to make the code compatible
% with both latex/dvips and pdflatex.
\ifx\pdftexversion\undefined
\usepackage[dvips]{graphicx}
\else
\usepackage{graphicx}
\DeclareGraphicsRule{*}{mps}{*}{}
\fi

3 comments:

Anonymous said...

... to comment the WYSIWYG-Thing: LEd is a Editor where you can see what your are doing without open a separate window first.
Find it here: http://www.latexeditor.org/

.... maybe some more people try latex if they have such an editor.

Sry, I am no nativ-english ;)
Greetz

betto said...

WOW, looks very appealing!

Unfortunately it's for Windows systems only, and this makes it unusable for a Linux man like me :-)

Roozbeh Daneshvar said...

Thank you!
I am using ubuntu Linux and it resolved the issue very well.