# How can I make subsections lose the section number within the section and gain the section number outside it?

For a paper I am typesetting, the author wants subsections to be written with single numerals. So far, OK,

\renewcommand{\thesubsection}{\arabic{subsection}}


does the job.

Yet frequently, he wants to cite the subsection in a later section, and wants both section and subsection numbers in references; i.e., he wants to quote Section 1.1 from Section 2.

My current workaround is to give both the section and subsection numbers in the reference.

MWE

\documentclass[11pt]{amsart}
\usepackage{hyperref}
\usepackage[backend=bibtex,citestyle=alphabetic]{biblatex}
\renewcommand{\thesubsection}{\arabic{subsection}}

\begin{document}
\section{A section} \label{sec:first}
\subsection{A subsection} \label{subsect:first} Something cool.
\section{New section}
Now I want to cite the coolness in Section~\ref{sec:first}.\ref{subsect:first}.
\end{document}


This works fine, except that the hyperref is set up so that if you click on the first 1, you go to Section 1, not Subsection 1. Yet I would prefer that both numerals go to the same place in the hyperref links.

I could just wrap each such citation in \renewcommand{\thesubsection}'s, but is there an easier way to add section numbers when citing subsections from a different section?

Note: Since I'm using biblatex, titlesec is not applicable.

-
What makes you can't use biblatexalong with titlesec? –  Bernard Jun 27 '14 at 18:04
@Bernard, the biblatex documentation mentions that titlesec can redefine the section and chapter commands, and hence conflicts with biblatex's usage of these for some reason. –  user52733 Jun 27 '14 at 22:02
It's funny that titlesec doesn't mention this. On an other hand, as I tested, I noticed a conflict between titlesecand the amsart class (biblatex not loaded, hence independent of it). –  Bernard Jun 27 '14 at 22:08
The question in the body seems to be on how to fix the 1.1 being two separate links, and this is what the current answers address. The question in the title is different, and does not seem to be answered so far. –  ronno Jun 28 '14 at 9:39
It's a point, @ronno . Fortunately, in the actual paper, subsections are never cited within their sections so that the answers below are adequate. Also, it seems that by @Werner's answer, zref certainly handles this (if not automatically) by its generality and flexibility. It would be nice, though, to do this automatically, although a conditional is presumably required. –  user52733 Jun 29 '14 at 12:48

You could (a) redefine \thesection as you're already doing and (b) redefine the macro \p@subsection. The macro \p@subsection, which governs the material that's prefixed to a cross-reference to an item of type subsection, is set up automatically by LaTeX when the counter subsection is set up. Its default behavior is to do nothing; here, we change it to insert \thesection. immediately before the cross-reference to a subsection-level item.

Because the macro name \p@subsection contains the character @, it's necessary to encase its redefinition in \makeatletter ... \makeatother.

\documentclass[11pt]{amsart}
\renewcommand{\thesubsection}{\arabic{subsection}}
\makeatletter
\renewcommand{\p@subsection}{\thesection.}
\makeatother

\begin{document}
\section{A section} \label{sec:first}
\subsection{A subsection} \label{subsect:first} Something cool.
\section{New section}
Now I want to cite the coolness in subsection \ref{subsect:first}.
\end{document}

-

You can redefine the \@seccntformat command to use \mythesubsection instead of \thesubsection, provided the former is defined.

\documentclass[11pt]{amsart}

\usepackage[backend=bibtex,citestyle=alphabetic]{biblatex}
\usepackage{hyperref}

\makeatletter
\renewcommand{\@seccntformat}[1]{%
\protect\textup{%
\protect\@secnumfont\protect\check@format{#1}\protect\@secnumpunct
}%
}
\newcommand{\check@format}[1]{%
\@ifundefined{mythe#1}{\@nameuse{the#1}}{\@nameuse{mythe#1}}%
}
\makeatother

% removing this line will restore the usual setting
\newcommand{\mythesubsection}{\arabic{subsection}} % just print the subsection number

\begin{document}
\section{A section} \label{sec:first}
\subsection{A subsection} \label{subsect:first} Something cool.
\section{New section}
Now I want to cite the coolness in Section~\ref{subsect:first}.
\end{document}


You might also want to define \mysubsubsection in case also \subsubsection is used and is numbered.

-

zref allows you to generate specific references based on a set of properties. Below I've defined the property list sections, which store the section, subsection and section.subsection as part of the property list what you mark a \label (actually, a \zref@labelbypropertylist):

\documentclass[11pt]{amsart}
\usepackage{hyperref}

\renewcommand{\thesubsection}{\arabic{subsection}}

\usepackage{zref}
\makeatletter
\zref@newlist{sections}
\zref@newprop{section}{\thesection}
\zref@newprop{subsection}{\thesubsection}
\zref@newprop{secsubsection}{\thesection.\thesubsection}
\newcommand{\zlabel}[1]{\zref@labelbylist{#1}{sections}}
\newcommand{\zref}[2][section]{\hyperref[#2]{\zref@extractdefault{z:#2}{#1}{\textbf{??}}}}
\makeatother
\AtBeginDocument{%
\let\oldlabel\label
\renewcommand{\label}[1]{\oldlabel{#1}\zlabel{z:#1}}}

\begin{document}

\section{A section}
\subsection{A subsection} \label{subsect:first} Something cool.
\section{New section}
Now I want to cite the coolness in Subsection~\zref[secsubsection]{subsect:first}
(it is Subsection~\zref[subsection]{subsect:first} in Section~\zref[section]{subsect:first}).
\end{document}


All the hyperlinks in the output point to the same location.

-