# Defining a new keyword in algorithm2e

I'm trying to define a new keyword for my algorithm:

\documentclass{article}
\usepackage[]{algorithm2e}
\begin{document}
\SetKw{kwInit}{Init:}
\begin{algorithm}
\kwInit{$\alpha_n=1$ for all $n$}
\While{not at end of this document}{
do this and that
}
\end{algorithm}
\end{document}


The problem is the colon after Init is not automatically generated and I have to define it like this {Init:} which will generate a bold colon instead of a normal one. How to fix this? Also, the argument "for all n" will be italic and immediately followed by "while" of the next line. How can I fix this?

Thanks.

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
– cfr
Nov 22, 2014 at 23:38

Sounds like you are after \SetKwInput, with syntax

\SetKwInput{<name>}{<keymord>}


which defines the macro \<name>{<arg>} to print <keyword> in keyword typography followed by :, and then argument <arg>.

A complete example:

\documentclass{article}
\usepackage[]{algorithm2e}

\SetKwInput{kwInit}{Init}

\begin{document}
\begin{algorithm}
\kwInit{$\alpha_n=1$ for all $n$}
\While{not at end of this document}{
do this and that
}
\end{algorithm}
\end{document}


The result: