Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Stuggling with the following problem for a small while and am stumped. I'm using the the elsart3p.cls document class, but it seems not to work well with the algorithmic package. Here's a minimal working example:

\documentclass{elsart3p} %also doesn't work with elsart
\usepackage{algorithmic}
\usepackage{algorithm}

\begin{document}

\begin{algorithm}[ht]
\begin{algorithmic}[1]
\REQUIRE help?
\end{algorithmic}
\caption{Algorithm}
\label{alg:test}
\end{algorithm}

\end{document}

When compiling using latex or pdflatex, I get a single error (per \begin{algorithmic} for each algorithm):

LaTeX Error: Command \AND already defined

...but the output looks okay. Usually I wouldn't mind too much, but I'll be passing on sources.

Anyone got any ideas for a workaround? I have a good few algorithms, so not keen on moving to another package (plus, I was never a big fan of algorithmic2e... too many braces give me vertigo).

I know this question isn't exactly blockbuster Hollywood material, but any help much appreciated!

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

The elsart3p class internally loads the elsart class, and the latter defines \AND as \&; the algorithmic package also defines \AND but with a different meaning, so these two definitions collide (that's why you get the error message included in your question). One possible solution is to use the savesym package to rename one of the two colliding names: using \savesymbol{AND} before loading the algorithmic package, renames the \AND command from the elsart as \origAND, avoiding the name clash:

\documentclass{elsart3p}
\usepackage{savesym}
\savesymbol{AND}
\usepackage{algorithmic}
\usepackage{algorithm}

\begin{document}

\begin{algorithm}[ht]
\begin{algorithmic}[1]
\STATE solved!
\end{algorithmic}
\caption{Algorithm}
\label{alg:test}
\end{algorithm}

\end{document}

On a side note, perhaps the algorithmicx package could be of interest for you.

share|improve this answer
    
Works like a charm! Many thanks! –  badroit Jun 2 '11 at 13:10
    
Thanks a lot! it works perfect. –  user15833 Jun 21 '12 at 18:26
    
Adding the two sentences of "\usepackage{savesym} \savesymbol{AND}" indeed solves the problem. Actually, it also solves the errors of using algorithm package in the autart.cls. –  datcn Jan 20 at 8:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.