algorítmico - Bug (?) com \ SetKwSwitch
Sep 10 2020
O seguinte M (não) 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}
Respostas
2 egreg Sep 10 2020 at 04:17
Sem bug: \SetKwSwitchrequer nove argumentos e você fornece apenas oito deles, então o \pargerado pela linha em branco é considerado o nono. E \paré ilegal no contexto em que 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 é colocado entre chaves, então há um bug, mas apenas na documentação. Na página 39, início da seção 11.6, você leu
\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}
O que significa um erro “Não é possível encontrar o símbolo” ou “Não é possível resolver o símbolo”?
Christopher Nolan uma vez se arrependeu de ter lido o 'roteiro de Pulp Fiction' de Quentin Tarantino