1

As I don't want my sections ... paragraphs to stay unnumbered, I wrote \setcounter{tocdepth}{5} \setcounter{secnumdepth}{0}. With cleveref I cannot refer to unnumbered sections as "section" at all.

To be more clear: I defined a new ref-format \RenewDocumentCommand\fullref{m}{\namecref{#1} \nameref{#1} \vpageref{#1}}, which should give something like "section sectiontitle on page 2" or "subsection sectiontitle on page 4.

% uses-*- MODE: latex; TeX-engine: luatex; coding: utf-8; -*-
\documentclass{scrartcl}
\usepackage[main=ngerman]{babel}
\usepackage[german,final]{varioref}
\usepackage{hyperref}
\usepackage[german,nameinlink]{cleveref}
\makeatletter
\RenewDocumentCommand\fullref{m}{\namecref{#1} \nameref{#1}
  \vpageref{#1}}
\setcounter{tocdepth}{5}
\setcounter{secnumdepth}{0} % <---
\makeatother
\begin{document}
\section{I'm Section}
\label{sec:section}
bla

see \namecref{sec:subsubsection}

see \fullref{sec:subsubsection} \newpage \subsection{I'm Subsection} \label{sec:subsection} bla

bla

see \namecref{sec:section}

see \fullref{sec:section}

see \namecref{sec:subsection}

see \fullref{sec:subsection} \newpage \subsubsection{I'm Child of Subsection} \label{sec:subsubsection}

\end{document}

  • 1
    you could try \autoref instead of \namecref. – Ulrike Fischer Jul 31 '23 at 22:54
  • 1
    \label only stores 4 values in the aux file: \@currentlabel, \thepage, \@currentlabelname and \@currentHref. The section title is stored in \@currentlabelname which is a missuse of the entry IMHO. – John Kormylo Jul 31 '23 at 23:14
  • @JohnKormylo @currentlabelname is meant for the title, it is not a misuse. – Ulrike Fischer Aug 01 '23 at 06:12
  • @JohnKormylo sorry I don't know what you mean. @currentlabelname is imho used since more than 20 years by nameref, and @currentcounter was never saved by \label (but you can save it e.g. with zref) – Ulrike Fischer Aug 01 '23 at 12:25
  • OTOH, I have seen people get the counter name by editing \currentHref. This doesn't always work (see https://tex.stackexchange.com/questions/643473/unexpected-table-figure-reference/643489?r=SearchResults&s=3%7C10.6660#643489). – John Kormylo Aug 01 '23 at 13:01
  • @JohnKormylo yes, autoref tries to guess the counter name by looking at currentHref, and that doesn't always work. But with the new label implementation you can now insert a hook to properly store the counter name and reference it e.g. with zref. At sometime I will perhaps try to adapt autoref to use the new option. – Ulrike Fischer Aug 01 '23 at 13:59
  • One could do like the subcaption package and create two \newlabel commands for each \label. – John Kormylo Aug 01 '23 at 16:15

1 Answers1

3

You could try the following. This requires a current LaTeX.

\documentclass{scrartcl}
\usepackage{varioref}
\usepackage{hyperref}
\usepackage{cleveref}
\RenewDocumentCommand\fullref{m}{\namecref{#1} \nameref{#1}
  \vpageref{#1}}

\setcounter{secnumdepth}{0} % <---

\makeatletter \AddToHookWithArguments{cmd/@sect/before}{\def\cref@currentlabel{[#1][??][??]??}} \makeatother

\crefname{section}{section}{sections} \crefname{subsection}{subsection}{subsections} \crefname{subsubsection}{subsubsection}{subsections} \begin{document}

\section{I'm Section}\label{sec:section} bla

see \namecref{sec:subsubsection}, \cref{sec:subsubsection}

see \fullref{sec:subsubsection} \subsection{I'm Subsection}\label{sec:subsection} bla see \namecref{sec:section}

see \fullref{sec:section}

see \namecref{sec:subsection}

see \fullref{sec:subsection} \subsubsection{I'm Child of Subsection} \label{sec:subsubsection} \end{document}

enter image description here

Ulrike Fischer
  • 327,261