algorithm2e - บั๊ก (?) ด้วย \ SetKwSwitch

Sep 10 2020

M (ไม่) ต่อไปนี้เราควรใช้งานได้ ฉันพบข้อบกพร่องหรือไม่?

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