nameref to label of \part

Issue #128 resolved
Holger Mitschke created an issue

By default currentlabelname is not set by the definition of part in documentclasses.

However, to use \nameref of hyperref, part can be redefined for this purpose.

See http://tex.stackexchange.com/questions/211035/problems-with-nameref-not-refering-to-the-correct-label-x-titlesec

Would you consider making the redefinition of part in classicthesis compatible with nameref?

\documentclass{scrbook}

\usepackage[
  parts,
]
{classicthesis}

\usepackage{hyperref}

% http://tex.stackexchange.com/questions/211035/problems-with-nameref-not-refering-to-the-correct-label-x-titlesec
\makeatletter
\let\oldpart\part
\def\part#1{\def\@currentlabelname{#1}\oldpart{#1}}
\makeatother

\usepackage[
  capitalise,
  nameinlink,
]{cleveref}

\begin{document}

\chapter*{Preface}
\label{chapt:preface}
We discuss in \emph{\cref{part:superpart} ``\nameref{part:superpart}''} the super results.

\part{Super Part}
\label{part:superpart}

This is the super part.

\end{document}

Official response

  • André Miede repo owner

    Thanks for the input. Ivo fixed a lot of things with the implementation of \part, so your work-around should work now:

    \makeatletter
    \let\oldpart\part
    \def\part#1{\def\@currentlabelname{#1}\oldpart{#1}}
    \makeatother
    

    However, the part-number is still in lower-case, which has to be fixed...

Comments (14)

  1. André Miede repo owner

    Thanks for the input. Ivo fixed a lot of things with the implementation of \part, so your work-around should work now:

    \makeatletter
    \let\oldpart\part
    \def\part#1{\def\@currentlabelname{#1}\oldpart{#1}}
    \makeatother
    

    However, the part-number is still in lower-case, which has to be fixed...

  2. Ivo Pletikosić

    Part number is in lowercase because of \renewcommand{\thepart}{\roman{part}} in classicthesis.sty. One could change this to \renewcommand{\thepart}{\Roman{part}}, then however the TOC would look ugly - part numbers would be too tall. One could then change \renewcommand{\cftpartpresnum}{\scshape} to \renewcommand{\cftpartpresnum}{\scshape\MakeTextLowercase}, but this would only lowercase the first character of the roman number because of the primitive way these entries are written to the .toc file. It's pretty hopeless, I think, unless one really digs deep into how the .toc entries are being written. This differs between document classes.

    How about we leave these instructions here for those few who really need it. The redefinition of \part above does not include \part* command, nor does it take into account that \part can have an optional argument (short title). Plus we have just gotten rid of an ugly and lengthy redefinition of the \part command, better not to go back there. My two cents.

  3. kluth

    An alternative workaround (from TeX stackexchange) which looks better to my eyes: In the preamble:

    \usepackage{cleveref}
    \crefformat{part}{Part #2\MakeUppercase{#1}#3}
    

    In the main text use \cref instead of \ref (no need to manually write "Part"):

    Bla bla in \cref{sec:part}.
    
  4. André Miede repo owner

    Thank you very much for you input and your patience. I will look into this for the next release.

  5. André Miede repo owner

    Thanks to kluth and Enrico Gregorio for this fix, will be in next release (to be tested for side effects).

  6. Log in to comment