Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cleveref + hyperref

297 views
Skip to first unread message

Ahmed Musa

unread,
Jul 1, 2011, 12:44:47 PM7/1/11
to
The following no longer gives hyperlinked references, if any at all. Please what could be happening?


\usepackage{cleveref} % version 2010/09/15 v0.17.5
\usepackage{hyperref} % version 2011/02/07 v6.82b

\begin{document}
\section{First Section}
\label{sec:one}
See something, say something.

\section{Second Section}
As mentioned in \cref{sec:one}, ...

\end{document}

Mico Loretan

unread,
Jul 1, 2011, 6:34:39 PM7/1/11
to

Ahmed: If you load hyperref first and then cleveref, you won't
experience the problem you describe. Incidentally, you may want to
consider working with more-recent versions of both hyperref (6.82g,
2011/04/17) and cleveref (0.17.9, 2011/03/11).

Sincerely, Mico

Ahmed Musa

unread,
Jul 1, 2011, 7:57:12 PM7/1/11
to
On Friday, 1 July 2011 23:34:39 UTC+1, Mico Loretan wrote:

@Mico: Thanks.

Another problem follows. Perhaps this one concerns only Heiko.

I used the following patch

\newcounter{appendix}
\def\appendix{%
\refstepcounter{appendix}%
\ltx@IfUndefined{chapter}%
{\gdef\theHsection{\Alph{appendix}}}%
{\gdef\theHchapter{\Alph{appendix}}}%
\xdef\Hy@chapapp{\Hy@appendixstring}%
\HyOrg@appendix
}

so that the following \autoref will give me 'Appendix A' instead of the native 'section A'.

\appendix
\section{First appendix section}
\label{xxx}

Don't mind W. Look the mouth of gift horse so that you don't end up with a liability where you expected a plus. :)

\autoref{xxx}


Is this safe and/or is there an alternative?

Mico Loretan

unread,
Jul 2, 2011, 5:20:14 AM7/2/11
to
Ahmed: I didn't try to work with your proposed code, so I can't tell
if it's "safe". However, I think you there is indeed a handy
alternative: \cref{xxx}. On my system (TeXlive 2010; March 2011
version of cleveref), I get "Appendix A" as the output of this
command, which is what I think you want as well. Best, Mico

Ahmed Musa

unread,
Jul 2, 2011, 8:37:26 AM7/2/11
to
On Saturday, 2 July 2011 10:20:14 UTC+1, Mico Loretan wrote:

The following works for me and, in the absence of Heiko advising otherwise, I'll continue to use it privately until it broke or until hyperref.sty provides for Appendix A in place of section A via \autoref:

\RequirePackage{catoptions}
\newvariables{if}[amd@]{inappendix}[false]
\newvariables{count}{c@appendix}[0]
\AfterStartOfDocument{%
\def\appendix{%
\amd@inappendixtrue
\refstepcounter{appendix}%
\ifdefTF\chapter


{\gdef\theHchapter{\Alph{appendix}}}%
{\gdef\theHsection{\Alph{appendix}}}%
\xdef\Hy@chapapp{\Hy@appendixstring}%
\HyOrg@appendix

}%
\newletcs\labell\label
\def\label{%
\ifamd@inappendix
\def\@currentHref{appendix.\@currentlabel}%
\fi
\labell
}%
}

Heiko Oberdiek

unread,
Jul 2, 2011, 10:02:03 AM7/2/11
to
Ahmed Musa <amu...@gmail.com> wrote:

> > > Another problem follows. Perhaps this one concerns only Heiko.
> > >
> > > I used the following patch
> > >
> > > \newcounter{appendix}
> > > \def\appendix{%
> > >   \refstepcounter{appendix}%
> > >   \ltx@IfUndefined{chapter}%
> > >     {\gdef\theHsection{\Alph{appendix}}}%
> > >     {\gdef\theHchapter{\Alph{appendix}}}%
> > >   \xdef\Hy@chapapp{\Hy@appendixstring}%
> > >   \HyOrg@appendix
> > >
> > > }
> > >
> > > so that the following \autoref will give me 'Appendix A' instead of the native 'section A'.

