LaTeX package conflicts

From Exterior Memory
Jump to: navigation, search

LaTeX package conflicts

Package conflicts in LaTeX are a hell. Perhaps I should have used ConTeX after all (ConTeX does not have package conflicts; I guess mostly because there are no packages...)

Contents

Hyperref

Hyperref is by far the package causing most conflicts. Do yourself a favour and do read the hyperref README file (Section 6 on Package Compatibility). It contains an extensive, albeit not complete list of conflicts and solutions.

Hyperref and preamble pages

Error:

pdfTeX warning (ext4): destination with the same identifier (name{page.2}) has been already used, duplicate ignored

If you have a preamble, e.g. you make a thesis and use \frontmatter, \mainmatter and \backmatter, then the page numbers in front matter are roman (i, ii, iii, iv, v, vi, etc.) The page numbers in main matter are arabic (1, 2, 3, 4, etc.). However, the page labels are the same in both cases (page.1, page.2, page.3, etc.). This leads to the error. To circumvent, tell the hyperref package to use page labels with roman symbols (page.i, page.ii, page.iii, etc.)

See also the LaTeX FAQ entry on Hyperref and repeated page numbers.

Solution:

\usepackage[plainpages=false]{hyperref}

Hyperref and Fancy headers

Error:

pdfTeX warning (ext4): destination with the same identifier (name{figure.1.1}) has been already used, duplicate ignored

If you get errors like the above, even though you really have only one figure 1.1, perhaps you experience a conflict between hyperref and fancy headers.

Solution: Hyperref must be loaded after fancy headers.

\usepackage{fancyhdr}
\usepackage[pdftex,colorlinks=false,plainpages=false]{hyperref}

Hyperref and LLNCS Class

Error:

Package hyperref Warning: bookmark level for unknown title defaults to 0.
Package hyperref Warning: bookmark level for unknown author defaults to 0.
Latex Error: ./D1.3.tex:30 Missing \endcsname inserted.

The LLNCS (Springer Lecture Notes in Computer Science) class had a bug rendering it incompatible with Hyperref. This was fixed in llncs.cls version 2.15.

Solution: Download the latest versions of llncs2e.zip.

Hyperref and Algorithm

LaTeX gives an error in lines with a \ref{} command that points to an algorithm:

undefined control sequence

If the above error occurs the second time you run latex, but not the first time, you may experience a conflict between the hyperref and algorithm package.

If algorithm is loaded after hyperref, any \label{alg:myalgorithm} statements ends up faulty in the .aux file (it contains a spurious \theAlgorithm statement). This causes the above error if latex is run the second time (when it includes the faulty aux file).

See also hyperref README file (Section 6 on Package Compatibility).

Solution: hyperref must be loaded before algorithm, but after float.

\usepackage{float}
\usepackage{hyperref}
\usepackage{algorithm}

Hyperref and Algorithmic

Error:

pdfTeX warning (ext4): destination with the same identifier (name{ALC@rem.1}) has been already used, duplicate ignored

If you include multiple algorithms in your document, the labels for the line numbers are the same for each algorithm, and the hyperref package complains about that.

See also fix hyperref warnings with line numbers

Solution: this is a bug in the algorithmic package. The above website contains a page against algorithmic version of 2006/06/02. Below is the diff. Copy this to a file, save as algorithmic.diff and apply using diff < algorithmic.diff (of course after you made a backup of the original algorithmic.sty):

