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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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 '14 at 8:19

protected by Kurt Oct 28 '15 at 2:34

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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