I'm trying to make a command which will create a new theorem environment and link the counter for it to a specified other counter. For example, I'd like to be able to do something where my theorem, proposition, definition, etc. environments all have the same counters. I've tried the following:


\DeclareDocumentCommand{\DeclareTheorem}{ m m m !o }{%
\IfNoValueTF{#4} {%

This doesn't seem to work. It doesn't throw an error, it just doesn't compile or something. If I require five arguments, as below, then it works.

\DeclareDocumentCommand{\DeclareTheorem}{ m m m m !o }{%
\IfNoValueTF{#5} {%

However, I'd prefer to automatically have the alias counter to have the same name as the theorem environment, so that I don't have to put in five different options every time. Any help?

1 Answer 1


The manual of the aliascnt-package says:

1.2 Syntax

Macro names in user land contain the package name aliascnt in order to prevent name clashes.


An alias counter ⟨ALIASCNT⟩ is created that does not allocate a new TeX counter register. It shares the count register and the clear list with counter ⟨BASECNT⟩. If the value of either the two registers is changed, the changes affects both.


This fixes a problem with \newtheorem if it is fooled by an alias counter with the same name:

\newtheorem{foo}{Foo}% counter "foo"
\newaliascnt{bar}{foo}% alias counter "bar"

I suppose you need \aliascntresetthe:



\DeclareDocumentCommand{\DeclareTheorem}{ m m m !o }{%
  % #1 = theoremstyle
  % #2 = name of theorem-emvironment
  % #3 = Phrase introducing the theorem.
  % #4 = the counter to use instead of allocating a new counter
    % In case the counter to use is not defined define it:



\label{ThmA1}This is an \ThmAname.

\label{ThmB2}This is a \ThmBname.

\label{ThmC3}This is a \ThmCname.


\verb|\autoref{ThmA1}| yields: \autoref{ThmA1}

\verb|\autoref{ThmB2}| yields: \autoref{ThmB2}

\verb|\autoref{ThmC3}| yields: \autoref{ThmC3}


enter image description here

  • Thanks! Actually, reading your comment, I realized that I could in fact use c@#2 in the place where I was confused, and that would fix it all!
    – boink
    Jul 4, 2020 at 14:43
  • @boink Be aware that a LaTeX-counter is more than just a \count-register. \newcounter also defines "infrastructure" like \p@<counter> , \the<counter>, \cl@<counter> and in case hyperref is loaded you also need to take care of things like \theH<ccounter> and \<counter>autorefname/\<counter>name. Some of these things are done by the aliascnt-package. More details about LaTeX's counter-infrastructure can be found in the commented LaTeX 2e sources, file m:ltcounts.dtx , 22.1 Environment Counter Macros. Jul 5, 2020 at 10:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .