# How to combine algorithm and algorithm2e in one document?

by Nasser   Last Updated October 20, 2019 03:23 AM - source

I got myself in big trouble and I can't get out of it.

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 \[email protected]
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.

*File List*
article.cls    2014/09/29 v1.4h Standard LaTeX document class
size11.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
amsmath.sty    2013/01/14 v2.14 AMS math features
amstext.sty    2000/06/29 v2.01
amsgen.sty    1999/11/30 v2.0
amsbsy.sty    1999/11/29 v1.2d
amsopn.sty    1999/12/14 v2.01 operator names
algorithm.sty    2009/08/24 v0.1 Document Style algorithm' - floating
float.sty    2001/11/08 v1.3d Float enhancements (AL)
ifthen.sty    2014/09/29 v1.1c Standard LaTeX ifthen package (DPC)
algorithmicx.sty    2005/04/27 v1.2 Algorithmicx
algpseudocode.sty
algorithm2e.sty    2013/01/06 v5.00 algorithms environments
xspace.sty    2014/10/28 v1.13 Space after command names (DPC,MH)
relsize.sty    2013/03/29 ver 4.1

Tags :