# Normalise numberings

From Toggle numbering method for theorem-like environments depending on nesting in a section or subsection I got the following theorem environment

\newtheorem{theorem}{Theorem}
\counterwithin*{theorem}{section}
\counterwithin*{theorem}{subsection}
\makeatletter
\renewcommand{\thetheorem}{%
\ifnum\value{subsection}=0
\thesection
\else
\thesubsection
\fi
.\arabic{theorem}%
}


It works to number according to section if there is no subsection, and according to subsection if there is a subsection. Naturally I wanted this for all the other environment, so I copied and pasted, and changed "theorem" to "proposition" and to "example" and so on. The problem now is that this environment only remembers the numbering of each defined object, is such a way that theorems are numbered independently from examples, and so on. For example, I can have the situation

theorem 1.1

...

example 1.1

...

theorem 1.2

...

definition 1.1

and so on. This is not really desirable. Is there a way to globalise the numbering of these environments, as defined above? Thanks in advance.

Edit: compilable example

\documentclass[11pt,a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}

\usepackage{amsmath, chngcntr}

\newtheorem{theorem}{Theorem}
\counterwithin*{theorem}{section}
\counterwithin*{theorem}{subsection}
\makeatletter
\renewcommand{\thetheorem}{%
\ifnum\value{subsection}=0
\thesection
\else
\thesubsection
\fi
.\arabic{theorem}%
}

\newtheorem{proposition}{Proposition}
\counterwithin*{proposition}{section}
\counterwithin*{proposition}{subsection}
\makeatletter
\renewcommand{\theproposition}{%
\ifnum\value{subsection}=0
\thesection
\else
\thesubsection
\fi
.\arabic{proposition}%
}

\begin{document}

\section{bla}

\begin{theorem}

\end{theorem}

\begin{proposition}

\end{proposition}

\begin{proposition}

\end{proposition}

\section{blabla}

\subsection{blablabla}

\begin{theorem}

\end{theorem}

\begin{theorem}

\end{theorem}

\begin{proposition}

\end{proposition}

\end{document}

• Please provide a compilable document. Your fragment above has no definition, proposition etc. – user31729 Feb 1 '18 at 8:20
• Hope it's better now. – LetGBeTheGraph Feb 1 '18 at 9:04
• \newtheorem{proposition}[theorem]{Proposition} (and no “normalization”). – egreg Feb 1 '18 at 9:10

Use the standard method for sharing counters between theorem-like environments:

\documentclass[11pt,a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}

\usepackage{amsmath, chngcntr}

% define the theorem-like environments we need
\newtheorem{theorem}{Theorem}
\newtheorem{proposition}[theorem]{Proposition}

% normalize the theorem counter
\counterwithin*{theorem}{section}
\counterwithin*{theorem}{subsection}
\renewcommand{\thetheorem}{%
\ifnum\value{subsection}=0
\thesection
\else
\thesubsection
\fi
.\arabic{theorem}%
}


Note that your \makeatletter was wrong (it usually is without an accompanying \makeatother); since the code doesn't use @ commands, it is not even needed.