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.

In this page, Andrew Swann points me a way to make verbose formatting of algorithms (I need this only for pedagogical reasons).

The problem with this solution is that it produces unwanted warnings with my second algorithm in the following example. Is there a way to not have this warnings ?

MWE

\documentclass[10pt,a4paper]{article}
    \usepackage[vlined]{algorithm2e}

    \newcommand\BlockIf[1]{\KwSty{Start If} \\ #1 \\ \KwSty{End If}}
    \newcommand\BlockElseIf[1]{\KwSty{Start Else If} \\ #1 \\ \KwSty{End Else If}}
    \newcommand\BlockElse[1]{\KwSty{Start Else} \\ #1 \\ \KwSty{End Else}}

    \makeatletter
        \renewcommand{\algocf@uIf}[2]{\If@ifthen{#1}\If@noend{\BlockIf{#2}}}
        \renewcommand{\algocf@uElseIf}[2]{\ElseIf@elseif{#1}\If@noend{\BlockElseIf{#2}}}
        \renewcommand{\algocf@Else}[1]{\Else@else\If@endif{\BlockElse{#1}}}
    \makeatother

\begin{document}

\begin{algorithm}[H]
    \uIf{1}{if...}
    \uElseIf{2}{else if...}
    \Else{else...}
\end{algorithm} 

\begin{algorithm}[H]
    \uIf{1}{if...}
    \uElseIf{2}{\ForAll{$i$}{Action $i$}}
    \Else{else...}
\end{algorithm} 

\end{document}

Unwanted warning

! LaTeX Error: There's no line here to end.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.26     \uElseIf{2}{\ForAll{$i$}{Action $i$}}
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You have a choice, depending on the layout you want.

Either make sure that LaTeX is in a paragraph before forcing a linebreak, so replace each \\ in your example by

\mbox{}\\

or don't force a linebreak if you are between paragraphs so replace each \\ by

\ifhmode\\\fi
share|improve this answer
    
Very tricky solution ! That's do the job. Thanks. –  projetmbc Oct 30 '12 at 16:28
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.