algoritmo2e - Bug (?) con \ SetKwSwitch

Sep 10 2020

La seguente M (non) WE dovrebbe funzionare. Ho trovato un 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}

Risposte

2 egreg Sep 10 2020 at 04:17

Nessun bug: \SetKwSwitchrichiede nove argomenti e ne fornisci solo otto in modo che il \pargenerato dalla riga vuota sia considerato come nono. Ed \parè illegale nel contesto in cui viene utilizzato il nono argomento.

\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}}%

Il manuale ha una descrizione in cui l'ultimo argomento (simbolico) non è rinforzato, quindi c'è un bug, ma solo nella documentazione. A pagina 39, all'inizio della sezione 11.6, leggi

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

ma dovrebbe essere

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

Esempio fisso:

\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}