2

I have the following MWE:

\documentclass[a4paper,12pt, oneside, final, headsepline]{scrartcl}

\usepackage{endnotes}
\usepackage[perpage, multiple]{footmisc}
\renewcommand{\notesname}{Linkverzeichnis}
\usepackage{float}
\usepackage[bf]{caption}

\begin{document}
\section{Grundlagen}

Bla bla bla Link\endnote{url1}
\begin{figure}[h]
\centering
\caption[Short caption without endnote to avoid errors]{Blubber. (Quelle\endnote{url2})}
\end{figure}

Bla bla bla Link\endnote{url3}

\theendnotes
\end{document}

The result is:

wrong endnots counter

Instead of the endnotes counting

1. url1
2. url2
3. url3

I get

1. url1
3. url2
4. url3

or alternatively:

1. url1
2. url2
3. url2
4. url3

In this case you can trigger the last one by commenting out the \usepackage[bf]{caption} line, but I get both in my text. I already figured out that this happens if there is an endnote inside a float, but I really don't know why.

How can I fix this?

Edit:

Based on the solution provided in the accepted answer, I built the following commands for future reuse:

\newcommand{\endnoteouter}[1]{\sbox0{\endnotemark}\endnotetext{\sloppy#1}}
\newcommand{\endnoteinner}{\usebox0}

Declare the endnote with \endnoteouter{Text} before the figure and call it with \endnoteinner at the correct place. If there are multiple endnotes in a figure, an argument could be passed to specify the box number.

piegames
  • 157
  • 1
    A simple solution is using \usepackage[singlelinecheck=false]{caption} see: http://tex.stackexchange.com/a/127935/124842 . – Bobyandbob Mar 13 '17 at 09:45
  • 1
    @Bobyandbob while being a nice solution this seems to break the \centering of the \caption. – Skillmon Mar 13 '17 at 09:59

1 Answers1

4

With the answer provided here you can get this working like this:

\documentclass[a4paper,12pt, oneside, final, headsepline]{scrartcl}

\usepackage{endnotes}
\usepackage[perpage, multiple]{footmisc}
\renewcommand{\notesname}{Linkverzeichnis}
\usepackage{float}
\usepackage[bf]{caption}

\begin{document}
\section{Grundlagen}

Bla bla bla Link\endnote{url1}
\sbox0{\endnotemark}
\begin{figure}[h]
\centering
\caption[Short caption without endnote to avoid errors]{Blubber.
    (Quelle\usebox0)}
\end{figure}
\endnotetext{url2}

Bla bla bla Link\endnote{url3}

\theendnotes
\end{document}

results

To the question why this happens: The contents of the \endnote might get evaluated twice (because the \caption is evaluated twice) resulting in an additional incrementation of endnote-counter.

EDIT: As requested here is a (very ugly) command, that might ease the process:

\documentclass[a4paper,12pt, oneside, final, headsepline]{scrartcl}

\usepackage{endnotes}
\usepackage[perpage, multiple]{footmisc}
\renewcommand{\notesname}{Linkverzeichnis}
\usepackage{float}
\usepackage[bf]{caption}

\newcommand\mycaption[4]{
    \sbox0{\endnotemark}
    \caption[#1]{#2\usebox0#3}
    \endnotetext{#4}
}

\begin{document}
\section{Grundlagen}

Bla bla bla Link\endnote{url1}
\sbox0{\endnotemark}
\begin{figure}[h]
\centering
\caption[Short caption without endnote to avoid errors]{Blubber.
    (Quelle\usebox0)}
\end{figure}
\endnotetext{url2}

Bla bla bla Link\endnote{url3}

\begin{figure}[h]
\centering
\mycaption{Short caption without endnote to avoid errors}{Blubber. (Quelle}{)}{url4}
\end{figure}

\theendnotes
\end{document}

The syntax of this command would be:

\mycaption[<short caption for lot/lof>]{<caption until the endnote-mark>}{<caption after the endnote-mark>}{<content of the endnotemark>}

EDIT 2: If the endnotemark should always be at the same spot (Quelle#) you might change the command to:

\newcommand\mycaption[3][]{
    \sbox0{\endnotemark}
    \ifx&#1&
        \caption[#2]{#2 (Quelle\usebox0)}
    \else
        \caption[#1]{#2 (Quelle\usebox0)}
    \fi
    \endnotetext{#3}
}

And use it this way: \mycaption[<short caption>]{<caption>}{<endnote text>} If you leave out the <short caption> the caption without "(Quelle#)" is displayed in the \listof...-commands.

Skillmon
  • 60,462
  • Thanks, this works. Is there a way to put this into a new command to integrate it into larger texts more easily? – piegames Mar 13 '17 at 10:16
  • @piegames see my edit. But it is a ugly command. – Skillmon Mar 13 '17 at 13:30
  • @piegames I added another example of the new command which might be better but is less versatile. – Skillmon Mar 13 '17 at 15:40
  • Just found out your method has a little drawback: It does not respect the text formatting in the float. Fortunately, this was only an issue in subfigures for me. – piegames Mar 16 '17 at 12:15
  • @piegames That's because the content of the box is not set inside of a caption. You might change the line \sbox0{\endnotemark} to something containing the required text formatting, e.g. \sbox0{\small\endnotemark}. – Skillmon Mar 16 '17 at 12:28