Looks like I managed to fix it: either defining \newbox\tmpbox% outside the definition of the command or using \lnewbox from the localloc package did it. I didn't realise that \newbox has global scope. Misha