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

  • Having multiple commands with underscores and numbers that start with same text 2012-01-04

    Recently me and some friends really got into "making everything compilable". More specifically, we need to do a lot of matlab calculations, and then we need to put the results into a tex document. I've had some time left recently and decided to

  • Redefining quote environment with tiny font and double quote signs? 2012-02-25

    I want to redefine the quote environment in such a way to get the output of the following code. \begin{quote}{\tiny\textquotedblleft Text \textquotedblright}\end{quote} I also want to fix the line spacing because the distance between the lines looks

  • How to redefine (via `environ` package) the `pmatrix` environment? 2011-01-27

    I want to redefine the pmatrix environment provided by the amsmath package (and changed by the mathtools package) for adding good-looking delimiters. The code is below: \documentclass{article} \usepackage{amsmath,mathtools,environ} \RenewEnviron{pmat

  • why run a Linux shell command with &? 2010-06-15

    I am using Red Hat Linux Enterprise version 5. I've noticed people sometimes running commands with a couple of & options. For example, in the below command, there are two & signs. What is the purpose of them? Are they always used together with noh

  • Ubuntu: Edit environment variables via command line 2010-08-14

    How can you edit the environment variables via command line in ubuntu? --------------Solutions------------- You can set environment variables from the command line, but the new values will apply only to that terminal session and any processes launche

  • Describe the best deployment environment you've worked with 2010-11-18

    The Joel Test includes the question: Can you make a build in one step? Which is important, but I'm wondering, how streamlined have some of the deployment processes been? All software from shrink-wrap to web applies: what's the best deployment environ

  • How to run a command with no-tty access, to run in admin privileges? 2011-04-29

    I would like to execute a command with administrative privileges, but do not have an access to the tty. I tried to execute it with the -A option of the sudo command and setting the environment variable SUDO_ASKPASS=/usr/bin/gksu. To do the same I ran

  • How to set env variables and run multiple commands with PsExec? 2011-09-07

    How can I run multiple commands with PsExec, and how can I export environment variables? I can run two commands by doing the below, but when I try to export an environment variable the second command errors out. Running two commands: psexec \\servern

  • How to run a batchfile automatically to setup environment whenever a command line shell is invoked? 2011-09-12

    From How to add a program to a list with right click button?, I could add "command" button to open command line prompt using right click. I normally open the command line prompt to use Visual Studio tools, so running 'vcvarsall.bat' in the comma

  • Which Lua environment should I use with LuaTeX (LuaLaTeX)? 2011-10-30

    Lua code environment I moved on to XeTeX (XeLaTeX) a while ago. I was using pdfLaTeX before that, but now I'm quite comfortable with XeLaTeX. Now, I'd like to use LuaLaTeX to embed Lua in some LaTeX documents. The doc states several ways to embed Lua

  • Putting a function into a new command with optional arguments 2011-11-18

    I know I have asked this before. But I just can not wrap my head around some things in LaTeX. Like the optional arguments. I have gotten some clues how to do it for comands, but not quite sure how to do it for commands. What I am looking for is putti

  • How can I run a cron command with existing environmental variables? 2011-12-21

    How can I run a cron command with existing environmental variables? If I am at a shell prompt I can type echo $ORACLE_HOME and get a path. This is one of my environmental variables that gets set in my ~/.profile. However, it seems that ~/.profile doe

  • Environment in \NewEnviron style, with key-value parameters 2012-03-13

    I want to define an environment that read its content before processing (like \newEnviron from the package environ) but also that allows key-value parameters (like \newkeyenvironment from the package keycommand that I usually use). How should I do? -

  • Create a macro that appends some code an existing command, with arguments 2012-04-04

    As I am working on improving my answer to Different approach to literate programming for LaTeX, I have created a macro that automatically processes two arguments and formats indexes accordingly. The arguments are strings (not control sequences), with

  • using history command with ssh and getting output with time stamps 2012-05-11

    Basically i want to get a record of all commands executed on my ssh server, with their times. The codes i have tried are : ssh [email protected] 'export HISTFILE=~/.bash_history; set -o history; history' I got all commands,but i dont get time stamps with this

  • using history command with ssh and getting output with correct time stamps 2012-05-21

    Possible Duplicate: using history command with ssh and getting output with time stamps Basically i want to get a record of all commands executed on my ssh server, with their correct timestamps. The codes i have tried are : ssh -i private_key [email protected]

  • New command with variable number of parameters 2012-09-17

    I would like to create new command with functionality like this (pseudo code): \newcommand{\myCommand}[numOfParameters] { for (i = 0; i < numOfParameters / 3; i++) { \somecommand1{#(i*3 + 1)} \somecommand1{#(i*3 + 2)} \somecommand1{#(i*3 + 3)} } } Is

  • How to redefine or patch the '\newcommand' command? 2012-09-19

    The Problem There are several packages I would like to write which require me to redefine the \newcommand (\renewcommand, etc.) command so I can track or change the commands that authors subsequently define. But I have no idea how to go about it. My

  • Environment for two columns with lstlistings 2013-12-03

    In order to reduce copy-pasting, I want to create an environment that will produce a two-column table with headers and two listings in different languages, like below: \begin{tabular}{l l} Python & Haskell \\ \hline \\ \lstset{language=Python} \begin

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 1.023 (s). 13 q(s)