# Cleveref won't work with enotez

I want to set endnotes in my document with enotez, and I want to reference them using cleveref. However, I always get this error:

LaTeX Warning: cref reference format for label type ' undefined

According to the cleveref manual, one can define formats for reference types with \crefname{type}{singular}{plural}, where typecorresponds to a counter. I have defined a format for the counter endnote; this counter is defined in enotez.sty, and it is known to LaTeX, as shown in the last line of output from the following MWE:

\documentclass{article}

\usepackage[backref]{enotez}
\usepackage[hyperfootnotes=true,pdftex]{hyperref}

\usepackage{cleveref}
\crefname{endnote}{Endnote}{Endnotes}

\begin{document}
This is an endnote with a label\endnote{Labeled endnote}\label{labeled}

Have you seen \cref{labeled} yet?

The current endnote\endnote{Another endnote} is \theendnote.
\printendnotes
\end{document}


So, although the counter exists it isn't recognized by cleveref. What could I do about it?

• Did you try putting \crefname{endnote} and \Crefname{endnote} in a cleveref.cfg file? – Bernard Oct 11 '17 at 15:10
• @Bernard It shouldn't make a difference whether the definition of crefname is put into the preamble or in an external config file -- except that you keep your preamble clean and mean. I tried it out, though, with the result that it didn't change anything. Thanks nevertheless! :-) – Andreas Oct 11 '17 at 15:19
• This is very likely because enotez does not use \refstepcounter... So I guess this is a feature request: make enotez compatible with cleveref – clemens Oct 11 '17 at 15:34
• @clemens Right you are! This is a feature request: please make enotez compatible with cleveref! :-) – Andreas Oct 11 '17 at 18:58
• @Andreas would you mind posting this as an issue on bitbucket.org/cgnieder/enotez/issues then? Else it is quite possible that I will forget about it – clemens Oct 11 '17 at 19:09

It is due to a coding mistake in the enotez.sty package and should be notified to the package author. The counter is change using \stepcounter and manually modifies \@currentlabel instead of just using \refstepcounter. You can override the faulty construction as follows:

\documentclass{article}

\usepackage{expl3}
\usepackage[backref]{enotez}
\usepackage[hyperfootnotes=true,pdftex]{hyperref}

\usepackage{cleveref}
\crefname{endnote}{Endnote}{Endnotes}

\ExplSyntaxOn
\cs_set_protected:Npn \enotez_endnote_mark:n #1
{
\int_gincr:N \g__enotez_endnote_id_int
\quark_if_no_value:nTF {#1}
{
\refstepcounter {endnote}
% \show \theendnote
% \cs_gset:cpx {@currentlabel} {\theendnote}
\enotez_write_mark:xn
{ \int_use:N \g__enotez_endnote_id_int }
{ \theendnote }
}
{
\cs_gset:cpn {@currentlabel} {#1}
% \cs_gset_eq:NN \theendnote \@currentlabel
\enotez_write_mark:xn { \int_use:N \g__enotez_endnote_id_int } {#1}
}
\bool_if:NT \l__enotez_disable_bool
{
\int_gdecr:N \g__enotez_endnote_id_int
}
}
\ExplSyntaxOff

\begin{document}

This is an endnote with a label\endnote{Labeled endnote}\label{labeled}

Have you seen \cref{labeled} yet?

The current endnote\endnote{Another endnote}\label{tt} is \theendnote.
\printendnotes
\end{document}


Note there is a second manual setting of \@currentlabel in the above code I have not corrected as it is not used in your use case.

• this is due to the history of the package: originally enotez` didn't use a counter – clemens Oct 11 '17 at 15:42
• @AndrewSwann Wonderful, that works great! Thanks a lot! – Andreas Oct 11 '17 at 19:01