2

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

HAL9000
  • 493

1 Answers1

2

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}
  • “Cases where it will not work”? – egreg Mar 19 '14 at 11:37
  • @egreg In your answer at http://tex.stackexchange.com/questions/116670/duplicating-environments, you mention verbatim and align as examples. – Steven B. Segletes Mar 19 '14 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 '14 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 '14 at 12:10
  • @egreg Revised, based on your comments. – Steven B. Segletes Mar 19 '14 at 12:30