I'm trying to do something similar as in this question.
I would like to use the value of a counter in the name of a \hypertarget and in addition, I want to be able to refer to this name in a \bookmark inside a \BookmarkAtEnd.
Here is a MWE of what I'm trying to do:
\documentclass{article}
\usepackage{hyperref}
\usepackage[atend]{bookmark}
\BookmarkAtEnd{\bookmark[level=0,named=LastPage]{Foos}}
\newcounter{foo}
\newcommand{\foo}{
\refstepcounter{foo}
\def\target{foo\arabic{foo}}
\hypertarget{\target}{Foo: \target}
\BookmarkAtEnd{\bookmark[level=1,dest=\target]{\target}}
}
\begin{document}
\foo
\foo
\end{document}
The bookmarks show up alright but the problem is they both link to the last target. As can be seen from the output of the MWE, the problem is that everything inside \BookmarkAtEnd is not expanded until the end of the document.
Is there a way to make sure the calls to \target inside \BookmarkAtEnd are expanded right away?
\BookmarkAtEndworks; with this technique you're sure that this command is issued outside that group. – egreg Mar 20 '12 at 20:36