I would like to customize keywords in algpseudocode
, including the rendering of \ElsIf
. But when I compile the file
\documentclass{article}
\usepackage{algpseudocode}
\algrenewcommand\algorithmicthen{\relax}
\algrenewcommand\algorithmicif{If}
\algrenewcommand\algorithmicelse{Else}
\algrenewcommand\algorithmicelsif{Elif}
\begin{document}
\end{document}
I get a syntactic error:
! LaTeX Error: Command \ALG@cmd@2@algorithmicelsif undefined.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.7 \algrenewcommand\algorithmicelsif
{Elif}
?
whereas the first three algrenewcommand
s work fine. What am I doing wrong?
I can see that the style file algorithmic.sty
contains
\newcommand{\algorithmicif}{\textbf{if}}
\newcommand{\algorithmicthen}{\textbf{then}}
\newcommand{\algorithmicelse}{\textbf{else}}
\newcommand{\algorithmicelsif}{\algorithmicelse\ \algorithmicif}
and so I thought that it should be possible to redefine any of these commands.
Best Answer
algorithmic.sty
forms part of thealgorithms
bundle, whilealgpseudocode.sty
forms part of thealgorithmicx
bundle, so you're comparing code that isn't used at all. The latter defines\ElsIf
to use\algorithmicelse
and\algorithmicif
, so redefining those should suffice. Alternatively, if you want a different output via\ElsIf
, define it as such:The above example code was partially taken from the
algorithmicx
documentation.