# How to resolve the error: “Missing { inserted.” inside an algorithm2e

When I use ShareLatex or MikTex to compile the following LaTeX code:

\begin{algorithm}
\uIf{$|F_d(D'(C_{\hat{i}})) - F_d(D(C_{\hat{i}}))| > \sigma$ OR numSeqNoise > $\mu$}{
SplitCluster($C_j$)\;
}
\uElseIf{$|F_d(D'(C_{\hat{i}})) - F_d(D(C_{\hat{i}}))| > \tau$}{
numSeqNoise++\;
}
\uElseIf{$j \neq \hat{i}$}{
Remove $S_{R}$ from cluster $C_j$\;
Place $S_{R}$ in cluster $C_\hat{i}$\;
}\uElse{
Replace $S_{R}$ in cluster $C_\hat{i}$\;
}
\end{algorithm}


it compiles normally, but when I try to use WriteLatex, then the following error always happens:

Missing { inserted.
\gdef
l.485          }
\uElse{


The line where the error is pointed out is }\uElse{.

Somebody can help me? ;)

• Use C_{\hat{i}} instead of C_\hat{i}, because \hat doesn't open a group. – Henri Menke Sep 10 '14 at 21:33
• FYI This Question has also been posted to LaTeX Community. – Johannes_B Sep 10 '14 at 22:06

You need to use C_{\hat{i}} instead of C_\hat{i}, because \hat doesn't open a group.

Typographical advice: Because \hat{i} is too high and looks weird, LaTeX provides a dotless i \imath.

It is favourable to use \hat{\imath} instead of \hat{i}. I replaced every occurrence in the example below.

\documentclass{article}
\usepackage{algorithm2e}
\begin{document}
\begin{algorithm}
\uIf{$|F_d(D'(C_{\hat{\imath}})) - F_d(D(C_{\hat{\imath}}))| > \sigma$ OR $\mathrm{numSeqNoise} > \mu$}{
SplitCluster($C_j$)\;
}
\uElseIf{$|F_d(D'(C_{\hat{\imath}})) - F_d(D(C_{\hat{\imath}}))| > \tau$}{
numSeqNoise++\;
}
\uElseIf{$j \neq \hat{\imath}$}{
Remove $S_{R}$ from cluster $C_j$\;
Place $S_{R}$ in cluster $C_{\hat{\imath}}$\;
}\uElse{
Replace $S_{R}$ in cluster $C_{\hat{\imath}}$\;
}
\end{algorithm}
\end{document}