# Temporarily modify the way a counter is displayed in an existing environment

My document has numbered assumptions 1.1, 1.2, etc. At some point in the text, I would like to define a variant of a previously-stated assumption, say Assumption 1.2, and have its counter display as 1.2b.

I'm trying to achieve that by defining a new assumptionb environment that redefines \theassumption by grabbing the correct assumption counter value using a label passed as argument, and appending a b to it.

Here's my attempt:

\documentclass{article}

\newtheorem{assumption}{Assumption}[section]

\usepackage{refcount}  % used to refer to a past assumption by label
\newcounter{assumptionbkup}
\newenvironment{assumptionb}[1]{%
\setcounter{assumptionbkup}{\value{assumption}}  % save current value of Assumption counter
\let\oldtheassumption\theassumption  % the current way assumption numbers are displayed
\setcounterref{assumption}{#1}       % set value of Assumption counter based on reference
\renewcommand{\theassumption}{{\oldtheassumption}b}
\begin{assumption}
}{%
\end{assumption}
\setcounter{assumption}{\value{assumptionbkup}}  % restore value of Assumption counter
\let\theassumption\oldtheassumption  % restore how assumption numbers should be displayed
}

\begin{document}

\section{Some section}

\begin{assumption}  % will display as Assumption 1.1
\label{asm:1}
First assumption.
\end{assumption}

\begin{assumption}  % will display as Assumption 1.2
\label{asm:2}
Second assumption.
\end{assumption}

\begin{assumption}  % will display as Assumption 1.3
\label{asm:3}
Third assumption.
\end{assumption}

\begin{assumptionb}{asm:3}  % should display as Assumption 1.3b
First variant.
\end{assumptionb}

\end{document}


The result is that the variant assumption is displayed as "Assumption 1.2b" regardless of what label I pass as argument to assumptionb. Also a ".3" is displayed before the environment:

The ".3" presumably refers to the argument of assumptionb but I don't see why it's being displayed.

I would like the assumptionb environment to be friendly with \usepackage[nameinlink]{cleveref} so that \cref{asm:2b} displays as "Assumption 1.2b" all hyperlinked.

You can manage it in a much simpler way: Just redefine \theassumption and nullify the effect of \refstepcounter to avoid incrementing the original assumption counter.

\documentclass{article}

\newtheorem{assumption}{Assumption}[section]

\usepackage{hyperref}

\makeatletter
\newenvironment{assumptionb}[1]{%
\renewcommand{\theassumption}{\ref*{#1}b}%
\renewcommand{\@currentlabel}{\protect\ref*{#1}b}% Update reference stored
\renewcommand{\refstepcounter}[1]{}% Remove functionality of \refstepcounter
\csname phantomsection\endcsname
\begin{assumption}
}{%
\end{assumption}
}
\makeatother

\begin{document}

\section{Some section}

\begin{assumption}[abc]  % will display as Assumption 1.1
\label{asm:1}
First assumption.
\end{assumption}

\begin{assumption}  % will display as Assumption 1.2
\label{asm:2}
Second assumption.
\end{assumption}

\begin{assumption}  % will display as Assumption 1.3
\label{asm:3}
Third assumption.
\end{assumption}

\begin{assumptionb}{asm:3}  % should display as Assumption 1.3b
\label{asm:b}
First variant.
\end{assumptionb}

See \ref{asm:b}.

\begin{assumption}  % will display as Assumption 1.4
\label{asm:4}
Fourth assumption.
\end{assumption}

\end{document}

• Thank you! That does it for the numbering. However, \cref{asm:b} is displayed as "section 1" for me (even though \ref{asm:b} works as in your example. – Dominique Oct 19 '19 at 13:09
• I found a working solution by removing the \renewcommand{\refstepcounter}[1]{}, which appears to be confusing cleveref, and saving and restoring the value of the assumption counter as in my initial attempt. Not sure if that's the best way to go but it appears to be working. – Dominique Oct 20 '19 at 3:40