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}{?} 

Replay

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}

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:

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

\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.

Category: lists Time: 2011-11-08 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.251 (s). 12 q(s)