--- algorithmic.sty     2006-06-02 00:00:00.000000000 +0000
+++ algorithmic.sty     2006-12-15 00:00:00.000000000 +0000
@@ -16,7 +16,7 @@
 % Boston, MA  02111-1307, USA.
 %
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{algorithmic}[2006/06/02]
+\ProvidesPackage{algorithmic}[2006/12/15]
 \typeout{Document Style `algorithmic' - environment}
 %
 \RequirePackage{ifthen}
@@ -26,6 +26,7 @@
 \setboolean{ALC@noend}{false}
 \newcounter{ALC@line}
 \newcounter{ALC@rem}
+\newcounter{ALC@unique}
 \newcounter{ALC@depth}
 \newlength{\ALC@tlm}
 %
@@ -128,7 +129,19 @@
     }
   }
   {\end{list}}
-  \newcommand{\ALC@it}{\refstepcounter{ALC@rem}\refstepcounter{ALC@line}\ifthenelse{\equal{\arabic{ALC@rem}}{#1}}{\setcounter{ALC@rem}{0}}{}\item\ALC@setref}
+  \newcommand{\ALC@it}{\@ifundefined{href}{% if not hyperref then do a simple refstepcounter
+    \refstepcounter{ALC@rem}%
+}{% else if hyperref, do the anchor so 2 lines in two differents algorithms cannot have the same href
+   
+\stepcounter{ALC@unique}\stepcounter{ALC@rem}\Hy@raisedlink{\hyper@anchorstart{ALC@rem\theALC@unique.\theALC@rem}\hyper@anchorend}%
+}%
+\@ifundefined{href}{% if not hyperref then do a simple refstepcounter
+    \refstepcounter{ALC@line}%
+}{% else if hyperref, do the anchor so 2 lines in two differents algorithms cannot have the same href
+   
+\stepcounter{ALC@unique}\stepcounter{ALC@line}\Hy@raisedlink{\hyper@anchorstart{ALC@line\theALC@unique.\theALC@line}\hyper@anchorend}%
+}%
+\ifthenelse{\equal{\arabic{ALC@rem}}{#1}}{\setcounter{ALC@rem}{0}}{}\item\ALC@setref}
   \newcommand{\ALC@com}[1]{\ifthenelse{\equal{##1}{default}}%
 {}{\ \algorithmiccomment{##1}}}
   \newcommand{\REQUIRE}{\item[\algorithmicrequire]}

Algorithms and Pseudocode

Errors:

Command \RETURN already defined
Command \TRUE already defined
Command \FALSE already defined
Command \AND already defined
Command \OR already defined
Command \NOT already defined
Command \TO already defined
Command \COMMAND already defined
Command \IF already defined

etcetera.

Both packages have very similar goals, and define macros with the same name.

Neither the pseudocode nor the algorithms package has provisions to cope with this name clash.

The easiest solution is simply not to use both packages in the same document, but pick a single package for all pseudo-code in your document.

PGF and double subscripts

Error:

Latex Error: ./mydocument.tex:8 Double subscript.

Strangely enough, this may be caused by an older version of the pgf package. (Strange because PGF is a draw package, and I did not expect it to interfere with mathematical equations).

The following code is a minimal example that throws the error just after the second \sum_ statement.

\documentclass{article}
\usepackage{pgf}

\begin{document}

The grand total is:
\begin{equation}
s = \sum_{y} \: \sum_{x} x*y
\end{equation}

\end{document}

Solution: PGF version 1.10 exhibits this behaviour. Upgrade to a newer version (PGF 2.00 works fine for me), or simply slightly change the formula. Simply changing the spacing from \: to \; solves the problem as well. (Please don't ask my why. The cause of this particular LaTeX magic is well over my head.)

XeLaTeX with pdftex driver

Error:

hpdftex.def:442 Undefined control sequence.

with line causing the error:

\pdfoutput=1


If you use xelatex instead of pdflatex as the typesetting program, and you specify pdftex as the driver for some packages:

%!TEX TS-program = xelatex

\usepackage[pdftex]{graphicx}
\usepackage[pdftex]{hyperref}

This is in conflict. XeTeX does not work properly with the pdftex driver. Instead, specify xetex as the driver:

%!TEX TS-program = xelatex

\usepackage[xetex]{graphicx}
\usepackage[xetex]{hyperref}

Note: The default driver has changed from xdv2pdf to xdvipdfmx in XeTeX 0.997. The xetex option works fine in XeTeX 0.996 or earlier, or in XeTeX 0.999 or higher. If you use version 0.997 and you have problems, you may want to explicitly specify \usepackage[dvipdfmx]{hyperref}.

XltXtra and Graphicx

Error:

LaTeX Error: Option clash for package graphicx.

The xltxtra (which loads fontspec, xunicode and defines the \xetex shortcut) does also load the graphicx package. However, it does not specify any options, so if you later load the graphicx package with options, this does conflict each other.

\usepackage{xltxtra}
\usepackage[xetex]{graphicx}

There are two solutions. The first is to simply not load the graphicx package anymore, or don't specify any options either:

\usepackage{xltxtra}
\usepackage{graphicx}

The second, and better, solution is to load the graphicx package before loading the xltxtra package.

\usepackage[xetex]{graphicx}
\usepackage{xltxtra}

Unicode in Listing

Error:

Latex Error: ./mydocument.tex:727 Package inputenc Error: Unicode char \u8:�\lst@EC� not set up for use with LaTeX.

Line 727 contained a ø character in a listing. Replacing it with \o did not work. Another common solution is to declare ø a special character as such:

\DeclareUnicodeCharacter{F8}{\o}

This did not work either. The \lst should have been a give-away. The listing package by default borks at non-ASCII characters.

Solution (works only for single-byte characters, not for all Unicode characters!):

Explain to listing how to display the required characters:

\usepackage{listings}
\lstset{extendedchars=true,literate={ø}Template:\o1}

For the exact syntax of the literate parameter, see the explanation by Philippe Goutet.

This is only a work-around, as extendedchars=true may interfere with the Unicode processing of other packages, and most likely won't work for multi-byte characters.

The following would -theoretically- be a better solution:

\usepackage{listingsutf8}
\lstset{inputencoding=utf8,extendedchars=false}

Unfortunately, the result was that my line København was changed to øKenhavn in the PDF file. It did display the ø character, alright, but not as I expected...

If you need multibyte characters in your listing, your best option is to escape to LaTeX, as explained in the listings documentation.

Amssymb with Xunicode

Error:

Latex Error: /opt/local/share/texmf-dist/tex/latex/amsfonts/amssymb.sty:252 Command `\Finv' already defined.

Solution: include amssymb before xunicode:

\usepackage{amssymb}
\usepackage{xunicode}

Note that if you include xltxtra, that automatically includes xunicode, so amssymb should also go before xltxtra:

\usepackage{amssymb}
\usepackage{xltxtra}    % xltxtra includes xunicode

Caption and Subfig

Error:

Option clash for package caption.

The caption package has already been loaded by some other LaTeX package, so you can’t do that again specifying different options. Likely, you already included the subfig package. The solution is to load cation before subfig:

\usepackage[format=plain,labelfont=bf,up,textfont=it,up]{caption}
\usepackage{subfig}

TOCLoft and Subfig

Error:

Latex Error: tocloft.sty:609 Command \c@lotdepth already defined.

TOCLoft and subfig conflict. The solution is to specify subfig as an option to tocloft:

\usepackage{subfig}
\usepackage[titles,subfigure]{tocloft}


XeTeX and titletoc

XeLaTeX and titletoc conflict:

\usepackage{titletoc}
\dottedcontents{section}[2.3em]{\vspace{3px}\sffamily}{1.5em}{1pc}
\tableofcontents

The \contentsline line in the .toc file gives the error:

   ! Illegal unit of measure (pt inserted).

No solution is known to me (let me know if you found one!).

A work-around is to use the tocloft package instead of the titletoc package. Make sure to specify the "titles" options if you combine it with the titlesec package:

\usepackage[titles]{tocloft}

XeTeX and Inputenc

The inputenc package should not be used in XeTeX. This is wrong:

\usepackage[utf8]{inputenc}

XeTeX always expects UTF-8 input, so it is not only redundant to specify the inputenc package, but also incorrect: inputenc changes the way that unicode text is parsed, giving incorrect behaviour for non-ascii input.

XeLaTeX and Babel

I am told that Babel is not compatible with XeLaTeX.

\usepackage[german]{babel}

\font\wsc="Arno Pro"

gives the following error:

! Font \wsc= not loadable: Metric (TFM) file or installed font not found.

The Babel package changes the meaning (\catcode) of the " character, to become active so as to provide the shorthand way to get umlauts (e.g., "o instead of \"o).

For this reason, as well as poor hyphenation support, babel is not recommended in conjunction with XeTeX. That said, I could not reproduce this problems, so you can just try and see what happens. If you experience problems, there are two solutions.

Use fontspec's \setmainfont or \fontspec instead of \font, to avoid using quote (") characters.

\usepackage[german]{babel}
\usepackage{fontspec}

\setromanfont{Arno Pro}

Use polyglossia instead of babel. Babel is considered a mess, and Polyglossia was developed specifically with XeTeX in mind.

\usepackage[german]{polyglossia}
\usepackage{fontspec}

\setromanfont{Arno Pro}

Hyperref and fncychap

Error:

In the PDF Table of Contents, the link and page number for Appendix 1 points to Chapter 1, even though the name is correct.

This is caused by an incompatibility between hyperref and fancychapter. The solution is to load hyperref after fncychap:

\usepackage[PetersLenny]{fncychap}
\usepackage[plainpages=false,pdfpagelabels]{hyperref}


Fancy Chapters (fncychap) and Polyglossia

You can set the style of chapter headers using the fncychap package.

\usepackage{fncychap}
\ChTitleVar{\Huge\bfseries\sffamily}  % Use Sans Serif for chapter titles

Error:

All chapter headers are in sans serif font, except for the table of contents, index and bibliography header, which are still in roman font.

This is caused by a bug in Polyglossia (a Babel replacement package).

Either still use Babel instead of Polyglossia (and face Babel's quirks), or redefine captionsenglish, captiongerman (or whatever language you choose) as a work-around.

\usepackage{polyglossia}  % babel replacement that is compatible with XeTeX
\setdefaultlanguage[variant=british]{english}
\setotherlanguage[]{dutch}

\def\captionsenglish{%
  \def\prefacename{Preface}%
  \def\refname{References}%
  \def\abstractname{Abstract}%
  \def\bibname{Bibliography}%
  \def\chaptername{Chapter}%
  \def\appendixname{Appendix}%
  \def\contentsname{Contents}%
  \def\listfigurename{List of Figures}%
  \def\listtablename{List of Tables}%
  \def\indexname{Index}%
  \def\figurename{Figure}%
  \def\tablename{Table}%
  \def\partname{Part}%
  \def\enclname{encl}%
  \def\ccname{cc}%
  \def\headtoname{To}%
  \def\pagename{Page}%
  \def\seename{see}%
  \def\alsoname{see also}%
  \def\proofname{Proof}%
}

Height of Link Boxes is Too High

Error:

The border around borders around links, as created by hyperref is too high. This looks bad.

This is caused by the Latin Modern font. The Computer Modern font looks better (see screenshot).

Borderheight.png

This problem is caused by a difference in the ascender and descender in the two fonts in combination with the way the xdvipdfmx (as used by XeTeX) calculates the box height. No good solution exists yet.

David Jones analyzed this problem. It turns out that ascender and descender in Latin Modern is larger than in Computer Modern. Unfortunately, the xdvipdfmx engine seems to calculate the box height based on the ascender and descender of the font, rather then the line height or the height of the actual glyphs in the link.

So the solution is to either use a different engine or use a different font. If that is not an option, live with it or modify (the source code of) xdvipdfmx. (Please let me know if you found a patch for xdvipdfmx, or let me know if is working fine for you with a newer version of Latin Modern or xdvipdfmx.)

XeTeX 0.996, fontspec and Latin Modern

Error:

Random characters (garbled text) when using the fontspec package.

First of all, make sure you specified fonts for all font families: roman, serif and monospaced:

\usepackage{fontspec}   % OpenType/TrueType font support. Requires XeTeX.
% CMU = Computer Modern Unicode, see https://cm-unicode.sourceforge.net/
\defaultfontfeatures{Mapping=tex-text}
\setmainfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}

Latin Modern is an extension to the older Computer Modern font set, and is the default font in the fontspec package. However, the naming convention of Latin Modern (lm) changed around the time TexLive 2007 came out. If you use Latin Modern with TexLive 2007, you will get the random characters in the output file. In order to fix this, either use another font, such as Computer Modern Unicode (CMU) or upgrade to a newer version of XeTeX and the fontspec package.

Enable Small Capitals with Fontspec

Error:

Latin Modern does not have small capitals. (\textsc{Small Capitals} does not work).

If you use XeTeX and fontspec, you need to specify which font XeTeX uses for small capitals. For Latin Modern Roman, that is Lation Modern Roman Caps, and for Latin Modern Mono, that is Latin Modern Mono Caps. Latin Modern Sans does not have a small capital variant.

\usepackage{fontspec}
\setmainfont[SmallCapsFont={* Caps}]{Latin Modern Roman}
\setsansfont{Latin Modern Sans}  % There is no small caps variant
\setmonofont[SmallCapsFont={Latin Modern Mono Caps}]{Latin Modern Mono Light}

Bold Typewriter is Not Bold

Error:

\texttt{Typewriter \textbf{Bold}} gives normal (not bold) text.

The standard LaTeX typewriter (Computer Modern) font does not have a distinguishable bold variant. Neither does the replacement font Latin Modern.

See LaTeX Bold Typewriter Font how to solve this.

Output File Removed

If you run XeTeX, and no PDF file is created and the output gives the notice:

Output file removed.

If you see this, you can get more details by splitting the run process in two:

xelatex --no-pdf test
xdvipdfmx test.xdv

or (depending on your default driver):

xelatex --no-pdf test
xdv2pdf test.xdv

The xdvipdfmx or xdv2pdf driver typically gives a more detailed error message. (see next entry.)

Failed to Find Font

Error:

xdv2pdf <Error>: can't find font object for font id 2949602.
xdv2pdf <Error>: WARNING: Type1 font data returned by OFAStreamPSDownload isn't in the correct format required by the Adobe Type 1Font Format specification.
xdv2pdf <Error>: ATSFontGetPostScriptName failed: error -984.
ttf_create_with_id: failed to find font object for id 2949602.
xdv2pdf <Error>: WARNING: --font-2949602-6--: missing or invalid font descriptor.

All these errors are caused by xdv2pdf, which is a relative old driver for XeTeX. You are recommended to use the xdvipdfmx driver, which is the default since XeTeX 0.999.7 (present in TexLive 2008 or later). Alternatively, specify the driver explicitly (though you may need to install it first):

xelatex -output-driver=xdvipdfmx test

or:

xelatex --no-pdf test
xdvipdfmx -vv test.xdv

Warning:

WARNING: Type1 font data returned by OFAStreamPSDownload isn't in the correct format required by the Adobe Type 1Font Format specification.

If you only get the above warning, you can safely ignore it, as the output will look good. The cause of this error is yet unknown. The solution according to the XeTeX site is to use a different Font. However, I got the same problem with all sort of fonts.

If you get the other errors about missing fonts, your document will not look good. While at first sight it may look good, I found that some texts are missing in pictures and formulas.

Invalid Font Description

Error:

** WARNING ** Found file "/Library/Fonts/Optima.dfont" for PFB font but it doesn't look like a PFB...
*** ERROR ** Invalid font: -1 (0)

or:

** ERROR ** Cannot proceed without the "native" font: CMUSerif-Roman (CMU Serif Roman)...

If you encounter the above errors, first of all, make sure you use a recent version of XeTeX. I encountered to above errors with version 0.999.6, while version 0.999.7 and higher works fine.

If you still get the errors with XeTeX 0.999.7 or higher, run

xelatex --no-pdf test
xdvipdfmx -vv test.xdv

And examine the output and log files. Perhaps a font is not found or could not be loaded.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox