I'm trying to do some voodoo with \peek_meaning. I want to have a command, \blubb, which is sensitive to repetitions of itself.
When I write \blubb{Lorem Ipsum}, I want the text coloured in red, but with \blubb\blubb{Lorem Ipsum} I would like the text to be coloured in blue. See this working example:
\documentclass{article}
\usepackage{xcolor}
\usepackage{expl3}
\usepackage{xparse}
%\usepackage{hyperref}
\ExplSyntaxOn
\DeclareRobustCommand\blubb{
\peek_meaning:NTF \blubb { \colorTwo } { \colorOne }
}
\ExplSyntaxOff
\DeclareRobustCommand\colorOne[1]{\textcolor{red}{#1}}
\DeclareRobustCommand\colorTwo[2]{\textcolor{blue}{#2}}
\begin{document}
Lorem Ipsum \blubb{is red} Dolor Sit \blubb\blubb{is blue}
\section{Lorem Ipsum \blubb{is red} Dolor Sit \blubb\blubb{is blue}}
% ^ does not work with hyperref
\end{document}
This works fine, until I enable the hyperref package. Then I get:
! TeX capacity exceeded, sorry [input stack size=5000].
\blubb ->\peek_meaning:NTF \blubb
{\colorTwo }{\colorOne }
l.23 ...b{is red} Dolor Sit \blubb\blubb{is blue}}
Apparently, the \blubb after \peek_meaning gets expanded, which leads to a recursion. How do I prevent this?



\peek_meaning_remove, this avoids the ugly, inconsistent definition of\colorXXX! – Peater de Xel Sep 13 '16 at 12:04;-)Adding a new answer just for fixing a couple of weaknesses was not a choice. – egreg Sep 13 '16 at 20:31\blubbthan have\ColorTwothrow its first argument away? Intuitively that seems better, but I could not explain why. – cfr Sep 13 '16 at 20:49\colorOneand\colorTwoindependently of their eventual position in the macro; with the_remove, the token is removed if found and the proper path is followed. This can be used to check for a third\blubb, for instance, without any need for defining differently\colorThree. – egreg Sep 13 '16 at 20:53