0

I'd like to have two equation-like environments, with separate numbering, and easily use them inside various amsmath environments.

Inspired by an answer by Egreg to Clone of the `amsmath` equation environment with different spacing, I wrote

\documentclass[a4paper,10pt]{article}

\usepackage{amsmath}

\newcounter{savedequation} \newcounter{myhypo}

\newcommand{\setmyhypo}{% \setcounter{savedequation}{\value{equation}}% \setcounter{equation}{\value{myhypo}}% \renewcommand\theequation{$H_\arabic{equation}$}% }

\newcommand{\unsetmyhypo}{% \setcounter{myhypo}{\value{equation}}% \setcounter{equation}{\value{savedequation}}% }

\newenvironment{hypothesis}{% \setmyhypo% \begin{equation}% }{% \end{equation}% \unsetmyhypo% }

\begin{document}

\begin{hypothesis} \label{test_1} a=b \end{hypothesis}

\begin{gather} \label{test_2} c=d \ \setmyhypo \notag e=f \ \label{test_3} h=i \unsetmyhypo \end{gather}

\setmyhypo \begin{gather} \label{test_4} j=k \ \notag l=m \end{gather} \unsetmyhypo

\eqref{test_1}, \eqref{test_2} and \eqref{test_4} work but not \eqref{test_3}.

\end{document}

Any idea on how to use both equation-like environments inside the same gather (it may be cleaner for alignment purpose)?

Edit: refinements:

\makeatletter
\newcommand{\setmyhypo}{%
  \setcounter{savedequation}{\value{equation}}%
  \setcounter{equation}{\value{myhypo}}%
  \renewcommand\theequation{$H_{\arabic{equation}}$}%
  \tagsleft@true\let\veqno\@@leqno%
}

\newcommand{\unsetmyhypo}{% \setcounter{myhypo}{\value{equation}}% \setcounter{equation}{\value{savedequation}}% \renewcommand\theequation{\arabic{equation}}% \tagsleft@false\let\veqno@@eqno% } \makeatother

1 Answers1

0

Use \tag (together with code that does the necessary stuff).

I made some changes to the code, please check them.

\documentclass[a4paper,10pt]{article}

\usepackage{amsmath}

\newcounter{savedequation} \newcounter{myhypo} \renewcommand\themyhypo{\ensuremath{\mathrm{H}_{\arabic{myhypo}}}}

\newcommand{\setmyhypo}{% \setcounter{savedequation}{\value{equation}}% \setcounter{equation}{\value{myhypo}}% \renewcommand\theequation{\ensuremath{\mathrm{H}_{\arabic{equation}}}}% }

\newcommand{\unsetmyhypo}{% \setcounter{myhypo}{\value{equation}}% \setcounter{equation}{\value{savedequation}}% }

\newenvironment{hypothesis}{% \setmyhypo \begin{equation}% }{% \end{equation}% \unsetmyhypo \ignorespacesafterend } \newcommand{\hypoline}{\stepcounter{myhypo}\tag{\themyhypo}}

\begin{document}

\begin{hypothesis}\label{test_1} a=b \end{hypothesis}

\begin{gather} c=d \label{test_2} \ e=f \notag \ h=i \hypoline \label{test_3} \ u=v \end{gather}

\setmyhypo \begin{gather} j=k \label{test_4} \ l=m \notag \end{gather} \unsetmyhypo

\eqref{test_1}, \eqref{test_2} and \eqref{test_4} work and also does \eqref{test_3}.

\end{document}

enter image description here

egreg
  • 1,121,712
  • Thanks. It is indeed cleaner. I did not use \tag initially because I also use hyperref and I was not sure it would work correctly with hyperref, but I do not see why not : I'm going to test it now. – dominique Oct 06 '22 at 13:43
  • Ah, its the requirement to change the side of the tag \tagsleft@true\let\veqno\@@leqno, that I foolishly added later, that I don't see how to make work properly... It does not seem to work if called inside an amsmath environment. However it was not so important. – dominique Oct 06 '22 at 14:04
  • Using your command \hypoline, there is no more real need of a specific hypothesis environment, nor of my commands \setmyhypo, \unsetmyhypo, nor of counter savedequation. – dominique Oct 06 '22 at 14:09
  • @dominique Yes, that's right. – egreg Oct 06 '22 at 14:11