5

I'm trying to write simple pseudocodes using package algorithmicx in TexWorks 0.4.4 and MiKTex 2.9 on Windows 7 but I get this error:

! 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.39  \State
             $sum\gets 0$

My document is pasted below, what's wrong with it?

\documentclass{article}
\usepackage{algorithmicx}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{algpascal}
\usepackage{algc}
\usepackage{algcompatible}
\usepackage[utf8]{inputenc}
\usepackage[brazilian]{babel}

\title{Pseudocódigos}
\author{}
\date{}

\begin{document}

\maketitle

\tableofcontents

\section{Introdução}

\section{Pilha}

\subsection{Empilhar}

Oia.

Just testing

\begin{algorithm}
\begin{algorithmic}[1]
\Procedure {Termial}{$n$}
 \State $sum\gets 0$
 \State $i\gets 1$
 \While{i\le n}
   \State $sum\gets sum+i$
   \State $i\gets i+1$
\EndWhile
\EndProcedure
\end{algorithmic}
\end{algorithm}

\subsection{Desempilhar}

\end{document} 
1
  • 2
    Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. Commented Jun 13, 2013 at 19:30

1 Answer 1

7

After some investigative work, I found that,

  • loading algpseudocode after algcompatible, and
  • adding inline-math delimiters ($) that are missing in your \While,

solves the problem; your input file now compiles without mishap (for me, anyway).

enter image description here

\documentclass{article}

\usepackage{algorithmicx}
\usepackage{algorithm}
\usepackage{algpascal}
\usepackage{algc}
\usepackage{algcompatible}
\usepackage{algpseudocode}
\usepackage[utf8]{inputenc}
\usepackage[brazilian]{babel}

\title{Pseudocódigos}
\author{}
\date{}

\begin{document}

\maketitle
\tableofcontents

\section{Introdução}
\section{Pilha}
\subsection{Empilhar}

Oia. Just testing

\begin{algorithm}
\begin{algorithmic}[1]
\Procedure {Termial}{$n$}
 \State $sum\gets 0$
 \State $i\gets 1$
 \While{$i\le n$}
   \State $sum\gets sum+i$
   \State $i\gets i+1$
\EndWhile
\EndProcedure
\end{algorithmic}
\end{algorithm}

\subsection{Desempilhar}

\end{document} 
2
  • 2
    +1 One day that error message will be generated by a missing \item. One day, perhaps. Commented Jun 13, 2013 at 19:58
  • Wow, that's crazy. Took me hours and turned out I just need to relocate algpseudocode
    – chepukha
    Commented Nov 19, 2015 at 6:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .