Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

\nameref breaks for the star versions of section, paragraph when titlesec is loaded. I have a document that numbers paragraphs by default, but I have a few I do not want to number but would like to refer to. These are marked with \paragraph*, however, if the titlesec package is loaded at the same time, it causes nameref to display an empty string (the link box of hyperref is still visible).

MWE:

\documentclass[12pt]{article}
\usepackage[sf]{titlesec} %comment this out and it works fine.
\usepackage{hyperref}
\begin{document}
\section{Sections}
\label{sec}
This is \nameref{sec}
\paragraph{A named Paragraph}
\label{par}
This is \nameref{par}
\paragraph*{A starred named Paragraph}
\label{par:star}
This is \nameref{par:star}
\end{document}

I suspect titlesec causes this defect for ALL star variants of sectioning commands but have not tested this. For me only paragraph* is relevant however a fix for all variants would be the best.

I have a hunch it might be related to this: http://tex.stackexchange.com/a/6658/19326 however this happens to go way beyond my latex knowledge and is just "magic" for me.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Add the following to your preamble:

\makeatletter
\def\ttl@useclass#1#2{%
  \@ifstar
    {\ttl@labeltrue\@dblarg{#1{#2}}}% {\ttl@labelfalse#1{#2}[]}%
    {\ttl@labeltrue\@dblarg{#1{#2}}}}
\makeatother

This allows for processing of the regular arguments \<section>[<ToC>]{<regular>} with the sectional unit \<section>. Additionally, setting \ttl@labeltrue inserts the appropriate hyperref anchor.

enter image description here

\documentclass[12pt]{article}
\usepackage[sf]{titlesec} %comment this out and it works fine.
\usepackage{hyperref}
\makeatletter
\def\ttl@useclass#1#2{%
  \@ifstar
    {\ttl@labelfalse\@dblarg{#1{#2}}}% {\ttl@labelfalse#1{#2}[]}%
    {\ttl@labeltrue\@dblarg{#1{#2}}}}
\makeatother
\begin{document}
\section{Sections}
\label{sec}
This is \nameref{sec}
\paragraph{A named Paragraph}
\label{par}
This is \nameref{par}
\paragraph*{A starred named Paragraph}
\label{par:star}
This is \nameref{par:star}
\end{document}

Not extensively tested.

share|improve this answer
    
Thank you, it seems to work ( I did not notice anything else breaking). Would you mind giving me a pointer were I could read/learn about @useclass , etc. so that I can understand what magic you used there? (googling @useclass turns up 2 results not related to tex, if you point me to a reference I am eager to learn by looking up the details myself rather than getting it laid out for me(Ihope to learn more that way)) –  ted Jul 11 '13 at 22:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.