# \nameref breaks for star versions of section/paragraph when titlesec is loaded

\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.

-

\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.

\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.

-
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
it needed several (at least 5) reruns of pdflatex to make this fix work. –  Jan Jul 30 at 8:26