[Tex/LaTex] algorithm2e missing document thestery

algorithm2einstallingpackages

I am trying to use the algorithm2e package. I downloaded the package from CTAN and verified that I can typeset its own documentation (algorithm2e.tex). I then try to write my own document that uses algorithm2e, as follows

\documentclass[12pt]{amsart}
\usepackage{algorithm2e}
\begin{document}
test
\end{document}

This TeX file is in the same directory as all the algorithm2e files that I copied from the web. I blew away all the aux files and other temporaries.

I get Latex error: Missing documentSee the LaTeX manual... etc. I have tried this under TeXWorks, TeXShop, and Texmaker on a Mac Book Pro, all with the same results. I have read the detailed log and output of TeX trying to figure out what TeX thinks is missing, and I haven't found it. Every other document I have tried to typeset works out ok.

If I take out the \usepackage{algorithm2e} command, everything is ok. I also have had no trouble using many other packages, such as

\usepackage[all]{xy}
\usepackage{noindent}
\usepackage{multirow}
\usepackage{amssymb,amsmath,latexsym,amsbsy,comment,pifont}
\usepackage{amscd}
\usepackage{palatino}
\usepackage{stmaryrd}
\usepackage{eulervm}
\usepackage{fullpage}
\usepackage[usenames,dvipsnames]{color}
\usepackage{fancybox}
\usepackage{graphicx}

All ok. The only one that seems to cause problems is algorithm2e, and only in my OWN document. To reiterate, it works great when typesetting its own documentation. I tried putting the following in every position in that block of usepackage commands

\usepackage[vlined]{algorithm2e}

it didn't matter where I put it, it generates the same error.

I've boiled this down into the smallest example I can make and I'm stumped.

Best Answer

The problem is caused by the relsize package (internally loaded by algorithm2e); the former package is incompatible with the AMS document classes; processing the following document:

\documentclass[12pt]{amsart}
\usepackage{relsize}
\begin{document}
test
\end{document}

produces the exact problem mentioned in the question; the process ends with many warnings and the obtained .pdf is the following:

enter image description here

To prevent this from happening, load the algorithm2e package with the norelsize package option, as in:

\usepackage[norelsize]{algorithm2e}

A complete example:

\documentclass[12pt]{amsart}
\usepackage[norelsize]{algorithm2e}

\begin{document}

\begin{algorithm}[H]
\SetAlgoLined
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
read current\;
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms}
\end{algorithm}

\end{document}

enter image description here

Perhaps the algorithmicx package could be of interest for you (it provides many possibilities to customize the layout of algorithms) to be used instead of algorithm2e.