TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

To avoid the problem of having to decide whether to use \newcommand or \renewcommand, LaTeX has the option of \providecommand.

Is there something corresponding to this for environments? I'd like to be able to type \provideenvironment (or similar) rather than first using \newenvironment and then using \renewenvironment.

share|improve this question
Good question! I think that anyone writing a generic newX macro ought to also provide both renewX and provideX variants. (I got so fed up of journals defining all different types of theorem variants - and therefore messing up my own definitions - that I wrote a \providetheorem command.) – Loop Space Jun 14 '11 at 10:07
It's worth pointing out that \providecommand isn't to avoid having to decide which to use, it's to provide a definition if one does not already exist. If it does, then \providecommand does not redefine it. – TH. Jun 14 '11 at 10:37
Yes, I think that's probably a better description of its intended usage. But because I often generate LaTeX automatically it's quite convenient for me to use \providecommand rather than keep track of whether my LaTeX code has already defined a command (hence the weird way I described its purpose). – bryn Jun 19 '11 at 7:49
up vote 20 down vote accepted

I don't believe there is a \provideenvironment defined anywhere, but you can define it.



\provideenvironment{foo}[1][blarg]{begin foo: #1 }{end foo}

The first time foo gets defined. The second time it does not because it is already defined.

share|improve this answer
Like! Can you tell us/point us to what \@star@or@long is and does? It appears very mystical ... – user1129682 Oct 29 '13 at 12:00
@user1129682: \@star@or@long is defined in the latex kernel (ltdefns.dtx): "Look ahead for a *. If present reset l@ngrel@x so that the next definition, #1, will be non-long". – wasteofspace Nov 20 '13 at 13:12


If you are familiar with expl3 (but not necessary), you can use \ProvideDocumentEnvironment in xparse package. The syntax is a little different. For example:

\ProvideDocumentEnvironment{foo}{ o m }{%
  \IfNoValueTF{#1}{only #2}{#1 and #2}%
  \IfNoValueTF{#1}{only #2}{#1 and #2}%
share|improve this answer

There is a \provideenvironment in the package makecmds. I suppose that is what you are looking for. Its syntax is analog to that of \newenvironment.

share|improve this answer

Your Answer


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.