It only works for \label right after \appendix and you would get
`Appendix 1'. After \section, \refstepcounter{section} is called
and the internal anchor name starts with "section".

> The following works for me and, in the absence of Heiko advising otherwise, I'll continue to use it privately until it broke or until hyperref.sty provides for Appendix A in place of section A via \autoref:
>
> \RequirePackage{catoptions}
> \newvariables{if}[amd@]{inappendix}[false]
> \newvariables{count}{c@appendix}[0]
> \AfterStartOfDocument{%
> \def\appendix{%
> \amd@inappendixtrue
> \refstepcounter{appendix}%
> \ifdefTF\chapter
> {\gdef\theHchapter{\Alph{appendix}}}%
> {\gdef\theHsection{\Alph{appendix}}}%
> \xdef\Hy@chapapp{\Hy@appendixstring}%
> \HyOrg@appendix
> }%
> \newletcs\labell\label
> \def\label{%
> \ifamd@inappendix
> \def\@currentHref{appendix.\@currentlabel}%
> \fi
> \labell
> }%
> }

Inside \label you have to check for section explicitely, otherwise you
get "Appendix" for other things like equations, ...

Also I don't understand the whole business.
\autoref supports the appendix stuff for years:

| 2007-01-14 6.75m Heiko Oberdiek
| * 6.75m
| * \autoref uses the name for appendix if it references sections
| that follow \appendix in classes without \chapter.

Your redefinition of \appendix destroys this.

\documentclass{article}
\usepackage{hyperref}[2007/01/14]
\begin{document}
\noindent
AutoRef(Section): \autoref{sec:hello}\\
AutoRef(Appendix): \autoref{app:hello}

\section{Hello Section}\label{sec:hello}
\appendix
\section{Hello Appendix}\label{app:hello}
\end{document}

--
Heiko Oberdiek

Ahmed Musa

unread,
Jul 2, 2011, 2:26:31 PM7/2/11
to
On Saturday, 2 July 2011 15:02:03 UTC+1, Heiko Oberdiek wrote:
> Ahmed Musa <amu...@gmail.com> wrote:
>
> > > > Another problem follows. Perhaps this one concerns only Heiko.
> > > >
> > > > I used the following patch
> > > >
> > > > \newcounter{appendix}
> > > > \def\appendix{%
> > > > � \refstepcounter{appendix}%
> > > > � \ltx@IfUndefined{chapter}%
> > > > � � {\gdef\theHsection{\Alph{appendix}}}%
> > > > � � {\gdef\theHchapter{\Alph{appendix}}}%
> > > > � \xdef\Hy@chapapp{\Hy@appendixstring}%
> > > > � \HyOrg@appendix

Many thanks. The problem lies in a private class file. I will find it.

Ahmed Musa

unread,
Jul 2, 2011, 7:24:36 PM7/2/11
to
I spent the whole day and night on this problem without success. I think I have to give up now. Please see below what is happening. Perhaps I won't be the last to encounter this problem. I don't know what is interfering with \@currentHref.

\appendix

\section{Test}
\label{sec:test}

gives:

\newlabel{sec:test}{{B}{17}{Test\relax }{section.B}{}}

in the .aux file.

And

\show\label

yields

> \label=macro:
#1->\@bsphack \begingroup \@onelevel@sanitize \@currentlabelname \edef \@curren
tlabelname {\expandafter \strip@period \@currentlabelname \relax .\relax \@@@ }
\protected@write \@auxout {}{\string \newlabel {#1}{{\@currentlabel }{\thepage
}{\@currentlabelname }{\@currentHref }{}}}\endgroup \@esphack .

Ahmed Musa

unread,
Jul 2, 2011, 7:26:54 PM7/2/11
to


The 'B' in the following could have been 'A'. 'B' simply means that there was another section before \section{Test}.

Heiko Oberdiek

unread,
Jul 2, 2011, 9:01:46 PM7/2/11
to
Ahmed Musa <amu...@gmail.com> wrote:

> I spent the whole day and night on this problem without success. I think I have to give up now. Please see below what is happening. Perhaps I won't be the last to encounter this problem. I don't know what is interfering with \@currentHref.
>
> \appendix
>
> \section{Test}
> \label{sec:test}
>
> gives:
>
> \newlabel{sec:test}{{B}{17}{Test\relax }{section.B}{}}
>
> in the .aux file.

I have already written that your redefinition of \appendix destroys
the feature of hyperref.

--
Heiko Oberdiek

Ahmed Musa

unread,
Jul 2, 2011, 9:05:16 PM7/2/11
to

Ahmed Musa

unread,
Jul 2, 2011, 11:45:16 PM7/2/11
to
>
> I have already written that your redefinition of \appendix destroys
> the feature of hyperref.
>
> --
> Heiko Oberdiek

The following preserves it and it too works:

\newvariables{if}[amd@]{inappendix}[false]
\newvariables{count}{c@appendix}[0]

\newletcs\amd@oldappendix\appendix


\AfterStartOfDocument{%
\def\appendix{%
\amd@inappendixtrue

\amd@oldappendix
}%
\newletcs\labell\label
\gdef\label{%

Heiko Oberdiek

unread,
Jul 3, 2011, 3:22:24 AM7/3/11
to
Ahmed Musa <amu...@gmail.com> wrote:

I doubt it. It will work only for \section commands, nothing else.

--
Heiko Oberdiek

Mico Loretan

unread,
Jul 3, 2011, 10:13:15 AM7/3/11
to
On Jul 3, 3:22 am, Heiko Oberdiek <heiko.oberd...@googlemail.com>
wrote:

Ahmed: I'm afraid I also can't follow where you're encountering
problems that would necessitate recoding some of hyperref's
instructions. Could you provide the group both an MWE and file-
listing?

Sincerely, Mico

PS The following MWE -- not quite minimal, as I've added instructions
to make the output of the two types of cross-referencing commands look
the same -- works flawlessly on my MacTeX installation.
-----
% hyperclev.tex
\listfiles
\documentclass{article}
\usepackage[colorlinks]{hyperref}
\renewcommand{\sectionautorefname}{Section}
\usepackage{cleveref}
\crefformat{section}{#2Section~#1#3}
\crefformat{appendix}{#2Appendix~#1#3}

\begin{document}
\section{autoref commands only} \label{sec:autoref}
As shown in \autoref{sec:aux} and \autoref{sec:cref}, \ldots

\section{cref commands only} \label{sec:cref}
As shown in \cref{sec:aux,sec:autoref}, \ldots

\appendix
\section{Auxiliary results}\label{sec:aux}
Mumble mumble \ldots
\end{document}
-----
This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011)
(format=pdflatex 2011.7.2) 3 JUL 2011 09:58
...
*File List*
article.cls 2007/10/19 v1.4h Standard LaTeX document class
size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
hyperref.sty 2011/04/17 v6.82g Hypertext links for LaTeX
hobsub-hyperref.sty 2011/04/23 v1.4 Bundle oberdiek, subset
hyperref (HO)
hobsub-generic.sty 2011/04/23 v1.4 Bundle oberdiek, subset generic
(HO)
hobsub.sty 2011/04/23 v1.4 Subsetting bundle oberdiek (HO)
infwarerr.sty 2010/04/08 v1.3 Providing info/warning/message (HO)
ltxcmds.sty 2011/04/18 v1.20 LaTeX kernel commands for general use
(HO)
ifluatex.sty 2010/03/01 v1.3 Provides the ifluatex switch (HO)
ifvtex.sty 2010/03/01 v1.5 Switches for detecting VTeX and its
modes (HO)
intcalc.sty 2007/09/27 v1.1 Expandable integer calculations (HO)
ifpdf.sty 2011/01/30 v2.3 Provides the ifpdf switch (HO)
etexcmds.sty 2011/02/16 v1.5 Prefix for e-TeX command names (HO)
kvsetkeys.sty 2011/04/07 v1.13 Key value parser (HO)
kvdefinekeys.sty 2011/04/07 v1.3 Defining keys (HO)
pdftexcmds.sty 2011/04/22 v0.16 Utilities of pdfTeX for LuaTeX (HO)
pdfescape.sty 2011/04/04 v1.12 Provides string conversions (HO)
bigintcalc.sty 2011/01/30 v1.2 Expandable big integer calculations
(HO)
bitset.sty 2011/01/30 v1.1 Data type bit set (HO)
uniquecounter.sty 2011/01/30 v1.2 Provides unlimited unique counter
(HO)
letltxmacro.sty 2010/09/02 v1.4 Let assignment for LaTeX macros
(HO)
hopatch.sty 2011/01/30 v1.0 Wrapper for package hooks (HO)
xcolor-patch.sty 2011/01/30 xcolor patch
atveryend.sty 2011/04/23 v1.7 Hooks at very end of document (HO)
atbegshi.sty 2011/01/30 v1.15 At begin shipout hook (HO)
refcount.sty 2010/12/01 v3.2 Data extraction from references (HO)
hycolor.sty 2011/01/30 v1.7 Color options of hyperref/bookmark
(HO)
keyval.sty 1999/03/16 v1.13 key=value parser (DPC)
ifxetex.sty 2010/09/12 v0.6 Provides ifxetex conditional
kvoptions.sty 2010/12/23 v3.10 Keyval support for LaTeX options
(HO)
pd1enc.def 2011/04/17 v6.82g Hyperref: PDFDocEncoding definition
(HO)
hyperref.cfg 2002/06/06 v1.2 hyperref configuration of TeXLive
url.sty 2006/04/12 ver 3.3 Verb mode for urls, etc.
hpdftex.def 2011/04/17 v6.82g Hyperref driver for pdfTeX
rerunfilecheck.sty 2011/04/15 v1.7 Rerun checks for auxiliary files
(HO)
cleveref.sty 2011/03/22 v0.17.9 Intelligent cross-referencing
color.sty 2005/11/14 v1.0j Standard LaTeX Color (DPC)
color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX
supp-pdf.mkii
nameref.sty 2010/04/30 v2.40 Cross-referencing by name of section
gettitlestring.sty 2010/12/03 v1.4 Cleanup title references (HO)
hyperclev.out
hyperclev.out
***********

Ahmed Musa

unread,
Jul 3, 2011, 11:02:22 AM7/3/11
to
On Sunday, 3 July 2011 15:13:15 UTC+1, Mico Loretan wrote:
> On Jul 3, 3:22 am, Heiko Oberdiek <heiko.o...@googlemail.com>
> wrote:

Mico: Many thanks for your great effort! The problem is most likely with my class file, which has grown too long in recent months. All the MWEs I have produced so far are flawless, meaning that I just have to keep trying to locate the source of the headache. It will take longer than I had thought, but surely I'll find it. Thanks.

Ahmed Musa

unread,
Jul 3, 2011, 4:03:37 PM7/3/11
to
I may have found the source of the problem: titlesec.sty + hyperref.sty. Nothing else causes this particular anomaly. Please run the following.

\documentclass{article}
\usepackage{titlesec}[2007/08/12]


\usepackage{hyperref}[2007/01/14]
\begin{document}
\noindent
AutoRef(Section): \autoref{sec:hello}\\
AutoRef(Appendix): \autoref{app:hello}

\section{Hello Section}\label{sec:hello}
\appendix
\section{Hello Appendix}\label{app:hello}

\autoref{app:hello}
\end{document}

I suspect the following:

\@ifpackageloaded{titlesec}{%
\def\ttl@Hy@steplink#1{%
\Hy@MakeCurrentHrefAuto{#1*}%
\edef\ttl@Hy@saveanchor{%
\noexpand\Hy@raisedlink{%
\noexpand\hyper@anchorstart{\@currentHref}%
\noexpand\hyper@anchorend
\def\noexpand\ttl@Hy@SavedCurrentHref{\@currentHref}%
\noexpand\ttl@Hy@PatchSaveWrite
}%
}%
}%
\def\ttl@Hy@PatchSaveWrite{%
\begingroup
\toks@\expandafter{\ttl@savewrite}%
\edef\x{\endgroup
\def\noexpand\ttl@savewrite{%
\let\noexpand\@currentHref
\noexpand\ttl@Hy@SavedCurrentHref
\the\toks@
}%
}%
\x
}%
\def\ttl@Hy@refstepcounter#1{%
\let\ttl@b\Hy@raisedlink
\def\Hy@raisedlink##1{%
\def\ttl@Hy@saveanchor{\Hy@raisedlink{##1}}%
}%
\refstepcounter{#1}%
\let\Hy@raisedlink\ttl@b
}%
}{}


Mico Loretan

unread,
Jul 4, 2011, 4:35:06 PM7/4/11
to

Ahmed: I have good news (of sorts!): I can completely replicate the
error you've discovered; I'm running MacTeX 2011 with hyperref version
6.82g. I've also determined that (i) if titlesec is loaded, cleveref's
\cref suffers the exact same problem as hyperref's \autoref does (in
terms of finding the correct prefix "Appendix" when a cross-reference
to an appendix section is made) and (ii) if titlesec is NOT loaded,
neither \cref nor \autoref encounter have any problems of this kind.
In short, it makes me think that the "real culprit" is not hyperref
(or cleveref) but titlesec. Cheers, Mico.

Ahmed Musa

unread,
Jul 4, 2011, 5:29:14 PM7/4/11
to
> Ahmed: I have good news (of sorts!): I can completely replicate the
> error you've discovered; I'm running MacTeX 2011 with hyperref version
> 6.82g. I've also determined that (i) if titlesec is loaded, cleveref's
> \cref suffers the exact same problem as hyperref's \autoref does (in
> terms of finding the correct prefix "Appendix" when a cross-reference
> to an appendix section is made) and (ii) if titlesec is NOT loaded,
> neither \cref nor \autoref encounter have any problems of this kind.
> In short, it makes me think that the "real culprit" is not hyperref
> (or cleveref) but titlesec. Cheers, Mico.

Yes, I was perhaps wrong in suspecting hyperref since the problem exists with cleveref as well. I don't suspect titlesec because its latest release is 2007/08/12 v2.8 (I have just confirmed this on CTAN), while both hyperref and cleveref have been updated several times since then.

Javier Bezos

unread,
Jul 15, 2011, 10:41:58 AM7/15/11
to
Mico,

>> I may have found the source of the problem: titlesec.sty +
>> hyperref.sty. Nothing else causes this particular anomaly. Please run
>> the following.

[...]


> In short,
> it makes me think that the "real culprit" is not hyperref (or cleveref)
> but titlesec.

Please, help other users and report bugs to the authors.
I've found a work-around (at least for the article class)
which seems to work. After loading both packages, put:

\makeatletter
\edef\Hy@chapterstring{\expandafter\strip@prefix\meaning\Hy@chapterstring}
\makeatother

This doesn't mean the problem is in hyperref, but there is
an unfortunate mixing of catcodes fixed by this piece of code
(but it could break other things -- I haven't tested it
thoroughly).

[BTW, Ahmed, the problem has no relation with the code you
pasted.]

Javier
-----------------------------
http://www.tex-tipografia.com


Ahmed Musa

unread,
Jul 16, 2011, 9:56:03 AM7/16/11
to
> Please, help other users and report bugs to the authors.

Noted with thanks!

>
> \makeatletter
> \edef\Hy@chapterstring{\expandafter\strip@prefix\meaning\Hy@chapterstring}
> \makeatother
>
> This doesn't mean the problem is in hyperref, but there is
> an unfortunate mixing of catcodes fixed by this piece of code
> (but it could break other things -- I haven't tested it
> thoroughly).
>

I doubt if this problem can be resolved completely without the intervention of Heiko (hyperref) and Toby Cubitt (cleveref). But Heiko's conspicuous silence suggests that he beleives the problem has nothing to do with hyperref.

0 new messages