0

I'm working with \autoref from the hyperref package to reference my sections, etc.

What I currently work with:

\documentclass[a4paper, 12pt, parskip]{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[hidelinks]{hyperref}
\addto\extrasenglish{%
    \renewcommand{\chapterautorefname}{Chapter}%
    \renewcommand{\sectionautorefname}{Section}%
    \renewcommand{\subsectionautorefname}{Section}%
    \renewcommand{\subsubsectionautorefname}{Section}%
    \renewcommand{\paragraphautorefname}{Paragraph}%
}

As my secnumdepth uses the default value my paragraphs are not numbered. Therefore, I'm currently using

\autoref{example} (\nameref{example})

to reference my paragraphs. I could obviously write a command for that but would have to change it in case I restructure my document (which somehow goes against the idea of autoref).

I wondered whether it would be possible to change the behavior of the \autoref command to something like the above depending on the secnumdepth counter, i.e. for all unnumbered sections (I'm never referencing starred sections line \section*).

As I have no idea how I would do that, my only idea was to redefine the \paragraphautorefname command like so

\def\paragraphautorefname~#1\null{%
  Section~#1 (<paragraphname>)\null
}

but I don't know how to access the paragraph's name there.

Any thoughts on this? Is there an easier way I'm not seeing?

Edit: To clarify the outcome I'm lookig for.

\documentclass[a4paper, 12pt, parskip]{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[hidelinks]{hyperref}
\addto\extrasenglish{%
    \renewcommand{\chapterautorefname}{Chapter}%
    \renewcommand{\sectionautorefname}{Section}%
    \renewcommand{\subsectionautorefname}{Section}%
    \renewcommand{\subsubsectionautorefname}{Section}%
    \renewcommand{\paragraphautorefname}{Paragraph}%
}

\begin{document}

\chapter{Chapter 1}\label{cha:1}
\section{Section 1}\label{sec:1}
\subsection{Subsection 1}\label{sub:1}
\subsubsection{Subsubsection 1}\label{subsub:1}
\paragraph{Paragraph 1}\label{par:1}

\section{Another Section}
Here I can happily reference \autoref{cha:1}, \autoref{sec:1}, \autoref{sub:1}, and \autoref{subsub:1}.

If I'm trying to reference the paragraph, as expected, I will get the result of the next enclosing numbered section \autoref{par:1}.

I want that \verb|\autoref| applied to \texttt{par:1} outputs something like \verb|\nameref{par:1} (\autoref{par:1})| would, so: \nameref{par:1} (\autoref{par:1}), without me doing that manually.

\end{document}

output of the MWE above

  • The \fullref command here will do exactly what you are looking for tex.stackexchange.com/a/121871/172926 (just put some parentheses around the \nameref*). – Pippip19 Feb 24 at 6:44
  • Sorry if that was not completely clear: I want to automatically do that when using \autoref but, if and only if the referenced section is not numbered. The \autoref command should have different outputs -- I do not want the name of the section if it is numbered. – fhred Feb 24 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.