While writing a paper I decided that I need a $\LaTeX$ environment that resembles the usual equation environment, i.e. it takes some content, centers it on it’s own line in the page and then adds, flushed left, a reference number for later use. There might be some ready-made environment or package for doing this, but I couldn’t find one after googling for 20 minutes or so. So I decided to make one which was a nice exercise. I feel like I finally understand the point of the minipage and makebox commands. Here is some code for a new environment that I call numtxt.

\newcounter{txtctr}[section] \setcounter{txtctr}{0}
\newenvironment{numtxt}
{% This is the begin code
\refstepcounter{txtctr} \vspace{0.2cm} {\noindent
(\arabic{section}.\arabic{subsection}.\arabic{txtctr})
}\hspace{-36pt}\begin{minipage}[c]{\textwidth}\centering}
{% This is the end code
\end{minipage} \vspace{0.2cm}}


Basically, I setup a counter (called txtctr, the name stolen from some other bit of macro code), start the environment by displaying the reference number in the format: ( section . subsection . # ). Next we start a minipage which is as wide as the line and center our content inside the minipage. Then to get that minipage aligned right (i.e. to ignore the space taken up by the reference number) I move everything 36 pts to the left. 36 points is about how long the reference number is. There’s probably a better way to do this…