# undefined control sequences for algorithm2e package

I have some major and some minor issues while using algorithm2e.

For major issues, although the package itself defined some controls such as \input , \Fn etc., but when it comes to use them, I receive and error indicating these controls are not defined.

For minor issues, taking into account the following MWE, first of all the if clause does not have and ending which I wonder how I should fix it and secondly, for each line of comment, there is a weird ; at the beginning of the line:

    \documentclass{article}

\usepackage{algorithm2e}
\usepackage{algpseudocode}
\usepackage{pifont}
\usepackage{program}
\begin{document}
\IncMargin{1em}
\begin{algorithm}[H]

%\Input{A bitmap $Im$ of size $w\times l$}
%\Output{A partition of the bitmap}

\uIf{domain.equals(keyword) AND id=0}{
\tcc*[r]{occurrence at the root node (first layer)}
setAttribute(D,PN)\;
}\uElseIf{domain.equals(keyword) AND $id\not=0$}{ \tcc*[r]{occurrence at the second layer}
setAttribute(D,SL)\;
}
\uElseIf{path.equals(keyword) AND id=0}{ \tcc*[r]{occurrence at path of root node}
setAttribute($P_a$, PN)\;
}

\caption{How to write algorithms}
\end{algorithm}
\end{document}


In its documentation, package algorithm2e uses macro \SetKwInOut to define \Input and \Output. The following example also uses \If instead of \uIf to get the end markers (not sure, whether I have the question correctly). Also normal comments are used to get rid of the semicolon.

\documentclass{article}
\usepackage{algpseudocode}
\usepackage{pifont}
\usepackage{program}
\begin{document}
\IncMargin{1em}
\begin{algorithm}[H]
\SetKwInOut{Input}{input}
\SetKwInOut{Output}{output}

\Input{A bitmap $Im$ of size $w\times l$}
\Output{A partition of the bitmap}
\BlankLine

\uIf{domain.equals(keyword) AND id=0}{
\tcc{occurrence at the root node (first layer)}
setAttribute(D,PN)\;
}\uElseIf{domain.equals(keyword) AND $id\not=0$}{
\tcc{occurrence at the second layer}
setAttribute(D,SL)\;
}
\ElseIf{path.equals(keyword) AND id=0}{
\tcc{occurrence at path of root node}
setAttribute($P_a$, PN)\;
}

\caption{How to write algorithms}
\end{algorithm}
\end{document}


Right aligned comments are not my taste. The indentation of source code provides information about the structure, this is destroyed by comments moved to the right.

The example inserts \hspace{0pt plus 1filll} to move the comments.

\documentclass{article}
\usepackage{algpseudocode}
\usepackage{pifont}
\usepackage{program}
\newcommand\HFilll{\hspace{0pt plus 1filll}}
\begin{document}
\IncMargin{1em}
\begin{algorithm}[H]
\SetKwInOut{Input}{input}
\SetKwInOut{Output}{output}

\Input{A bitmap $Im$ of size $w\times l$}
\Output{A partition of the bitmap}
\BlankLine

\uIf{domain.equals(keyword) AND id=0}{
\HFilll\tcc{occurrence at the root node (first layer)}
setAttribute(D,PN)\;
}\uElseIf{domain.equals(keyword) AND $id\not=0$}{
\HFilll\tcc{occurrence at the second layer}
setAttribute(D,SL)\;
}
\ElseIf{path.equals(keyword) AND id=0}{
\HFilll\tcc{occurrence at path of root node}
setAttribute($P_a$, PN)\;
}

\caption{How to write algorithms}
\end{algorithm}
\end{document}


• I see. How about the other issues? – lonesome Aug 5 '17 at 8:14
• but if i want to show that first if-clause is the condition that if it is not satisfied, the rest of if-clauses wont be triggered, I'm afraid this new look will make reader not aware of this. – lonesome Aug 5 '17 at 9:42
• @lonesome Maybe, you take a look into the documentation? I do not know, what you like and what you want to have as result. – Heiko Oberdiek Aug 5 '17 at 9:43
• There should be only one end which corresponds to first if followed by else if nested in between, – lonesome Aug 5 '17 at 9:56
• Where did you change? – lonesome Aug 5 '17 at 10:05