如何Switch
在环境中使用语句。我尝试了以下示例代码,algorithmic
但错误是:无法识别的命令(,,,,,algorithmicswitch
等)。algorithmiccase
\Switch
\EndSwitch
\Case
\documentclass{article}
\usepackage{amsmath}
\usepackage{algpseudocode}
\begin{document}
% New definitions
\algnewcommand\algorithmicswitch{\textbf{switch}}
\algnewcommand\algorithmiccase{\textbf{case}}
\algnewcommand\algorithmicassert{\texttt{assert}}
\algnewcommand\Assert[1]{\State \algorithmicassert(#1)}%
% New "environments"
\algdef{SE}[SWITCH]{Switch}{EndSwitch}[1]{\algorithmicswitch\ #1\ \algorithmicdo} {\algorithmicend\ \algorithmicswitch}%
\algdef{SE}[CASE]{Case}{EndCase}[1]{\algorithmiccase\ #1}{\algorithmicend\ \algorithmiccase}%
\algtext*{EndSwitch}%
\algtext*{EndCase}%
\begin{figure}
\begin{algorithmic}[1]
\Switch{$s$}
\Case{$a$}
\State hello1
\State hello1
\EndCase
\Case{$b$}
\State hello2
\State hello2
\EndCase
\EndSwitch
\end{algorithmic}
\caption{Pseudocode}
\end{figure}
\end{document}