Let's go through your posting:
In the document I'm writing, I have redefined each environment and
have included a new counter, called counter
, to help with the
numbering of the environments. My intention is for each definition,
proposition, theorem, and so on to all use the same counter, which
displays the section and then the counter number with the counter
reset for each section. For example, in Section 2, the first
definition reads "Definition 2.1", and the following proposition then
reads "Proposition 2.2".
Instead of doing this, you could define your environments in terms of \newtheorem
.
Syntax of \newtheorem
is:
\newtheorem{⟨Name of the environment and — in case no already
existing counter is to be used — name of
newly to allocate underlying counter.⟩}%
[⟨Name of already existing counter to be used for
numbering the environment.⟩]%
{⟨Textual phrase denoting the title/heading/the kind of
item of sectioning produced by an instance of the
environment.⟩}%
[⟨Name of superordinate sectioning counter whose value is
part of the number of the sectioning-item provided by
this environment, and whose incrementing via `\refstepcounter`
triggers resetting the counter in use for numbering the
environment.⟩]
Thus you could, e.g., do:
\newtheorem{theorem}{Theorem}[section]%
\newtheorem{proposition}[theorem]{Proposition}%
\newtheorem{definition}[theorem]{Definition}%
If with this approach you wish to also use the hyperref package and to use its \autoref
-feature, you need to also load the aliascnt package and do:
\documentclass...
...
\usepackage{hyperref}
\usepackage{aliascnt}
...
\newtheorem{theorem}{Theorem}[section]%
%
\newaliascnt{proposition}{theorem}
\newtheorem{proposition}[proposition]{Proposition}%
\aliascntresetthe{proposition}
\newcommand\propositionautorefname{Proposition}
%
\newaliascnt{definition}{theorem}
\newtheorem{definition}[definition]{Definition}%
\aliascntresetthe{definition}
\newcommand\definitionnautorefname{Definition}
Beneath other things, the aliascnt-package solves problems related to the \autoref
-feature of the hyperref-package.
Also it provides the possibility of having different anchor-name-patterns for hyperlinks. (More information about this can be found in the manual of the hyperref package, section 4: additional user macros, \autoref
.)
E.g., the name of the anchor of theorem 2.4 will not be #counter.2.4
but #theorem.2.4
.
E.g., the name of the anchor of proposition 2.5 will not be #counter.2.5
but #proposition.2.5
.
E.g., the name of the anchor of definition 2.6 will not be #counter.2.6
but #definition.2.6
.
The counter has been defined as follows.
\newcounter{counter}
\renewcommand\thecounter{\thesection.\arabic{counter}}
If you wish the counter counter
to be reset to the value 0 whenever the counter section
is incremented via \refstepcounter
, which in turn is used by the sectioning-command \section
, apply \newcounter
as follows:
\newcounter{counter}[section]
Each environment has \label{}
after \begin{<environment>}
to
insert the anchor.
The assumption that the \label
-command would place an anchor is a common misunderstanding.
Anchors are placed by sectioning-commands like \section
or \begin{theorem}
or \item
(of an enumerate-environment). They internally use \refstepcounter
as you did with your environments.
\refstepcounter
does
increment the counter,
create an anchor-name,
place an anchor of that name,
make the name of that just placed anchor available to the \label
-macro as the expansion of the macro \@currentHref
,
make the value of the just incremented counter availabe to the \label
-macro as the expansion of the macro \@currentlabel
.
\label
itself does neither create anchor names nor place anchors. \label
only writes information that is provided by sectioning-commands in terms of redefining macros of specific names (\@currentlabel
, \@currentHref
, ...) into the .aux-file in terms of these nice \newlabel
-entries.
In case I wouldn't care about anchor-names for hyperlinks and the \autoref
-feature, I would probably do it as follows:
\documentclass{article}
\usepackage{hyperref}
\newcounter{counter}[section]
\renewcommand\thecounter{\thesection.\arabic{counter}}
\renewcommand\theHcounter{\theHsection.\arabic{counter}}
\newcommand\underlyingformatting[1]{%
\refstepcounter{counter}%
\par\noindent
\textsc{#1}~\thecounter. #1
}%
\newcommand\counterautorefname{Theorem/Definition/Proposition}
\newenvironment{theorem}[1][]{\underlyingformatting{Theorem}}{}%
\newenvironment{definition}[1][]{\underlyingformatting{Definition}}{}%
\newenvironment{proposition}[1][]{\underlyingformatting{Proposition}}{}%
\begin{document}
\section{A section}
\ref{thm1}
\autoref{thm1}
\ref{def1}
\autoref{def1}
\ref{pro1}
\autoref{pro1}
\ref{thm2}
\autoref{thm2}
\ref{def2}
\autoref{def2}
\ref{pro2}
\autoref{pro2}
\begin{theorem}\label{thm1}
A theorem
\end{theorem}
\begin{definition}\label{def1}
A definition
\end{definition}
\begin{proposition}\label{pro1}
A proposition
\end{proposition}
\begin{theorem}\label{thm2}
Another theorem
\end{theorem}
\begin{definition}\label{def2}
Another definition
\end{definition}
\begin{proposition}\label{pro2}
Another proposition
\end{proposition}
\end{document}
In case of caring about anchor-names and \autoref
and the like, I would do it as follows—I "borrowed" the \theoremstyle
-code from egreg ;-) :
\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{hyperref}
\usepackage{aliascnt}
\usepackage{lipsum} % for context
\newtheoremstyle{wallisdefinition}
{\topsep} % ABOVESPACE
{\topsep} % BELOWSPACE
{\upshape} % BODYFONT
{0pt} % INDENT (empty value is the same as 0pt)
{\upshape} % HEADFONT
{} % HEADPUNCT
{ } % HEADSPACE
% CUSTOM-HEAD-SPEC follows
{\thmname{\textsc{#1}}\thmnumber{ #2}.\thmnote{ #3}}
\theoremstyle{wallisdefinition}
\newtheorem{theorem}{Theorem}[section]%
\newaliascnt{proposition}{theorem}
\newtheorem{proposition}[proposition]{Proposition}%
\aliascntresetthe{proposition}
\newcommand\propositionautorefname{Proposition}
\newaliascnt{definition}{theorem}
\newtheorem{definition}[definition]{Definition}%
\aliascntresetthe{definition}
\newcommand\definitionautorefname{Definition}
\begin{document}
\section{Test}
See definition~\ref{def:foo}.
See \autoref{def:foo}.
See theorem~\ref{thm:foo}.
See \autoref{thm:foo}.
See proposition~\ref{prp:foo}.
See \autoref{prp:foo}.
See definition~\ref{def:bar}.
See \autoref{def:bar}.
See theorem~\ref{thm:bar}.
See \autoref{thm:bar}.
See proposition~\ref{prp:bar}.
See \autoref{prp:bar}.
\clearpage
\lipsum[2]
\begin{definition}[(Foo-attribution.)]\label{def:foo}
A \emph{foo} is something very useful. Therefore we will not use
foos all the time in this paper. This should be enough to wrap.
\end{definition}
\lipsum[3]
\begin{theorem}[(Foo's bar-associativity.)]\label{thm:foo}
Foo is bar-associative. The proof is left to a drunken monkey.
\end{theorem}
\lipsum[4]
\begin{proposition}[(Foo's foobar-associativity.)]\label{prp:foo}
Foo is also foobar-associative. Before the break we announce proving
after the break. After the break we proclaim having proven just
before the break and continue with other things.
\end{proposition}
\lipsum[5]
\begin{definition}[(Bar-attribution.)]\label{def:bar}
A \emph{bar} is something very useful but we will never really
use bars in this paper. This should be enough to wrap.
\end{definition}
\lipsum[6]
\begin{theorem}[(Bar's foo-associativity.)]\label{thm:bar}
Bar is foo-associative. The proof is left to a drunken donkey.
\end{theorem}
\lipsum[7]
\begin{proposition}[(Bar's barfoo-assoviativity.)]\label{prp:bar}
Bar is also barfoo-associative. We proclaim that this is obvious
and cause fear of attracting attention in an embarrassing way on
the side of those people that don't agree.
\end{proposition}
\end{document}