algoritmo2e - Bug (?) com \SetKwSwitch

algoritmo2e - Bug (?) com \SetKwSwitch

O seguinte M(not)WE deve funcionar. Eu encontrei um bug?

\documentclass{article}

\usepackage{algorithm2e}

\SetKwSwitch{Switch}{Case}{Other}{Switch}{:}{Case}{Other}{} 

\begin{document}

\begin{algorithm}
    \Switch{X}{
        \Case{1}{A}
        \Other{Other}
    }
\end{algorithm}

\end{document}

Responder1

Sem bug: \SetKwSwitchrequernoveargumentos e você fornece apenas oito deles, então o \pargerado pela linha em branco é considerado o nono. E \paré ilegal no contexto onde o nono argumento é usado.

\newcommand{\SetKwSwitch}[9]{% #1=\Switch #2=\Case #3=\Other #4=switch #5=do #6=case #7=otherwise #8=endcase #9=endsw
%       \algocf@newcmdside{#1}{3}%
        \algocf@newcmdside@koif{#1}%
                {\KwSty{#4}\algocf@scond\ArgSty{##2}\algocf@econd\KwSty{#5}\ifArgumentEmpty{##1}\relax{ ##1}\algocf@block{##3}{#9} {##4\relax}}%

O manual tem uma descrição onde o último argumento (simbólico) não está entre colchetes, então há um bug, mas apenas na documentação. Na página 39, início da seção 11.6, você lê

 \SetKwSwitch{Switch}{Case}{Other}{switch}{do}{case}{otherwise}{endcase}endsw

mas deveria ser

\SetKwSwitch{Switch}{Case}{Other}{switch}{do}{case}{otherwise}{endcase}{endsw}

Exemplo fixo:

\documentclass{article}

\usepackage{algorithm2e}

\SetKwSwitch{Switch}{Case}{Other}{Switch}{:}{Case}{Other}{EndCase}{EndSwitch}

\begin{document}

\begin{algorithm}
    \Switch{X}{
        \Case{1}{A}
        \Other{Other}
    }
\end{algorithm}

\end{document}

insira a descrição da imagem aqui

informação relacionada