# How do I create a new command \listofcodes in latex?

In addition to tables and figures, I have a bunch of code pieces. Just like follows:

    \begin{figure}
\lstinputlisting[
language=C++, breaklines=true,
keywordstyle=\color{blue},
stringstyle=\color{red},
frame=single,
backgroundcolor=\color{gray},
basicstyle=\footnotesize\ttfamily,
caption={Data acquisition code},
label={code:data}]
{codes/data.cpp}
\end{figure}


Those codes do not appear in table of figures or table of contents which is exactly what I want.

Now I want to create a new table of codes \listofcodes similar to \listoffigures. It should create a third table. How do I do that?

-

If you are using the listings package, then you have \lstlistoflistings to generate a list of listings. I see that you are enclosing your lstinputlistings in a figure environment; if the idea is to turn them into floats then you could use the float option; a little example:

\documentclass{book}
\usepackage{listings}

\begin{document}
\lstlistoflistings

%A non-floating listing:
\begin{lstlisting}[caption={Useless code one},label=uselessone]
for i:=maxint to 0 do
begin
{ do nothing }
end;
\end{lstlisting}

%A floating listing:
\begin{lstlisting}[float,caption={Useless code two},label=uselesstwo]
for i:=maxint to 0 do
begin
{ do nothing }
end;
\end{lstlisting}

\end{document}


EDIT: corrected the example according to Andrey Vihrov's comment.

-
You are a lifesaver. Thanks! –  Dan Paradox Jun 1 '11 at 4:40
This isn't the correct usage. listings has the float parameter. –  Andrey Vihrov Jun 1 '11 at 6:43
@Andrey Vihrov: thanks. I've edited my answer accordingly. –  Gonzalo Medina Jun 1 '11 at 11:32