As the title says, I want to define an eqref
command such that if the equation is in the current subsection then it produces the usual (1) and that if the equation is in another subsection then the cite looks like ¶2.3 Equation (4). It is similar to my previous question Include the subsection number in cross-reference to a theorem-like environment (the solution given by @egreg).
I have tried to copy the code with some changes. Here it is:
\let\eqref\relax
\makeatletter
\renewcommand*{\c@equation}{\perhapssubsection{\thesubsection}}
\newcommand{\eqref}[1]{\textsc{Equation}~\textup{(\ref{#1})}}
\makeatother
However, it does not work. Can you help me, please?
Here is my MWE:
\documentclass[a4paper,12pt]{article}
\usepackage{mathtools}
\usepackage{xparse}
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheoremstyle[%
spaceabove=\topsep,
spacebelow=\topsep,
headfont=\scshape,
bodyfont=\itshape,
notefont=\normalfont,
notebraces={}{.},
headpunct={},
postheadspace=1em,
headformat=\NAME\space\NUMBER.---\NOTE,
headindent=\parindent
% qed=$\qedsymbol$%
]{theorem}
\declaretheorem[style=theorem,name=Theorem,numberwithin=subsection]{theorem}
\makeatletter
\@addtoreset{equation}{subsection}% Reset equation at \section
\makeatother
\makeatletter
\def\gobblesomething#1\csname thesection\endcsname{\begingroup\normalfont\S\thesection\endgroup}
\def\gobblesomethingother#1\csname thesubsection\endcsname{\begingroup\normalfont\P\thesubsection\endgroup}
\renewcommand*{\p@section}{\gobblesomething}
\renewcommand*{\p@subsection}{\gobblesomethingother}
\makeatother
\renewcommand{\thetheorem}{\arabic{theorem}}
\makeatletter
\def\gobblesomethinga#1\csname thetheorem\endcsname{\begingroup\normalfont\textsc{Theorem}~\thetheorem\endgroup}
\renewcommand*{\p@theorem}{\perhapssubsection{\thesubsection}\gobblesomethinga}
\makeatother
\ExplSyntaxOn
\NewDocumentCommand{\perhapssubsection}{m}
{
\str_if_eq_x:nnF { #1 }{\thesubsection}{\P\textup{#1}~}
}
\ExplSyntaxOff
\begin{document}
\section{One}
\subsection{A}
\begin{theorem}
\label{th:E}
Bla bla bla
\begin{equation}
E=mc^2
\label{eq:E}
\end{equation}
\end{theorem}
\subsection{B}
In \ref{th:E} and \eqref{eq:E}
\end{document}
\perhapssubsection
is not a default command, so you need to copy its definition also.\gobblethinga
is quite difficult to understand.