# Double printing the endnote using enotez

I have an endnote in the caption of a figure environment. When compiled the endnote is printed twice.

However, if b5paper option is removed, or one or two words are removed from the caption preceding the endnote command the numbering is correct.

\documentclass[11pt,b5paper,draft]{book}

\usepackage{geometry}
\usepackage[split=chapter,reset=true]{enotez}
\usepackage{graphicx}
\begin{document}
\chapter{title}
More generally, it is to this source we must look for the increase of property of every description\endnote{Some text.}
\begin{figure}
\begin{center}
\caption{for five British manufacturing sectors, 1730–1820. 1780 = 100.\endnote{Data from R. V. Jackson, ‘Rates of Industrial Growth during the Industrial Revolution,’ EHR 45 (1992), 18.}}
\end{center}
\label{figure31}
\end{figure}
\printendnotes
\end{document}


• Please add a report on bitbucket.org/cgnieder/enotez/issues – clemens Jun 15 '16 at 16:43
• I won't promise a solution, though. Captions are moving arguments and as such difficult places for any kinds of notes. – clemens Jun 15 '16 at 16:43
• It's ok. thank you. I'll also report it on bitbucket. – nima Jun 15 '16 at 18:11

MANUAL SOLUTION (see below for automation of this approach)

An ugly workaround... I use a \textsuperscript to set the endnote number inside of the caption, and then I set the \endnote in a temporary box outside of the caption.

\documentclass[11pt,b5paper,draft]{book}

\usepackage{geometry}
\usepackage[split=chapter,reset=true]{enotez}
\usepackage{graphicx}
\begin{document}
\chapter{title}
More generally, it is to this source we must look for the increase of property of every description\endnote{Some text.}
\begin{figure}
\begin{center}
\caption{for five British manufacturing sectors, 1730–1820. 1780 = 100.%
\textsuperscript{\the\numexpr\theendnote+1\relax}}
\setbox0=\hbox{\endnote{Data from R. V. Jackson, ‘Rates of Industrial Growth during the Industrial Revolution,’ EHR 45 (1992), 18.}}
\end{center}
\label{figure31}
\end{figure}
\printendnotes
\end{document}


AUTOMATIC SOLUTION (if only one endnote per caption)

Here I introduce \encaption[<toc-caption-text>]{<caption-text>}{<endnote-text>} for captions that include exactly one endnote. Inside the caption-text, one should use \entag to signify where the endnote tag is to be placed.

This is set up so that the endnote tag does not show up in the list of figures, per the OP's comment to egreg.

\documentclass[11pt,b5paper,draft]{book}

\usepackage{geometry}
\usepackage[split=chapter,reset=true]{enotez}
\usepackage{graphicx}
\usepackage{xpatch}
\newcommand\encaption[3][\relax]{%
\ifx\relax#1\relax\caption{#2}\setbox0=\hbox{\endnote{#3}}\else%
\caption[#1]{#2}\setbox0=\hbox{\endnote{#3}}\fi
}
\def\entag{\protect\entaghelp}
\def\setentag{\def\entaghelp{\textsuperscript{\the\numexpr\theendnote+1\relax}}}
\let\entaghelp\relax
\apptocmd{\listoffigures}{\setentag}{}{}
\begin{document}
\listoffigures
\chapter{title}
More generally, it is to this source we must look for the increase of property of every description\endnote{Some text.}
\begin{figure}
\centering
\encaption{for five British manufacturing sectors, 1730–1820. 1780 = 100.%
\entag}{%
Data from R. V. Jackson, ‘Rates of Industrial Growth during the Industrial Revolution,’ EHR 45 (1992), 18.}
\label{figure31}
\end{figure}
\printendnotes
\end{document}

• Thanks for the solution, I think at the end if there were no solution I'll use yours. – nima Jun 15 '16 at 18:17
• @nima See my revision which shows an automatic approach if the caption contains only a single endnote. – Steven B. Segletes Jun 15 '16 at 18:54
• @nima If there is a need for captions with more than a single endnote in them, let me know and I will try to automate that, as well. – Steven B. Segletes Jun 15 '16 at 19:12
• @nima The definition \def\entaghelp{\textsuperscript{\the\numexpr\theendnote+1\relax}} needs to occur at some point. It is done with \setentag, which is set up to invoke itself at the end of the list of figures. But if you have no list of figures, \setentag will never get invoked automatically. If you omit the list of figures, you will need instead to invoke \setentag manually. – Steven B. Segletes Jun 16 '16 at 12:17
• Aha, I removed list of figures'' and the superscript for the endnote get lost, and I just put \setentag instead of \listoffigures and everything got correct. I'll ask further question to this post in chat if there were any. Thank you. – nima Jun 16 '16 at 12:24

It is a tough problem; the standard working of \caption is to typeset it for getting its size. This already stores the endnote text in memory; if the caption is wider than the text width, it is typeset again and this stores the endnote once more. This is your case.

A solution is to avoid this double typesetting of the caption text.

You have to use the optional argument anyway, if you compile the list of figures, or the endnote would appear also there.

The package should implement \endnotemark and \endnotetext for this case. According to the documentation, the author deems them to not be needed: he's wrong. The counter used to store the current endnote number should also be publicly available.

\documentclass[11pt,b5paper,draft]{book}

\usepackage{geometry}
\usepackage[split=chapter,reset=true]{enotez}
\usepackage{graphicx}

\makeatletter
%%% ugly hack for not typesetting twice the endnote
\long\def\@makecaption#1#2{%
\vskip\abovecaptionskip
\begingroup
\def\endnote##1{%
\textsuperscript{\the\numexpr\csname g__enotez_endnote_id_int\endcsname+1}%
}%
\sbox\@tempboxa{#1: #2}%
\ifdim \wd\@tempboxa >\hsize
\endgroup
#1: #2\par
\else
\endgroup
\global \@minipagefalse
\hb@xt@\hsize{\hfil#1: #2\hfil}%
\fi
\vskip\belowcaptionskip}
\makeatother

\begin{document}

\chapter{title}

More generally, it is to this source we must look
for the increase of property of every description\endnote{Some text.}

\begin{figure}
\centering
\caption[for five British manufacturing sectors, 1730--1820. 1780 = 100.]%
{for five British manufacturing sectors, 1730--1820. 1780 = 100.%
\endnote{Data from R. V. Jackson, ‘Rates of Industrial Growth
during the Industrial Revolution,’ EHR 45 (1992), 18.}}
\label{figure31}
\end{figure}

\printendnotes

\end{document}


By the way, don't use center in a figure environment; if you prefer its enlarged spacing, fine, but don't set the label outside the center environment: it must be at the same group level as \caption.

• No I don't want it. Thank you for the advice. – nima Jun 15 '16 at 18:12
• I am not sure why, when I compile your code, the problem of duplicate endnotes does not disappear. – Steven B. Segletes Jun 15 '16 at 18:23
• @StevenB.Segletes OMG! – egreg Jun 15 '16 at 19:33
• Sorry I'm just ever novice and I really didn't get what you explained. But I actually liked it that there was an explanation for it. – nima Jun 15 '16 at 20:24