[texhax] memoir, hyperref, nameref

Lars Madsen daleif at imf.au.dk
Fri Apr 16 13:42:57 CEST 2010


Lars Madsen wrote:
> Heiko Oberdiek wrote:
>> On Thu, Apr 15, 2010 at 04:06:46PM +0200, Uwe Lueck wrote:
>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: Lars Madsen <daleif at imf.au.dk>
>>> Gesendet: Apr 15, 2010 2:54:25 PM
>>> An: Heiko Oberdiek <oberdiek at uni-freiburg.de>,Victor Ivrii 
>>> <vivrii at gmail.com>,TeXhax <texhax at tug.org>
>>> Betreff: Re: [texhax] memoir, hyperref, nameref
>>>>> we change the \label contents after nameref, because we emulate 
>>>>> titleref and thus otherwise could not get our hands on the title. 
>>>>> So the \let\nameref\titleref fixed that problem
>>>> this now fails
>>>> just adding a
>>>> \AtBeginDocument{\typeout{test}}
>>>> at the very end of memhfixc shows that this AtBeginDocument gets 
>>>> executed before nameref is even loaded
>>>> This also means that the
>>>> \AtBeginDocument{%
>>>>   \@ifpackageloaded{nameref}{\let\nameref\titleref}{}%
>>>> }
>>>>
>>>> is never executed
>>> So try ctan.org/pkg/afterpackage:
>>>     \usepackage{afterpackage}
>>>     \AfterPackage{nameref}{\let\nameref\titleref}
>>
>> And the star form of \nameref is unsupported ...
>>
>> Yours sincerely
>>   Heiko Oberdiek
> 
> replace it with
> 
> \DeclareRobustCommand\nameref{\@ifstar{\@mem at titlerefnolink}{\@mem at titleref}} 
> 
> 
> that is how titleref is defined internally
> 
> \@mem at titlerefnolink gets redefined if hyperref is loaded
> 
> 
> /daleif
> 
> 
> 


Ok, I seem to have found a solution. A functionality similar to 
afterpackage is build into memoir, so this might do the trick

If it is ok by you, I'll add this to memoir in the coming update.

\documentclass[12pt]{memoir}
\usepackage{hyperref}
\makeatletter
\AtEndPackage{nameref}{
   \@ifundefined{NR at sectm@m}{% haven't fiddled with \M at sect
     \typeout{Redoing nameref's sectioning}
     \let\NR at sectm@m\M at sect
     \def\M at sect##1##2##3##4##5##6[##7][##8]##9{%
       \setcounter{section at level}{##2}%
       \def\@currentlabelname{##7}%
 
\NR at sectm@m{##1}{##2}{##3}{##4}{##5}{##6}[{##7}][{##8}]{\Sectionformat{##9}{##2}}}%
   }{}% \NR at sectm@m has already been defined

   \@ifundefined{MNR at label}{% haven't fiddled with \label
     \typeout{Redoing nameref's label}
     \let\MNR at label\label
     \def\label##1{\@bsphack\begingroup
       \protected at edef\@currentlabel{\protect\M at TitleReference
         {\@currentlabel}{\M at currentTitle}}%
       \MNR at label{##1}%
       \endgroup \@esphack}%
     \let\MNR at old@caption\@caption
     \long\def\@caption##1[##2]##3{%
       \MNR at old@caption{##1}[{##2}]{##3}%
       \def\@currentlabelname{##2}%
       \M at gettitle{##2}%
     }%
   }%
   {}% \MNR at label has already been defined
\DeclareRobustCommand\nameref{\@ifstar{\@mem at titlerefnolink}{\@mem at titleref}} 

}
\makeatother
\begin{document}
\section{One}
\label{sect-1}


nameref: \nameref{sect-1}

\noindent nameref*: \nameref*{sect-1}

\noindent titleref: \titleref{sect-1}
\end{document}






-- 

/daleif


More information about the texhax mailing list