Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

If you want to write an algorithm, you have to write three commands to initialize a writing environment.

\usepackage{algorithm}
\usepackage[noend]{algpseudocode}

\begin{algorithm} % no.1
\begin{algorithmic} % no.2
\Procedure{Sum}{100} % no.3
\State abcd
\EndProcedure
\end{algorithmic}
\end{algorithm}

And write three lines to end it. So is there any way to wrap it up, using one command to simplify it?

share|improve this question

1 Answer 1

You can define a myalgorithm environment (you can call it anything you want) that does this. If you add

\newenvironment{myalgorithm}[2]
  {\begin{algorithm}\begin{algorithmic}\Procedure{#1}{#2}}
  {\EndProcedure\end{algorithmic}\end{algorithm}}

you can use this in your document as

\begin{myalgorithm}{Sum}{100}
  \State abcd
\end{myalgorithm}

The two arguments are those that are given to the \Procedure command. Note that this will not allow you to add a caption or label to the algorithm floating environment.

share|improve this answer
    
Thank you for that. \end{myalgorithm} in the end. –  Peter Jul 13 at 5:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.