0

How can I type another word for the statement \while in the pseudo-code? Normally, it writes,

While *some termination condition* do

and I want to change it to:

DONGU: *some termination condition*

And here is the MWE:

\documentclass{article}
\usepackage[ruled,vlined]{algorithm2e}
\usepackage{algorithmic}
\begin{document}
\begin{algorithm}[ht]
\centering
\begin{algorithmic}
\caption{some algorithm} \label{alg:myalgo}
\While {a termination condition bla bla}{
    \STATE $do\;something $\;       
    }
\end{algorithmic}
\end{algorithm}
\end{document}
3
  • Hi and welcome to TeX.SX. Your MWE does not compile. It is lacking the documentclass, but even with \documentclass{article} it still produces errors: the algorithm environment from algorithm2e package does not require an algorithmic in it. Check this out for more detail: en.wikibooks.org/wiki/LaTeX/Algorithms It also details how to change the while in algorithmic
    – Elad Den
    Mar 9, 2021 at 15:25
  • 1
    This answer details how to change the while keywords in algorithm2e tex.stackexchange.com/a/212302/90297
    – Elad Den
    Mar 9, 2021 at 15:26
  • @EladDen I don't know man but it works on my side as it is. And thanks for the answer.
    – WhoCares
    Mar 9, 2021 at 18:30

1 Answer 1

1

You can't mix the formats of algorithm2e and those provided by either the algorithms bundle (which supplies the algorithmic environment) or algorithmicx (which also supplies the algorithmic environment).

Here is a purely algorithm2e implementation:

enter image description here

\documentclass{article}

\usepackage[ruled,vlined]{algorithm2e}
\DontPrintSemicolon

\begin{document}

\begin{algorithm}
  \caption{First algorithm}
  \While {a termination condition bla bla}{
    do something\;
  }
\end{algorithm}

\SetKwFor{While}{DONGU:}{}{}

\begin{algorithm}
  \caption{Second algorithm}
  \While {a termination condition bla bla}{
    do something\;
  }
\end{algorithm}

\end{document}

Of course, you can also just define your own \DONGU:

\SetKwFor{DONGU}{DONGU:}{}{}
1
  • thanks. it worked like charm. However, I just can't remove any of the environments from my code. It produces error either way. And since my real job is to finish my thesis, I am going to leave it as it is. Thank again.
    – WhoCares
    Mar 9, 2021 at 18:51

Not the answer you're looking for? Browse other questions tagged .