Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using LaTeX for homework in algorithms, but I have an error that I can't solve.

I think the error comes from Algorithm2e which doesn't like multiple nested if(?)

Runaway argument?
{ \eIf {$firstWall$}{ Tourne vers la gauche tant que pas blanc \; }{ \ETC.
! Paragraph ended before \algocf@eIfthen was complete.
<to be read again> 
               \par 
l.86 

My source code is:

\eIf{$firstWall$}{
  Rotation du robot de 10 degrés \;
}
{
  Rotation du robot de 10 degrés \;
}

\eIf{$lightValue() >= blanc$}{
      \eIf{$firstWall$}{
            Tourne vers la gauche tant que pas blanc \;
          }{
            Tourne vers la droite tant que pas blanc \;
          }
          %Here is the line 86%
          Tourne vers la gauche jusqu'à retrouver du blanc et enregistre l'angle de rotation du robot. \;

          $alignTrajectory(false)$ \;

          Continue à avancer \;
    }{
      Tourne vers la droite jusqu'à retrouver du blanc \;

      $alignTrajectory(true)$ \;

      Continue à avancer \;
    }

Sorry the commands are in French but I think it doesn't matter.

How can I solve this issue? Where does this error come from?

share|improve this question

migrated from stackoverflow.com Dec 5 '11 at 1:54

This question came from our site for professional and enthusiast programmers.

    
Welcome to TeX.sx! Your question was migrated here from another stackexchange site. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. –  Gonzalo Medina Dec 5 '11 at 2:11
add comment

2 Answers 2

up vote 7 down vote accepted

As Paŭlo Ebermann mentioned in his answer, \eIf doesn't admit paragraph breaks (in your case, the empty blank lines). If those blank lines don't serve any purpose, then delete them. If you are using those blank lines to make your code more readable, you can simply comment out those lines using the % character (first version of your code below); if your intention is actually to add some vertical space between some lines, you can use something like \mbox{}\\ at the end of the lines, without leaving empty blank lines (second version of your code below):

\documentclass{article}
\usepackage{algorithm2e}

\begin{document}

\begin{algorithm}
\eIf{$firstWall$}{
  Rotation du robot de 10 degrés \;
}
{
  Rotation du robot de 10 degrés \;
}

\eIf{$lightValue() >= blanc$}{
      \eIf{$firstWall$}{
            Tourne vers la gauche tant que pas blanc \;
          }{
            Tourne vers la droite tant que pas blanc \;
          }
          %Here is the line 86%
          Tourne vers la gauche jusqu'à retrouver du blanc et enregistre l'angle de rotation du robot. \;
%
          $alignTrajectory(false)$ \;
%
          Continue à avancer \;
    }{
      Tourne vers la droite jusqu'à retrouver du blanc \;
%
      $alignTrajectory(true)$ \;
%
      Continue à avancer \;
    }
\end{algorithm}

\begin{algorithm}
\eIf{$firstWall$}{
  Rotation du robot de 10 degrés \;
}
{
  Rotation du robot de 10 degrés \;
}

\eIf{$lightValue() >= blanc$}{
      \eIf{$firstWall$}{
            Tourne vers la gauche tant que pas blanc \;
          }{
            Tourne vers la droite tant que pas blanc \;
          }
          %Here is the line 86%
          Tourne vers la gauche jusqu'à retrouver du blanc et enregistre l'angle de rotation du robot. \;\mbox{}\\
          $alignTrajectory(false)$ \;\mbox{}\\
          Continue à avancer \;
    }{
      Tourne vers la droite jusqu'à retrouver du blanc \;\mbox{}\\
      $alignTrajectory(true)$ \;\mbox{}\\
      Continue à avancer \;
    }
\end{algorithm}

\end{document}

Here's the result of the first version:

enter image description here

and here's the result of the second version:

enter image description here

share|improve this answer
add comment

In LaTeX, commands can be defined in a way that doesn't allow line paragraph breaks (i.e. either an explicit \par or an empty line) inside their arguments. The error message looks like this is the case for the \eIf command, too.

I don't know the solution here, other than omitting the empty line here. Maybe other answerers can help here.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.