Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to combine algorithm and algorithm2e packages in one document?

1,133 views
Skip to first unread message

Nasser M. Abbasi

unread,
Apr 21, 2016, 1:42:21 PM4/21/16
to
hi;
I asked this question at tex.stackexchange but got no answer. So
it might not be possible to do. I thought to ask here to see
if someone might have a hint.

The question is here:
http://tex.stackexchange.com/questions/305293/how-to-combine-algorithm-and-algorithm2e-in-one-document

Summary:
I need to build a document from number of files, where one
uses algorithm package and the other uses algorithm2e. These
two packages seems to have an incompatibility issue.

Details: (copy of my question above)
I use standalone package to combine different latex files into one.
Each Latex file compiles OK on its own. When I combined them, I
found a conflict, since I used algorithm2e in one file and used
algorithm in another to type different algorithms. With standalone
one must include the union of all packages used in all the files.
So I have to include both packages now. I am stuck now. I do not
want to rewrite the algorithm I did, as it took long time.

Here is a MWE

-----------------
documentclass[11pt]{article}%
\usepackage{amsmath}
\usepackage[linesnumbered,ruled,lined,boxed,algo2e]{algorithm2e}
\usepackage{algorithm,algorithmicx,algpseudocode}
\begin{document}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\If {$i\geq 1$}
\State $i\gets 0$
\Else
\State $i\gets 2$
\EndIf
\end{algorithmic}
\end{algorithm}
\end{document}
-------------------------------

And the error is

------------------------------
pdflatex foo.tex
Document Style algorithmicx 1.2 - a greatly improved `algorithmic' style
) (/usr/local/texlive/2015/texmf-dist/tex/latex/algorithmicx/algpseudocode.sty
Document Style - pseudocode environments for use with the `algorithmicx' style
) (./foo.aux)
! You can't use `\prevdepth' in horizontal mode.
\nointerlineskip ->\prevdepth
-\@m \p@
l.13 \State $
i\gets 0$
?
-----------------------

if I comment out algorithm2e it compiles OK. But again, I have
to include both in the master document since it using standalone
to combine many different latex files and one of the other
files (not shown here) needs algorithm2e.

Any way to handle this situation? I am using TL 2015. note
that I also have to use pdflatex and not lualatex, since
algorithm2e does not compile with lualatex.

any ideas how to do this? I might have to re-write the
algorithms again using one package.

TexLive 2015 on Linux.

thanks
--Nasser


0 new messages