एल्गोरिथम 2e - बग (?) with \ SetKwSwitch

Sep 10 2020

निम्नलिखित एम (नहीं) हमें काम करना चाहिए। क्या मुझे एक बग मिला?

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

जवाब

2 egreg Sep 10 2020 at 04:17

बग नहीं: नौ तर्कों की \SetKwSwitchआवश्यकता है और आप उनमें से केवल आठ की आपूर्ति करते हैं इसलिए रिक्त लाइन द्वारा उत्पन्न नौवें के रूप में लिया जाता है। और उस संदर्भ में अवैध है जहां नौवें तर्क का उपयोग किया जाता है।\par\par

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

मैनुअल में एक विवरण होता है जहां अंतिम (प्रतीकात्मक) तर्क लट में नहीं होता है, इसलिए एक बग है, लेकिन केवल प्रलेखन में। पृष्ठ 39 पर, खंड 11.6 की शुरुआत, आप पढ़ते हैं

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

लेकिन यह होना चाहिए

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

निश्चित उदाहरण:

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