1

I try to rename the \autoref from subsection to just section. But it seems that the [english]{babel} is preventing it somehow. Interestingly it works for subsubsections (but I do not use them.)

\documentclass[11pt,numbers=noenddot,bibliography=totocnumbered,twoside]{scrreprt}
\usepackage[english]{babel}
% \let\subsectionautorefname\sectionautorefname
\def\subsectionautorefname{section}
\def\subsubsectionautorefname{section}  %define subsection as section and subsub to section
\usepackage[unicode]{hyperref}  %Hyperlinks in text as reference unicode to use in references

\begin{document}
\chapter{Chapter}
\section{Section}
\label{sec}

\subsection{Foo}
\label{ssec:foo}
This is the overview.

\subsubsection{Bar}
\label{sssec:bar}
This is the small part.

Later in the text, we refer to \autoref{sec}, \autoref{ssec:foo} and \autoref{sssec:bar}.
\end{document}

I also tried to work here to test it. Also \let\subsectionautorefname\sectionautorefname do not change it.

Is there any other way, without changing the document class or other major changes?

Kind regards, DeepWater

2
  • Hyperref does a lot at the start of the doc, have you tried delaying th redefs by wrapping it in \AtBeginDocument{...} and probably moving it after loading hyperref (I'm not at a pc so cannot test)
    – daleif
    Apr 8, 2020 at 11:40
  • 1
    I confirm that \AtBeginDocument works.
    – Bernard
    Apr 8, 2020 at 11:43

4 Answers 4

1

With scrreprt you can use KOMA-Script command \defcaptionname:

\defcaptionname*{english}{\subsectionautorefname}{section}
\defcaptionname*{english}{\subsubsectionautorefname}{section}

If you want to reference the number of a subsubsection (using \autoref or\ref`), this subsubsection must be numbered. So you have to add:

\setcounter{secnumdepth}{\subsubsectionnumdepth}

to your preamble.

Example:

\documentclass[11pt,numbers=noenddot,bibliography=totocnumbered,twoside]{scrreprt}
\usepackage[english]{babel}
\defcaptionname*{english}{\subsectionautorefname}{section}
\defcaptionname*{english}{\subsubsectionautorefname}{section}
\usepackage[unicode]{hyperref}
\setcounter{secnumdepth}{\subsubsectionnumdepth}% subsubsections should be numbered
\begin{document}
\chapter{Chapter}
\section{Section}\label{sec}
\subsection{Foo}\label{ssec:foo}
This is the overview.
\subsubsection{Bar}\label{sssec:bar}
This is the small part.

Later in the text, we refer to \autoref{sec}, \autoref{ssec:foo} and \autoref{sssec:bar}.
\end{document}
1
  • I think you should mention explicitly the other instruction you inserted, viz. \setcounter{secnumdepth}{\subsubsectionnumdepth} (which is equivalent to \setcounter{secnumdepth}{3}). Without this instruction, the two \defcaptionname* instructions have no useful effect.
    – Mico
    Apr 8, 2020 at 15:09
0

Thx daleif and Bernard,

loading hyperref early do not change anything, but putting the definition after \begin{document} solved it.

Also testing some more, after you suggested the order resulting that

\usepackage[unicode]{hyperref}
\usepackage[english]{babel} 

also where, independet where the definitions are.

Thx a lot.

6
  • 2
    That is actually not the right solution, as soon as you select a language it will revert back. Doing it right for subsection is easy, but the real mystery is the subsubsection behaviour - that looks like a bug. Apr 8, 2020 at 11:58
  • @UlrikeFischer - Not a bug at all -- see my answer.
    – Mico
    Apr 8, 2020 at 11:58
  • 1
    @Mico What I meant is that autoref should detect an unnumbered section and not fall back to section in this case. Apr 8, 2020 at 12:03
  • @Ulrike Fischer, using the order above seems to define the autoref label first with the default language and do not change if i use [ngerman] after hyperref. At least i still get the same output. Just changing the order of babel and hyperref results in a different output.
    – DeepWater
    Apr 8, 2020 at 12:30
  • Yes, if you load babel later, hyperref won't detect it and not activate its language support. But normally you should load hyperref late. Apr 8, 2020 at 12:33
0

hyperref has language support and when it detects babel it will add the autoref definitions to \extrasenglish. To overwrite the definitions you should add your changes there too (after the hyperref changes). As Mico wrote, for a correct behaviour (both regarding the text and the counter) with \subsubsection you should set secnumdepth.

\documentclass[11pt,numbers=noenddot,bibliography=totocnumbered,twoside]{scrreprt}
\usepackage[english]{babel}
\usepackage[unicode]{hyperref} 


 \addto\extrasenglish{%
  \def\subsectionautorefname{section}%
  \def\subsubsectionautorefname{section}%
  }

\setcounter{secnumdepth}{3}
\begin{document} 

\chapter{Chapter}
\section{Section}
\label{sec}

\subsection{Foo}
\label{ssec:foo}
This is the overview.

\subsubsection{Bar}
\label{sssec:bar}
This is the small part.

Later in the text, we refer to \autoref{sec},   \autoref{ssec:foo}  and \autoref{sssec:bar} 
\end{document}
0

The issue you've encountered is not related to the fact that you employ the babel package. Instead, the issue arises for the following reason. In the scrreport document class, the default value of the counter secnumdepth is 2, meaning that only section- and subsection-level headers, but not subsubseection-level headers as well, are numbered. You may verify this claim by looking at the output of your MWE: The header "Bar" is not numbered at all. Because it's not numbered, the label {sssec:bar} doesn't point to that header.

The remedy? Increase the value of secnumdepth via \setcounter{secnumdepth}{3}.

Addendum: About the "labels" for subsections and subsubsections: I wouldn't fiddle with \def\subsectionautorefname etc. Instead, load the cleveref package after hyperref, with the option nameinlink. That way, the cross-reference generated by \cref will look automatically like the one generated by \autoref.

enter image description here

\documentclass[11pt,numbers=noenddot,twoside]{scrreprt}
\setcounter{secnumdepth}{3} % new
\usepackage[english]{babel}
\usepackage{hyperref}
\usepackage[nameinlink]{cleveref}

\begin{document}
\chapter{Chapter}
\section{Section}   \label{sec}
\subsection{Foo}    \label{ssec:foo}
\subsubsection{Bar} \label{sssec:bar}

\cref{sec}, \cref{ssec:foo}, \cref{sssec:bar}
\end{document}
3
  • I appreciate your concerns. The subsub label "Bar" point to Bar but said by default section 1.1.1. I just used it to confirm if the subsection is not working or all relabeling. But with your answer i can also relabel the subsub name, which i did not indent to use. But it helps a lot understanding what is going on better.
    – DeepWater
    Apr 8, 2020 at 12:19
  • @DeepWater - The claim that "The subsub label "Bar" point to Bar" is not quite right. More precisely, it's correct only if the counter subsubsection actually gets incremented. Why? LaTeX associates a \label instruction with the most recently incremented counter variable. If secnumdepth=2, then the most-recently-incremented counter variable is not subsubsection but subsection -- and that's what the number in the cross-reference says.
    – Mico
    Apr 8, 2020 at 12:22
  • for me there are to pointers, one for the labelname and one for the lable position. And the position is the correct one, even if the name is wrong. Yes i agree, if you use subsubsection you should enable them with "\setcounter{secnumdepth}{3} " first to fully support them.
    – DeepWater
    Apr 8, 2020 at 12:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .