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 –  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
  • @barbarabeeton That did the trick. Very simple solution. Thanks! Because I don't want the section appearing in the theorem/definition numbering, I customized that. My code is now: `\documentclass{amsart}

    \numberwithin{subsection}{section} \renewcommand\thesubsection{\textbf{\arabic{subsection}}}

    \newtheorem{dummy}{***}[subsection] \newtheorem{theorem}[dummy]{Theorem} ...`

    – Nicholas Camacho Jan 16 '18 at 20:03
  • @NicholasCamacho -- since this works, you should post a self-answer, with a clear example and its output. (i don't have access to a latex setup where i am, so i can't do anything useful.) – barbara beeton Jan 16 '18 at 21:49
  • @barbarabeeton For some reason, after I compiled it a second time, it stopped working. It does output the references the way I want, but unfortunately it also changes the numbering of theorems to include the section number as well. I think its because I'm giving it two commands to obey concerning the subsection. – Nicholas Camacho Jan 16 '18 at 22:56
  • @NicholasCamacho -- this may possibly help: Theorem numbering without the section and subsection numbers. unfortunately, as i said before, i haven't got access to a latex installation where i am. (but i know that what you want is possible.) – barbara beeton Jan 17 '18 at 01:09
  • @barbarabeeton Got it! See my answer below. – Nicholas Camacho Jan 20 '18 at 20:46

1 Answers1

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}