Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sorry for the title, I don't know how to formulate the question in short.
What I need is to define something like constant parameters, for example I have through the code this list:

\begin{list}{\labelitemi}{\leftmargin=2em}
\item a
\item b
\end{list}

I never remember this part {\labelitemi}{\leftmargin=2em} and I always need to copy and paste it to create a new list. In which way could I define something like

\begin{myList}
\end{myList}

such that \begin{myList} is actually \begin{list}{\labelitemi}{\leftmargin=2em}?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The entering and exiting of environment abc is accompanied by the execution of macros \abc and \endabc. Often, one can invoke those macros as part of your own environment definition as I did here. There are some cases where it will not work (verbatim and align environments are two examples). But, when unsure, I inevitably try it and find out if it works. In this case, it seems to.

See Duplicating Environments for more details.

\documentclass{article}
\newenvironment{myList}{\list{\labelitemi}{\leftmargin=2em}}{\endlist}
\begin{document}
\begin{myList}
\item a
\item b
\end{myList}
\end{document}
share|improve this answer
    
“Cases where it will not work”? –  egreg Mar 19 at 11:37
    
@egreg In your answer at tex.stackexchange.com/questions/116670/duplicating-environments, you mention verbatim and align as examples. –  Steven B. Segletes Mar 19 at 11:49
    
Well, your way of putting it seems to say “there's almost no chance to know in advance when it works or not”. Some special environments cannot be used like that, but this is usually documented in the package that defines them. In many cases when \begin{env} doesn't work in the argument to \newenvironment, \env (with \endenv) work. –  egreg Mar 19 at 12:00
    
@egreg, what I meant was, for those of us too lazy to investigate whether a particular environment is amenable to this approach, one should just test it to find out. –  Steven B. Segletes Mar 19 at 12:10
    
@egreg Revised, based on your comments. –  Steven B. Segletes Mar 19 at 12:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.