# Redefining an environment or a command with an indefinite numbers of items

According to LaTeX's basic commands if I want to create a list of items I have to use the following concept code:

\begin{itemize}
\item first
\item second
\item third
\end{itemize}


To keep my code as clean as possible and really customizable I use another concept:

\begin{myenv}
\item first
\item second
\item third
\end{myenv}


If it's possible, I'd like to also customize the "item command" like this (but it's not really essential):

\begin{myenv}
\myitem first
\myitem second
\myitem third
\end{myenv}


The problem is: How I can redefine an environment like this?

\newenvironment{myenv}
{?}
{?}


I'd like to ask the same question for the newly created command with

\newcommand{\mycmd}{?}

-
Will \myitem have an optional argument as the standard \item? – Gonzalo Medina Nov 8 '11 at 0:49
@gonzalo-medina yes, i'd like to create my own tags to keep the code simple and customizable, but i don't want to lose any features. – Micro Nov 8 '11 at 0:55

You could use the enumitem package to set up your own list.

Note that in the code below I have used \newlist to create the environment mylist and setlist to customize it. The {10} refers to the max-depth, which means that you could have at most 10 nested versions you are likely to have.

The enumitem package provides many more options for customizing the labels, indentation, margins, font, etc- see the documentation for more details.

\documentclass{article}

\usepackage{enumitem}
\newlist{mylist}{enumerate}{10}
\setlist[mylist]{label=$\triangleright$}

\begin{document}

\begin{mylist}
\item my first item
\item my second item
\end{mylist}

\end{document}

-
So it's not possible to define a new itemlist in a new environment, have to use the \newlist command, but what about a new command with an indefinite list of arguments? For example i like to create a command to set all text to a monospaced font <code> \newcommand{\cmd}[?]{\texttt{#?}} <\code> – Micro Nov 8 '11 at 12:57
I think the keyval package might be useful to you – cmhughes Nov 8 '11 at 15:11
When it could be possible i will give it a look, thanks – Micro Nov 8 '11 at 17:06

Defining a new environment that matches the itemize environment is done in the following way:

\newenvironment{myenv}%
{\begin{itemize}}% \begin{myenv}
{\end{itemize}}% \end{myenv}


Defining a command that does something similar to \item is done in the following way:

\usepackage{letltxmacro}% http://ctan.org/pkg/letltxmacro
\LetLtxMacro{\mycmd}{\item}% \mycmd = \item


Note that \item may take an optional argument, and it is therefore not as easy to merely "copy" it through \newcommand{\mycmd}{\item}. The letltxmacro package allows for making a "responsible" copy. Here is a minimal example that shows the usage:

\documentclass{article}
\newenvironment{myenv}%
{\begin{itemize}}% \begin{myenv}
{\end{itemize}}% \end{myenv}
\usepackage{letltxmacro}% http://ctan.org/pkg/letltxmacro
\LetLtxMacro{\mycmd}{\item}% \mycmd = \item
\begin{document}
\begin{myenv}
\mycmd first
\mycmd second
\mycmd third
\end{myenv}
​\end{document}​​​​​​


As mentioned above, you can now also use \mycmd[<stuff>] which will override the traditional \textbullet itemized bullet.

-
Actually \item is not defined to have an optional argument, but in doubt it's better to use \LetLtxMacro. One can check with Martin Scharrer's texdef script: texdef -t latex item will answer macro:->... which means that it has no argument. – egreg Nov 8 '11 at 1:00