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

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}
amsart
document 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:05zref
approach given in the linked answer should work – user31729 Jan 16 '18 at 18:45amsart
(which incorporatesamsthm
) you would need to also specify\numberwithin{subsection}{section}
. that isn't automatic. – barbara beeton Jan 16 '18 at 19:53