# How to change an environment into newcommand?

Suppose that I want to create a new command named step, which functionally add Step 1., Step 2., and so on in the proof. This can be done by:

\newcounter{stepnum}
\newcommand{\step}{\stepcounter{stepnum}\textbf{Step \arabic{stepnum}}.}


The problem is, which will not automatically start a newline at the end of each step, but this can be fixed by:

\newcounter{stepnum}
\newenvironment{step}{\stepcounter{stepnum}\textbf{Step \arabic{stepnum}}.}{\par}


I "hate" to write \begin{step} and \end{step} each time, clearly the command \step is more simple, but in the later case \step will not add a par at the end of line.

How can I fix this?

• consider adding \par at the beginning of the expansion of the command. if it's in vertical mode, it should make no difference; if in horizontal mode, it will have the desired effect. assuming you're using an environment for proof, that should take care of the end of the group. – barbara beeton Apr 15 '13 at 12:48
• It works! But why the "beginning" par are working at the "end" of line? even through I have more than one paragraph in a step? – user19832 Apr 15 '13 at 12:58
• TOO Long, I can't get the point, why this related? – user19832 Apr 15 '13 at 13:04
• @barbarabeeton's suggestion is very nice, otherwise you could define your command with an argument: \newcommand{\step}[1]{\stepcounter{stepnum}\textbf{Step \arabic{stepnum}}. #1\par} \step{This is the first step}\step{This is the second step} should work. – AndreasT Apr 15 '13 at 13:13
• If you are automatically enumerating something it is better to use \refstepcounter rather than \stepcounter then you can use label/\ref. Also it's normally better to use a list environment definition: your definition is essentially the definition of \item but the standard definition goes to a lot of trouble to get \par handling right. – David Carlisle Apr 15 '13 at 13:49

I'd do it differently:

\newcounter{stepnum}
\newenvironment{steps}
{\setcounter{stepnum}{0}}
{\par}
\newcommand{\step}{%
\par
\refstepcounter{stepnum}%
\textbf{Step \arabic{stepnum}}.\enspace\ignorespaces
}


Thus you can do

\begin{steps}
\step This is the first
\step And the second

\step Third
\end{steps}


The blank line is optional.

However, using enumitem is better.

\documentclass{article}
\usepackage{enumitem}
\newlist{steps}{enumerate}{1}
\setlist[steps,1]{
leftmargin=*,
label=\textbf{Step \arabic*}.,
ref=Step~\arabic*,
}

\usepackage{lipsum}

\begin{document}
\lipsum[2]
\begin{steps}
\item This is the first
\item And the second

\item Third
\end{steps}

\lipsum[3]
\end{document}


You can customize the list in many ways.