5

I was trying to put a nested if in algorithm area like this:

          \If{$isContentMethod(\mathcal{M})$}{
            $URI \leftarrow getURI(SubCG, \mathcal{M})$\;
            \If($URI \in \mathcal{P}_c$){
                $Permission \leftarrow getPermission(URI, \mathcal{P}_c)$\;
                $\mathcal{B}.add(Permission, URI, Entrypoints)$ \;
            }
         }

But LaTeX keep giving me errors:

! Argument of \algocf@Ifmain has an extra }.
<inserted text>
\par
l.69 }
I've run across a `}' that doesn't seem to match anything.
2
  • Welcome to TeX.SX! Could you post a complete minimal working example? It is really of help to answer you. Commented Dec 6, 2013 at 19:27
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Commented Dec 6, 2013 at 19:49

1 Answer 1

6

While algorithm2e does supply an \If(..)-style conditional (for commenting), you're probably after \If{..}{...} inside your nested if. The reason for the failure is because the \If(..)-style usage requires more arguments than you are currently supplying.

Mere's a MWE:

enter image description here

\documentclass{article}
\usepackage{algorithm2e}% http://ctan.org/pkg/algorithm2e
\begin{document} 
\begin{algorithm}
\If{$isContentMethod(\mathcal{M})$}{
  $URI \leftarrow getURI(SubCG, \mathcal{M})$\;
  \If{$URI \in \mathcal{P}_c$}{% Don't use `\If(..)`
    $Permission \leftarrow getPermission(URI, \mathcal{P}_c)$\;
    $\mathcal{B}.add(Permission, URI, Entrypoints)$ \;
  }
}
\end{algorithm}
\end{document}

Also consider using the amsmath package that provides \text{...} for setting some of your text-related math content.

1
  • Thanks a lot! I made a mistake by using () instead of {} Commented Dec 6, 2013 at 19:32

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.