# Error message when displaying algorithm

MWE below. I am working on my Bachelor's thesis and have been stuck with these errors for quite a while. They produce almost the correct output but the numbers of the lines are always zero and I get these errors. The errors, my Packages, and my code is below:

! Missing \endcsname inserted. \ALG@currentblock@0 l.35 \If {$Med(q_{-i}) > p_i$} The control sequence marked should not appear between \csname and \endcsname.

! Extra \endcsname. \ALG@makebeginrepeat ...\ALG@thisblock \endcsname \relax \def \ALG@thisblock... l.35 \If {$Med(q_{-i}) > p_i$} I'm ignoring this, since I wasn't doing a \csname.

! Package algorithmicx Error: Some blocks are not closed!!!.

See the algorithmicx package documentation for explanation. Type H for immediate help. ...

l.57 \end{algorithmic} This error message was generated by an \errmessage command, so I can't give any explicit help. Pretend that you're Hercule Poirot: Examine all clues, and deduce the truth by order and method.

Packages:

\usepackage[latin1]{inputenc}  \usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{multirow}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{tikz}
\usepackage{array}
\usepackage{scrhack}
\usepackage{listings}
\usepackage{pdfpages}
\usepackage{placeins}
\usepackage{textcomp}
\usepackage{comment}
\usepackage[raiselinks=true, bookmarks=true, bookmarksopenlevel=1, bookmarksopen=true, bookmarksnumbered=true, hyperindex=true, plainpages=false,


Code:

\begin{algorithm} \caption{Best Response under median-rule} \begin{algorithmic}   \If {$Med(q_{-i}) > p_i$}   \If {$n_q$ is even}  \If {$q_{Med-} > p_i$}
\State ideal vote $\leq q_{Med-}$    \ElsIf{$q_{Med-} \leq p_i$}
\State ideal vote $= p_i$   \ElsIf{$n_q$ is odd}
\If {$\frac{q_{Med-} + Med(q_{-i})}{2} > p_i$}
\State ideal vote $\leq q_Med-$
\ElsIf{$\frac{q_{Med-} + Med(q_{-i})}{2} \leq p_i$}
\State ideal vote $= Med(q_{-i}) - 2*(Med(q_{-i}) - p_i)$            \ElsIf{$Med(q_{-i}) \leq p_i$}       \If {$n_q$ is even}    \If {$q_{Med+} < p_i$}
\State ideal vote $\geq q_{Med+}$    \ElsIf{$q_{Med+} \geq p_i$}
\State ideal vote $= p_i$               \ElsIf{$n_q$ is odd}
\If {$\frac{q_{Med+} + Med(q_{-i})}{2} < p_i$}
\State ideal vote $\geq q_{Med+}$
\ElsIf{$\frac{q_{Med+} + Med(q_{-i})}{2} \geq p_i$}
\State ideal vote $= Med(q_{-i}) + 2*(p_i - Med(q_{-i}))$
\end{algorithmic} \end{algorithm}


Minimal Working Example:

\documentclass{thesis}
\usepackage{algorithm}
%\usepackage{algorithmic}
%\usepackage{algorithmicx}
\usepackage{algpseudocode}
\begin{document}
\pagenumbering{roman}

\begin{algorithm}
\caption{Best Response under median-rule}
\begin{algorithmic}
\If {$Med(q_{-i}) > p_i$}
\If {$n_q$ is even}
\If {$q_{Med-} > p_i$}
\State ideal vote $\leq q_{Med-}$
\ElsIf{$q_{Med-} \leq p_i$}
\State ideal vote $= p_i$
\EndIf
\ElsIf{$n_q$ is odd}
\If {$\frac{q_{Med-} + Med(q_{-i})}{2} > p_i$}
\State ideal vote $\leq q_Med-$
\ElsIf{$\frac{q_{Med-} + Med(q_{-i})}{2} \leq p_i$}
\State ideal vote $= Med(q_{-i}) - 2*(Med(q_{-i}) - p_i)$
\EndIf
\EndIf
\ElsIf{$Med(q_{-i}) \leq p_i$}
\If {$n_q$ is even}
\If {$q_{Med+} < p_i$}
\State ideal vote $\geq q_{Med+}$
\ElsIf{$q_{Med+} \geq p_i$}
\State ideal vote $= p_i$
\EndIf
\ElsIf{$n_q$ is odd}
\If {$\frac{q_{Med+} + Med(q_{-i})}{2} < p_i$}
\State ideal vote $\geq q_{Med+}$
\ElsIf{$\frac{q_{Med+} + Med(q_{-i})}{2} \geq p_i$}
\State ideal vote $= Med(q_{-i}) + 2*(p_i - Med(q_{-i}))$
\EndIf
\EndIf
\EndIf
\end{algorithmic}
\end{algorithm}

\bibliographystyle{apalike} % german style

% Use IEEEtran for numeric references
%\bibliographystyle{IEEEtranSA})

\bibliography{thesis}

\end{document}

• Can you please make a minimal working example (MWE)? – user36296 Oct 18 '18 at 11:40
• I did, if I simplify that much everything works fine with no errors. There must be some issue with another package or something. – NikNet Oct 18 '18 at 11:59
• Maybe this could help: in the MWE there is no numbering of rows which seems to be closely related to the problem. – NikNet Oct 18 '18 at 12:14
• No error if I use report instead of thesis (which I don't have and don't know where to find). – egreg Oct 18 '18 at 12:40
• thesis.cls isn't generally available (or more exactly there are thousands of local classes of that name) please use use a standard class, or if the problem is only with that class, you need to post that class here as we can't debug code we can't see... – David Carlisle Oct 18 '18 at 20:46

I found the problem, thesis.cls included packages algorithmic and algpseudocode which produced the errors together. I took out algorithmic and now it works like a charm.