Cross-referencing – How to Get the Section Label from a Label Inside an Enumerate List in LaTeX

cross-referencing

When I define a label inside an enumerate-list I get a reference to the item number.

Is it possible to get a reference to the section?

Example:

\documentclass[english]{scrartcl} 
\usepackage{babel} 
\usepackage{blindtext} 

\newcommand\secref[1]{[section of label '#1']}%<-- I ask for this function.
\begin{document}
%Should be: The 2nd item point on page 3 is in section 2.3.1
The \ref{mylabel}nd item point on page \pageref{mylabel} is in section \secref{mylabel}

%Should be: The 2nd item point on page 3 is in section 2.3.1
The \ref{mylabel}nd item point on page \pageref{mylabel} is in section \ref{sec:mylabel}

\blinddocument%create some (sub)sections

\label{sec:mylabel}
\begin{enumerate}
\item point 1
\item \label{mylabel} here is a label
\end{enumerate}

\end{document}

Remark I: I don't want to replace \ref to show always the section reference. I want to have the choice to get the item reference or the section reference.

Remark II:
The 2nd sentence in my example shows the result I want. But I want to avoid the definition of the help-label sec:mylabel.

Best Answer

Emit two \label commands:

\documentclass{article}
\makeatletter
\newcommand{\seclabel}[1]{{%
  \label{#1}%
  \edef\@currentlabel{\thesection}%
  \label{sec:#1}}}
\makeatother

\begin{document}
\section{A}

\begin{enumerate}
\item X
\item\seclabel{mylabel} Y
\item Z
\end{enumerate}

This is a reference to item~\ref{mylabel} in section~\ref{sec:mylabel}
on page~\pageref{mylabel}.

\end{document}

This gives

This is a reference to item 2 in section 1 on page 1.

Of course, if hyperref is loaded, clicking on the link created by \ref{sec:mylabel} will take to the item in the enumerate environment.