TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

From this question Creating PDF bookmarks in custom order arose another. (I hope it is correct to create a new question instead of commenting or editing/answering my old question.)

Using this macro (after creating counter nops):

    \bookmark[dest=nop\arabic{nops}]{page \arabic{nops}}

I want \nop to mark the current place and add a bookmark to it to the end of my bookmark list. what happens is that the correct number of bookmarks is created, but they all reference the last occurence of \nop. It seems that this is because the text within \BookmarkAtEnd is practically copied to the end instead of inserting the current values first. How can i change this?

share|improve this question
up vote 7 down vote accepted

\BookmarkAtEnd simply stores the token list given as its argument, but you need that \arabic{nops} is expanded before storing.

The more common trick is to say

    \noexpand\bookmark[dest=nop\arabic{nops}]{page \arabic{nops}}}}\x

The \begingroup and \endgroup are used just in order to avoid that \x has a definition after being used. We protect from expansion the commands \BookmarkAtEnd and \bookmark (\endgroup doesn't need to be protected because it's unexpandable); in this way the token list to be stored will contain the actual value of nops and not a command to get at its representation.

share|improve this answer
There is a } missing before \x, but otherwise it works! Thank you. – peter Apr 30 '11 at 23:33
@peter: Oops, corrected. – egreg Apr 30 '11 at 23:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.