LaTeX package conflicts

From Exterior Memory
Revision as of 20:03, 4 January 2009 by MacFreek (Talk | contribs) (Bold Typewriter)

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...)

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 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]}

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.

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: this works fine for XeTeX 0.996-patch1. Up till XeTeX 0.996, the default graphics driver for Mac OS X was xdv2pdf. However, since XeTeX 0.997 this has changed to xdvipdfmx for all platforms. For what I understand, the option [xetex] selects the xdv2pdf driver, while the option [dvipdfmx] selects the xdvipdfmx driver. If you use a newer version of XeTeX, let me know what works for you!

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 pacakage. 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}

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

Fontspec and Inputenc

The following is completely redundant:

\usepackage[utf8]{inputenc}
\usepackage{fontspec}

The fontspec package requires XeTeX or xelatex to run. XeTeX always expects UTF-8 input, so it is completely redundant to specify that using the inputenc package. While I have not seen any error, I'm told that this may cause unexpected behaviour. If you use fontspec, you should not use inputenc. Also, I'm told that fontspec and babel packages don't mix well. If you still want more explicit unicode support, have a look at the xunicode package instead (though I found that even without, you can simply type any UTF-8 character which are all understood by XeTex).

\usepackage{fontspec}
\usepackage{xunicode}

or nearly equivalent:

\usepackage{xltxtra}   % loads graphicx, fontspec, xunicode and others

XeTeX 0.996, fontspec and Latin Modern

Error:

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

Latin Modern is an extension to the older Computer Modern font set. It is loaded by default by the fontspec package. However, the naming convention of Latin Modern (lm) changed around the time TexLive 2007 came out. This causes 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 fontspect package.

Disclaimer: I haven't tried the last solution yet.

Bold Typewriter

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.

LaTeX distinguishes between three font families:

  • Roman (serif)
  • Sans-serif
  • Typewriter (monospaced or fixed character width)

Furthermore, each font has multiple variants, either variants in series or shapes, or combination thereof:

Series
medium and bold (others such as condensed, semi-bold and bold-extended are less common)
Shapes
Normal, italic, slanted, small capitals

The solution is to change the font variant that is associated with typewriter bold. This can be done by either changing the font variant of only the bold variant, or by simply changing the whole font for the typewriter series. The details of using a different font altogether depends if you use TFM fonts (regular LaTeX) or OpenType/TrueType fonts (using xetex/fontspec).

Change the Monospace Bold Variant

In LaTeX, one can declare cmttb10 as a boldface version of cmtt and then use it with the standard \texttt and \textbf commands.

\documentclass{article}
\DeclareFontShape{OT1}{cmtt}{bx}{n}{
  <5><6><7><8><9><10><10.95><12><14.4><17.28><20.74><24.88>cmttb10}{}
\begin{document}
\texttt{Normal and \textbf{bold Typewriter.}}
\end{document}

(source http://wiki.contextgarden.net/Bold_typewriter)

Different Font for Monospace using TFM Fonts

To change the font for Monospace series, use \renewcommand:

\renewcommand{\ttdefault}{pcr}

The above sets the font to pcr, which is commonly know as Courier. The courier package does exactly this, but in a much more readable and user-friendly way:

\usepackage{courier}

Different Font for Monospace using OpenType/TrueType Fonts

If you use TrueType fonts, simply choose a TrueType fonts which has better distinction between plain and bold.

(Todo: write down how this is done)

This article is unfinished.

Type1 Font Error

Error:

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

Unknown yet

This article is unfinished.