TransWikia.com

I get the error " You can't use `prevdepth` in horizontal mode" while using `algorithm2e` package

TeX - LaTeX Asked on February 19, 2021

I use a separate .tex file for every section in my document.
One of these documents require an algorithm to be written. I use algorithm2e package to do so.

Here is my MWE (algorithm is taken from this website):

%!TeX root = Section2

%Section 2
documentclass[crop=false]{standalone}
usepackage{enumerate,tikz}
usepackage[ruled,linesnumbered,vlined]{algorithm2e}

begin{document}
    
subsection{Simple algorithm}
begin{algorithm}
KwIn{A sequence of integers $langle a_1, a_2, ldots, a_n rangle$}
KwOut{The index of first location witht he same value as in a previous location in the sequence}
$location gets 0$;
$i gets 2$;
While{$i leq n$ textbf{and} $location = 0$}{
    $j gets 1$;
    While{$j < i$ textbf{and} $location = 0$}{
        % The "u" before the "If" makes it so there is no "end" after the statement, so the else will then follow
        uIf{$a_i = a_j$}{
            $location gets i$;
        }
        Else{
            $j gets j + 1$;
        }
    }
    $i gets i + 1$;
}
Return{location};
caption{{sc FindDuplicate}}
label{algo:duplicate}
end{algorithm}

        subsection{Advanced algorithm}
    end{document}

The output of the algorithm looks like this:
enter image description here

The indentations and the line numbers are all messed up.
Below are the error messages I get, and I assume the main problem is so called prevdepth command which is used somewhere automatically and causes incompatibility with some other environment.

! You can't use `prevdepth' in horizontal mode.
nointerlineskip ->prevdepth 
                              -@m p@ 
l.70    Return
             {$max$};
! Missing $ inserted.
<inserted text> 
                $
l.70    Return
             {$max$};
! Missing number, treated as zero.
<to be read again> 
                   advance 
l.70    Return
             {$max$};
! Illegal unit of measure (pt inserted).
<to be read again> 
                   advance 
l.70    Return
             {$max$};
! You can't use `moveright' in math mode.
algocf@push ...dvance skiptotal by #1moveright 
                                                  #1
l.70    Return
             {$max$};
! Missing number, treated as zero.
<to be read again> 
                   hbox 
l.70    Return
             {$max$};
! Illegal unit of measure (pt inserted).
<to be read again> 
                   hbox 
l.70    Return
             {$max$};
! Arithmetic overflow.
<recently read> p@ 
                    
l.70    Return
             {$max$};

Package relsize Warning: Size requested is too small.
(relsize)                Using 5.0pt instead on input line 70.

! Improper `at' size (0.0pt), replaced by 10pt.
<to be read again> 
                   relax 
l.70    Return
             {$max$};
! You can't use `prevdepth' in horizontal mode.
nointerlineskip ->prevdepth 
                              -@m p@ 
l.70    Return
             {$max$};
! Missing $ inserted.
<inserted text> 
                $
l.70    Return
             {$max$};
! Missing number, treated as zero.
<to be read again> 
                   advance 
l.70    Return
             {$max$};
! Illegal unit of measure (pt inserted).
<to be read again> 
                   advance 
l.70    Return
             {$max$};
! You can't use `moveright' in math mode.
algocf@push ...dvance skiptotal by #1moveright 
                                                  #1
l.70    Return
             {$max$};
! Missing number, treated as zero.
<to be read again> 
                   hbox 
l.70    Return
             {$max$};
! Illegal unit of measure (pt inserted).
<to be read again> 
                   hbox 
l.70    Return
             {$max$};
! Arithmetic overflow.
<recently read> p@ 
                    
l.70    Return
             {$max$};

Package relsize Warning: Size requested is too small.
(relsize)                Using 5.0pt instead on input line 70.

! Missing $ inserted.
<inserted text> 
                $
l.70    Return
             {$max$};

! LaTeX Error: Something's wrong--perhaps a missing item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.70    Return
             {$max$};
! Missing $ inserted.
<inserted text> 
                $
l.70    Return
             {$max$};

! LaTeX Error: Something's wrong--perhaps a missing item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.70    Return
             {$max$};

! LaTeX Error: Something's wrong--perhaps a missing item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.70    Return{$max$};
                      

! LaTeX Error: Something's wrong--perhaps a missing item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.71    caption{{sc Max} finds the maximum number}
                                                  

! LaTeX Error: Something's wrong--perhaps a missing item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.73 end{algorithm}
                    

Overfull hbox (15.0pt too wide) in paragraph at lines 73--73

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP