I have a label that references what is currently section 1.4. Can I tweak either the \ref
or \label
so that it appears as 4 (i.e. only the subsection number) when reffed?
1 Answer
Assuming you're sure that your reference have the form m.n, then the following code
\usepackage{refcount}
\newcommand\subsecref[1]{%
\edef\temp{\getrefnumber{#1}}%
\ifnum0=\temp ??\else
\expandafter\eatsection\temp\eatsection
\fi}
\def\eatsection#1.#2\eatsection{#2}
will do: call \subsecref{label}
.
It's more complicated if the form of the references is different (say if they are chapter.section.subsection, but not conceptually more difficult.
A less efficient implementation that works also in expansion context is
\usepackage{refcount}
\newcommand\subsecref[1]{%
\ifnum0=\romannumeral-`0\getrefnumber{#1}??%
\else
\expandafter\eatsection\romannumeral-`0\getrefnumber{#1}\eatsection
\fi}
\def\eatsection#1.#2\eatsection{#2}