0

I have my theorems labeled as subsection.theoremnumber. So for example: Theorem 2.3 is the third theorem in subsection 2. If the subsection is in say, section 4, I would like when I reference this theorem in say, section 6, for it to read Theorem 4.2.3.

I know that this is similar to refer to theorems in previous chapter, but the answers there do not work for sections.

  • in order to answer this, we need to know what document class and theorem package you are using, and how you assign the number to the theorems. – barbara beeton Jan 16 '18 at 16:52
  • @barbarabeeton I left it ambiguous in hopes for a general simple fix, but I suppose it must depend on the document class. I am using theamsartdocument class. I have a "dummy" theorem environment \newthoerem{dummy}{***}[subsection], so that my theorems, definitions, etc. can all be numbered with the same counter:\newtheorem{theorem}[dummy]{Theorem} and \newtheorem{definition}[dummy]{Definition}. – Nicholas Camacho Jan 16 '18 at 17:05
  • The zref approach given in the linked answer should work – user31729 Jan 16 '18 at 18:45
  • @ChristianHupfer I tried a couple different ways to apply that code, and it hasn't worked. Would you show me an example of how it would work in my case? – Nicholas Camacho Jan 16 '18 at 19:37
  • @NicholasCamacho -- with amsart (which incorporates amsthm) you would need to also specify \numberwithin{subsection}{section}. that isn't automatic. – barbara beeton Jan 16 '18 at 19:53
1

By changing the word "chapter" to "section" everywhere in the code which is linked in my question, I achieved my desired result.

Output:

enter image description here

Code:

\documentclass{amsart} 
\usepackage{amsthm}
\usepackage{zref}% http://ctan.org/pkg/zref

\makeatletter
\let\oldlabel\label
\renewcommand{\label}[1]{%
\zref@labelbylist{#1}{special}% Special label
\oldlabel{#1}% Old label
}
\newcounter{splabel}
\zref@newlist{special}% Create a new property list called special
\zref@newprop{section}{\arabic{section}}% Section property holds \arabic{section}
\zref@addprop{special}{section}% Add a section property to special
\newcommand*{\thmref}[1]{%
  \stepcounter{splabel}% Increment local "special label" counter
\zref@labelbylist{#1-\thesplabel}{special}% Create label
\edef\targetsec{\zref@extractdefault{#1}{section}{-1}}% Extract target section
\edef\sourcesec{\zref@extractdefault{#1-\thesplabel}{section}{-1}}% Extract source section
\ifnum\targetsec=\sourcesec\else\targetsec.\fi%
\ref{#1}%
}

\newtheorem{dummy}{***}[subsection]% Used so that theorems, definitions, etc can have same counter within subsections
\newtheorem{theorem}[dummy]{Theorem}
\newtheorem{lemma}[dummy]{Lemma}

\theoremstyle{definition}
\newtheorem{definition}[dummy]{Definition}
\newtheorem{remark}[dummy]{Remark}

\renewcommand{\thesubsection}{\arabic{subsection}}% Custom numbering on subsection to remove section number

\begin{document}

\section{First Section}
\subsection{First Subsection in Section 1}
\begin{definition} 
    Good definition.
\end{definition}

\subsection{Second Subsection in Section 1}
\begin{remark}
    Interesting remark. 
\end{remark}
\begin{lemma} \label{lem:name}
    Useful lemma.
\end{lemma}

\subsection{Third subsection in Section 1}

\begin{theorem} \label{thm:name}
    Important theorem.
\end{theorem}

\section{Section 2}
\subsection{Another subsection} There's not much to say here. 
\subsection{Last Subsection}\ 
 As you can see, Theorem \thmref{thm:name}  is very important. Indeed, Lemma~\thmref{lem:name} was quite useful. 
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.